/[ascend]/trunk/ascend/general/platform.h
ViewVC logotype

Contents of /trunk/ascend/general/platform.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2326 - (show annotations) (download) (as text)
Tue Dec 21 11:35:07 2010 UTC (11 years, 6 months ago) by jpye
File MIME type: text/x-chdr
File size: 14354 byte(s)
Comment out some disused functions and variables (reverse_ad.c, cmslv.c, relation.c).
Add comments about ascConfig.h->platform.h rename.
Address some compiler warnings with minor code changes in ospath and importhandler.
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 Platform-specific configuration parameters. This file has been renamed
22 from 'ascConfig.h', and moved from the 'utilities' folder to this one.
23 The main reason was because there is another file called 'config.h' which
24 performs closer to the classical Autotools 'config.h' function in ASCEND.
25 This file is more involved with platform-specific #includes and setting
26 various preprocessor constants, hence the name. However, the name is not
27 ideal, maybe we can call it something better eventually.
28
29 This module defines the fundamental constants used by the rest of
30 ASCEND and pulls in some platform-specific system headers where needed.
31 There is no corresponding platform.c.
32
33 The file also defines some global variables. Naughty, naughty.
34
35 This file also includes utilities/error.h, which we would like to avoid.
36
37 @TODO refactor this file to remove global variables and typedefs.
38 *//*
39 by Mark Thomas
40 Version: $Revision: 1.12 $
41 Version control file: $RCSfile: ascConfig.h,v $
42 Date last modified: $Date: 2003/08/23 18:43:13 $
43 Last modified by: $Author: ballan $
44 */
45
46 /** @addtogroup general_platform General Platform-specific Definitions
47 @{
48 */
49
50 #ifndef ASC_ASCCONFIG_H
51 #define ASC_ASCCONFIG_H
52
53 #ifndef ASC_BUILDING_INTERFACE
54 # define ASC_BUILDING_LIBASCEND
55 #endif
56
57 /*
58 *
59 * Determine the Operating System we are building on
60 *
61 */
62
63 /* windows */
64 #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
65 # ifndef __WIN32__
66 # define __WIN32__
67 # endif
68 #endif
69
70 #ifdef __alpha
71 /** DEC Alpha running OSF */
72 # define __ALPHA_OSF__
73 #endif /* __alpha */
74
75 #ifdef __hpux
76 /** HP running HP-UX */
77 # define __HPUX__
78 #endif /* __hpux */
79
80 #ifdef _AIX
81 /** IBM RS6000 or PowerPC running AIX */
82 # define __IBM_AIX__
83 #endif /* _AIX */
84
85 #ifdef __sgi
86 /** SGI running IRIX */
87 # define __SGI_IRIX__
88 #endif /* __sgi */
89
90 #if defined(__sun) || defined(sun)
91 # ifdef __SVR4
92 /** Sparc running Solaris 2.x (SunOS 5.x) */
93 # define __SUN_SOLARIS__
94 # else /* __SVR4 */
95 /** Sparc running SunOS 4.x (Solaris 1.x) */
96 # define __SUN_SUNOS__
97 # endif /* __SVR4 */
98 #endif /* __sun || sun */
99
100 #ifdef linux
101 #define __LINUX__
102 #endif /* linux */
103
104 /* FIXME: need to slip osx in here now. */
105
106 /*
107 ASCEND code in base/generic only EXPORTS symbols, no imports.
108 The ASC_DLLSPEC macro will, depending on whether we are
109 ASC_BUILDING_LIBASCEND (building libascend.so aka ascend.dll)
110 or ASC_BUILDING_INTERFACE (building for example _ascpy.dll or
111 ascendtcl.dll), act respectively to declare symbols as being
112 *exported* or *imported*.
113
114 New versions of GCC are able to make use of these declarations
115 as well.
116 */
117 #ifdef __WIN32__
118 # define ASC_EXPORT __declspec(dllexport)
119 # define ASC_IMPORT __declspec(dllimport)
120 #else
121 # ifdef HAVE_GCCVISIBILITY
122 # define ASC_EXPORT __attribute__ ((visibility("default")))
123 # define ASC_IMPORT
124 # else
125 # define ASC_EXPORT
126 # define ASC_IMPORT
127 # endif
128 #endif
129
130 #ifdef ASC_BUILDING_LIBASCEND
131 # define ASC_DLLSPEC extern ASC_EXPORT
132 #else
133 # define ASC_DLLSPEC extern ASC_IMPORT
134 #endif
135
136 #if !defined(ASC_DLLSPEC) || !defined(ASC_EXPORT) || !defined(ASC_IMPORT)
137 # error "NO ASC_DLLSPEC DEFINED"
138 #endif
139
140 /**
141 What kind of C compiler do we have?
142
143 Use compiler flag -DDISABLE_C99 to force older ISO C
144 This means no variadic macros, maybe other things too.
145 */
146 #if defined(__STDC__) && defined(__STDC_VERSION__)
147 # if __STDC_VERSION__>=199901L
148 # ifndef DISABLE_C99
149 # define HAVE_C99
150 # endif
151 # endif
152 #endif
153
154 /**
155 Define 'NORETURN' to the appropriate compiler-specific flags
156 for a function that never returns
157 */
158 #ifdef __GNUC__
159 # define NORETURN __attribute__((noreturn))
160 #elif defined(_MSC_VER)
161 # define NORETURN __declspec(noreturn)
162 #else
163 # define NORETURN /* nothing */
164 #endif
165
166 /*
167 * Make certain we have proper limits defined
168 */
169 #include <stdlib.h>
170 #include <time.h>
171 #include <limits.h>
172 #include <float.h>
173 #include <sys/types.h>
174 #ifdef _OSF_SOURCE
175 # include <sys/syslimits.h>
176 #endif
177 /* for use practically everywhere */
178 #include<stdio.h>
179
180
181 #if defined(__WIN32__) && !defined(__MINGW32__)
182 # undef Status /* jds20041229 - #define in tcl include/X11/XLib.h conflicts. */
183 # define WIN32_LEAN_AND_MEAN
184 # include <windows.h> /* jds20041212 - some limits defined in winnt.h (MAXLONG). */
185 # undef WIN32_LEAN_AND_MEAN
186 #endif
187
188 #ifndef PATH_MAX
189 /** Normally will come from stdio.h or limits.h
190 * POSIX values of PATH_MAX is 255, traditional is 1023
191 */
192 # define PATH_MAX 1023
193 #endif
194
195 /* the following numbers should have come through limits.h */
196 #ifndef SHRT_MAX
197 # define SHRT_MAX 32767
198 #endif
199 #ifndef INT_MAX
200 # define INT_MAX 2147483647
201 /* 32 bit machines */
202 #endif
203 #ifndef LONG_MAX
204 # ifdef __alpha
205 # define LONG_MAX 9223372036854775807 /* 64 bit machines */
206 # else /* __alpha */
207 # define LONG_MAX 2147483647 /* 32 bit machines */
208 # endif /* __alpha */
209 #endif /* LONG_MAX */
210
211 #ifndef MAXDOUBLE
212 # define MAXDOUBLE DBL_MAX
213 #endif
214 #ifndef MAXINT
215 # define MAXINT INT_MAX
216 #endif
217 #ifndef MAXUINT
218 # define MAXUINT UINT_MAX
219 #endif
220 #ifndef MAXLONG
221 # define MAXLONG LONG_MAX
222 #endif
223 #ifndef MAXULONG
224 # define MAXULONG UILONG_MAX
225 #endif
226
227 /**
228 * The largest number of digits we'd ever expect to see in a single
229 * numeric value, * 3 or so for good measure.
230 */
231 #define MAXIMUM_NUMERIC_LENGTH 80
232
233 /*
234 * Useful Headers
235 */
236
237 /* for use by ascmalloc, which is also practically everywhere */
238 #include <assert.h>
239 #include <string.h>
240 /*
241 * #include <malloc.h>
242 *
243 * malloc() is defined in <stdlib.h> in ANSI-C
244 */
245
246 #define MAXTOKENLENGTH 1024 /**< Maximum token size.
247 Most significant for identifiers and strings */
248 #ifndef FALSE
249 # define FALSE 0
250 # define TRUE 1
251 #endif
252
253 #ifndef CONST
254 # define CONST const
255 #endif
256
257 #define VOIDPTR void *
258
259 /* moved UGLint and GLint to config.h */
260
261 #ifdef REIMPLEMENT_STREAMS
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 #else
274 # define ASCERR stderr
275 # define ASCWAR stderr
276 # define ASCINF stderr
277 #endif
278
279
280 /*
281 * file pointers for whine. they default to stderr. if you change
282 * them, be sure to change them to valid files.
283 */
284
285 #define BYTESIZE 8
286 #define WORDSIZE (sizeof(unsigned)*BYTESIZE)
287
288 #ifndef HAVE_BOOLEAN
289 /* don't need to define this stuff if using GraphViz types.h (it's already defined identically there) */
290 #ifndef TRUE
291 # define TRUE 1
292 #endif
293 #ifndef FALSE
294 # define FALSE 0
295 #endif
296 typedef char *POINTER; /**< Generic pointer. */
297
298 typedef unsigned char boolean; /**< Boolean type. */
299 /* changed from 'char' to 'unsigned char' for compatibility with standard headers with MinGW GCC 3.4.2 */
300 #endif
301
302 typedef int ALIGN; /**< Data alignment. */
303 /**
304 * real64:
305 * change this typedef and all the solver code should change
306 * precision automatically. The code is predicated on 64bit ieee math.
307 * change the typedef as needed to get 64bit numbers. In particular
308 * crays may change this to float.
309 * int32:
310 * uint32;
311 * a 32bit int. change this typedef and all the solver code changes
312 * with it. may be of use for compiler which default int to 16bits
313 * equivalent to -i4 on most f77 compilers.
314 */
315 typedef double real64; /* a value */
316 typedef int int32; /**< a row/col/var/rel index number */
317 typedef unsigned uint32;
318
319
320 /**
321 * MAXREFCOUNT should always be defined to be the maximum value
322 * that the reference count attribute of reference count objects
323 * can take. It is unreasonable that a refcount be 64 bits, so
324 * it is 32.
325 */
326 #define MAXREFCOUNT UINT_MAX
327 #define REFCOUNT_T unsigned int
328
329 /*
330 * A bit of header magic to address the question of NULL being implementation
331 * defined, though virtually all systems of interest define it as 0 or 0L,
332 * if we are to claim ANSI conformance.
333 *
334 * IEEE 754 arithmetic implies all 0 bits <--> 0.0, so there isn't
335 * a problem where this is concerned. We have assumed ieee math.
336 *
337 * Notes to myself:
338 * Put this in base.h and suggest its insertion in
339 * compiler.h and perhaps interface1.h.
340 * Any place that calloc is being used to allocate arrays of NULL pointers,
341 * put a proper #if to replace it with a call to malloc and an appropriate
342 * NULLing function.
343 *
344 * Ben Allan, Jan 6, 1994.
345 */
346
347 /*
348 * NOTE: The below if works for 0 or 0L, which is to say I assume it
349 * works for 0 and I have tested that it works for 0L. Next we define
350 * the cheap versions of null testing for machine with 0 == NULL
351 *
352 * These are the proper ANSI C tests for NULL on 0!=NULL machines, should
353 * we ever run into them.
354 */
355 #ifdef NULL
356 /* ok, so the machine has a NULL defined. */
357 # ifndef ISNULL
358 /* and we've not got an ISNULL function */
359 # define ISNULL(a) ((a) == NULL)
360 # define NOTNULL(a) ((a) != NULL)
361 # endif /* ISNULL */
362 # endif /* NULL */
363
364 #ifndef NULL
365 # error "Null not defined by the time ascConfig.h seen"
366 #endif
367
368 #ifndef UNUSED_PARAMETER
369 /** Standardize the treatment of unreferenced function parameters. */
370 # define UNUSED_PARAMETER(p) (void)(p)
371 #endif
372
373 /* ASCEND assertion defines */
374 /** Exit status code for failed assertion. */
375 #define ASCERR_ASSERTION_FAILED 100
376 /*
377 * For now, asc_assert tied to NDEBUG just like regular assert.
378 * Having a separate assertion deactivator (ASC_NO_ASSERTIONS)
379 * gives us the ability to decouple from NDEBUG and leave
380 * assertions active in release code if desired.
381 */
382 #ifdef NDEBUG
383 /** If defined, asc_assert() will be removed from code. */
384 # define ASC_NO_ASSERTIONS
385 #endif
386
387 /*
388 *
389 * Platform specific fixes
390 *
391 */
392
393 #if defined(__WIN32__) && !defined(__MINGW32__)
394
395 /*
396 * use the ASCEND printf substitutes
397 */
398 # ifndef USE_ASC_PRINTF
399 # define USE_ASC_PRINTF
400 # endif /* USE_ASC_PRINTF */
401
402 /*
403 * build the Tk Console
404 */
405 # ifndef ASC_USE_TK_CONSOLE
406 # define ASC_USE_TK_CONSOLE
407 # endif /* ASC_USE_TK_CONSOLE */
408
409 #endif
410
411 /* signal traps stuff moved to config.h.in */
412
413 /*------------------------------------*
414 OUTPUT FILE* MAPPINGS
415
416 On Windows, we have to use these special Asc_Printf (etc)
417 routines in order that output can be captured correctly by the GUI.
418
419 On non-Windows platforms, allow error.h to
420 */
421 #ifdef USE_ASC_PRINTF
422 # define ASC_PRINTF Asc_Printf
423 # define ASC_FPRINTF Asc_FPrintf
424 # define ASC_VFPRINTF Asc_VFPrintf
425 # define ASC_FFLUSH Asc_FFlush
426 # define ASC_PUTC Asc_FPutc
427 # define ASC_FPUTC Asc_FPutc
428 # define ASC_PUTCHAR Asc_Putchar
429 # include <stdarg.h>
430 # include "ascend/utilities/ascPrint.h"
431 #else
432 # define ASC_PRINTF printf
433 # define ASC_FPRINTF fprintf
434 # define ASC_VFPRINTF vfprintf
435 # define ASC_FFLUSH fflush
436 # define ASC_PUTC putc
437 # define ASC_FPUTC fputc
438 # define ASC_PUTCHAR putchar
439 #endif
440
441 /* error.h will define handlers for
442 FPRINTF
443 FPUTC
444 FFLUSH
445 */
446 #ifdef IS_BINTOKEN_COMPILE
447 # define FPRINTF ASC_FPRINTF
448 # define FPUTC ASC_FPUTC
449 # define FFLUSH ASC_FFLUSH
450 #else
451 # include "ascend/utilities/error.h"
452 #endif
453
454 /* These are the remaining output macros that need to be mapped
455 */
456 #define PRINTF ASC_PRINTF
457 #define PUTCHAR ASC_PUTCHAR
458 /*------------------------------------*/
459
460
461 #ifndef __SUN_SUNOS__
462 /* do this for non-sun machines and for sun-solaris machines */
463 # ifndef roundup
464 # define rounddown(num,mod) ((num)-(num)%(mod))
465 # define roundup(num,mod) rounddown((num)+(mod)-1,(mod))
466 # define roundoff(num,mod) rounddown((num)+((mod)/2),(mod))
467 # endif /* roundup */
468 #endif /* __SUN_SUNOS__ */
469
470
471 /* These define integer divide and modulus mathematically correctly */
472 #define imod(num,den) ((num)%(den) + ((num)%(den)<0 ? (den) : 0))
473 #define idiv(num,den) ((num)/(den) + ((num)%(den)<0))
474 #define array_length(a) (sizeof(a)/sizeof((a)[0]))
475
476 /*
477 * the following patch up IEEE754isms that some systems can't seem to
478 * get right.
479 */
480 #ifdef __WIN32__
481 /* renamed in some __WIN32__ compiler systems */
482 # ifndef NO_RENAME_IEEE_FUNCTIONS
483 # undef finite
484 # define finite(x) _finite(x)
485 # undef isnan
486 # define isnan(x) _isnan(x)
487 # undef isinf
488 # define isinf(x) _isinf(x)
489 # endif
490 /* MSVC peculiarities */
491 # ifdef _MSC_VER
492 # undef snprintf
493 # define snprintf _snprintf
494 # undef vsnprintf
495 # define vsnprintf _vsnprintf
496 # undef tempnam
497 # define tempnam _tempnam
498 # undef fdopen
499 # define fdopen _fdopen
500 # undef fileno
501 # define fileno _fileno
502 # undef getpid
503 # define getpid _getpid
504 # undef dup
505 # define dup _dup
506 # undef dup2
507 # define dup2 _dup2
508 # undef putenv
509 # define putenv _putenv
510 # endif
511 #endif /* __WIN32__ */
512
513 #ifdef __SUN_SUNOS__
514 /** not properly headered in math.h or ieee*.h */
515 extern int finite(double);
516 #endif
517
518 /** This macro returns a nonzero value if X is NaN. */
519 #define asc_isnan(x) isnan(x)
520
521 /**
522 This function returns `-1' if X represents negative infinity, `1'
523 if X represents positive infinity, and `0' otherwise.
524 note that 0 can be a number or a nan.
525 */
526 #define asc_isinf(x) isinf(x)
527
528 /**
529 This macro returns a nonzero value if X is finite: not plus or
530 minus infinity, and not NaN.
531 */
532 #if (defined(__STDC_VERSION__)&&(__STDC_VERSION__ >= 199901L))
533 /* c99 std */
534 #define asc_finite(x) isfinite(x)
535 #else
536 /* gnu c89 and most other compilers when not in anti-bsd mode */
537 #define asc_finite(x) finite(x)
538 #endif
539
540
541 #endif /* ASC_ASCCONFIG_H */
542

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