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

  1. {These are the routines to run the mini-editor}
  2.  
  3. PROCEDURE mini_ed; {restart:BOOLEAN}
  4. (*****************************************************************************
  5. input message text directly
  6. -> note: lots of sub-subprocedures!
  7. ******************************************************************************)
  8. CONST
  9.     Ins_Mode : BOOLEAN = TRUE;          {editor mode: TRUE=Insert, FALSE=Overwrite}
  10.     Tab_Col = 15;                       {tab column}
  11.     Ln_Pg = 20;                         {maximum lines/pg in mini-editor}
  12. VAR
  13.     c             : CHAR;               {input character}
  14.     done,anyc     : BOOLEAN;            {flow control}
  15.     ln,cc,top_ln  : INTEGER;            {current line#, Col#, top screen line}
  16.     tmpstr        : STRING;             {temp string}
  17.     delstr,spaces : STRING[Max_Tty_Width]; {deleted, and blank line}
  18.     i,j,k,err     : INTEGER;            {flow control}
  19.     end_mfr_ln,msi,end_ed_msg : INTEGER;{count of last MFR line}
  20.     ed_text : ARRAY [1..Max_Ed_Lines] OF STRING[Max_Tty_Width]; {editor buffer}
  21.     last_ln : INTEGER;                  {what is last non-blank line of buffer}
  22.  
  23. {sub-subprocedures for the mini-editor}
  24. (****************************************************)
  25. PROCEDURE mini_editor;                  FORWARD;
  26. PROCEDURE inp_ctrl;                     FORWARD;
  27. PROCEDURE inp_extchr;                   FORWARD;
  28. PROCEDURE inp_char;                     FORWARD;
  29. PROCEDURE dr_frame;                     FORWARD;
  30. PROCEDURE dr_page;                      FORWARD;
  31. PROCEDURE dr_loc;                       FORWARD;
  32. FUNCTION wrapper : BYTE;                FORWARD;
  33. PROCEDURE ed_help;                      FORWARD;
  34.  
  35. {$i ed_file.pas}                        {file actions}
  36. {$i ed_procs.pas}                       {char insert/del procedures}
  37. {$i ed_curse.pas}                       {cursor movements}
  38.  
  39. PROCEDURE mini_editor;
  40. (*****************************************************************************
  41. input and edit message text
  42. ******************************************************************************)
  43. BEGIN
  44.     dr_loc;                             {mark cursor location}
  45.     done:=FALSE;
  46.     WHILE NOT done DO BEGIN
  47.         c:=ReadKey;                     {get a keystroke}
  48.         IF c <> #0 THEN
  49.             IF ORD(c)<32 THEN
  50.                 inp_ctrl                {control keys}
  51.             ELSE
  52.                 inp_char                {standard input}
  53.             {end}
  54.         ELSE BEGIN
  55.             c:=ReadKey;                 {function keys}
  56.             inp_extchr
  57.         END;
  58.         dr_loc                          {mark cursor location}
  59.     END
  60. END; {PROCEDURE mini_editor}
  61.  
  62. PROCEDURE inp_ctrl;
  63. (*****************************************************************************
  64. process control char
  65. ******************************************************************************)
  66. var temp,i:INTEGER;
  67. BEGIN
  68.     CASE c OF                           {control & ASCII keys}
  69.     ^M : ed_ent;                        {<ret> or <ent>}
  70.     ^N : ed_insln;                      {insert blank line}
  71.     ^I : ed_tab;                        {tab}
  72.     ^H : ed_bs;                         {destructive backspace}
  73.     ^U : ed_recall;                     {recall line}
  74.     ^Y : ed_delln;                      {delete line}
  75.     ^G : ed_del;                        {delete char}
  76.     ^V : ed_ins;                        {insert mode toggle}
  77.     ^E : ed_up;                         {cursor up}
  78.     ^X : ed_down;                       {cursor down}
  79.     ^S : ed_left;                       {cursor left}
  80.     ^D : ed_right;                      {cursor right}
  81.     ^F : ed_fwdwd;                      {forward a word}
  82.     ^A : ed_bckwd;                      {back a word}
  83.     ^R : ed_pgup;                       {page up}
  84.     ^C : ed_pgdn;                       {page down}
  85.     ^K : BEGIN                          {file ops}
  86.              GOTOXY(30,1);
  87.              WRITE('^K');
  88.              c:=ReadKey;                {get a keystroke}
  89.              CASE c OF
  90.              'W','w',^W : savefile;     {write to file}
  91.              'D','d',^D : done:=TRUE;   {save and exit}
  92.              'R','r',^R : BEGIN
  93.                               readfile(TRUE);    {request and read file}
  94.                               dr_frame; dr_page  {redraw screen}
  95.                           END;
  96.              'Q','q',^Q : BEGIN
  97.                               ed_abort; {quit - abort?}
  98.                               dr_frame; dr_page;
  99.                           END
  100.              END; {case}
  101.              GOTOXY(30,1);
  102.              WRITE('  ');
  103.          END;
  104.     ^Q : BEGIN                          {quick ops}
  105.              GOTOXY(30,1);
  106.              WRITE('^Q');
  107.              c:=ReadKey;                {get a keystroke}
  108.              CASE c OF
  109.              'R','r',^R : ed_tof;       {top of file}
  110.              'C','c',^C : ed_eof;       {end of file}
  111.              'E','e',^E : ed_home;      {top of screen}
  112.              'X','x',^X : ed_end;       {end of screen}
  113.              'D','d',^D : ed_eol;       {end of line}
  114.              'S','s',^S : ed_bol;       {beginning of line}
  115.              'F','f',^F : ed_find;      {find}
  116.              'Y','y',^Y : ed_deleol;    {delete to eol}
  117.              END; {case}
  118.              GOTOXY(30,1);
  119.              WRITE('  ');
  120.          END;
  121.     ^W : ed_scrldown;                   {scroll down}
  122.     ^Z : ed_scrlup;                     {scroll up}
  123.     ELSE
  124.         beep;                           {undefined control char}
  125.     END {case - ASCII chars}
  126. END; {PROCEDURE inp_ctrl}
  127.  
  128. PROCEDURE inp_extchr;
  129. (*****************************************************************************
  130. extended editing chars
  131. ******************************************************************************)
  132. VAR i:integer;
  133. BEGIN
  134.     CASE ORD(c) OF
  135.     44 : ed_zap;                        {alt-Z - zap (clear) msg text}
  136.     45 : BEGIN                          {alt-X - abort}
  137.             ed_abort;
  138.             dr_frame; dr_page;
  139.          END;
  140.     59 : ed_help;                       {F1-Editor Help}
  141. {   60 :                                {F2-not used}
  142. {   61 :                                {F3-not used}
  143. {   62 :                                {F4-not used}
  144.     63 : Savefile;                      {F5-save (write) file}
  145.     64 : BEGIN
  146.             readfile(TRUE);             {F6-request and read (insert) file}
  147.             dr_frame; dr_page           {redraw screen}
  148.          END;
  149.     65 : ed_delln;                      {F7-delete line}
  150.     66 : ed_insln;                      {F8-insert blank line}
  151.     67 : ed_recall;                     {F9-recall deleted line}
  152.     68 : done:=TRUE;                    {F10-done editing}
  153.     71 : ed_home;                       {home}
  154.     72 : ed_up;                         {up arrow}
  155.     73 : ed_pgup;                       {pg Up}
  156.     75 : ed_left;                       {left arrow}
  157.     77 : ed_right;                      {right arrow}
  158.     79 : ed_end;                        {end}
  159.     80 : ed_down;                       {down arrow}
  160.     81 : ed_pgdn;                       {Pg Down}
  161.     82 : ed_ins;                        {insert}
  162.     83 : ed_del;                        {del}
  163.    115 : ed_bol;                        {ctrl-left arrow}
  164.    116 : ed_eol;                        {ctrl-right arrow}
  165.    117 : ed_end;                        {ctrl-end}
  166.    118 : ed_eof;                        {ctrl-pgdn}
  167.    119 : ed_tof;                        {ctrl-home}
  168.    132 : ed_tof;                        {ctrl-Pgup}
  169.     ELSE
  170.          beep;                          {undefined extended character}
  171.     END {case - extended chars}
  172. END; {PROCEDURE inp_extchr}
  173.  
  174. PROCEDURE inp_char;
  175. (*****************************************************************************
  176. input one character (standard input)
  177. ******************************************************************************)
  178. VAR i:INTEGER;
  179.     pos:BYTE;
  180. BEGIN
  181.     c:=UpCase(c);     {force uppercase}
  182.     IF Ins_Mode THEN BEGIN
  183.         tmpstr:=copy(ed_text[ln],1,cc-1)+C+       {insert char into line}
  184.             copy(ed_text[ln],cc,Max_Tty_Width);
  185.         pos:=wrapper;                             {& wrap}
  186.         IF pos>0 THEN BEGIN                       {it took two lines, so}
  187.             IF cc>Max_Tty_Width-pos THEN BEGIN  {is cursor in wrap portion?}
  188.                 ln:=ln+1;                         {and put cursor in place}
  189.                 cc:=pos-(Max_Tty_Width-cc)-1;
  190.                 IF top_ln+Ln_Pg-1<ln THEN top_ln:=top_ln+1
  191.             END;
  192.             dr_page                               {redraw whole page}
  193.         END ELSE BEGIN
  194.             GOTOXY(2,3+ln-top_ln);                {redraw just this line}
  195.             WRITE(ed_text[ln])
  196.         END;
  197.     END ELSE
  198.         IF cc=Max_Tty_Width+1 THEN BEGIN
  199.             tmpstr:=ed_text[ln]+C;                {tag the char on eol}
  200.             pos:=wrapper;                         {& wrap}
  201.             ln:=ln+1;
  202.             cc:=pos-(Max_Tty_Width-cc)-1;       {and put cursor in place}
  203.             IF top_ln+Ln_Pg-1<ln THEN top_ln:=top_ln+1;
  204.             dr_page                               {redraw whole page}
  205.         END ELSE BEGIN
  206.             ed_text[ln][cc]:=c;                   {insert the character}
  207.             WRITE(c)
  208.         END;
  209.     {end}
  210.     ed_right;                                     {move cursor}
  211.     IF last_ln<ln THEN last_ln:=ln;               {mark the last line}
  212. END; {PROCEDURE inp_char}
  213.  
  214. PROCEDURE dr_frame;
  215. (*****************************************************************************
  216. displays editing screen
  217. ******************************************************************************)
  218. VAR i:INTEGER;
  219. BEGIN
  220.     TextBackground(black); TextColor(Yellow); ClrScr;
  221.     WRITE('TTY Print!  Mini Editor              ');
  222.     TextColor(Cyan); WRITELN('Last Line:    Current Line:    Column:');
  223.     TextColor(green);
  224.  
  225.     GOTOXY(1, 2); WRITE('┌────────────────────────────────────────────────────────────────────┐');
  226.     FOR i:=3 TO 22 DO BEGIN
  227.         GOTOXY( 1,i); WRITE('│');
  228.         GOTOXY(70,i); WRITE('│');
  229.     END;
  230.     GOTOXY(1,23); WRITE('└────────────────────────────────────────────────────────────────────┘');
  231.  
  232.     GOTOXY(71, 3); TextColor(LightRed); WRITE('<F1> '); TextColor(Cyan); WRITE('for');
  233.     GOTOXY(71, 4); WRITE('  Help');
  234.     GOTOXY(71, 6); WRITE('Use Arrow');
  235.     GOTOXY(71, 7); WRITE(' Keys to');
  236.     GOTOXY(71, 8); WRITE('mov cursr');
  237.     GOTOXY(71,10); TextColor(LightRed); WRITE('<INS>'); TextColor(Cyan); WRITE('Mode');
  238.     GOTOXY(71,11); TextColor(LightRed); WRITE('<Tab>'); TextColor(Cyan); WRITE('Addr');
  239.     GOTOXY(71,13); TextColor(LightRed); WRITE('<F5>'); TextColor(Cyan); WRITE('SavFn');
  240.     GOTOXY(71,14); TextColor(LightRed); WRITE('<F6>'); TextColor(Cyan); WRITE('ReadF');
  241.     GOTOXY(71,15); TextColor(LightRed); WRITE('<F7>'); TextColor(Cyan); WRITE('DelLn');
  242.     GOTOXY(71,16); TextColor(LightRed); WRITE('<F8>'); TextColor(Cyan); WRITE('InsLn');
  243.     GOTOXY(71,18); TextColor(LightRed); WRITE(' <Alt-X>');
  244.     GOTOXY(71,19); TextColor(Cyan); WRITE(' to quit');
  245.     GOTOXY(71,21); TextColor(LightRed);WRITE(' <F10> '); TextColor(Cyan); WRITE('to');
  246.     GOTOXY(71,22); WRITE('Save/Exit');
  247.  
  248.     GOTOXY( 5,24); WRITE('Mode:');
  249.     GOTOXY(11,24); TextColor(LightGray); TextBackGround(Blue);
  250.     IF Ins_Mode THEN
  251.         WRITE('Insert   ')
  252.     ELSE
  253.         WRITE('Overwrite');
  254. END; {PROCEDURE dr_frame}
  255.  
  256. PROCEDURE dr_page;
  257. (*****************************************************************************
  258. fills in editing screen with lines to be edited
  259. ******************************************************************************)
  260. VAR i:INTEGER;
  261. BEGIN
  262.     TextColor(LightGray); TextBackGround(Blue);
  263.     FOR i:=1 TO Ln_Pg DO BEGIN
  264.         GOTOXY(2,2+i);
  265.         WRITE(ed_text[top_ln-1+i])
  266.     END;
  267. END; {PROCEDURE dr_page}
  268.  
  269. PROCEDURE dr_loc;
  270. (*****************************************************************************
  271. marks location of cursor on editing screen
  272. ******************************************************************************)
  273. BEGIN
  274.     TextColor(LightGray); TextBackGround(Blue);
  275.     GOTOXY(48,1); WRITE(last_ln:3);
  276.     GOTOXY(65,1); WRITE(ln:3);
  277.     GOTOXY(78,1); WRITE(cc:2);
  278.     GOTOXY(1+cc,3+ln-top_ln)
  279. END; {PROCEDURE dr_loc}
  280.  
  281. FUNCTION wrapper; {: BYTE}
  282. (*****************************************************************************
  283. do an autowrap of the current line, if non-blank overflow insert to
  284. next line.  Returns number of characters wrapped to second line
  285. ******************************************************************************)
  286. VAR
  287.     cln,non_sp,lst_sp,i,orgln:INTEGER;
  288.     wrapstr:STRING[Max_Tty_Width];
  289.     keychr:CHAR;     {first char of next line}
  290. BEGIN
  291.     orgln:=ln;              {store original line we started from}
  292.     i:=length(tmpstr);
  293.     WHILE (tmpstr[i]=' ') AND (i>Max_Tty_Width) DO i:=i-1;
  294.     IF i<=Max_Tty_Width THEN BEGIN           {no added line is neccessary}
  295.         ed_text[ln]:=COPY(tmpstr+spaces,1,Max_Tty_Width);
  296.         wrapper:=0
  297.     END ELSE BEGIN          {given input line requires two output lines}
  298.         non_sp:=i;
  299.         WHILE ((tmpstr[i]<>' ') OR (i>Max_Tty_Width)) AND (i>0) DO i:=i-1;
  300.         IF i=0 THEN
  301.             lst_sp:=Max_Tty_Width {no spaces in line, so break at last pos}
  302.         ELSE
  303.             lst_sp:=i;
  304.         wrapstr:=COPY(tmpstr,lst_sp+1,non_sp-lst_sp);
  305.         ed_text[ln]:=COPY(COPY(tmpstr,1,lst_sp)+spaces,1,Max_Tty_Width);
  306.         keychr:=ed_text[ln+1][1];
  307.         IF (keychr=' ') OR (keychr='!') OR                {if next line is blank}
  308.             ((keychr>'1') AND (keychr<'9')) THEN BEGIN    {or starts a new paragraph}
  309.             FOR i:=last_ln DOWNTO ln+1 DO  {bump every subsequent line down one}
  310.                 ed_text[i+1]:=ed_text[i];
  311.             ed_text[ln+1]:=COPY(wrapstr+spaces,1,Max_Tty_Width); {overflow to next ln}
  312.             last_ln:=last_ln+1;                {we added a line to msg}
  313.         END ELSE BEGIN
  314.             ln:=ln+1;                          {now on next line}
  315.             tmpstr:=wrapstr+' '+ed_text[ln];   {add wrap string to next line}
  316.             i:=wrapper;                        {recursive! throw away return value}
  317.         END;
  318.         ln:=orgln;                             {return value to original line}
  319.         wrapper:=LENGTH(wrapstr);              {where cursor should be on next line}
  320.     END
  321. END; {FUNCTION wrapper : BYTE}
  322.  
  323. (************* main mini editor routine ***************)
  324.  
  325. BEGIN
  326.     spaces:= '';                        {initialize to all spaces}
  327.     FOR i:=1 TO Max_Tty_Width DO spaces:=spaces+' ';
  328.     delstr:=spaces;                     {initialize delete line buffer}
  329.     ln:=1; top_ln:=1;                   {setup}
  330.  
  331.     IF restart THEN BEGIN               {do this if restarting mini-ed}
  332.         FOR i:=1 TO Tot_tty_lines DO    {copy message back into mini-ed buff}
  333.             ed_text[i]:=COPY(tty[i]+spaces,1,Max_Tty_Width);
  334.         IF tot_mfr_lines > 0 THEN BEGIN {any mfr?}
  335.             tty[tot_tty_lines+1]:=COPY('!'+spaces,1,Max_Tty_Width);
  336.             msi:=tot_tty_lines+2;
  337.             FOR i:=1 TO Tot_mfr_lines DO BEGIN
  338.                 ed_text[msi]:=COPY(mfr[i]+spaces,1,Max_Tty_Width);
  339.                 msi:=msi+1
  340.             END
  341.         END;
  342.         last_ln:=tot_tty_lines+1+tot_mfr_lines;
  343.     END ELSE BEGIN                      {else do this first time only}
  344.         FOR i:=1 TO Max_Ed_Lines DO ed_text[i]:=spaces;
  345.         last_ln:=1;
  346.         readfile(FALSE)                 {try to open and read autoload.msg file}
  347.     END;
  348.     dr_frame; dr_page;                  {draw screen}
  349.     ed_tof;                             {start cursor at TOF}
  350.     mini_editor;                        {call editor}
  351.     savefile;                           {save file}
  352.     msi:=1;
  353.     i:=1;
  354.     WHILE (ed_text[i][1] <> End_Mark) AND (i<=last_ln) DO BEGIN
  355.         anyc:=FALSE;                    {copy ed_text to tty}
  356.         FOR j:=1 TO Max_Tty_Width DO  {set flag if non-blank}
  357.             IF ed_text[i][j] <> #32 THEN anyc:=TRUE;
  358.         IF anyc THEN BEGIN
  359.             tty[msi]:=ed_text[i];      {only copy non-blank lines}
  360.             msi:=msi+1;
  361.             IF msi>Max_TTY_Length THEN BEGIN
  362.                 TextBackGround(black); clrscr;
  363.                 beep; TextColor(LightMagenta+Blink);
  364.                 WRITELN('Message is longer than ',Max_Tty_Length,' lines.');
  365.                 TextColor(LightMagenta);
  366.                 WRITELN('i.e., Msg text in mini-editor exceeds ',Max_tty_Length/20:0,' TTY pages,');
  367.                 WRITELN;
  368.                 WRITELN('TTYPRT cannot handle a message that long.  Please split up and');
  369.                 WRITELN('send as two (or more) separate messages.');
  370.                 TextColor(Yellow);
  371.                 WRITELN;
  372.                 WRITELN('Strike any key to save file (if not done already)');
  373.                 WRITE('and then return to DOS ');
  374.                 c:=READKEY;
  375.                 savefile;
  376.                 halt
  377.             END
  378.         END;
  379.         i:=i+1
  380.     END;
  381.     tot_tty_lines:=msi-1;                    {total lines in tty}
  382.  
  383.     msi:=1;                                  {init mfr line counter}
  384.     IF ed_text[i][1] = End_Mark THEN BEGIN   {is there a mfr?}
  385.         i:=i+1;                              {point to first line in mfr}
  386.         WHILE (i <= last_ln) AND (msi>Max_MFR_Length) DO BEGIN
  387.             mfr[msi]:=ed_text[i];
  388.             msi:=msi+1;
  389.             IF msi>Max_MFR_Length THEN BEGIN
  390.                 TextBackGround(black); clrscr;
  391.                 beep; TextColor(LightMagenta);
  392.                 WRITELN('MFR is longer than ',Max_MFR_Length,' lines.');
  393.                 WRITELN;
  394.                 WRITELN('TTYPRT cannot handle MFRs that long.');
  395.                 WRITELN('Additional text will be truncated.');
  396.                 TextColor(Yellow);
  397.                 WRITELN;
  398.                 WRITE('Strike any key to continue ');
  399.                 c:=READKEY
  400.             END;
  401.             i:=i+1
  402.         END
  403.     END;
  404.     tot_mfr_lines:=msi-1;
  405. END; {PROCEDURE mini_ed;}
  406.