ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
extraUtilFile.c File Reference
#include <limits.h>
#include "extra.h"
Include dependency graph for extraUtilFile.c:

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_FileInTheSameDir (char *pPathFile, char *pFileName)
 
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 ///.
 
void Extra_PrintBinary2 (FILE *pFile, unsigned Sign[], int nBits)
 
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_PrintHex2 (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

◆ Extra_FileCheck()

int Extra_FileCheck ( char * pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 300 of file extraUtilFile.c.

301{
302 FILE * pFile;
303 pFile = fopen( pFileName, "rb" );
304 if ( pFile == NULL )
305 {
306 printf( "Extra_FileCheck(): File \"%s\" does not exist.\n", pFileName );
307 return 0;
308 }
309 fseek( pFile, 0, SEEK_END );
310 if ( ftell( pFile ) == 0 )
311 printf( "Extra_FileCheck(): File \"%s\" is empty.\n", pFileName );
312 fclose( pFile );
313 return 1;
314}
#define SEEK_END
Definition zconf.h:392
Here is the caller graph for this function:

◆ Extra_FileDesignName()

char * Extra_FileDesignName ( char * pFileName)

Definition at line 269 of file extraUtilFile.c.

270{
271 char * pBeg, * pEnd, * pStore, * pCur;
272 // find the first dot
273 for ( pEnd = pFileName; *pEnd; pEnd++ )
274 if ( *pEnd == '.' )
275 break;
276 // find the first char
277 for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
278 if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
279 break;
280 pBeg++;
281 // fill up storage
282 pStore = ABC_ALLOC( char, pEnd - pBeg + 1 );
283 for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
284 *pCur = *pBeg;
285 *pCur = 0;
286 return pStore;
287}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
Here is the caller graph for this function:

◆ Extra_FileGetSimilarName()

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 78 of file extraUtilFile.c.

79{
80 FILE * pFile;
81 char * pFileNameOther;
82 char * pFileGen;
83
84 if ( pS1 == NULL )
85 return NULL;
86
87 // get the generic file name
88 pFileGen = Extra_FileNameGeneric( pFileNameWrong );
89 pFileNameOther = Extra_FileNameAppend( pFileGen, pS1 );
90 pFile = fopen( pFileNameOther, "r" );
91 if ( pFile == NULL && pS2 )
92 { // try one more
93 pFileNameOther = Extra_FileNameAppend( pFileGen, pS2 );
94 pFile = fopen( pFileNameOther, "r" );
95 if ( pFile == NULL && pS3 )
96 { // try one more
97 pFileNameOther = Extra_FileNameAppend( pFileGen, pS3 );
98 pFile = fopen( pFileNameOther, "r" );
99 if ( pFile == NULL && pS4 )
100 { // try one more
101 pFileNameOther = Extra_FileNameAppend( pFileGen, pS4 );
102 pFile = fopen( pFileNameOther, "r" );
103 if ( pFile == NULL && pS5 )
104 { // try one more
105 pFileNameOther = Extra_FileNameAppend( pFileGen, pS5 );
106 pFile = fopen( pFileNameOther, "r" );
107 }
108 }
109 }
110 }
111 ABC_FREE( pFileGen );
112 if ( pFile )
113 {
114 fclose( pFile );
115 return pFileNameOther;
116 }
117 // did not find :(
118 return NULL;
119}
#define ABC_FREE(obj)
Definition abc_global.h:267
char * Extra_FileNameAppend(char *pBase, char *pSuffix)
char * Extra_FileNameGeneric(char *FileName)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileInTheSameDir()

char * Extra_FileInTheSameDir ( char * pPathFile,
char * pFileName )

Definition at line 257 of file extraUtilFile.c.

258{
259 static char pBuffer[1000]; char * pThis;
260 assert( strlen(pPathFile) + strlen(pFileName) < 990 );
261 memmove( pBuffer, pPathFile, strlen(pPathFile) );
262 for ( pThis = pBuffer + strlen(pPathFile) - 1; pThis >= pBuffer; pThis-- )
263 if ( *pThis == '\\' || *pThis == '/' )
264 break;
265 memmove( ++pThis, pFileName, strlen(pFileName) );
266 pThis[strlen(pFileName)] = '\0';
267 return pBuffer;
268}
#define assert(ex)
Definition util_old.h:213
int strlen()
char * memmove()
Here is the call graph for this function:

◆ Extra_FileIsType()

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 439 of file extraUtilFile.c.

440{
441 int lenS, lenF = strlen(pFileName);
442 lenS = pS1 ? strlen(pS1) : 0;
443 if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS1, lenS ) )
444 return 1;
445 lenS = pS2 ? strlen(pS2) : 0;
446 if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS2, lenS ) )
447 return 1;
448 lenS = pS3 ? strlen(pS3) : 0;
449 if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS3, lenS ) )
450 return 1;
451 return 0;
452}
int strncmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileLineNumAdd()

