head     1.1;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.1
date     89.03.08.10.59.56;  author quist;  state Exp;
branches ;
next     ;


desc
@source file scanner for SPY operations
@



1.1
log
@Initial revision
@
text
@$DEBUG OFF$ $RANGE OFF$ $OVFLCHECK OFF$
PROGRAM SCANLIST(INPUT,OUTPUT);
CONST
  linesname = 'SRCSTATS';
  maxline   = 65535;
  smaxline  = (maxline div 4) + 1;
TYPE
  string255  = string[255];
  byte       = 0..255;
  linetype   = packed array[0..maxline] of byte;
VAR
  infile    : text;
  outfile   : text;
  linesfile : file of byte;
  inname    : string255;
  inline    : string255;
  newfile   : string255;
  lines     : ^linetype;
  min,max,
  num,num2  : integer;
  i,i2,
  lnum,ll   : integer;
  count     : integer;
  op        : char;
  
BEGIN
  writeln('Listing Scanner Rev 2.1, 24 FEB 89');
  writeln;
  writeln('Enter the full name of the Compiler listing file');
  writeln('of the full name of the Librarian print file');
  write('file = '); readln(inname);
  reset(infile,inname);
  new(lines);
  open(linesfile,linesname);
  min := maxint; max := minint; num := 0;
  write('Clear stats ? '); read(op); writeln;
  if (op='y') or (op='Y') then for i := 0 to maxline do lines^[i]:=0
  else
  if eof(linesfile) then for i := 0 to maxline do lines^[i]:=0
  else
  begin
    writeln('Now reading SRCSTATS file');
    for i := 0 to maxline do
    begin
      read(linesfile,lines^[i]);
      if lines^[i]<>0 then
      begin
        num := num + 1;
        if i < min then min := i
        else
        if i > max then max := i;
      end;
    end;
    if num=1 then max := min;
  end;
  if num>0 then
  begin
    writeln('initial stats');
    write('min line # = ',min:5);
    write(' max line # = ',max:5);
    write(' total # = ',num:5);
    writeln;
  end;
  
  { find out what kind of a file it is }
  writeln('Now scanning input file');
  op    := ' ';
  while (not eof(infile)) and (op=' ') do
  begin
    readln(infile,inline);
    inline := strltrim(inline);
    if strlen(inline)>10 then
    begin
      if str(inline,1,9)='Librarian' then op:='L'
      else
      if str(inline,1,6)='Pascal' then op:='P';
    end; 
  end;
  
  if op='L' then
  begin
    write('Create a new file with adjusted line numbers (Y/N) ? ');
    read(op); writeln;
    if not (op in ['Y','y']) then op := 'L'
    else
    begin
      write('Name of the new file (NEWFILE.TEXT) ? '); readln(newfile);
      if strlen(newfile)=0 then newfile := 'NEWFILE.TEXT';
      rewrite(outfile,newfile);
      op := 'l';
      reset(infile);
    end;
  end;
  
  { locate & process the line numbers in the file }
  count := 0;
  if op='P' then
  begin
    while not eof(infile) do
    begin
      readln(infile,inline);
      count := count + 1;
      if strlen(inline)>7 then
      if inline[7]='*' then
      begin
        strread(inline,1,i,lnum);
        if lnum<min then min := lnum
        else
        if lnum>max then max := lnum;
        
        if lines^[lnum]<>0 then writeln(lnum:1,' is a duplicate')
                           else begin lines^[lnum] := 1;
                                      num := num + 1;
                                end;
      end;
    end;
  end
  else
  if (op='L') or (op='l') then
  begin
    ll := -1;
    while not eof(infile) do
    begin
      readln(infile,inline);
      count := count + 1;
      i := strpos('trap #0,#',inline);
      if i>0 then
      begin
        strread(inline,i+9,i2,lnum);
        if lnum=ll then
        begin
          lines^[lnum]:=lines^[lnum]+1;
          if op='l' then
          begin
            num2 := num2 + 1;
            strwrite(inline,i+9,i2,lnum + (smaxline*num2):1);
          end;
        end
        else
        begin
          ll := lnum;
          num2 := 0;
          if lnum<min then min := lnum
          else
          if lnum>max then max := lnum;
          
          if lines^[lnum]<>0 then writeln(lnum:1,' is a duplicate')
                             else begin lines^[lnum] := 1;
                                        num := num + 1;
                                  end;
        end;
      end;
      if op='l' then writeln(outfile,inline);
    end;
    if op='l' then close(outfile,'SAVE');
  end
  else writeln('File given is not a Listing or Librarian print file');
  if op<>' ' then
  begin
    if num=1 then max := min;
    writeln('final stats');
    write('min line # = ',min:5);
    write(' max line # = ',max:5);
    write(' total # = ',num:5);
    writeln(' total scanned = ',count:1);
    writeln('Now writeing SRCSTATS file');
    rewrite(linesfile);
    for i := 0 to maxline do write(linesfile,lines^[i]);
    close(linesfile,'SAVE');
    writeln('Done');
  end;
  close(infile);
  
END. { SCANLIST }
@
