home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / APPS / BUSINESS / TTYPRT36.ZIP / TTYPRT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-01-16  |  16.9 KB  |  379 lines

  1. PROGRAM ttyprt;
  2. {$m 49152,0,655360}
  3. (*****************************************************************************
  4. **
  5. **  Author: Robert W. Bloom
  6. **
  7. **  Function:  This program outputs a file in TTY format (double-spaced, all
  8. **             caps, 20 lines per page) with appropriate headers and footers
  9. **             to a HP LaserJet, Qume Kiss, NEC Spinwriter, or ALPS P2000
  10. **             printer.  It can read either a external ASCII or WordStar file,
  11. **             or handle direct input.  Special WordStar formatting (high bits,
  12. **             dot commands, etc) are handled correctly, but special commands
  13. **             (tabs, fonts) are not.  Also handles the straight ASCII files
  14. **             like can be output from Word Perfect and PC-Write.
  15. **
  16. **  Acknowledgement:  The original 'Le Message' was done by Mike Orlowicz who
  17. **             did all the hard stuff with the NEC printer.  I converted the
  18. **             original BASIC source to TurboPascal, added bells and
  19. **             whistles, and added the formatting for other printers.
  20. **
  21. ******************************************************************************)
  22.  
  23. USES printer,crt,dos;
  24. CONST
  25. {$define HPLJ}                  {should be HPLJ, NEC, KISS, or ALPS}
  26.     Version='v3.6, 16 Jan 91';
  27.  
  28. {$ifdef HPLJ}
  29.     TypPrt='HP LaserJet';      {'L' version for LaserJet w/OCR Font}
  30. {$endif}
  31. {$ifdef NEC}
  32.     TypPrt='NEC w/OCR  ';      {'N' version for NEC SpinWriter w/OCR Thimble}
  33. {$endif}
  34. {$ifdef KISS}
  35.     TypPrt='QMS Kiss   ';      {'K' version for Kiss w/OCR Cartridge}
  36. {$endif}
  37. {$ifdef ALPS}
  38.     TypPrt='ALPS w/Crtg';      {'K' version for ALPS w/OCR Cartridge}
  39. {$endif}
  40.     Max_Lines_Page=20;         {number of lines per page}
  41.     Max_Tty_Width=68;          {how wide is the TTY lines?}
  42.     Max_Mfr_Width=132;         {how wide is the MFR lines?}
  43.     Max_Tty_Length=400;        {max number of lines in a long tty (20 pages)}
  44.     Max_MFR_Length=100;        {max number of lines in a long mfr}
  45.     Max_Ed_Lines=500;          {max number of lines for mini-editor}
  46.     End_Mark='!';              {end message mark}
  47.     Sign_Line=53;              {line for signature block (NEC only)}
  48.     Sign_Length=35;            {max length of signature block line}
  49.     Bot_Class_Line=58;         {line for bottom classification (NEC only)}
  50.  
  51. {TYPED "CONSTANTS" -> used in HP LJ print positioning.  These are the defaults}
  52.                                {if the SIG_BLKS.DAT file is not found}
  53.     hp_lm : REAL = 6.1;        {left margin}
  54.     hp_tm : REAL = 2.1;        {top margin - where top classification goes}
  55.     hp_head : REAL = 5.2;      {absolute line number of the header line}
  56.     hp_no : REAL = 7.2;        {absolute line number of the 'BOOK' field}
  57.     hp_text : REAL = 8.7;      {absolute line number where text should start}
  58.     hp_sign : REAL = 54.0;     {absolute line number of first signature line}
  59.     hp_cl : REAL = 59.4;       {absolute line number of closing classification}
  60.     sfn : STRING[30] = 'SAVEMSG.TTY';   {file to save to from mini-editor}
  61.     rfn : STRING[30] = 'AUTOLOAD.MSG';  {file to read into mini-editor}
  62.     ifn : STRING[30] = '';              {file to read into file input}
  63.     bfn : STRING[30] = 'SIG_BLKS.DAT';  {signature blocks file name}
  64.     hfn : STRING[30] = 'HELP_MSG.OVL';  {on-line help file name}
  65.     ffn : STRING[30] = 'OCR-A.FNT';     {OCR soft font filename}
  66.     sfid : INTEGER = 1776;              {softfont id number, a 'good' year}
  67.  
  68. TYPE
  69.     FILE_STR=STRING[30];
  70.     S10=STRING[10];
  71.     S35=STRING[35];
  72.     IO_FILE_TYPE=TEXT;
  73.     SIG_BLK_REC=RECORD
  74.          code : CHAR;
  75.         line1 : S35;
  76.         line2 : S35;
  77.     END;
  78.  
  79. VAR
  80.     tty : ARRAY [1..Max_Tty_Length] OF STRING[Max_Tty_Width]; {the whole message}
  81.     mfr : ARRAY [1..Max_Mfr_Length] OF STRING[Max_Mfr_Width]; {possible MFR}
  82.     sig_blk : ARRAY [1..50] OF SIG_BLK_REC; {preset signature blocks}
  83. {   ed_text : ARRAY [1..Max_Ed_Lines] OF STRING[Max_Tty_Width]; 
  84.        editor buffer - defined in procedure mini-ed due to space constraints}
  85.     tot_tty_lines,tot_mfr_lines,        {number text, MFR lines}
  86.     tot_pages,                          {number pages in message}
  87.     cur_line, cur_page : INTEGER;       {current line, page}
  88.     io_file : IO_FILE_TYPE;             {all files are text}
  89.     start_page,end_page : INTEGER;      {printing limits}
  90.     class : STRING[25];                 {classification}
  91.     class_by,declass : S35;             {classified by, declassify lines}
  92.     act_pred,info_pred : STRING[2];     {precedences}
  93.     dtg : S10;                          {day time group}
  94.     sign1,sign2 : S35;                  {signature block}
  95.     mon_str : STRING[3];                {current month, three chars}
  96.     yr_str : STRING[2];                 {current year, two digits}
  97.  
  98. (******************* Procedure List ******************************************)
  99. FUNCTION menu : CHAR;                        FORWARD;
  100.     PROCEDURE help_msg(subj:S10);            FORWARD;
  101.     FUNCTION get_fn(c:CHAR) : S35;           FORWARD;
  102.     FUNCTION open_fn(fn:FILE_STR) : BOOLEAN; FORWARD;
  103.     FUNCTION get_line : STRING;              FORWARD;
  104.     PROCEDURE load_font;                     FORWARD;
  105. PROCEDURE mini_ed(restart:BOOLEAN);          FORWARD;
  106.     PROCEDURE disp_dir;                      FORWARD;
  107.     PROCEDURE chg_dir;                       FORWARD;
  108. PROCEDURE read_ifn;                          FORWARD;
  109. PROCEDURE get_hfaoi(EorF:CHAR);              FORWARD;
  110.     PROCEDURE disp_msg;                      FORWARD;
  111. PROCEDURE prt_msg(VAR ok : BOOLEAN);         FORWARD;
  112.     PROCEDURE prt_header;                    FORWARD;
  113.     PROCEDURE prt_body;                      FORWARD;
  114.     PROCEDURE prt_sign;                      FORWARD;
  115.     PROCEDURE prt_class;                     FORWARD;
  116. PROCEDURE prt_mfr;                           FORWARD;
  117.     PROCEDURE beep;                          FORWARD;
  118.  
  119. FUNCTION menu; { :char}
  120. (*****************************************************************************
  121. Initializes variables, asks for input file, gives help
  122. Returns character selected
  123. ******************************************************************************)
  124. LABEL help_loop,file_loop,file_menu;
  125. VAR
  126.     temp : STRING[132];
  127.     i : INTEGER;
  128.     c,opt : CHAR;    {menu selections}
  129. BEGIN
  130. help_loop:
  131.     TextBackGround(Black); TextColor(LightGreen);
  132.     WRITELN; WRITELN('Main Menu');
  133.     TextColor(LightCyan);
  134.     WRITELN; WRITE('Options:  ');
  135.     TextColor(LightRed);  WRITE('F  ');
  136.     TextColor(Cyan); WRITELN(#26,' To read message text from external WordStar or ASCII file');
  137.     TextColor(LightRed);  WRITE('          E  ');
  138.     TextColor(Cyan); WRITELN(#26,' To enter the message text directly with mini-editor');
  139. {$ifdef HPLJ}
  140.     TextColor(LightRed);  WRITE('          L  ');
  141.     TextColor(Cyan); WRITELN(#26,' To load OCR-A softfont into printer memory');
  142. {$endif}
  143.     TextColor(LightRed);  WRITE('          D  ');
  144.     TextColor(Cyan); WRITELN(#26,' Describe this program to me');
  145.     TextColor(LightRed);  WRITE('          ?  ');
  146.     TextColor(Cyan); WRITELN(#26,' Help!  Explain these options to me');
  147.     TextColor(LightRed);  WRITE('       <esc> ');
  148.     TextColor(Cyan); WRITELN(#26,' To exit TTYPRT without any further action');
  149.     WRITELN;
  150.     TextColor(Yellow);  WRITE('Waiting ');
  151.     opt:=READKEY;
  152.     WRITELN;
  153.     CASE opt OF
  154.     'e','E' : menu:='E';                    {input from keyboard into mini-editor}
  155.     'H','?' : BEGIN                         {display help message}
  156.                   help_msg('main');
  157.                   clrscr;
  158.                   GOTO help_loop
  159.               END;
  160. {$ifdef HPLJ}
  161.     'L','l' : BEGIN                         {Load soft font}
  162.                   load_font;
  163.                   clrscr;
  164.                   GOTO help_loop
  165.               END;
  166. {$endif}
  167.     'D','d' : BEGIN                         {display help message}
  168.                   help_msg('full');
  169.                   clrscr;
  170.                   GOTO help_loop
  171.               END;
  172.     'X',#27 : BEGIN                     {exit}
  173.                   WRITELN; TextColor(Cyan);
  174.                   WRITELN('TTYPRT completed, returning to DOS.');
  175.                   halt
  176.               END;
  177.     'f','F' : BEGIN                         {input from file}
  178. file_menu:
  179.                   ClrScr;
  180.                   TextColor(LightGreen); WRITELN('Input from external file');
  181.                   WRITELN;
  182.                   TextColor(LightCyan);   WRITE('    Options:   ');
  183.                   TextColor(LightRed);  WRITE('*   ');
  184.                   TextColor(Cyan); WRITELN(#26,' To display current file directory');
  185.                   TextColor(LightRed);  WRITE('               .   ');
  186.                   TextColor(Cyan); WRITELN(#26,' To change the current directory');
  187.                   TextColor(LightRed);  WRITE('             <esc> ');
  188.                   TextColor(Cyan); WRITELN(#26,' To exit back to main menu');
  189.                   TextColor(LightRed);  WRITE('               ?   ');
  190.                   TextColor(Cyan); WRITELN(#26,' Help!  Explain this to me');
  191.                   TextColor(LightRed);  WRITE('             _____ ');
  192.                   TextColor(Cyan); WRITELN(#26,' Filename to read');
  193. file_loop:
  194.                   WRITELN; TextColor(Yellow);
  195.                   WRITE('Enter filename to use for message text (or other option) ',#26,' ');
  196.                   c:=READKEY; TextBackground(Blue); TextColor(LightGray);
  197.                   WRITE(c); TextBackground(Black);
  198.                   CASE c OF
  199.                   '*' : BEGIN
  200.                             disp_dir;
  201.                             GOTO file_loop
  202.                         END;
  203.                   '.' : BEGIN
  204.                             chg_dir;
  205.                             GOTO file_loop
  206.                         END;
  207.                   '?'  : BEGIN
  208.                             help_msg('extread');
  209.                             GOTO file_menu;
  210.                         END;
  211.                   ^M,#27 : BEGIN
  212.                             clrscr;
  213.                             GOTO help_loop;
  214.                         END;
  215.                   ELSE  BEGIN
  216.                             ifn:=get_fn(c);
  217.                             IF Length(ifn)=0 THEN BEGIN
  218.                                 TextBackground(Black); ClrScr;
  219.                                 GOTO help_loop;
  220.                             END;
  221.                             IF NOT open_fn(ifn) THEN BEGIN
  222.                                 beep; TextColor(LightMagenta+Blink);
  223.                                 WRITELN; WRITELN('File not found');
  224.                                 TextColor(Cyan);
  225.                                 GOTO file_loop
  226.                             END;
  227.                             menu:='F'
  228.                         END
  229.                   END {case}
  230.               END;
  231.     ELSE      BEGIN                         {beep if anything else}
  232.                   beep;
  233.                   GOTO help_loop
  234.               END
  235.     END {case}
  236. END; {FUNCTION menu}
  237.  
  238. PROCEDURE read_ifn;
  239. (*****************************************************************************
  240. Reads entire message, counts lines, checks for overlong lines, aborts if so.
  241. ******************************************************************************)
  242. VAR
  243.     ln_2_long,end_text : BOOLEAN;
  244.     c : CHAR;          {char to read from file}
  245.     tmpstr : STRING[132];  {line to read}
  246.     lc : BYTE;      {line count}
  247. BEGIN
  248.     WRITELN; TextColor(Cyan);
  249.     WRITELN('reading and checking file for length ... ');
  250.     lc:=1; end_text:=FALSE; ln_2_long:=FALSE;
  251.     WHILE (NOT EOF(io_file)) AND (NOT end_text) AND (lc<=Max_Tty_Length) DO BEGIN
  252.         TextColor(Cyan); WRITE(^M'reading line ',lc);
  253.         tmpstr:=get_line;
  254.         IF (LENGTH(tmpstr)>0) AND (tmpstr[1]<>'.') THEN BEGIN
  255.             {don't save blank lines or dot commands}
  256.             IF tmpstr[1]='!' THEN
  257.                 end_text:=TRUE           {end of text section}
  258.             ELSE IF LENGTH(tmpstr)>Max_Tty_Width THEN BEGIN
  259.                 ln_2_long:=TRUE;
  260.                 TextColor(Cyan); WRITELN(^M'Line ',lc:2,' too long:');
  261.                 TextColor(LightGray); WRITELN(' -> ',tmpstr);
  262.                 lc:=lc+1
  263.             END ELSE BEGIN
  264.                 tty[lc]:=tmpstr;
  265.                 tty[lc][0]:=tmpstr[0];   {match actual lengths}
  266.                 lc:=lc+1
  267.             END
  268.         END
  269.     END; {while}
  270.     tot_tty_lines:=lc-1;
  271.  
  272.     lc:=1; tmpstr:='';
  273.     WRITELN; TextColor(Cyan);
  274.     WRITELN('Reading MFR, if any');
  275.     WHILE (NOT EOF(io_file)) AND (NOT ln_2_long) AND (lc<=Max_Tty_Length) DO BEGIN
  276.         TextColor(Cyan); WRITE(^M'reading line ',lc);
  277.         tmpstr:=get_line;
  278.         IF tmpstr[1]<>'.' THEN BEGIN        {don't save dot commands}
  279.             mfr[lc]:=tmpstr;
  280.             mfr[lc][0]:=tmpstr[0];
  281.             lc:=lc+1
  282.         END
  283.     END; {while}
  284.     CLOSE(io_file);
  285.     tot_mfr_lines:=lc-1;                     {total number of lines in mfr}
  286.     WRITELN;
  287.  
  288.     IF lc>Max_Tty_Length THEN BEGIN
  289.         beep; TextColor(LightMagenta+Blink);
  290.         WRITELN(^M'Message is longer than ',Max_Tty_Length,' lines.');
  291.         TextColor(LightMagenta);
  292.         WRITELN('TTYPRT cannot handle a message that long.  Please split up and');
  293.         WRITELN('send as two (or more) separate messages.');
  294.         TextColor(Yellow);
  295.         WRITELN; WRITE('Strike any key to return to DOS ');
  296.         c:=READKEY;
  297.         halt
  298.     END;
  299.     IF ln_2_long THEN BEGIN
  300.         beep; TextColor(LightMagenta);
  301.         WRITELN(^M'One or more lines are overlong.  Switching input to');
  302.         WRITELN('TTYPRT''s mini-editor.  Please correct lines as necessary.');
  303.         WRITELN; TextColor(Yellow);
  304.         WRITE('Strike <esc> to abort or any other key to continue on to mini-editor.');
  305.         c:=READKEY;
  306.         WRITELN;
  307.         IF c=#27 THEN halt;
  308.         rfn:=ifn;
  309.         mini_ed(FALSE);
  310.     END
  311. END; {PROCEDURE read_ifn;}
  312.  
  313. {$i util.pas}             {utility procedures}
  314. {$i hfaoi.pas}            {get Header, Footer And Output Information}
  315. {$i out_proc.pas}         {output procedures and printer-specific stuff}
  316. {$i mini_ed.pas}          {mini_editor with other sub-procedures}
  317.  
  318. (******************* Main Program ********************************************)
  319. VAR
  320.     prt_ok : BOOLEAN;
  321.     i : INTEGER;
  322.     select: CHAR;
  323. BEGIN
  324.     TextBackground(Black); TextColor(Green); ClrScr;
  325.     GOTOXY(24, 1); WRITE('╔═══════════════════════════════╗');
  326.     GOTOXY(24, 2); WRITE('║                               ║');
  327.     GOTOXY(24, 3); WRITE('║                               ║');
  328.     GOTOXY(24, 4); WRITE('║                               ║');
  329.     GOTOXY(24, 5); WRITE('╠═══════════════════════════════╣');
  330.     GOTOXY(24, 6); WRITE('║                               ║');
  331.     GOTOXY(24, 7); WRITE('║                               ║');
  332.     GOTOXY(24, 8); WRITE('║                               ║');
  333.     GOTOXY(24, 9); WRITE('║                               ║');
  334.     GOTOXY(24,10); WRITE('║                               ║');
  335.     GOTOXY(24,11); WRITE('╚═══════════════════════════════╝');
  336.     TextColor(Yellow);
  337.     GOTOXY(31, 2); WRITE('T T Y   P R I N T !');
  338.     TextColor(Cyan);
  339.     GOTOXY(33, 3); WRITE(version);
  340.     GOTOXY(31, 4); WRITE('Printer: ');
  341.     TextBackground(Blue); TextColor(LightGray); WRITE(TypPrt);
  342.     TextBackground(Black); TextColor(Cyan);
  343.     GOTOXY(29, 7); WRITE('Formats and prints files');
  344.     GOTOXY(34, 8); WRITE('for a DD173/2');
  345.     GOTOXY(31, 9); WRITE('(Joint Messageform)');
  346.     GOTOXY( 9,12);
  347.     tot_tty_lines:=0; tot_mfr_lines:=0;
  348.     FOR i:=1 TO Max_Tty_Length DO tty[i]:='';   {clear msg buffer}
  349.     FOR i:=1 TO Max_Mfr_Length DO mfr[i]:='';   {clear mfr buffer}
  350.     IF paramcount=0 THEN BEGIN          {any filename on command line?}
  351.         ifn:='';                        {no, so zero it}
  352.         select:=menu                    {and get char from menu}
  353.     END ELSE BEGIN
  354.         ifn:=ParamStr(1);               {yes, filename given on command line}
  355.         IF NOT open_fn(ifn) THEN BEGIN      {so open it}
  356.             beep; TextColor(LightMagenta+Blink);
  357.             WRITELN('Filename given on command line not found');
  358.             TextColor(Cyan);
  359.             select:=menu                {if not openable, ask!}
  360.         END ELSE BEGIN
  361.             select:=' ';                 {non-menu selection}
  362.             read_ifn                    {and read it}
  363.         END
  364.     END;
  365.  
  366.     CASE select OF
  367.        'E' : mini_ed(FALSE);            {goto mini editor}
  368.        'F' : read_ifn;                  {read input file if so stated}
  369.     {else, file given on command line and read successfully}
  370.     END; {case}
  371.     get_hfaoi(select);                  {get the header/footer/output info}
  372.     prt_msg(prt_ok);                    {and print it}
  373.     WRITELN;
  374.     IF (cur_page<=end_page) AND prt_ok AND (tot_mfr_lines>0) THEN prt_mfr;
  375.                                         {and mfr if printing all}
  376.     WRITELN; TextColor(Cyan);
  377.     WRITELN('TTYPrt completed.')        {all done}
  378. END. {program}
  379.