Software Tools - String Filters

zhaozj2021-02-16  49

/ * * In the development of software development, write several useful tool software for yourself will help yourself easier and efficiently. * Here is a string in the source program, and use macro replacement software Tool, you can see, it is so simple, * So any programmer can be easily done, but I don't dare to imagine, if not it, * with handmade the same job will waste me how much valuable time * /// Detect the string, use the string with macro, and write the macro file, and add the macro file to the file header // macro format STR_ $ filename_ $ line_ $ Num # include "stdio.h" #include "assert.h "#include" windows.h "// Filter input file int Street (char * filename) {file * fpin, * fpout, * fphead; int Num = 0; char Outfilename [20]; char ch INT line = 2; // First line Add header file reference // Enter file if (! Filename ||! (Fpin = fopen (FileName, "R"))) {Printf ("Enter file% s failed to open ./N" ,filename); Return 1;} sprintf (outfilename, "% s.tmp", filename); // output file IF (! (Fpout = fopen (Outfilename, "W")))))) {printf (" Output file% s cannot be opened / n ", outfilename); fclose (fpin); returnif 1;} // output header file if (! Headname ||! (Fphead = fopen))) {fphead = STDOUT; Printf ("/ * Output header file does not exist, use the display instead.

* // n ");} // Add header file if (headname) fprintf (fpout," # include / "% s /" / n ", headname); // start filtering fprintf (fphead," / *% s * // n ", filename); while (ch = fgetc (fpin)) && ch! = EOF) {while (ch == '/ n') // Eliminate the blank line {FPUTC (CH, FPOUT); // Output Cargo ; // Row CH = FGETC (FPIN); // Read the next line of the first IF (CH == '#') // The first is #, this is macro {FPUTC (ch, fpout ); // Output # while ((ch = fgetc (fpin)) && (ch! = EOF) && (ch! = '/ N')) FPUTC (CH, fpout); // Skip the row // output The line content IF (CH == EOF) Return 0;}}} f (cH == '//') // // Skip Transmission Character {FPUTC ('//', fpout); ch = fgetc (fpin ); Fputc (ch, fpout);} else if (ch == '/ ") // string start {char * p = strchr (filename,'. '); If (p) * p =' / 0 '; FPRINTF (FPOUT, "STR_FILE% S_LINE% D_NUM% D", FileName, Line, Num); FPRINTF (fphead, "# define str_file% s_line% d_num% d / t /" ", FileName, Line, Num ); If (p) * p = '.'; P = null; while ((ch = fgetc (fpin)) && ch! = EOF) {if (ch == '/ n') {fputc ('//) , fphead); FPUTC ('n', fphead) } Else if (CH == '//') {fputc ('//', fphead); CH = fgetc (fpin); FPUTC (CH, Fphead);} else if (ch == '/ ") // String end {FPUTC ('/ "', fphead); // divided fputc ('/ n', fphead); // break BREAK;} else fputc (ch, fphead);}} else fputc (ch , fpout;} fclose (fpin);

Fclose (fpout); if (fphead! = stdout) fclose (fphead); Remove (filename); Rename (OutfileName, FileName); Return 0;} / * * Driver, here Win32APi, you can replace it into yours File search function provided by the compiler. * / Int main (int Argc, char * argv []) {if (argc> 1) // at least one input {Win32_find_data findfileData; // handling wildcard *? Handle hfind = FindFirstFile Argv [1], & FindFileData; if (-1! = (int) hfind) {strext (FindFileData.cfileName, Argv [2]); While (FindNextFile (Hfind, & FindFileData) strexT (FindFileData.cfileName, Argv [2 ]); PUTS ("/ N ------------------------------------------------------------------------ -------- / n "); FindClose (HFIND);} else {printf (" Enter file% s is invalid ./n" ,arv[1]);}}} else {printf ("This program will The string of the source code is replaced by macro, and automatically generates macro / N "); Printf (" Usage: strexT [output header files] / N "); Printf (" example: strexT *. C strhead.h / n ");} getCH (); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-23565.html

New Post(0)