home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / XAFMT2.ZIP / XAFMT2.PAS
Encoding:
Pascal/Delphi Source File  |  1985-12-28  |  4.7 KB  |  116 lines

  1.  PROGRAM CIS_XA_Directory_ReFormat;
  2. { Once you have downloaded a directory onto your own system, this  }
  3. { program will reformat it to a slightly more compact form.  The   }
  4. { CompuServe format has PPN on one line, the rest of the header    }
  5. { information (file name, date, etc.) on the next.  This program   }
  6. { combines those two lines into one, deletes groups of spaces, and }
  7. { inserts tab characters (^I). Lines that start with characters    }
  8. { other than "[" are not changed.  A new output file is created so }
  9. { that the original will be around if a mistake is made.  The      }
  10. { program prompts for input and output filenames, and I believe    }
  11. { that no statements unique to TURBO PASCAL (R) are included.  The }
  12. { program should therefore run on any Pascal system.  --- CPW      }
  13. {                                                                  }
  14. { This new version (v. 2) handles listings with multiple filenames }
  15. { under one PPN, as often occurs with CAT listings. It also has a  }
  16. { switch to turn all formatting off at any point you want. Simply  }
  17. { insert any unlikely 4-character sequence (I use ")~~(") into the }
  18. { file at the beginning of the line before the section to skip.    }
  19. { Formatting will stop at that point.    --- CPW     9/03/84       }
  20. {                                                                  }
  21. CONST
  22.      CATSW: STRING[4] = ')~~(';
  23. VAR
  24.    FIN: TEXT;
  25.    LINE: STRING[255];
  26.    FOUT: TEXT;
  27.    VDTLINE: STRING[80];
  28.    I, K, L, LYNZRED, LYNZWRIT, LYNZFMTD: INTEGER;
  29.    FYLENAME: STRING[14];
  30.    CATSECT, XTRA: BOOLEAN;
  31. PROCEDURE GetNextLine;
  32. BEGIN
  33.      READLN (FIN,LINE);
  34.      LYNZRED:= LYNZRED + 1;
  35. END;
  36. PROCEDURE Tabber;
  37. BEGIN
  38.      INSERT (^I,VDTLINE,I);
  39.      I:= I + 1;
  40. END;
  41. PROCEDURE XfrLtr;
  42. BEGIN
  43.      INSERT (LINE[K],VDTLINE,I);
  44.      I:= I + 1;
  45.      K:= K + 1;
  46. END;
  47. BEGIN
  48.      LYNZRED:= 0; LYNZWRIT:= 0; LYNZFMTD:= 0;
  49.      CATSECT:= TRUE; XTRA:= FALSE;
  50.      WRITE ('Enter name of file to reformat: '); READLN (FYLENAME);
  51.      ASSIGN (FIN,FYLENAME); RESET (FIN);
  52.      WRITE ('Enter name of output file: '); READLN (FYLENAME);
  53.      ASSIGN (FOUT,FYLENAME);
  54.      REWRITE (FOUT);
  55.      WHILE NOT EOF(FIN) DO
  56.      BEGIN
  57.           VDTLINE:= '';
  58.           GetNextLine;
  59.           IF (LINE = CATSW) THEN CATSECT:= FALSE;
  60.           IF CATSECT AND (LINE[1] = '[') THEN        {Line has PPN so... }
  61.           BEGIN
  62.                I:= 1;
  63.                XTRA:= FALSE;
  64.                LYNZFMTD:= LYNZFMTD + 1;
  65.                REPEAT                                {Put PPN in output line.}
  66.                BEGIN
  67.                     INSERT (LINE[I],VDTLINE,I);
  68.                     I:= I + 1;
  69.                END;
  70.                UNTIL LINE[I-1] = ']';
  71.                Tabber;                               {Insert a CRTL-I}
  72.                GetNextLine;
  73.                WHILE (LENGTH(LINE) > 0) DO
  74.                BEGIN
  75.                  K:= 1;
  76.                  IF XTRA THEN                        {Insert two tabs...}
  77.                  BEGIN                               {...before filename.}
  78.                       I:= 1;
  79.                       Tabber;                {XTRA only true after first pass.}
  80.                       Tabber;
  81.                  END;
  82.                  WHILE (LINE[K] <> ' ') DO XfrLtr;     {Add filename and...}
  83.                  Tabber;                               {...one tab or...}
  84.                  IF (K <= 8) THEN Tabber;              {...two for short name.}
  85.                  WHILE (LINE[K] = ' ') DO K:= K + 1;   {Delete spaces.}
  86.                  WHILE (LINE[K] <> ' ') DO XfrLtr;     {Add date and one tab.}
  87.                  Tabber;
  88.                  L:= I;
  89.                  WHILE (LINE[K] = ' ') DO K:= K + 1;   {Delete spaces.}
  90.                  WHILE (LINE[K] <> ' ') DO XfrLtr;     {Add file size.}
  91.                  L:= I - L;
  92.                  Tabber;
  93.                  IF (L <= 8) THEN Tabber;              {Add one or two tabs.}
  94.                  WHILE (LINE[K] = ' ') DO K:= K + 1;
  95.                  WHILE (K<= LENGTH(LINE)) DO XfrLtr;   {Last, add # of dnloads.}
  96.                  WRITELN (FOUT,VDTLINE);
  97.                  LYNZWRIT:= LYNZWRIT + 1;
  98.                  VDTLINE:= '';
  99.                  XTRA:= TRUE;
  100.                  GetNextLine;
  101.                END;
  102.                VDTLINE:= LINE;           {Line is blank so output it.}
  103.                XTRA:= FALSE;             {End of filename list so switch off.}
  104.           END
  105.           ELSE VDTLINE:= LINE;                       {All other lines unchg'd.}
  106.           WRITELN (VDTLINE);
  107.           WRITELN (FOUT,VDTLINE);
  108.           LYNZWRIT:= LYNZWRIT + 1;
  109.      END;
  110.      CLOSE (FIN);
  111.      CLOSE (FOUT);
  112.      WRITELN (LYNZRED:8,' LINES READ.');
  113.      WRITELN (LYNZWRIT:8,' LINES WRITTEN.');
  114.      WRITELN (LYNZFMTD:8,' LINES COMBINED.');
  115. END.
  116.