home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / ega / egapaint.arc / PREP.C < prev    next >
Text File  |  1988-04-15  |  2KB  |  69 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <bios.h>
  5. #include <process.h>
  6. #include <io.h>
  7.  
  8. #define LENGTH 80
  9.  
  10. FILE *infile;
  11. FILE *outfile;
  12.  
  13. void main(int argc, char *argv[])
  14. {
  15.  
  16.     register int i, count = 0;
  17.     int flag = 1;
  18.  
  19.     char c;
  20.     char tmp_file[LENGTH], *temptr;
  21.     char src_file[LENGTH], *srcptr;
  22.     char bak_file[LENGTH], *bakptr;
  23.  
  24.     if(argc != 2) {
  25.         printf("\nUsage: prep <argv[1]>\n");
  26.         exit(0);
  27.     }
  28.     strcpy(src_file, argv[1]);            /* copy the filename  */
  29.     temptr = tmp_file;                    /* point to the files */
  30.     srcptr = src_file;
  31.     bakptr = bak_file;
  32.     while(*srcptr) {                    /* copy the name til a . appears */
  33.         if(*srcptr == '.') break;        /*   or we run out of stuff      */
  34.         *bakptr++ = *srcptr;
  35.         *temptr++ = *srcptr++;
  36.     }
  37.     strcpy(temptr, ".$$$");                /* fill in the file types        */
  38.     strcpy(bakptr, ".BAK");
  39.     if((infile = fopen(src_file, "r")) == NULL) {
  40.         printf("\nCannot open file: %s\n", src_file);
  41.         exit(0);
  42.     }
  43.     if((outfile = fopen(tmp_file, "w")) == NULL) {
  44.         printf("\nCannot open file: %s\n", tmp_file);
  45.         exit(0);
  46.     }
  47.     while(flag) {                        /* copy characters until End-Of-File */
  48.         c = fgetc(infile);
  49.         if(c == EOF) flag = 0;
  50.         if(c != '\t') {
  51.             fputc(c, outfile); /* expand the tab */
  52.             count++;
  53.         }
  54.         else {
  55.             i = 4 - (count % 4);
  56.             while(i--) {
  57.                 fputc(' ', outfile);
  58.                 count++;
  59.             }
  60.         }
  61.         if(c == '\n')  count = 0;
  62.     }
  63.     fcloseall();
  64.     unlink(bak_file);                    /* delete any previous .BAK files */
  65.     rename(src_file, bak_file);            /* rename the files */
  66.     rename(tmp_file, src_file);
  67.  
  68. }
  69.