abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilUtil.c File Reference
#include <stdio.h>
#include <string.h>
#include "extra.h"
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define EXTRA_RLIMIT_DATA_DEFAULT   67108864
 DECLARATIONS ///. More...
 

Functions

int Extra_GetSoftDataLimit ()
 FUNCTION DEFINITIONS ///. More...
 
void Extra_UtilGetoptReset ()
 
int Extra_UtilGetopt (int argc, char *argv[], const char *optstring)
 
char * Extra_UtilPrintTime (long t)
 
char * Extra_UtilStrsav (const char *s)
 
char * Extra_UtilTildeExpand (char *fname)
 
int Extra_UtilCheckFile (char *filename, const char *mode)
 
char * Extra_UtilFileSearch (char *file, char *path, char *mode)
 
void Extra_UtilMMout_Of_Memory (long size)
 
abctime Extra_CpuTime ()
 
ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START
double 
Extra_CpuTimeDouble ()
 
void Extra_MemTest ()
 

Variables

const char * globalUtilOptarg
 
int globalUtilOptind = 0
 
static const char * pScanStr
 
void(* Extra_UtilMMoutOfMemory )(long size) = (void (*)( long size ))Extra_UtilMMout_Of_Memory
 

Macro Definition Documentation

#define EXTRA_RLIMIT_DATA_DEFAULT   67108864

DECLARATIONS ///.

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

FileName [extraUtilUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Old SIS utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
extraUtilUtil.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

]

Definition at line 31 of file extraUtilUtil.c.

Function Documentation

abctime Extra_CpuTime ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 350 of file extraUtilUtil.c.

351 {
352  return Abc_Clock();
353 }
static abctime Abc_Clock()
Definition: abc_global.h:279
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START double Extra_CpuTimeDouble ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 381 of file extraUtilUtil.c.

382 {
383  struct rusage ru;
384  getrusage(RUSAGE_SELF, &ru);
385  return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
386 }
int Extra_GetSoftDataLimit ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [getSoftDataLimit()]

Description []

SideEffects []

SeeAlso []

Definition at line 64 of file extraUtilUtil.c.

65 {
67 }
#define EXTRA_RLIMIT_DATA_DEFAULT
DECLARATIONS ///.
Definition: extraUtilUtil.c:31
void Extra_MemTest ( )

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

Synopsis [Testing memory leaks.]

Description []

SideEffects []

SeeAlso []

Definition at line 400 of file extraUtilUtil.c.

401 {
402 // ABC_ALLOC( char, 1002 );
403 }
int Extra_UtilCheckFile ( char *  filename,
const char *  mode 
)

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

Synopsis [check_file()]

Description []

SideEffects []

SeeAlso []

Definition at line 232 of file extraUtilUtil.c.

233 {
234  FILE *fp;
235  int got_file;
236 
237  if (strcmp(mode, "x") == 0) {
238  mode = "r";
239  }
240  fp = fopen(filename, mode);
241  got_file = (fp != 0);
242  if (fp != 0) {
243  (void) fclose(fp);
244  }
245  return got_file;
246 }
char * filename
Definition: globals.c:40
int strcmp()
char* Extra_UtilFileSearch ( char *  file,
char *  path,
char *  mode 
)

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

Synopsis [util_file_search()]

Description []

SideEffects []

SeeAlso []

Definition at line 259 of file extraUtilUtil.c.

263 {
264  int quit;
265  char *buffer, *filename, *save_path, *cp;
266 
267  if (path == 0 || strcmp(path, "") == 0) {
268  path = "."; /* just look in the current directory */
269  }
270 
271  save_path = path = Extra_UtilStrsav(path);
272  quit = 0;
273  do {
274  cp = strchr(path, ':');
275  if (cp != 0) {
276  *cp = '\0';
277  } else {
278  quit = 1;
279  }
280 
281  /* cons up the filename out of the path and file name */
282  if (strcmp(path, ".") == 0) {
283  buffer = Extra_UtilStrsav(file);
284  } else {
285  buffer = ABC_ALLOC(char, strlen(path) + strlen(file) + 4);
286  (void) sprintf(buffer, "%s/%s", path, file);
287  }
288  filename = Extra_UtilTildeExpand(buffer);
289  ABC_FREE(buffer);
290 
291  /* see if we can access it */
292  if (Extra_UtilCheckFile(filename, mode)) {
293  ABC_FREE(save_path);
294  return filename;
295  }
296  ABC_FREE(filename);
297  path = ++cp;
298  } while (! quit);
299 
300  ABC_FREE(save_path);
301  return 0;
302 }
char * filename
Definition: globals.c:40
char * Extra_UtilTildeExpand(char *fname)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
int strcmp()
char * strchr()
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Extra_UtilCheckFile(char *filename, const char *mode)
int strlen()
int Extra_UtilGetopt ( int  argc,
char *  argv[],
const char *  optstring 
)

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

