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

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