/[ascend]/trunk/base/generic/utilities/ascConfig.h
ViewVC logotype

Contents of /trunk/base/generic/utilities/ascConfig.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 495 - (show annotations) (download) (as text)
Tue Apr 18 07:25:04 2006 UTC (18 years, 2 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13739 byte(s)
Still trying to get the Lionux build working again. I think it's still broken.
1 /* ASCEND modelling environment
2 Copyright (C) 1997 Carnegie Mellon University
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 @file
21 Global configuration parameters.
22
23 This module defines the fundamental constants used by the rest of
24 Ascend and pulls in system headers.
25 There is not corresponding compiler.c. The variables
26 declared in this header are defined in ascParse.y.
27
28 This header and tcl/tk headers are known to conflict. This header
29 should be included AFTER tcl.h or tk.h, not before.
30
31 If including the file, you should also include utilities/error.h
32 *//*
33 by Mark Thomas
34 Version: $Revision: 1.12 $
35 Version control file: $RCSfile: ascConfig.h,v $
36 Date last modified: $Date: 2003/08/23 18:43:13 $
37 Last modified by: $Author: ballan $
38 */
39
40 #ifndef ASC_ASCCONFIG_H
41 #define ASC_ASCCONFIG_H
42
43 #ifndef ASC_BUILDING_INTERFACE
44 # define ASC_BUILDING_LIBASCEND
45 #endif
46
47
48 /*
49 *
50 * Determine the Operating System we are building on
51 *
52 */
53
54 /* windows */
55 #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
56 # ifndef __WIN32__
57 # define __WIN32__
58 # endif
59 #endif
60
61 #ifdef __alpha
62 /** DEC Alpha running OSF */
63 # define __ALPHA_OSF__
64 #endif /* __alpha */
65
66 #ifdef __hpux
67 /** HP running HP-UX */
68 # define __HPUX__
69 #endif /* __hpux */
70
71 #ifdef _AIX
72 /** IBM RS6000 or PowerPC running AIX */
73 # define __IBM_AIX__
74 #endif /* _AIX */
75
76 #ifdef __sgi
77 /** SGI running IRIX */
78 # define __SGI_IRIX__
79 #endif /* __sgi */
80
81 #if defined(__sun) || defined(sun)
82 # ifdef __SVR4
83 /** Sparc running Solaris 2.x (SunOS 5.x) */
84 # define __SUN_SOLARIS__
85 # else /* __SVR4 */
86 /** Sparc running SunOS 4.x (Solaris 1.x) */
87 # define __SUN_SUNOS__
88 # endif /* __SVR4 */
89 #endif /* __sun || sun */
90
91 /*
92 ASCEND code in base/generic only EXPORTS symbols, no imports.
93 The ASC_DLLSPEC macro will, depending on whether we are
94 ASC_BUILDING_LIBASCEND (building libascend.so aka ascend.dll)
95 or ASC_BUILDING_INTERFACE (building for example _ascpy.dll or
96 ascendtcl.dll), act respectively to declare symbols as being
97 *exported* or *imported*.
98
99 New versions of GCC are able to make use of these declarations
100 as well.
101 */
102
103 #ifdef __GNUC__
104 #else
105 # ifdef __WIN32__
106 # define HAVE_DECLSPEC_DLL
107 # endif
108 #endif
109
110 #ifdef HAVE_DECLSPEC_DLL
111 # define ASC_EXPORT(TYPE) extern __declspec(dllexport) TYPE
112 # define ASC_IMPORT(TYPE) extern __declspec(dllimport) TYPE
113 #else
114 # define ASC_EXPORT(TYPE) extern TYPE
115 # define ASC_IMPORT(TYPE) extern TYPE
116 #endif
117
118 #ifdef ASC_BUILDING_LIBASCEND
119 # define ASC_DLLSPEC(TYPE) ASC_EXPORT(TYPE)
120 #else
121 # define ASC_DLLSPEC(TYPE) ASC_IMPORT(TYPE)
122 #endif
123
124 #if !defined(ASC_DLLSPEC) || !defined(ASC_EXPORT) || !defined(ASC_IMPORT)
125 # error "NO ASC_DLLSPEC DEFINED"
126 #endif
127
128 /*
129 An attempt to prevent unexported symbols from slipping through
130 the net when developing with GCC on linux:
131 */
132 /*
133 #if defined(__GNUC__) && __GNUC__ >= 4
134 # pragma GCC visibility push(hidden)
135 #endif
136 */
137
138 /**
139 What kind of C compiler do we have?
140
141 Use compiler flag -DDISABLE_C99 to force older ISO C
142 This means no variadic macros, maybe other things too.
143 */
144 #if defined(__STDC__) && defined(__STDC_VERSION__)
145 # if __STDC_VERSION__>=199901L
146 # ifndef DISABLE_C99
147 # define HAVE_C99
148 # endif
149 # endif
150 #endif
151
152 /*
153 * If we are in a tcl-infested file, define
154 * CONST84 to be empty for back-compatibility with
155 * tcl8.3
156 */
157 #ifdef TCL_VERSION
158 # ifndef CONST84
159 # define CONST84
160 # define QUIET(x) x
161 # define QUIET2(x) x
162 # else
163 /** use this macro to shut up const when const
164 from tcl-land would be going into non-tcl C.
165 */
166 # define QUIET(x) ((char *)x)
167 # define QUIET2(v) ((char **)v)
168 # endif
169 #endif
170
171 /*
172 * Make certain we have proper limits defined
173 */
174 #include <stdlib.h>
175 #include <limits.h>
176 #include <float.h>
177 #include <sys/types.h>
178 #ifdef _OSF_SOURCE
179 # include <sys/syslimits.h>
180 #endif
181 /* for use practically everywhere */
182 #include<stdio.h>
183
184
185 #if 0 /* there seems to be some confusion about the interaction of comment blocks and the preprocessor. there isn't any..., which means everything in this
186 if 0 block is broken. */
187
188 /* trying without this... */
189 #if defined(__WIN32__) && !defined(__MINGW32__)
190 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
191 # define WIN32_LEAN_AND_MEAN
192 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
193 # undef WIN32_LEAN_AND_MEAN
194 #endif
195 */
196 #endif /* 0 block needs fixing above */
197 #ifndef PATH_MAX
198 /** Normally will come from stdio.h or limits.h
199 * POSIX values of PATH_MAX is 255, traditional is 1023
200 */
201 # define PATH_MAX 1023
202 #endif
203
204 /* the following numbers should have come through limits.h */
205 #ifndef SHRT_MAX
206 # define SHRT_MAX 32767
207 #endif
208 #ifndef INT_MAX
209 # define INT_MAX 2147483647
210 /* 32 bit machines */
211 #endif
212 #ifndef LONG_MAX
213 # ifdef __alpha
214 # define LONG_MAX 9223372036854775807 /* 64 bit machines */
215 # else /* __alpha */
216 # define LONG_MAX 2147483647 /* 32 bit machines */
217 # endif /* __alpha */
218 #endif /* LONG_MAX */
219
220 #ifndef MAXDOUBLE
221 # define MAXDOUBLE DBL_MAX
222 #endif
223 #ifndef MAXINT
224 # define MAXINT INT_MAX
225 #endif
226 #ifndef MAXUINT
227 # define MAXUINT UINT_MAX
228 #endif
229 #ifndef MAXLONG
230 # define MAXLONG LONG_MAX
231 #endif
232 #ifndef MAXULONG
233 # define MAXULONG UILONG_MAX
234 #endif
235
236 /**
237 * The largest number of digits we'd ever expect to see in a single
238 * numeric value, * 3 or so for good measure.
239 */
240 #define MAXIMUM_NUMERIC_LENGTH 80
241
242 /*
243 * Useful Headers
244 */
245
246 /* for use by ascmalloc, which is also practically everywhere */
247 #include <stdio.h>
248 #include <assert.h>
249 #include <string.h>
250 /*
251 * #include <malloc.h>
252 *
253 * malloc() is defined in <stdlib.h> in ANSI-C
254 */
255
256 #define MAXTOKENLENGTH 1024 /**< Maximum token size.
257 Most significant for identifiers and strings */
258 #ifndef FALSE
259 # define FALSE 0
260 # define TRUE 1
261 #endif
262
263 #ifndef CONST
264 # define CONST const
265 #endif
266
267 #define VOIDPTR void *
268
269 /* Updated the following to use new Wiki URLS */
270 #define ASC_MILD_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
271 #define ASC_BIG_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
272
273 ASC_DLLSPEC(FILE*) g_ascend_errors; /**< File stream to receive error messages. */
274 ASC_DLLSPEC(FILE*) g_ascend_warnings; /**< File stream to receive warning messages. */
275 ASC_DLLSPEC(FILE*) g_ascend_information; /**< File stream to receive general messages. */
276
277 /* NB For error messages to be correctly captured, all output needs to go to stderr in error.h */
278 #ifndef ASCERR
279 # define ASCERR g_ascend_errors
280 # define ASCWAR g_ascend_warnings
281 # define ASCINF g_ascend_information
282 #endif
283 /*
284 * file pointers for whine. they default to stderr. if you change
285 * them, be sure to change them to valid files.
286 */
287
288 #define BYTESIZE 8
289 #define WORDSIZE (sizeof(unsigned)*BYTESIZE)
290 #ifndef TRUE
291 # define TRUE 1
292 #endif
293 #ifndef FALSE
294 # define FALSE 0
295 #endif
296 typedef char *POINTER; /**< Generic pointer. */
297 typedef char boolean; /**< Boolean type. */
298 typedef int ALIGN; /**< Data alignment. */
299 /**
300 * real64:
301 * change this typedef and all the solver code should change
302 * precision automatically. The code is predicated on 64bit ieee math.
303 * change the typedef as needed to get 64bit numbers. In particular
304 * crays may change this to float.
305 * int32:
306 * uint32;
307 * a 32bit int. change this typedef and all the solver code changes
308 * with it. may be of use for compiler which default int to 16bits
309 * equivalent to -i4 on most f77 compilers.
310 */
311 typedef double real64; /* a value */
312 typedef int int32; /**< a row/col/var/rel index number */
313 typedef unsigned uint32;
314
315
316 /**
317 * MAXREFCOUNT should always be defined to be the maximum value
318 * that the reference count attribute of reference count objects
319 * can take. It is unreasonable that a refcount be 64 bits, so
320 * it is 32.
321 */
322 #define MAXREFCOUNT UINT_MAX
323 #define REFCOUNT_T unsigned int
324
325 /*
326 * A bit of header magic to address the question of NULL being implementation
327 * defined, though virtually all systems of interest define it as 0 or 0L,
328 * if we are to claim ANSI conformance.
329 *
330 * IEEE 754 arithmetic implies all 0 bits <--> 0.0, so there isn't
331 * a problem where this is concerned. We have assumed ieee math.
332 *
333 * Notes to myself:
334 * Put this in base.h and suggest its insertion in
335 * compiler.h and perhaps interface1.h.
336 * Any place that calloc is being used to allocate arrays of NULL pointers,
337 * put a proper #if to replace it with a call to malloc and an appropriate
338 * NULLing function.
339 *
340 * Ben Allan, Jan 6, 1994.
341 */
342
343 /*
344 * NOTE: The below if works for 0 or 0L, which is to say I assume it
345 * works for 0 and I have tested that it works for 0L. Next we define
346 * the cheap versions of null testing for machine with 0 == NULL
347 *
348 * These are the proper ANSI C tests for NULL on 0!=NULL machines, should
349 * we ever run into them.
350 */
351 #ifdef NULL
352 /* ok, so the machine has a NULL defined. */
353 # ifndef ISNULL
354 /* and we've not got an ISNULL function */
355 # define ISNULL(a) ((a) == NULL)
356 # define NOTNULL(a) ((a) != NULL)
357 # endif /* ISNULL */
358 # endif /* NULL */
359
360 #ifndef NULL
361 # error "Null not defined by the time ascConfig.h seen"
362 #endif
363
364 #ifndef UNUSED_PARAMETER
365 /** Standardize the treatment of unreferenced function parameters. */
366 # define UNUSED_PARAMETER(p) (void)(p)
367 #endif
368
369 /* ASCEND assertion defines */
370 /** Exit status code for failed assertion. */
371 #define ASCERR_ASSERTION_FAILED 100
372 /*
373 * For now, asc_assert tied to NDEBUG just like regular assert.
374 * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
375 * gives us the ability to decouple from NDEBUG and leave
376 * assertions active in release code if desired.
377 */
378 #ifdef NDEBUG
379 /** If defined, asc_assert() will be removed from code. */
380 # define ASC_NO_ASSERTIONS
381 #endif
382
383 /*
384 *
385 * Platform specific fixes
386 *
387 */
388
389 #if defined(__WIN32__) && !defined(__MINGW32__)
390
391 /*
392 * use the ASCEND printf substitutes
393 */
394 # ifndef USE_ASC_PRINTF
395 # define USE_ASC_PRINTF
396 # endif /* USE_ASC_PRINTF */
397
398 /*
399 * build the Tk Console
400 */
401 # ifndef ASC_USE_TK_CONSOLE
402 # define ASC_USE_TK_CONSOLE
403 # endif /* ASC_USE_TK_CONSOLE */
404
405 #endif
406
407 /* use signals by default, but disable with configure. */
408 #ifdef ASC_NO_TRAPS
409 /** Don't use signals. */
410 # define NO_SIGNAL_TRAPS 1
411 #else
412 /** Use signals. */
413 # undef NO_SIGNAL_TRAPS
414 #endif
415
416 /*------------------------------------*
417 OUTPUT FILE* MAPPINGS
418
419 On Windows, we have to use these special Asc_Printf (etc)
420 routines in order that output can be captured correctly by the GUI.
421
422 On non-Windows platforms, allow error.h to
423 */
424 #ifdef USE_ASC_PRINTF
425 # define ASC_PRINTF Asc_Printf
426 # define ASC_FPRINTF Asc_FPrintf
427 # define ASC_VFPRINTF Asc_VFPrintf
428 # define ASC_FFLUSH Asc_FFlush
429 # define ASC_PUTC Asc_FPutc
430 # define ASC_FPUTC Asc_FPutc
431 # define ASC_PUTCHAR Asc_Putchar
432 # include <stdarg.h>
433 # include "utilities/ascPrint.h"
434 #else
435 # define ASC_PRINTF printf
436 # define ASC_FPRINTF fprintf
437 # define ASC_VFPRINTF vfprintf
438 # define ASC_FFLUSH fflush
439 # define ASC_PUTC putc
440 # define ASC_FPUTC fputc
441 # define ASC_PUTCHAR putchar
442 #endif
443
444 /* error.h will define handlers for
445 FPRINTF
446 FPUTC
447 FFLUSH
448 */
449 #ifdef IS_BINTOKEN_COMPILE
450 # define FPRINTF ASC_FPRINTF
451 # define FPUTC ASC_FPUTC
452 # define FFLUSH ASC_FFLUSH
453 #else
454 # include "utilities/error.h"
455 #endif
456
457 /* These are the remaining output macros that need to be mapped
458 */
459 #define PRINTF ASC_PRINTF
460 #define PUTCHAR ASC_PUTCHAR
461 /*------------------------------------*/
462
463
464 #ifndef __SUN_SUNOS__
465 /* do this for non-sun machines and for sun-solaris machines */
466 # ifndef roundup
467 # define rounddown(num,mod) ((num)-(num)%(mod))
468 # define roundup(num,mod) rounddown((num)+(mod)-1,(mod))
469 # define roundoff(num,mod) rounddown((num)+((mod)/2),(mod))
470 # endif /* roundup */
471 #endif /* __SUN_SUNOS__ */
472
473
474 /* These define integer divide and modulus mathematically correctly */
475 #define imod(num,den) ((num)%(den) + ((num)%(den)<0 ? (den) : 0))
476 #define idiv(num,den) ((num)/(den) + ((num)%(den)<0))
477 #define array_length(a) (sizeof(a)/sizeof((a)[0]))
478
479 /*
480 * the following patch up IEEE754isms that some systems can't seem to
481 * get right.
482 */
483 #define FPRESET (void)0
484 #ifdef __WIN32__
485 /* renamed in some __WIN32__ compiler systems */
486 # ifndef NO_RENAME_IEEE_FUNCTIONS
487 # undef finite
488 # define finite(x) _finite(x)
489 # undef isnan
490 # define isnan(x) _isnan(x)
491 # undef isinf
492 # define isinf(x) _isinf(x)
493 # endif
494 # undef FPRESET
495 # define FPRESET _fpreset()
496 /* MSVC peculiarities */
497 # ifdef _MSC_VER
498 # undef snprintf
499 # define snprintf _snprintf
500 # undef vsnprintf
501 # define vsnprintf _vsnprintf
502 # undef tempnam
503 # define tempnam _tempnam
504 # undef fdopen
505 # define fdopen _fdopen
506 # undef fileno
507 # define fileno _fileno
508 # undef getpid
509 # define getpid _getpid
510 # undef dup
511 # define dup _dup
512 # undef dup2
513 # define dup2 _dup2
514 # undef putenv
515 # define putenv _putenv
516 # endif
517 #endif /* __WIN32__ */
518
519 #ifdef __SUN_SUNOS__
520 /** not properly headered in math.h or ieee*.h */
521 extern int finite(double);
522 #endif
523
524 #endif /* ASC_ASCCONFIG_H */
525

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22