void Extra_FileLineNumAdd ( char * pFileName,
char * pFileNameOut )

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

Synopsis [Appends line number in the end.]

Description []

SideEffects []

SeeAlso []

Definition at line 857 of file extraUtilFile.c.

858{
859 char Buffer[1000];
860 FILE * pFile;
861 FILE * pFile2;
862 int iLine;
863 pFile = fopen( pFileName, "rb" );
864 if ( pFile == NULL )
865 {
866 printf( "Extra_FileLineNumAdd(): Cannot open file \"%s\".\n", pFileName );
867 return;
868 }
869 pFile2 = fopen( pFileNameOut, "wb" );
870 if ( pFile2 == NULL )
871 {
872 fclose( pFile );
873 printf( "Extra_FileLineNumAdd(): Cannot open file \"%s\".\n", pFileNameOut );
874 return;
875 }
876 for ( iLine = 0; fgets( Buffer, 1000, pFile ); iLine++ )
877 {
878 sprintf( Buffer + strlen(Buffer) - 2, "%03d\n%c", iLine, 0 );
879 fputs( Buffer, pFile2 );
880 }
881 fclose( pFile );
882 fclose( pFile2 );
883 // report the result
884 printf( "The resulting file is \"%s\".\n", pFileNameOut );
885}
char * sprintf()
Here is the call graph for this function:

◆ Extra_FileNameAppend()

char * Extra_FileNameAppend ( char * pBase,
char * pSuffix )

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 153 of file extraUtilFile.c.

154{
155 static char Buffer[500];
156 assert( strlen(pBase) + strlen(pSuffix) < 500 );
157 sprintf( Buffer, "%s%s", pBase, pSuffix );
158 return Buffer;
159}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileNameCorrectPath()

