source: icGREP/icgrep-devel/cudd-2.5.1/util/util.h @ 5820

Last change on this file since 5820 was 4597, checked in by nmedfort, 4 years ago

Upload of the CUDD library.

File size: 5.3 KB
Line 
1/* $Id: util.h,v 1.10 2012/02/05 05:34:04 fabio Exp fabio $ */
2
3#ifndef UTIL_H
4#define UTIL_H
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#if defined(__GNUC__)
11#   define UTIL_INLINE __inline__
12#   if __GNUC__ > 2 || __GNUC_MINOR__ >= 7
13#       define UTIL_UNUSED __attribute__ ((unused))
14#   else
15#       define UTIL_UNUSED
16#   endif
17#else
18#   define UTIL_INLINE
19#   define UTIL_UNUSED
20#endif
21
22#ifndef SIZEOF_VOID_P
23#define SIZEOF_VOID_P 4
24#endif
25#ifndef SIZEOF_INT
26#define SIZEOF_INT 4
27#endif
28#ifndef SIZEOF_LONG
29#define SIZEOF_LONG 4
30#endif
31
32#if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
33typedef long util_ptrint;
34#else
35typedef int util_ptrint;
36#endif
37
38/* #define USE_MM */            /* choose libmm.a as the memory allocator */
39
40/* these are too entrenched to get away with changing the name */
41#define strsav          util_strsav
42#include <unistd.h>
43
44#define NIL(type)               ((type *) 0)
45
46#if defined(USE_MM) || defined(MNEMOSYNE)
47/*
48 *  assumes the memory manager is either libmm.a or libmnem.a
49 *      libmm.a:
50 *      - allows malloc(0) or realloc(obj, 0)
51 *      - catches out of memory (and calls MMout_of_memory())
52 *      - catch free(0) and realloc(0, size) in the macros
53 *      libmnem.a:
54 *      - reports memory leaks
55 *      - is used in conjunction with the mnemalyse postprocessor
56 */
57#ifdef MNEMOSYNE
58#include "mnemosyne.h"
59#define ALLOC(type, num)        \
60    ((num) ? ((type *) malloc(sizeof(type) * (num))) : \
61            ((type *) malloc(sizeof(long))))
62#else
63#define ALLOC(type, num)        \
64    ((type *) malloc(sizeof(type) * (num)))
65#endif
66#define REALLOC(type, obj, num) \
67    (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \
68            ((type *) malloc(sizeof(type) * (num)))
69#define FREE(obj)               \
70    ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
71#else
72/*
73 *  enforce strict semantics on the memory allocator
74 *      - when in doubt, delete the '#define USE_MM' above
75 */
76#define ALLOC(type, num)        \
77    ((type *) MMalloc((long) sizeof(type) * (long) (num)))
78#define REALLOC(type, obj, num) \
79    ((type *) MMrealloc((char *) (obj), (long) sizeof(type) * (long) (num)))
80#define FREE(obj)               \
81    ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
82#endif
83
84
85/* Ultrix (and SABER) have 'fixed' certain functions which used to be int */
86#if defined(ultrix) || defined(SABER) || defined(aiws) || defined(hpux) || defined(apollo) || defined(__osf__) || defined(__SVR4) || defined(__GNUC__)
87#define VOID_OR_INT void
88#define VOID_OR_CHAR void
89#else
90#define VOID_OR_INT int
91#define VOID_OR_CHAR char
92#endif
93
94
95/* No machines seem to have much of a problem with these */
96#include <stdio.h>
97#include <ctype.h>
98
99
100/* Some machines fail to define some functions in stdio.h */
101#if !defined(__STDC__) && !defined(__cplusplus)
102extern FILE *popen(), *tmpfile();
103extern int pclose();
104#endif
105
106
107/* most machines don't give us a header file for these */
108#if (defined(__STDC__) || defined(__cplusplus) || defined(ultrix)) && !defined(MNEMOSYNE) || defined(__SVR4)
109# include <stdlib.h>
110#else
111# ifndef _IBMR2
112    extern VOID_OR_INT abort(), exit();
113# endif
114# if !defined(MNEMOSYNE) && !defined(_IBMR2)
115    extern VOID_OR_INT free (void *);
116    extern VOID_OR_CHAR *malloc(), *realloc();
117# endif
118  extern char *getenv();
119  extern int system();
120  extern double atof();
121#endif
122
123
124/* some call it strings.h, some call it string.h; others, also have memory.h */
125#if defined(__STDC__) || defined(__cplusplus) || defined(_IBMR2) || defined(ultrix)
126#include <string.h>
127#else
128/* ANSI C string.h -- 1/11/88 Draft Standard */
129extern char *strcpy(), *strncpy(), *strcat(), *strncat(), *strerror();
130extern char *strpbrk(), *strtok(), *strchr(), *strrchr(), *strstr();
131extern int strcoll(), strxfrm(), strncmp(), strlen(), strspn(), strcspn();
132extern char *memmove(), *memccpy(), *memchr(), *memcpy(), *memset();
133extern int memcmp(), strcmp();
134#endif
135
136
137#ifdef __STDC__
138#include <assert.h>
139#else
140#ifndef NDEBUG
141#define assert(ex) {\
142    if (! (ex)) {\
143        (void) fprintf(stderr,\
144            "Assertion failed: file %s, line %d\n\"%s\"\n",\
145            __FILE__, __LINE__, "ex");\
146        (void) fflush(stdout);\
147        abort();\
148    }\
149}
150#else
151#define assert(ex) ;
152#endif
153#endif
154
155
156#define fail(why) {\
157    (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
158        __FILE__, __LINE__, why);\
159    (void) fflush(stdout);\
160    abort();\
161}
162
163
164#ifdef lint
165#undef putc                     /* correct lint '_flsbuf' bug */
166#undef ALLOC                    /* allow for lint -h flag */
167#undef REALLOC
168#define ALLOC(type, num)        (((type *) 0) + (num))
169#define REALLOC(type, obj, num) ((obj) + (num))
170#endif
171
172
173/* These arguably do NOT belong in util.h */
174#define ABS(a)                  ((a) < 0 ? -(a) : (a))
175#define MAX(a,b)                ((a) > (b) ? (a) : (b))
176#define MIN(a,b)                ((a) < (b) ? (a) : (b))
177
178
179#ifndef USE_MM
180extern char *MMalloc (long);
181extern void MMout_of_memory (long);
182extern void (*MMoutOfMemory) (long);
183extern char *MMrealloc (char *, long);
184#endif
185
186extern long util_cpu_time (void);
187extern char *util_path_search (char const *);
188extern char *util_file_search (char const *, char *, char const *);
189extern int util_pipefork (char * const *, FILE **, FILE **, int *);
190extern void util_print_cpu_stats (FILE *);
191extern char *util_print_time (unsigned long);
192extern int util_save_image (char const *, char const *);
193extern char *util_strsav (char const *);
194extern char *util_tilde_expand (char const *);
195extern void util_restart (char const *, char const *, int);
196
197
198extern unsigned long getSoftDataLimit (void);
199
200#ifdef __cplusplus
201}
202#endif
203
204#endif /* UTIL_H */
Note: See TracBrowser for help on using the repository browser.