abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilFile.c File Reference
#include "extra.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START char * Extra_FileGetSimilarName (char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
 
char * Extra_FileNameExtension (char *FileName)
 
char * Extra_FileNameAppend (char *pBase, char *pSuffix)
 
char * Extra_FileNameGeneric (char *FileName)
 
char * Extra_FileNameGenericAppend (char *pBase, char *pSuffix)
 
void Extra_FileNameCorrectPath (char *FileName)
 
char * Extra_FileNameWithoutPath (char *FileName)
 
char * Extra_FilePathWithoutName (char *FileName)
 
char * Extra_FileDesignName (char *pFileName)
 
int Extra_FileCheck (char *pFileName)
 
int Extra_FileSize (char *pFileName)
 
char * Extra_FileRead (FILE *pFile)
 
char * Extra_FileRead2 (FILE *pFile, FILE *pFile2)
 
char * Extra_FileReadContents (char *pFileName)
 
char * Extra_FileReadContents2 (char *pFileName, char *pFileName2)
 
int Extra_FileIsType (char *pFileName, char *pS1, char *pS2, char *pS3)
 
char * Extra_TimeStamp ()
 
unsigned Extra_ReadBinary (char *Buffer)
 
void Extra_PrintBinary (FILE *pFile, unsigned Sign[], int nBits)
 DECLARATIONS ///. More...
 
int Extra_ReadHex (unsigned Sign[], char *pString, int nDigits)
 
int Extra_ReadHexadecimal (unsigned Sign[], char *pString, int nVars)
 
void Extra_PrintHexadecimal (FILE *pFile, unsigned Sign[], int nVars)
 
void Extra_PrintHexadecimalString (char *pString, unsigned Sign[], int nVars)
 
void Extra_PrintHex (FILE *pFile, unsigned *pTruth, int nVars)
 
void Extra_PrintHexReverse (FILE *pFile, unsigned *pTruth, int nVars)
 
void Extra_PrintSymbols (FILE *pFile, char Char, int nTimes, int fPrintNewLine)
 
char * Extra_StringAppend (char *pStrGiven, char *pStrAdd)
 
void Extra_StringClean (char *pStrGiven, char *pCharKeep)
 
int Extra_StringCompare (const char *pp1, const char *pp2)
 
void Extra_FileSort (char *pFileName, char *pFileNameOut)
 
void Extra_FileLineNumAdd (char *pFileName, char *pFileNameOut)
 

Function Documentation

