1 /*****************************************************************************
2    Major portions of this software are copyrighted by the Medical College
3    of Wisconsin, 1994-2000, and are released under the Gnu General Public
4    License, Version 2.  See the file README.Copyright for details.
5 ******************************************************************************/
6 #ifndef _MCW_MACHDEP_
7 #define _MCW_MACHDEP_
8 
9 #ifdef SPARKY
10 #undef _POSIX_SOURCE
11 #endif
12 
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <sys/mman.h>
16 #include <fcntl.h>
17 
18 #ifdef  __cplusplus
19 extern "C" {
20 #endif
21 
22 extern void machdep() ;
23 
24 #ifdef  __cplusplus
25 }
26 #endif
27 
28 /*----------------------------------------------------------------------------
29   Flags that can be used to work around bugs on some systems
30   (you could also use the -Dname command line switch in the Makefile
31    definition of the CC commands to enable these options):
32 
33     USE_TRACING = if #define-d, then AFNI and its programs will compile
34                    in a set of data/functions that allows debug tracing
35                    of execution.
36 
37     ALLOW_MCW_MALLOC = if this is set, then the malloc wrappers
38                        defined in mcw_malloc.[ch] will be used.
39                        (These functions provide some ability to track
40                        and debug the use of malloc-ed memory space.)
41 
42     DONT_USE_METER  = if #define-d, won't show progress meter during
43                        brick write operations (and other similar places)
44 
45     FIX_SCALE_VALUE_PROBLEM = if #defined-d, will work around a bug
46                                in Solaris Motif where the threshold scale
47                                value is not displayed
48                                [Doesn't seem to be needed anymore]
49 
50     FIX_SCALE_SIZE_PROBLEM = if #define-d, will work around a bug in
51                               some versions of Motif where the
52                               threshold scale resizes itself whenever
53                               the pbar is touched
54 
55     FIX_SCALE_SIZE_LATER   = if this is ALSO defined, then the
56                              FIX_SCALE_SIZE_PROBLEM is applied after a
57                              time delay when panel is opened
58 
59     SCANDIR_WANT_CONST = if #define-d, says that the "scandir" library
60                           routine wants "const" arguments -- setting this
61                           flag will avoid some stupid compiler warnings
62 
63     DONT_USE_SCANDIR   = if #define-d, the Unix routine scandir won't
64                           be used.  This seems to help on Solaris, and
65                           doesn't hurt on other systems, so it is now
66                           the default.
67 
68     DONT_INSTALL_ICONS = if #define-d, won't try to install icons for the
69                           various windows (Sun's OpenWindows complains when
70                           I do this, and I don't know why, and I don't care)
71 
72     DONT_CHECK_FOR_MWM = if this is set, then the program won't bother
73                           to check for the Motif Window Manager (MWM).
74                           This can be useful on Linux systems using FVWM,
75                           which won't be detected as MWM, but can be set up
76                           to act like it with regards to decorations, etc.
77 
78     BOXUP_SCALE = if this is set, then the slider for the functional
79                   threshold will have a "box" (Frame widget) drawn
80                   around it.  Some people think this looks nicer, some don't.
81 
82     NO_FRIVOLITIES = if this is set, then the hidden "fun" parts of
83                      AFNI are disabled.  What these are is a secret.
84 
85     DONT_USE_HINTS = if this is set, then the popup hints won't be
86                      compiled into AFNI.
87 
88     NEED_XSETLOCALE = if this is set, then the routine _Xsetlocale
89                       must be provided (needed for some Linux systems).
90 
91     NEED_NL_LANGINFO = if this is set, then the routine nl_langinfo()
92                        must be provided (need on Mac OS X)
93 
94     DONT_UNROLL_FFTS = if this is set, then the unrolled FFT routines
95                        (for lengths 32, 64, 128, 256) will NOT be used --
96                        they are generally faster, but may have trouble
97                        compiling on some systems [see file csfft.c].
98                        The program fftest.c can be used to test the
99                        speed of FFTs.
100 
101     SOLARIS_DIRENT_PATCH = if this is set, then a patch for the
102                            difference between Sun's "dirent" functions
103                            and everbody else's is used in the file
104                            mcw_glob.c -- this seems to be necessary
105                            on Solaris 2.6 systems in order to get the
106                            AFNI file reading software to work.
107                            (This patch was supplied by Christoph Losert
108                            of the Institut fuer Radiologische Diagnostik,
109                            Munchen, and has not been tested at MCW due to
110                            the absence of any Sun workstations to play with.)
111 
112     SOLARIS_DIRENT_ZERO  = if this is defined, the patch described above
113                            is modified slightly -- see mcw_glob.c for
114                            the gory details.  The patch above seems to
115                            be needed for Solaris 2.5.x and this modification
116                            is also needed for Solaris 2.6.x.
117                               [God, I hope this is the end of this ]
118                               [Solaris nightmare -- I'm sick of it!]
119 
120     USE_FLOCK = There are two incompatible ways of 'locking' a file
121     USE_LOCKF = on Unix: the flock() and lockf() functions.  Defining
122                 one of these will enable the use of the corresponding
123                 function.  If neither is defined, file locking will
124                 not be used.
125 
126     DONT_USE_SHM = Set this to disable use of shared memory.
127 
128     DISCARD_EXCESS_EXPOSES = Set this if a ConfigureNotify event is
129                              followed by an Expose event on your
130                              systems - this will eliminate duplicate
131                              image redraws in imseq.c.
132 
133   Exactly one of the following flags must be set for AFNI plugins
134   to work:
135 
136     DYNAMIC_LOADING_VIA_DL = if this is set, then loading of dynamic
137                              libraries is accomplished using the "dl"
138                              routines, such as "dlopen".  This is true
139                              for all Unixes that I know of, except for
140                              HP-UX.
141 
142     DYNAMIC_LOADING_VIA_SHL = if this is set, then loading of dynamic
143                               libraries is accomplished using the "shl"
144                               routines, such as "shl_load".  This is
145                               only used on HP-UX, as far as I know.
146 
147     NO_DYNAMIC_LOADING = if this is set, then AFNI will load the plugins
148                          statically - this means that you can't add plugins
149                          without recompiling AFNI;  this option has only
150                          been tested on CYGWIN, and requires a special Makefile.
151 
152     BAD_BUTTON3_POPUPS = if this is set, then Button-3 popup menus don't work
153                          and the program tries something else (i.e., Solaris).
154 
155   Flags that MUST be set appropriately for each system:
156 
157     THD_MMAP_FLAG = value to set when using "mmap" to map a file to memory
158                      (see man mmap to figure this one out)
159 
160     THD_MKDIR_MODE = flag to set creation mode for directories that might
161                       be created during dataset output (you can probably
162                       copy this from any other machine)
163 
164     NO_RINT = #define this if the system you are on doesn't have the
165               "rint" (round-to-integer) math function -- I don't know
166               of any system without this function, but you never can tell.
167 
168     DONT_USE_STRPTIME = #define this if your system doesn't have the
169                         C function strptime()
170 
171     USE_RANDOM = #define this if you want/have to use the srandom/random
172                  functions instead of the srand48/drand48 functions for
173                  random number generation. [not needed at this time :]
174 
175     DONT_USE_HTMLWIN = #define this if the 'AFNI Tips' HTML widget
176                        causes trouble on your system
177 
178     UNFONTIZE_HTMLWIN = #define this if the HTML widget works OK as
179                         long as font changes aren't ordered
180 
181     USE_FENV = #define this if you want to enable the randomization
182                of the floating-point rounding mode in this compilation
183 
184   Some systems need extra header files included.  Some system header
185   files don't give a prototype for alphasort.  This is a place to fix
186   these things up.
187 -------------------------------------------------------------------------*/
188 
189 #define DONT_USE_SCANDIR
190 #define DONT_UNROLL_FFTS  /* off by default */
191 #define FIX_SCALE_SIZE_PROBLEM
192 #define FIX_SCALE_SIZE_LATER
193 
194 #ifdef DT_UNKNOWN                 /** 07 Mar 2006: niftilib problem fix **/
195 # define QQDT_UNK DT_UNKNOWN
196 # undef  DT_UNKNOWN
197 #else
198 # undef  QQDT_UNK
199 #endif
200 
201 /*** HP-UX ***/
202 
203 #ifdef HP
204 # include <dirent.h>
205 # define THD_MMAP_FLAG  (MAP_FILE | MAP_VARIABLE | MAP_SHARED)
206 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
207 # define SCANDIR_WANTS_CONST
208 # define BOXUP_SCALE
209 # define DYNAMIC_LOADING_VIA_SHL
210 # undef  DONT_UNROLL_FFTS    /* FFTs are faster, but csfft.c compiles slowly */
211 # define USE_LOCKF
212 #endif
213 
214 /*** SGI IRIX ***/
215 
216 #if defined(SGI) || defined(OSF1) /*BUG: should have a separate OSF1 ifdef*/
217 # include <dirent.h>
218 # define THD_MMAP_FLAG  MAP_SHARED
219 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
220 # define BOXUP_SCALE
221 # define DYNAMIC_LOADING_VIA_DL
222 # ifndef DONT_USE_SCANDIR
223     extern int alphasort(struct dirent **, struct dirent **) ;
224 # endif
225 # undef  DONT_UNROLL_FFTS         /* helps some */
226 # define USE_FLOCK
227 #endif
228 
229 /*** SunOS or Solaris ***/
230 
231 #ifdef SPARKY
232 # include <sys/dirent.h>
233 # define THD_MMAP_FLAG  (MAP_SHARED | MAP_NORESERVE)
234 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
235 # define DONT_INSTALL_ICONS
236 # define NO_FRIVOLITIES
237 # ifndef DONT_USE_SCANDIR
238     extern int alphasort(struct dirent **, struct dirent **) ;
239 # endif
240 
241 extern double strtod() ;
242 extern long   strtol() ;
243 
244 /**
245 #ifndef S_IFREG
246 #  define S_IFREG _IFREG
247 # endif
248 # ifndef S_IFDIR
249 #  define S_IFDIR _IFDIR
250 # endif
251 **/
252 #endif
253 
254 #if defined(SOLARIS) || defined(SUN)
255 # include <sys/types.h>
256 # ifndef DONT_USE_SCANDIR
257 #   include <sys/dir.h>
258     extern int alphasort(struct dirent **, struct dirent **) ;
259 # endif
260 # define THD_MMAP_FLAG  (MAP_SHARED | MAP_NORESERVE)
261 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
262 # define dirent direct
263 # define DONT_INSTALL_ICONS
264 # define DYNAMIC_LOADING_VIA_DL
265 # define USE_LOCKF
266 # define DONT_USE_MATRIX_MAT  /* 04 Mar 2005 */
267 # undef  DONT_USE_HTMLWIN     /* 08 Jul 2011 */
268 # define UNFONTIZE_HTMLWIN    /* 08 Jul 2011 */
269 
270 
271 #ifdef SOLARIS_OLD            /* 03 Feb 2009 [rickr] */
272 # define fabsf  fabs          /* 09 Jul 2007 */
273 # define sqrtf  sqrt          /* to deal with lameness of Solaris */
274 # define cbrtf  cbrt
275 # define logf   log
276 # define powf   pow
277 # define sinf   sin
278 # define cosf   cos
279 # define asinf  asin
280 # define acosf  acos
281 # define floorf floor
282 # define ceilf  ceil
283 # define expf   exp
284 # define atanhf atanh         /* 27 Jul 2009 [rickr] */
285 # define atan2f atan2         /* 24 Aug 2009 [RWCox] */
286 # define tanhf  tanh          /* 20 Oct 2009 [RWCox] */
287 # define rintf  rint          /* 16 Dec 2009 [RWCox] */
288 
289 #endif
290 
291 #endif
292 
293 /*** IBM RS6000 courtesy Doug Morris of UIUC ***/
294 
295 #ifdef RS6000
296 # include <dirent.h>
297 # define THD_MMAP_FLAG  MAP_SHARED
298 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
299 # ifndef DONT_USE_SCANDIR
300     extern int alphasort(struct dirent **, struct dirent **) ;
301 # endif
302 #endif
303 
304 /*** Linux 1.2.x ***/
305 
306 #ifdef LINUX2
307 # define NEED_XSETLOCALE
308 # ifndef LINUX
309 #   define LINUX
310 # endif
311 #endif
312 
313 #if defined(LINUX) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD)
314 # include <dirent.h>
315 # define THD_MMAP_FLAG  MAP_SHARED
316 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
317 # define SCANDIR_WANTS_CONST
318 /* # define MMAP_THRESHOLD -1 */       /* no mmap-ing */
319 # define DONT_CHECK_FOR_MWM       /* assume Motif WM functionality is present */
320 # define BOXUP_SCALE              /* looks nicer */
321 # define DYNAMIC_LOADING_VIA_DL
322 # undef  DONT_UNROLL_FFTS         /* helps a lot */
323 # define USE_FLOCK
324 #endif
325 
326 #ifdef CYGWIN
327 # include <dirent.h>
328 # define THD_MMAP_FLAG  MAP_SHARED
329 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
330 # define SCANDIR_WANTS_CONST
331 # define MMAP_THRESHOLD -1        /* no mmap-ing */
332 # define DONT_CHECK_FOR_MWM       /* assume Motif WM functionality is present */
333 /**# define BOXUP_SCALE**/              /* looks nicer */
334 # define NO_DYNAMIC_LOADING
335 # undef  DONT_UNROLL_FFTS         /* helps a lot */
336 # define DONT_USE_STRPTIME
337 # define NO_FRIVOLITIES
338 # define USING_LESSTIF            /* try to avoid some bugs */
339 #endif
340 
341 /* SCO UDK under Unixware 7 -- contributed by Jason Bacon */
342 #ifdef SCO
343 # include <dirent.h>
344 # define THD_MMAP_FLAG  MAP_SHARED
345 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
346 # define SCANDIR_WANTS_CONST
347 /* # define MMAP_THRESHOLD -1 */       /* no mmap-ing */
348 # define DONT_CHECK_FOR_MWM       /* assume Motif WM functionality is present */
349 # define BOXUP_SCALE              /* looks nicer */
350 # define DYNAMIC_LOADING_VIA_DL
351 # undef  DONT_UNROLL_FFTS         /* helps a lot */
352 #endif
353 
354 /* Mac OSX (Darwin) */
355 #ifdef DARWIN
356 # include <dirent.h>
357 # define THD_MMAP_FLAG  MAP_SHARED
358 # define THD_MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
359 # define SCANDIR_WANTS_CONST
360 /* # define MMAP_THRESHOLD -1 */       /* no mmap-ing */
361 #if 0
362 # define DONT_CHECK_FOR_MWM       /* assume Motif WM functionality is present */
363 #endif
364 # define BOXUP_SCALE              /* looks nicer */
365 # define DYNAMIC_LOADING_VIA_DL
366 # undef  DONT_UNROLL_FFTS
367 # define USE_FLOCK
368 #if 0
369 # define USE_RANDOM
370 #endif
371 # define DONT_USE_STRPTIME
372 /** # define NEED_XSETLOCALE **/  /* removed on 16 May 2005, for Tiger */
373 # define NEED_NL_LANGINFO
374 # define USE_SYSCTL               /* 02 Aug 2016 */
375 #endif
376 
377 /************************************************************************
378    Do NOT change anything below this line (unless your name is Cox)!
379 *************************************************************************/
380 
381 #ifdef QQDT_UNK                   /** 07 Mar 2006 **/
382 # undef  DT_UNKNOWN
383 # define DT_UNKNOWN QQDT_UNK
384 # undef  QQDT_UNK
385 #endif
386 
387 # define DISCARD_EXCESS_EXPOSES   /* 15 Aug 2002 */
388 
389 #if defined(DYNAMIC_LOADING_VIA_DL) || defined(DYNAMIC_LOADING_VIA_SHL) || defined(NO_DYNAMIC_LOADING)
390 #  define ALLOW_PLUGINS
391 #else
392 #  define DONT_ALLOW_PLUGINS
393 #endif
394 
395 #ifdef NO_RINT
396 extern double rint(double) ;  /* 12 Feb 2001 */
397 #endif
398 
399 #ifdef USE_RANDOM             /* 04 Sep 2001 (cf. machdep.c) */
400 extern void srand48(long int);
401 extern double drand48(void);
402 extern long int lrand48(void);
403 #endif
404 
405 #ifdef NO_GAMMA               /* 16 May 2005 (cf. machdep.c) */
406 extern double lgamma(double) ;
407 #endif
408 
409 extern char * Random_Insult(void) ;
410 extern void init_rand_seed( long int seed ) ; /* 15 Apr 2009 (cf machdep.c) */
411 #undef  SET_RAND_SEED
412 #define SET_RAND_SEED init_rand_seed(0)
413 
414 extern int machdep_be_quiet(void) ;  /* 08 Dec 2010 */
415 extern char * GetAfniWebBrowser(void);
416 extern char * GetAfniWebDownloader(void);
417 extern char * GetAfniPDFViewer(void);
418 extern char * GetAfniImageViewer(void);
419 extern char * GetAfniTextEditor(void);
420 extern char * AFNI_strcasestr(const char *s1, const char *s2);
421 
422 #ifndef strcasestr
423 #define strcasestr AFNI_strcasestr  /* replacement [24 Jun 2020] */
424 #endif
425 
426 extern void AFNI_do_nothing(void) ;
427 
428 extern int     AFNI_get_ncpu(void) ;    /* 11 Feb 2016 */
429 extern int64_t AFNI_get_memsize(void) ; /* 02 Aug 2016 */
430 
431 /*--------- stuff for changing floating point rounding mode ---------*/
432 /* Macro RAND_ROUND will randomize the rounding method if USE_FENV
433    is enabled at compile time; otherwise, these things do nothing! --*/
434 
435 #ifdef USE_FENV
436 extern void change_rounding( int lll ) ; /* 25 Feb 2020 */
437 extern void change_rounding_random(void) ;
438 # define RAND_ROUND change_rounding_random()  /* macro for easy use */
439 # define TONEAREST_ROUND  change_rounding(0)
440 # define UPWARD_ROUND     change_rounding(1)
441 # define DOWNWARD_ROUND   change_rounding(2)
442 # define TOWARDZERO_ROUND change_rounding(3)
443 #else
444 # define change_rounding(lll) /*nada*/
445 # define RAND_ROUND           /*nada*/
446 # define TONEAREST_ROUND      /*nada*/
447 # define UPWARD_ROUND         /*nada*/
448 # define DOWNWARD_ROUND       /*nada*/
449 # define TOWARDZERO_ROUND     /*nada*/
450 #endif
451 /*-------------------------------------------------------------------*/
452 
453 #endif /* _MCW_MACHDEP_ */
454