/[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 488 - (show annotations) (download) (as text)
Tue Apr 18 06:08:03 2006 UTC (18 years, 2 months ago) by wangym
File MIME type: text/x-chdr
File size: 13755 byte(s)
warning free for vc compile.
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 # define HAVE_DECLSPEC_DLL
105 #else
106 # ifdef __WIN32__
107 # define HAVE_DECLSPEC_DLL
108 # endif
109 #endif
110
111 #ifdef HAVE_DECLSPEC_DLL
112 # define ASC_EXPORT(TYPE) __declspec(dllexport) TYPE
113 # define ASC_IMPORT(TYPE) __declspec(dllimport) TYPE
114 #else
115 # define ASC_EXPORT(TYPE) TYPE
116 # define ASC_IMPORT(TYPE) TYPE
117 #endif
118
119 #ifdef ASC_BUILDING_LIBASCEND
120 # define ASC_DLLSPEC(TYPE) ASC_EXPORT(TYPE)
121 #else
122 # define ASC_DLLSPEC(TYPE) ASC_IMPORT(TYPE)
123 #endif
124
125 #if !defined(ASC_DLLSPEC) || !defined(ASC_EXPORT) || !defined(ASC_IMPORT)
126 # error "NO ASC_DLLSPEC DEFINED"
127 #endif
128
129 /*
130 An attempt to prevent unexported symbols from slipping through
131 the net when developing with GCC on linux:
132 */
133 #if defined(__GNUC__) && __GNUC__ >= 4
134 # pragma GCC visibility push(hidden)
135 #endif
136
137 /**
138 What kind of C compiler do we have?
139
140 Use compiler flag -DDISABLE_C99 to force older ISO C
141 This means no variadic macros, maybe other things too.
142 */
143 #if defined(__STDC__) && defined(__STDC_VERSION__)
144 # if __STDC_VERSION__>=199901L
145 # ifndef DISABLE_C99
146 # define HAVE_C99
147 # endif
148 # endif
149 #endif
150
151 /*
152 * If we are in a tcl-infested file, define
153 * CONST84 to be empty for back-compatibility with
154 * tcl8.3
155 */
156 #ifdef TCL_VERSION
157 # ifndef CONST84
158 # define CONST84
159 # define QUIET(x) x
160 # define QUIET2(x) x
161 # else
162 /** use this macro to shut up const when const
163 from tcl-land would be going into non-tcl C.
164 */
165 # define QUIET(x) ((char *)x)
166 # define QUIET2(v) ((char **)v)
167 # endif
168 #endif
169
170 /*
171 * Make certain we have proper limits defined
172 */
173 #include <stdlib.h>
174 #include <limits.h>
175 #include <float.h>
176 #include <sys/types.h>
177 #ifdef _OSF_SOURCE
178 # include <sys/syslimits.h>
179 #endif
180 /* for use practically everywhere */
181 #include<stdio.h>
182
183
184 #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
185 if 0 block is broken. */
186
187 /* trying without this... */
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 #endif /* 0 block needs fixing above */
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 <stdio.h>
247 #include <assert.h>
248 #include <string.h>
249 /*
250 * #include <malloc.h>
251 *
252 * malloc() is defined in <stdlib.h> in ANSI-C
253 */
254
255 #define MAXTOKENLENGTH 1024 /**< Maximum token size.
256 Most significant for identifiers and strings */
257 #ifndef FALSE
258 # define FALSE 0
259 # define TRUE 1
260 #endif
261
262 #ifndef CONST
263 # define CONST const
264 #endif
265
266 #define VOIDPTR void *
267
268 /* Updated the following to use new Wiki URLS */
269 #define ASC_MILD_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
270 #define ASC_BIG_BUGMAIL "https://pse.cheme.cmu.edu/wiki/view/Ascend/BugReport"
271
272 extern ASC_DLLSPEC(FILE*) g_ascend_errors; /**< File stream to receive error messages. */
273 extern ASC_DLLSPEC(FILE*) g_ascend_warnings; /**< File stream to receive warning messages. */
274 extern ASC_DLLSPEC(FILE*) g_ascend_information; /**< File stream to receive general messages. */
275
276 /* NB For error messages to be correctly captured, all output needs to go to stderr in error.h */
277 #ifndef ASCERR
278 # define ASCERR g_ascend_errors
279 # define ASCWAR g_ascend_warnings
280 # define ASCINF g_ascend_information
281 #endif
282 /*
283 * file pointers for whine. they default to stderr. if you change
284 * them, be sure to change them to valid files.
285 */
286
287 #define BYTESIZE 8
288 #define WORDSIZE (sizeof(unsigned)*BYTESIZE)
289 #ifndef TRUE
290 # define TRUE 1
291 #endif
292 #ifndef FALSE
293 # define FALSE 0
294 #endif
295 typedef char *POINTER; /**< Generic pointer. */
296 typedef char boolean; /**< Boolean type. */
297 typedef int ALIGN; /**< Data alignment. */
298 /**
299 * real64:
300 * change this typedef and all the solver code should change
301 * precision automatically. The code is predicated on 64bit ieee math.
302 * change the typedef as needed to get 64bit numbers. In particular
303 * crays may change this to float.
304 * int32:
305 * uint32;
306 * a 32bit int. change this typedef and all the solver code changes
307 * with it. may be of use for compiler which default int to 16bits
308 * equivalent to -i4 on most f77 compilers.
309 */
310 typedef double real64; /* a value */
311 typedef int int32; /**< a row/col/var/rel index number */
312 typedef unsigned uint32;
313
314
315 /**
316 * MAXREFCOUNT should always be defined to be the maximum value
317 * that the reference count attribute of reference count objects
318 * can take. It is unreasonable that a refcount be 64 bits, so
319 * it is 32.
320 */
321 #define MAXREFCOUNT UINT_MAX
322 #define REFCOUNT_T unsigned int
323
324 /*
325 * A bit of header magic to address the question of NULL being implementation
326 * defined, though virtually all systems of interest define it as 0 or 0L,
327 * if we are to claim ANSI conformance.
328 *
329 * IEEE 754 arithmetic implies all 0 bits <--> 0.0, so there isn't
330 * a problem where this is concerned. We have assumed ieee math.
331 *
332 * Notes to myself:
333 * Put this in base.h and suggest its insertion in
334 * compiler.h and perhaps interface1.h.
335 * Any place that calloc is being used to allocate arrays of NULL pointers,
336 * put a proper #if to replace it with a call to malloc and an appropriate
337 * NULLing function.
338 *
339 * Ben Allan, Jan 6, 1994.
340 */
341
342 /*
343 * NOTE: The below if works for 0 or 0L, which is to say I assume it
344 * works for 0 and I have tested that it works for 0L. Next we define
345 * the cheap versions of null testing for machine with 0 == NULL
346 *
347 * These are the proper ANSI C tests for NULL on 0!=NULL machines, should
348 * we ever run into them.
349 */
350 #ifdef NULL
351 /* ok, so the machine has a NULL defined. */
352 # ifndef ISNULL
353 /* and we've not got an ISNULL function */
354 # define ISNULL(a) ((a) == NULL)
355 # define NOTNULL(a) ((a) != NULL)
356 # endif /* ISNULL */
357 # endif /* NULL */
358
359 #ifndef NULL
360 # error "Null not defined by the time ascConfig.h seen"
361 #endif
362
363 #ifndef UNUSED_PARAMETER
364 /** Standardize the treatment of unreferenced function parameters. */
365 # define UNUSED_PARAMETER(p) (void)(p)
366 #endif
367
368 /* ASCEND assertion defines */
369 /** Exit status code for failed assertion. */
370 #define ASCERR_ASSERTION_FAILED 100
371 /*
372 * For now, asc_assert tied to NDEBUG just like regular assert.
373 * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
374 * gives us the ability to decouple from NDEBUG and leave
375 * assertions active in release code if desired.
376 */
377 #ifdef NDEBUG
378 /** If defined, asc_assert() will be removed from code. */
379 # define ASC_NO_ASSERTIONS
380 #endif
381
382 /*
383 *
384 * Platform specific fixes
385 *
386 */
387
388 #if defined(__WIN32__) && !defined(__MINGW32__)
389
390 /*
391 * use the ASCEND printf substitutes
392 */
393 # ifndef USE_ASC_PRINTF
394 # define USE_ASC_PRINTF
395 # endif /* USE_ASC_PRINTF */
396
397 /*
398 * build the Tk Console
399 */
400 # ifndef ASC_USE_TK_CONSOLE
401 # define ASC_USE_TK_CONSOLE
402 # endif /* ASC_USE_TK_CONSOLE */
403
404 #endif
405
406 /* use signals by default, but disable with configure. */
407 #ifdef ASC_NO_TRAPS
408 /** Don't use signals. */
409 # define NO_SIGNAL_TRAPS 1
410 #else
411 /** Use signals. */
412 # undef NO_SIGNAL_TRAPS
413 #endif
414
415 /*------------------------------------*
416 OUTPUT FILE* MAPPINGS
417
418 On Windows, we have to use these special Asc_Printf (etc)
419 routines in order that output can be captured correctly by the GUI.
420
421 On non-Windows platforms, allow error.h to
422 */
423 #ifdef USE_ASC_PRINTF
424 # define ASC_PRINTF Asc_Printf
425 # define ASC_FPRINTF Asc_FPrintf
426 # define ASC_VFPRINTF Asc_VFPrintf
427 # define ASC_FFLUSH Asc_FFlush
428 # define ASC_PUTC Asc_FPutc
429 # define ASC_FPUTC Asc_FPutc
430 # define ASC_PUTCHAR Asc_Putchar
431 # include <stdarg.h>
432 # include "utilities/ascPrint.h"
433 #else
434 # define ASC_PRINTF printf
435 # define ASC_FPRINTF fprintf
436 # define ASC_VFPRINTF vfprintf
437 # define ASC_FFLUSH fflush
438 # define ASC_PUTC putc
439 # define ASC_FPUTC fputc
440 # define ASC_PUTCHAR putchar
441 #endif
442
443 /* error.h will define handlers for
444 FPRINTF
445 FPUTC
446 FFLUSH
447 */
448 #ifdef IS_BINTOKEN_COMPILE
449 # define FPRINTF ASC_FPRINTF
450 # define FPUTC ASC_FPUTC
451 # define FFLUSH ASC_FFLUSH
452 #else
453 # include "utilities/error.h"
454 #endif
455
456 /* These are the remaining output macros that need to be mapped
457 */
458 #define PRINTF ASC_PRINTF
459 #define PUTCHAR ASC_PUTCHAR
460 /*------------------------------------*/
461
462
463 #ifndef __SUN_SUNOS__
464 /* do this for non-sun machines and for sun-solaris machines */
465 # ifndef roundup
466 # define rounddown(num,mod) ((num)-(num)%(mod))
467 # define roundup(num,mod) rounddown((num)+(mod)-1,(mod))
468 # define roundoff(num,mod) rounddown((num)+((mod)/2),(mod))
469 # endif /* roundup */
470 #endif /* __SUN_SUNOS__ */
471
472
473 /* These define integer divide and modulus mathematically correctly */
474 #define imod(num,den) ((num)%(den) + ((num)%(den)<0 ? (den) : 0))
475 #define idiv(num,den) ((num)/(den) + ((num)%(den)<0))
476 #define array_length(a) (sizeof(a)/sizeof((a)[0]))
477
478 /*
479 * the following patch up IEEE754isms that some systems can't seem to
480 * get right.
481 */
482 #define FPRESET (void)0
483 #ifdef __WIN32__
484 /* renamed in some __WIN32__ compiler systems */
485 # ifndef NO_RENAME_IEEE_FUNCTIONS
486 # undef finite
487 # define finite(x) _finite(x)
488 # undef isnan
489 # define isnan(x) _isnan(x)
490 # undef isinf
491 # define isinf(x) _isinf(x)
492 # endif
493 # undef FPRESET
494 # define FPRESET _fpreset()
495 /* MSVC peculiarities */
496 # ifdef _MSC_VER
497 # undef snprintf
498 # define snprintf _snprintf
499 # undef vsnprintf
500 # define vsnprintf _vsnprintf
501 # undef tempnam
502 # define tempnam _tempnam
503 # undef fdopen
504 # define fdopen _fdopen
505 # undef fileno
506 # define fileno _fileno
507 # undef getpid
508 # define getpid _getpid
509 # undef dup
510 # define dup _dup
511 # undef dup2
512 # define dup2 _dup2
513 # undef putenv
514 # define putenv _putenv
515 # endif
516 #endif /* __WIN32__ */
517
518 #ifdef __SUN_SUNOS__
519 /** not properly headered in math.h or ieee*.h */
520 extern int finite(double);
521 #endif
522
523 #endif /* ASC_ASCCONFIG_H */
524

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