int Extra_FileCheck ( char *  pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 281 of file extraUtilFile.c.

282 {
283  FILE * pFile;
284  pFile = fopen( pFileName, "rb" );
285  if ( pFile == NULL )
286  {
287  printf( "Extra_FileCheck(): File \"%s\" does not exist.\n", pFileName );
288  return 0;
289  }
290  fseek( pFile, 0, SEEK_END );
291  if ( ftell( pFile ) == 0 )
292  printf( "Extra_FileCheck(): File \"%s\" is empty.\n", pFileName );
293  fclose( pFile );
294  return 1;
295 }
#define SEEK_END
Definition: zconf.h:392
char* Extra_FileDesignName ( char *  pFileName)

Definition at line 250 of file extraUtilFile.c.

251 {
252  char * pBeg, * pEnd, * pStore, * pCur;
253  // find the first dot
254  for ( pEnd = pFileName; *pEnd; pEnd++ )
255  if ( *pEnd == '.' )
256  break;
257  // find the first char
258  for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
259  if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
260  break;
261  pBeg++;
262  // fill up storage
263  pStore = ABC_ALLOC( char, pEnd - pBeg + 1 );
264  for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
265  *pCur = *pBeg;
266  *pCur = 0;
267  return pStore;
268 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_NAMESPACE_IMPL_START char* Extra_FileGetSimilarName ( char *  pFileNameWrong,
char *  pS1,
char *  pS2,
char *  pS3,
char *  pS4,
char *  pS5 
)

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

FileName [extraUtilFile.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [File management utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
extraUtilFile.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Tries to find a file name with a different extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file extraUtilFile.c.

72 {
73  FILE * pFile;
74  char * pFileNameOther;
75  char * pFileGen;
76 
77  if ( pS1 == NULL )
78  return NULL;
79 
80  // get the generic file name
81  pFileGen = Extra_FileNameGeneric( pFileNameWrong );
82  pFileNameOther = Extra_FileNameAppend( pFileGen, pS1 );
83  pFile = fopen( pFileNameOther, "r" );
84  if ( pFile == NULL && pS2 )
85  { // try one more
86  pFileNameOther = Extra_FileNameAppend( pFileGen, pS2 );
87  pFile = fopen( pFileNameOther, "r" );
88  if ( pFile == NULL && pS3 )
89  { // try one more
90  pFileNameOther = Extra_FileNameAppend( pFileGen, pS3 );
91  pFile = fopen( pFileNameOther, "r" );
92  if ( pFile == NULL && pS4 )
93  { // try one more
94  pFileNameOther = Extra_FileNameAppend( pFileGen, pS4 );
95  pFile = fopen( pFileNameOther, "r" );
96  if ( pFile == NULL && pS5 )
97  { // try one more
98  pFileNameOther = Extra_FileNameAppend( pFileGen, pS5 );
99  pFile = fopen( pFileNameOther, "r" );
100  }
101  }
102  }
103  }
104  ABC_FREE( pFileGen );
105  if ( pFile )
106  {
107  fclose( pFile );
108  return pFileNameOther;
109  }
110  // did not find :(
111  return NULL;
112 }
char * Extra_FileNameGeneric(char *FileName)
char * Extra_FileNameAppend(char *pBase, char *pSuffix)
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Extra_FileIsType ( char *  pFileName,
char *  pS1,
char *  pS2,
char *  pS3 
)

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

Synopsis [Returns one if the file has a given extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 420 of file extraUtilFile.c.

421 {
422  int lenS, lenF = strlen(pFileName);
423  lenS = pS1 ? strlen(pS1) : 0;
424  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS1, lenS ) )
425  return 1;
426  lenS = pS2 ? strlen(pS2) : 0;
427  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS2, lenS ) )
428  return 1;
429  lenS = pS3 ? strlen(pS3) : 0;
430  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS3, lenS ) )
431  return 1;
432  return 0;
433 }
int strncmp()
int strlen()
void Extra_FileLineNumAdd ( char *  pFileName,
char *  pFileNameOut 
)

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

Synopsis [Appends line number in the end.]

Description []

SideEffects []

SeeAlso []

Definition at line 816 of file extraUtilFile.c.

