1 SUB M11SCR (ENTERED.TEXT$, ROW%, COL%, MAX.CHARS%, DEFAULT.VALUE$, & VALIDATION$, F.END%) & 2 !******************************************************************** & ! & ! & ! M11SCR & ! & ! Reads an answer from the user & ! & ! & !******************************************************************** & ! 3 ! Subprogram : M11SCR & ! Version : 1 & ! Programmer : John Montrym & ! Releaser : Jean Fullerton & ! & !-------------------------------------------------------------------- 11 ! & ! & ! C O P Y R I G H T & ! & ! & !-------------------------------------------------------------------- 100 ! & ! & ! Description & ! & ! & ! This subprogram receives user input of maximum length MAX.CHARS% & ! from the keyboard on channel CH.KB%. The cursor is first placed & ! at (ROW%,COL%) and the default value (DEFAULT.VALUE$) is displayed, & ! followed by enough underscores to fill out the field to & ! the allowable input length (MAX.CHARS%). The user may type & ! just a carriage return to accept DEFAULT.VALUE$. In that case, & ! ENTERED.TEXT$ equals DEFAULT.VALUE$ upon return. The user may & ! enter one or more spaces followed by RETURN to blank out & ! the field. Of course, he may also enter up to MAX.CHARS% & ! printing characters terminated by a . & ! & ! The key will erase individual characters; & ! will erase the entire entry. will & ! return with F.END% set, as though the user typed "END". & ! All other non-printing characters are ignored. Control & ! characters and leading and trailing blanks are stripped & ! from the input and the text is redisplayed and returned & ! in ENTERED.TEXT$. & ! & ! Text is validated according to the value of VALIDATION$: & ! & ! "a" Text can be anything & ! "A" Text can be anything, changed to upper case & ! "N" Text must be all numeric & ! "I" Text must be a positive integer value & ! "D" Text must be in DEC standard date format & ! "Y" Text must be either Y or N & ! & ! & ! Text is redisplayed left-justified. & ! This subprogram assumes it is talking to a VT52, opened on & ! CH.KB%, MODE 8%. & ! & ! Calling modules: Any module & ! & !-------------------------------------------------------------------- & ! & ! System Dependent Features: & ! & ! RSTS - SYS call to exit and clear program & ! (without cleaning up partial buffers) & ! & !-------------------------------------------------------------------- 200 ! & ! & ! Interfaces & ! & ! Common areas: & ! & ! COMERR - Error conditions variables & ! COMCON - General system constants & ! & ! & ! Arguments: & ! & ! ENTERED.TEXT$ output Validated user answer & ! & ! ROW% input Line on screen to show answer & ! COL% input Char position on screen to show ans & ! MAX.CHARS% input Maximum number char.s to allow in ans & ! DEFAULT.VALUE$ input Default answer to display & ! VALIDATION$ input Type of validation to do on answer & ! & ! F.END% output TRUE, if ^Z was entered & ! & !--------------------------------------------------------------------- 300 ! & ! & ! Input / Output & ! & ! & ! Channel Filename Map name Status at entry/exit & ! ------- --------- -------- -------------------- & ! CH.KB% User keyboard None Open/Open & ! 400 !-------------------------------------------------------------------- & ! & ! Variable and Array Definitions & ! & ! & ! & ! CAP.TEXT$ Capitalized version of user input & ! CRPOS% Position of CR/LF characters in input string & ! D.LEN% Length of default answer string & ! DEF.VALUE$ Default value cleaned up & ! ENT.TEXT$ Working version of answer string & ! ERL Line in which error occurred & ! ERR Set to error number after error & ! INPUT.FIELD.LEN% Allowable length of answer string & ! UNDERSCORE% ASCII value of underscore (fill) character & ! VALID.DATE$ Date answer, in an acceptable form & ! WORK($) Intermediate work variable & ! & ! 600 !-------------------------------------------------------------------- & ! & ! & ! COMMON Declarations & ! & ! & !-------------------------------------------------------------------- 650 !-------------------------------------------------------------------- & ! & ! & ! MAP Statements & ! & ! & !--------------------------------------------------------------------- 700 ! & ! & ! Subprograms & ! & ! & ! none & ! & !-------------------------------------------------------------------- & ! 800 ! Subroutines & ! & ! none & ! & !-------------------------------------------------------------------- & ! & ! Functions & ! & ! 15100 FNPOS$ (X%,Y%) Returns a string which, when printed & ! to a VT52, puts the cursor at position & ! (X%,Y%) & ! & ! 15800 FN.VALID.DATE% (DD.MMM.YY$) Validates a date & ! & ! & 1000 !******************************************************************** & ! & ! & ! S T A R T P R O G R A M L O G I C & ! & ! & !******************************************************************** & & 1010 ON ERROR GOTO 19000 & \ ERR.SUBNAM$ = "M11SCR VER:01" & ! Set standard error trap. & ! Set up COMMON for error reporting. & 1020 UNDERSCORE% = 95% & \ M11.ALL.DONE% = FALSE% & \ XLATE.STR$ = STRING$ (32%,33%) +STRING$ (95%,0%) +STRING$ (1%,33%) & ! Define ASCII underscore character value. & ! Define the translation string that will replace printable & ! characters will nulls and non-printing char.s with an exclamation. & 1030 SET_TERM$ = CHR$(6%)+CHR$(16%)+CHR$(0%)+CHR$(255%) & + STRING$(17%,0%) ! Set up prefix for the SYS call to set terminal characterostics. ! Used to set and reset the ESC SEQ characteristic. 1040 SET_ESC$ = SYS( SET_TERM$ + CHR$( 255% ) ) ! SYS call to set terminal to recognize incoming escape sequences. 1100 !-------------------------------------------------------------------- & ! & ! Read Answer & ! & !-------------------------------------------------------------------- & & 1120 ENT.TEXT$ = "" & \ F.END% = FALSE% & \ DEF.VALUE$ = EDIT$ (DEFAULT.VALUE$, 140%) & \ D.LEN% = LEN (DEF.VALUE$) & \ PRINT #CH.KB%, FNPOS$ (ROW%,COL%) & + DEF.VALUE$ & + STRING$ (MAX.CHARS% - D.LEN%, UNDERSCORE%) & + SPACE$ (3% - MAX.CHARS%) & + FNPOS$ (ROW%,COL%); & \ INPUT.FIELD.LEN% = MAX.CHARS% & \ INPUT.FIELD.LEN% = 3% IF MAX.CHARS% < 3% & ! Null out the return data string, clear 'end' flag, & ! Clean up default - no leading/trailing spaces/tabs, no junk. & ! Paint the default, if any, and the underscores. & ! Set the input field length to allow at least "END". & 1150 WORK$ = CHR$ (INPUT.FIELD.LEN%) + CHR$ (UNDERSCORE%) & \ MOVE TO #CH.KB%, WORK$ = 2% & 1170 PUT #CH.KB%, RECORD 256%, COUNT 2% & ! Tell 'block mode' KB handler about repaint character & ! and length of field. & 1200 GET #CH.KB% MOVE FROM #CH.KB%, A$ = RECOUNT GOTO 1210 UNLESS ASCII (A$) = 3% IF M11.PROG.LINE% = 11550% OR & M11.PROG.LINE% = 12010% THEN M11.UPDATE.CODE% = CNTRL.C% GOTO 9000 ! Allow ^C at lines 11550 and 12012 in M11ADD or ! M11MOD. PROG.LINE% is stored in COMVAR. M11MOD and M11ADD ! set this variable and test M11.UPDATE.CODE%. This allows a ! user to abort an add or update. ELSE PRINT #CH.KB%, FNPOS$ (1%, 1%) & + ERASE.EOS$ & + "Smart Mailer terminated by ^C" CLOSE #I% FOR I% = 1% TO 12% WORK$ = SYS (CHR$(9%)) END IF ! Get entry from keyboard, it should be terminated with . & ! Handle a control-C character input - close off all files cleanly & ! and then exit and clear the program. & !\ IF ASCII (A$) = 3% THEN C = CTRLC & !\ PRINT #CH.KB%, FNPOS$ (1%, 1%) & ! + ERASE.EOS$ & ! + "Smart Mailer terminated by ^C" & !\ CLOSE #I% FOR I% = 1% TO 12% & !\ WORK$ = SYS (CHR$(9%)) & 1210 IF ASCII (A$) = 10% THEN A$ = "" & \ M11.ALL.DONE% = TRUE% & \ F.END% = TRUE% & \ GO TO 1240 & ! Check for a line feed at the beginning of the field. & 1220 ESC_POS% = POS ( A$, CHR$( 155% ), 1% ) GOTO 1230 IF ESC_POS% = 0% ! Check input string for an character. The program receives ! the escape sequence as CHR$(128%) + + CHR$(155%) ESC_START% = POS (A$, CHR$(128%), 1%) ESCAPE_SEQUENCE$ = SEG$ ( A$, ESC_START%+1%, ESC_POS%-1% ) A$ = SEG$ ( A$, 1%, ESC_START% - 1% ) ! Extract the escape sequence. ! Extract the input string. A null string is returned if ! nothing was entered before the escape. SELECT ESCAPE_SEQUENCE$ CASE "[29~", "29~" A$ = A$ + CR + LF ! Treat DO key as if was typed. CASE "[28~", "28~" A$ = "?" + CR + LF ! Treat HELP key as if user typed "?". CASE "[25~", "25~" A$ = A$ + LF GOTO 1210 ! Treat F13 key as if was typed. CASE ELSE GOTO 1100 ! If no HELP or DO, return to try again. END SELECT 1230 CRPOS% = POS (A$, CHR$(13%) + CHR$(10%), 1%) & \ GO TO 1100 IF CRPOS% = 0% & \ A$ = DEF.VALUE$ IF CRPOS% = 1% & ! If was not the terminator, return to try again. & ! If was the only thing typed, return the default. & ! Other terminators can be ESC and LF. & 1240 A$ = EDIT$ (A$, 140%) ! 140 = 128 + 8 + 4 & \ WORK$ = XLATE (A$, XLATE.STR$) & \ GO TO 1100 IF WORK$ > "" & \ ENT.TEXT$ = A$ & ! Clean out delimiters and leading & trailing spaces. & ! Check for non-printing characters. & ! If present, return to try again. & 1250 CAP.TEXT$ = EDIT$ (ENT.TEXT$, 32%) & \ GO TO 7000 IF CAP.TEXT$ = "END" & ! Go handle "END" if user typed it. & 1265 GO TO 1400 IF ENT.TEXT$ = "?" & \ GO TO 1400 IF ENT.TEXT$ = "" and VALIDATION$ <> "Y" & ! Bypass validations if answer is only a request for help. & ! Bypass validations if user wants field to be empty (except if Y/N). & 1300 !-------------------------------------------------------------------- & ! & ! Validate Answer & ! & !-------------------------------------------------------------------- & & 1305 ENT.TEXT$ = CAP.TEXT$ UNLESS VALIDATION$ = "a" & ! Capitalize the answer unless the user is allowing lower case. & 1310 IF VALIDATION$ = "N" THEN & WORK = VAL (ENT.TEXT$) & \ GO TO 1400 & ! Make sure the entry is a number if that is what is required. & ! If not, 19000 will send us to 8020 where the bell will sound. & ! Then, go redisplay it. & 1315 IF VALIDATION$ = "I" THEN & WORK = VAL% (ENT.TEXT$) & \ IF (WORK < 0) OR ((WORK) <> INT (WORK)) & THEN GO TO 8025 & ELSE GO TO 1400 & ! Make sure the entry is a positive integer if that is what & ! is required. If not, 19000 will send us to 8025 where the & ! bell will sound. Then, go redisplay it. & 1320 IF VALIDATION$ = "D" THEN & DATE.OK% = FN.VALID.DATE% (ENT.TEXT$) & \ on error go to 19000 & \ GO TO 8030 UNLESS DATE.OK% & \ ENT.TEXT$ = VALID.DATE$ & & ! See if FN.VALID.DATE% likes what the user typed. & ! If not, buzz and try again. & ! VALID.DATE$ is a nice clean date. & 1330 IF VALIDATION$ = "Y" THEN & ENT.TEXT$ = "Y" IF ENT.TEXT$ = "YES" & OR ENT.TEXT$ = "YE" & \ ENT.TEXT$ = "N" IF ENT.TEXT$ = "NO" & \ GO TO 8040 UNLESS ENT.TEXT$ = "Y" OR ENT.TEXT$ = "N" & ! If answer is not Y or N, buzz and try again. & 1400 !-------------------------------------------------------------------- & ! & ! Redisplay Answer & ! & !-------------------------------------------------------------------- & & 1420 PRINT #CH.KB%, FNPOS$ (ROW%,COL%) + & ENT.TEXT$ + & SPACE$ (MAX.CHARS% - LEN(ENT.TEXT$)) + & FNPOS$ (ROW%, COL%); & \ GO TO 9000 & ! Now redisplay the entry & clean up underscores. We're done. & & 6999 !-------------------------------------------------------------------- & ! & ! Control characters & ! & !-------------------------------------------------------------------- & & 7000 F.END% = TRUE% & \ PRINT #CH.KB%, FNPOS$(ROW%, COL%) + & "END" + & SPACE$ (MAX.CHARS% - 3%) + & FNPOS$ (ROW%, COL%); & \ ENT.TEXT$ = "" & \ GO TO 9000 & ! Do this if "END" or was typed. & 8000 !******************************************************************** & ! & ! & ! E R R O R M E S S A G E S & ! & ! & !******************************************************************** & 8020 M11.MSG$ = "Entry must be all numbers." & \ GO TO 8090 & ! Not a valid number. & 8025 M11.MSG$ = "Entry must be a positive integer." & \ GO TO 8090 & ! Not a positive integer. & 8030 M11.MSG$ = "Entry must be a valid date." & \ ERR.CODE% = OK% & \ GO TO 8090 & ! Date not in correct format. Reset error code. & 8040 M11.MSG$ = "Entry must be either Y (for yes) or N (for no)." & \ GO TO 8090 & ! Not a valid Y/N answer. & 8090 PRINT #CH.KB%, FNPOS$ (24%, 1%) + ERASE.EOL$ + M11.MSG$ + BEL; & \ GO TO 1100 & ! Beep at user for not typing good stuff. & & 9000 !*************************************************************** & ! & ! & ! E N D O F P R O C E S S I N G & ! & ! & !*************************************************************** & 9010 RESET_ESC$ = SYS( SET_TERM$ + CHR$( 128% ) ) ! SYS call to set terminal to NO ESC SEQ. 9100 ENTERED.TEXT$ = ENT.TEXT$ & \ PRINT #CH.KB%, FNPOS$ (24%, 1%) + ERASE.EOL$; & ! Set the return value, clear away any error messages. & 9900 ERR.SUBNAM$ = "" & \ GO TO 32767 & ! Go to the end of the subprogram. 15000 !******************************************************************** & ! & ! & ! F U N C T I O N S L O C A L T O & ! & ! T H I S S U B P R O G R A M & ! & ! & !******************************************************************** & 15100 !*************************************************************** & ! & ! & ! FNPOS$ (X%, Y%) & ! & ! This function returns a string which when printed to & ! a VT52 or VT61 moves the cursor to row X%, column Y%. & ! The upper left corner is defined as position (1,1). & ! & !-------------------------------------------------------------------- & 15110 DEF FNPOS$ (X%,Y%) IF VT52% THEN FNPOS$ = ESC$ + "Y" + CHR$(31%+X%) + CHR$(31%+Y%) ELSE FNPOS$ = ESC$ + "[" + NUM1$(X%) + ";" + NUM1$(Y%) + "f" END IF ! Function returns escape sequence to position cursor at line X% ! column Y%. END DEF 19000 !*************************************************************** & ! & ! & ! S T A N D A R D E R R O R H A N D L I N G & ! & ! & !*************************************************************** & 19050 RESUME 7000 IF ERR = CNTRL.Z% & ! If user types ^Z, we treat it exactly like 'END'. & 19100 RESUME 8020 IF ERL = 1310 & ! We expected a number but user didn't oblige. & 19150 RESUME 8025 IF ERL = 1315 & ! We expected a positive integer but user didn't oblige. & 19200 RESUME 1170 IF ERL = 1170 AND ERR = 3 & ! Try again if 'account or device in use'. & 19900 ERR.ERL% = ERL & \ ERR.ERR% = ERR & \ ERR.CODE% = FATAL.ERROR% & \ ERR.MSG$ = "Unexpected fatal error" & \ ON ERROR GO BACK & ! Set the traceback variables. & ! Resume at the end of the program. & 32767 SUBEND