home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
EDUCATIN
/
K-CHING.LBR
/
STATUSLN.MZD
/
STATUSLN.MOD
Wrap
Text File
|
2000-06-30
|
10KB
|
312 lines
IMPLEMENTATION MODULE StatusLn;
FROM Terminal IMPORT WriteString, GotoXY, ReadChar, WriteChar;
FROM Strings IMPORT Append, Length, Copy, Insert, Delete;
PROCEDURE CursorRecall(Mem: BOOLEAN);
(* If Mem is TRUE current cursor position is remembered
If Mem is FALSE the cursor is returned to previously membered position!*)
BEGIN
WriteChar(33C);
IF Mem=TRUE THEN WriteChar('B') ELSE WriteChar('C'); END;
WriteChar('6');
END CursorRecall;
PROCEDURE PreserveStatusLine(Mem: BOOLEAN);
(* I've got no idea what this function does. It's just mentioned
briefly in the Kaypro manual. In case I ever want to use it...
TRUE turns preservation on, FALSE turns it off. WOW! *)
BEGIN
WriteChar(33C);
IF Mem=TRUE THEN WriteChar('B') ELSE WriteChar('C'); END;
WriteChar('7');
END PreserveStatusLine;
PROCEDURE GotoStatusX(x: CARDINAL);
(* Gets around m2's inability [ie BUG] to write to the status line
and have the editor behave as well by writing a Kaypro excape sequence
Notice that the statusline scrolls after every LF, so a WriteLn following
this routine will note give lasting results. Also, the cursor MUST be
dragged out of the statusline back to its proper position in the text
before continuing normal text output *)
BEGIN
WriteChar(33C);
WriteChar('=');
WriteChar(CHR(24+32));
WriteChar(CHR(x+32));
END GotoStatusX;
PROCEDURE Blank(x: CARDINAL);
(* Blanks the screen and homes cursor if x=0
If x>99 prints x DIV 100 LINEFEEDS
then prints 1-99 [x MOD 100] blanks at current position
*)
VAR y: CARDINAL;
BEGIN
IF x=0 THEN WriteChar(32C); (*BLANK SCREEN*)
ELSE
FOR y:= 1 TO (x DIV 100) DO
WriteChar(15C);
WriteChar(12C);
END;
FOR y:= 1 TO (x MOD 100) DO WriteChar(' '); END;
END;
END Blank;
PROCEDURE ErrorMessage(s: ARRAY OF CHAR);
(* Writes an errormessage to the programmer.
Program Execution can be halted at this point by pressing ^C
*)
VAR c: CHAR;
BEGIN
CursorRecall(TRUE);
GotoStatusX(0);
WriteString('ERROR : ');
WriteString(s);
WriteString(' (^C abort) ');
ReadChar(c);
IF (c=CHR(3)) THEN HALT; END;
GotoStatusX(0);
Blank(79);
CursorRecall(FALSE);
END ErrorMessage;
PROCEDURE InputED(VAR StringToEdit: ARRAY OF CHAR; Prompt: ARRAY OF CHAR;
MaxLength : CARDINAL) ;
(* This little gem enables you to input with editing, starting from
scratch [''] or from an assigned default StringToEdit.
Prompt is usually = '>' or '?'.
<CR> with the cursor in col zero returns the original StringToEdit,
ignoring any changes that have been made during the procedure.
<CR> anywhere else truncates the string at the character before the
cursor and returns that value.
<ESC> returns the entire string as displayed, regardless of cursor
position.
<DEL> Deletes the Char to the left of the cursor and closes the gap
<TAB> (^I) Inserts a space at the current cursor position.
<LEFTARROW> (^H or ^S) performs nondestructive backspace.
<RIGHTARROW> (^L or ^D) performs nondestructive aheadspace upto
MaxLength.
^C halts the program.
All printable characters are accepted into the displayed string,
overwriting the character under the cursor and advancing one position.
If the Default StringToEdit is longer than MaxLength, it is truncated.
MaxLength MUST be <80.
Trailing blanks are stripped from result.
*)
VAR
x,xx: CARDINAL;
SafeString,TempString: ARRAY [0..79] OF CHAR;
c: CHAR;
BEGIN
IF MaxLength>79 THEN
ErrorMessage('MaxLength > 79');
END;
IF Length(StringToEdit)>MaxLength
THEN Copy(StringToEdit,1,MaxLength,StringToEdit);
END;
SafeString:=StringToEdit;
GotoStatusX(0);
Blank(80);
GotoStatusX(0);
WriteString(Prompt);
x:=Length(Prompt);
xx:=x;
GotoStatusX(xx);
WriteString(StringToEdit);
GotoStatusX(xx);
REPEAT
ReadChar(c);
IF ( (c=(10C)) OR (c=CHR(19)) ) AND (xx>x) THEN
xx:=xx-1;
GotoStatusX(xx);
ELSIF ( (c=(14C)) OR (c=(4C)) ) AND (xx-x<MaxLength)
AND ( xx-x<Length(StringToEdit) )
THEN
xx:=xx+1;
GotoStatusX(xx);
ELSIF (c=(33C))THEN StringToEdit:=StringToEdit;
ELSIF (c=(15C)) AND (xx=x) THEN StringToEdit:=SafeString;
ELSIF (c=(15C)) THEN
Copy(StringToEdit,0,(xx-x),TempString);
StringToEdit:=TempString;
ELSIF ( (ORD(c)=127) (*DEL*) AND (xx-x>0) ) THEN
Delete(StringToEdit,(xx-x-1),1);
xx:=xx-1;
GotoStatusX(x);
WriteString(StringToEdit);
WriteChar(' ');
GotoStatusX(xx);
ELSIF (ORD(c)=3) (*CTRL-C*) THEN HALT;
ELSIF ( ORD(c)=9 (*TAB*) ) THEN
Insert(' ',StringToEdit,xx-x);
IF (Length(StringToEdit)>MaxLength)
THEN Delete(StringToEdit,Length(StringToEdit),1);
END;
GotoStatusX(x);
WriteString(StringToEdit);
GotoStatusX(xx);
ELSIF ( (ORD(c)>31) AND (ORD(c)<127) ) THEN
IF ( (xx-x)<=Length(StringToEdit) ) AND (xx-x<=MaxLength) THEN
StringToEdit[xx-x]:=c;
ELSIF (xx-x<=MaxLength) AND (xx-x>Length(StringToEdit)) THEN
Append(' ',StringToEdit);
StringToEdit[xx-x]:=c;
END;
IF xx-x<=MaxLength THEN
WriteChar(c);
xx:=xx+1;
END;
END;
UNTIL ( (c=(15C)) OR (ORD(c)=27) );
WHILE (StringToEdit[Length(StringToEdit)] = ' ') DO
Delete(StringToEdit, Length(StringToEdit), 1);
END; (* Remove Trailing Blanks *)
END InputED;
PROCEDURE HitAny;
VAR c: CHAR;
(*
Calls a temporary halt in execution with the prompt
"Press ANY key to continue" on the statusline.
^C will abort the program.
Cursor is returned to screenposition it occupied prior to HitAny
*)
BEGIN
CursorRecall(TRUE);
GotoStatusX(0);
Blank(79);
GotoStatusX(0);
WriteString('Press ANY key to continue ');
ReadChar(c);
IF c=CHR(3) THEN HALT; END;
CursorRecall(FALSE);
END HitAny;
PROCEDURE UserWantsTo(Question: ARRAY OF CHAR): BOOLEAN;
(*
Cleverly worded PROCEDURE name forms an English phrase with clear meaning
if Question is worded to complete the option being queried:
e.g.
IF UserWantsTo('Continue') THEN . . . ELSE HALT;
displays
Continue? (Y/n)
on the statusline. N,n,<ESC>= FALSE. ^C aborts. Y,y,<SP>,<CR> = TRUE.
Nothing else is accepted.
Cursor is remembered and replaced.
NB: This function supplies its own questionmark!!
*)
VAR c: CHAR;
BEGIN
CursorRecall(TRUE);
GotoStatusX(0);
Blank(79);
GotoStatusX(0);
WriteString(Question);
WriteString('? (Y/n) ');
LOOP;
ReadChar(c);
CursorRecall(FALSE);
IF c=CHR(3) THEN HALT;
ELSIF ( (c='N') OR (c='n') OR (c=CHR(27)) ) THEN RETURN FALSE;
ELSIF ( (c='Y') OR (c='y') OR (c=CHR(13)) OR (c=' ') ) THEN RETURN TRUE;
END;
END;
END UserWantsTo;
PROCEDURE Copyright
(ProgramName,Version,Date: ARRAY OF CHAR; PrivateDomain: BOOLEAN);
VAR x: INTEGER;
(* Generates an opening screen complete with copyright notice
and version number. If PrivateDomain is FALSE, program is ceded to
the Public Domain.
ProgramName may be upto 80CHARs long and is displayed centered in a
prominant position. To ensure fit, Date should be 4-10 chars eg '1987'
*)
BEGIN
WriteChar(CHR(26)); (*CLEARSCREEN*)
(*DRAW BOX*)
GotoXY(10,3);
FOR x:= 1 TO 30 DO WriteChar('*'); WriteChar(' '); END;
GotoXY(70,3); WriteChar('*');
FOR x := 4 TO 17 DO
GotoXY(10,x);WriteChar('*');
GotoXY(70,x);WriteChar('*');
END;
GotoXY(10,18);
FOR x:= 1 TO 30 DO WriteChar('*'); WriteChar(' '); END;
GotoXY(70,18); WriteChar('*');
x:= (80-Length(ProgramName)) DIV 2;
GotoXY(x,6);
WriteString(ProgramName);
x:= ((80-Length(Version)-8) DIV 2);
GotoXY(x,8);
WriteString('version ');
WriteString(Version);
GotoXY(15,12);
IF PrivateDomain THEN
WriteString('(c) ');
WriteString(Date);
WriteString(' Copyright J. F. Cuff' );
ELSE
WriteString('(pd) ');
WriteString(Date);
WriteString(' placed in the Public Domain by J. F. Cuff' );
END;
GotoXY(15,14);
WriteString('dba ZYQOTE Systems');
GotoXY(15,15);
WriteString('P. O. Box 1165 - Bonavista - Newfoundland - A0C 1B0');
GotoStatusX(0);
END Copyright;
PROCEDURE Notice(s: ARRAY OF CHAR);
(*Blanks the Statusline then writes the message s to the statusline.
Returns Cursor to precall position on exit.
*)
BEGIN
CursorRecall(TRUE);
GotoStatusX(0);
Blank(79); (* to blankout any previous message *)
GotoStatusX(0);
WriteString(s);
CursorRecall(FALSE);
END Notice;
END StatusLn.