home *** CD-ROM | disk | FTP | other *** search
- PROGRAM CIS_XA_Directory_ReFormat;
- { Once you have downloaded a directory onto your own system, this }
- { program will reformat it to a slightly more compact form. The }
- { CompuServe format has PPN on one line, the rest of the header }
- { information (file name, date, etc.) on the next. This program }
- { combines those two lines into one, deletes groups of spaces, and }
- { inserts tab characters (^I). Lines that start with characters }
- { other than "[" are not changed. A new output file is created so }
- { that the original will be around if a mistake is made. The }
- { program prompts for input and output filenames, and I believe }
- { that no statements unique to TURBO PASCAL (R) are included. The }
- { program should therefore run on any Pascal system. --- CPW }
- { }
- { This new version (v. 2) handles listings with multiple filenames }
- { under one PPN, as often occurs with CAT listings. It also has a }
- { switch to turn all formatting off at any point you want. Simply }
- { insert any unlikely 4-character sequence (I use ")~~(") into the }
- { file at the beginning of the line before the section to skip. }
- { Formatting will stop at that point. --- CPW 9/03/84 }
- { }
- CONST
- CATSW: STRING[4] = ')~~(';
- VAR
- FIN: TEXT;
- LINE: STRING[255];
- FOUT: TEXT;
- VDTLINE: STRING[80];
- I, K, L, LYNZRED, LYNZWRIT, LYNZFMTD: INTEGER;
- FYLENAME: STRING[14];
- CATSECT, XTRA: BOOLEAN;
- PROCEDURE GetNextLine;
- BEGIN
- READLN (FIN,LINE);
- LYNZRED:= LYNZRED + 1;
- END;
- PROCEDURE Tabber;
- BEGIN
- INSERT (^I,VDTLINE,I);
- I:= I + 1;
- END;
- PROCEDURE XfrLtr;
- BEGIN
- INSERT (LINE[K],VDTLINE,I);
- I:= I + 1;
- K:= K + 1;
- END;
- BEGIN
- LYNZRED:= 0; LYNZWRIT:= 0; LYNZFMTD:= 0;
- CATSECT:= TRUE; XTRA:= FALSE;
- WRITE ('Enter name of file to reformat: '); READLN (FYLENAME);
- ASSIGN (FIN,FYLENAME); RESET (FIN);
- WRITE ('Enter name of output file: '); READLN (FYLENAME);
- ASSIGN (FOUT,FYLENAME);
- REWRITE (FOUT);
- WHILE NOT EOF(FIN) DO
- BEGIN
- VDTLINE:= '';
- GetNextLine;
- IF (LINE = CATSW) THEN CATSECT:= FALSE;
- IF CATSECT AND (LINE[1] = '[') THEN {Line has PPN so... }
- BEGIN
- I:= 1;
- XTRA:= FALSE;
- LYNZFMTD:= LYNZFMTD + 1;
- REPEAT {Put PPN in output line.}
- BEGIN
- INSERT (LINE[I],VDTLINE,I);
- I:= I + 1;
- END;
- UNTIL LINE[I-1] = ']';
- Tabber; {Insert a CRTL-I}
- GetNextLine;
- WHILE (LENGTH(LINE) > 0) DO
- BEGIN
- K:= 1;
- IF XTRA THEN {Insert two tabs...}
- BEGIN {...before filename.}
- I:= 1;
- Tabber; {XTRA only true after first pass.}
- Tabber;
- END;
- WHILE (LINE[K] <> ' ') DO XfrLtr; {Add filename and...}
- Tabber; {...one tab or...}
- IF (K <= 8) THEN Tabber; {...two for short name.}
- WHILE (LINE[K] = ' ') DO K:= K + 1; {Delete spaces.}
- WHILE (LINE[K] <> ' ') DO XfrLtr; {Add date and one tab.}
- Tabber;
- L:= I;
- WHILE (LINE[K] = ' ') DO K:= K + 1; {Delete spaces.}
- WHILE (LINE[K] <> ' ') DO XfrLtr; {Add file size.}
- L:= I - L;
- Tabber;
- IF (L <= 8) THEN Tabber; {Add one or two tabs.}
- WHILE (LINE[K] = ' ') DO K:= K + 1;
- WHILE (K<= LENGTH(LINE)) DO XfrLtr; {Last, add # of dnloads.}
- WRITELN (FOUT,VDTLINE);
- LYNZWRIT:= LYNZWRIT + 1;
- VDTLINE:= '';
- XTRA:= TRUE;
- GetNextLine;
- END;
- VDTLINE:= LINE; {Line is blank so output it.}
- XTRA:= FALSE; {End of filename list so switch off.}
- END
- ELSE VDTLINE:= LINE; {All other lines unchg'd.}
- WRITELN (VDTLINE);
- WRITELN (FOUT,VDTLINE);
- LYNZWRIT:= LYNZWRIT + 1;
- END;
- CLOSE (FIN);
- CLOSE (FOUT);
- WRITELN (LYNZRED:8,' LINES READ.');
- WRITELN (LYNZWRIT:8,' LINES WRITTEN.');
- WRITELN (LYNZFMTD:8,' LINES COMBINED.');
- END.