/[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 778 - (show annotations) (download) (as text)
Tue Jul 18 05:10:03 2006 UTC (13 years, 6 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13741 byte(s)
Working to fix the 'NORETURN' stuff so that it works on both MSVC++ and GCC and fails
gracefully elsewhere.
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 <limits.h>
179 #include <float.h>
180 #include <sys/types.h>
181 #ifdef _OSF_SOURCE
182 # include <sys/syslimits.h>
183 #endif
184 /* for use practically everywhere */
185 #include<stdio.h>
186
187
188 #if defined(__WIN32__) && !defined(__MINGW32__)
189 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
190 # define WIN32_LEAN_AND_MEAN
191 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
192 # undef WIN32_LEAN_AND_MEAN
193 #endif
194
195 #ifndef PATH_MAX
196 /** Normally will come from stdio.h or limits.h
197 * POSIX values of PATH_MAX is 255, traditional is 1023
198 */
199 # define PATH_MAX 1023
200 #endif
201
202 /* the following numbers should have come through limits.h */
203 #ifndef SHRT_MAX
204 # define SHRT_MAX 32767
205 #endif
206 #ifndef INT_MAX
207 # define INT_MAX 2147483647
208 /* 32 bit machines */
209 #endif
210 #ifndef LONG_MAX
211 # ifdef __alpha
212 # define LONG_MAX 9223372036854775807 /* 64 bit machines */
213 # else /* __alpha */
214 # define LONG_MAX 2147483647 /* 32 bit machines */
215 # endif /* __alpha */
216 #endif /* LONG_MAX */
217
218 #ifndef MAXDOUBLE
219 # define MAXDOUBLE DBL_MAX
220 #endif
221 #ifndef MAXINT
222 # define MAXINT INT_MAX
223 #endif
224 #ifndef MAXUINT
225 # define MAXUINT UINT_MAX
226 #endif
227 #ifndef MAXLONG
228 # define MAXLONG LONG_MAX
229 #endif
230 #ifndef MAXULONG
231 # define MAXULONG UILONG_MAX
232 #endif
233
234 /**
235 * The largest number of digits we'd ever expect to see in a single
236 * numeric value, * 3 or so for good measure.
237 */
238 #define MAXIMUM_NUMERIC_LENGTH 80
239
240 /*
241 * Useful Headers
242 */
243
244 /* for use by ascmalloc, which is also practically everywhere */
245 #include <stdio.h>
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 /* Updated the following to use new Wiki URLS */
268 #define ASC_MILD_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
269 #define ASC_BIG_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
270
271 ASC_DLLSPEC(FILE*) g_ascend_errors; /**< File stream to receive error messages. */
272 ASC_DLLSPEC(FILE*) g_ascend_warnings; /**< File stream to receive warning messages. */
273 ASC_DLLSPEC(FILE*) g_ascend_information; /**< File stream to receive general messages. */
274
275 /* NB For error messages to be correctly captured, all output needs to go to stderr in error.h */
276 #ifndef ASCERR
277 # define ASCERR g_ascend_errors
278 # define ASCWAR g_ascend_warnings
279 # define ASCINF g_ascend_information
280 #endif
281 /*
282 * file pointers for whine. they default to stderr. if you change
283 * them, be sure to change them to valid files.
284 */
285
286 #define BYTESIZE 8
287 #define WORDSIZE (sizeof(unsigned)*BYTESIZE)
288 #ifndef TRUE
289 # define TRUE 1
290 #endif
291 #ifndef FALSE
292 # define FALSE 0
293 #endif
294 typedef char *POINTER; /**< Generic pointer. */
295 typedef char boolean; /**< Boolean type. */
296 typedef int ALIGN; /**< Data alignment. */
297 /**
298 * real64:
299 * change this typedef and all the solver code should change
300 * precision automatically. The code is predicated on 64bit ieee math.
301 * change the typedef as needed to get 64bit numbers. In particular
302 * crays may change this to float.
303 * int32:
304 * uint32;
305 * a 32bit int. change this typedef and all the solver code changes
306 * with it. may be of use for compiler which default int to 16bits
307 * equivalent to -i4 on most f77 compilers.
308 */
309 typedef double real64; /* a value */
310 typedef int int32; /**< a row/col/var/rel index number */
311 typedef unsigned uint32;
312
313
314 /**
315 * MAXREFCOUNT should always be defined to be the maximum value
316 * that the reference count attribute of reference count objects
317 * can take. It is unreasonable that a refcount be 64 bits, so
318 * it is 32.
319 */
320 #define MAXREFCOUNT UINT_MAX
321 #define REFCOUNT_T unsigned int
322
323 /*
324 * A bit of header magic to address the question of NULL being implementation
325 * defined, though virtually all systems of interest define it as 0 or 0L,
326 * if we are to claim ANSI conformance.
327 *
328 * IEEE 754 arithmetic implies all 0 bits <--> 0.0, so there isn't
329 * a problem where this is concerned. We have assumed ieee math.
330 *
331 * Notes to myself:
332 * Put this in base.h and suggest its insertion in
333 * compiler.h and perhaps interface1.h.
334 * Any place that calloc is being used to allocate arrays of NULL pointers,
335 * put a proper #if to replace it with a call to malloc and an appropriate
336 * NULLing function.
337 *
338 * Ben Allan, Jan 6, 1994.
339 */
340
341 /*
342 * NOTE: The below if works for 0 or 0L, which is to say I assume it
343 * works for 0 and I have tested that it works for 0L. Next we define
344 * the cheap versions of null testing for machine with 0 == NULL
345 *
346 * These are the proper ANSI C tests for NULL on 0!=NULL machines, should
347 * we ever run into them.
348 */
349 #ifdef NULL
350 /* ok, so the machine has a NULL defined. */
351 # ifndef ISNULL
352 /* and we've not got an ISNULL function */
353 # define ISNULL(a) ((a) == NULL)
354 # define NOTNULL(a) ((a) != NULL)
355 # endif /* ISNULL */
356 # endif /* NULL */
357
358 #ifndef NULL
359 # error "Null not defined by the time ascConfig.h seen"
360 #endif
361
362 #ifndef UNUSED_PARAMETER
363 /** Standardize the treatment of unreferenced function parameters. */
364 # define UNUSED_PARAMETER(p) (void)(p)
365 #endif
366
367 /* ASCEND assertion defines */
368 /** Exit status code for failed assertion. */
369 #define ASCERR_ASSERTION_FAILED 100
370 /*
371 * For now, asc_assert tied to NDEBUG just like regular assert.
372 * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
373 * gives us the ability to decouple from NDEBUG and leave
374 * assertions active in release code if desired.
375 */
376 #ifdef NDEBUG
377 /** If defined, asc_assert() will be removed from code. */
378 # define ASC_NO_ASSERTIONS
379 #endif
380
381 /*
382 *
383 * Platform specific fixes
384 *
385 */
386
387 #if defined(__WIN32__) && !defined(__MINGW32__)
388
389 /*
390 * use the ASCEND printf substitutes
391 */
392 # ifndef USE_ASC_PRINTF
393 # define USE_ASC_PRINTF
394 # endif /* USE_ASC_PRINTF */
395
396 /*
397 * build the Tk Console
398 */
399 # ifndef ASC_USE_TK_CONSOLE
400 # define ASC_USE_TK_CONSOLE
401 # endif /* ASC_USE_TK_CONSOLE */
402
403 #endif
404
405 /* use signals by default, but disable with configure. */
406 #ifdef ASC_NO_TRAPS
407 /** Don't use signals. */
408 # define NO_SIGNAL_TRAPS 1
409 #else
410 /** Use signals. */
411 # undef NO_SIGNAL_TRAPS
412 #endif
413
414 /*------------------------------------*
415 OUTPUT FILE* MAPPINGS
416
417 On Windows, we have to use these special Asc_Printf (etc)
418 routines in order that output can be captured correctly by the GUI.
419
420 On non-Windows platforms, allow error.h to
421 */
422 #ifdef USE_ASC_PRINTF
423 # define ASC_PRINTF Asc_Printf
424 # define ASC_FPRINTF Asc_FPrintf
425 # define ASC_VFPRINTF Asc_VFPrintf
426 # define ASC_FFLUSH Asc_FFlush
427 # define ASC_PUTC Asc_FPutc
428 # define ASC_FPUTC Asc_FPutc
429 # define ASC_PUTCHAR Asc_Putchar
430 # include <stdarg.h>
431 # include "utilities/ascPrint.h"
432 #else
433 # define ASC_PRINTF printf
434 # define ASC_FPRINTF fprintf
435 # define ASC_VFPRINTF vfprintf
436 # define ASC_FFLUSH fflush
437 # define ASC_PUTC putc
438 # define ASC_FPUTC fputc
439 # define ASC_PUTCHAR putchar
440 #endif
441
442 /* error.h will define handlers for
443 FPRINTF
444 FPUTC
445 FFLUSH
446 */
447 #ifdef IS_BINTOKEN_COMPILE
448 # define FPRINTF ASC_FPRINTF
449 # define FPUTC ASC_FPUTC
450 # define FFLUSH ASC_FFLUSH
451 #else
452 # include "utilities/error.h"
453 #endif
454
455 /* These are the remaining output macros that need to be mapped
456 */
457 #define PRINTF ASC_PRINTF
458 #define PUTCHAR ASC_PUTCHAR
459 /*------------------------------------*/
460
461
462 #ifndef __SUN_SUNOS__
463 /* do this for non-sun machines and for sun-solaris machines */
464 # ifndef roundup
465 # define rounddown(num,mod) ((num)-(num)%(mod))
466 # define roundup(num,mod) rounddown((num)+(mod)-1,(mod))
467 # define roundoff(num,mod) rounddown((num)+((mod)/2),(mod))
468 # endif /* roundup */
469 #endif /* __SUN_SUNOS__ */
470
471
472 /* These define integer divide and modulus mathematically correctly */
473 #define imod(num,den) ((num)%(den) + ((num)%(den)<0 ? (den) : 0))
474 #define idiv(num,den) ((num)/(den) + ((num)%(den)<0))
475 #define array_length(a) (sizeof(a)/sizeof((a)[0]))
476
477 /*
478 * the following patch up IEEE754isms that some systems can't seem to
479 * get right.
480 */
481 #define FPRESET (void)0
482 #ifdef __WIN32__
483 /* renamed in some __WIN32__ compiler systems */
484 # ifndef NO_RENAME_IEEE_FUNCTIONS
485 # undef finite
486 # define finite(x) _finite(x)
487 # undef isnan
488 # define isnan(x) _isnan(x)
489 # undef isinf
490 # define isinf(x) _isinf(x)
491 # endif
492 # undef FPRESET
493 # define FPRESET _fpreset()
494 /* MSVC peculiarities */
495 # ifdef _MSC_VER
496 # undef snprintf
497 # define snprintf _snprintf
498 # undef vsnprintf
499 # define vsnprintf _vsnprintf
500 # undef tempnam
501 # define tempnam _tempnam
502 # undef fdopen
503 # define fdopen _fdopen
504 # undef fileno
505 # define fileno _fileno
506 # undef getpid
507 # define getpid _getpid
508 # undef dup
509 # define dup _dup
510 # undef dup2
511 # define dup2 _dup2
512 # undef putenv
513 # define putenv _putenv
514 # endif
515 #endif /* __WIN32__ */
516
517 #ifdef __SUN_SUNOS__
518 /** not properly headered in math.h or ieee*.h */
519 extern int finite(double);
520 #endif
521
522 #endif /* ASC_ASCCONFIG_H */
523

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