home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
tptools.zip
/
BINED.ZIP
/
DEMO2.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-12-21
|
7KB
|
227 lines
{ DEMO2.PAS
Copyright (c) 1985, 87 by Borland International, Inc. }
program Demo2;
uses
bined,
dos,
crt;
const
{Commands other than ^K^D to exit editor}
ExitCommands : array[0..6] of Char = (#2, ^K, ^Q, #2, #0, #68, #0);
MakeBackup = True;
{**************************************************************}
{****************** demonstration follows *********************}
{********* ************}
{*** This demonstration shows the use of two editor windows ***}
{************* opening on two separate files. *****************}
{**************************************************************}
const
{Number of windows}
nwindows = 3;
type
BorderElements = (topleft, topright, botleft, botright, horiz, vert);
BorderChars = array[BorderElements] of Char;
FileArray = array[1..nwindows] of String;
EdWindowArray = array[1..nwindows] of EdCB;
const
{Coordinates of the editor windows}
windpos : array[1..nwindows, 1..4] of Byte =
((2, 3, 39, 13), (42, 3, 79, 13), (2, 16, 79, 23));
{Borders around the windows}
Border : BorderChars = '┌┐└┘─│';
var
EdWindows : EdWindowArray; {Array of editor control blocks}
ExitCode : Word; {Status code set by binary editor functions}
ExitCommand : Integer; {Code for command used to leave editor}
Fname : FileArray; {Files being edited}
CurWindow : Word; {Current editor window}
{Procedures and functions used as part of the demo}
{$I demo.inc}
procedure GetFileNames(var Fname : FileArray);
{-Return a file name either from the command line or a prompt}
var
i : Word;
begin {GetFileName}
for i := 1 to nwindows do
if i <= ParamCount then
Fname[i] := ParamStr(i)
else
repeat
Write('Enter file name #', i, ': ');
ReadLn(Fname[i]);
until (Fname[i] <> '');
end; {GetFileName}
procedure InitWindow(var EdData : EdCB);
{-Draw a nice screen frame around the editor window}
var
MsgPos : Byte;
DemoMsg : String;
begin {InitWindow}
with EdData do begin
{Draw a frame around the editor window}
DrawBox(Border, x1, y1, x2, y2);
{Demo line}
DemoMsg := ' '+FilenameBinaryEditor(eddata)+' ';
MsgPos := Succ((X2+X1-Length(DemoMsg)) shr 1);
CRTputFast(MsgPos, Y2+2, CAerr+DemoMsg);
end;
end; {InitWindow}
procedure InitStatusLine;
{-Draw a status/prompt line for the editor demo}
begin {InitStatusLine}
WriteStatus(' ^K^D saves file, ^K^Q quits editor, <F10> switches windows');
{Initialize for the on-screen clock}
TickMax := 2500;
TickCount := TickMax;
LastTime := '';
end; {InitStatusLine}
function ExitBinaryEditor(var EdWindows : EdWindowArray;
ExitCommand : Integer;
var CurWindow : Word) : Boolean;
{-Handle an editor exit - save, abandon file, switch windows}
var
ExitCode : Word;
msg : String;
ch : Char;
function AnyModified : Boolean;
{-Return true if any window is unsaved}
var
modified : Boolean;
i : Word;
begin {AnyModified}
modified := False;
for i := 1 to nwindows do
modified := modified or ModifiedFileBinaryEditor(EdWindows[i]);
AnyModified := modified;
end; {AnyModified}
procedure SwitchWindows(var CurWindow : Word);
{-Move to the next window}
begin {SwitchWindows}
CurWindow := Succ(CurWindow);
if CurWindow > nwindows then
CurWindow := 1;
end; {SwitchWindows}
begin {ExitBinaryEditor}
case ExitCommand of
-1 : {^K^D}
begin
ExitCode := SaveFileBinaryEditor(EdWindows[CurWindow], MakeBackup);
CheckSaveFile(ExitCode, FilenameBinaryEditor(edwindows[curwindow]));
if AnyModified then begin
SwitchWindows(CurWindow);
ExitBinaryEditor := False;
end else begin
ExitBinaryEditor := True;
GoToXY(1, 25);
end;
end;
0 : {^K^Q}
if AnyModified then begin
WriteStatus(' Changes made. Abandon all windows? (Y/N) ');
repeat
ch:=upcase(readkey);
until ch in ['Y','N'];
if ch='Y' then begin
ExitBinaryEditor := True;
GoToXY(1, 25);
end else begin
while KeyPressed do
ch:=Readkey;
ExitBinaryEditor := False;
InitStatusLine;
end;
end else begin
ExitBinaryEditor := True;
GoToXY(1, 25);
end;
1 : {F10}
begin
{Switch to another window}
SwitchWindows(CurWindow);
ExitBinaryEditor := False;
end;
end;
end; {ExitBinaryEditor}
begin {Demo2}
{Get file names}
GetFileNames(Fname);
ClrScr;
{Initialize a window for each file}
for CurWindow := 1 to nwindows do begin
ExitCode :=
InitBinaryEditor(
EdWindows[CurWindow], {Editor control block, initialized by InitBinaryEditor}
MaxFileSize, {Size of data area to reserve for binary editor text buffer, $FFE0 max}
windpos[CurWindow, 1], {Coordinates of editor window, upper left 1..80}
windpos[CurWindow, 2], {Coordinates of editor window, upper left 1..25}
windpos[CurWindow, 3], {Coordinates of editor window, lower right}
windpos[CurWindow, 4], {Coordinates of editor window, lower right}
True, {True to wait for retrace on color cards}
EdOptInsert+EdOptIndent, {Initial editor toggles}
'.PAS', {Default extension for file names}
ExitCommands, {Commands to exit editor}
Addr(UserEventCheck)); {Address of user event handler}
CheckInitBinary(ExitCode);
{Read each file}
ExitCode := ReadFileBinaryEditor(EdWindows[CurWindow], Fname[CurWindow]);
CheckReadFile(ExitCode, FilenameBinaryEditor(edwindows[curwindow]));
{Reset the editor for the new file}
ResetBinaryEditor(EdWindows[CurWindow]);
{Set up the window border and title}
InitWindow(EdWindows[CurWindow]);
{Enter and exit the editor to draw the screen}
ExitCommand := UseBinaryEditor(EdWindows[CurWindow], ^K^Q);
end;
{Write a status and prompt line}
InitStatusLine;
CurWindow := 1;
repeat
{Edit the file}
ExitCommand := UseBinaryEditor(EdWindows[CurWindow], '');
{Handle the exit by saving the file or switching windows}
until ExitBinaryEditor(EdWindows, ExitCommand, CurWindow);
ClrScr;
end. {Demo2}