GETWORD: PROC (PROMPT_STRING, KEYWORD_LIST) RETURNS (CHAR (*) VARYING); /* FUNCTION PROMPTS FOR A RESPONSE UNTIL USER REPLIES WITH ONE OF A SUPPLIED LIST OF KEYWORDS (OR AN UNAMBIGUOUS ABBREVIATION). THE MATCHING KEYWORD IS THEN RETURNED. AUTHOR: MIKE RHOADS DATE: 3/5/82 */ %INCLUDE UPPER; %INCLUDE TESTWORD; %REPLACE NONDELIMITERS BY 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; DCL (PROMPT_STRING, KEYWORD_LIST) CHAR (*) VARYING; DCL DELIMITER CHAR (1); DCL POS FIXED BIN (31); DCL ANSWER CHAR (80) VARYING; DCL VALID_RESPONSE BIT (1); DCL (YES INIT ('1'B), NO INIT ('0'B)) BIT (1); DCL P PTR, KEYWORD CHAR (LENGTH(KEYWORD_LIST)) VARYING BASED (P); ALLOCATE KEYWORD; VALID_RESPONSE = NO; DO WHILE (^ VALID_RESPONSE); PUT SKIP; GET EDIT (ANSWER) (A(80)) OPTIONS (PROMPT (PROMPT_STRING)); IF ANSWER = '' THEN DO; /** NULL ANSWER VALID IF AND ONLY IF KEYWORD_LIST CONTAINS TWO CONSECUTIVE DELIMITERS **/ POS = VERIFY (UPPER(KEYWORD_LIST), NONDELIMITERS); IF 0 < POS & POS < LENGTH (KEYWORD_LIST) THEN DO; DELIMITER = SUBSTR (KEYWORD_LIST, POS, 1); IF INDEX (KEYWORD_LIST, DELIMITER || DELIMITER) > 0 THEN DO; KEYWORD = ''; VALID_RESPONSE = YES; END; END; END; ELSE DO; KEYWORD = TESTWORD (ANSWER, KEYWORD_LIST); IF LENGTH (KEYWORD) > 0 THEN VALID_RESPONSE = YES; END; IF ^ VALID_RESPONSE THEN DO; PUT EDIT (COPY(BYTE(7),3),'Invalid answer--acceptable keywords are:', KEYWORD_LIST) (SKIP,2 A,SKIP,A); END; END; RETURN (KEYWORD); END GETWORD;