src/misc/util/util_hack.h File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <math.h>
Include dependency graph for util_hack.h:

Go to the source code of this file.

Defines

#define EXTERN   extern
#define NIL(type)   ((type *) 0)
#define random   rand
#define srandom   srand
#define util_cpu_time   Extra_CpuTime
#define getSoftDataLimit   Extra_GetSoftDataLimit
#define util_getopt_reset   Extra_UtilGetoptReset
#define util_getopt   Extra_UtilGetopt
#define util_print_time   Extra_UtilPrintTime
#define util_strsav   Extra_UtilStrsav
#define util_tilde_expand   Extra_UtilTildeExpand
#define util_file_search   Extra_UtilFileSearch
#define MMoutOfMemory   Extra_UtilMMoutOfMemory
#define util_optarg   globalUtilOptarg
#define util_optind   globalUtilOptind
#define ALLOC(type, num)   ((type *) malloc(sizeof(type) * (num)))
#define FREE(obj)   ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
#define REALLOC(type, obj, num)

Functions

long Extra_CpuTime ()
int Extra_GetSoftDataLimit ()
void Extra_UtilGetoptReset ()
int Extra_UtilGetopt (int argc, char *argv[], char *optstring)
char * Extra_UtilPrintTime (long t)
char * Extra_UtilStrsav (char *s)
char * Extra_UtilTildeExpand (char *fname)
char * Extra_UtilFileSearch (char *file, char *path, char *mode)

Variables

char * globalUtilOptarg
int globalUtilOptind

Define Documentation

#define ALLOC ( type,
num   )     ((type *) malloc(sizeof(type) * (num)))

Definition at line 73 of file util_hack.h.

#define EXTERN   extern

CFile****************************************************************

