#include "extra.h"
Go to the source code of this file.
Functions | |
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) |
int | Extra_FileSize (char *pFileName) |
char * | Extra_FileRead (FILE *pFile) |
char * | Extra_TimeStamp () |
unsigned | Extra_ReadBinary (char *Buffer) |
void | Extra_PrintBinary (FILE *pFile, unsigned Sign[], int nBits) |
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 uTruth, int nVars) |
void | Extra_PrintSymbols (FILE *pFile, char Char, int nTimes, int fPrintNewLine) |
char * | Extra_StringAppend (char *pStrGiven, char *pStrAdd) |
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 [
]AutomaticStart AutomaticEnd Function*************************************************************
Synopsis [Tries to find a file name with a different extension.]
Description []
SideEffects []
SeeAlso []
Definition at line 68 of file extraUtilFile.c.
00069 { 00070 FILE * pFile; 00071 char * pFileNameOther; 00072 char * pFileGen; 00073 00074 if ( pS1 == NULL ) 00075 return NULL; 00076 00077 // get the generic file name 00078 pFileGen = Extra_FileNameGeneric( pFileNameWrong ); 00079 pFileNameOther = Extra_FileNameAppend( pFileGen, pS1 ); 00080 pFile = fopen( pFileNameOther, "r" ); 00081 if ( pFile == NULL && pS2 ) 00082 { // try one more 00083 pFileNameOther = Extra_FileNameAppend( pFileGen, pS2 ); 00084 pFile = fopen( pFileNameOther, "r" ); 00085 if ( pFile == NULL && pS3 ) 00086 { // try one more 00087 pFileNameOther = Extra_FileNameAppend( pFileGen, pS3 ); 00088 pFile = fopen( pFileNameOther, "r" ); 00089 if ( pFile == NULL && pS4 ) 00090 { // try one more 00091 pFileNameOther = Extra_FileNameAppend( pFileGen, pS4 ); 00092 pFile = fopen( pFileNameOther, "r" ); 00093 if ( pFile == NULL && pS5 ) 00094 { // try one more 00095 pFileNameOther = Extra_FileNameAppend( pFileGen, pS5 ); 00096 pFile = fopen( pFileNameOther, "r" ); 00097 } 00098 } 00099 } 00100 } 00101 FREE( pFileGen ); 00102 if ( pFile ) 00103 { 00104 fclose( pFile ); 00105 return pFileNameOther; 00106 } 00107 // did not find :( 00108 return NULL; 00109 }
char* Extra_FileNameAppend | ( | char * | pBase, | |
char * | pSuffix | |||
) |
Function*************************************************************
Synopsis [Returns the composite name of the file.]
Description []
SideEffects []
SeeAlso []
Definition at line 143 of file extraUtilFile.c.
00144 { 00145 static char Buffer[500]; 00146 sprintf( Buffer, "%s%s", pBase, pSuffix ); 00147 return Buffer; 00148 }
char* Extra_FileNameExtension | ( | char * | FileName | ) |
Function*************************************************************
Synopsis [Returns the pointer to the file extension.]
Description []
SideEffects []
SeeAlso []
Definition at line 122 of file extraUtilFile.c.
char* Extra_FileNameGeneric | ( | char * | FileName | ) |
Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
Definition at line 161 of file extraUtilFile.c.
00162 { 00163 char * pDot; 00164 char * pUnd; 00165 char * pRes; 00166 00167 // find the generic name of the file 00168 pRes = Extra_UtilStrsav( FileName ); 00169 // find the pointer to the "." symbol in the file name 00170 // pUnd = strstr( FileName, "_" ); 00171 pUnd = NULL; 00172 pDot = strstr( FileName, "." ); 00173 if ( pUnd ) 00174 pRes[pUnd - FileName] = 0; 00175 else if ( pDot ) 00176 pRes[pDot - FileName] = 0; 00177 return pRes; 00178 }
char* Extra_FileRead | ( | FILE * | pFile | ) |
Function*************************************************************
Synopsis [Read the file into the internal buffer.]
Description []
SideEffects []
SeeAlso []
Definition at line 219 of file extraUtilFile.c.
00220 { 00221 int nFileSize; 00222 char * pBuffer; 00223 // get the file size, in bytes 00224 fseek( pFile, 0, SEEK_END ); 00225 nFileSize = ftell( pFile ); 00226 // move the file current reading position to the beginning 00227 rewind( pFile ); 00228 // load the contents of the file into memory 00229 pBuffer = ALLOC( char, nFileSize + 3 ); 00230 fread( pBuffer, nFileSize, 1, pFile ); 00231 // terminate the string with '\0' 00232 pBuffer[ nFileSize + 0] = '\n'; 00233 pBuffer[ nFileSize + 1] = '\0'; 00234 return pBuffer; 00235 }
int Extra_FileSize | ( | char * | pFileName | ) |
Function*************************************************************
Synopsis [Returns the file size.]
Description [The file should be closed.]
SideEffects []
SeeAlso []
Definition at line 191 of file extraUtilFile.c.
00192 { 00193 FILE * pFile; 00194 int nFileSize; 00195 pFile = fopen( pFileName, "r" ); 00196 if ( pFile == NULL ) 00197 { 00198 printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" ); 00199 return 0; 00200 } 00201 fseek( pFile, 0, SEEK_END ); 00202 nFileSize = ftell( pFile ); 00203 fclose( pFile ); 00204 return nFileSize; 00205 }
void Extra_PrintBinary | ( | FILE * | pFile, | |
unsigned | Sign[], | |||
int | nBits | |||
) |
Function*************************************************************
Synopsis [Prints the bit string.]
Description []
SideEffects []
SeeAlso []
Definition at line 299 of file extraUtilFile.c.
00300 { 00301 int Remainder, nWords; 00302 int w, i; 00303 00304 Remainder = (nBits%(sizeof(unsigned)*8)); 00305 nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0); 00306 00307 for ( w = nWords-1; w >= 0; w-- ) 00308 for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- ) 00309 fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) ); 00310 00311 // fprintf( pFile, "\n" ); 00312 }
void Extra_PrintHex | ( | FILE * | pFile, | |
unsigned | uTruth, | |||
int | nVars | |||
) |
Function*************************************************************
Synopsis [Prints the hex unsigned into a file.]
Description []
SideEffects []
SeeAlso []
Definition at line 416 of file extraUtilFile.c.
00417 { 00418 int nMints, nDigits, Digit, k; 00419 00420 // write the number into the file 00421 fprintf( pFile, "0x" ); 00422 nMints = (1 << nVars); 00423 nDigits = nMints / 4; 00424 for ( k = nDigits - 1; k >= 0; k-- ) 00425 { 00426 Digit = ((uTruth >> (k * 4)) & 15); 00427 if ( Digit < 10 ) 00428 fprintf( pFile, "%d", Digit ); 00429 else 00430 fprintf( pFile, "%c", 'a' + Digit-10 ); 00431 } 00432 // fprintf( pFile, "\n" ); 00433 }
void Extra_PrintHexadecimal | ( | FILE * | pFile, | |
unsigned | Sign[], | |||
int | nVars | |||
) |
Function*************************************************************
Synopsis [Prints the hex unsigned into a file.]
Description []
SideEffects []
SeeAlso []
Definition at line 361 of file extraUtilFile.c.
00362 { 00363 int nDigits, Digit, k; 00364 // write the number into the file 00365 nDigits = (1 << nVars) / 4; 00366 for ( k = nDigits - 1; k >= 0; k-- ) 00367 { 00368 Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15); 00369 if ( Digit < 10 ) 00370 fprintf( pFile, "%d", Digit ); 00371 else 00372 fprintf( pFile, "%c", 'a' + Digit-10 ); 00373 } 00374 // fprintf( pFile, "\n" ); 00375 }
void Extra_PrintHexadecimalString | ( | char * | pString, | |
unsigned | Sign[], | |||
int | nVars | |||
) |
Function*************************************************************
Synopsis [Prints the hex unsigned into a file.]
Description []
SideEffects []
SeeAlso []
Definition at line 388 of file extraUtilFile.c.
00389 { 00390 int nDigits, Digit, k; 00391 // write the number into the file 00392 nDigits = (1 << nVars) / 4; 00393 for ( k = nDigits - 1; k >= 0; k-- ) 00394 { 00395 Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15); 00396 if ( Digit < 10 ) 00397 *pString++ = '0' + Digit; 00398 else 00399 *pString++ = 'a' + Digit-10; 00400 } 00401 // fprintf( pFile, "\n" ); 00402 *pString = 0; 00403 }
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 446 of file extraUtilFile.c.
unsigned Extra_ReadBinary | ( | char * | Buffer | ) |
Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
Definition at line 272 of file extraUtilFile.c.
00273 { 00274 unsigned Result; 00275 int i; 00276 00277 Result = 0; 00278 for ( i = 0; Buffer[i]; i++ ) 00279 if ( Buffer[i] == '0' || Buffer[i] == '1' ) 00280 Result = Result * 2 + Buffer[i] - '0'; 00281 else 00282 { 00283 assert( 0 ); 00284 } 00285 return Result; 00286 }
int Extra_ReadHexadecimal | ( | unsigned | Sign[], | |
char * | pString, | |||
int | nVars | |||
) |
Function*************************************************************
Synopsis [Reads the hex unsigned into the bit-string.]
Description []
SideEffects []
SeeAlso []
Definition at line 325 of file extraUtilFile.c.
00326 { 00327 int nWords, nDigits, Digit, k, c; 00328 nWords = Extra_TruthWordNum( nVars ); 00329 for ( k = 0; k < nWords; k++ ) 00330 Sign[k] = 0; 00331 // read the number from the string 00332 nDigits = (1 << nVars) / 4; 00333 if ( nDigits == 0 ) 00334 nDigits = 1; 00335 for ( k = 0; k < nDigits; k++ ) 00336 { 00337 c = nDigits-1-k; 00338 if ( pString[c] >= '0' && pString[c] <= '9' ) 00339 Digit = pString[c] - '0'; 00340 else if ( pString[c] >= 'A' && pString[c] <= 'F' ) 00341 Digit = pString[c] - 'A' + 10; 00342 else if ( pString[c] >= 'a' && pString[c] <= 'f' ) 00343 Digit = pString[c] - 'a' + 10; 00344 else { assert( 0 ); return 0; } 00345 Sign[k/8] |= ( (Digit & 15) << ((k%8) * 4) ); 00346 } 00347 return 1; 00348 }
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 468 of file extraUtilFile.c.
char* Extra_TimeStamp | ( | ) |
Function*************************************************************
Synopsis [Returns the time stamp.]
Description [The file should be closed.]
SideEffects []
SeeAlso []
Definition at line 248 of file extraUtilFile.c.