home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
tptools.zip
/
BINED.ZIP
/
DEMO1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-12-21
|
10KB
|
312 lines
{ DEMO1.PAS
Copyright (c) 1985, 87 by Borland International, Inc. }
program Demo1;
uses
bined,
dos,
crt;
const
{Commands other than ^K^D to exit editor}
ExitCommands : array[0..9] of Char = (#2, ^K, ^Q, #2, #0, #68, #2, ^K, ^S, #0);
MakeBackup = True;
{***************************************************************}
{****************** demonstration follows **********************}
{***************************************************************}
{* This demonstration shows the use of one editor window which *}
{****** can be sized and shifted during an edit session. *******}
{***************************************************************}
const
{Initial Coordinates of the editor window}
Windx1 = 11;
Windy1 = 6;
Windx2 = 58;
Windy2 = 20;
var
EdData : EdCB; {Editor control block}
ExitCode : Word; {Status code set by binary editor functions}
ExitCommand : Word; {Code for command used to leave editor}
Fname : String; {Input name of file being edited}
type
BorderElements = (topleft, topright, botleft, botright, horiz, vert);
BorderChars = array[BorderElements] of Char;
const
Border : BorderChars = '┌┐└┘─│';
NoBorder : BorderChars = ' ';
{Procedures and functions used as part of the demo}
{$I demo.inc}
function GetFileName : String;
{-Return a file name either from the command line or a prompt}
var
Fname : String;
begin {GetFileName}
if ParamCount > 0 then
Fname := ParamStr(1)
else begin
Write('Enter file name to edit: ');
ReadLn(Fname);
end;
if Fname = '' then
Halt;
GetFileName := Fname;
end; {GetFileName}
procedure InitWindow(var EdData : EdCB);
{-Draw a nice screen frame around the editor window}
var
MsgPos : Byte;
DemoMsg : String;
begin {InitWindow}
{Draw a frame around the editor window}
with EdData do begin
DrawBox(Border, x1, y1, x2, y2);
{Demo line}
DemoMsg := ' Borland Binary Editor ';
MsgPos := 2+((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 abandons, <F10> resizes window');
{Initialize for the on-screen clock}
TickMax := 2500; {Empirical: keep clock ticking without excessive overhead}
TickCount := TickMax;
LastTime := '';
end; {InitStatusLine}
function ExitBinaryEditor(var EdData : EdCB; ExitCommand : Integer)
: Boolean;
{-Handle an editor exit - save or abandon file}
var
ExitCode : Word;
procedure ModifyWindow(var EdData : EdCB);
{-Move or resize editor window interactively}
var
ch : Char;
redraw, done, scroll : Boolean;
kbflag : Word absolute $0040 : $0017;
lastkbflag : Word;
procedure UpdateScreen(var EdData : EdCb);
{-Update the screen after the window is resized}
var
junk : Word;
begin {UpdateScreen}
{Redraw the window box}
InitWindow(EdData);
if not(keypressed) then begin
{Force the editor to update the screen and return}
junk := UseBinaryEditor(EdData, ^K^S);
redraw := false;
end;
end; {UpdateScreen}
begin {ModifyWindow}
with eddata do begin
{Show a prompt for resizing}
WriteStatus(^X^Y^Z^[' to move/resize window. <ScrollLock> moves. <Enter> accepts.');
lastkbflag := not(kbflag);
done := False;
redraw := False;
repeat
{Update the screen}
if redraw then
UpdateScreen(EdData);
{Keep keyboard toggles up to date}
repeat
scroll := (kbflag and $10) <> 0;
if kbflag <> lastkbflag then begin
WriteKeyboardToggles(kbflag);
lastkbflag := kbflag;
end;
until KeyPressed;
ch := Readkey;
if (ch = #0) and KeyPressed then begin
ch:=Readkey;
case ch of
#75 : {left arrow}
if scroll then begin
if X1 > 1 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
X1 := Pred(X1);
X2 := Pred(X2);
redraw := true;
end;
end else if X2 > X1+30 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
X2 := Pred(X2);
redraw := true;
end;
#77 : {right arrow}
if scroll then begin
if X2 < 78 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
X1 := Succ(X1);
X2 := Succ(X2);
redraw := true;
end;
end else if X2 < 78 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
X2 := Succ(X2);
redraw := true;
end;
#72 : {up arrow}
if scroll then begin
if Y1 > 1 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
Y1 := Pred(Y1);
Y2 := Pred(Y2);
redraw := true;
end;
end else if Y2 > Y1+3 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
Y2 := Pred(Y2);
redraw := true;
end;
#80 : {down arrow}
if scroll then begin
if Y2 < 22 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
Y1 := Succ(Y1);
Y2 := Succ(Y2);
redraw := true;
end;
end else if Y2 < 22 then begin
DrawBox(NoBorder, x1, y1, x2, y2);
Y2 := Succ(Y2);
redraw := true;
end;
end;
end else if ch = #13 then
done := True;
until done;
InitStatusLine;
end;
end; {ModifyWindow}
function YesAnswer(prompt : String) : Boolean;
{-Return true for a yes answer to the prompt}
var
ch : Char;
begin {YesAnswer}
WriteStatus(prompt);
repeat
ch:=UpCase(Readkey);
until ch in ['Y', 'N'];
YesAnswer := (ch = 'Y');
end; {YesAnswer}
begin {ExitBinaryEditor}
case ExitCommand of
-1 : {^K^D}
begin
ExitCode := SaveFileBinaryEditor(EdData, MakeBackup);
CheckSaveFile(ExitCode, FilenameBinaryEditor(eddata));
ExitBinaryEditor := True;
GoToXY(1, 25);
end;
0 : {^K^Q}
begin
if ModifiedFileBinaryEditor(EdData) then
if YesAnswer('File modified. Save it? (Y/N) ') then begin
ExitCode := SaveFileBinaryEditor(EdData, MakeBackup);
CheckSaveFile(ExitCode, FilenameBinaryEditor(eddata));
end;
ExitBinaryEditor := True;
GoToXY(1, 25);
end;
1, 2 : {F10 or ^K^S}
begin
{Allow moving or resizing the window}
ModifyWindow(EdData);
ExitBinaryEditor := False;
end;
end;
end; {ExitBinaryEditor}
begin {Demo1}
{Get a file name}
Fname := GetFileName;
ClrScr;
{Initialize a window for the file}
ExitCode :=
InitBinaryEditor(
EdData, {Editor control block, initialized by InitBinaryEditor}
MaxFileSize, {Size of data area to reserve for binary editor text buffer, $FFE0 max}
Windx1, {Coordinates of editor window, upper left 1..80}
Windy1, {Coordinates of editor window, upper left 1..25}
Windx2, {Coordinates of editor window, lower right}
Windy2, {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 the file}
ExitCode := ReadFileBinaryEditor(EdData, Fname);
CheckReadFile(ExitCode, FilenameBinaryEditor(eddata));
{Reset the editor for the new file}
ResetBinaryEditor(EdData);
{Write a status and prompt line}
InitStatusLine;
repeat
{Set up the window border and title}
InitWindow(EdData);
{Edit the file}
ExitCommand := UseBinaryEditor(EdData, '');
{Handle the exit by saving the file or whatever}
until ExitBinaryEditor(EdData, ExitCommand);
ClrScr;
end. {Demo1}