817 {
818  char Buffer[1000];
819  FILE * pFile;
820  FILE * pFile2;
821  int iLine;
822  pFile = fopen( pFileName, "rb" );
823  if ( pFile == NULL )
824  {
825  printf( "Extra_FileLineNumAdd(): Cannot open file \"%s\".\n", pFileName );
826  return;
827  }
828  pFile2 = fopen( pFileNameOut, "wb" );
829  if ( pFile2 == NULL )
830  {
831  fclose( pFile );
832  printf( "Extra_FileLineNumAdd(): Cannot open file \"%s\".\n", pFileNameOut );
833  return;
834  }
835  for ( iLine = 0; fgets( Buffer, 1000, pFile ); iLine++ )
836  {
837  sprintf( Buffer + strlen(Buffer) - 2, "%03d\n%c", iLine, 0 );
838  fputs( Buffer, pFile2 );
839  }
840  fclose( pFile );
841  fclose( pFile2 );
842  // report the result
843  printf( "The resulting file is \"%s\".\n", pFileNameOut );
844 }
char * sprintf()
int strlen()
char* Extra_FileNameAppend ( char *  pBase,
char *  pSuffix 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 146 of file extraUtilFile.c.

147 {
148  static char Buffer[500];
149  assert( strlen(pBase) + strlen(pSuffix) < 500 );
150  sprintf( Buffer, "%s%s", pBase, pSuffix );
151  return Buffer;
152 }
char * sprintf()
#define assert(ex)
Definition: util_old.h:213
int strlen()
void Extra_FileNameCorrectPath ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file extraUtilFile.c.

209 {
210  char * pStart;
211  if ( FileName )
212  for ( pStart = FileName; *pStart; pStart++ )
213  if ( *pStart == '>' || *pStart == '\\' )
214  *pStart = '/';
215 }
char* Extra_FileNameExtension ( char *  FileName)

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

Synopsis [Returns the pointer to the file extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 125 of file extraUtilFile.c.

126 {
127  char * pDot;
128  // find the last "dot" in the file name, if it is present
129  for ( pDot = FileName + strlen(FileName)-1; pDot >= FileName; pDot-- )
130  if ( *pDot == '.' )
131  return pDot + 1;
132  return FileName;
133 }
int strlen()
char* Extra_FileNameGeneric ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file extraUtilFile.c.

166 {
167  char * pDot, * pRes;
168  pRes = Extra_UtilStrsav( FileName );
169  if ( (pDot = strrchr( pRes, '.' )) )
170  *pDot = 0;
171  return pRes;
172 }
char * Extra_UtilStrsav(const char *s)
char * strrchr()
char* Extra_FileNameGenericAppend ( char *  pBase,
char *  pSuffix 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 185 of file extraUtilFile.c.

186 {
187  static char Buffer[1000];
188  char * pDot;
189  assert( strlen(pBase) + strlen(pSuffix) < 1000 );
190  strcpy( Buffer, pBase );
191  if ( (pDot = strrchr( Buffer, '.' )) )
192  *pDot = 0;
193  strcat( Buffer, pSuffix );
194  return Buffer;
195 }
char * strcpy()
char * strcat()
#define assert(ex)
Definition: util_old.h:213
int strlen()
char * strrchr()
char* Extra_FileNameWithoutPath ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 228 of file extraUtilFile.c.

229 {
230  char * pRes;
231  for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
232  if ( *pRes == '\\' || *pRes == '/' )
233  return pRes + 1;
234  return FileName;
235 }
int strlen()
char* Extra_FilePathWithoutName ( char *  FileName)

Definition at line 236 of file extraUtilFile.c.

237 {
238  char * pRes;
239  FileName = Abc_UtilStrsav( FileName );
240  for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
241  if ( *pRes == '\\' || *pRes == '/' )
242  {
243  *pRes = 0;
244  Extra_FileNameCorrectPath( FileName );
245  return FileName;
246  }
247  ABC_FREE( FileName );
248  return NULL;
249 }
void Extra_FileNameCorrectPath(char *FileName)
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
char* Extra_FileRead ( FILE *  pFile)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 336 of file extraUtilFile.c.

337 {
338  int nFileSize;
339  char * pBuffer;
340  int RetValue;
341  // get the file size, in bytes
342  fseek( pFile, 0, SEEK_END );
343  nFileSize = ftell( pFile );
344  // move the file current reading position to the beginning
345  rewind( pFile );
346  // load the contents of the file into memory
347  pBuffer = ABC_ALLOC( char, nFileSize + 3 );
348  RetValue = fread( pBuffer, nFileSize, 1, pFile );
349  // terminate the string with '\0'
350  pBuffer[ nFileSize + 0] = '\n';
351  pBuffer[ nFileSize + 1] = '\0';
352  return pBuffer;
353 }
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
VOID_HACK rewind()
char* Extra_FileRead2 ( FILE *  pFile,
FILE *  pFile2 
)

Definition at line 354 of file extraUtilFile.c.

355 {
356  char * pBuffer;
357  int nSize, nSize2;
358  int RetValue;
359  // get the file size, in bytes
360  fseek( pFile, 0, SEEK_END );
361  nSize = ftell( pFile );
362  rewind( pFile );
363  // get the file size, in bytes
364  fseek( pFile2, 0, SEEK_END );
365  nSize2 = ftell( pFile2 );
366  rewind( pFile2 );
367  // load the contents of the file into memory
368  pBuffer = ABC_ALLOC( char, nSize + nSize2 + 3 );
369  RetValue = fread( pBuffer, nSize, 1, pFile );
370  RetValue = fread( pBuffer + nSize, nSize2, 1, pFile2 );
371  // terminate the string with '\0'
372  pBuffer[ nSize + nSize2 + 0] = '\n';
373  pBuffer[ nSize + nSize2 + 1] = '\0';
374  return pBuffer;
375 }
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
VOID_HACK rewind()
char* Extra_FileReadContents ( char *  pFileName)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 388 of file extraUtilFile.c.

389 {
390  FILE * pFile;
391  char * pBuffer;
392  pFile = fopen( pFileName, "rb" );
393  pBuffer = pFile ? Extra_FileRead( pFile ) : NULL;
394  if ( pFile ) fclose( pFile );
395  return pBuffer;
396 }
char * Extra_FileRead(FILE *pFile)
char* Extra_FileReadContents2 ( char *  pFileName,
char *  pFileName2 
)

Definition at line 397 of file extraUtilFile.c.

398 {
399  FILE * pFile, * pFile2;
400  char * pBuffer;
401  pFile = fopen( pFileName, "rb" );
402  pFile2 = fopen( pFileName2, "rb" );
403  pBuffer = (pFile && pFile2) ? Extra_FileRead2( pFile, pFile2 ) : NULL;
404  if ( pFile ) fclose( pFile );
405  if ( pFile2 ) fclose( pFile2 );
406  return pBuffer;
407 }
char * Extra_FileRead2(FILE *pFile, FILE *pFile2)
int Extra_FileSize ( char *  pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 308 of file extraUtilFile.c.

309 {
310  FILE * pFile;
311  int nFileSize;
312  pFile = fopen( pFileName, "rb" );
313  if ( pFile == NULL )
314  {
315  printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" );
316  return 0;
317  }
318  fseek( pFile, 0, SEEK_END );
319  nFileSize = ftell( pFile );
320  fclose( pFile );
321  return nFileSize;
322 }
#define SEEK_END
Definition: zconf.h:392
void Extra_FileSort ( char *  pFileName,
char *  pFileNameOut 
)

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

Synopsis [Sorts lines in the file alphabetically.]

Description []

SideEffects []

SeeAlso []

Definition at line 757 of file extraUtilFile.c.

758 {
759  FILE * pFile;
760  char * pContents;
761  char ** pLines;
762  int i, nLines, Begin;
763  pFile = fopen( pFileName, "rb" );
764  if ( pFile == NULL )
765  {
766  printf( "Extra_FileSort(): Cannot open file \"%s\".\n", pFileName );
767  return;
768  }
769  pContents = Extra_FileRead( pFile );
770  fclose( pFile );
771  if ( pContents == NULL )
772  {
773  printf( "Extra_FileSort(): Cannot read contents of file \"%s\".\n", pFileName );
774  return;
775  }
776  // count end of lines
777  for ( nLines = 0, i = 0; pContents[i]; i++ )
778  nLines += (pContents[i] == '\n');
779  // break the file into lines
780  pLines = (char **)malloc( sizeof(char *) * nLines );
781  Begin = 0;
782  for ( nLines = 0, i = 0; pContents[i]; i++ )
783  if ( pContents[i] == '\n' )
784  {
785  pContents[i] = 0;
786  pLines[nLines++] = pContents + Begin;
787  Begin = i + 1;
788  }
789  // sort the lines
790  qsort( pLines, nLines, sizeof(char *), (int(*)(const void *,const void *))Extra_StringCompare );
791  // write a new file
792  pFile = fopen( pFileNameOut, "wb" );
793  for ( i = 0; i < nLines; i++ )
794  if ( pLines[i][0] )
795  fprintf( pFile, "%s\n", pLines[i] );
796  fclose( pFile );
797  // cleanup
798  free( pLines );
799  free( pContents );
800  // report the result
801  printf( "The file after sorting is \"%s\".\n", pFileNameOut );
802 }
char * malloc()
VOID_HACK free()
int Extra_StringCompare(const char *pp1, const char *pp2)
char * Extra_FileRead(FILE *pFile)
void Extra_PrintBinary ( FILE *  pFile,
unsigned  Sign[],
int  nBits 
)

DECLARATIONS ///.

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

Synopsis [Prints the bit string.]

Description []

SideEffects []

SeeAlso []

Definition at line 497 of file extraUtilFile.c.

498 {
499  int Remainder, nWords;
500  int w, i;
501 
502  Remainder = (nBits%(sizeof(unsigned)*8));
503  nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
504 
505  for ( w = nWords-1; w >= 0; w-- )
506  for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
507  fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
508 
509 // fprintf( pFile, "\n" );
510 }
int nWords
Definition: abcNpn.c:127
void Extra_PrintHex ( FILE *  pFile,
unsigned *  pTruth,
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 620 of file extraUtilFile.c.

621 {
622  int nMints, nDigits, Digit, k;
623 
624  // write the number into the file
625  fprintf( pFile, "0x" );
626  nMints = (1 << nVars);
627  nDigits = nMints / 4 + ((nMints % 4) > 0);
628  for ( k = nDigits - 1; k >= 0; k-- )
629  {
630  Digit = ((pTruth[k/8] >> (k * 4)) & 15);
631  if ( Digit < 10 )
632  fprintf( pFile, "%d", Digit );
633  else
634  fprintf( pFile, "%c", 'A' + Digit-10 );
635  }
636 // fprintf( pFile, "\n" );
637 }
void Extra_PrintHexadecimal ( FILE *  pFile,
unsigned  Sign[],
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 565 of file extraUtilFile.c.

566 {
567  int nDigits, Digit, k;
568  // write the number into the file
569  nDigits = (1 << nVars) / 4;
570  for ( k = nDigits - 1; k >= 0; k-- )
571  {
572  Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
573  if ( Digit < 10 )
574  fprintf( pFile, "%d", Digit );
575  else
576  fprintf( pFile, "%c", 'a' + Digit-10 );
577  }
578 // fprintf( pFile, "\n" );
579 }
void Extra_PrintHexadecimalString ( char *  pString,
unsigned  Sign[],
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 592 of file extraUtilFile.c.

593 {
594  int nDigits, Digit, k;
595  // write the number into the file
596  nDigits = (1 << nVars) / 4;
597  for ( k = nDigits - 1; k >= 0; k-- )
598  {
599  Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
600  if ( Digit < 10 )
601  *pString++ = '0' + Digit;
602  else
603  *pString++ = 'a' + Digit-10;
604  }
605 // fprintf( pFile, "\n" );
606  *pString = 0;
607 }
void Extra_PrintHexReverse ( FILE *  pFile,
unsigned *  pTruth,
int  nVars 
)

Definition at line 638 of file extraUtilFile.c.

639 {
640  int nMints, nDigits, Digit, k;
641 
642  // write the number into the file
643  fprintf( pFile, "0x" );
644  nMints = (1 << nVars);
645  nDigits = nMints / 4 + ((nMints % 4) > 0);
646  for ( k = 0; k < nDigits; k++ )
647  {
648  Digit = ((pTruth[k/8] >> (k * 4)) & 15);
649  if ( Digit < 10 )
650  fprintf( pFile, "%d", Digit );
651  else
652  fprintf( pFile, "%c", 'A' + Digit-10 );
653  }
654 // fprintf( pFile, "\n" );
655 }
void Extra_PrintSymbols ( FILE *  pFile,
char  Char,
int  nTimes,
int  fPrintNewLine 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 668 of file extraUtilFile.c.

669 {
670  int i;
671  for ( i = 0; i < nTimes; i++ )
672  printf( "%c", Char );
673  if ( fPrintNewLine )
674  printf( "\n" );
675 }
char Char
Definition: bzlib_private.h:43
unsigned Extra_ReadBinary ( char *  Buffer)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 470 of file extraUtilFile.c.

471 {
472  unsigned Result;
473  int i;
474 
475  Result = 0;
476  for ( i = 0; Buffer[i]; i++ )
477  if ( Buffer[i] == '0' || Buffer[i] == '1' )
478  Result = Result * 2 + Buffer[i] - '0';
479  else
480  {
481  assert( 0 );
482  }
483  return Result;
484 }
#define assert(ex)
Definition: util_old.h:213
int Extra_ReadHex ( unsigned  Sign[],
char *  pString,
int  nDigits 
)

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

Synopsis [Reads the hex unsigned into the bit-string.]

Description []

SideEffects []

SeeAlso []

Definition at line 523 of file extraUtilFile.c.

524 {
525  int Digit, k, c;
526  for ( k = 0; k < nDigits; k++ )
527  {
528  c = nDigits-1-k;
529  if ( pString[c] >= '0' && pString[c] <= '9' )
530  Digit = pString[c] - '0';
531  else if ( pString[c] >= 'A' && pString[c] <= 'F' )
532  Digit = pString[c] - 'A' + 10;
533  else if ( pString[c] >= 'a' && pString[c] <= 'f' )
534  Digit = pString[c] - 'a' + 10;
535  else { assert( 0 ); return 0; }
536  Sign[k/8] |= ( (Digit & 15) << ((k%8) * 4) );
537  }
538  return 1;
539 }
#define assert(ex)
Definition: util_old.h:213
int Extra_ReadHexadecimal ( unsigned  Sign[],
char *  pString,
int  nVars 
)

Definition at line 540 of file extraUtilFile.c.

541 {
542  int nWords, nDigits, k;
543  nWords = Extra_TruthWordNum( nVars );
544  for ( k = 0; k < nWords; k++ )
545  Sign[k] = 0;
546  // read the number from the string
547  nDigits = (1 << nVars) / 4;
548  if ( nDigits == 0 )
549  nDigits = 1;
550  Extra_ReadHex( Sign, pString, nDigits );
551  return 1;
552 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
int Extra_ReadHex(unsigned Sign[], char *pString, int nDigits)
char* Extra_StringAppend ( char *  pStrGiven,
char *  pStrAdd 
)

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

Synopsis [Appends the string.]

Description [Assumes that the given string (pStrGiven) has been allocated before using malloc(). The additional string has not been allocated. Allocs more root, appends the additional part, frees the old given string.]

SideEffects []

SeeAlso []

Definition at line 690 of file extraUtilFile.c.

691 {
692  char * pTemp;
693  if ( pStrGiven )
694  {
695  pTemp = ABC_ALLOC( char, strlen(pStrGiven) + strlen(pStrAdd) + 2 );
696  sprintf( pTemp, "%s%s", pStrGiven, pStrAdd );
697  ABC_FREE( pStrGiven );
698  }
699  else
700  pTemp = Extra_UtilStrsav( pStrAdd );
701  return pTemp;
702 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
void Extra_StringClean ( char *  pStrGiven,
char *  pCharKeep 
)

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

Synopsis [Only keep characters belonging to the second string.]

Description []

SideEffects []

SeeAlso []

Definition at line 715 of file extraUtilFile.c.

716 {
717  char * pTemp, * pChar, * pSave = pStrGiven;
718  for ( pTemp = pStrGiven; *pTemp; pTemp++ )
719  {
720  for ( pChar = pCharKeep; *pChar; pChar++ )
721  if ( *pTemp == *pChar )
722  break;
723  if ( *pChar == 0 )
724  continue;
725  *pSave++ = *pTemp;
726  }
727  *pSave = 0;
728 }
int Extra_StringCompare ( const char *  pp1,
const char *  pp2 
)

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

Synopsis [String comparison procedure.]

Description []

SideEffects []

SeeAlso []

Definition at line 741 of file extraUtilFile.c.

742 {
743  return strcmp(*(char **)pp1, *(char **)pp2);
744 }
int strcmp()
char* Extra_TimeStamp ( )

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

Synopsis [Returns the time stamp.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 446 of file extraUtilFile.c.

447 {
448  static char Buffer[100];
449  char * TimeStamp;
450  time_t ltime;
451  // get the current time
452  time( &ltime );
453  TimeStamp = asctime( localtime( &ltime ) );
454  TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
455  strcpy( Buffer, TimeStamp );
456  return Buffer;
457 }
char * strcpy()
int strlen()