program CheckLIB(input,output); (* Program compares two catalogues generated by: LIB library [M] Output of the command should be redirected by: PUT CONSOLE TO FILE lib Two of the files 'lib' will be read and module names will be compared. Any difference will be listed How to call : CHECKLIB lib_1 {lib_2} If only one file name is given, CHECKLIB expects as first file the filename with extension .1 and as second file extension .2 *) const HEADER = 'LIB'; CtrlC = ^C; CR = #$0D; type Name = string[ 8]; Fname = string[14]; Long = string; DatPtr = ^DatList; DatList = record Link : DatPtr; ModNam : Name; Which : integer; end; var OneFile : boolean; Count : integer; Root : DatPtr; Names : array[1..2] of Fname; function IsInList(Item:DatPtr):boolean; var p : DatPtr; GotIt : boolean; begin if Root=NIL then GotIt:=FALSE else begin p:=Root; repeat GotIt:=p^.ModNam=Item^.ModNam; p:=p^.Link; until (GotIt) OR (p=NIL); end; IsInList:=GotIt; end; procedure PutToList(Item:DatPtr); var p,q : DatPtr; begin if Root=NIL then begin Item^.Link:=NIL; Root:=Item; end else if Root^.ModNam>Item^.ModNam then begin Item^.Link:=Root; Root:=Item; end else begin p:=Root; q:=Root; while (p^.Link<>NIL) and (p=q) do begin p:=p^.Link; if p^.ModNam>Item^.ModNam then begin q^.Link:=Item; Item^.Link:=p; end else q:=p; end; if (p^.Link=NIL) and (p^.ModNamNIL) AND (p=q) AND (p^.ModNamsizeof(pt)) then new(pt) else begin writeln('No more memory for data'); halt; end; end; procedure ProcModule; var p : DatPtr; begin while line[length(line)]=' ' do delete(line,length(line),1); makenew(p); with p^ do begin Link:=NIL; ModNam:=line; Which:=fileno; end; if IsInList(p) then begin dec(Count); Remove(line); dispose(p); Status('deleted '); end else begin inc(Count); PutToList(p); Status('inserted'); end; end; procedure WantAbort; var ch : char; begin read(kbd,ch); if ch=CtrlC then begin write('Received abort signal - Abort really [y,n] '); repeat repeat until keypressed; read(kbd,ch); ch:=UpCase(ch); until (ch in ['N','Y']); if (ch='Y') then begin writeln(ch); writeln('User interrupt.. aborted'); halt; end else begin write(CR); ClrEol; end; end; end; Begin { PutFile } if NOT OneFile then Names[fileno]:=ParamStr(fileno) else Names[fileno]:=ParamStr(1)+'.'+chr(ord('0')+(fileno MOD 10)); assign(F,Names[fileno]); if NOT exist(F) then IO_ABORT('Cannot find source file ',fileno); reset(F); Sync; FEOF:=FALSE; while NOT FEOF do begin readln(F,line); if keypressed then WantAbort; FEOF:=(length(line)=0) OR (EOF(F)); if NOT FEOF then ProcModule; end; close(F); End; BEGIN Root:=NIL; Count:=0; if (ParamCount>2) OR (ParamCount=0) then Help else begin OneFile:=(ParamCount=1); PutFile(1); PutFile(2); if NOT (Root=NIL) then begin writeln; writeln('Differnces found:'); writeln; while NOT (Root=NIL) do begin writeln('Missing ',Root^.ModNam:9,' in file ',Names[Root^.Which]); Root:=Root^.Link; end; end else writeln('Files ',Names[1],' and ',Names[2],' hold same modules'); end; END.