/[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 777 - (show annotations) (download) (as text)
Tue Jul 18 04:40:08 2006 UTC (14 years, 3 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13771 byte(s)
Working on fixing a couple of VC++ warnings
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 Flag non-returning functions for GCC and Visual C++
142
143 Previously, see comments 'Needed to keep gcc from whining'
144 */
145 #ifdef __GNUC__ /* GCC */
146 # define NORETURN __attribute__((noreturn))
147 #elif defined(_MSC_VER) /* Visual C++ */
148 # define NORETURN __declspec(noreturn)
149 #else
150 # define NORETURN
151 #endif
152
153 /**
154 @TODO move the 'CONST84' stuff to a file in the TCL/TK section.
155 */
156 /*
157 * If we are in a tcl-infested file, define
158 * CONST84 to be empty for back-compatibility with
159 * tcl8.3
160 */
161 #ifdef TCL_VERSION
162 # ifndef CONST84
163 # define CONST84
164 # define QUIET(x) x
165 # define QUIET2(x) x
166 # else
167 /** use this macro to shut up const when const
168 from tcl-land would be going into non-tcl C.
169 */
170 # define QUIET(x) ((char *)x)
171 # define QUIET2(v) ((char **)v)
172 # endif
173 #endif
174
175 /*
176 * Make certain we have proper limits defined
177 */
178 #include <stdlib.h>
179 #include <limits.h>
180 #include <float.h>
181 #include <sys/types.h>
182 #ifdef _OSF_SOURCE
183 # include <sys/syslimits.h>
184 #endif
185 /* for use practically everywhere */
186 #include<stdio.h>
187
188
189 #if defined(__WIN32__) && !defined(__MINGW32__)
190 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
191 # define WIN32_LEAN_AND_MEAN
192 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
193 # undef WIN32_LEAN_AND_MEAN
194 #endif
195
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 ASC_DLLSPEC(FILE*) g_ascend_errors; /**< File stream to receive error messages. */
273 ASC_DLLSPEC(FILE*) g_ascend_warnings; /**< File stream to receive warning messages. */
274 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