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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 778 - (hide annotations) (download) (as text)
Tue Jul 18 05:10:03 2006 UTC (14 years, 3 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 johnpye 485 /* ASCEND modelling environment
2     Copyright (C) 1997 Carnegie Mellon University
3     Copyright (C) 2006 Carnegie Mellon University
4 johnpye 332
5 johnpye 485 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 johnpye 162 Global configuration parameters.
22 johnpye 485
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 johnpye 162 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 johnpye 332
31 johnpye 162 If including the file, you should also include utilities/error.h
32 johnpye 669
33     @NOTE you must include <tcl.h> BEFORE this file for it to work properly.
34 johnpye 485 *//*
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 aw0a 1
42 johnpye 67 #ifndef ASC_ASCCONFIG_H
43     #define ASC_ASCCONFIG_H
44 aw0a 1
45 johnpye 480 #ifndef ASC_BUILDING_INTERFACE
46     # define ASC_BUILDING_LIBASCEND
47     #endif
48    
49     /*
50 wangym 487 *
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 johnpye 480 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 johnpye 500 #ifdef __WIN32__
104 johnpye 507 # define ASC_EXPORT(TYPE) __declspec(dllexport) TYPE
105     # define ASC_IMPORT(TYPE) __declspec(dllimport) TYPE
106 johnpye 485 #else
107 johnpye 500 # ifdef HAVE_GCCVISIBILITY
108 johnpye 507 # define ASC_EXPORT(TYPE) __attribute__ ((visibility("default"))) TYPE
109     # define ASC_IMPORT(TYPE) TYPE
110 johnpye 500 # else
111 johnpye 507 # define ASC_EXPORT(TYPE) TYPE
112     # define ASC_IMPORT(TYPE) TYPE
113 johnpye 500 # endif
114 johnpye 485 #endif
115    
116     #ifdef ASC_BUILDING_LIBASCEND
117 johnpye 507 # define ASC_DLLSPEC(TYPE) extern ASC_EXPORT(TYPE)
118 johnpye 485 #else
119 johnpye 507 # define ASC_DLLSPEC(TYPE) extern ASC_IMPORT(TYPE)
120 johnpye 485 #endif
121    
122     #if !defined(ASC_DLLSPEC) || !defined(ASC_EXPORT) || !defined(ASC_IMPORT)
123 johnpye 480 # error "NO ASC_DLLSPEC DEFINED"
124     #endif
125    
126 johnpye 77 /**
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 johnpye 534 /**
141 johnpye 778 Define 'NORETURN' to the appropriate compiler-specific flags
142     for a function that never returns
143 johnpye 709 */
144 johnpye 778 #ifdef __GNUC__
145 johnpye 709 # define NORETURN __attribute__((noreturn))
146 johnpye 778 #elif defined(_MSC_VER)
147 johnpye 777 # define NORETURN __declspec(noreturn)
148 johnpye 709 #else
149 johnpye 778 # define NORETURN /* nothing */
150 johnpye 709 #endif
151    
152     /**
153 johnpye 534 @TODO move the 'CONST84' stuff to a file in the TCL/TK section.
154     */
155 aw0a 1 /*
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 johnpye 62 # ifndef CONST84
162     # define CONST84
163     # define QUIET(x) x
164     # define QUIET2(x) x
165     # else
166 aw0a 1 /** use this macro to shut up const when const
167     from tcl-land would be going into non-tcl C.
168     */
169 johnpye 62 # define QUIET(x) ((char *)x)
170     # define QUIET2(v) ((char **)v)
171     # endif
172 aw0a 1 #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 johnpye 62 # include <sys/syslimits.h>
183 aw0a 1 #endif
184 jds 40 /* for use practically everywhere */
185     #include<stdio.h>
186 aw0a 1
187 johnpye 332
188     #if defined(__WIN32__) && !defined(__MINGW32__)
189 ben.allan 423 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
190 johnpye 62 # define WIN32_LEAN_AND_MEAN
191 ben.allan 423 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
192 johnpye 62 # undef WIN32_LEAN_AND_MEAN
193 jds 40 #endif
194 johnpye 641
195 aw0a 1 #ifndef PATH_MAX
196 johnpye 332 /** Normally will come from stdio.h or limits.h
197     * POSIX values of PATH_MAX is 255, traditional is 1023
198 jds 54 */
199 johnpye 62 # define PATH_MAX 1023
200 aw0a 1 #endif
201    
202     /* the following numbers should have come through limits.h */
203     #ifndef SHRT_MAX
204 johnpye 62 # define SHRT_MAX 32767
205 aw0a 1 #endif
206     #ifndef INT_MAX
207 johnpye 62 # define INT_MAX 2147483647
208 aw0a 1 /* 32 bit machines */
209     #endif
210     #ifndef LONG_MAX
211 johnpye 62 # 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 aw0a 1 #endif /* LONG_MAX */
217    
218     #ifndef MAXDOUBLE
219 johnpye 62 # define MAXDOUBLE DBL_MAX
220 aw0a 1 #endif
221     #ifndef MAXINT
222 johnpye 62 # define MAXINT INT_MAX
223 aw0a 1 #endif
224     #ifndef MAXUINT
225 johnpye 62 # define MAXUINT UINT_MAX
226 aw0a 1 #endif
227     #ifndef MAXLONG
228 johnpye 62 # define MAXLONG LONG_MAX
229 aw0a 1 #endif
230     #ifndef MAXULONG
231 johnpye 62 # define MAXULONG UILONG_MAX
232 aw0a 1 #endif
233    
234 jds 54 /**
235     * The largest number of digits we'd ever expect to see in a single
236 aw0a 1 * 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 wangym 487 #include <stdio.h>
246 aw0a 1 #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 johnpye 332 #define MAXTOKENLENGTH 1024 /**< Maximum token size.
255 jds 54 Most significant for identifiers and strings */
256 aw0a 1 #ifndef FALSE
257 johnpye 62 # define FALSE 0
258     # define TRUE 1
259 aw0a 1 #endif
260    
261     #ifndef CONST
262 johnpye 62 # define CONST const
263 aw0a 1 #endif
264    
265     #define VOIDPTR void *
266    
267 johnpye 77 /* 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 aw0a 1
271 johnpye 492 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 johnpye 77
275     /* NB For error messages to be correctly captured, all output needs to go to stderr in error.h */
276 aw0a 1 #ifndef ASCERR
277 johnpye 62 # define ASCERR g_ascend_errors
278     # define ASCWAR g_ascend_warnings
279     # define ASCINF g_ascend_information
280 aw0a 1 #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 johnpye 62 # define TRUE 1
290 aw0a 1 #endif
291     #ifndef FALSE
292 johnpye 62 # define FALSE 0
293 aw0a 1 #endif
294 jds 54 typedef char *POINTER; /**< Generic pointer. */
295     typedef char boolean; /**< Boolean type. */
296     typedef int ALIGN; /**< Data alignment. */
297     /**
298 aw0a 1 * 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 jds 54 typedef int int32; /**< a row/col/var/rel index number */
311 aw0a 1 typedef unsigned uint32;
312    
313    
314 jds 54 /**
315 aw0a 1 * 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 jds 54 #define REFCOUNT_T unsigned int
322 aw0a 1
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 johnpye 62 # ifndef ISNULL
352 aw0a 1 /* and we've not got an ISNULL function */
353 johnpye 62 # define ISNULL(a) ((a) == NULL)
354     # define NOTNULL(a) ((a) != NULL)
355     # endif /* ISNULL */
356     # endif /* NULL */
357 aw0a 1
358 ben.allan 45 #ifndef NULL
359 johnpye 62 # error "Null not defined by the time ascConfig.h seen"
360 ben.allan 45 #endif
361 aw0a 1
362 jds 54 #ifndef UNUSED_PARAMETER
363 jds 47 /** Standardize the treatment of unreferenced function parameters. */
364 johnpye 62 # define UNUSED_PARAMETER(p) (void)(p)
365 jds 47 #endif
366 aw0a 1
367 jds 59 /* ASCEND assertion defines */
368     /** Exit status code for failed assertion. */
369     #define ASCERR_ASSERTION_FAILED 100
370 johnpye 332 /*
371 jds 59 * For now, asc_assert tied to NDEBUG just like regular assert.
372     * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
373 johnpye 332 * gives us the ability to decouple from NDEBUG and leave
374 jds 59 * assertions active in release code if desired.
375     */
376     #ifdef NDEBUG
377     /** If defined, asc_assert() will be removed from code. */
378 johnpye 62 # define ASC_NO_ASSERTIONS
379 jds 59 #endif
380    
381 aw0a 1 /*
382     *
383     * Platform specific fixes
384     *
385     */
386    
387 johnpye 332 #if defined(__WIN32__) && !defined(__MINGW32__)
388 aw0a 1
389     /*
390     * use the ASCEND printf substitutes
391     */
392 johnpye 62 # ifndef USE_ASC_PRINTF
393     # define USE_ASC_PRINTF
394     # endif /* USE_ASC_PRINTF */
395 aw0a 1
396     /*
397     * build the Tk Console
398     */
399 johnpye 62 # ifndef ASC_USE_TK_CONSOLE
400 johnpye 332 # define ASC_USE_TK_CONSOLE
401 johnpye 62 # endif /* ASC_USE_TK_CONSOLE */
402 aw0a 1
403 johnpye 332 #endif
404    
405 jds 59 /* use signals by default, but disable with configure. */
406 ben.allan 14 #ifdef ASC_NO_TRAPS
407 jds 54 /** Don't use signals. */
408 johnpye 62 # define NO_SIGNAL_TRAPS 1
409 ben.allan 14 #else
410 jds 59 /** Use signals. */
411 johnpye 62 # undef NO_SIGNAL_TRAPS
412 ben.allan 14 #endif
413 aw0a 1
414 johnpye 62 /*------------------------------------*
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 johnpye 332 On non-Windows platforms, allow error.h to
421 johnpye 62 */
422 aw0a 1 #ifdef USE_ASC_PRINTF
423 johnpye 62 # 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 aw0a 1
442 johnpye 62 /* error.h will define handlers for
443     FPRINTF
444     FPUTC
445     FFLUSH
446     */
447 johnpye 162 #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 aw0a 1
455 johnpye 62 /* These are the remaining output macros that need to be mapped
456     */
457     #define PRINTF ASC_PRINTF
458     #define PUTCHAR ASC_PUTCHAR
459     /*------------------------------------*/
460 aw0a 1
461 johnpye 62
462 aw0a 1 #ifndef __SUN_SUNOS__
463     /* do this for non-sun machines and for sun-solaris machines */
464 johnpye 62 # 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 aw0a 1 #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 jds 48 #define FPRESET (void)0
482 aw0a 1 #ifdef __WIN32__
483 jds 55 /* renamed in some __WIN32__ compiler systems */
484     # ifndef NO_RENAME_IEEE_FUNCTIONS
485     # undef finite
486 jds 47 # define finite(x) _finite(x)
487 jds 55 # undef isnan
488     # define isnan(x) _isnan(x)
489     # undef isinf
490     # define isinf(x) _isinf(x)
491 jds 47 # endif
492     # undef FPRESET
493     # define FPRESET _fpreset()
494 jds 97 /* MSVC peculiarities */
495     # ifdef _MSC_VER
496     # undef snprintf
497     # define snprintf _snprintf
498     # undef vsnprintf
499     # define vsnprintf _vsnprintf
500 jds 216 # 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 jds 97 # endif
515 jds 48 #endif /* __WIN32__ */
516 aw0a 1
517     #ifdef __SUN_SUNOS__
518 johnpye 62 /** not properly headered in math.h or ieee*.h */
519     extern int finite(double);
520 aw0a 1 #endif
521    
522 johnpye 67 #endif /* ASC_ASCCONFIG_H */
523 aw0a 1

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