void Extra_FileNameCorrectPath ( char * FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 215 of file extraUtilFile.c.

216{
217 char * pStart;
218 if ( FileName )
219 for ( pStart = FileName; *pStart; pStart++ )
220 if ( *pStart == '>' || *pStart == '\\' )
221 *pStart = '/';
222}
Here is the caller graph for this function:

◆ Extra_FileNameExtension()

char * Extra_FileNameExtension ( char * FileName)

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

Synopsis [Returns the pointer to the file extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 132 of file extraUtilFile.c.

133{
134 char * pDot;
135 // find the last "dot" in the file name, if it is present
136 for ( pDot = FileName + strlen(FileName)-1; pDot >= FileName; pDot-- )
137 if ( *pDot == '.' )
138 return pDot + 1;
139 return FileName;
140}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileNameGeneric()

char * Extra_FileNameGeneric ( char * FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 172 of file extraUtilFile.c.

173{
174 char * pDot, * pRes;
175 pRes = Extra_UtilStrsav( FileName );
176 if ( (pDot = strrchr( pRes, '.' )) )
177 *pDot = 0;
178 return pRes;
179}
char * Extra_UtilStrsav(const char *s)
char * strrchr()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileNameGenericAppend()

char * Extra_FileNameGenericAppend ( char * pBase,
char * pSuffix )

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file extraUtilFile.c.

193{
194 static char Buffer[PATH_MAX];
195 char * pDot;
196 assert( strlen(pBase) + strlen(pSuffix) < PATH_MAX );
197 strcpy( Buffer, pBase );
198 if ( (pDot = strrchr( Buffer, '.' )) )
199 *pDot = 0;
200 strcat( Buffer, pSuffix );
201 return Buffer;
202}
char * strcpy()
char * strcat()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileNameWithoutPath()

char * Extra_FileNameWithoutPath ( char * FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 235 of file extraUtilFile.c.

236{
237 char * pRes;
238 for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
239 if ( *pRes == '\\' || *pRes == '/' )
240 return pRes + 1;
241 return FileName;
242}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FilePathWithoutName()

char * Extra_FilePathWithoutName ( char * FileName)

Definition at line 243 of file extraUtilFile.c.

244{
245 char * pRes;
246 FileName = Abc_UtilStrsav( FileName );
247 for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
248 if ( *pRes == '\\' || *pRes == '/' )
249 {
250 pRes[1] = '\0';
251 Extra_FileNameCorrectPath( FileName );
252 return FileName;
253 }
254 ABC_FREE( FileName );
255 return NULL;
256}
void Extra_FileNameCorrectPath(char *FileName)
Here is the call graph for this function:

◆ Extra_FileRead()

char * Extra_FileRead ( FILE * pFile)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 355 of file extraUtilFile.c.

356{
357 int nFileSize;
358 char * pBuffer;
359 int RetValue;
360 // get the file size, in bytes
361 fseek( pFile, 0, SEEK_END );
362 nFileSize = ftell( pFile );
363 // move the file current reading position to the beginning
364 rewind( pFile );
365 // load the contents of the file into memory
366 pBuffer = ABC_ALLOC( char, nFileSize + 3 );
367 RetValue = fread( pBuffer, nFileSize, 1, pFile );
368 // terminate the string with '\0'
369 pBuffer[ nFileSize + 0] = '\n';
370 pBuffer[ nFileSize + 1] = '\0';
371 return pBuffer;
372}
VOID_HACK rewind()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileRead2()

char * Extra_FileRead2 ( FILE * pFile,
FILE * pFile2 )

Definition at line 373 of file extraUtilFile.c.

374{
375 char * pBuffer;
376 int nSize, nSize2;
377 int RetValue;
378 // get the file size, in bytes
379 fseek( pFile, 0, SEEK_END );
380 nSize = ftell( pFile );
381 rewind( pFile );
382 // get the file size, in bytes
383 fseek( pFile2, 0, SEEK_END );
384 nSize2 = ftell( pFile2 );
385 rewind( pFile2 );
386 // load the contents of the file into memory
387 pBuffer = ABC_ALLOC( char, nSize + nSize2 + 3 );
388 RetValue = fread( pBuffer, nSize, 1, pFile );
389 RetValue = fread( pBuffer + nSize, nSize2, 1, pFile2 );
390 // terminate the string with '\0'
391 pBuffer[ nSize + nSize2 + 0] = '\n';
392 pBuffer[ nSize + nSize2 + 1] = '\0';
393 return pBuffer;
394}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileReadContents()

char * Extra_FileReadContents ( char * pFileName)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 407 of file extraUtilFile.c.

408{
409 FILE * pFile;
410 char * pBuffer;
411 pFile = fopen( pFileName, "rb" );
412 pBuffer = pFile ? Extra_FileRead( pFile ) : NULL;
413 if ( pFile ) fclose( pFile );
414 return pBuffer;
415}
char * Extra_FileRead(FILE *pFile)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_FileReadContents2()

char * Extra_FileReadContents2 ( char * pFileName,
char * pFileName2 )

Definition at line 416 of file extraUtilFile.c.

417{
418 FILE * pFile, * pFile2;
419 char * pBuffer;
420 pFile = fopen( pFileName, "rb" );
421 pFile2 = fopen( pFileName2, "rb" );
422 pBuffer = (pFile && pFile2) ? Extra_FileRead2( pFile, pFile2 ) : NULL;
423 if ( pFile ) fclose( pFile );
424 if ( pFile2 ) fclose( pFile2 );
425 return pBuffer;
426}
char * Extra_FileRead2(FILE *pFile, FILE *pFile2)
Here is the call graph for this function:

◆ Extra_FileSize()

int Extra_FileSize ( char * pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 327 of file extraUtilFile.c.

328{
329 FILE * pFile;
330 int nFileSize;
331 pFile = fopen( pFileName, "rb" );
332 if ( pFile == NULL )
333 {
334 printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" );
335 return 0;
336 }
337 fseek( pFile, 0, SEEK_END );
338 nFileSize = ftell( pFile );
339 fclose( pFile );
340 return nFileSize;
341}
Here is the caller graph for this function:

◆ Extra_FileSort()

void Extra_FileSort ( char * pFileName,
char * pFileNameOut )

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

Synopsis [Sorts lines in the file alphabetically.]

Description []

SideEffects []

SeeAlso []

Definition at line 798 of file extraUtilFile.c.

799{
800 FILE * pFile;
801 char * pContents;
802 char ** pLines;
803 int i, nLines, Begin;
804 pFile = fopen( pFileName, "rb" );
805 if ( pFile == NULL )
806 {
807 printf( "Extra_FileSort(): Cannot open file \"%s\".\n", pFileName );
808 return;
809 }
810 pContents = Extra_FileRead( pFile );
811 fclose( pFile );
812 if ( pContents == NULL )
813 {
814 printf( "Extra_FileSort(): Cannot read contents of file \"%s\".\n", pFileName );
815 return;
816 }
817 // count end of lines
818 for ( nLines = 0, i = 0; pContents[i]; i++ )
819 nLines += (pContents[i] == '\n');
820 // break the file into lines
821 pLines = (char **)malloc( sizeof(char *) * nLines );
822 Begin = 0;
823 for ( nLines = 0, i = 0; pContents[i]; i++ )
824 if ( pContents[i] == '\n' )
825 {
826 pContents[i] = 0;
827 pLines[nLines++] = pContents + Begin;
828 Begin = i + 1;
829 }
830 // sort the lines
831 qsort( pLines, (size_t)nLines, sizeof(char *), (int(*)(const void *,const void *))Extra_StringCompare );
832 // write a new file
833 pFile = fopen( pFileNameOut, "wb" );
834 for ( i = 0; i < nLines; i++ )
835 if ( pLines[i][0] )
836 fprintf( pFile, "%s\n", pLines[i] );
837 fclose( pFile );
838 // cleanup
839 free( pLines );
840 free( pContents );
841 // report the result
842 printf( "The file after sorting is \"%s\".\n", pFileNameOut );
843}
int Extra_StringCompare(const char *pp1, const char *pp2)
VOID_HACK free()
char * malloc()
Here is the call graph for this function:

◆ Extra_PrintBinary()

void Extra_PrintBinary ( FILE * pFile,
unsigned Sign[],
int nBits )

DECLARATIONS ///.

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

Synopsis [Prints the bit string.]

Description []

SideEffects []

SeeAlso []

Definition at line 516 of file extraUtilFile.c.

517{
518 int i;
519 for ( i = nBits-1; i >= 0; i-- )
520 fprintf( pFile, "%c", '0' + Abc_InfoHasBit(Sign, i) );
521// fprintf( pFile, "\n" );
522}
Here is the caller graph for this function:

◆ Extra_PrintBinary2()

void Extra_PrintBinary2 ( FILE * pFile,
unsigned Sign[],
int nBits )

Definition at line 523 of file extraUtilFile.c.

524{
525 int i;
526 for ( i = 0; i < nBits; i++ )
527 fprintf( pFile, "%c", '0' + Abc_InfoHasBit(Sign, i) );
528// fprintf( pFile, "\n" );
529}
Here is the caller graph for this function:

◆ Extra_PrintHex()

void Extra_PrintHex ( FILE * pFile,
unsigned * pTruth,
int nVars )

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 643 of file extraUtilFile.c.

644{
645 int nMints, nDigits, Digit, k;
646
647 // write the number into the file
648 fprintf( pFile, "0x" );
649 nMints = (1 << nVars);
650 nDigits = nMints / 4 + ((nMints % 4) > 0);
651 for ( k = nDigits - 1; k >= 0; k-- )
652 {
653 Digit = ((pTruth[k/8] >> (k * 4)) & 15);
654 if ( Digit < 10 )
655 fprintf( pFile, "%d", Digit );
656 else
657 fprintf( pFile, "%c", 'A' + Digit-10 );
658 }
659// fprintf( pFile, "\n" );
660}
Here is the caller graph for this function:

◆ Extra_PrintHex2()

void Extra_PrintHex2 ( FILE * pFile,
unsigned * pTruth,
int nVars )

Definition at line 661 of file extraUtilFile.c.

662{
663 int nMints, nDigits, Digit, k;
664
665 // write the number into the file
666 //fprintf( pFile, "0x" );
667 nMints = (1 << nVars);
668 nDigits = nMints / 4 + ((nMints % 4) > 0);
669 for ( k = nDigits - 1; k >= 0; k-- )
670 {
671 Digit = ((pTruth[k/8] >> (k * 4)) & 15);
672 if ( Digit < 10 )
673 fprintf( pFile, "%d", Digit );
674 else
675 fprintf( pFile, "%c", 'A' + Digit-10 );
676 }
677// fprintf( pFile, "\n" );
678}
Here is the caller graph for this function:

◆ Extra_PrintHexadecimal()

void Extra_PrintHexadecimal ( FILE * pFile,
unsigned Sign[],
int nVars )

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 584 of file extraUtilFile.c.

585{
586 int nDigits, Digit, k;
587 // write the number into the file
588 nDigits = (1 << nVars) / 4;
589 for ( k = nDigits - 1; k >= 0; k-- )
590 {
591 Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
592 if ( Digit < 10 )
593 fprintf( pFile, "%d", Digit );
594 else
595 fprintf( pFile, "%c", 'a' + Digit-10 );
596 }
597// fprintf( pFile, "\n" );
598}
Here is the caller graph for this function:

◆ Extra_PrintHexadecimalString()

void Extra_PrintHexadecimalString ( char * pString,
unsigned Sign[],
int nVars )

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 611 of file extraUtilFile.c.

612{
613 int nDigits, Digit, k;
614 if ( nVars == 0 && !(Sign[0] & 1) ) { sprintf(pString, "0"); return; } // const0
615 if ( nVars == 0 && (Sign[0] & 1) ) { sprintf(pString, "1"); return; } // const1
616 if ( nVars == 1 && (Sign[0] & 1) ) { sprintf(pString, "1"); return; } // inverter
617 if ( nVars == 1 && !(Sign[0] & 1) ) { sprintf(pString, "2"); return; } // buffer
618 // write the number into the file
619 nDigits = (1 << nVars) / 4;
620 for ( k = nDigits - 1; k >= 0; k-- )
621 {
622 Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
623 if ( Digit < 10 )
624 *pString++ = '0' + Digit;
625 else
626 *pString++ = 'a' + Digit-10;
627 }
628// fprintf( pFile, "\n" );
629 *pString = 0;
630}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_PrintHexReverse()

void Extra_PrintHexReverse ( FILE * pFile,
unsigned * pTruth,
int nVars )

Definition at line 679 of file extraUtilFile.c.

680{
681 int nMints, nDigits, Digit, k;
682
683 // write the number into the file
684 fprintf( pFile, "0x" );
685 nMints = (1 << nVars);
686 nDigits = nMints / 4 + ((nMints % 4) > 0);
687 for ( k = 0; k < nDigits; k++ )
688 {
689 Digit = ((pTruth[k/8] >> (k * 4)) & 15);
690 if ( Digit < 10 )
691 fprintf( pFile, "%d", Digit );
692 else
693 fprintf( pFile, "%c", 'A' + Digit-10 );
694 }
695// fprintf( pFile, "\n" );
696}

◆ Extra_PrintSymbols()

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 709 of file extraUtilFile.c.

710{
711 int i;
712 for ( i = 0; i < nTimes; i++ )
713 printf( "%c", Char );
714 if ( fPrintNewLine )
715 printf( "\n" );
716}
char Char

◆ Extra_ReadBinary()

unsigned Extra_ReadBinary ( char * Buffer)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 489 of file extraUtilFile.c.

490{
491 unsigned Result;
492 int i;
493
494 Result = 0;
495 for ( i = 0; Buffer[i]; i++ )
496 if ( Buffer[i] == '0' || Buffer[i] == '1' )
497 Result = Result * 2 + Buffer[i] - '0';
498 else
499 {
500 assert( 0 );
501 }
502 return Result;
503}
Here is the caller graph for this function:

◆ Extra_ReadHex()

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 542 of file extraUtilFile.c.

543{
544 int Digit, k, c;
545 for ( k = 0; k < nDigits; k++ )
546 {
547 c = nDigits-1-k;
548 if ( pString[c] >= '0' && pString[c] <= '9' )
549 Digit = pString[c] - '0';
550 else if ( pString[c] >= 'A' && pString[c] <= 'F' )
551 Digit = pString[c] - 'A' + 10;
552 else if ( pString[c] >= 'a' && pString[c] <= 'f' )
553 Digit = pString[c] - 'a' + 10;
554 else { assert( 0 ); return 0; }
555 Sign[k/8] |= ( (Digit & 15) << ((k%8) * 4) );
556 }
557 return 1;
558}
Here is the caller graph for this function:

◆ Extra_ReadHexadecimal()

int Extra_ReadHexadecimal ( unsigned Sign[],
char * pString,
int nVars )

Definition at line 559 of file extraUtilFile.c.

560{
561 int nWords, nDigits, k;
562 nWords = Extra_TruthWordNum( nVars );
563 for ( k = 0; k < nWords; k++ )
564 Sign[k] = 0;
565 // read the number from the string
566 nDigits = (1 << nVars) / 4;
567 if ( nDigits == 0 )
568 nDigits = 1;
569 Extra_ReadHex( Sign, pString, nDigits );
570 return 1;
571}
int nWords
Definition abcNpn.c:127
int Extra_ReadHex(unsigned Sign[], char *pString, int nDigits)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_StringAppend()

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 731 of file extraUtilFile.c.

732{
733 char * pTemp;
734 if ( pStrGiven )
735 {
736 pTemp = ABC_ALLOC( char, strlen(pStrGiven) + strlen(pStrAdd) + 2 );
737 sprintf( pTemp, "%s%s", pStrGiven, pStrAdd );
738 ABC_FREE( pStrGiven );
739 }
740 else
741 pTemp = Extra_UtilStrsav( pStrAdd );
742 return pTemp;
743}
Here is the call graph for this function:

◆ Extra_StringClean()

void Extra_StringClean ( char * pStrGiven,
char * pCharKeep )

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 756 of file extraUtilFile.c.

757{
758 char * pTemp, * pChar, * pSave = pStrGiven;
759 for ( pTemp = pStrGiven; *pTemp; pTemp++ )
760 {
761 for ( pChar = pCharKeep; *pChar; pChar++ )
762 if ( *pTemp == *pChar )
763 break;
764 if ( *pChar == 0 )
765 continue;
766 *pSave++ = *pTemp;
767 }
768 *pSave = 0;
769}

◆ Extra_StringCompare()

int Extra_StringCompare ( const char * pp1,
const char * pp2 )

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

Synopsis [String comparison procedure.]

Description []

SideEffects []

SeeAlso []

Definition at line 782 of file extraUtilFile.c.

783{
784 return strcmp(*(char **)pp1, *(char **)pp2);
785}
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Extra_TimeStamp()

char * Extra_TimeStamp ( )

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

Synopsis [Returns the time stamp.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 465 of file extraUtilFile.c.

466{
467 static char Buffer[100];
468 char * TimeStamp;
469 time_t ltime;
470 // get the current time
471 time( &ltime );
472 TimeStamp = asctime( localtime( &ltime ) );
473 TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
474 strcpy( Buffer, TimeStamp );
475 return Buffer;
476}
Here is the call graph for this function: