home *** CD-ROM | disk | FTP | other *** search
- FUNCTION User_ConIn : CHAR;
- {
- User-defined Console-In driver function. Allows us to trap Console-in bytes
- so that user interrupts can be supported. When TLIST is used to output
- to disk files, TURBO's "KEYPRESSED" function works fine to detect when a key
- has been pressed; it can then be read to see if it was a ^C. However, when
- output is to the printer, this does not work (ask Borland, I don't know).
- Use of TURBO's direct BIOS handlers is to no avail also (which makes sense
- since KEYPRESSED makes use of the same routines). The compiler switch $U+
- doesn't seem to work either. Therefore, console input is buffered here with
- a global abort switch set whenever ^C is seen.
- }
-
- VAR
- I : INTEGER;
-
- BEGIN
- I := 0;
- WHILE I = 0 DO I := BDOS(6,255); {BDOS procedure for Direct Console I/O}
- IF I = 3 THEN Abort := TRUE;
- User_ConIn := CHR(I);
- END;
-
- BEGIN {Main program}
- DiskFile := FALSE;
- Paginate := FALSE;
- Starting_page_number := 1;
- IF PARAMCOUNT = 0 THEN
- BEGIN
- CLRSCR;
- WRITELN(Header);
- WRITELN;
- WRITELN(' This lists TURBO* Pascal files to CP/M''s LST: device [L]');
- WRITELN(' or to default disk [D], with paper change pauses [P] and');
- WRITELN(' from starting page number [##]. Arbitrary option order;');
- WRITELN(' last option controls. Defaults are LST:, no Pause, and');
- WRITELN(' Page 1 start. "TLIST filename.ext [d] [l] [p] [##]"');
- WRITELN;
- WRITELN(' e.g. TLIST FILENAME.EXT D P 12 (disk, pause, page 12)');
- WRITELN(' TLIST FILENAME.EXT 5 P L (LST:, pause, page 5)');
- WRITELN(' TLIST FILENAME.EXT (LST:, no pause, page 1)');
- WRITELN(' TLIST FILENAME.EXT L 2 (LST:, no pause, page 2)');
- WRITELN(' TLIST FILENAME.EXT L P D P (disk, no pause, page 1)');
- WRITELN;
- WRITELN(' *Registered Trademark of Borland International.');
- WRITELN;
- WRITELN;
- WRITE('Filename and print options (separated by spaces)? ');
- READLN(CmdLine); {Place into CP/M's command line buffer.}
- WRITELN;
- END
- ELSE
- BEGIN
- WRITELN;
- WRITELN(Header);
- WRITELN;
- END;
- Header := PARAMSTR(1);
- FOR I := 2 TO PARAMCOUNT DO {Not executed if no parameters given.}
- BEGIN
- Ch := COPY(PARAMSTR(I), 1, 1);
- IF Ch IN ['L', 'l'] THEN DiskFile := FALSE;
- IF Ch IN ['D', 'd'] THEN DiskFile := TRUE;
- IF Ch IN ['P', 'p'] THEN Paginate := NOT Paginate;
- VAL(PARAMSTR(I), Count, Dummy);
- IF Dummy = 0 THEN Starting_page_number := Count;
- END;
- FOR I := 1 TO LENGTH(Header) DO
- Header[I] := UPCASE(Header[I]);
- ASSIGN(Text_File, Header);
- {$I-}
- RESET(Text_File);
- {$I+}
- IF IORESULT <> 0 THEN
- WRITELN('Cannot find ', Header)
- ELSE
- BEGIN
- I := POS('.', Header);
- IF DiskFile THEN
- BEGIN
- IF I <> 0 THEN
- ASSIGN(List_file, COPY(Header, 1, I - 1) + '.PRN')
- ELSE
- ASSIGN(List_file, Header + '.PRN');
- REWRITE(List_file);
- END;
- Set_up_hash_tables;
- Comment := FALSE;
- Strng := FALSE;
- Header := CONCAT('Listing of ', Header, ', ', Header_String);
- Line_number := 0;
- LineCount := 0;
- Page_number := 1;
- Max_no_lines := Page_Length - Margin_Top - Margin_Bottom;
- IF Page_number >= Starting_page_number THEN
- IF DiskFile THEN
- BEGIN
- FOR I := 1 TO Margin_Top - Header_Margin - 1 DO WRITELN(List_file);
- WRITELN(List_file, Header:(LENGTH(Header) + Page_Offset), ^M,
- 'Page':(Line_Width + Page_Offset - 4), Page_number:4);
- FOR I := 1 TO Header_Margin DO WRITELN(List_file);
- END
- ELSE
- BEGIN
- FOR I := 1 TO Margin_Top - Header_Margin - 1 DO WRITELN(LST);
- WRITELN(LST, Header:(LENGTH(Header) + Page_Offset), ^M,
- 'Page':(Line_Width + Page_Offset - 4), Page_number:4);
- FOR I := 1 TO Header_Margin DO WRITELN(LST);
- END;
-
- {
- Reassign TURBO's CONIN function to user-defined so that keyboard input
- can be trapped by this program.
- }
- Abort := FALSE;
- CONINPTR := ADDR(User_ConIn);
- WHILE NOT EOF(Text_File) DO
- BEGIN
- READLN(Text_File, Line);
- LineCount := LineCount + 1;
- IF Abort THEN Ch := ^C ELSE Ch := 'P';
- Abort_TLIST;
- WRITE(^M, 'Processing Line ', LineCount);
- CLREOL;
- Includes(Line, Include_file_present, Include_file_name);
- Process_Line;
- IF Include_file_present THEN
- BEGIN
- FOR I := 1 TO LENGTH(Include_file_name) DO
- Include_file_name[I] := UPCASE(Include_file_name[I]);
- ASSIGN(Include_File, Include_file_name);
- {$I-}
- RESET(Include_File);
- {$I+}
- IF IORESULT <> 0 THEN
- BEGIN
- WRITELN;
- WRITELN('Cannot find include file, ', Include_file_name);
- Ch := ^C;
- Abort_TLIST;
- END;
- WHILE NOT EOF(Include_File) DO
- BEGIN
- READLN(Include_File, Line);
- LineCount := LineCount + 1;
- IF Abort THEN Ch := ^C ELSE Ch := 'P';
- Abort_TLIST;
- WRITE(^M, 'Processing Line I', LineCount);
- CLREOL;
- Includes(Line, Include_file_present, Include_file_name);
- IF Include_file_present THEN
- BEGIN
- WRITELN;
- WRITELN('Include directive in include file not allowed!');
- Ch := ^C;
- Abort_TLIST;
- END;
- Process_Line;
- END;
- CLOSE(Include_File);
- END;
- END;
- IF DiskFile THEN
- BEGIN
- WRITE(List_file, ^L);
- CLOSE(List_file);
- END
- ELSE
- WRITE(LST, ^L);
- CLOSE(Text_File);
- WRITE(^M, Page_number, ' pages.');
- CLREOL;
- WRITELN;
- END;
- END.