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