/* Program DUPCENT duplicates the per cent character */ /* ************************************************* */ /* 30.1.1993 Petr Olsak */ /* Program types the input file to terminal, but all per cent characters are duplicated. The DOS line can look as: dupcent param1 param2 where param1 ... the input file name (including the path if needed) param2 (optionally) ... the text, which is included before each line The program is used for OPTIONS/SAVE item in TeX menu system (for example). */ #include #include #define FGETC(INPUT) (feof(INPUT)||i>=127 ? '\n' : fgetc(INPUT)) FILE *input; char r[128]; main(int argc, char *argv[]) { register int i; input = fopen(argv[1], "r"); if (input != NULL ) while (!feof(input)) { i = 0; lab1: while ((r[i]=FGETC(input)) != '\n' && r[i] != '%') i++; if (feof(input) && r[i-1]==-1) r[--i] = '\n' ; if (r[i]=='%') { r[++i]='%'; i++; goto lab1;} r[i]=0; if (argv[2] == NULL || r[0]==0) printf ("%s\n", r); else printf ("%s %s\n", argv[2], r); } return 0; }