DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦93b35aedf⟧ TextFile

    Length: 6528 (0x1980)
    Types: TextFile
    Names: »LIST.PAS«

Derivation

└─⟦74e5ee6fb⟧ Bits:30002683 PolyPascal-86 v. 3.11 - Piccoline
└─⟦74e5ee6fb⟧ Bits:30003934 SW1402 PolyPascal v3.11 (dk) til Piccoline
    └─ ⟦this⟧ »LIST.PAS« 

TextFile

PROGRAM list; æ$C-,K-,R-å

æ LIST is a very useful all-purpose list program. It can output å
æ listings of all sorts of text files, with headers, line num-  å
æ bers, and full control of page length, line length, left mar- å
æ gin and bottom margin. LIST obtains all its parameters from   å
æ the command line. The command line format is:                 å
æ                                                               å
æ    LIST <filename><options>,...,<filename><options>           å
æ                                                               å
æ where <filename> is a file name acceptable to the operating   å
æ system, and <options> are one or more options, selected from  å
æ the following list:                                           å
æ                                                               å
æ    Pnn     Set page length to nn.                             å
æ    Lnn     Set line length to nn.                             å
æ    Inn     Indent each line printed by nn blanks.             å
æ    Snn     Skip nn lines at the bottom of each page.          å
æ    H       Print file name and page number on top of          å
æ            each page.                                         å
æ    Hsssss  Print header string and page number on top         å
æ            of each page.                                      å
æ    N       Print line number before each line.                å
æ    F       Form-feed. Skip to top of next page.               å
æ                                                               å
æ Each option must be preceded by a forward slash. An example   å
æ of a LIST command line:                                       å
æ                                                               å
æ    LIST WORK.PAS/I8/N/HWorkfile Listing,CALC.PAS,/F           å
æ                                                               å
æ This line will cause WORK.PAS to be listed with an indenta-   å
æ tion (left margin) of 8, line numbers and a user specified    å
æ heading. Following this, CALC.PAS is listed using the default å
æ page format parameters, and finally a form-feed is output.    å

CONST
  dpagelen = 72;                æDefault page lengthå
  dlinelen = 74;                æDefault line lengthå
  dindent  = 0;                 æDefault indentationå
  dskip    = 6;                 æDefault bottom skipå
  cr       = @13;               æCarriage returnå
  lf       = @10;               æLinefeedå
  ht       = @9;                æHorizontal tabå
  ff       = @12;               æFormfeedå
  esc      = @27;               æEscapeå

VAR
  i,pos,pagelen,linelen,indent,skip,arg,
  pageno,lineno,lin,col,width: integer;
  ch,opt: char;
  printhdr,linenumbers: boolean;
  ns: STRINGÆ4Å;
  filename,header: STRINGÆ64Å;
  line: STRINGÆ127Å;
  infile: text;
  cmdlin: STRINGÆ127Å AT dseg:$80;

FUNCTION cap(ch: char): char;
BEGIN
  IF (ch>='a') AND (ch<='z') THEN
  cap:=chr(ord(ch)-32) ELSE cap:=ch;
END;

BEGIN
  pagelen:=dpagelen; linelen:=dlinelen; indent:=dindent;
  skip:=dskip; header:=''; printhdr:=false; linenumbers:=false;
  filename:=''; line:=cmdlin+@0; pos:=1;
  REPEAT
    WHILE lineÆposÅ IN Æ' ',','Å DO pos:=succ(pos);
    WHILE NOT(lineÆposÅ IN Æ' ',',','/',@0Å) DO
    BEGIN
      filename:=filename+lineÆposÅ; pos:=succ(pos);
    END;
    WHILE lineÆposÅ=' ' DO pos:=succ(pos);
    WHILE lineÆposÅ='/' DO
    BEGIN
      pos:=succ(pos); opt:=cap(lineÆposÅ); pos:=succ(pos);
      CASE opt OF
        'P','L','I','S':
        BEGIN
          arg:=0;
          WHILE lineÆposÅ IN Æ'0'..'9'Å DO
          BEGIN
            arg:=arg*10+ord(lineÆposÅ)-ord('0');
            pos:=succ(pos);
          END;
          CASE opt OF
            'P': pagelen:=arg;
            'L': linelen:=arg;
            'I': indent:=arg;
            'S': skip:=arg;
          END;
        END;
        'H':
        BEGIN
          WHILE NOT(lineÆposÅ IN Æ',','/',@0Å) DO
          BEGIN
            header:=header+lineÆposÅ; pos:=succ(pos);
          END;
          printhdr:=true;
        END;
        'N': linenumbers:=true;
        'F': FOR i:=1 TO pagelen DO write(lst,lf);
      OTHERWISE
        writeln('Unknown option identifier: "',opt,'"');
        halt;
      END;
      WHILE lineÆposÅ=' ' DO pos:=succ(pos);
    END;
    IF filename<>'' THEN
    BEGIN
      assign(infile,filename);
      æ$I-å reset(infile) æ$I+å;
      IF iores<>0 THEN
      BEGIN
        writeln('File not found: "',filename,'"');
        halt;
      END;
      IF header='' THEN header:='File '+filename;
      pageno:=1; lineno:=1; lin:=0; width:=linelen-indent;
      IF linenumbers THEN width:=width-6;
      WHILE NOT eof(infile) DO
      BEGIN
        IF keypress THEN
        BEGIN
          read(kbd,ch);
          IF ch=esc THEN
          BEGIN
            writeln('Interrupted');
            IF lin<>0 THEN
            FOR i:=lin TO pred(pagelen) DO write(lst,lf);
            halt;
          END;
        END;
        IF printhdr AND (lin=0) THEN
        BEGIN
          write(lst,'':indent,header);
          writeln(lst,'':linelen-indent-len(header)-8,'Page ',pageno);
          write(lst,lf,lf); lin:=3;
        END;
        write(lst,'':indent);
        IF linenumbers THEN
        BEGIN
          str(lineno,ns); write(lst,copy('000',1,4-len(ns)),ns,'  ');
        END;
        col:=0;
        WHILE NOT eoln(infile) DO
        BEGIN
          read(infile,ch);
          CASE ch OF
            @32..@126:
            BEGIN
              IF col<width THEN write(lst,ch);
              col:=succ(col);
            END;
            ht:
            REPEAT
              IF col<width THEN write(lst,' ');
              col:=succ(col);
            UNTIL col MOD 8=0;
            ff:
            IF lin<>0 THEN
            BEGIN
              FOR i:=lin TO pred(pagelen) DO write(lst,lf);
              pageno:=succ(pageno); lin:=0;
            END;
          END;
        END;
        readln(infile); writeln(lst);
        lineno:=succ(lineno); lin:=succ(lin);
        IF lin=pagelen-skip THEN
        BEGIN
          FOR i:=1 TO skip DO write(lst,lf);
          pageno:=succ(pageno); lin:=0;
        END;
      END;
      IF lin<>0 THEN
      FOR i:=lin TO pred(pagelen) DO write(lst,lf);
      filename:=''; header:='';
      printhdr:=false; linenumbers:=false;
    END;
  UNTIL lineÆposÅ=@0;
END.
«nul»«nul»«nul»«nul»