home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #include <io.h>
- #include <string.h>
- #include <cxlstr.h>
-
- /*
- Global Replace - Reads a data file of token definitions and then applies them
- to images read from an input file and writes the converted
- text to an output file.
-
- Call is: GR inputfile outputfile tokenfile
-
- All three fields must be supplied or Global Replace errors.
-
- The format of the images in the token file is:
-
- token=replacement-string
-
- */
-
- void file_error(char *fn)
- {
- printf("***ERROR*** Unable to open %s File - Global Replace terminates.\n",fn);
- exit(99);
- }
-
- main(int argc, char *argv[])
- {
- FILE *infile, *outfile, *tokfile;
-
- char token[100][80];
- char *rplstr[100];
- char buffer[132];
- char temp[132];
- char *where, *nxtline, *tokloc, *nlchar;
-
- int numtokens, numlines, i, j;
-
-
- printf("Global Replace 1R1A (Case insensitive) 2/10/89\n");
-
- /* First check command line */
-
- if (argc < 4)
- {
- printf("***ERROR*** Not all files specified. Global Replace terminates.\n");
- exit(99);
- }
-
-
- /* Read in tokens and set up pointers */
-
- tokfile = fopen(argv[3], "r");
- if (!tokfile) file_error("Token");
-
- numtokens=0; /* Initialize token count */
-
- while (nxtline = fgets(token[numtokens],80,tokfile))
- {
- if (where = strchr(token[numtokens], '='))
- {
- *where = '\0';
- rplstr[numtokens] = where+1;
- if (nlchar = strchr(rplstr[numtokens],'\n'))
- *nlchar = '\0';
- numtokens +=1;
- }
- else
- rplstr[numtokens] = NULL;
-
- }
- fclose(tokfile);
-
- /* Now open input and output files */
-
- infile = fopen(argv[1],"r");
- if (!infile) file_error("Input");
-
- outfile = fopen(argv[2],"w");
- if (!outfile) file_error("Output");
-
- /* Now read in each image, convert it, and write it out */
-
- numlines = 0;
-
- while (where = fgets(buffer, 132, infile))
- {
-
- numlines +=1;
- for (i=0; i<numtokens; i++)
- {
- while (tokloc = striinc(token[i],buffer))
- {
- *tokloc = '\0';
- strcpy(temp,buffer);
- strcat(temp,rplstr[i]);
- strcat(temp,(char *)(tokloc+strlen(token[i])));
- strcpy(buffer,temp);
- }
- }
- fputs(buffer,outfile);
- }
-
- fclose(infile);
- fclose(outfile);
- printf("Conversion completed ... %d lines\n",numlines);
- exit(0);
- }
-