Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-05 - 43,50337/23/reques.sim
There is 1 other file named reques.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-Q/-A/-I/-D);
TEXT PROCEDURE request
(prompt,default,result,valid,errmessage,help);
NAME prompt,default,result,valid,errmessage,help;
TEXT prompt,default,result,errmessage,help;
BOOLEAN valid;
!
Procedure REQUEST may be used when putting simple questions to
an interactive user.
The PROMPTing question and the DEFAULT value will be displayed on
the user's TTY (SYSOUT).  The Stripped input line from the TTY (SYSIN)
is stored in RESULT. If then the NAME parameter VALID is TRUE
the result is accepted and (also) returned through REQUEST.
Otherwise the ERRMESSAGE is displayed followed by a new
PROMPTing question. If the user enters an empty anser -
i.e. presses the return key - the DEFAULT answer will be used.
(This may be prohibited by using an illegal answer for default.)
If the user enters a questionmark '?', the text HELP will
be printed. Since it is a NAME parameter, actual parameter
may be a text procedure call with the possible side effect of
displaying additional help text.

Since it may be difficult the remember the different parameters -
learn the following sentence:
Please ( P for Prompt)  Don't (D for Default) Risk (R for Result)
Villainous (V for Valid) Entries (E for Errmessage) Here (H for Help).

Example:
!BEGIN EXTERNAL TEXT PROCEDURE conc,request,rest;
!    EXTERNAL REF (Infile) PROCEDURE findinfile;
!    EXTERNAL INTEGER PROCEDURE checkreal;
!
!    TEXT u;!    REAL x;
!
!    request("File:",NOTEXT,u,
!    findinfile(u)=/=NONE,conc("? Can't find:",u),
!    "Enter valid file spec for input file.");
!
!    x:=
!    request("Enter x:","2.5",u,
!    checkreal(u) = 1 AND rest(u).Strip == NOTEXT,
!    "?Illegal real item.","Enter valid real item").Getreal;
!
!END
    ! For more frequent applications it is recommended to use
    ! a special validity testing Boolean procedure with the side-
    ! effect of saving (the finally correct) result. I.e.
    ! EXTERNAL TEXT PROCEDURE rest;
    ! EXTERNAL LONG REAL PROCEDURE scanreal;
    !
    ! BOOLEAN PROCEDURE testreal(u,x);
    ! NAME x;!   TEXT u;!   REAL x;
    ! BEGIN   INTEGER p;
    !     p:= u.Pos;!   x:= scanreal(u);
    !     testreal:= IF u.Pos > p THEN rest(u).Strip == NOTEXT ELSE
    !                FALSE;
    ! END of testreal;
    !
    !    request("Enter x:","2.5",u,testreal(u,x),
    !    "?Illegal real item.","Enter valid real item");
    ! ........;

BEGIN   TEXT t;

    GO TO start;

    WHILE NOT valid DO
    BEGIN
	Outtext(errmessage);   Outimage;
	start:
	Outtext(prompt);
	IF default =/= NOTEXT THEN
	BEGIN   Outchar('/');   Outtext(default);
	    Outchar('/');   Outchar(':')
	END;
	Breakoutimage;   Inimage;
	t:- Copy(Sysin.Image.Strip);   Sysin.Setpos(0);
	IF t == NOTEXT THEN result:- Copy(default) ELSE
	IF t.Getchar = '?' THEN
	BEGIN   Outtext(help);   Outimage;
	    GO TO start
	END ELSE
	BEGIN   t.Setpos(1);   result:- t   END;
    END loop;

    request:- result

END of request;