home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
tptools.zip
/
BINED.ZIP
/
LINE-ED.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-12-21
|
4KB
|
77 lines
{ LINE-ED.PAS
Copyright (c) 1985, 87 by Borland International, Inc. }
program LineEd;
{$R+} {Range checking on}
uses Crt;
const
MaxLines = 50; {We will allocate space for 50 lines}
MaxLineLength = 80; {Maximum length of a line}
Help = {Help message}
'U)p D)own C)hange S)how L)ist R)ead W)rite Q)uit';
Error = 'Illegal command. Press H for help.'; {Error message}
type
Line = string[MaxLineLength];
var
Lines : Array[1..MaxLines] of Line; {The text buffer}
CurLine : 1..MaxLines; {The current line}
I : Integer; {Loop index, used in various commands}
Cmd : Char; {Command character}
FileName : String[64]; {Name of file to read or write}
F : Text; {File variable for work file}
begin
for I := 1 to MaxLines do {Clear the buffer}
Lines[I] := '';
CurLine := 1; {Set current line to line 1}
WriteLn( Help ); {Show available commands}
repeat
Write('Line ',CurLine:2,'>'); {Prompt with line number}
Cmd := ReadKey; {Get a command}
WriteLn;
case UpCase(Cmd) of
'U' : if CurLine > 1 then {Up line}
Dec(CurLine);
'D' : if CurLine < MaxLines then {Down line}
Inc(CurLine);
'C' : begin {Change line}
if Lines[CurLine] <> '' then
WriteLn('Old line: ', Lines[CurLine]);
Write('New line: ');
ReadLn(Lines[CurLine]);
if CurLine < MaxLines then
Inc(CurLine);
end;
'S' : WriteLn(Lines[CurLine]); {Show lines}
'L' : for I := 1 to MaxLines do {List buffer}
WriteLn(I:2,'> ',Lines[I]);
'R' : begin {Read File}
Write('Filename: ');
ReadLn(FileName);
Assign(F, FileName);
Reset(F);
I := CurLine;
while not Eof(F) and (I <= MaxLines) do begin
ReadLn(F, Lines[I]);
Inc(I);
end;
Close(F);
end;
'W' : begin {Write file}
Write('Filename: ');
ReadLn(FileName);
Assign(F, FileName);
Rewrite(F);
for I := 1 to MaxLines do
WriteLn(F, Lines[I]);
Close(F);
end;
'H' : WriteLn(Help); {Print help message}
'Q' : Halt; {Exit}
else WriteLn(^G,Error); {Print error message}
end; {Case}
until False; {Loop until user quits}
end.