OPTIONS(/E/-A/-Q/-I/-D/C/P:"SAFEIO - System"); EXTERNAL TEXT PROCEDURE rest,upcase; EXTERNAL LONG REAL PROCEDURE scanreal; EXTERNAL INTEGER PROCEDURE scanint; COMMENT --- CLASS SAFMIN --- Version 4.0 Date: 76-01-09 Author: Mats Ohlin Swedish Research Institute of National Defence FOA 1 Fack S-104 50 STOCKHOLM 80 SWEDEN The information in this document is subject to change without notice. The institute assumes no responsibility for any errors that may be present in this document. The described software is furnished to the user for use on a SIMULA system. (SIMULA is a registered trademark of the Norwegian Computing Center, Oslo, Norway). Copyright 1975 by the Swedish Research Institute for National Defence. Copying is allowed. ---------------------------------------------------------------------- SAFMIN is a SIMULA class which is designed to faciliate the programming of conversational parts of SIMULA programs. SAFMIN is a reduced variant of the SAFEI class. SAFMIN does not contain the file handling facilities and has thus no SAFEIO command (!...) functions. Neither has SAFMIN the following SAFEI(O) properties: 1. LONGREALINPUT 2. IRANGE, RANGE 3. OUTOFIRANGE, OUTOFRANGE 4. COMMANDHELP 5. COMMANDMESSAGE 6. LANGUAGE FILE 7. LOG FILE 8. PRINTINT, PRINTREAL 9. INTPUT, REALPUT, FRACPUT The procedure HELP accepts only texts not longer than Sysout.Length. For more information, see SAFEIO.HLP and SAFEIO.DOC bearing in mind the excluded facilities listed above. ; CLASS safmin; VIRTUAL: LABEL eof; BEGIN PROCEDURE outline(t); VALUE t; TEXT t; BEGIN WHILE t.Length > Length DO BEGIN Outtext(t.Sub(1,Length)); t:- t.Sub(Length+1,t.Length-Length) END loop; Outtext(t); Outimage; END of outline; BOOLEAN PROCEDURE nohelp; outline("--- There is no help in this case."); ! The nohelp procedure issues a message that no special help ! information is available. The programmer is however encouraged to ! define his specific help procedures when using ! the request procedure. ; BOOLEAN PROCEDURE help(message); NAME message; TEXT message; ! This procedure will have the side effect of displaying the ! text MESSAGE on Sysout.; outline(message); OPTIONS(/P); BOOLEAN PROCEDURE intinput(result,valid); ! This procedure checks that the rest of the Sysin.image ! contain exactly one integer item (and nothing more). ! If so the syntaxok will be flagged true (so that the errormessage in ! request may be printed) and the intinput will return the value of ! the dynamically evaluated parameter valid (which usually is a boolean ! expression). Otherwise a message will be issued and the syntaxok will ! will be flagged false. ; NAME result,valid; INTEGER result; BOOLEAN valid; BEGIN INTEGER p,x; p:= Sysin.Pos; x:= scanint(Sysin.Image); IF Sysin.Pos > p AND rest(Sysin.Image).Strip == NOTEXT THEN BEGIN result:= x; syntaxok:= TRUE; intinput:= IF checkvalidity THEN valid ELSE TRUE; END ELSE BEGIN Outtext("? Illegal integer item:"); outline(Sysin.Image.Sub(p,Sysin.Length-p+1).Strip); syntaxok:= FALSE END error END of intinput; BOOLEAN PROCEDURE realinput(result,valid); ! This procedure checks a real item. Otherwise as intinput. ; NAME result,valid; REAL result; BOOLEAN valid; BEGIN INTEGER p; REAL x; p:= Sysin.Pos; x:= scanreal(Sysin.Image); IF Sysin.Pos > p AND rest(Sysin.Image).Strip == NOTEXT THEN BEGIN Sysin.Setpos(p); result:= x; syntaxok:= TRUE; realinput:= IF checkvalidity THEN valid ELSE TRUE; END ELSE BEGIN syntaxok:= FALSE; Outtext("? Illegal real item:"); outline(Sysin.Image.Sub(p,Sysin.Length-p+1).Strip) END error END of realinput; BOOLEAN PROCEDURE boolinput(result); NAME result; BOOLEAN result; ! The boolinput procedure has one parameter only. The validity check ! is of course unnecessary for boolean parameters. ! Accepted input depends on the content in the SAFEIO.language file. ! The input line may have lower case letters. ! In the English case it is YES, NO, TRUE OR FALSE. ! P} svenska g{ller JA, NEJ, SANN eller FALSK.; BEGIN TEXT t; CHARACTER c; t:- upcase(rest(Sysin.Image).Strip); IF t.Length = 1 THEN c:= t.Getchar; syntaxok:= TRUE; ! Allow errormessage to be issued.; GO TO IF c = 'Y' OR c = 'J' THEN l_true ELSE IF c = 'N' THEN l_false ELSE IF t = "FALSE" THEN l_false ELSE IF t = "TRUE" THEN l_true ELSE IF t = "YES" THEN l_true ELSE IF t = "NO" THEN l_false ELSE error; l_true: boolinput:= result:= TRUE; GO TO exit; l_false: boolinput:= TRUE; result:= FALSE; GO TO exit; error: Outtext("? Illegal boolean item:"); outline(t); syntaxok:= FALSE; exit: END of boolinput; BOOLEAN PROCEDURE textinput(result,valid); ! This procedure returns a copy of the stripped rest of the input line. ! The syntax is always considered correct.; NAME result,valid; TEXT result; BOOLEAN valid; BEGIN result:- Copy(rest(Sysin.Image).Strip); syntaxok:= TRUE; textinput:= IF checkvalidity THEN valid ELSE TRUE END of textinput; OPTIONS(/P); PROCEDURE request(prompt,default,inputok,errormessage,help); ! The request procedure has the following parameters: ! Prompt is the prompting question, often ending with a ! prompting character as ':'. ! Default is the default text value. If default action is to be ! prohibited, the nodefault variable should be used. ! Inputok shall become true if the input is to be accepted, ! else false. Usually the actual parameter is a call to ! an ***input procedure.; ! Errormessage is a text that will be printed if inputok is ! is false and syntaxok is true (c.f. comment for intinput). ! Help is a BOOLEAN parameter by NAME which will ! be evaluated when the user types a '?'. !; VALUE prompt; NAME default,errormessage,inputok,help; TEXT prompt,default,errormessage; BOOLEAN inputok,help; BEGIN INTEGER p; TEXT u; mainprompt:- prompt; Sysin.Setpos(0); GO TO start; WHILE NOT inputok DO BEGIN Sysin.Setpos(0); IF syntaxok THEN BEGIN Outtext(errormessage); Outimage END; start: Outtext(prompt); IF displaydefault AND default =/= nodefault THEN BEGIN Outchar(defaultquote); Outtext(default); Outchar(defaultquote); Outchar(promptingchar); END display default; IF Pos > 1 THEN BEGIN IF Pos < margin THEN Setpos(margin); Breakoutimage END; u:- rest(Sysin.Image); IF u.Strip == NOTEXT THEN BEGIN Inimage; IF Endfile THEN BEGIN Outtext("[End of file on Sysin.]"); Outimage; GO TO eof END; u:- Sysin.Image END; ! Ignore lines ending with char 11(VT), 12(FF).; FOR p:= IF u.Strip =/= NOTEXT THEN Rank(u.Sub(u.Strip.Length,1).Getchar) ELSE 0 WHILE p = 11 OR p = 12 DO BEGIN Inimage; IF Endfile THEN BEGIN Outtext("[End of file on Sysin.]"); Outimage; GO TO eof END; u:- Sysin.Image END; IF u.Getchar = helpchar THEN BEGIN IF help THEN ; Sysin.Setpos(0); GO TO start END; IF u.Strip == NOTEXT THEN BEGIN IF default == nodefault THEN BEGIN Outtext("? Default answer not allowed."); Outimage; GO TO start; END no default allowed; ! Note the implicit restriction on length ! of the default text. ; u:= IF default.Length > u.Length THEN default.Sub(1,u.Length) ELSE default; END empty input; END input ok loop; Sysin.Setpos(0); END of request; TEXT nodefault,mainprompt; BOOLEAN syntaxok,displaydefault,checkvalidity; INTEGER margin; CHARACTER helpchar,defaultquote,promptingchar; ! Set up initial values. ; nodefault:- Copy("No default"); syntaxok:= displaydefault:= checkvalidity:= TRUE; ! May be changed to zero if no indentation of answers ! is wanted. Could also be increased if very long questions. ; margin:= 35; ! These characters may be changed. However be ! carefull for clashes. ; ! Note the possibility to change these chracters. ; helpchar:= '?'; defaultquote:= '/'; promptingchar:= ':'; ! Eliminating page skipping on Sysout. ; INSPECT Sysout WHEN Printfile DO Linesperpage(-1); start: ; INNER; ! Jumped here if End of File on Sysin:; eof: END of safmin;