abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilFile.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [extraUtilFile.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [extra]
8 
9  Synopsis [File management utilities.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: extraUtilFile.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "extra.h"
22 
24 
25 
26 /*---------------------------------------------------------------------------*/
27 /* Constant declarations */
28 /*---------------------------------------------------------------------------*/
29 
30 /*---------------------------------------------------------------------------*/
31 /* Stucture declarations */
32 /*---------------------------------------------------------------------------*/
33 
34 /*---------------------------------------------------------------------------*/
35 /* Type declarations */
36 /*---------------------------------------------------------------------------*/
37 
38 /*---------------------------------------------------------------------------*/
39 /* Variable declarations */
40 /*---------------------------------------------------------------------------*/
41 
42 /*---------------------------------------------------------------------------*/
43 /* Macro declarations */
44 /*---------------------------------------------------------------------------*/
45 
46 
47 /**AutomaticStart*************************************************************/
48 
49 /*---------------------------------------------------------------------------*/
50 /* Static function prototypes */
51 /*---------------------------------------------------------------------------*/
52 
53 /**AutomaticEnd***************************************************************/
54 
55 
56 /*---------------------------------------------------------------------------*/
57 /* Definition of exported functions */
58 /*---------------------------------------------------------------------------*/
59 
60 /**Function*************************************************************
61 
62  Synopsis [Tries to find a file name with a different extension.]
63 
64  Description []
65 
66  SideEffects []
67 
68  SeeAlso []
69 
70 ***********************************************************************/
71 char * Extra_FileGetSimilarName( char * pFileNameWrong, char * pS1, char * pS2, char * pS3, char * pS4, char * pS5 )
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 }
113 
114 /**Function*************************************************************
115 
116  Synopsis [Returns the pointer to the file extension.]
117 
118  Description []
119 
120  SideEffects []
121 
122  SeeAlso []
123 
124 ***********************************************************************/
125 char * Extra_FileNameExtension( char * FileName )
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 }
134 
135 /**Function*************************************************************
136 
137  Synopsis [Returns the composite name of the file.]
138 
139  Description []
140 
141  SideEffects []
142 
143  SeeAlso []
144 
145 ***********************************************************************/
146 char * Extra_FileNameAppend( char * pBase, char * pSuffix )
147 {
148  static char Buffer[500];
149  assert( strlen(pBase) + strlen(pSuffix) < 500 );
150  sprintf( Buffer, "%s%s", pBase, pSuffix );
151  return Buffer;
152 }
153 
154 /**Function*************************************************************
155 
156  Synopsis []
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
165 char * Extra_FileNameGeneric( char * FileName )
166 {
167  char * pDot, * pRes;
168  pRes = Extra_UtilStrsav( FileName );
169  if ( (pDot = strrchr( pRes, '.' )) )
170  *pDot = 0;
171  return pRes;
172 }
173 
174 /**Function*************************************************************
175 
176  Synopsis [Returns the composite name of the file.]
177 
178  Description []
179 
180  SideEffects []
181 
182  SeeAlso []
183 
184 ***********************************************************************/
185 char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix )
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 }
196 
197 /**Function*************************************************************
198 
199  Synopsis []
200 
201  Description []
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ***********************************************************************/
208 void Extra_FileNameCorrectPath( char * FileName )
209 {
210  char * pStart;
211  if ( FileName )
212  for ( pStart = FileName; *pStart; pStart++ )
213  if ( *pStart == '>' || *pStart == '\\' )
214  *pStart = '/';
215 }
216 
217 /**Function*************************************************************
218 
219  Synopsis []
220 
221  Description []
222 
223  SideEffects []
224 
225  SeeAlso []
226 
227 ***********************************************************************/
228 char * Extra_FileNameWithoutPath( char * FileName )
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 }
236 char * Extra_FilePathWithoutName( char * FileName )
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 }
250 char * Extra_FileDesignName( char * pFileName )
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 }
269 
270 /**Function*************************************************************
271 
272  Synopsis [Returns the file size.]
273 
274  Description [The file should be closed.]
275 
276  SideEffects []
277 
278  SeeAlso []
279 
280 ***********************************************************************/
281 int Extra_FileCheck( char * pFileName )
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 }
296 
297 /**Function*************************************************************
298 
299  Synopsis [Returns the file size.]
300 
301  Description [The file should be closed.]
302 
303  SideEffects []
304 
305  SeeAlso []
306 
307 ***********************************************************************/
308 int Extra_FileSize( char * pFileName )
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 }
323 
324 
325 /**Function*************************************************************
326 
327  Synopsis [Read the file into the internal buffer.]
328 
329  Description []
330 
331  SideEffects []
332 
333  SeeAlso []
334 
335 ***********************************************************************/
336 char * Extra_FileRead( FILE * pFile )
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 }
354 char * Extra_FileRead2( FILE * pFile, FILE * pFile2 )
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 }
376 
377 /**Function*************************************************************
378 
379  Synopsis [Read the file into the internal buffer.]
380 
381  Description []
382 
383  SideEffects []
384 
385  SeeAlso []
386 
387 ***********************************************************************/
388 char * Extra_FileReadContents( char * pFileName )
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 }
397 char * Extra_FileReadContents2( char * pFileName, char * pFileName2 )
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 }
408 
409 /**Function*************************************************************
410 
411  Synopsis [Returns one if the file has a given extension.]
412 
413  Description []
414 
415  SideEffects []
416 
417  SeeAlso []
418 
419 ***********************************************************************/
420 int Extra_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 )
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 }
434 
435 /**Function*************************************************************
436 
437  Synopsis [Returns the time stamp.]
438 
439  Description [The file should be closed.]
440 
441  SideEffects []
442 
443  SeeAlso []
444 
445 ***********************************************************************/
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 }
458 
459 /**Function*************************************************************
460 
461  Synopsis []
462 
463  Description []
464 
465  SideEffects []
466 
467  SeeAlso []
468 
469 ***********************************************************************/
470 unsigned Extra_ReadBinary( char * Buffer )
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 }
485 
486 /**Function*************************************************************
487 
488  Synopsis [Prints the bit string.]
489 
490  Description []
491 
492  SideEffects []
493 
494  SeeAlso []
495 
496 ***********************************************************************/
497 void Extra_PrintBinary( FILE * pFile, unsigned Sign[], int nBits )
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 }
511 
512 /**Function*************************************************************
513 
514  Synopsis [Reads the hex unsigned into the bit-string.]
515 
516  Description []
517 
518  SideEffects []
519 
520  SeeAlso []
521 
522 ***********************************************************************/
523 int Extra_ReadHex( unsigned Sign[], char * pString, int nDigits )
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 }
540 int Extra_ReadHexadecimal( unsigned Sign[], char * pString, int nVars )
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 }
553 
554 /**Function*************************************************************
555 
556  Synopsis [Prints the hex unsigned into a file.]
557 
558  Description []
559 
560  SideEffects []
561 
562  SeeAlso []
563 
564 ***********************************************************************/
565 void Extra_PrintHexadecimal( FILE * pFile, unsigned Sign[], int nVars )
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 }
580 
581 /**Function*************************************************************
582 
583  Synopsis [Prints the hex unsigned into a file.]
584 
585  Description []
586 
587  SideEffects []
588 
589  SeeAlso []
590 
591 ***********************************************************************/
592 void Extra_PrintHexadecimalString( char * pString, unsigned Sign[], int nVars )
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 }
608 
609 /**Function*************************************************************
610 
611  Synopsis [Prints the hex unsigned into a file.]
612 
613  Description []
614 
615  SideEffects []
616 
617  SeeAlso []
618 
619 ***********************************************************************/
620 void Extra_PrintHex( FILE * pFile, unsigned * pTruth, int nVars )
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 }
638 void Extra_PrintHexReverse( FILE * pFile, unsigned * pTruth, int nVars )
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 }
656 
657 /**Function*************************************************************
658 
659  Synopsis [Returns the composite name of the file.]
660 
661  Description []
662 
663  SideEffects []
664 
665  SeeAlso []
666 
667 ***********************************************************************/
668 void Extra_PrintSymbols( FILE * pFile, char Char, int nTimes, int fPrintNewLine )
669 {
670  int i;
671  for ( i = 0; i < nTimes; i++ )
672  printf( "%c", Char );
673  if ( fPrintNewLine )
674  printf( "\n" );
675 }
676 
677 /**Function*************************************************************
678 
679  Synopsis [Appends the string.]
680 
681  Description [Assumes that the given string (pStrGiven) has been allocated
682  before using malloc(). The additional string has not been allocated.
683  Allocs more root, appends the additional part, frees the old given string.]
684 
685  SideEffects []
686 
687  SeeAlso []
688 
689 ***********************************************************************/
690 char * Extra_StringAppend( char * pStrGiven, char * pStrAdd )
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 }
703 
704 /**Function*************************************************************
705 
706  Synopsis [Only keep characters belonging to the second string.]
707 
708  Description []
709 
710  SideEffects []
711 
712  SeeAlso []
713 
714 ***********************************************************************/
715 void Extra_StringClean( char * pStrGiven, char * pCharKeep )
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 }
729 
730 /**Function*************************************************************
731 
732  Synopsis [String comparison procedure.]
733 
734  Description []
735 
736  SideEffects []
737 
738  SeeAlso []
739 
740 ***********************************************************************/
741 int Extra_StringCompare( const char * pp1, const char * pp2 )
742 {
743  return strcmp(*(char **)pp1, *(char **)pp2);
744 }
745 
746 /**Function*************************************************************
747 
748  Synopsis [Sorts lines in the file alphabetically.]
749 
750  Description []
751 
752  SideEffects []
753 
754  SeeAlso []
755 
756 ***********************************************************************/
757 void Extra_FileSort( char * pFileName, char * pFileNameOut )
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 }
803 
804 
805 /**Function*************************************************************
806 
807  Synopsis [Appends line number in the end.]
808 
809  Description []
810 
811  SideEffects []
812 
813  SeeAlso []
814 
815 ***********************************************************************/
816 void Extra_FileLineNumAdd( char * pFileName, char * pFileNameOut )
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 }
845 
846 /**Function*************************************************************
847 
848  Synopsis []
849 
850  Description []
851 
852  SideEffects []
853 
854  SeeAlso []
855 
856 ***********************************************************************/
857 /*
858 int main( int argc, char ** argv )
859 {
860  if ( argc == 2 )
861  Extra_FileSort( argv[1], Extra_FileNameAppend(argv[1], "_sorted") );
862  else
863  printf( "%s: Wrong number of command line arguments.\n", argv[0] );
864  return 1;
865 }
866 */
867 
868 /*---------------------------------------------------------------------------*/
869 /* Definition of internal functions */
870 /*---------------------------------------------------------------------------*/
871 
872 /*---------------------------------------------------------------------------*/
873 /* Definition of static Functions */
874 /*---------------------------------------------------------------------------*/
875 
876 
877 ////////////////////////////////////////////////////////////////////////
878 /// END OF FILE ///
879 ////////////////////////////////////////////////////////////////////////
880 
881 
883 
char * malloc()
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
VOID_HACK free()
void Extra_PrintHexReverse(FILE *pFile, unsigned *pTruth, int nVars)
char * Extra_FileNameGeneric(char *FileName)
void Extra_PrintSymbols(FILE *pFile, char Char, int nTimes, int fPrintNewLine)
char * Extra_FileNameExtension(char *FileName)
#define SEEK_END
Definition: zconf.h:392
void Extra_FileNameCorrectPath(char *FileName)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Extra_FileSize(char *pFileName)
void Extra_PrintHexadecimalString(char *pString, unsigned Sign[], int nVars)
char * Extra_FileDesignName(char *pFileName)
int nWords
Definition: abcNpn.c:127
char * Extra_FilePathWithoutName(char *FileName)
void Extra_FileLineNumAdd(char *pFileName, char *pFileNameOut)
unsigned Extra_ReadBinary(char *Buffer)
char * Extra_UtilStrsav(const char *s)
int strcmp()
char * Extra_FileNameWithoutPath(char *FileName)
char * Extra_FileNameAppend(char *pBase, char *pSuffix)
int Extra_StringCompare(const char *pp1, const char *pp2)
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
char Char
Definition: bzlib_private.h:43
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Extra_FileSort(char *pFileName, char *pFileNameOut)
char * sprintf()
char * strcpy()
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Extra_ReadHexadecimal(unsigned Sign[], char *pString, int nVars)
int Extra_FileIsType(char *pFileName, char *pS1, char *pS2, char *pS3)
void Extra_StringClean(char *pStrGiven, char *pCharKeep)
int Extra_FileCheck(char *pFileName)
char * Extra_TimeStamp()
#define ABC_FREE(obj)
Definition: abc_global.h:232
char * Extra_FileReadContents2(char *pFileName, char *pFileName2)
char * Extra_FileRead2(FILE *pFile, FILE *pFile2)
char * strcat()
int strncmp()
char * Extra_FileReadContents(char *pFileName)
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
int Extra_ReadHex(unsigned Sign[], char *pString, int nDigits)
ABC_NAMESPACE_IMPL_START char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
Definition: extraUtilFile.c:71
#define assert(ex)
Definition: util_old.h:213
int strlen()
char * Extra_StringAppend(char *pStrGiven, char *pStrAdd)
char * strrchr()
char * Extra_FileRead(FILE *pFile)
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
VOID_HACK rewind()