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