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

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