home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_edit / sti_ed_f.pas next >
Encoding:
Pascal/Delphi Source File  |  1990-11-08  |  43.7 KB  |  1,398 lines

  1. Unit STI_ED_F;
  2.  
  3. interface
  4.  
  5. Uses Crt,                                   { standard TP 5.0 library       }
  6.      Dos,                                   { staandard Dos unit            }
  7.      STI_SCRF,                              { a few screen procedures       }
  8.      STI_STRN,                              { string handling               }
  9.      STI_KEYS,                              { key scanning unit             }
  10.      STI_ED_V,                              { editor variables              }
  11.      Printer;                               { printer unit                  }
  12.  
  13. procedure Erase_Buffer;
  14. procedure Reset_Colors;                     { reset display colors          }
  15. procedure Error_Message(Message : string);  { put a message on screen       }
  16. function  Allocate_One_Line(LineNo : word) : boolean;
  17. procedure Set_Up_Screen(Var Buff : Buffer); { open the window               }
  18. procedure Restore_Screen(Var Buff : Buffer);{ reset the window              }
  19. procedure Put_Top_Line;                     { draw the top line             }
  20. procedure Put_Bottom_Line;                  { put the bottom line           }
  21. procedure Load_File(Name : string);         { load in a file                }
  22. procedure Draw_All_Screen;
  23. procedure One_Screen_Down;                  { scroll down one page          }
  24. procedure One_Screen_Up;                    { scroll up one page            }
  25. procedure Jump_End_Of_File;
  26. procedure Jump_Start_Of_File;
  27. procedure One_Line_Up;
  28. procedure One_Line_Down;
  29. procedure One_Char_Left;
  30. procedure One_Char_Right;
  31. procedure Begin_Of_Line;
  32. procedure End_Of_Line;
  33. procedure Erase_Line_Contents(LineNo : word);
  34. procedure Insert_One_Line;
  35. procedure Delete_One_Line;
  36. procedure Process_Return_Key;
  37. procedure Delete_One_Char;
  38. procedure Do_Tab;
  39. procedure Reset_TAB;
  40. procedure Do_Help;
  41. procedure Save_File(Name : string);
  42. procedure Load_New_File;
  43. procedure Search;
  44. procedure Search_And_Replace;
  45. procedure Quit_Check;
  46. procedure One_Word_Back;
  47. procedure One_Word_Forward;
  48. procedure Block_Mark_Start;
  49. procedure Block_Mark_End;
  50. procedure Block_Copy;
  51. procedure Block_Erase;
  52. procedure Block_Read;
  53. procedure Block_Write;
  54. procedure Block_Move;
  55. procedure Erase_One_Word;
  56. procedure Pass_Chars_On(Pass : ChrSet);
  57. procedure Block_Print;
  58. procedure Print_File;
  59.  
  60.  
  61. implementation
  62.  
  63. {---------------------------------------------------------------------------}
  64.  
  65. procedure Reset_Block_Markers;
  66.  
  67. begin
  68.   Edit_Buffer^.Block.BC := 0;
  69.   Edit_Buffer^.Block.BL := 0;
  70.   Edit_Buffer^.Block.EC := 0;
  71.   Edit_Buffer^.Block.EL := 0;
  72. end;
  73.  
  74. {---------------------------------------------------------------------------}
  75.  
  76. procedure Erase_Buffer;
  77.  
  78. Var
  79.   Loop : Word;
  80.  
  81. begin
  82.   for Loop := 1 to MAX_LINES do
  83.     begin
  84.       if Edit_Buffer^.TextBuffer^[Loop] <> NIL then
  85.         begin
  86.           Dispose(Edit_Buffer^.TextBuffer^[Loop]);
  87.           Edit_Buffer^.TextBuffer^[Loop] := NIL;
  88.         end;
  89.     end;
  90. end;
  91.  
  92. {---------------------------------------------------------------------------}
  93.  
  94. procedure Reset_Colors;                     { reset display colors          }
  95.  
  96. begin
  97.   TextColor(White);                         { default is white              }
  98.   TextReverse(NoReverse);                   { default is no reverse         }
  99. end;
  100.  
  101. {---------------------------------------------------------------------------}
  102.  
  103. procedure Error_Message(Message : string);  { put a message on screen       }
  104.  
  105. Var
  106.   Len : byte;
  107.  
  108. begin
  109.   Len := length(Message);
  110.   TextColor(Edit_Buffer^.PromptCol);        { change to prompt color        }
  111.   GotoXY(Edit_Buffer^.X1,                   { move to the bottom line       }
  112.          Edit_Buffer^.Y2+1);
  113.   Message := Message + makeStr(80,32);      { pack the string               }
  114.   Write(copy(message,1,Edit_Buffer^.X2-Edit_Buffer^.X1+1)); { write message }
  115.   GotoXY(Edit_Buffer^.X1+Len,Edit_Buffer^.Y2+1);
  116. end;
  117.  
  118. {---------------------------------------------------------------------------}
  119.  
  120. function Allocate_One_Line(LineNo : word) : boolean;
  121.  
  122. begin
  123.   if Edit_Buffer^.TextBuffer^[LineNo] = NIL then
  124.     begin
  125.       if MemAvail > 4000 then
  126.         begin
  127.           New(Edit_Buffer^.TextBuffer^[LineNo]);
  128.           Allocate_One_Line := TRUE;
  129.           Edit_Buffer^.TextBuffer^[LineNo]^ := #31;
  130.         end
  131.       else
  132.         begin
  133.           Error_Message('Out of memory');
  134.           Allocate_One_Line := FALSE;
  135.         end;
  136.     end;
  137. end;
  138.  
  139. {---------------------------------------------------------------------------}
  140.  
  141. procedure Set_Up_Screen(Var Buff : Buffer); { open the window               }
  142.                                             { and save the old screen       }
  143. begin
  144.   MakeWindow(Buff.WinSave,Buff.X1,Buff.Y1,  { open a window                 }
  145.              Buff.X2,Buff.Y2,Buff.TextCol,  { & save screen etc             }
  146.              Buff.BorderCol,Buff.Border);
  147.   if Buff.Border then                       { check for a border            }
  148.     begin
  149.       Inc(Buff.X1); Inc(Buff.Y1);           { adjust the window boundaries  }
  150.       Dec(Buff.X2); Dec(Buff.Y2);           { adjust the window boundaries  }
  151.     end
  152.   else
  153.     Inc(Buff.Y1);                           { always leave bottom free      }
  154. end;
  155.  
  156. {---------------------------------------------------------------------------}
  157.  
  158. procedure Restore_Screen(Var Buff : Buffer);{ reset the window              }
  159.  
  160. begin
  161.   DisposeWindow(Buff.WinSave);              { draw the old screen           }
  162. end;
  163.  
  164. {---------------------------------------------------------------------------}
  165.  
  166. procedure Put_Top_Line;                     { draw the top line             }
  167.  
  168. Var
  169.   Dummy1,                                   { dummy strings                 }
  170.   Dummy2   : string;
  171.  
  172. begin
  173.   TextColor(Edit_Buffer^.BorderCol);        { set the color to frame        }
  174.   GotoXY(Edit_Buffer^.X1,Edit_Buffer^.Y1-1);{ goto a good place             }
  175.   Str(Edit_Buffer^.Row:6,Dummy1);           { get the string converted      }
  176.   Dummy2 := ' Line : '+Dummy1+'    Col : '; { start building it up          }
  177.   Str(Edit_Buffer^.Column:3,Dummy1);        { get the string converted      }
  178.   Dummy2 := Dummy2 + Dummy1;                { build, build                  }
  179.   if Edit_Buffer^.Insert then               { check for insert mode         }
  180.     Dummy2 := Dummy2 + '   INSERT   '       { insert is on                  }
  181.   else
  182.     Dummy2 := Dummy2 + '            ';      { insert is off                 }
  183.   Dummy2 := Dummy2 + Edit_Buffer^.FileName; { add the file name             }
  184.   Str(MemAvail:6,Dummy1);                   { get the string converted      }
  185.   Dummy2 := Dummy2 + '    Mem : ' + Dummy1; { last thing of all             }
  186.   Dummy2 := Dummy2 + MakeStr(128,32);       { build it right up             }
  187.   Write(copy(Dummy2,1,(Edit_Buffer^.X2-Edit_Buffer^.X1)+1));
  188.   Reset_Colors;                             { back to defaults              }
  189. end;
  190.  
  191. {---------------------------------------------------------------------------}
  192.  
  193. procedure Put_Bottom_Line;                  { put the bottom line           }
  194.  
  195. Var
  196.   Dummy   : string;                         { dummy string                  }
  197.  
  198. begin
  199.   TextColor(Edit_Buffer^.BorderCol);        { set the color to frame        }
  200.   GotoXY(Edit_Buffer^.X1,Edit_Buffer^.Y2+1);{ goto a good place             }
  201.   if STI_CapsPressed then                   { check for caps                }
  202.     Dummy := '  CAPS  '                     { yes, add it to dummy          }
  203.   else
  204.     Dummy := '        ';                    { no, add spaces                }
  205.   if STI_KanaPressed then                   { check for kana key            }
  206.     Dummy := Dummy + '  KANA  '             { yes, add it to dummy          }
  207.   else
  208.     Dummy := Dummy + '        ';            { no, add spaces                }
  209.   Dummy := Dummy + MakeStr(128,32);         { pack the string               }
  210.   Write(copy(Dummy,1,(Edit_Buffer^.X2-Edit_Buffer^.X1)+1));
  211.   Reset_Colors;                             { back to defaults              }
  212. end;
  213.  
  214. {---------------------------------------------------------------------------}
  215.  
  216. procedure Load_File(Name : string);         { load in a file                }
  217.  
  218. Var
  219.   InFile : Text;                            { the file                      }
  220.   Dummy  : string;                          { dummy string                  }
  221.   Loop   : byte;
  222.  
  223. begin
  224.   Name := UpCaseStr(Name);
  225.   Edit_Buffer^.FileName := Name;
  226.   Edit_Buffer^.NoLines := 1;                { reset the number of lines     }
  227.   assign(InFile,Name);                      { set the file name             }
  228.   {$I-}
  229.   reset(InFile);                            { open it                       }
  230.   {$I+}
  231.   if IOResult <> 0 then                     { no can do                     }
  232.     begin
  233.       Error_Message('New File : '+Name);    { put a little message          }
  234.       Reset_Colors;
  235.       Exit;                                 { then get oput of here         }
  236.     end;
  237.   Error_Message('Loading '+UpCaseStr(Name)+'...');  { put a prompt          }
  238.   HiddenCursor;                             { hide the cursor               }
  239.   while not(eof(InFile)) do                 { loop until end of file        }
  240.     begin
  241.       ReadLn(InFile,Dummy);                 { read in a line                }
  242.       for Loop := 1 to length(Dummy) do
  243.         begin
  244.           if Dummy[Loop] = #9 then
  245.             Dummy := copy(Dummy,1,Loop-1)+MakeStr(Loop mod 8,32)+Copy(Dummy,Loop+1,255);
  246.         end;
  247.       Dummy := Dummy + #31;
  248.       if Edit_Buffer^.TextBuffer^[Edit_Buffer^.NoLines] <> NIL then
  249.          Edit_Buffer^.TextBuffer^[Edit_Buffer^.NoLines]^ := Dummy
  250.       else
  251.          begin
  252.            if Length(Dummy)+2000 > MemAvail then
  253.              Error_Message('Not enough memory to read complete file')
  254.            else
  255.              begin
  256.                New(Edit_Buffer^.TextBuffer^[Edit_Buffer^.NoLines]);
  257.                Edit_Buffer^.TextBuffer^[Edit_Buffer^.NoLines]^ := Dummy
  258.              end;
  259.          end;
  260.       Put_Top_Line;                         { write top line                }
  261.       Inc(Edit_Buffer^.NoLines);            { increment number of lines     }
  262.     end;
  263.   Close(InFile);                            { close the file                }
  264.   Put_Bottom_Line;                          { draw the bottom line          }
  265.   NormalCursor;                             { restore cursor                }
  266. end;
  267.  
  268. {---------------------------------------------------------------------------}
  269.  
  270. procedure Draw_All_Screen;
  271.  
  272. Var
  273.   Loop    : byte;
  274.   LineNo  : word;
  275.   FromC   : byte;
  276.  
  277. begin
  278.   HiddenCursor;
  279.   FromC := (Edit_Buffer^.Column - Edit_Buffer^.SCRX) + 1;
  280.   Window(Edit_Buffer^.X1,Edit_Buffer^.Y1,Edit_Buffer^.X2,Edit_Buffer^.Y2);
  281.   TextColor(Edit_Buffer^.TextCol);
  282.   for Loop := 1 to Edit_Buffer^.Y2-Edit_Buffer^.Y1+1 do
  283.     begin
  284.       LineNo := (Edit_Buffer^.Row - Edit_Buffer^.SCRY) + Loop;
  285.       GotoXY(1,Loop);
  286.       ClrEol;
  287.       if (Edit_Buffer^.Block.BL < LineNo) and (LineNo < Edit_Buffer^.Block.EL) then
  288.         begin
  289.           Reset_Colors;
  290.           TextColor(Edit_Buffer^.PromptCol);
  291.         end;
  292.       if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  293.         Write(copy(Edit_Buffer^.TextBuffer^[LineNo]^,FromC,
  294.               Edit_Buffer^.X2 - Edit_Buffer^.X1));
  295.       if (Edit_Buffer^.Block.BL = LineNo) then
  296.         begin
  297.           Reset_Colors;
  298.           TextColor(Edit_Buffer^.PromptCol);
  299.           if (Edit_Buffer^.Block.BC <= FromC) then
  300.             begin
  301.               GotoXY(1,Loop);
  302.               ClrEol;
  303.               if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  304.                 Write(copy(Edit_Buffer^.TextBuffer^[LineNo]^,FromC,
  305.                            Edit_Buffer^.X2 - Edit_Buffer^.X1));
  306.             end
  307.           else
  308.             begin
  309.               GotoXY((Edit_Buffer^.Block.BC - FromC)+1,Loop);
  310.               ClrEol;
  311.               if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  312.                 Write(copy(Edit_Buffer^.TextBuffer^[LineNo]^,Edit_Buffer^.Block.BC,
  313.                            (Edit_Buffer^.X2 - Edit_Buffer^.X1)-Edit_Buffer^.Block.BC));
  314.             end;
  315.         end;
  316.       if (Edit_Buffer^.Block.EL = LineNo) then
  317.         begin
  318.           Reset_Colors;
  319.           TextColor(Edit_Buffer^.TextCol);
  320.           if FromC > Edit_Buffer^.Block.EC then
  321.             begin
  322.               GotoXY(1,Loop);
  323.               ClrEol;
  324.               if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  325.                 Write(copy(Edit_Buffer^.TextBuffer^[LineNo]^,FromC,
  326.                 Edit_Buffer^.X2 - Edit_Buffer^.X1));
  327.             end
  328.           else
  329.             begin
  330.               GotoXY((Edit_Buffer^.Block.EC - FromC)+1,Loop);
  331.               ClrEol;
  332.               if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  333.                 Write(copy(Edit_Buffer^.TextBuffer^[LineNo]^,Edit_Buffer^.Block.EC,
  334.                 Edit_Buffer^.X2 - Edit_Buffer^.X1));
  335.             end;
  336.         end;
  337.     end;
  338.   Reset_Colors;
  339.   Window(1,1,80,25);
  340.   Put_Top_Line;
  341.   Put_Bottom_Line;
  342.   NormalCursor;
  343.   GotoXY(Edit_Buffer^.X1+Edit_Buffer^.SCRX -1,
  344.          Edit_Buffer^.Y1+Edit_Buffer^.SCRY -1);
  345. end;
  346.  
  347. {---------------------------------------------------------------------------}
  348.  
  349. procedure One_Screen_Down;                  { scroll down one page          }
  350.  
  351. begin
  352.   Edit_Buffer^.SCRY := 1;
  353.   if Edit_Buffer^.Row > (Edit_Buffer^.Y2 - Edit_Buffer^.Y1) then
  354.     Edit_Buffer^.Row := Edit_Buffer^.Row - ((Edit_Buffer^.Y2-Edit_Buffer^.Y1) -2)
  355.   else
  356.       Edit_Buffer^.Row  := 1;
  357. end;
  358.  
  359. {---------------------------------------------------------------------------}
  360.  
  361. procedure One_Screen_Up;                    { scroll up one page            }
  362.  
  363. begin
  364.   if Edit_Buffer^.Row < Edit_Buffer^.NoLines - (Edit_Buffer^.Y2 - Edit_Buffer^.Y1) then
  365.     Edit_Buffer^.Row := Edit_Buffer^.Row +
  366.                             ((Edit_Buffer^.Y2-Edit_Buffer^.Y1) -2)
  367.   else
  368.     begin
  369.       Edit_Buffer^.SCRY := 1;
  370.       Edit_Buffer^.Row := Edit_Buffer^.NoLInes;
  371.     end;
  372. end;
  373.  
  374. {---------------------------------------------------------------------------}
  375.  
  376. procedure Jump_End_Of_File;
  377.  
  378. begin
  379.   Edit_Buffer^.SCRY := 1;
  380.   Edit_Buffer^.Row := Edit_Buffer^.NoLInes;
  381. end;
  382.  
  383. {---------------------------------------------------------------------------}
  384.  
  385. procedure Jump_Start_Of_File;
  386.  
  387. begin
  388.   Edit_Buffer^.SCRY := 1;
  389.   Edit_Buffer^.Row  := 1;
  390. end;
  391.  
  392. {---------------------------------------------------------------------------}
  393.  
  394. procedure One_Line_Up;
  395.  
  396. begin
  397.   if Edit_Buffer^.Row > 1 then
  398.     begin
  399.       Dec(Edit_Buffer^.Row);
  400.       Dec(Edit_Buffer^.SCRY);
  401.       if Edit_Buffer^.SCRY = 0 then
  402.         begin
  403.           Edit_Buffer^.SCRY := 1;
  404.           Draw_All_Screen;
  405.           Exit;
  406.         end;
  407.       Put_Top_Line;
  408.       Put_Bottom_Line;
  409.       Delay(70);
  410.       GotoXY(Edit_Buffer^.SCRX+Edit_Buffer^.X1-1,
  411.              Edit_Buffer^.SCRY+Edit_Buffer^.Y1-1);
  412.     end;
  413. end;
  414.  
  415. {---------------------------------------------------------------------------}
  416.  
  417. procedure One_Line_Down;
  418.  
  419. begin
  420.   if Edit_Buffer^.Row < Edit_Buffer^.NoLines then
  421.     begin
  422.       Inc(Edit_Buffer^.Row);
  423.       Inc(Edit_Buffer^.SCRY);
  424.       if Edit_Buffer^.SCRY > (Edit_Buffer^.Y2 - Edit_Buffer^.Y1)+1 then
  425.         begin
  426.           Dec(Edit_Buffer^.SCRY);
  427.           Draw_All_Screen;
  428.           Exit;
  429.         end;
  430.       Put_Top_Line;
  431.       Put_Bottom_Line;
  432.       Delay(70);
  433.       GotoXY(Edit_Buffer^.SCRX+Edit_Buffer^.X1-1,
  434.              Edit_Buffer^.SCRY+Edit_Buffer^.Y1-1);
  435.     end;
  436. end;
  437.  
  438. {---------------------------------------------------------------------------}
  439.  
  440. procedure One_Char_Left;
  441.  
  442. begin
  443.   Dec(Edit_Buffer^.Column);
  444.   Dec(Edit_Buffer^.SCRX);
  445.   if (Edit_Buffer^.SCRX = 0) and (Edit_Buffer^.Column = 0) then
  446.     begin
  447.       if Edit_Buffer^.Row = 1 then
  448.         begin
  449.           Edit_Buffer^.SCRX   := 1;
  450.           Edit_Buffer^.Column := 1;
  451.           Put_top_Line;
  452.         end
  453.       else
  454.         begin
  455.           One_Line_Up;
  456.           Edit_Buffer^.Column := length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  457.           if Edit_Buffer^.Column > Edit_Buffer^.X2 - Edit_Buffer^.X1 then
  458.             Edit_Buffer^.SCRX := Edit_Buffer^.X2 - Edit_Buffer^.X1
  459.           else
  460.             Edit_Buffer^.SCRX := Edit_Buffer^.Column;
  461.         end;
  462.     end
  463.   else
  464.     if (Edit_Buffer^.Column > 0) and (Edit_Buffer^.SCRX = 0) then
  465.      begin
  466.        Edit_Buffer^.SCRX := 1;
  467.        Draw_All_Screen;
  468.        Exit;
  469.      end;
  470.   Put_Bottom_Line;
  471.   Put_Top_Line;
  472.   Delay(70);
  473.   GotoXY(Edit_Buffer^.X1+Edit_Buffer^.SCRX -1,
  474.          Edit_Buffer^.Y1+Edit_Buffer^.SCRY -1);
  475. end;
  476.  
  477. {---------------------------------------------------------------------------}
  478.  
  479. procedure One_Char_Right;
  480.  
  481. begin
  482.   Inc(Edit_Buffer^.Column);
  483.   Inc(Edit_Buffer^.SCRX);
  484.   if (Edit_Buffer^.SCRX > (Edit_Buffer^.X2-Edit_Buffer^.X1)) then
  485.     begin
  486.       if Edit_Buffer^.Column <= length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^) then
  487.         begin
  488.           Dec(Edit_Buffer^.SCRX);
  489.           Draw_All_Screen;
  490.           Exit;
  491.         end
  492.       else
  493.         begin
  494.           Edit_Buffer^.SCRX := 1;
  495.           One_Line_Down;
  496.           Exit;
  497.         end;
  498.     end
  499.   else
  500.     if Edit_Buffer^.Column > length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^) then
  501.       begin
  502.         One_Line_Down;
  503.         Edit_Buffer^.Column := 1;
  504.         Edit_Buffer^.SCRX   := 1;
  505.       end;
  506.   Put_Top_Line;
  507.   Put_Bottom_Line;
  508.   Delay(70);
  509.   GotoXY(Edit_Buffer^.X1+Edit_Buffer^.SCRX -1,
  510.          Edit_Buffer^.Y1+Edit_Buffer^.SCRY -1);
  511. end;
  512.  
  513. {---------------------------------------------------------------------------}
  514.  
  515. procedure Begin_Of_Line;
  516.  
  517. begin
  518.   Edit_Buffer^.SCRX   := 1;
  519.   Edit_Buffer^.Column := 1;
  520. end;
  521.  
  522. {---------------------------------------------------------------------------}
  523.  
  524. procedure End_Of_Line;
  525.  
  526. begin
  527.   Edit_Buffer^.Column := length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  528.   if Edit_Buffer^.Column > Edit_Buffer^.X2 - Edit_Buffer^.X1 then
  529.     Edit_Buffer^.SCRX := Edit_Buffer^.X2 - Edit_Buffer^.X1
  530.   else
  531.     Edit_Buffer^.SCRX := Edit_Buffer^.Column;
  532. end;
  533.  
  534. {---------------------------------------------------------------------------}
  535.  
  536. procedure Erase_Line_Contents(LineNo : word);
  537.  
  538. begin
  539.   if Edit_Buffer^.TextBuffer^[LineNo] <> NIL then
  540.     Edit_Buffer^.TextBuffer^[LineNo]^ := #31;
  541. end;
  542.  
  543. {---------------------------------------------------------------------------}
  544.  
  545. procedure Insert_One_Line;
  546.  
  547. Var
  548.   Loop : word;
  549.  
  550. begin
  551.   Inc(Edit_Buffer^.NoLines);
  552.   for Loop := Edit_Buffer^.NoLines downto Edit_Buffer^.Row + 1 do
  553.     begin
  554.       Edit_Buffer^.TextBuffer^[Loop] := Edit_Buffer^.TextBuffer^[Loop-1];
  555.     end;
  556.   Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row] := NIL;
  557.   if not Allocate_One_Line(Edit_Buffer^.Row) then
  558.     begin
  559.       Error_Message('Out_Of_Memory');
  560.     end;
  561.   Begin_Of_Line;
  562. end;
  563.  
  564. {---------------------------------------------------------------------------}
  565.  
  566. procedure Delete_One_Line;
  567.  
  568.  
  569. Var
  570.   Loop : word;
  571.  
  572. begin
  573.   if Edit_Buffer^.Row > Edit_Buffer^.NoLines then
  574.     Exit;
  575.   Dispose(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]);
  576.   for Loop := Edit_Buffer^.Row to Edit_Buffer^.NoLInes - 1  do
  577.     begin
  578.       Edit_Buffer^.TextBuffer^[Loop] := Edit_Buffer^.TextBuffer^[Loop+1];
  579.     end;
  580.   Edit_Buffer^.TextBuffer^[Edit_Buffer^.NoLines] := NIL;
  581.   Dec(Edit_Buffer^.NoLines);
  582.   Begin_Of_Line;
  583. end;
  584.  
  585. {---------------------------------------------------------------------------}
  586.  
  587. procedure Process_Return_Key;
  588.  
  589. Var
  590.   Dummy   : string;
  591.   Col,Len : byte;
  592.  
  593. begin
  594.   Col := Edit_Buffer^.Column;
  595.   Len := length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  596.   if Col > Len then
  597.     begin
  598.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ :=
  599.         Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,1,Len-1)
  600.         + MakeStr(Col-Len,32) + #31;
  601.     end;
  602.   if Edit_Buffer^.Insert then
  603.     begin
  604.       if (Edit_Buffer^.Column = 1) then
  605.         begin
  606.           Insert_One_Line;
  607.           One_Line_Down;
  608.         end
  609.       else
  610.         if (Edit_Buffer^.Column = length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^)) then
  611.           begin
  612.             One_Line_Down;
  613.             Insert_One_Line;
  614.           end
  615.         else
  616.           begin
  617.             Dummy := copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,Edit_Buffer^.Column,128);
  618.             Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ :=
  619.               copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,1,Edit_Buffer^.Column-1)+#31;
  620.             One_Line_Down;
  621.             Insert_One_Line;
  622.             Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Dummy+#31;
  623.           end;
  624.     end
  625.   else
  626.     begin
  627.       Edit_Buffer^.Column := 1;
  628.       Edit_Buffer^.SCRX   := 1;
  629.       One_Line_Down;
  630.     end;
  631. end;
  632.  
  633. {---------------------------------------------------------------------------}
  634.  
  635. procedure Delete_One_Char;
  636.  
  637. Var
  638.   Col,Len : byte;
  639.   Dummy   : string;
  640.  
  641. begin
  642.   Col     := Edit_Buffer^.Column;
  643.   Len     := Length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  644.   Dummy   := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^;
  645.   if Col > Len then
  646.     Exit;
  647.   if Col < Len then
  648.     begin
  649.       Dummy := Copy(Dummy,1,Col-1) + Copy(Dummy,Col+1,128);
  650.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Dummy;
  651.     end
  652.   else
  653.     begin
  654.       if Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row+1] <> NIL then
  655.         begin
  656.           Dummy := Copy(Dummy,1,Len-1) + Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row+1]^;
  657.           if Length(Dummy) < 128 then
  658.             begin
  659.               Col := Edit_Buffer^.Column;
  660.               Delete_One_Line;
  661.               Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Dummy;
  662.               Edit_Buffer^.Column := Col;
  663.               if Col < Edit_Buffer^.X2 - Edit_Buffer^.X1 then
  664.                 Edit_Buffer^.SCRX := Col
  665.               else
  666.                 Edit_Buffer^.SCRX := Edit_Buffer^.X2-Edit_Buffer^.X1;
  667.             end
  668.           else
  669.             begin
  670.               Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^   := Copy(Dummy,1,127) + #31;
  671.               Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row+1]^ := Copy(Dummy,128,256);
  672.               End_Of_Line;
  673.             end;
  674.         end;
  675.     end;
  676. end;
  677.  
  678. {---------------------------------------------------------------------------}
  679.  
  680. procedure Do_Tab;
  681.  
  682. begin
  683.   if Edit_Buffer^.TabMarks[Edit_Buffer^.Column] then
  684.     One_Char_Right;
  685.   While not(Edit_Buffer^.TabMarks[Edit_Buffer^.Column]) do
  686.     One_Char_Right;
  687. end;
  688.  
  689. {---------------------------------------------------------------------------}
  690.  
  691. procedure Reset_TAB;
  692.  
  693. Var
  694.   Loop : Byte;
  695.  
  696. begin
  697.   Error_Message('New Tab : ');
  698.   GotoXY(Edit_Buffer^.X1+10,Edit_Buffer^.Y2+1);
  699.   ReadLn(Edit_Buffer^.TabWidth);
  700.   if Edit_Buffer^.TabWidth > 32 then
  701.     Edit_Buffer^.TabWidth := 32;
  702.   for Loop := 1 to MAX_LEN   do             { loop on width                 }
  703.     begin
  704.       if Loop mod Edit_Buffer^.TabWidth = 0 then
  705.         Edit_Buffer^.TabMarks[Loop] := TRUE
  706.       else                                  { set tab markers               }
  707.         Edit_Buffer^.TabMarks[Loop] := FALSE;
  708.     end;
  709.   Put_Bottom_Line;
  710.   Reset_Colors;
  711. end;
  712.  
  713. {---------------------------------------------------------------------------}
  714.  
  715. procedure Do_Help;
  716.  
  717. begin
  718.   if @Edit_Buffer^.HP <> NIL then
  719.     Edit_Buffer^.HP;
  720. end;
  721.  
  722. {---------------------------------------------------------------------------}
  723.  
  724. procedure Save_File(Name : String);
  725.  
  726. Var
  727.   Loop    : word;
  728.   OutFile : Text;                           { the file                      }
  729.   Dummy   : string;                         { dummy string                  }
  730.  
  731. begin
  732.   assign(OutFile,Name);                     { set the file name             }
  733.   {$I-}
  734.   rewrite(OutFile);                         { open it                       }
  735.   {$I+}
  736.   if IOResult <> 0 then                     { no can do                     }
  737.     begin
  738.       Error_Message('Write Error : '+Name); { put a little message          }
  739.       Exit;                                 { then get oput of here         }
  740.       Close(OutFile);                        { close the file               }
  741.     end;
  742.   Error_Message('Saving '+UpCaseStr(Name)+'...');   { put a prompt          }
  743.   HiddenCursor;                             { hide the cursor               }
  744.   for Loop := 1 to Edit_Buffer^.NoLines do  { loop until end of file        }
  745.     begin
  746.       if Edit_Buffer^.TextBuffer^[Loop] <> NIL then
  747.         WriteLn(OutFile,copy(Edit_Buffer^.TextBuffer^[Loop]^,1,
  748.                 length(Edit_Buffer^.TextBuffer^[Loop]^)-1));
  749.     end;
  750.   Close(OutFile);                           { close the file                }
  751.   Put_Bottom_Line;                          { draw the bottom line          }
  752.   NormalCursor;                             { restore cursor                }
  753. end;
  754.  
  755. {---------------------------------------------------------------------------}
  756.  
  757. procedure Load_New_File;
  758.  
  759. Var
  760.   Name : string;
  761.  
  762. begin
  763.   if @Edit_Buffer^.DP <> NIL then
  764.     begin
  765.       Name := Edit_Buffer^.DP;
  766.     end
  767.   else
  768.     begin
  769.       Error_Message('New File : ');
  770.       GotoXY(Edit_Buffer^.X1 + 11,Edit_Buffer^.Y2+1);
  771.       ReadLn(Name);
  772.     end;
  773.   if Name = ''
  774.     then Exit;
  775.   Erase_Buffer;
  776.   Put_Top_Line;
  777.   Load_File(Name);
  778.   Jump_Start_Of_File;
  779.   Reset_Block_Markers;
  780. end;
  781.  
  782. {---------------------------------------------------------------------------}
  783.  
  784. procedure Search;
  785.  
  786. var
  787.   Temp        : string[30];
  788.   Loop,
  789.   Pointer,
  790.   Line,
  791.   Len         : word;
  792.  
  793. begin
  794.   Error_Message('Search : ó'+SearchString+'ú ');
  795.   Temp := '';
  796.   ReadLn(Temp);
  797.   Reset_Colors;
  798.   if Temp <> '' then
  799.     SearchString := temp;
  800.   Len := length(SearchString);
  801.   if Len = 0 then
  802.     begin
  803.       Jump_Start_Of_File;
  804.       Exit;
  805.      end;
  806.   Error_Message('Searching .......');
  807.   Reset_Colors;
  808.  
  809.   for Loop := Edit_Buffer^.Row to Edit_Buffer^.NoLines do
  810.     begin
  811.       Pointer := pos(SearchString,Edit_Buffer^.TextBuffer^[Loop]^);
  812.       if (Pointer > 0) then
  813.         begin
  814.           Edit_Buffer^.Row := Loop;
  815.           Edit_Buffer^.Column := Pointer;
  816.           Draw_All_Screen;
  817.           Exit;
  818.         end;
  819.     end;
  820.   Error_Message('Search string not found.');
  821.   Reset_Colors;
  822.   Repeat until KeyPressed;
  823.   Loop := ord(ReadKey);
  824.   Delay(100);
  825. end;
  826.  
  827. {---------------------------------------------------------------------------}
  828.  
  829. procedure Search_And_Replace;
  830.  
  831. var
  832.   Temp        : string[30];
  833.   Loop,
  834.   Position,
  835.   Pointer,
  836.   Line,
  837.   Len         : word;
  838.   Choice      : char;
  839.  
  840. begin
  841.   Error_Message('Search for ó'+SearchString+'ú ');
  842.   Temp := '';
  843.   ReadLn(Temp);
  844.   if Temp <> '' then
  845.     SearchString := temp;
  846.   Len := length(SearchString);
  847.   if Len = 0 then
  848.     begin
  849.       Jump_Start_Of_File;
  850.       Reset_Colors;
  851.       Exit;
  852.      end;
  853.  
  854.   Error_Message('Replace With ó'+ReplaceString+'ú ');
  855.   Temp := '';
  856.   ReadLn(Temp);
  857.   if Temp <> '' then
  858.     ReplaceString := temp;
  859.   Len := length(ReplaceString);
  860.  
  861.   Error_Message('Searching......');
  862.   Reset_Colors;
  863.   for Line := 1 to Edit_Buffer^.NoLines do
  864.     begin
  865.       Position := pos(SearchString,Edit_Buffer^.TextBuffer^[Line]^);
  866.       while (Position > 0) do
  867.        begin
  868.          Reset_Colors;
  869.          Edit_Buffer^.Row    := Line;
  870.          Edit_Buffer^.Column := Position;
  871.          Draw_All_Screen;
  872.          TextColor(Edit_Buffer^.PromptCol);
  873.          Write(SearchString);
  874.          Reset_Colors;
  875.          Error_Message('Replace (Y/N/ESC)? ');
  876.          Repeat Until KeyPressed;
  877.          Choice := ReadKey;
  878.          Reset_Colors;
  879.          if Choice = #27 then
  880.            begin
  881.              Begin_Of_Line;
  882.              Jump_Start_Of_File;
  883.              Exit;
  884.            end;
  885.          Error_Message('Searching......');
  886.          if Choice in ['y','Y'] then
  887.            begin
  888.              Edit_Buffer^.TextBuffer^[Line]^ :=
  889.                 Copy(Edit_Buffer^.TextBuffer^[Line]^, 1,Position-1) +
  890.                 ReplaceString +
  891.                 Copy(Edit_Buffer^.TextBuffer^[Line]^,Position+Length(SearchString),MAX_LEN);
  892.              Position := pos(SearchString,
  893.                              Copy(Edit_Buffer^.TextBuffer^[Line]^,
  894.                                   Position+Length(ReplaceString)+1,128));
  895.            end
  896.          else
  897.            Position := Pos(SearchString,Copy(Edit_Buffer^.TextBuffer^[Line]^,
  898.                            Position + Length(SearchString)+1,128)) +
  899.                            Position + Length(SearchString);
  900.  
  901.            Reset_Colors;
  902.       end;
  903.     end;
  904.  
  905.   Error_Message('End of Replace');
  906.   Repeat until KeyPressed;
  907.   Choice := ReadKey;
  908.   Delay(100);
  909.   Reset_Colors;
  910. end;
  911.  
  912.  
  913.  
  914. {---------------------------------------------------------------------------}
  915.  
  916. procedure Quit_Check;
  917.  
  918. begin
  919.   if Edit_Buffer^.Saved then
  920.     Edit_Buffer^.Done := TRUE
  921.   else
  922.     begin
  923.       Error_Message('Save Y/N ');
  924.       GotoXY(Edit_Buffer^.X1+10,Edit_Buffer^.Y2+1);
  925.       repeat until KeyPressed;
  926.       if ReadKey in ['Y','y'] then
  927.         Save_File(Edit_Buffer^.FileName);
  928.       Edit_Buffer^.Done := TRUE;
  929.     end;
  930. end;
  931.  
  932. {---------------------------------------------------------------------------}
  933.  
  934. procedure One_Word_Back;
  935.  
  936. begin
  937.   if Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ' then
  938.     begin
  939.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ') do
  940.         One_Char_Left;
  941.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] <> ' ') do
  942.         One_Char_Left;
  943.       One_Char_Right;
  944.     end
  945.   else
  946.     begin
  947.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] <> ' ') do
  948.         One_Char_Left;
  949.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ') do
  950.         One_Char_Left;
  951.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] <> ' ') do
  952.         One_Char_Left;
  953.       One_Char_Right;
  954.     end;
  955. end;
  956.  
  957. {---------------------------------------------------------------------------}
  958.  
  959. procedure One_Word_Forward;
  960.  
  961. begin
  962.   if Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ' then
  963.     begin
  964.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ') do
  965.         One_Char_Right;
  966.     end
  967.   else
  968.     begin
  969.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] <> ' ') do
  970.         One_Char_Right;
  971.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ') do
  972.         One_Char_Right;
  973.     end;
  974. end;
  975.  
  976. {---------------------------------------------------------------------------}
  977.  
  978. procedure Block_Mark_Start;
  979.  
  980. begin
  981.   Edit_Buffer^.Block.BC := Edit_Buffer^.Column;
  982.   Edit_Buffer^.Block.BL := Edit_Buffer^.Row;
  983.   if (Edit_Buffer^.Block.EC = Edit_Buffer^.Block.BC) and
  984.      (Edit_Buffer^.Block.EL = Edit_Buffer^.Block.BL) then
  985.      Reset_Block_Markers;
  986. end;
  987.  
  988. {---------------------------------------------------------------------------}
  989.  
  990. procedure Block_Mark_End;
  991.  
  992. begin
  993.   Edit_Buffer^.Block.EC := Edit_Buffer^.Column;
  994.   Edit_Buffer^.Block.EL := Edit_Buffer^.Row;
  995.   if (Edit_Buffer^.Block.EC = Edit_Buffer^.Block.BC) and
  996.      (Edit_Buffer^.Block.EL = Edit_Buffer^.Block.BL) then
  997.      Reset_Block_Markers;
  998.   if Edit_Buffer^.Block.EC = 1 then
  999.     begin
  1000.       Dec(Edit_Buffer^.Block.EL);
  1001.       Edit_Buffer^.Block.EC := 255;
  1002.     end;
  1003. end;
  1004.  
  1005. {---------------------------------------------------------------------------}
  1006.  
  1007. procedure Block_Copy;
  1008.  
  1009. Var
  1010.   Hold,
  1011.   Dummy  : string;
  1012.   DumDum,
  1013.   OldRow,
  1014.   Loop   : word;
  1015.  
  1016. begin
  1017.   if (Edit_Buffer^.Block.BC = 0) or (Edit_Buffer^.Block.EC = 0) or
  1018.      (Edit_Buffer^.Block.BL = 0) or (Edit_Buffer^.Block.EL = 0) then
  1019.     begin
  1020.       Reset_Block_Markers;
  1021.       Exit;
  1022.     end;
  1023.   if Edit_Buffer^.Block.BL = Edit_Buffer^.Block.EL then
  1024.     begin
  1025.       Dummy := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^;
  1026.       Hold  := Copy(Dummy,Edit_Buffer^.Column+1,MAX_LEN);
  1027.       Dummy := Copy(Dummy,1,Edit_Buffer^.Column) +
  1028.                Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1029.                     Edit_Buffer^.Block.BC,
  1030.                     Edit_Buffer^.Block.EC-Edit_Buffer^.Block.BC)+Hold;
  1031.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN);
  1032.       Edit_Buffer^.Block.BL := Edit_Buffer^.Row;
  1033.       Edit_Buffer^.Block.EL := Edit_Buffer^.Row;
  1034.       if length(Dummy) > MAX_LEN then
  1035.         begin
  1036.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1037.           One_Line_Down;
  1038.           Insert_One_Line;
  1039.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,MAX_LEN,256)+#31;
  1040.           Edit_Buffer^.Block.EL := Edit_Buffer^.Row;
  1041.         end;
  1042.       Edit_Buffer^.Block.EC := Edit_Buffer^.Column +
  1043.         (Edit_Buffer^.Block.EC-Edit_Buffer^.Block.BC);
  1044.       Edit_Buffer^.Block.BC := Edit_Buffer^.Column;
  1045.     end
  1046.   else
  1047.     begin
  1048.       DumDum := 0;
  1049.       OldRow := Edit_Buffer^.Row;
  1050.       Dummy := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^;
  1051.       Hold  := Copy(Dummy,Edit_Buffer^.Column+1,MAX_LEN);
  1052.       Dummy := Copy(Dummy,1,Edit_Buffer^.Column) +
  1053.                Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1054.                     Edit_Buffer^.Block.BC,
  1055.                     Edit_Buffer^.Block.EC-Edit_Buffer^.Block.BC);
  1056.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN);
  1057.       Edit_Buffer^.Block.BC := Edit_Buffer^.Column;
  1058.       if length(Dummy) > MAX_LEN then
  1059.         begin
  1060.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1061.           One_Line_Down;
  1062.           Insert_One_Line;
  1063.           if Edit_Buffer^.Row < Edit_Buffer^.Block.EL then
  1064.             inc(DumDum);
  1065.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,MAX_LEN,256);
  1066.         end;
  1067.       for Loop := Edit_Buffer^.Block.BL+1 to Edit_Buffer^.Block.EL-1 do
  1068.         begin
  1069.           One_Line_Down;
  1070.           Insert_One_Line;
  1071.           if Edit_Buffer^.Row < Edit_Buffer^.Block.EL then
  1072.             begin
  1073.               inc(DumDum);
  1074.             end;
  1075.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ :=
  1076.              Edit_Buffer^.TextBuffer^[Loop+DumDum]^;
  1077.         end;
  1078.       One_Line_Down;
  1079.       Insert_One_Line;
  1080.       if Edit_Buffer^.Row < Edit_Buffer^.Block.EL then
  1081.        inc(DumDum);
  1082.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ :=
  1083.         Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.EL+DumDum]^,1,Edit_Buffer^.Block.EC);
  1084.       Edit_Buffer^.Block.EC := length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  1085.         Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ :=
  1086.           Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,1,
  1087.              length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^)-1) + Hold;
  1088.       Dummy := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^;
  1089.       if length(Dummy) > MAX_LEN then
  1090.         begin
  1091.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1092.           One_Line_Down;
  1093.           Insert_One_Line;
  1094.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,MAX_LEN,256);
  1095.         end;
  1096.       Edit_Buffer^.Block.EL := Edit_Buffer^.Row;
  1097.       Edit_Buffer^.Block.BL := OldRow;
  1098.     end;
  1099. end;
  1100.  
  1101. {---------------------------------------------------------------------------}
  1102.  
  1103. procedure Block_Erase;
  1104.  
  1105. Var
  1106.   OLDROW,
  1107.   OLDSY,
  1108.   OLDSX  : byte;
  1109.   Loop   : word;
  1110.   Dummy,
  1111.   ELStr,
  1112.   BLStr  : string;
  1113.  
  1114.  
  1115. begin
  1116.   if (Edit_Buffer^.Block.BC = 0) or (Edit_Buffer^.Block.EC = 0) or
  1117.      (Edit_Buffer^.Block.BL = 0) or (Edit_Buffer^.Block.EL = 0) then
  1118.     begin
  1119.       Reset_Block_Markers;
  1120.       Exit;
  1121.     end;
  1122.   OLDROW := Edit_Buffer^.Row;
  1123.   OLDSY := Edit_Buffer^.SCRY;
  1124.   OLDSX := Edit_Buffer^.SCRX;
  1125.   ELStr := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.EL]^;
  1126.   BLStr := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^;
  1127.   Edit_Buffer^.Row := Edit_Buffer^.Block.BL;
  1128.   if Edit_Buffer^.Block.BL = Edit_Buffer^.Block.EL then
  1129.     Delete_One_Line
  1130.   else
  1131.     begin
  1132.       for Loop := 0 to Edit_Buffer^.Block.EL - Edit_Buffer^.Block.BL do
  1133.         Delete_One_Line;
  1134.       end;
  1135.   if (Edit_Buffer^.Block.BC > 1) or (Edit_Buffer^.Block.EC < MAX_LEN) then
  1136.     begin
  1137.       Insert_One_Line;
  1138.       Dummy := copy(BLStr,1,Edit_Buffer^.Block.BC-1) +
  1139.                copy(ELStr,Edit_Buffer^.Block.EC+1,MAX_LEN);
  1140.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Dummy;
  1141.     end;
  1142.   Reset_Block_Markers;
  1143.   Edit_Buffer^.Row  := OLDROW;
  1144.   Edit_Buffer^.SCRY := OLDSY;
  1145. end;
  1146.  
  1147. {---------------------------------------------------------------------------}
  1148.  
  1149. procedure Block_Read;
  1150.  
  1151. Var
  1152.   InStr,
  1153.   Hold,
  1154.   Dummy  : string;
  1155.   InFile : text;
  1156.  
  1157. begin
  1158.   Reset_Block_Markers;
  1159.   if @Edit_Buffer^.DP <> NIL then
  1160.     begin
  1161.       InStr := Edit_Buffer^.DP;
  1162.     end
  1163.   else
  1164.     begin
  1165.       Error_Message('From File : ');
  1166.       GotoXY(13,Edit_Buffer^.Y2+1);
  1167.       ReadLn(InStr);
  1168.     end;
  1169.   assign(InFile,InStr);
  1170.   {$I-}
  1171.   reset(InFile);
  1172.   {$I+}
  1173.   if IOResult <> 0 then
  1174.     begin
  1175.       Error_Message('Can not open '+InStr);
  1176.       Exit;
  1177.     end;
  1178.   Dummy := Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,1,Edit_Buffer^.Column);
  1179.   Hold  := Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^,Edit_Buffer^.Column+1,MAX_LEN);
  1180.   Edit_Buffer^.Block.BC := Edit_Buffer^.Column;
  1181.   Edit_Buffer^.Block.BL := Edit_Buffer^.Row;
  1182.   ReadLn(InFile,InStr);
  1183.   Dummy := Dummy+InStr;
  1184.   Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN);
  1185.   if length(Dummy) > MAX_LEN then
  1186.     begin
  1187.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1188.       One_Line_Down;
  1189.       Insert_One_Line;
  1190.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,MAX_LEN,256)+#31;
  1191.     end;
  1192.   while not eof(InFile) do
  1193.     begin
  1194.       ReadLn(InFile,InStr);
  1195.       One_Line_Down;
  1196.       Insert_One_Line;
  1197.       Dummy := InStr;
  1198.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN);
  1199.       if length(Dummy) > MAX_LEN then
  1200.         begin
  1201.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1202.           One_Line_Down;
  1203.           Insert_One_Line;
  1204.           Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^  := Copy(Dummy,MAX_LEN,256)+#31;
  1205.         end;
  1206.     end;
  1207.   Dummy := Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^+Hold;
  1208.   Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN);
  1209.   if length(Dummy) > MAX_LEN then
  1210.     begin
  1211.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,1,MAX_LEN)+#31;
  1212.       One_Line_Down;
  1213.       Insert_One_Line;
  1214.       Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^ := Copy(Dummy,MAX_LEN,256)+#31;
  1215.     end;
  1216.   Edit_Buffer^.Block.EL := Edit_Buffer^.Row;
  1217.   Edit_Buffer^.Block.EC := length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^);
  1218.   Close(InFile);
  1219.   Put_Bottom_Line;
  1220. end;
  1221.  
  1222. {---------------------------------------------------------------------------}
  1223.  
  1224. procedure Block_Write;
  1225.  
  1226. Var
  1227.   Dummy  : string;
  1228.   OutF   : text;
  1229.   Loop   : word;
  1230.  
  1231. begin
  1232.   if (Edit_Buffer^.Block.BC = 0) or (Edit_Buffer^.Block.EC = 0) or
  1233.      (Edit_Buffer^.Block.BL = 0) or (Edit_Buffer^.Block.EL = 0) then
  1234.     begin
  1235.       Reset_Block_Markers;
  1236.       Exit;
  1237.     end;
  1238.   if @Edit_Buffer^.DP <> NIL then
  1239.     begin
  1240.       Dummy := Edit_Buffer^.DP;
  1241.     end
  1242.   else
  1243.     begin
  1244.       Error_Message('To File : ');
  1245.       GotoXY(11,Edit_Buffer^.Y2+1);
  1246.       ReadLn(Dummy);
  1247.     end;
  1248.   assign(OutF,Dummy);
  1249.   {$I-}
  1250.   rewrite(OutF);
  1251.   {$I+}
  1252.   if IoResult <> 0 then
  1253.     begin
  1254.       Error_Message('Can not open '+Dummy);
  1255.       Exit;
  1256.     end;
  1257.   if Edit_Buffer^.Block.BL = Edit_Buffer^.Block.EL then
  1258.     begin
  1259.       WriteLn(OutF,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1260.                         Edit_Buffer^.Block.BC,
  1261.                         Edit_Buffer^.Block.EC-Edit_Buffer^.Block.BC));
  1262.     end
  1263.   else
  1264.     begin
  1265.       WriteLn(OutF,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1266.                         Edit_Buffer^.Block.BC,length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^)-1));
  1267.       if Edit_Buffer^.Block.EL = Edit_Buffer^.Block.BL + 1 then
  1268.         begin
  1269.           WriteLn(OutF,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL+1]^,
  1270.                         1,Edit_Buffer^.Block.EC));
  1271.         end
  1272.       else
  1273.         begin
  1274.           for Loop := Edit_Buffer^.Block.BL+1 to Edit_Buffer^.Block.EL-1 do
  1275.             WriteLn(OutF,Copy(Edit_Buffer^.TextBuffer^[Loop]^,1,length(Edit_Buffer^.TextBuffer^[Loop]^)-1));
  1276.           WriteLn(OutF,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL+1]^,
  1277.                         1,Edit_Buffer^.Block.EC));
  1278.         end;
  1279.     end;
  1280.   Close(OutF);
  1281.   Put_Bottom_Line;
  1282. end;
  1283.  
  1284. {---------------------------------------------------------------------------}
  1285.  
  1286. procedure Block_Move;
  1287.  
  1288. Var
  1289.   BC1,BL1,EC1,EL1  : word;
  1290.  
  1291. begin
  1292.   BC1 := Edit_Buffer^.Block.BC;
  1293.   BL1 := Edit_Buffer^.Block.BL;
  1294.   EC1 := Edit_Buffer^.Block.EC;
  1295.   EL1 := Edit_Buffer^.Block.EL;
  1296.   Block_Copy;
  1297.   Edit_Buffer^.Block.BC := BC1;
  1298.   Edit_Buffer^.Block.BL := BL1;
  1299.   Edit_Buffer^.Block.EC := EC1;
  1300.   Edit_Buffer^.Block.EL := EL1;
  1301.   Block_Erase;
  1302.   Reset_Block_Markers;
  1303. end;
  1304.  
  1305. {---------------------------------------------------------------------------}
  1306.  
  1307. procedure Block_Print;
  1308.  
  1309. Var
  1310.   Dummy  : string;
  1311.   Loop   : word;
  1312.  
  1313. begin
  1314.   if (Edit_Buffer^.Block.BC = 0) or (Edit_Buffer^.Block.EC = 0) or
  1315.      (Edit_Buffer^.Block.BL = 0) or (Edit_Buffer^.Block.EL = 0) then
  1316.     begin
  1317.       Reset_Block_Markers;
  1318.       Exit;
  1319.     end;
  1320.   Error_Message('Printing......');
  1321.   WriteLn(Lst);
  1322.   if Edit_Buffer^.Block.BL = Edit_Buffer^.Block.EL then
  1323.     begin
  1324.       WriteLn(Lst,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1325.                         Edit_Buffer^.Block.BC,
  1326.                         Edit_Buffer^.Block.EC-Edit_Buffer^.Block.BC));
  1327.     end
  1328.   else
  1329.     begin
  1330.       WriteLn(Lst,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^,
  1331.                         Edit_Buffer^.Block.BC,length(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL]^)-1));
  1332.       if Edit_Buffer^.Block.EL = Edit_Buffer^.Block.BL + 1 then
  1333.         begin
  1334.           WriteLn(Lst,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL+1]^,
  1335.                         1,Edit_Buffer^.Block.EC));
  1336.         end
  1337.       else
  1338.         begin
  1339.           for Loop := Edit_Buffer^.Block.BL+1 to Edit_Buffer^.Block.EL-1 do
  1340.             WriteLn(Lst,copy(Edit_Buffer^.TextBuffer^[Loop]^,1,length(Edit_Buffer^.TextBuffer^[loop]^)-1));
  1341.           WriteLn(Lst,Copy(Edit_Buffer^.TextBuffer^[Edit_Buffer^.Block.BL+1]^,
  1342.                         1,Edit_Buffer^.Block.EC));
  1343.         end;
  1344.     end;
  1345.   Put_Bottom_Line;
  1346. end;
  1347.  
  1348. {---------------------------------------------------------------------------}
  1349.  
  1350. procedure Print_File;
  1351.  
  1352. Var
  1353.   Loop    : word;
  1354.   Dummy   : string;                         { dummy string                  }
  1355.  
  1356. begin
  1357.   Error_Message('Printing..... ');          { put a prompt          }
  1358.   HiddenCursor;                             { hide the cursor               }
  1359.   for Loop := 1 to Edit_Buffer^.NoLines do  { loop until end of file        }
  1360.     begin
  1361.       if Edit_Buffer^.TextBuffer^[Loop] <> NIL then
  1362.         WriteLn(Lst,copy(Edit_Buffer^.TextBuffer^[Loop]^,1,
  1363.                 length(Edit_Buffer^.TextBuffer^[Loop]^)-1));
  1364.     end;
  1365.   Put_Bottom_Line;                          { draw the bottom line          }
  1366.   NormalCursor;                             { restore cursor                }
  1367. end;
  1368.  
  1369. {---------------------------------------------------------------------------}
  1370.  
  1371. procedure Erase_One_Word;
  1372.  
  1373. begin
  1374.   if Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ' then
  1375.     begin
  1376.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] = ' ') do
  1377.         Delete_One_Char;
  1378.     end
  1379.   else
  1380.     begin
  1381.       while (Edit_Buffer^.TextBuffer^[Edit_Buffer^.Row]^[Edit_Buffer^.Column] <> ' ') do
  1382.         Delete_One_Char;
  1383.     end;
  1384. end;
  1385.  
  1386. {---------------------------------------------------------------------------}
  1387.  
  1388. procedure Pass_Chars_On(Pass : ChrSet);
  1389.  
  1390. begin
  1391.   if @Edit_Buffer^.PP <> NIL then
  1392.     Edit_Buffer^.PP(Pass);
  1393. end;
  1394.  
  1395. {---------------------------------------------------------------------------}
  1396.  
  1397. begin
  1398. end.