Synopsis [util_getopt()]

Description []

SideEffects []

SeeAlso []

Definition at line 98 of file extraUtilUtil.c.

99 {
100  register int c;
101  register const char *place;
102 
103  globalUtilOptarg = NULL;
104 
105  if (pScanStr == NULL || *pScanStr == '\0') {
107  if (globalUtilOptind >= argc) return EOF;
108  place = argv[globalUtilOptind];
109  if (place[0] != '-' || place[1] == '\0') return EOF;
111  if (place[1] == '-' && place[2] == '\0') return EOF;
112  pScanStr = place+1;
113  }
114 
115  c = *pScanStr++;
116  place = strchr(optstring, c);
117  if (place == NULL || c == ':') {
118  (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
119  return '?';
120  }
121  if (*++place == ':') {
122  if (*pScanStr != '\0') {
124  pScanStr = NULL;
125  } else {
126  if (globalUtilOptind >= argc) {
127  (void) fprintf(stderr, "%s: %c requires an argument\n",
128  argv[0], c);
129  return '?';
130  }
133  }
134  }
135  return c;
136 }
const char * globalUtilOptarg
Definition: extraUtilUtil.c:44
int globalUtilOptind
Definition: extraUtilUtil.c:45
char * strchr()
static const char * pScanStr
Definition: extraUtilUtil.c:47
void Extra_UtilGetoptReset ( )

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

Synopsis [util_getopt_reset()]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file extraUtilUtil.c.

81 {
82  globalUtilOptarg = 0;
83  globalUtilOptind = 0;
84  pScanStr = 0;
85 }
const char * globalUtilOptarg
Definition: extraUtilUtil.c:44
int globalUtilOptind
Definition: extraUtilUtil.c:45
static const char * pScanStr
Definition: extraUtilUtil.c:47
void Extra_UtilMMout_Of_Memory ( long  size)

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

Synopsis [MMout_of_memory()]

Description []

SideEffects []

SeeAlso []

Definition at line 316 of file extraUtilUtil.c.

317 {
318  (void) fflush(stdout);
319  (void) fprintf(stderr, "\nout of memory allocating %u bytes\n",
320  (unsigned) size);
321  assert( 0 );
322  exit(1);
323 }
VOID_HACK exit()
static int size
Definition: cuddSign.c:86
#define assert(ex)
Definition: util_old.h:213
char* Extra_UtilPrintTime ( long  t)

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

Synopsis [util_print_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 149 of file extraUtilUtil.c.

150 {
151  static char s[40];
152 
153  (void) sprintf(s, "%ld.%02ld sec", t/1000, (t%1000)/10);
154  return s;
155 }
char * sprintf()
char* Extra_UtilStrsav ( const char *  s)

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

Synopsis [Extra_UtilStrsav()]

Description []

SideEffects []

SeeAlso []

Definition at line 169 of file extraUtilUtil.c.

170 {
171  if(s == NULL) { /* added 7/95, for robustness */
172  return NULL;
173  }
174  else {
175  return strcpy(ABC_ALLOC(char, strlen(s)+1), s);
176  }
177 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * strcpy()
int strlen()
char* Extra_UtilTildeExpand ( char *  fname)

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

Synopsis [util_tilde_expand()]

Description [The code contributed by Niklas Sorensson.]

SideEffects []

SeeAlso []

Definition at line 190 of file extraUtilUtil.c.

191 {
192  return Extra_UtilStrsav( fname );
193 /*
194  int n_tildes = 0;
195  const char* home;
196  char* expanded;
197  int length;
198  int i, j, k;
199 
200  for (i = 0; i < (int)strlen(fname); i++)
201  if (fname[i] == '~') n_tildes++;
202 
203  home = getenv("HOME");
204  length = n_tildes * strlen(home) + strlen(fname);
205  expanded = ABC_ALLOC(char, length + 1);
206 
207  j = 0;
208  for (i = 0; i < (int)strlen(fname); i++){
209  if (fname[i] == '~'){
210  for (k = 0; k < (int)strlen(home); k++)
211  expanded[j++] = home[k];
212  }else
213  expanded[j++] = fname[i];
214  }
215 
216  expanded[j] = '\0';
217  return expanded;
218 */
219 }
char * Extra_UtilStrsav(const char *s)

Variable Documentation

void(* Extra_UtilMMoutOfMemory)(long size) = (void (*)( long size ))Extra_UtilMMout_Of_Memory

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

Synopsis [MMoutOfMemory()]

Description []

SideEffects []

SeeAlso []

Definition at line 336 of file extraUtilUtil.c.

const char* globalUtilOptarg

Definition at line 44 of file extraUtilUtil.c.

int globalUtilOptind = 0

Definition at line 45 of file extraUtilUtil.c.

const char* pScanStr
static

Definition at line 47 of file extraUtilUtil.c.