home *** CD-ROM | disk | FTP | other *** search
- {$G512,P1,D-}
- Program FILELIST;
-
- (****************************************************************************)
- (* This program is a DOS FILTER. It will list a text file to the standard *)
- (* output device with a heading on each page. Each file selected by the *)
- (* DOS DIR command will be printed. [See FILELIST.DOC] *)
- (* *)
- (* Sample invocation: A>DIR C:\LANG\PASCAL\*.PAS | FILELIST > PRN <cr> *)
- (* *)
- (* DIR may specify any disk and any path. Source disk of files must *)
- (* remain present for listing by filter program. *)
- (* *)
- (* Any file may be aborted with an 'Esc' and the next file will then *)
- (* begin. The entire procedure may be aborted with a ^E. *)
- (* *)
- (* *)
- (* Written by: Russell J. Wintner [74736,2255] 22-Jul-85 *)
- (* *)
- (****************************************************************************)
-
- Type
- S12 = String[12];
- S80 = String[80];
- S243 = String[243];
- RegisterSet=Record Case Integer Of
- 1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
- 2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
- End;
- Time=Record
- Hours,Min,Sec,Hundreths: Byte;
- End;
- DOW=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
- Date=Record
- Month,Day: Byte;
- Year: Integer;
- DayOfWeek: DOW;
- End;
- String2=String[2];
-
- Var
- L1, L2 : String[255];
- RevTime : String[7];
- RevDate : String[18];
- Filvar1 : Text;
- Filname : S12;
- FilnameP : S12;
- Path : S243;
- S : String[1];
- C : Char;
- X,X1,X2 : Integer;
- Regs : RegisterSet;
- T1 : Time;
- D1 : Date;
- AP : String2;
-
- Const
- DayName: Array [DOW] Of String[9]=
- ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
- MonName: Array [1..12] Of String[9]=
- ('January','February','March','April','May','June','July',
- 'August','September','October','November','December');
-
- (****************************************************************************)
- (* Function removes spaces in file name taken from DIR listing. *)
- (****************************************************************************)
-
- Function ParseOutSpc(StrVar : S12) : S12;
- Var
- Str2 : S12;
- begin
- Str2 := '';
- for X := 1 to Length(StrVar) do
- if copy(StrVar,X,1)<>' ' then
- Str2 := Str2 + copy(StrVar,X,1);
- ParseOutSpc := Str2;
- end;
-
- (****************************************************************************)
- (* Date and Time functions to get system date and time. *)
- (****************************************************************************)
-
- Procedure GetTime(Var T:Time);
- Begin
- With Regs,T Do
- Begin
- AH:=$2C;
- MsDos(Regs);
- Hours:=CH;
- Min:=CL;
- Sec:=DH;
- Hundreths:=DL;
- End;
- End;
-
- Procedure GetDate(Var D:Date);
- Begin
- With Regs,D Do
- Begin
- AH:=$2A;
- MsDos(Regs);
- Month:=DH;
- Day:=DL;
- Year:=CX;
- DayOfWeek:=DOW(AL);
- End;
- End;
-
- Function V2(I:Integer):String2;
- Begin
- V2:=Chr(48+I Div 10)+Chr(48+I Mod 10);
- End;
-
-
- (****************************************************************************)
- (* This procedure updates the screen with the current date and time and *)
- (* posts the name of the file that is being listed with its path. *)
- (****************************************************************************)
-
- Procedure UpDateScr;
- Var
- X : Integer;
- begin
- GetTime(T1); {Get system date and time}
- GetDate(D1);
- AP:='am';
- With T1 Do
- begin
- If Hours>11 Then AP:='pm'; {Convert time to standard from military}
- Hours:=Hours Mod 12;
- If Hours=0 Then Hours:=12;
- end;
- ClrScr;
- GotoXY(1,1);
- With D1 Do Write(Con,' ',DayName[DayOfWeek],', ',MonName[Month],' ',
- V2(Day),', ',Year);
- GotoXY(72,1);
- With T1 Do Write(Con,V2(Hours),':',V2(Min),AP);
- If Length(Path)>79 then X:=1 else X:=(79-(Length(Path)+6)) div 2;
- GotoXY(X,9);
- Writeln(Con,'Path: ',Path);
- X:=(79-(Length(FilnameP)+6)) div 2;
- GotoXY(X,14);
- Writeln(Con,'File: ',FilnameP);
- end;
-
-
- (****************************************************************************)
- (* This procedure puts a sign-off message of user's choice on the screen. *)
- (****************************************************************************)
-
- Procedure SignOff(Msg : S80);
- Var
- X : Integer;
- begin
- GetTime(T1); {Get system date and time}
- GetDate(D1);
- AP:='am';
- With T1 Do
- begin
- If Hours>11 Then AP:='pm'; {Convert time to standard from military}
- Hours:=Hours Mod 12;
- If Hours=0 Then Hours:=12;
- end;
- ClrScr;
- GotoXY(1,1);
- With D1 Do Write(Con,' ',DayName[DayOfWeek],', ',MonName[Month],' ',
- V2(Day),', ',Year);
- GotoXY(72,1);
- With T1 Do Write(Con,V2(Hours),':',V2(Min),AP);
- X:=(79-(Length(Msg))) div 2;
- GotoXY(X,13);
- Writeln(Con,Msg);
- GotoXY(1,24);
- end;
-
- (****************************************************************************)
- (* This is the procedure that will list the file. Note that the HEADING *)
- (* procedure is internal to this procedure and that both make use of the *)
- (* global variables defined in the program declaration part. *)
- (****************************************************************************)
-
- Procedure Listfile(var Filname : S12);
-
- Var
- LineCnt,
- Page : Integer;
- AbortFileFlag : Boolean;
-
- Const
- PgLen = 63; {Maximum lines per page (63 leaves a 3 line bottom margin.}
- FF = ^L; {Form Feed}
-
- Procedure Heading;
- Var
- PathToPrint : S243;
- begin
- Page := Page + 1;
- Writeln(FF);
- Writeln;
- Writeln;
- X := 6 + Length(Path) + Length(FilnameP);
- If X>70 then begin {If path name is too long, don't print it}
- X := 6 + Length(FilnameP);
- PathToPrint := '';
- end else PathToPrint := Path;
- Write('File: ',PathToPrint,FilnameP);
- Repeat
- Write(' ');
- X := X + 1;
- until X=71;
- Writeln('Page:',Page:3);
- Writeln('Last Revised: ',RevDate,' at ',RevTime);
- Writeln;
- LineCnt := 6;
- end;
-
- Procedure ListAbort;
- Var
- C : Char;
- begin
- Read(Kbd,C);
- if (C=^[) and (not KeyPressed) then AbortFileFlag:= True else
- if C=^E then begin {*** TOTAL PROGRAM ABORT ***}
- Write(FF);
- SignOff('User Aborted');
- Halt;
- end;
- end;
-
- begin
- AbortFileFlag := False;
- Assign(Filvar1,Path+Filname); {Open and reset file}
- Reset(Filvar1);
- LineCnt := PgLen+1; {Require heading by setting LineCnt beyond max}
- Page := 0; {Reset page number}
- While (not Eof(Filvar1)) and (not AbortFileFlag) do begin
- If LineCnt>=PgLen then Heading;
- Readln(Filvar1,L1);
- Writeln(L1);
- LineCnt := LineCnt + 1;
- If KeyPressed then ListAbort;
- end;
- Close(Filvar1); {Close file}
- if odd(Page) then writeln(FF); {issue FF to keep first page of next file
- on inside page of bi-fold paper.}
- end;
-
- (****************************************************************************)
- (* End of Procedure LISTFILE *)
- (****************************************************************************)
-
- Begin
-
- {Main program => As a DOS filter, input comes from the listing of the DIR
- command. Look for line that has the word 'Directory' and
- steal from it the path. Then skip down to the individual
- files listed and grab the names, one at a time, and list
- them. Repeat until the last line of the directory listing
- is found.}
-
- L2 := 'Directory';
- Repeat
- Readln(L1);
- Until 0<>Pos(L2,L1); {quit when word 'Directory' found in line just read}
-
- X := 0; {Steal path string}
- S := Copy(L1,16,1);
- Path := '';
- While (S>#$20) and (S<#$7F) do begin
- Path := Path + S;
- X := X + 1;
- S := Copy(L1,16+X,1);
- end;
- If '\'<>Copy(Path,Length(Path),1) then Path := Path + '\';
-
- Readln(L1);
- While Pos('File',L2)=0 do
- begin
- Readln(L2);
- If Pos(' File',L2)=0 then begin
- Filname := Copy(L2,1,8) + '.' + Copy(L2,10,3);
- RevTime := Copy(L2,34,6) + 'm';
- Val(ParseOutSpc(Copy(L2,24,2)),X1,X);
- Val(Copy(L2,27,2),X2,X);
- RevDate := MonName[X1]+' '+V2(X2)+', 19'+Copy(L2,30,2);
- FilnameP := ParseOutSpc(Filname); {Get rid of spaces inside file name}
- If FilnameP='.' then begin
- SignOff('No files found.');
- Halt;
- end;
- UpDateScr;
- Listfile(Filname);
- end;
- end;
- SignOff('Job Complete');
- end. {Program: FILELIST}