home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOM2 / SRCLIST.LBR / SRCLIST.MOD < prev   
Text File  |  2000-06-30  |  4KB  |  123 lines

  1. MODULE sourcelister;
  2.  
  3. (*   translated to Turbo Modula-2 by Glenn Brooke 1/5/87
  4.  
  5.   Ok, another file lister.  Yes, it's better.  Sigh.  Actually, this is
  6.   a significant improvement over any other lister I've seen -- it handles
  7.   lines longer than 80 characters without screwing up the pagination!  It's
  8.   especially great for program source listings.
  9.  
  10.   To use, compile with Turbo Modula-2, and run!  You can run this as an
  11.   .MCD file from within the TM2 compiler/editor shell (it takes about 2K).
  12.   The program will prompt you for filenames and whether you want pagination
  13.   or not.  Pagination provides the filename and page # on each page.
  14.  
  15.   You can modify the source to your heart's content.  I use 79 columns per
  16.   line and 55 lines per page most frequently.
  17.  
  18.   Important note : program works only with text (ASCII) files.
  19.  
  20.   Intended for the public domain.  This program may not be sold
  21.   or used for profit without the express written permission of Glenn Brooke.
  22.  
  23.                                           Glenn Brooke
  24.                                           1025 Garnett Place
  25.                                           Evanston, IL 60201
  26.                       Lillipute Z-node (312)649-1730
  27.                                                                        *)
  28. FROM strings IMPORT String, Length;
  29. FROM texts IMPORT TEXT, OpenText, CloseText,EOT,output,CreateText,
  30.                   ReadLine;
  31. FROM fileexis IMPORT exists;
  32.  
  33. TYPE filename = String;
  34.  
  35. VAR
  36.    filetolist : filename;
  37.    CH : CHAR;
  38.    pagination,ok : BOOLEAN;
  39.  
  40.  
  41. PROCEDURE ListFile(name : filename; pagination : BOOLEAN);
  42. (*lists files with wraparound, pagination if desired, on lst: device*)
  43. CONST
  44.      MaxLinesPerPage = 55;   (* you can change these to suit yourself *)
  45.      MaxCharPerLine = 79;
  46. VAR
  47.    line : String;
  48.    i,L, linecount, pagecount : INTEGER;
  49.    filetoshow : TEXT;
  50.  
  51. BEGIN
  52.      IF NOT OpenText(filetoshow, Name) THEN
  53.        WRITELN("Sorry, couldn't open ", filetoshow);
  54.        HALT;
  55.      END;  (* if then *)
  56.      linecount := 0; pagecount := 1;
  57.      IF pagination THEN
  58.          WRITELN(output);
  59.          WRITELN(output,'   ',Name,'   Page ',pagecount);
  60.          WRITELN(output);
  61.      ELSE
  62.         WRITELN(output);
  63.         WRITELN(output);
  64.         WRITELN(output);
  65.      END; (* if then else *)
  66.  
  67.      WHILE NOT EOT(filetoshow) DO
  68.            line := '';
  69.            ReadLine(filetoshow,line);
  70.            l := Length(line);
  71.            IF l <= MaxCharPerLine THEN
  72.               INC(linecount);
  73.               WRITELN(output,line);
  74.            ELSE  (*handle lines longer than MaxCharPerLine*)
  75.               FOR i := 1 TO l DO
  76.                   WRITE(output,line[i]);   (*WRITE char by char*)
  77.                   IF i MOD MaxCharPerLine = 0 THEN (*begin new line*)
  78.                      WRITELN(output);
  79.                      INC(linecount);
  80.                   END (*if*)
  81.               END; (* for *)
  82.               WRITELN(output);
  83.               INC(linecount)
  84.            END; (* if then else *)
  85.         IF linecount >= MaxLinesPerPage THEN (*begin new page*)
  86.            WRITELN(output);
  87.            WRITELN(output); WRITELN(output); WRITELN(output); WRITELN(output);
  88.            linecount := 0;
  89.        INC(pagecount);
  90.            IF pagination THEN
  91.               WRITELN(output);
  92.               WRITELN(output,'   ',Name,'   Page ',pagecount);
  93.            ELSE
  94.                WRITELN(output); WRITELN(output);
  95.            END; (* if then else *)
  96.            WRITELN(output);WRITELN(output);WRITELN(output);WRITELN(output);
  97.        END; (* if then *)
  98.      END; (*while*)
  99.      CloseText(filetoshow);
  100. END ListFile;
  101.  
  102.  
  103. BEGIN (* main program body *)
  104.   WRITELN(" Source file lister -- make sure printer is on!");
  105.   WRITE(" Enter name of file to list (RET to quit) : ");
  106.   READLN(filetolist);
  107.   IF filetolist = "" THEN HALT END;
  108.   IF NOT exists(filetolist) THEN
  109.     WRITELN("   Sorry, coudn't find ", filetolist);
  110.     HALT;
  111.   END; (* if then *)
  112.   WRITE("  Do you want pagination (Y/N) ? ");
  113.   READ(ch);
  114.   IF CAP(ch) = "Y" THEN
  115.      pagination := TRUE;
  116.   ELSE
  117.      pagination := FALSE;
  118.   END; (* if then *)
  119.   CreateText(output, "LST:");   (* send output to printer *)
  120.   ListFile(filetolist, pagination);
  121.   CloseText(output);
  122. END sourcelister.
  123.