home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / edit / clmwp / clmwp.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1986-02-21  |  52.4 KB  |  2,109 lines

  1. {$I-,V-,C-,U-,K-,D-}
  2. Program Words;
  3.  
  4. CONST
  5.   OFF        = false;
  6.   ON         = True;
  7.   ENDLINE    = 4021;
  8.   TOPEND     = 4000;
  9.   cnotice    = '  Copyright  1986,  K. D. Sherrets,  P. O. Box 37093,  Omaha,  NE   68137';
  10. type
  11.   str255 = string[255];
  12.   Str80 = String[80];
  13.   anystr = string[80];
  14.   CharSet = Set of Char;
  15.   registers = Record case integer of
  16.                  0 : (ax,bx,cx,dx,bp,si,di,ds,es,flags: integer);
  17.                  1 : (al,ah,bl,bh,cl,ch,dl,dh : byte);
  18.               End;
  19.  
  20.   Screentype  = array [1..4000] of byte;
  21.   WPLine = String[79];
  22. var
  23.   Astring    : string[80];
  24.   Att,
  25.   fcol,
  26.   frow       : byte;
  27.   Aendline   : integer;
  28.   Atopend    : integer;
  29.   heaptop    : ^integer;
  30.   Cdir,
  31.   WPFileVar,
  32.   DFilevar,
  33.   tempfile   : String[60];
  34.   WPFileName : text[$F00];
  35.   DFileName  : text[$F00];
  36.   WrapOn,
  37.   MarkBlock,
  38.   SAVED      : BOOLEAN;
  39.   sline      : array [1..endline] of ^wpline;
  40.   dline      : array [1..99] of string[79];
  41.   nomem,
  42.   noprint,
  43.   formright,
  44.   Inserton   : Boolean;
  45.   lns,
  46.   PriorLN,
  47.   MarkOne,
  48.   MarkTwo,
  49.   xx,
  50.   MAXLN,
  51.   LNN        : Integer;
  52.   newline,
  53.   ckln       : string[80];
  54.   Fword,
  55.   Junk,
  56.   Temp,
  57.   Tbuff      : string[79];
  58.   pageYN,
  59.   pause,
  60.   priorch,
  61.   NumYn,
  62.   Ch,
  63.   zip,
  64.   YN         : Char;
  65.   Last,
  66.   LineNum,
  67.   priorP,
  68.   PP,
  69.   Header,
  70.   Bottom,
  71.   margin,
  72.   pagesize,
  73.   count,
  74.   linewidth,
  75.   TopLine,
  76.   online,
  77.   OldXpos,
  78.   OldYpos,
  79.   Crtmode     : integer;
  80.   Screen      : Screentype;
  81.   Monobuffer  : Screentype absolute $B000:$0000;
  82.   Colorbuffer : Screentype absolute $B800:$0000;
  83.  
  84.  
  85. PROCEDURE Typeadapter;
  86. var
  87.   regs  : registers;
  88. BEGIN
  89.    with regs do
  90.    begin
  91.      ah := 15;
  92.      intr($10,regs);
  93.      crtmode := al;
  94.    end;
  95. END;
  96.  
  97. PROCEDURE bigw;
  98. begin
  99.   window(1,1,80,25);
  100. end;
  101.  
  102. PROCEDURE littlew;
  103. begin
  104.   window(1,1,80,22);
  105. end;
  106.  
  107.  
  108. PROCEDURE BEEP;
  109. begin
  110.    Write(chr(7));
  111. end;
  112.  
  113. PROCEDURE PromptAt(x : byte; y : byte; promptstr : str80);
  114. begin
  115.   gotoxy(x,y);
  116.   write(promptstr);clreol;
  117. end;
  118.  
  119. PROCEDURE cursor(switchon : boolean);
  120. var
  121.    regs  : registers;
  122. begin
  123.   with regs do
  124.   begin
  125.     if crtmode <> 7 then
  126.     begin
  127.       if switchon then ch := 6 else ch := $20;
  128.       cl := 7;
  129.     end
  130.     else
  131.     begin
  132.       if switchon then ch := 12 else ch := $20;
  133.       cl := 13;
  134.     end;
  135.     ah := 1;
  136.     intr($10,regs);
  137.   end;
  138. end;
  139.  
  140. PROCEDURE TextInfo;
  141. var
  142.    pageno : integer;
  143. begin
  144.    bigw;
  145.    lowvideo;
  146.    cursor(off);
  147.    if maxln >= aendline -6 then
  148.    begin
  149.      PromptAt(1,24,'Warning - Text Buffer full!  Save your file');
  150.      write(chr(7));
  151.    end;
  152.    gotoxy(20,25);
  153.    pageno := (lnn div (1+ pagesize -header-bottom)) + 1;
  154.    write('Page: ',pageno,', Line: ',LNN,', Col: ',pp+1,', Lines Used: ',maxln);clreol;
  155.    cursor(on);
  156.    highvideo;
  157. end;
  158.  
  159. PROCEDURE wpstatus;
  160. begin
  161.   bigw;
  162.   PromptAt(1,24,'"F10" = Quit,  "Alt & F10" = Help');
  163.   gotoxy(36,24);
  164.   lowvideo;
  165.   if InsertOn then write('Insert-On: ',WPFileVar)
  166.   else write('Overwrite: ',WPFileVar);
  167.   textinfo;
  168. end;
  169.  
  170. PROCEDURE writewrapon;
  171. begin
  172.   bigw;
  173.   lowvideo;
  174.   gotoxy(1,25);clreol;
  175.   if WrapOn then write('Word Wrap-ON  ') else write('Word Wrap-OFF ');
  176.   highvideo;
  177. end;
  178.  
  179.  
  180. PROCEDURE Directwrite(col,row, attrib : byte; var str : str80);
  181. begin
  182. inline($1E/
  183.        $1E/
  184.        $8A/$86/ROW/
  185.        $B3/$50/
  186.        $F6/$E3/
  187.        $2B/$DB/
  188.        $8A/$9E/COL/
  189.        $03/$C3/
  190.        $03/$C0/
  191.        $8B/$F8/
  192.        $8A/$BE/ATTrib/
  193.        $C4/$B6/Str/
  194.        $2b/$c9/
  195.        $26/$8A/$0C/
  196.        $2B/$C0/
  197.        $8E/$D8/
  198.        $A0/$49/$04/
  199.        $1F/
  200.        $2C/$07/
  201.        $74/$21/
  202.        $BA/$00/$B8/
  203.        $8E/$DA/
  204.        $BA/$DA/$03/
  205.        $46/
  206.        $26/$8A/$1C/
  207.        $EC/
  208.        $A8/$01/
  209.        $75/$FB/
  210.        $FA/
  211.        $EC/
  212.        $A8/$01/
  213.        $74/$FB/
  214.        $89/$1D/
  215.        $47/
  216.        $47/
  217.        $E2/$EB/
  218.        $2A/$C0/
  219.        $74/$0F/
  220.        $BA/$00/$B0/
  221.        $8E/$DA/
  222.        $46/
  223.        $26/$8A/$1C/
  224.        $89/$1D/
  225.        $47/
  226.        $47/
  227.        $E2/$F6/
  228.        $1F/
  229.        $FB);
  230. end;
  231.  
  232. PROCEDURE makenewline( x : integer);
  233. begin
  234.   if (sline[x] = nil) then
  235.   begin
  236.     if ((memavail * 16.0) -20000.0 < 1680) then
  237.     begin
  238.        gotoxy(1,1);
  239.        write(^G,'You are running out of memory!'); delay(600);
  240.     end;
  241.     if ((memavail * 16.0) -20000.0 > 160) then
  242.     begin
  243.       new(sline[x]);
  244.       sline[x]^ := '';
  245.     end
  246.     else begin write(^G,'Out Of Memory'); nomem := true; end;
  247.   end;
  248. end;
  249.  
  250. PROCEDURE VideoSignal(Switch : boolean);
  251. var
  252.    CrtAdapter : integer absolute $0040:$0063;
  253.    VideoMode  : byte    absolute $0040:$0065;
  254. Begin
  255.   If (Switch = Off)
  256.   then
  257.   Port[CrtAdapter+4] := (VideoMode - $08)
  258.   else
  259.   Port[CrtAdapter+4] := (VideoMode or $08);
  260. end;
  261.  
  262. procedure insertline(s : str80; lnn : integer);
  263. var y,tcount,nln :integer;
  264. begin
  265.   y := wherey;
  266.   insline;
  267.   gotoxy(1,22);
  268.   if y < 21 then clreol;
  269.   bigw;
  270.   littlew;
  271.   gotoxy(1,y);
  272.   tcount := 1;
  273.   temp:= s;
  274.   for NLN := LNN to MAXLN + 1 do
  275.   begin
  276.     makenewline(lnn + tcount);
  277.     Tbuff := sline[LNN + tcount]^;
  278.     sline[LNN + tcount]^ := temp;
  279.     temp := Tbuff;
  280.     tcount := tcount + 1;
  281.   end;
  282.   maxln :=maxln + 1;
  283. end;
  284.  
  285. function rmblks(s : anystr) : anystr;
  286. var  ct : integer;
  287. begin
  288.   if (length(s) > 1) and (pos(' ',s) <> 0) then
  289.   begin
  290.      ct :=0;
  291.      s := s + ' ';
  292.      while (length(s) > 0) and (s[1] = ' ') do delete(s,1,1);
  293.      repeat
  294.        ct := ct + 1;
  295.        if (s[ct] = ' ') and (s[ct+1] = ' ') then delete(s,ct,1);
  296.        if (ct = length(s)-1) and (pos('  ',s) <> 0) then ct := 0;
  297.      until ct >= length(s)-1;
  298.      while s[length(s)] = ' ' do delete(s,length(s),1);
  299.   end;
  300.   rmblks := s;
  301. end;
  302.  
  303. procedure formpara(var curline :integer);
  304. var
  305.   useddlines,lastline,oln,nln,lw,y,nlcnt : integer;
  306.   word : string[79];
  307.   right,newpara : boolean;
  308.   bufline : string[255];
  309.  
  310. procedure initialize;
  311. var x:integer;
  312. begin
  313.   for x := 1 to 99 do dline[x] := '';
  314.   right := false;
  315.   newline := '';
  316.   bufline := '';
  317.   nlcnt := 0;
  318. end;
  319.  
  320. PROCEDURE deletelines(curLn : integer; NumLn : integer);
  321. var dnln : integer; termline : string[79];
  322. begin
  323.   for dnln := maxln to maxln + numln do makenewline(dnln);
  324.   for dnln := curln-1 to maxln do sline[dnln]^ := sline[dnln+numln]^;
  325.   for dnln := maxln to maxln + numln do sline[dnln]^ := '';
  326.   maxln := maxln - numln;
  327. end;
  328.  
  329. procedure spread(var newline : str80);
  330. var i : integer;
  331.    wch : char;
  332. begin
  333.   if pos(^M,newline) <> 0 then newpara := true else newpara := false;
  334.   if ((length(newline) < lw) and (Not newpara)) and (pos(' ',newline) <> 0) then
  335.   begin
  336.       i := 0;
  337.       if right then
  338.       begin
  339.         repeat
  340.           i := i + 1;
  341.           wch := newline[i];
  342.           if wch = ' ' then
  343.           begin
  344.             insert(' ',newline,i+1);
  345.             i := i + 1;
  346.           end;
  347.           if (i >= length(newline)) and (Length(newline) < lw) then i := 1;
  348.         until (length(newline) >= lw);
  349.       end
  350.       else
  351.       begin
  352.         i := Length(newline);
  353.         if i > 0 then
  354.         while (length(newline) < lw) do
  355.         begin
  356.           i := i - 1;
  357.           wch := newline[i];
  358.           if wch = ' ' then
  359.           begin
  360.             insert(' ',newline,i + 1);
  361.             i := i - 1;
  362.           end;
  363.           if i <= 1 then i := length(newline);
  364.         end;
  365.       end;
  366.    end;
  367.    if pos(^M,newline) <> 0 then delete(newline,pos(^M,newline),1);
  368.  end;
  369.  
  370. function getword(var oldline : str255) : str80;
  371. var wch : char; word : string[80]; i,L : integer;
  372. begin
  373.   word := '';
  374.   i := 0;
  375.   if length(oldline) > 0 then
  376.   begin
  377.     repeat
  378.       i := i + 1;
  379.       wch := oldline[i];
  380.     until (wch = ' ') or (i = length(oldline));
  381.     word := copy(oldline,1,i);
  382.     delete(oldline,1,i);
  383.   end;
  384.   if length(word) >= (lw div 2) - 1 then
  385.   begin
  386.     beep;
  387.     L := length(word) div 2;
  388.     oldline := copy(word,L+1,255) + ' ' + oldline;
  389.     word := copy(word,1,L);
  390.   end;
  391.   getword := rmblks(word);
  392. end;
  393.  
  394.  procedure getlines;
  395.  begin
  396.    nln :=1;
  397.    repeat
  398.      dline[nln]  := rmblks(sline[oln]^);
  399.      nln := nln + 1;
  400.      oln := oln + 1;
  401.    until (length(sline[oln]^) in [0,1]) or (nln = 99);
  402.    lastline := oln-1;
  403.    useddlines := nln-1;
  404.    dline[nln-1] := rmblks(dline[nln-1]) + ^M;
  405.  end;
  406.  
  407. function makestring : str80;
  408. var done : boolean;
  409. begin
  410.    newline := '';
  411.    done := false;
  412.    repeat
  413.      if (length(bufline) < (lw * 2)) and (nln < useddlines) then
  414.      repeat
  415.         nln := nln + 1;
  416.         bufline := bufline + ' '+ dline[nln];
  417.      until (length(bufline) > lw) or (nln = useddlines);
  418.      word := getword(bufline);
  419.      if (length(word) + length(newline)) <= lw then
  420.         newline := newline + ' ' + word
  421.      else
  422.      begin
  423.        done := true;
  424.        bufline := word + ' '+ bufline;
  425.      end;
  426.    until done;
  427.    makestring := rmblks(newline);
  428.    nlcnt := nlcnt + 1;
  429. end;
  430.  
  431. procedure formatlines;
  432. var templine : string[80];
  433. begin
  434.    templine := ' ';
  435.    bufline := bufline + ' '+ dline[nln];
  436.    while (oln <= lastline + 1) and (templine <> '') do
  437.    begin
  438.      templine := makestring;
  439.      if (sline[oln]^ = '') and (templine <> '' ) then
  440.      begin
  441.        insertline('X',oln);
  442.        if templine <> '' then lastline := lastline + 1;
  443.      end;
  444.      sline[oln]^ := templine;
  445.      lowvideo;
  446.      if formright then spread(sline[oln]^) else
  447.      if pos(^M,sline[oln]^) <> 0 then delete(sline[oln]^,pos(^M,sline[oln]^),1);
  448.      write(sline[oln]^);clreol; writeln;
  449.      oln := oln + 1;
  450.   end;
  451.   if (sline[oln]^ <> '') and (sline[oln-1]^ <> '') then insertline('',oln-1);
  452. end;
  453.  
  454. procedure formatnotice;
  455. begin
  456.  astring :='Formating.   [please wait]';
  457.  directwrite(0,24,135,astring);
  458. end;
  459.  
  460. begin
  461.   if sline[curline]^ <> '' then
  462.   begin
  463.     y :=wherey;
  464.     bigw;
  465.     gotoxy(1,24);clreol;
  466.     gotoxy(1,25);clreol;
  467.     Formatnotice;
  468.     littlew;
  469.     gotoxy(1,y);
  470.     initialize;
  471.     if formright then lw := linewidth else lw := linewidth + 5;
  472.     oln := curline;
  473.     getlines;
  474.     oln := curline;
  475.     nln := 1;
  476.     formatlines;
  477.     curline := oln;
  478.     oln := (nln + 1) - nlcnt;
  479.     if nlcnt < nln then deletelines(curline,oln);
  480.     writewrapon;
  481.     wpstatus;
  482.   end
  483.   else curline := curline + 1;
  484. end;
  485.  
  486. PROCEDURE DrawWin(x1,y1,x2,y2 : integer);
  487. var x,y : integer;
  488. begin
  489.   Window(1,1,80,25);
  490.   gotoxy(x1,y1);  Write(chr(213));
  491.   for x := x1+1 to x2-1 do Write(chr(205));  Write(chr(184));
  492.   for y := y1+1 to y2-1 do
  493.   begin
  494.     gotoxy(x1,y); write(chr(179));
  495.     gotoxy(X2,y); write(chr(179));
  496.   end;
  497.   gotoxy(x1,y2); write(chr(212));
  498.   for x := x1+1 to x2-1 do write(chr(205)); write(chr(190));
  499.   Window(x1+1,y1+1,x2-1,y2-1);
  500.   ClrScr;
  501. end;
  502.  
  503. PROCEDURE MakeWin(x1,y1,x2,y2 :integer);
  504. begin
  505.   VideoSignal(Off);
  506.   If CrtMode = 7 then screen := monobuffer
  507.   else screen := colorbuffer;
  508.   VideoSignal(On);
  509.   DrawWin(x1,y1,x2,y2);
  510. end;
  511.  
  512. PROCEDURE RemoveWin;
  513. Begin
  514.   VideoSignal(Off);
  515.   If crtmode = 7 then monobuffer := screen
  516.   else colorbuffer := screen;
  517.   VideoSignal(On);
  518.   window(1,1,80,25);
  519. end;
  520.  
  521. PROCEDURE center(var s: str80);
  522. var xl : integer;
  523. begin
  524.   if length(s) > 0 then
  525.   begin
  526.     while (length(s)>0)and(s[1] = ' ') do delete(s,1,1);
  527.     if length(s) >0 then
  528.     for xl := 1 to ((linewidth - length(s)) div 2) do s:= ' '+s;
  529.   end;
  530.   gotoxy(1,wherey);
  531.   write(s);clreol;
  532. end;
  533.  
  534. PROCEDURE form;
  535. begin
  536.   LOWVIDEO;
  537.   gotoxy(1,23); for xx := 1 to 80 do write(chr(205));
  538.   HIGHVIDEO;
  539. end;
  540.  
  541. function ioerr: boolean;
  542. var err : integer;
  543. begin
  544.   err:= ioresult;
  545.   if err <> 0 then
  546.   begin
  547.     ioerr := true;
  548.     writeln;
  549.     write(chr(7),' I/O Error # ',err,', ');
  550.     case err of
  551.      $01,$FF:write('File missing');
  552.      $F1,240:write('Disk full or invalid Directory');
  553.      $04:write('File not open');
  554.      $99:write('Unexpected end of file');
  555.      $08:write('Disk write error');
  556.      $F2:write('File size overflow');
  557.      $F0:write('Disk write error');
  558.      $91:write('Seek beyond end of file');
  559.      243,$F3:write('To many files open');
  560.      else write(' error type unknown');
  561.     end;
  562.     write('. When ready Press <Return>');
  563.     repeat read(kbd,ch) until ch = ^M;
  564.     gotoxy(1,wherey);clreol;
  565.   end
  566.   else ioerr :=false;
  567. end;
  568.  
  569. FUNCTION PrinterOK : boolean;
  570. var ch : char;
  571. var  reg:     registers;
  572.        i:     integer;
  573. begin
  574.   repeat
  575.     reg.ah := $02;
  576.     reg.dx := $00;
  577.     intr($17,reg);
  578.     i := reg.ah;
  579.     if (i = 144) then
  580.     begin
  581.       printerOk := True;
  582.       ch := #27;
  583.     end
  584.     else
  585.     begin
  586.       printerOK := False;
  587.       gotoxy(1,25);clreol;
  588.       Write(^G,'Printer NOT READY!  When Ready Press <RETURN>,  To Quit Press <ESC>');
  589.       repeat
  590.         read(kbd,ch)
  591.       until ch in[^M,#27];
  592.       gotoxy(1,25);clreol;
  593.     end;
  594.   until ch in [#27];
  595. end;
  596.  
  597. FUNCTION UpcaseStr(s: str80) : Str80;
  598. var px : integer;
  599. begin
  600.   for Px := 1 to Length(s) do
  601.   S[px] := Upcase(S[px]);
  602.   UpcaseStr := S;
  603. end;
  604.  
  605. FUNCTION Lowcase(ch : char) : CHAR;
  606. begin
  607.   if Ch in ['A'..'Z'] then lowcase := chr(ord(ch)+32)
  608.   else lowcase := ch;
  609. end;
  610.  
  611. {$I \turbo\Dirlst.pas}
  612. {$I \turbo\sysutil.pas}
  613.  
  614. PROCEDURE help;
  615. label quit;
  616. var
  617.   Hfile : text[$F00];
  618.   hh,item : char;
  619.   Line : string[80];
  620.   Counter : integer;
  621.  
  622. begin
  623.   OldxPos := wherex;
  624.   OldyPos := wherey;
  625.   counter:= 0;
  626.   item := '0';
  627.   makewin(2,1,78,24);
  628.   clrscr;
  629.   if Exist('TSWWP.HLP') then
  630.   begin
  631.     Assign(Hfile,'TSWWP.HLP');
  632.     Reset(Hfile);
  633.     if ioresult<> 0 then goto quit;
  634.     while not Eof(Hfile) do
  635.     begin
  636.       gotoxy(1,1);
  637.       LowVideo;
  638.       repeat
  639.           Readln(Hfile,Line);
  640.       until  Eof(Hfile) or (Copy(Line,1,4)='.PA'+item);
  641.       if ioresult <> 0 then goto quit;
  642.       repeat
  643.         Write(' ');
  644.         if pos('.PA',line) = 0 then Writeln(line);
  645.         Readln(Hfile,Line);
  646.         if ioresult <> 0  then goto quit;
  647.       until  Eof(Hfile) or (Copy(Line,1,3)= '.PA');
  648.       GotoXY(12,22); highvideo;
  649.       counter := counter + 1;
  650.       if counter = 1 then write('Select Number or Press <Return> for All')
  651.         else  write('< Press any key to continue or Press <ESC> to quit >');
  652.       LowVideo;
  653.       read(Kbd,hh);
  654.       if hh in['0'..'9'] then item := hh else item :=succ(item);
  655.       clrscr;
  656.       if hh = #27 then goto quit;
  657.     end;
  658.     GotoXY(20,22); HighVideo;
  659.     quit :
  660.     close(Hfile);
  661.     if ioerr then;
  662.   end
  663.   else
  664.   begin
  665.     gotoxy(1,1);
  666.     write('Help File missing. Press <RETURN>');clreol;
  667.     repeat Read(kbd,hh) until hh=^M;
  668.   end;
  669.   removewin;
  670.   highvideo;
  671.   gotoxy(OldxPos,OldyPos);
  672. end;
  673.  
  674.  
  675. PROCEDURE WPIBMCH(var Ch : Char);
  676. var
  677.    scancode : byte;
  678.    extended : boolean;
  679.    regs : registers;
  680. begin
  681.   regs.ah := $07;
  682.   MsDos(regs);
  683.   scancode := regs.al;
  684.   if scancode = 0 then
  685.   begin
  686.     extended := true;
  687.     MsDos(regs);
  688.     scancode:= regs.al;
  689.   end
  690.   else extended := false;
  691.   Ch := chr(scancode);
  692.   if extended then
  693.   begin
  694.     case Ch of
  695.           'Q' : Ch := ^C;  { page down key }
  696.           'I' : Ch := ^R;  { page up key }
  697.           'H' : Ch := ^E;  { up arrow key }
  698.           'P' : Ch := ^X;  { down arrow key }
  699.           'M' : Ch := ^D;  { right arrow key }
  700.           'K' : Ch := ^S;  { left arrow key }
  701.           'S' : Ch := ^G;  { delete key }
  702.           ^O  : Ch := ^O;  { TAB KEY}
  703.       ';','w' : Ch := ^U;  { F1 goto Top line}
  704.       '<','u' : Ch := ^J;  { F2 Jump down to end}
  705.           '=' : Ch := ^^;  { F3 find word}
  706.           '>' : Ch := ^^;  { F4 find word}
  707.           '?' : Ch := ^<;  { F5 upcase letter}
  708.           '@' : Ch := ^\;  { F6 lower case}
  709.           'A' : Ch := #205; { center}
  710.           'B' : Ch := #132;  { Form para}
  711.           '[' : ch := #133;  {reform para}
  712.           'C' : Ch := ^N;  { F9 save file}
  713.           'D' : Ch := ^Z;  { F10 quit enter}
  714.           'R' : Ch := ^V;  { insert key }
  715.           'O' : Ch := ^F;  { end key goto end of line}
  716.           'G' : Ch := ^A;  { home key go to start of line}
  717.           #113: ch := #206;
  718.       else Ch := #00;
  719.     End;
  720.   end;
  721. end;
  722.  
  723. PROCEDURE BOutWPForm;
  724. var XX : integer;
  725. begin
  726.     gotoxy(1,1); clreol;
  727.     gotoxy(1,2);
  728.     frow := 1;
  729.     for xx := LNN -20 TO LNN-1 DO
  730.     begin
  731.       makenewline(xx);
  732.       astring :='                                                                               ';
  733.       astring := sline[xx]^ + astring;
  734.       if not nomem then directwrite(0,frow,att,astring);
  735.       frow := frow +1;
  736.     end;
  737. end;
  738.  
  739. PROCEDURE FOutWPForm;
  740. var xx : integer;
  741. begin
  742.   makenewline(lnn-1);
  743.   gotoxy(1,1);
  744.   if LNN > 20 then write(sline[lnn-1]^);clreol;
  745.   gotoxy(1,2);
  746.   frow := 1;
  747.   for xx := LNN TO LNN + 19 DO
  748.   begin
  749.     makenewline(xx);
  750.     astring :='                                                                               ';
  751.     astring := sline[xx]^ + astring;
  752.     if not nomem then directwrite(0,frow,att,astring);
  753.     frow := frow +1;
  754.   end;
  755. end;
  756.  
  757. PROCEDURE SaveWP(filevar : str80);
  758. var Py,xx,endln : integer;
  759.     tempfilename : text;
  760. begin
  761.   If MAXLN > 1 then
  762.   begin
  763.     form;
  764.     if markblock then
  765.     begin
  766.       gotoxy(1,24);
  767.       write('Save Marked Block from line ',markone,' to ',marktwo ,' to disk Y/N ');clreol;
  768.       repeat
  769.          read(kbd,YN); YN := upcase(YN);
  770.       until YN in ['Y','N'];
  771.       if yn = 'N' then exit else yn := 'N';
  772.     end
  773.     else
  774.     begin
  775.       PromptAt(1,24,'Save Document as:' + FileVar +' Y/N ');
  776.       repeat
  777.         read(kbd,YN); YN := upcase(YN);
  778.       until YN in ['Y','N'];
  779.     end;
  780.     if YN = 'N' then
  781.     begin
  782.       filevar :='';
  783.       PromptAt(1,24,'Enter Document Name: ');
  784.       readln(FileVar);
  785.       if FileVar = '' then
  786.       begin
  787.         write('NOT Saved!'); delay(900); exit;
  788.       end;
  789.       filevar := upcasestr(filevar);
  790.       if pos('.',filevar) = 0 then filevar := filevar + '.TXT';
  791.     end;
  792.     if markblock then
  793.     begin
  794.        xx := markone-1;
  795.        endln := marktwo;
  796.     end
  797.     else
  798.     begin
  799.       xx := 0;
  800.       endln := maxln;
  801.     end;
  802.     PromptAt(1,24,'Saving Document: '+ FileVar);
  803.     assign(wpFileName,FileVar);
  804.     if exist(filevar) then
  805.     begin
  806.       tempfile := filevar;
  807.       py := pos('.',tempfile);
  808.       if py <> 0 then delete(tempfile,py,4);
  809.       tempfile := tempfile + '.bak';
  810.       if exist(tempfile) then
  811.       begin
  812.         assign(tempfilename,tempfile);
  813.         erase(tempfilename);
  814.       end;
  815.       if tempfile <> filevar then
  816.       begin
  817.         rename(wpfilename,tempfile);
  818.         if ioerr then beep;
  819.       end;
  820.     end;
  821.     assign(WPFileName,FileVar);
  822.     if markblock then
  823.     begin
  824.       markblock:=false;
  825.       gotoxy(1,22); clreol;
  826.     end
  827.     else wpfilevar :=filevar;
  828.     rewrite(WPFileName);
  829.     if ioerr then
  830.     begin
  831.       close(wpfilename); if ioerr then exit;
  832.     end;
  833.     repeat
  834.       xx := xx + 1;
  835.       writeln(WPFileName,sline[xx]^);
  836.       if ioerr then
  837.       begin
  838.         close(wpfilename); if ioerr then exit; exit;
  839.       end;
  840.     until (xx >= endln);
  841.     if pos(^Z,sline[xx]^) = 0 then writeln(wpfilename,^Z);
  842.     close(WPFileName);
  843.     if ioerr then exit;
  844.   end;
  845. end;
  846.  
  847. PROCEDURE WPInputStr(var S: AnyStr;L,X,Y : Integer;Term :CharSet;var TC : Char);
  848. var
  849.   spn,P,NLN,count,Tcount : Integer;
  850.   LTR,LTRA,Ch,Fch : Char;
  851.  
  852. PROCEDURE movelinesdown(curLn : integer; NumLn : integer);
  853. var termline : string[79];
  854. begin
  855.    for nln := maxln to maxln + numln do makenewline(nln);
  856.    for nln := maxln+Numln downto curln+numln do sline[nln]^ := sline[nln-numln]^;
  857.    maxln := maxln + numln;
  858.    if numln > 1 then
  859.    for nln := curln+1 to curln + numln do sline[nln]^ := '';
  860. end;
  861.  
  862. PROCEDURE movelinesup(curLn : integer; NumLn : integer);
  863. var termline : string[79];
  864. begin
  865.    for nln := maxln to maxln + numln do makenewline(nln);
  866.    for nln := curln-1 to maxln do sline[nln]^ := sline[nln+numln]^;
  867.    for nln := maxln to maxln + numln do sline[nln]^ := '';
  868.    maxln := maxln - numln;
  869.    if lnn > maxln then begin lnn := maxln; if not (ch in[^Y,^H]) then ch := ^R; end;
  870. end;
  871.  
  872. PROCEDURE return;
  873. begin
  874.   NewLine := Copy(S,P + 1,L);
  875.   Delete(S,P+1,L);
  876.   gotoxy(1,Y+1);
  877.   Write(S);clreol;
  878.   gotoxy(1,22); DelLine;
  879.   gotoxy(1,Y+2);
  880.   if y <= 20 then
  881.   begin
  882.      gotoxy(1,Y+2); insline;
  883.      write(newline);
  884.      P:= wherey;
  885.      clreol;
  886.      gotoxy(1,22);clreol;
  887.      gotoxy(1,P);
  888.   end;
  889.   x := 0;
  890.   p := 0;
  891.   movelinesdown(lnn,1);
  892.   sline[lnn+1]^ :=newline;
  893. end;
  894.  
  895. PROCEDURE MakeString;
  896. begin
  897.   if P < L then
  898.   begin
  899.     if ch = ^Q then
  900.     begin
  901.       write(chr(7));
  902.       gotoxy(1,22); write('Insert Control Character');
  903.       GotoXY(X + 1 + P,Y + 1);
  904.       ch:= #00; read(kbd,ch);
  905.       gotoxy(1,22); clreol;
  906.       GotoXY(X + 1 + P,Y + 1);
  907.     end;
  908.     if InsertOn then
  909.     begin
  910.       if Length(S) >= L-1 then
  911.       begin
  912.         if p >= L-1 then begin beep; exit; end;
  913.         p := p+1;
  914.         pp:=p;
  915.         Insert(Ch,S,P);
  916.         return;
  917.         p := pp;
  918.         exit;
  919.       end;
  920.       P := P + 1;
  921.       Insert(Ch,S,P);
  922.       Write(Copy(S,P,L));clreol;
  923.     end
  924.     else
  925.     begin
  926.       if (P = Length(S)+1) or (P=0) and (Length(S)=1)
  927.       then S := S + Ch
  928.       else
  929.       delete(S,P + 1,1);
  930.       P := P + 1;
  931.       Insert(Ch,S,P);
  932.      Write(copy(S,P,L));clreol;
  933.     end;
  934.     if MaxLn < LNN then MaxLn :=LNN;
  935.   end
  936.   else Beep;
  937. end;
  938.  
  939. PROCEDURE backspace;
  940. begin
  941.   fch := ch;
  942.   Last := online + 1;
  943.   if (LNN = maxln) and (p=0) and (length(s)=0) then
  944.   begin                 {if at the end then just move up}
  945.     Ch :=^E;
  946.     Maxln := maxln - 1;
  947.   end
  948.   else        {else change to ^Y and delete current the line}
  949.   if (P = 0) and (Length(s) = 0) then Ch := ^Y
  950.  
  951.   else            { else copy current line upto next line}
  952.   if (Length(s) + Length(sline[LNN-1]^) <= 79) and (P = 0) and (LNN >1) then
  953.   begin
  954.     if S <> '' then Temp := Copy(S,P+1,L);
  955.     s := '';
  956.     ckln := sline[lnn-1]^;
  957.     if (ckln <> '') and (ckln[length(ckln)] <> ' ') then
  958.     sline[lnn-1]^ := sline[lnn-1]^ + ' ' + Temp {move with space}
  959.  
  960.     else
  961.     sline[lnn-1]^ := sline[lnn-1]^ + Temp;   {move without space}
  962.     gotoxy(1,y);
  963.     write(sline[lnn-1]^); clreol; {write new line}
  964.     gotoxy(1,Y+1); delline;
  965.     gotoxy(1,21); insline;
  966.     LineNum := 21 - Last + lnn;
  967.     if linenum > 0 then
  968.     begin
  969.         makenewline(linenum+1);
  970.         write(sline[LineNum+1]^);clreol;
  971.     end;
  972.     P := length(ckln);
  973.     gotoxy(p+1,y);
  974.     temp := sline[lnn-1]^;
  975.     if lnn < maxln then movelinesup(lnn,1);
  976.     sline[lnn-1]^ := temp;
  977.     ch := ^E;
  978.   end;
  979. end;
  980.  
  981. PROCEDURE TabLeft;
  982. begin
  983.   if P > 0 then
  984.   begin
  985.     count := P;
  986.     repeat
  987.       count := count - 1;
  988.       LTR := S[count];
  989.       LTRA := S[count-1];
  990.       P := P - 1;
  991.     until ((LTR = ' ') and (LTRA in [#33..#126])) or (P = 0);
  992.     if P > 0 then P := P-1
  993.   end
  994.   else beep;
  995. end;
  996.  
  997. PROCEDURE TabRight;
  998. begin
  999.   if P < Length(S) then
  1000.   begin
  1001.     count := P;
  1002.     repeat
  1003.       count := count + 1;
  1004.       LTR:= S[count];
  1005.       LTRA := S[count+1];
  1006.       P := P + 1;
  1007.     until ((LTR = ' ') and (LTRA in [#33..#126]))or (P = Length(S));
  1008.   end
  1009.   else
  1010.   begin
  1011.     count := P;
  1012.     if lnn > 1 then ckln := sline[lnn-1]^ else ckln := '';
  1013.     if ckln <> '' then
  1014.     repeat
  1015.       count := count + 1;
  1016.       LTR:= ckln[count];
  1017.       LTRA := ckln[count+1];
  1018.       s := s + ' ';
  1019.       p:=p+1;
  1020.     until ((LTR = ' ') and (LTRA in [#33..#126])) or (P = length(ckln));
  1021.   end;
  1022. end;
  1023.  
  1024. PROCEDURE upcaseltr;
  1025. begin
  1026.   s[p+1] := upcase(s[p+1]);
  1027.   Write(Copy(S,P + 1,L));clreol;
  1028.   ch:=^D;
  1029. end;
  1030.  
  1031. PROCEDURE lowcaseltr;
  1032. begin
  1033.   s[p+1] := lowcase(s[p+1]);
  1034.   Write(Copy(S,P + 1,L));clreol;
  1035.   ch:=^D;
  1036. end;
  1037.  
  1038. PROCEDURE DeleteLeftChar;
  1039. begin
  1040.   Delete(S,P,1);
  1041.   Write(^H,copy(S,P,L));clreol;
  1042.   P := P - 1;
  1043. end;
  1044.  
  1045. PROCEDURE DeleteChar;
  1046. begin
  1047.   if P < Length(S) then
  1048.   begin
  1049.     Delete(S,P + 1,1);
  1050.     Write(Copy(S,P + 1,L));clreol;
  1051.   end;
  1052. end;
  1053.  
  1054. PROCEDURE MarkTop;
  1055. begin
  1056.   inserton := true;
  1057.   MarkOne := LNN;
  1058.   GOTOXY(1,22);clreol; lowvideo;
  1059.   WRITE('Top of Block Marked at Line: ',MarkOne);
  1060.   normvideo;
  1061. end;
  1062.  
  1063. PROCEDURE MarkBottom;
  1064. begin
  1065.   MarkTwo := LNN;
  1066. {  if marktwo - markone > 99 then marktwo := markone + 98;}
  1067.   xx := 0;
  1068.   repeat
  1069.     dline[xx+1] := sline[markone + xx]^;
  1070.     xx := xx +1;
  1071.   until (xx >= (marktwo + 1 - markone)) or (xx = 99);
  1072.   GOTOXY(1,22);clreol;
  1073.   lowvideo;
  1074.   WRITE('Top of Block Marked at Line: ',MarkOne,' - Bottom Mark at Line: ',MarkTwo);
  1075.   normvideo;
  1076.   if MarkOne < MarkTwo then MarkBlock := true else markblock := false;
  1077.   if markone = marktwo then
  1078.   begin
  1079.     markone := 0;
  1080.     marktwo := 0;
  1081.     markblock := false;
  1082.     GOTOXY(1,22);clreol;
  1083.   end;
  1084. end;
  1085.  
  1086.  PROCEDURE KopyBlock;
  1087.  begin
  1088.    if (MarkBlock) and (sline[lnn]^ = '') then
  1089.    begin
  1090.      gotoxy(1,22); clreol;
  1091.      PriorLN := LNN;
  1092.      movelinesdown(lnn,(marktwo-markone)+1);
  1093.      for nln:= lnn to lnn +(marktwo-markone) do sline[NLN]^ := dline[nln-lnn+1];
  1094.      MarkBlock := false;
  1095.    end else
  1096.    if (lnn >= markone) and (lnn <= marktwo) then
  1097.    begin
  1098.      bigw;
  1099.      beep;
  1100.      PromptAt(1,24,'Delete Lines '); write(markone,' to ',marktwo,' ? Y/N');
  1101.      repeat read(kbd,yn);yn :=upcase(yn); until yn in ['Y','N'];
  1102.      if yn = 'Y' then  movelinesup(markone+1,marktwo-markone+1);
  1103.      markblock := false;
  1104.      markone:= 0;
  1105.      marktwo :=0;
  1106.    end;
  1107.    wpstatus;
  1108. end;
  1109.  
  1110. PROCEDURE Load66;
  1111. begin
  1112.   if sline[lnn]^ = '' then
  1113.   begin
  1114.     bigw;
  1115.     Inserton := true;
  1116.     if lnn mod 20 = 0 then priorln := lnn +1 else priorln := lnn;
  1117.     repeat
  1118.        PromptAt(1,24,'Read Disk Directory ? Y/N ');
  1119.        repeat read(kbd,yn); yn := upcase(yn); until yn in['Y','N'];
  1120.        if yn = 'Y' then ListDir;
  1121.        PromptAt(1,24,'Enter Name of Disk Text File to Merge: ');
  1122.        read(DFilevar);
  1123.        if DFilevar <> '' then
  1124.        begin
  1125.          if pos('.',dfilevar) = 0 then dfilevar := dfilevar + '.TXT';
  1126.          assign(DFileName,DFilevar);
  1127.          reset(DFileName);
  1128.          if ioerr then begin wpstatus; exit; end;
  1129.        end;
  1130.      until not ioerr;
  1131.      if DFilevar <> '' then
  1132.      begin
  1133.        while not eof(DFileName) do
  1134.        begin
  1135.          xx := xx + 1;
  1136.          if xx <= 99 then Readln(DFileName,dline[xx])
  1137.          else readln(DFileName,junk);
  1138.          if ioerr then
  1139.          begin
  1140.            close(Dfilename); if ioerr then exit;
  1141.            wpstatus;
  1142.            exit;
  1143.          end;
  1144.       end;
  1145.       close(DFileName);
  1146.       if ioerr then
  1147.       begin
  1148.         close(Dfilename); if ioerr then exit;
  1149.         wpstatus;
  1150.         exit;
  1151.       end;
  1152.       if xx > 99 then xx := 99;
  1153.       NewLine := Copy(S,P + 1,L);
  1154.       Delete(S,P+1,L); gotoxy(1,Y+1);
  1155.       if Y<20 then write(S);clreol;
  1156.       count := 1;
  1157.       makenewline(maxln+1);
  1158.       movelinesdown(lnn,xx);
  1159.       for nln:= lnn to lnn +xx do sline[NLN]^ := dline[nln-lnn+1];
  1160.     end;
  1161.     wpstatus;
  1162.   end else begin beep; ch := #00; end;
  1163. end;
  1164.  
  1165. PROCEDURE YankItOut;
  1166. begin
  1167.   Last := online+1;
  1168.   if S <> '' then Temp := Copy(S,P+1,L);
  1169.   Write('');clreol;
  1170.   Delete(S,P + 1,L);
  1171.   if (P = 0) and (Length(S) = 0) then
  1172.   begin
  1173.     gotoxy(1,Y+1); delline;
  1174.     gotoxy(1,21); insline;
  1175.     if last > 1 then LineNum := lnn +(21 - Last) else linenum := lnn;
  1176.     makenewline(linenum);
  1177.     makenewline(linenum+1);
  1178.     write(sline[LineNum+1]^); clreol;
  1179.     gotoxy(1,last);
  1180.     gotoxy(1,22); clreol;
  1181.     gotoxy(1,Y+1);
  1182.     if lnn >= maxln then makenewline(lnn+1);
  1183.     if lnn < maxln then movelinesup(lnn+1,1);
  1184.     if maxln < LNN then Maxln := LNN;
  1185.     if fch in [^H,#127] then
  1186.     begin
  1187.       P := length(sline[lnn-1]^);
  1188.       ch := ^E;
  1189.       fch:=#00
  1190.     end else P := 0;
  1191.   end;
  1192. end;
  1193.  
  1194. PROCEDURE centerstr;
  1195. begin
  1196.   center(s);
  1197.   P:= 0;
  1198.   gotoxy(1,wherey);
  1199.   if Lnn < maxln then ch := ^X;
  1200. end;
  1201.  
  1202. PROCEDURE searchfile;
  1203. begin
  1204.   bigw;
  1205.   if Fword = '' then
  1206.   begin
  1207.     PromptAt(1,24,'Enter word to search for: ');
  1208.     readln(Fword);
  1209.     if fword <> '' then begin gotoxy(27,24);write(fword,' searching...'); end;
  1210.   end
  1211.   else
  1212.   begin
  1213.     PromptAt(1,24,'Continue Search for: '+Fword+ ' ? Y/N ');
  1214.     repeat
  1215.       read(kbd,Fch);
  1216.       Fch := upcase(fch);
  1217.     until Fch in ['Y','N'];
  1218.     if Fch = 'N' then
  1219.     begin
  1220.       PromptAt(1,24,'Enter word to search for: ');
  1221.       readln(Fword);
  1222.     end else write(Fch,' searching...');
  1223.   end;
  1224.   if Fword <> '' then
  1225.   begin
  1226.     Fword := upcasestr(Fword);
  1227.  
  1228.     Lns := Lnn-1;
  1229.     if Lnn < Maxln then
  1230.     repeat
  1231.        Lns := Lns +1;
  1232.        if length(sline[lns]^) >0 then ckln := copy(sline[lns]^,p+1,79)
  1233.        else ckln := sline[lns]^;
  1234.        ckln := upcasestr(ckln);
  1235.        pp := p;
  1236.        if pos(Fword,ckln) <> 0 then
  1237.        begin
  1238.          if LNS = lnn then
  1239.          begin
  1240.            P := pos(fword,ckln) +length(fword)-1 +pp;
  1241.            ch := #00;
  1242.          end
  1243.          else
  1244.          begin
  1245.            if lns < 20 then Lnn := lns else Lnn := lns -20;
  1246.            p := 0;
  1247.          end;
  1248.        end
  1249.        else
  1250.        p :=0;
  1251.      until (Lns >= maxln) or (pos(Fword,ckln) <> 0);
  1252.      if lns >= maxln then
  1253.      begin
  1254.        bigw;
  1255.        gotoxy(1,24); clreol;
  1256.        write(chr(7),'"',Fword,'" not found! Press any key to continue');
  1257.        read(kbd,zip);
  1258.        Fword := '';
  1259.        if (Maxln > 20) and (ch <> #00) then
  1260.        begin
  1261.          LNN := MaxLN-20;
  1262.          Ch := ^C;
  1263.        end
  1264.        else ch := #00;
  1265.      end;
  1266.    end
  1267.    else ch := #00;
  1268.    wpstatus;
  1269.    GotoXY(X + P + 1,Y + 1);
  1270.  end;
  1271.  
  1272. PROCEDURE moveleft;
  1273. begin
  1274.   if P > 0 then P := P - 1 else Beep;
  1275. end;
  1276.  
  1277. PROCEDURE moveright;
  1278. begin
  1279.   if P < Length(S) then P := P + 1 else beep;
  1280. end;
  1281.  
  1282. PROCEDURE wraponoff;
  1283. begin
  1284.    WrapOn := not WrapOn;
  1285.    writeWrapOn;
  1286.  end;
  1287.  
  1288. PROCEDURE InsertOnOff;
  1289. begin
  1290.   bigw;
  1291.   gotoxy(36,24); clreol;
  1292.   InsertOn := not InsertOn;
  1293.   lowvideo;
  1294.   if InsertOn then write('Insert-On: File-> ',WPFileVar)
  1295.   else write('OverWrite: File-> ',WPFileVar);
  1296.   highvideo;
  1297. end;
  1298.  
  1299. PROCEDURE PutItBack;
  1300. begin
  1301.   if Length(S + Temp) <= 79 then
  1302.   insert(Temp,S,P+1) else
  1303.   begin
  1304.     beep;
  1305.     repeat
  1306.       gotoxy(1,22);
  1307.       write('No room for insertion. Press <ESC> Key and insert blank line');
  1308.       delay(400);
  1309.       if keypressed then Read(KBD,Ch);
  1310.       gotoxy(1,22);clreol;
  1311.       delay(150);
  1312.     until Ch = #27;
  1313.   end;
  1314.   gotoXY(X + 1,Y + 1);
  1315.   Write(S);clreol;
  1316. end;
  1317.  
  1318.  
  1319. begin {wpinstring}
  1320.   GotoXY(X + 1,Y + 1); {Write(S);clreol;}
  1321.   fcol := x; frow := Y;
  1322.   astring :='                                                                               ';
  1323.   astring := s + astring;
  1324.   directwrite(fcol,frow,att,astring);
  1325.   if priorch = ^^ then P := PP else
  1326.   if length(sline[lnn]^) < PP then P := length(sline[lnn]^) else P := PP;
  1327.   tcount := 0;
  1328.   count := 0;
  1329.   xx := 0;
  1330.   REPEAT
  1331.     if markblock then
  1332.     begin
  1333.       GOTOXY(1,22);clreol;
  1334.       lowvideo;
  1335.       WRITE('Top of Block Marked at Line: ',MarkOne,' - Bottom Mark at Line: ',MarkTwo);
  1336.       highvideo;
  1337.     end;
  1338.     littlew;
  1339.     PP := P;
  1340.     GotoXY(X + P + 1,Y + 1);
  1341.     WPIBMCH(Ch);
  1342.     if ch in[^C,^J,^X,^<,^U,^\,' ',^D,^H,#127,^S] then
  1343.     begin
  1344.       if (ch =^C ) and ((maxln <= 20) or (maxln-(21-online)<lnn) and (online<>0)) then ch := #00;
  1345.       if (ch in[^C,^J,^X]) and (lnn >= maxln) then ch :=#00;
  1346.       if (ch = ^J) and ((lnn <= 20) and (maxln  <=20)) then
  1347.       begin
  1348.         online := maxln-1;
  1349.         Lnn := maxln-1;
  1350.         ch  := ^X;
  1351.       end;
  1352.       Case Ch of
  1353.         ^<  : upcaseltr;
  1354.         ^\  : lowcaseltr;
  1355.         ^J  : begin LNN := MaxLN-20; Ch := ^C ; end;
  1356.         ^U  : begin LNN := 1; FOutWPForm; online := 1; end;
  1357.         ' ' : begin
  1358.                 if (Length(S) >= linewidth-5) and (P >= linewidth) and WrapOn
  1359.                 then
  1360.                 begin
  1361.                   if S[p] <> ' ' then
  1362.                   S := S + Ch;
  1363.                   Ch := ^M;
  1364.                 end;
  1365.               end;
  1366.         ^D  : if LNN <= maxln then
  1367.               begin
  1368.                 if (P = Length(S)) and (LNN <maxln) then
  1369.                 begin
  1370.                   P := 0;
  1371.                   Ch := ^X;
  1372.                 end;
  1373.               end else ch := #00;
  1374.     ^H,#127 :  backspace;
  1375.  
  1376.         ^S  : begin
  1377.                 if (P = 0) then if LNN > 1 then
  1378.                 begin
  1379.                    P := length(sline[lnn-1]^);
  1380.                    Ch := ^E;
  1381.                 end else Ch := #00;
  1382.               end;
  1383.  
  1384.        end;
  1385.     end;
  1386.  
  1387.     case Ch of
  1388.  #32..#125,^Q : MakeString;
  1389.       #205    :  Centerstr;
  1390.       ^^      :  Searchfile;
  1391.       ^N      :  begin bigw; savewp(wpfilevar); wpstatus; end;
  1392.       ^O      :  TabLeft;
  1393.       ^I      :  TabRight;
  1394.       ^S      :  Moveleft;
  1395.       ^D      :  Moveright;
  1396.       ^A      :  P := 0;
  1397.       ^F      :  P := Length(S);
  1398.       ^G      :  DeleteChar;
  1399.       ^H,#127 :  if P > 0 then  DeleteleftChar else beep;
  1400.       ^T      :  MarkTop;
  1401.       ^B      :  MarkBottom;
  1402.       ^K      :  KopyBlock;
  1403.       ^L      :  Load66;
  1404.       ^Y      :  YankItOut;
  1405.       ^M      :  Return;
  1406.       ^P      :  PutItBack;
  1407.       ^V      :  InsertOnOff;
  1408.       ^W      :  wraponoff;
  1409.       #132    :  begin formright := true; formpara(lnn); ch := ^K; end;
  1410.       #133    :  begin formright := false; formpara(lnn); ch := ^K; end;
  1411.       #206    :  help;
  1412.      else if not (Ch in Term) then beep;
  1413.     end;
  1414.     PP := P;
  1415.     if not (ch in term) then textinfo;
  1416.     priorch := Ch;
  1417.     priorP := P;
  1418.     if (ch = ^E) and (lnn = 1) then begin beep; ch:=#00 end;
  1419.   until Ch in Term;
  1420.   TC := Ch;
  1421. end;
  1422.  
  1423.  
  1424. PROCEDURE WRITEHIGH(PromptStr : Str80);
  1425. var xx : integer;
  1426. begin
  1427.    for xx := 1 to length(PromptStr) do
  1428.    begin
  1429.      if ((PromptStr[xx] in ['A'..'Z']) and  (PromptStr[xx+1] = '(')
  1430.          or (pos(':',PromptStr) >= xx)) then highvideo else lowvideo;
  1431.      write(PromptStr[xx]);
  1432.   end;
  1433. end;
  1434.  
  1435.  
  1436. PROCEDURE PROMPT(PromptStr : Str80; TC_Set : CharSet; var CH : Char);
  1437. var pc : char;
  1438. begin
  1439.   gotoxy(1,24);
  1440.   writehigh(PromptStr);clreol;
  1441.   repeat
  1442.     read(kbd,pc);
  1443.     CH := upcase(pc);
  1444.     if not(CH in TC_Set) then Beep;
  1445.   until CH in TC_Set;
  1446.   write(CH);
  1447.   highvideo;
  1448. end;
  1449.  
  1450. PROCEDURE ClearTextWindow;
  1451. begin
  1452.   littlew;
  1453.   GotoXY(1,1);
  1454.   clrscr;
  1455.   bigw;
  1456. end;
  1457.  
  1458. PROCEDURE printer;
  1459. var keych : char;  n : integer;
  1460. begin
  1461.   if printerok then
  1462.   begin
  1463.   ClearTextWindow;
  1464.   gotoxy(1,1);
  1465.   writeln('You may send Control or Escape Character sequences to your printer for ');
  1466.   writeln('the purpose of setting your print style. (i.e. correspondence quality) ');
  1467.   writeln('Press ALL the necessary keys, then press return.  See your printer''s');
  1468.   writeln('instruction manual for more information.');
  1469.   repeat
  1470.     read(kbd,keych);
  1471.     write(keych);
  1472.     case keych of
  1473.       #27    : write(lst,#27);
  1474.       ^A..^Z : write(lst,keych);
  1475.       else write(lst,keych);
  1476.     end;
  1477.   until keych = ^M;
  1478.   WRITELN(LST);
  1479.   for n := 1 to 2 do
  1480.   writeln(lst,'abcdefghijklmnopqrstuvwxyz..1234567890/+-!?:ABCDEFGHIJKLMNOPQRSTUVWXYZ');
  1481.   WRITE(LST,CHR(12));
  1482.   ClearTextWindow
  1483.   end;
  1484. end;
  1485.  
  1486. PROCEDURE setprint;
  1487. var Pnumstr,PageStr,PauseStr : string[3];
  1488.     item : char;
  1489. begin
  1490.   noprint := false;
  1491.   ClearTextWindow;
  1492.   repeat
  1493.     PromptAt(1,24,' ');
  1494.     gotoxy(1,1);
  1495.     if pause = 'N' then  PauseStr := 'No' Else PauseStr := 'Yes';
  1496.     if pageYN = 'N' then  PageStr := 'No' Else PageStr := 'Yes';
  1497.     if numYN = 'N' then  PnumStr := 'No' Else PnumStr := 'Yes';
  1498.     writeln('            Print Format Parameters');
  1499.     writeln;
  1500.     writeln('1 - Top Margin is.............: ',Header:3,' lines');clreol;
  1501.     writeln;
  1502.     writeln('2 - Bottom Margin is..........: ',Bottom:3,' lines');clreol;
  1503.     writeln;
  1504.     writeln('3 - Left Margin is............: ',Margin:3,' spaces');clreol;
  1505.     writeln;
  1506.     linewidth := 80 - margin - margin-1;
  1507.     writeln('4 - Maximum Lines per Page is.: ',Pagesize:3,' lines');clreol;
  1508.     writeln;
  1509.     writeln('5 - Pause Between Pages.......: ',PauseStr:3);clreol;
  1510.     writeln;
  1511.     writeln('6 - Automatic Pagination......: ',PageStr:3);clreol;
  1512.     writeln;
  1513.     writeln('7 - Number All Pages..........: ',PnumStr:3);clreol;
  1514.     writeln;
  1515.     writeln('8 - Send setup characters to printer');
  1516.     writeln;
  1517.     writeln('9 - Return to Select Choice Menu');
  1518.     writeln;
  1519.     write('Select Item # to change or press ''C'' to Continue ');
  1520.     repeat
  1521.       read(kbd,item);
  1522.       item := upcase(item);
  1523.     until item in ['1'..'9','C'];
  1524.     if item <> 'C' then
  1525.     begin
  1526.       case item of
  1527.       '1':begin
  1528.             repeat gotoxy(34,3);clreol; readln(header);
  1529.             until header in [1..66];
  1530.           end;
  1531.       '2':begin
  1532.             repeat gotoxy(34,5);clreol; readln(bottom);
  1533.             until bottom in [0..15];
  1534.           end;
  1535.       '3':begin
  1536.             repeat gotoxy(34,7);clreol; readln(margin);
  1537.             until margin in [0..15];
  1538.           end;
  1539.       '4':begin
  1540.             repeat gotoxy(34,9);clreol; readln(pagesize);
  1541.             until pagesize in [40..90];
  1542.           end;
  1543.       '5':begin
  1544.             repeat gotoxy(33,11);clreol; read(kbd,pause);
  1545.             pause := upcase(pause);
  1546.             until pause in ['Y','N'];
  1547.           end;
  1548.       '6':begin
  1549.             repeat gotoxy(33,13);clreol; read(kbd,PageYN);
  1550.             pageYN := upcase(pageYN);
  1551.             until pageYN in ['Y','N'];
  1552.           end;
  1553.       '7':begin
  1554.             repeat gotoxy(33,15); clreol; read(kbd,NumYN);
  1555.             NumYn := Upcase(NumYn);
  1556.             until NumYN in ['Y','N'];
  1557.           end;
  1558.       '8': printer;
  1559.       '9': begin NoPrint := true; item :='C' end;
  1560.        end;
  1561.  
  1562.     end;
  1563.   until item = 'C';
  1564. end;
  1565.  
  1566. PROCEDURE InputWP;
  1567. const
  1568.   Term : CharSet  =  [^X,^M,^E,^K,^L,^R,^C,^Z,^^,^U];
  1569. var
  1570.   TC : Char;
  1571.   top : boolean;
  1572. begin
  1573.   top := true;
  1574.   SAVED := FALSE;
  1575.   LNN := 1;
  1576.   TC := #00;
  1577.   online := 1;
  1578.   FOutWPForm;
  1579.  
  1580.   repeat
  1581.  
  1582.     if ((TC in [^X,^M]) and (online >= 21)) then
  1583.                         begin
  1584.                            online := 20;
  1585.                            littlew;
  1586.                            gotoxy(1,1);delline;
  1587.                            gotoxy(1,21); insline;
  1588.                          end
  1589.   else
  1590.   if (TC = ^E) and (online = 0) then
  1591.                           begin
  1592.                               littlew;
  1593.                               gotoxy(1,21);clreol;
  1594.                               gotoxy(1,1);insline;
  1595.                               if lnn > 1 then write(sline[lnn-1]^);
  1596.                               online := 1;
  1597.                               if (online = 1) and (lnn = 1) then top := true
  1598.                               else top :=false;
  1599.                           end;
  1600.  
  1601.  makenewline(lnn);
  1602.  textinfo;
  1603.  WPInputStr(sline[LNN]^,79,0,online,Term,TC);
  1604.     if LNN <= 0 then LNN := 1;
  1605.     if TC in[^X,^M] then
  1606.     begin
  1607.       LNN := LNN + 1;
  1608.       online := online + 1;
  1609.     end
  1610.  
  1611.     else
  1612.  
  1613.     if (TC = ^E) and (not top or (lnn>1) )then
  1614.     begin
  1615.       if LNN > 1 then LNN := LNN - 1;
  1616.       if online <=0 then online := 1;
  1617.       if online > 20 then online := 20;
  1618.       if (online in[1..20]) then online := online - 1;
  1619.     end;
  1620.  
  1621.   if (TC =^C) and (LNN < aTOPEND +1) then
  1622.   begin
  1623.     TopLine := (trunc(Lnn/20) *20) + 21;
  1624.     Lnn := topline;
  1625.     online := (lnn mod 20);
  1626.     FOutWPForm;
  1627.   end;
  1628.  
  1629.   if (TC in[^K,^L]) and (LNN < aTOPEND +1) then
  1630.   begin
  1631.     online := 1;
  1632.     FOutWPForm;
  1633.   end;
  1634.  
  1635.   if (TC = ^R) then if (LNN <= 20) then
  1636.     begin
  1637.       LNN := 1; FOutWPForm; online := 1;
  1638.     end
  1639.     else
  1640.     if (LNN > 20) then
  1641.     begin
  1642.         BOutWPForm;
  1643.         lnn := lnn -20;
  1644.         online :=1;
  1645.      end;
  1646.  if TC = ^^ then
  1647.    begin
  1648.      LNN := Lns;
  1649.      if LNN > maxln then Lnn := maxln;
  1650.      foutwpform;
  1651.      online := 1;
  1652.      if (TC = ^^) and (pos(fword,ckln) <> 0) then
  1653.         PP := (pos(fword,ckln)-1+ length(fword));
  1654.    end;
  1655.  
  1656.   If MAXLN >= aENDLINE THEN MAXLN := aENDLINE-2;
  1657.  
  1658.   if (TC = ^M) or (TC = ^X) then if LNN = aENDLINE-1 then beep;
  1659.  
  1660.   if LNN <= 0 then LNN := 1
  1661.   else
  1662.   if LNN >= aENDLINE-1 then LNN := aENDLINE-2;
  1663. until TC = ^Z;
  1664. ClearTextWindow
  1665. end;
  1666.  
  1667. PROCEDURE EnterWP;
  1668. begin
  1669.     InsertOn := true;
  1670.     wpstatus;
  1671.     writewrapon;
  1672.     InputWP;
  1673.     gotoxy(1,25);clreol;
  1674. end;
  1675.  
  1676. PROCEDURE GETWPFILE;
  1677. var
  1678.   xx : integer;
  1679.   NewFileVar : string[60];
  1680. begin
  1681.   WPFileVar := 'NONAME.TXT';
  1682.   xx := 0;
  1683.   MAXLN := 0;
  1684.   for xx := 1 to aendline do if sline[xx] <> nil then sline[xx]^ := '';
  1685.   for xx := 1 to 99 do  dline[xx] := '';
  1686.   cursor(on);
  1687.   repeat
  1688.     astring := cnotice;
  1689.     directwrite(0,0,7,astring);
  1690.     PROMPT('Select Choice:  C(reate or R(evise document,  D(irectory,  Q(uit,  U(tilitys ', ['D','C','R','Q','U'], Ch);
  1691.     if ch = 'U' then
  1692.     begin
  1693.       sysutil;
  1694.       form;
  1695.     end;
  1696.     if Ch = 'D' then
  1697.     begin
  1698.       ClearTextWindow;
  1699.       ListDir;
  1700.       window(1,1,80,25);
  1701.       form;
  1702.     end;
  1703.   if Ch = 'C' then
  1704.   begin
  1705.     PromptAt(1,24,'Enter Name of Document To Create: ');
  1706.     readln(WPFileVar);
  1707.     if WPFileVar = '' then WPFileVar := 'NONAME.TXT';
  1708.     IF pos('.',wpfilevar) = 0 then wpfilevar := wpfilevar + '.TXT';
  1709.     wpfilevar := UPCASESTR(WPFILEVAR);
  1710.     gotoxy(1,24); clreol;
  1711.   end;
  1712.  
  1713.   if Ch =  'R' then
  1714.   begin
  1715.     PromptAt(1,24,'Enter Name of Document To Load: ');
  1716.     readln(WPFileVar);
  1717.     if wpfilevar <> ''then
  1718.     begin
  1719.       IF pos('.',wpfilevar) = 0 then wpfilevar := wpfilevar + '.TXT';
  1720.       wpfilevar := UPCASESTR(WPFILEVAR);
  1721.       if WPFileVar = '' then ch := #00;
  1722.       gotoxy(1,24); clreol; write('Loading: ',WPFileVar);
  1723.       assign(WPFileName,WPFileVar);
  1724.       Reset(WPFileName);
  1725.       if ioresult <> 0 then
  1726.       begin
  1727.         PROMPT('File not found - Create New File ?  Y/N  ',['Y','N'],Ch);
  1728.         if Ch = 'Y' then ch := 'C';
  1729.         if Ch = 'N'then ch := #00;
  1730.       end
  1731.       else
  1732.       begin
  1733.         xx := 0;
  1734.         while not eof(WPFileName) do
  1735.         begin
  1736.           xx := xx + 1;
  1737.           makenewline(xx);
  1738.           if xx <= aendline-2 then Readln(WPFileName,sline[xx]^)
  1739.           else readln(wpfilename,junk);
  1740.           if ioerr then
  1741.           begin
  1742.              Close(wpfilename); exit;
  1743.           end;
  1744.           MAXLN := xx;
  1745.           if MAXLN > aendline then MAXLN := aendline-2;
  1746.         end;
  1747.         makenewline(xx+1);
  1748.         close(WPfileName);
  1749.         if ioerr then exit;
  1750.       end;
  1751.     end
  1752.     else ch := #00;
  1753.   end;
  1754.   until ch in ['C','R','Q'];
  1755.   if Ch <> 'Q' then Ch := 'W';
  1756. end;
  1757.  
  1758.  
  1759. PROCEDURE PrintIt(mm : boolean);
  1760. label quit;
  1761. VAR P1,P2,cnum,pagenum,counter,nl,LCNT,LM,Posn,lx : INTEGER;
  1762.     RP : char;
  1763.     tline : string[79];
  1764.     spaces : string[25];
  1765.     Firstname : string[40];
  1766.     SurName : string[40];
  1767.     LASTNAME,PAUSED : BOOLEAN;
  1768.     bufln,cmdline : string[79];
  1769. begin
  1770.   if printerok then
  1771.   begin
  1772.     noprint := false;
  1773.     PAUSED := FALSE;
  1774.     LASTNAME := FALSE;
  1775.     xx := 0;
  1776.     pageNum := 1;
  1777.     firstName := '';
  1778.     SURname := '';
  1779.     tline:= '';
  1780.     for xx := 1 to 99 do dline[xx] := '';
  1781.     xx:=0;
  1782.     COUNTER := 0;
  1783.     If maxln < 1 then getWPfile;
  1784.     spaces :=  ' ';
  1785.     PromptAt(1,24,'Review Print Format Parameters ? Y/N ');
  1786.     repeat
  1787.       read(kbd,RP);
  1788.       RP := Upcase(RP);
  1789.     until RP in ['Y','N'];
  1790.     if RP = 'Y' then SetPrint;
  1791.     if not noprint then
  1792.     begin
  1793.       ClearTextWindow;
  1794.       if margin > 1 then for LM := 1 to margin do
  1795.       begin
  1796.         spaces := spaces + ' ';
  1797.       end;
  1798.       if MM then
  1799.       begin
  1800.         repeat
  1801.           PromptAt(1,24,'Enter Name of Disk Text File to Merge: ');clreol;
  1802.           read(DFilevar);
  1803.           ClearTextWindow;
  1804.           if DFilevar <> '' then
  1805.           begin
  1806.             IF pos('.',Dfilevar) = 0 then Dfilevar := Dfilevar + '.TXT';
  1807.             assign(DFileName,DFilevar);
  1808.             reset(DFileName);
  1809.             if ioerr then exit;
  1810.           end;
  1811.         until not ioerr;
  1812.       end else DFilevar := ' ';
  1813.       if DFilevar <> '' then
  1814.       begin
  1815.         gotoxy(1,24);clreol;
  1816.         write('Printing: ',WPFilevar);
  1817.         gotoxy(1,1);
  1818.         write('Press  <ESC>  to abort printing');
  1819.         repeat
  1820.           if keypressed then begin read(kbd,ch); if ch = #27 then goto quit; end;
  1821.           if (numYn = 'Y') and (pagenum <> 1) then writeln(lst,spaces,pagenum:39-margin);
  1822.           if ioerr then exit;
  1823.           pagenum := pageNum + 1;
  1824.           if header > 6 then FOR LCNT := 0 TO HEADER-6 DO
  1825.           begin
  1826.             WRITELN(LST);
  1827.             if ioerr then exit;
  1828.           end;
  1829.  
  1830.           if MM then
  1831.           begin
  1832.           repeat
  1833.             if keypressed then begin read(kbd,ch); if ch = #27 then goto quit; end;
  1834.             xx := xx + 1;
  1835.             if xx <= 99 then Readln(DFileName,dline[xx])
  1836.             else readln(DFileName,junk);
  1837.             if ioerr then exit;
  1838.             if xx = 1 then
  1839.             begin
  1840.               FirstName := copy(dline[xx],1,pos(' ',dline[xx])-1);
  1841.               lx := length(dline[xx]);
  1842.               tline := dline[xx];
  1843.               if lx > 0 then
  1844.               repeat
  1845.                 ch := tline[lx];
  1846.                 lx := lx - 1;
  1847.               until ch = ' ';
  1848.               surname :=  copy(dline[xx],lx+2,40);
  1849.             end;
  1850.             ckln := upcasestr(Dline[XX]);
  1851.             IF POS('@@',CKLN) <> 0 THEN LASTNAME := TRUE;
  1852.           until pos('@',dline[xx]) <> 0
  1853.           end
  1854.           else lastname := true;
  1855.  
  1856.           LNN := 1;
  1857.           counter := COUNTER + XX;
  1858.           REPEAT
  1859.             cnum := 0;
  1860.             if keypressed then begin read(kbd,ch); if ch = #27 then goto quit; end;
  1861.             counter := counter +1;
  1862.             ckln := upcasestr(sline[LNN]^);
  1863.             if MM then
  1864.             begin
  1865.               if Pos('{@}',ckln) <> 0 then
  1866.               begin
  1867.                 LNN := Lnn + 1;
  1868.                 for NL := 1 to XX-1 do writeln(lst,spaces,dline[NL]);
  1869.                 if ioerr then exit;
  1870.               end
  1871.               else if Pos('{^',ckln) <> 0 then
  1872.               begin
  1873.                 bufln := sline[lnn]^;
  1874.                 if Pos('{^}',ckln) <> 0 then
  1875.                 begin
  1876.                   Posn := pos('{',sline[LNN]^);
  1877.                   delete(sline[lnn]^,posn,3);
  1878.                   insert(firstname,sline[LNN]^,posn);
  1879.                 end;
  1880.                 ckln := upcasestr(sline[LNN]^);
  1881.                 if Pos('{^^}',ckln) <> 0 then
  1882.                 begin
  1883.                   Posn := pos('{',sline[LNN]^);
  1884.                   delete(sline[lnn]^,posn,4);
  1885.                   insert(surname,sline[LNN]^,posn);
  1886.                 end;
  1887.                 writeln(LST,spaces,sline[LNN]^);
  1888.                 sline[lnn]^ := bufln;
  1889.                 lnn := lnn + 1;
  1890.               end;
  1891.             end;
  1892.             ckln := upcasestr(sline[LNN]^);
  1893.             cmdline := sline[LNN]^;
  1894.             cmdline := cmdline + ' ';
  1895.             if (POS('{NP}',ckln) <> 0) or (pos('{UL}',ckln) <> 0) or (pos('{BP}',ckln) <> 0) then
  1896.             begin
  1897.               write(lst,spaces);
  1898.               if ioerr then exit;
  1899.               if pos('{UL}',ckln) <> 0 then
  1900.               begin
  1901.                 P1 := pos('{',ckln);
  1902.                 delete(cmdline,P1,4);
  1903.                 P2 := pos('{',cmdline);
  1904.                 if p2 = 0 then p2 := length(cmdline);
  1905.                 delete(cmdline,P2,4);
  1906.                 repeat
  1907.                   cnum := cnum + 1;
  1908.                   write(lst,cmdline[cnum]);
  1909.                   if ioerr then exit;
  1910.                 until cnum= P2;
  1911.                 repeat
  1912.                   cnum := cnum - 1;
  1913.                   write(lst,^H);
  1914.                   if ioerr then exit;
  1915.                 until cnum = P1-1;
  1916.                 repeat
  1917.                   cnum := cnum + 1;
  1918.                   write(lst,'_');
  1919.                 if ioerr then exit;
  1920.                 until cnum = P2-1;
  1921.                 if cnum < length(cmdline) then
  1922.                 repeat
  1923.                   cnum := cnum + 1;
  1924.                   write(lst,cmdline[cnum]);
  1925.                   if ioerr then exit;
  1926.                 until cnum >= length(cmdline);
  1927.               end;
  1928.               if pos('{BP}',ckln) <> 0 then
  1929.               begin
  1930.                 P1 := pos('{',ckln);
  1931.                 delete(cmdline,P1,4);
  1932.                 P2 := pos('{',cmdline);
  1933.                 if p2 = 0 then p2 := length(cmdline);
  1934.                 delete(cmdline,P2,4);
  1935.                 repeat
  1936.                   cnum := cnum + 1;
  1937.                   write(lst,cmdline[cnum]);
  1938.                   if ioerr then exit;
  1939.                 until cnum= P2;
  1940.                 repeat
  1941.                   cnum := cnum - 1;
  1942.                   write(lst,^H);
  1943.                   if ioerr then exit;
  1944.                 until cnum = P1-1;
  1945.                 repeat
  1946.                   cnum := cnum + 1;
  1947.                   write(lst,cmdline[cnum]);
  1948.                   if ioerr then exit;
  1949.                until cnum = P2-1;
  1950.                if cnum < length(cmdline) then
  1951.                repeat
  1952.                  cnum := cnum + 1;
  1953.                  write(lst,cmdline[cnum]);
  1954.                  if ioerr then exit;
  1955.                until cnum >= length(cmdline);
  1956.              end;
  1957.              writeln(lst);
  1958.              if ioerr then exit;
  1959.            end
  1960.            else
  1961.            writeln(LST,spaces,sline[LNN]^);
  1962.            if ioerr then exit;
  1963.            ckln := upcasestr(sline[LNN]^);
  1964.            IF (((counter + HEADER + BOTTOM) MOD pagesize = 0) and (pageYN = 'Y'))
  1965.            or (POS('{NP}',ckln) <> 0) THEN
  1966.            BEGIN
  1967.              counter := 0;
  1968.              WRITE(LST,CHR(12));
  1969.              if ioerr then exit;
  1970.              if pause = 'Y' then
  1971.              begin
  1972.                PAUSED := TRUE;
  1973.                gotoxy(2,3);
  1974.                writeln('   Pausing between Pages...');
  1975.                write('Press Any Key to Continue Print');
  1976.                read(kbd,ch);
  1977.                if ch = #27 then goto quit;
  1978.                gotoxy(1,4);clreol;
  1979.              end;
  1980.              if numYn = 'Y' then writeln(lst,spaces,pagenum:39-margin);
  1981.              if ioerr then exit;
  1982.              pagenum := pageNum + 1;
  1983.              if header > 6 then FOR LCNT := 0 TO HEADER-6 DO WRITELN(LST);
  1984.              if ioerr then exit;
  1985.            END;
  1986.            LNN := LNN + 1;
  1987.          until EOF(WPFileName) or (LNN >= MAXLN + 1);
  1988.          xx := 0;
  1989.          write(lst,chr(12));
  1990.          if ioerr then exit;
  1991.          counter := 0;
  1992.          if (pause = 'Y') AND NOT PAUSED then
  1993.          begin
  1994.            PAUSED := FALSE;
  1995.            gotoxy(2,3);
  1996.            writeln('Pausing between Pages');
  1997.            write('Press Return to Continue or Esc to Quit');
  1998.            repeat
  1999.               read(kbd,ch);
  2000.            until ch in [#27,^M];
  2001.            if ch = #27 then goto quit;
  2002.            gotoxy(1,4);clreol;
  2003.          end;
  2004.          if keypressed then
  2005.          begin
  2006.             read(kbd,ch);
  2007.             if ch = #27 then goto quit;
  2008.          end;
  2009.        until lastname or EOF(DfileName);
  2010.        quit:
  2011.        if ch = #27 then WRITE(LST,CHR(12));
  2012.        if ioerr then exit;
  2013.        close(dfilename);
  2014.       end;
  2015.     end;
  2016.   end;
  2017.   clearTextWindow;
  2018.   form;
  2019. end;
  2020.  
  2021. PROCEDURE MailMergePrint;
  2022. begin
  2023.  printit(true);
  2024. end;
  2025.  
  2026. PROCEDURE RegularPrint;
  2027. begin
  2028.   printit(false);
  2029. end;
  2030.  
  2031. PROCEDURE initialize;
  2032. begin
  2033.   clrscr;
  2034.   Typeadapter;
  2035.   nomem := false;
  2036.   if crtmode = 3 then att := 14 else att := 15;
  2037.   form;
  2038.   noprint := false;
  2039.   getdir(0,Cdir);
  2040.   Fword := '';
  2041.   markone:=0;
  2042.   marktwo := 0;
  2043.   WrapOn := true;
  2044.   markblock := false;
  2045.   header := 7;
  2046.   pause := 'N';
  2047.   pageYN := 'Y';
  2048.   numYn := 'N';
  2049.   bottom := 7;
  2050.   pagesize := 66;
  2051.   margin := 9;
  2052.   linewidth := 80 - margin - margin;
  2053.   Temp := '';
  2054.   MAXLN := 0;
  2055.   mark(heaptop);
  2056.   for xx := 1 to endline do sline[xx] := nil;
  2057.   aendline := xx;
  2058.   atopend := xx-20;
  2059. end;
  2060.  
  2061. begin
  2062.   Initialize;
  2063.   GETWPFILE;
  2064.   if Ch <> 'Q' then
  2065.   begin
  2066.     repeat
  2067.       priorch := #00;
  2068.       priorP := 0;
  2069.       PP := 0;
  2070.       PROMPT('Select: E(nter text, G(et file, H(elp, M(erge, P(rint, S(ave, Q(uit, U(tility',
  2071.       ['M','G','S','P','H','E','Q','U'],ch);
  2072.       case Ch of
  2073.         'U' : SysUtil;
  2074.         'E' : EnterWP;
  2075.         'G' : begin
  2076.                 IF (NOT SAVED) and (Maxln >0) THEN
  2077.                 begin
  2078.                   form;
  2079.                   PromptAt(1,24,'File Not Saved!  Save it ? Y/N ');
  2080.                   repeat
  2081.                     read(kbd,Ch);
  2082.                     Ch := upcase(ch);
  2083.                   until Ch in ['Y','N'];
  2084.                   if ch = 'Y' then SaveWP(wpfilevar);
  2085.                 end;
  2086.                 GetWPFile;
  2087.               end;
  2088.         'H' : Help;
  2089.         'M' : mailmergeprint;
  2090.         'P' : regularprint;
  2091.         'S' : BEGIN SaveWP(wpfilevar); SAVED := TRUE; END;
  2092.       end;
  2093.       form;
  2094.     until UpCase(Ch) = 'Q';
  2095.     IF (NOT SAVED) and (MaxLn > 0) THEN
  2096.     begin
  2097.       beep;
  2098.       PromptAt(1,24,'File Not Saved!  Save it ? Y/N ');
  2099.       repeat
  2100.         read(kbd,Ch);
  2101.         Ch := upcase(ch);
  2102.       until Ch in ['Y','N'];
  2103.       if ch = 'Y' then SaveWP(wpfilevar);
  2104.     end;
  2105.   end;
  2106.   release(heaptop);
  2107.  end.
  2108.  
  2109.