home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tptools.zip / BINED.ZIP / LINE-ED.PAS < prev    next >
Pascal/Delphi Source File  |  1987-12-21  |  4KB  |  77 lines

  1. {                          LINE-ED.PAS
  2.              Copyright (c) 1985, 87 by Borland International, Inc.            }
  3.  
  4. program LineEd;
  5. {$R+}                                                        {Range checking on}
  6.  
  7. uses Crt;
  8.  
  9. const
  10.    MaxLines = 50;                          {We will allocate space for 50 lines}
  11.    MaxLineLength = 80;                                {Maximum length of a line}
  12.    Help =                                                         {Help message}
  13.      'U)p  D)own  C)hange  S)how  L)ist  R)ead  W)rite  Q)uit';
  14.    Error = 'Illegal command. Press H for help.';                 {Error message}
  15. type
  16.    Line = string[MaxLineLength];
  17. var
  18.    Lines : Array[1..MaxLines] of Line;                         {The text buffer}
  19.    CurLine : 1..MaxLines;                                     {The current line}
  20.    I : Integer;                           {Loop index, used in various commands}
  21.    Cmd : Char;                                               {Command character}
  22.    FileName : String[64];                        {Name of file to read or write}
  23.    F : Text;                                       {File variable for work file}
  24.  
  25. begin
  26.    for I := 1 to MaxLines do                                  {Clear the buffer}
  27.       Lines[I] := '';
  28.    CurLine := 1;                                    {Set current line to line 1}
  29.    WriteLn( Help );                                    {Show available commands}
  30.    repeat
  31.       Write('Line ',CurLine:2,'>');                    {Prompt with line number}
  32.       Cmd := ReadKey;                                            {Get a command}
  33.       WriteLn;
  34.       case UpCase(Cmd) of
  35.          'U' : if CurLine > 1 then                                     {Up line}
  36.                  Dec(CurLine);
  37.          'D' : if CurLine < MaxLines then                             {Down line}
  38.                  Inc(CurLine);
  39.          'C' : begin                                               {Change line}
  40.                   if Lines[CurLine] <> '' then
  41.                     WriteLn('Old line: ', Lines[CurLine]);
  42.                   Write('New line: ');
  43.                   ReadLn(Lines[CurLine]);
  44.                   if CurLine < MaxLines then
  45.                     Inc(CurLine);
  46.                end;
  47.          'S' : WriteLn(Lines[CurLine]);                             {Show lines}
  48.          'L' : for I := 1 to MaxLines do                           {List buffer}
  49.                   WriteLn(I:2,'> ',Lines[I]);
  50.          'R' : begin                                                 {Read File}
  51.                   Write('Filename: ');
  52.                   ReadLn(FileName);
  53.                   Assign(F, FileName);
  54.                   Reset(F);
  55.                   I := CurLine;
  56.                   while not Eof(F) and (I <= MaxLines) do begin
  57.                     ReadLn(F, Lines[I]);
  58.                     Inc(I);
  59.                   end;
  60.                   Close(F);
  61.                end;
  62.          'W' : begin                                                {Write file}
  63.                   Write('Filename: ');
  64.                   ReadLn(FileName);
  65.                   Assign(F, FileName);
  66.                   Rewrite(F);
  67.                   for I := 1 to MaxLines do
  68.                     WriteLn(F, Lines[I]);
  69.                   Close(F);
  70.                end;
  71.          'H' : WriteLn(Help);                               {Print help message}
  72.          'Q' : Halt;                                                      {Exit}
  73.          else  WriteLn(^G,Error);                          {Print error message}
  74.       end;                                                                {Case}
  75.    until False;                                          {Loop until user quits}
  76. end.
  77.