home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPPROC19.ZIP / FILPRN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-09-02  |  11.0 KB  |  406 lines

  1. {           PRNT2.PAS      10/24/84
  2. Copyright (c) 1985 Scott Daniels
  3. Prints any text file with Date & Time & Page # at top of page
  4.  
  5. revisions
  6. Ver 1.2  1/20: uses Command Tail now
  7. Ver 1.3  1/24: max line length=132 vice 80; prints long lines Compressed
  8. Ver 1.31 2/28: revised include file names, eg GetFilNm.Inc
  9.  
  10.  
  11. *** NOTICE:
  12. This program is hereby placed into the Public Domain,  for non-commercial use
  13. only.  The author,  Scott Daniels of Turtle Micro-Ware Co./East Lyme, CT 06333
  14. retains sole commercial rights to this program}
  15.  
  16. Program Prnt;
  17.  
  18. {TEMPORARY LINE TO TEST PRINTING OF >80 CHARACTER LINES IN THIS FILE PRNT2.PAS, THIS IS SO FAR 98 CHARS LONG,LET'S SEE !!!}
  19.  
  20.  
  21. {$R-  Range Index check: - passive}
  22. {$U+  User Interrupt: + enabled   }
  23. {$V-  String Var Param Type Checking: - passive}
  24. {$X-  Array Optimization: - disabled}
  25. {$C+  Control S,C: + enabled }
  26.  
  27. type
  28.   Anystring   = string[70];
  29.   String14    = string[14];
  30.   regpack = record
  31.                 ax,bx,cx,dx,bp,si,ds,es,flags: integer;
  32.               end;
  33. var
  34.      recpack : regpack;
  35.  
  36. var
  37.   Control_Str : string[80];  {printer control string}
  38.   Escape      : boolean;
  39.   Ch          : Char;        { Current character being scanned }
  40.   Line        : Integer;   { display line # for next write}
  41.   KeyNo       : char;
  42.   MenuFn      : AnyString;
  43.   SuFile      : text;   {file of char}
  44.   TestFile,
  45.   FileName    : string14;
  46.   DriveNo     : string[2];
  47.  
  48. const
  49.   VersionNo   = '1.31I';       {I:Itoh; E:Epson}
  50.   RevDate     = 'Jan. 24, 1985';
  51.   EofLine     = ^M;
  52.   DefaultDrv  = 'B:';
  53.   TestName    = 'Test.Txt';
  54.   Compress_On = '15';      {for Epson FX-80, use '15'; for C-Itoh 8510 use '27:81'}
  55.   Compress_Off= '18';      {Epson: 18; Itoh: 27:78}
  56.  
  57.  
  58. (* You may wish to separate the following groups of procedures into separate
  59. files, so they may be used with other programs. If so, use the following
  60. declarations when compiling the program :
  61.  
  62. {$I Strings.Inc}       {String functions}
  63. {$I DosCall.Inc}       {DOS function Call for Date/Time}
  64. {$I DateTime.Inc}      {Date/Time via DOS function $2A,$2C}
  65. {$I Exist.Inc}         {Disk file exist? fn for GetFilNm}
  66. {$I GetFilNm.Inc}      {user input of filename}
  67. {$I CmdTail.Inc}       {gets command line drive & filename}  *)
  68.  
  69. {*******************************************************************}
  70. {*                       PROCEDURES                                *}
  71. {*******************************************************************}
  72.  
  73. {++++++++++++ INCLUDE FILES +++++++++++++++++
  74. NOTE: The following files are required for the above program. They may be left
  75. here as they are, or split out into separate Include files. }
  76.  
  77. {---------------- STRINGS.INC      10/24/84   Rev 1/24/85 }
  78. {An Include file: a collection of string handling routines}
  79.  
  80. const
  81.   LineWidth = 80;   {video line width}
  82.  
  83.  
  84. {*** UPPER: converts all chars of a string to upper case}
  85. function Upper(InString:Anystring):Anystring;
  86. var
  87.     charpos : integer;
  88.     temp : anystring;
  89.  
  90. begin
  91.     FillChar(Temp,70,#32);
  92.     for charpos := 1 to length(InString) do Temp[charpos]:=UpCase(InString[charpos]);
  93.     Upper := Temp;
  94. end; {function}
  95.  
  96.  
  97.  
  98. {*** ASC: gives ascii number for the given character *** DELETE ???}
  99. {NOTE: built-in fn Integer(ch) gives same result}
  100. function Asc(Ch:Char):integer;
  101. begin
  102.    Asc := Ord(Ch);
  103. end;
  104.  
  105.  
  106. {*** RIGHT yields right-most characters of a string ***}
  107. function Right(Str:AnyString;NChars:integer):AnyString;
  108. begin
  109.   Right := Copy(Str,Length(Str)+1-NChars,NChars);
  110. end; {Right}
  111.  
  112.  
  113. {***STRNG converts positive integer to string with no spaces, eg 9='9' ***}
  114. function Strng(Value:integer):AnyString;
  115. var
  116.   temp     : AnyString;
  117.   ndigits  : integer;
  118. begin
  119.    Str(Value:5,Temp);
  120.    if Value <10 then ndigits := 1 else
  121.    if Value <100 then ndigits := 2 else
  122.    if Value <1000 then ndigits := 3 else
  123.    if Value <10000 then ndigits := 4 else
  124.    ndigits := 5;
  125.    Temp := Right(Temp,ndigits);
  126.    Strng := Temp;
  127. end; {Strng}
  128.  
  129.  
  130. {*** TSTRNG converts value to string; adds leading zero if <10; eg 9 = "09"}
  131. function TStrng(Value:integer):AnyString;
  132. var
  133.    temp       : AnyString;
  134. begin
  135.    Temp := Strng(Value);           {convert to string}
  136.    if Value < 10 then Temp := '0'+ Temp;
  137.    TStrng := Temp;
  138. end; {TStrng}
  139.  
  140.  
  141. {*** DISP: displays 2 strings on selected line ***}
  142. procedure Disp(X,Y:integer;Str1,Str2:AnyString);
  143. begin
  144.      GoToXY(X,Y);
  145.      Write(Str1); Writeln(Str2);
  146. end;
  147.  
  148.  
  149. {*** CENTERSTR centers a string on the selected Line ***}
  150. procedure CenterStr(Line:integer;Str:AnyString);
  151. var
  152.    strlen,blanks: integer;
  153. begin
  154.      StrLen := Length(Str);
  155.      Blanks := Round((LineWidth-StrLen)/2);
  156.      GoToXY(Blanks,Line);
  157.      Writeln(Str);
  158. {     GoToXY(1,23);Writeln(strlen,'/',blanks);}     { Diagnostic}
  159. end;
  160.  
  161.  
  162. {---------------- *** DOSCALL.INC
  163. calls a DOS fn; Fn is function #, which goes into AH reg}
  164. {NOTE: variable recpack is globally defined in the calling program}
  165.  
  166. procedure DosCall(Fn:integer);
  167.  
  168. begin
  169.   with recpack do
  170.   begin
  171.     ax := Fn shl 8;
  172.   end;
  173.   MsDos(recpack);                        { call function }
  174. end;
  175.  
  176.  
  177.  
  178. {---------------- **** DATETIME.INC  Library file    10/28/84; rev 1/19/85}
  179. {NOTE: variable recpack is globally defined in the calling program}
  180.  
  181. {uses following .INC files}
  182. {DosCall.Inc - performs the DOS function call}
  183. {Strings.Inc - converts number to string, with leading '0' if <10}
  184.  
  185. type
  186.    DateStr = string[10];
  187.    TimeStr = string[8];
  188.  
  189. {*** DATE calls DOS fn 2A; on return CX:DX contains date}
  190. { year = CX (1984...); month = DH (1=Jan); day = DL}
  191. function Date:DateStr;
  192.  
  193. var
  194.   month,day : string[2];
  195.   year      : string[4];
  196.  
  197. begin
  198.   DosCall($2A);
  199.   with recpack do
  200.   begin
  201.     str(cx,year);                        {convert CX binary to string}
  202.     day := Tstrng(dx mod 256);                 {convert DX to DL, string}
  203.     month := Tstrng(dx shr 8);                 {convert DX to DH, string}
  204.   end;
  205.   date := month+'/'+day+'/'+year;
  206. end;
  207.  
  208.  
  209. {*** TIME uses DOS fn 2C}
  210. function Time:TimeStr;
  211.  
  212. var
  213.   hr,mins,secs : string[2];
  214.  
  215. begin
  216.   DosCall($2C);
  217.   with recpack do
  218.   begin
  219.       hr := Tstrng(cx shr 8);                 {CH}
  220.     mins := Tstrng(cx mod 256);             {CL}
  221.     secs := Tstrng(dx shr 8);               {DH}
  222.   end;
  223. Time := hr+':'+mins+':'+secs;
  224. end;
  225.  
  226.  
  227.  
  228. {---------------- *** EXIST.INC checks that a file exists on the disk}
  229. function Exist(FileN: AnyString): boolean;
  230. var F: file;
  231. begin
  232.    {$I-}
  233.    assign(F,FileN);
  234.    reset(F);
  235.    {$I+}
  236.    if IOResult<>0 then
  237.     Exist:=false
  238.    else Exist:=true;
  239. end; {fn exist}
  240.  
  241.  
  242. {---------------- *** GETFILNM.INC      10/24/84   Rev /    AN INCLUDE FILE}
  243. {An Include file: gets file name & check if exists}
  244.  
  245. var
  246.   LastFile: string14;
  247.  
  248. procedure GetFilNm(var FileN: String14);
  249. begin
  250.  Escape := False;
  251.  Read(kbd,Ch); if Ch = #27 then Escape := True
  252.  else
  253.    if Ch = #13 then FileName := LastFile      {CR}
  254.  else
  255.    begin
  256.       Write(Ch);
  257.       Readln(FileName); FileName := Ch + FileName;
  258.       if length(FileName) > 14 then
  259.          begin Writeln('Filespec too long - max 14 chars-');
  260.          GetFilNm(FileName);
  261.          end  {if length}
  262.       else
  263.       if FileName = '' then FileName := LastFile;
  264.       if not(Exist(FileName)) then
  265.          repeat
  266.             Write('File not found. Re-enter >');
  267.             GetFilNm(FileName);
  268.          until exist(FileName);
  269.       LastFile := FileName;     {last file read}
  270.  end; {if #27}
  271. end; {GetFileName}
  272.  
  273.  
  274. {---------------- *** CMDTAIL    1/20/85     an INCLUDE FILE}
  275. {Decodes command tail of drive,commands when a program is invoked}
  276. {eg, if call 'PRNT B:Test.Txt', will run Prnt.Com program and pass}
  277. { the command tail = 'B:Test.Txt' to the program}
  278. {ref: Borland SIG; also TUG newsletter}
  279.  
  280. var        {global variables}
  281.     CmdTail : string[14] absolute CSeg:$0080;   {eg 'space + B: + filename.ext'}
  282.     Drive : string[2];
  283.  
  284. procedure GetTail;
  285.  
  286. begin
  287.     CmdTail := Copy(CmdTail,2,Length(CmdTail)-1);  {chop off initial space}
  288.     If Pos(':',CmdTail) <>0 then Drive := Copy(CmdTail,1,2) else Drive:='';
  289. end; {Procedure CmdTail}
  290.  
  291. {-------------------------------------------------------------------------
  292. The remainder of the program's Procedures & Functions follows :}
  293.  
  294. {*** WELCOME: Initial Screen ***}
  295. Procedure Welcome;
  296. begin
  297.     CenterStr(1,'File Print Program');
  298.     CenterStr(2,'Version: '+VersionNo+'    '+RevDate);
  299.     CenterStr(3,'Copyright (c) 1985 by: S. Daniels');
  300.     CenterStr(4,'Turtle Micro-Ware Co.');
  301.     CenterStr(5,'9 Joval Street - East Lyme, CT 06333');
  302.     CenterStr(6,'Phone: (203) 739-5056');
  303.     CenterStr(8,'*** DONATIONS KINDLY ACCEPTED ***');
  304. end;
  305.  
  306.  
  307. {*** INIT: Initialize any variables ***}
  308. Procedure Init;
  309. begin
  310.    DriveNo  := DefaultDrv;
  311. end;
  312.  
  313.  
  314. {*** PRINTER_CONTROL: sends one char at a time of Control_Str, to printer}
  315. procedure Printer_Control(Control_Str:Anystring);
  316. var
  317.      Posn,TempVal,ErrCode : integer;
  318.      Str1 : Anystring;
  319.  
  320. begin
  321.      Posn := 1;
  322.      while Posn <Length(Control_Str) do begin
  323.           Str1 := Concat(Control_Str[Posn],Control_Str[Posn+1]);
  324.           Val(Str1,TempVal,ErrCode);
  325.           write(Lst,Chr(TempVal));
  326.           Posn := Posn+3;             {skip the ':'}
  327.      end; {while Posn}
  328. end; {procedure}
  329.  
  330.  
  331. {*** COMPRESS_MODE: sets printer to compress or normal for each line}
  332. procedure Compress_Mode(Compress:boolean);
  333. var
  334.    k : integer;
  335. begin
  336.    Case Compress of
  337.       True:  Printer_Control(Compress_On);
  338.       False: Printer_Control(Compress_Off);
  339.    end; {case Mode}
  340. end; {procedure}
  341.  
  342.  
  343.  
  344. procedure PrntHeading(FNam:string14; var PgNo:integer);
  345. begin
  346.    Write(Lst,'Listing of >> ',FNam,' <<   ');
  347.    Writeln(Lst,Date,'      ',Time,'       Page ',PgNo:4);
  348.    Writeln(Lst);
  349. end; {PrntHeading}
  350.  
  351.  
  352. procedure GetName;
  353. begin
  354.    Write('Enter file name, or ^C to Quit: ');
  355.    GetFilNm(FileName);
  356. end; {GetName}
  357.  
  358.  
  359. procedure PrntFile;     {send to prtr}
  360. var
  361.    PgNo,LineNo: integer;
  362.    FileLine: string[132];
  363.  
  364. begin
  365.    CenterStr(10,'now PRINTING '+FileName+'...');
  366.    PgNo := 1;
  367.    PrntHeading(FileName,PgNo); LineNo := 3;
  368.    Assign(SuFile,FileName);
  369.    Reset(SuFile);
  370.    repeat
  371.         Readln(SuFile,FileLine);
  372.         If Length(FileLine)>80 then Compress_Mode(True) else Compress_Mode(False);
  373.         Writeln(Lst,FileLine);
  374.         LineNo := LineNo + 1;
  375.         if LineNo >60 then begin
  376.           LineNo:=2; PgNo := PgNo + 1;
  377.           Writeln(Lst,#12);             {form-feed}
  378.           PrntHeading(FileName,PgNo);
  379.         end; {if}
  380.    until eof(SuFile);
  381.    Writeln(Lst); Writeln(Lst,#12);
  382. end; {DispFile}
  383.  
  384.  
  385. {*********************************************************************}
  386. {*          MAIN PROGRAM SECTION                                     *}
  387. {*********************************************************************}
  388.  
  389. begin
  390.   Welcome;
  391.   Init;
  392.   GetTail; if CmdTail='' then GetName else
  393.   begin
  394.     FileName:=CmdTail;
  395.     if not(Exist(FileName)) then GetName;
  396.   end;
  397.   FileName := Upper(FileName);
  398.   PrntFile;
  399.   Writeln;
  400.   Writeln('* DONE *');
  401. end.
  402.  
  403.  
  404.  
  405.  
  406.