FileName [util_hack.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [This file is used to simulate the presence of "util.h".]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
util_hack.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 35 of file util_hack.h.

#define FREE ( obj   )     ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)

Definition at line 74 of file util_hack.h.

#define getSoftDataLimit   Extra_GetSoftDataLimit

Definition at line 41 of file util_hack.h.

#define MMoutOfMemory   Extra_UtilMMoutOfMemory

Definition at line 48 of file util_hack.h.

#define NIL ( type   )     ((type *) 0)

Definition at line 36 of file util_hack.h.

#define random   rand

Definition at line 37 of file util_hack.h.

#define REALLOC ( type,
obj,
num   ) 
Value:
((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
        ((type *) malloc(sizeof(type) * (num))))

Definition at line 75 of file util_hack.h.

#define srandom   srand

Definition at line 38 of file util_hack.h.

#define util_cpu_time   Extra_CpuTime

Definition at line 40 of file util_hack.h.

#define util_file_search   Extra_UtilFileSearch

Definition at line 47 of file util_hack.h.

#define util_getopt   Extra_UtilGetopt

Definition at line 43 of file util_hack.h.

#define util_getopt_reset   Extra_UtilGetoptReset

Definition at line 42 of file util_hack.h.

Definition at line 50 of file util_hack.h.

Definition at line 51 of file util_hack.h.

#define util_print_time   Extra_UtilPrintTime

Definition at line 44 of file util_hack.h.

#define util_strsav   Extra_UtilStrsav

Definition at line 45 of file util_hack.h.

#define util_tilde_expand   Extra_UtilTildeExpand

Definition at line 46 of file util_hack.h.


Function Documentation

long Extra_CpuTime (  ) 

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 61 of file extraUtilUtil.c.

00062 {
00063     return clock();
00064 }

int Extra_GetSoftDataLimit (  ) 

Function*************************************************************

Synopsis [getSoftDataLimit()]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file extraUtilUtil.c.

00078 {
00079     return EXTRA_RLIMIT_DATA_DEFAULT;
00080 }

char* Extra_UtilFileSearch ( char *  file,
char *  path,
char *  mode 
)

Function*************************************************************

Synopsis [util_file_search()]

Description []

SideEffects []

SeeAlso []

Definition at line 246 of file extraUtilUtil.c.

00250 {
00251     int quit;
00252     char *buffer, *filename, *save_path, *cp;
00253 
00254     if (path == 0 || strcmp(path, "") == 0) {
00255         path = ".";             /* just look in the current directory */
00256     }
00257 
00258     save_path = path = Extra_UtilStrsav(path);
00259     quit = 0;
00260     do {
00261         cp = strchr(path, ':');
00262         if (cp != 0) {
00263             *cp = '\0';
00264         } else {
00265             quit = 1;
00266         }
00267 
00268         /* cons up the filename out of the path and file name */
00269         if (strcmp(path, ".") == 0) {
00270             buffer = Extra_UtilStrsav(file);
00271         } else {
00272             buffer = ALLOC(char, strlen(path) + strlen(file) + 4);
00273             (void) sprintf(buffer, "%s/%s", path, file);
00274         }
00275         filename = Extra_UtilTildeExpand(buffer);
00276         FREE(buffer);
00277 
00278         /* see if we can access it */
00279         if (Extra_UtilCheckFile(filename, mode)) {
00280             FREE(save_path);
00281             return filename;
00282         }
00283         FREE(filename);
00284         path = ++cp;
00285     } while (! quit); 
00286 
00287     FREE(save_path);
00288     return 0;
00289 }

int Extra_UtilGetopt ( int  argc,
char *  argv[],
char *  optstring 
)

Function*************************************************************

Synopsis [util_getopt()]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file extraUtilUtil.c.

00112 {
00113     register int c;
00114     register char *place;
00115 
00116     globalUtilOptarg = NULL;
00117 
00118     if (pScanStr == NULL || *pScanStr == '\0') {
00119     if (globalUtilOptind == 0) globalUtilOptind++;
00120     if (globalUtilOptind >= argc) return EOF;
00121     place = argv[globalUtilOptind];
00122     if (place[0] != '-' || place[1] == '\0') return EOF;
00123     globalUtilOptind++;
00124     if (place[1] == '-' && place[2] == '\0') return EOF;
00125     pScanStr = place+1;
00126     }
00127 
00128     c = *pScanStr++;
00129     place = strchr(optstring, c);
00130     if (place == NULL || c == ':') {
00131     (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
00132     return '?';
00133     }
00134     if (*++place == ':') {
00135     if (*pScanStr != '\0') {
00136         globalUtilOptarg = pScanStr;
00137         pScanStr = NULL;
00138     } else {
00139         if (globalUtilOptind >= argc) {
00140         (void) fprintf(stderr, "%s: %c requires an argument\n", 
00141             argv[0], c);
00142         return '?';
00143         }
00144         globalUtilOptarg = argv[globalUtilOptind];
00145         globalUtilOptind++;
00146     }
00147     }
00148     return c;
00149 }

void Extra_UtilGetoptReset (  ) 

Function*************************************************************

Synopsis [util_getopt_reset()]

Description []

SideEffects []

SeeAlso []

Definition at line 93 of file extraUtilUtil.c.

00094 {
00095     globalUtilOptarg = 0;
00096     globalUtilOptind = 0;
00097     pScanStr = 0;
00098 }

char* Extra_UtilPrintTime ( long  t  ) 

Function*************************************************************

Synopsis [util_print_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 162 of file extraUtilUtil.c.

00163 {
00164     static char s[40];
00165 
00166     (void) sprintf(s, "%ld.%02ld sec", t/1000, (t%1000)/10);
00167     return s;
00168 }

char* Extra_UtilStrsav ( char *  s  ) 

Function*************************************************************

Synopsis [Extra_UtilStrsav()]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file extraUtilUtil.c.

00183 {
00184     if(s == NULL) {  /* added 7/95, for robustness */
00185        return s;
00186     }
00187     else {
00188        return strcpy(ALLOC(char, strlen(s)+1), s);
00189     }
00190 }

char* Extra_UtilTildeExpand ( char *  fname  ) 

Function*************************************************************

Synopsis [util_tilde_expand()]

Description []

SideEffects []

SeeAlso []

Definition at line 203 of file extraUtilUtil.c.

00204 {
00205     return Extra_UtilStrsav( fname );
00206 }


Variable Documentation

Definition at line 41 of file extraUtilUtil.c.

Definition at line 42 of file extraUtilUtil.c.


Generated on Tue Jan 5 12:19:19 2010 for abc70930 by  doxygen 1.6.1