.TITLE TPAUTIL - LIB$TPARSE utility routines .IDENT /1.00/ ;++ ; Title: ; TPAUTIL - LIB$TPARSE utility routines ; ; Facility: ; Utility command parsing. ; ; Abstract: ; This is a collection of routines used when doing ; parsing with LIB$TPARSE. Except for TPA_INIT, they ; are all called as action routines with the TPARSE ; parameter block as a parameter. ; ; The routines are: ; TPA_INIT - Initialize common data structures ; TPA_FIRST_INPUT - Get command line input ; TPA_RETURN_STATUS - Return special status as success ; TPA_PARAM_INPUT - Get input to supply a parameter ; TPA_PARSE_ERR - Signal an error with location in line ; TPA_UNTIL_BLANK - Match single character except blank ; TPA_SET_BLANKS - Make blanks and tab significant ; TPA_CLR_BLANKS - Make blanks and tabs invisible ; ; Environment: ; Native Mode. No other considerations. ; ; Author: ; Gary L. Grebus, Creation date: 18-Mar-1982 ; Battelle Columbus Labs ; ; Modified by: ; ;-- .PAGE .SBTTL Symbol definitions ; System symbols $TPADEF ; Define LIB$TPARSE symbols $STSDEF ; Define status value symbols ; Local symbols TPA_C_BUFSZ = 255 ; Size of scratch input buffer .PAGE .SBTTL Local macros .MACRO CODE FACILITY=TPA,ALIGN=LONG .PSECT FACILITY'_CODE RD,NOWRT,EXE,SHR,ALIGN .ENDM CODE .MACRO RODATA FACILITY=TPA,ALIGN=LONG .PSECT FACILITY'_RODATA RD,NOWRT,NOEXE,SHR,ALIGN .ENDM RODATA .MACRO RWDATA FACILITY=TPA,ALIGN=LONG .PSECT FACILITY'_RWDATA RD,WRT,NOEXE,NOSHR,ALIGN .ENDM RWDATA .PAGE .SBTTL Read/write data RWDATA ; Global data structures used by TPA utility routines TPA_GL_TPARSE_BLK: .BLKL 1 ; Address of user supplied TPARSE ; block TPA_GL_CMD_BUFFER: .BLKL 1 ; Address of descriptor for user ; supplied buffer. TPA_TEMP_LEN: .BLKW 1 ; Scratch location for string lengths TPA_TEMP_BUFFER: STRING TPA_C_BUFSZ ; Descriptor and space for holding ; a string TPA_W_CMD_LEN: .BLKW 1 ; Total length of command in user ; buffer .PAGE .SBTTL TPA_INIT - Initialize common data structures ;++ ; Functional Description: ; Routine to initialize data structures used by this package. Must ; be called before LIB$TPARSE. Note the user is responsible for ; initializing the static parts of the TPARSE block. ; ; Calling Sequence: ; CALLS #2, TPA_INIT ; ; Input Parameters: ; 4(AP) - Address of user's TPARSE block ; 8(AP) - Address of descriptor for user's buffer ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: NONE ; ; Completion Status: ; Always returns SS$_NORMAL ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_INIT,^M<> MOVL 4(AP),R0 ; Get address of TPARSE block MOVL R0,TPA_GL_TPARSE_BLK ; and save it CLRQ TPA$L_STRINGCNT(R0) ; Clear command descriptor in block MOVL 8(AP),- TPA_GL_CMD_BUFFER ; Save address of buffer descriptor MOVZWL #SS$_NORMAL,R0 ; Return success RET .PAGE .SBTTL TPA_FIRST_INPUT - Get command line input ;++ ; Functional Description: ; This routine is used to obtain the command line input ; for the program. It is called as an action routine from a ; dummy state. The dummy state serves only to cause the input ; to be read. This routine always returns a failure status ; so as to cause other transitions to be examined. Note that ; we might not succeed in actually returning a command line. ; The state table must make allowances for this case. The ; TPARSE block parameter field is the address of the descriptor ; of a prompt string. ; ; Calling Sequence: ; Called by LIB$TPARSE ; ; Input Parameters: ; AP - Address of TPARSE block ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: ; LIB$GET_FOREIGN ; ; Completion Status: ; Always returns a failure status. If LIB$GET_FOREIGN returns ; an error status, the error is signaled. ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_FIRST_INPUT,^M ; Register usage: ; R0-R2 - Scratch ; Get command line MOVL TPA_GL_CMD_BUFFER,R2 ; Get address of buffer desc CALL LIB$GET_FOREIGN - R2,@TPA$L_PARAM(AP),TPA_W_CMD_LEN ; Get the command IF THEN IF THEN SIGNAL - CODE1=R0 ; Signal any errors ENDIF ELSE ; Point TPARSE block at string MOVL DSC$A_POINTER(R2),- TPA$L_STRINGPTR(AP) ; Set address MOVZWL TPA_W_CMD_LEN,- TPA$L_STRINGCNT(AP) ; and length CALL STR$UPCASE - TPA$L_STRINGCNT(AP),- TPA$L_STRINGCNT(AP) ; Upcase the string CLRL R0 ; Return failure ENDIF RET .PAGE .SBTTL TPA_RETURN_STATUS - Return special status as success ;++ ; Functional Description: ; This routine is intended to be called as an action routine. It ; is to provide an exit from LIB$TPARSE by which some status value ; can be returned. The parameter field of the TPARSE block contains ; the status to be returned. We convert that status to an informational ; so the transition is accepted. The state transition is assumed ; to branch to TPA$_EXIT so this status is returned. ; ; Calling Sequence: ; Called by LIB$TPARSE ; ; Input Parameters: ; AP - Address of TPARSE block ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: NONE ; ; Completion Status: ; Specified status converted to a severity of informational. ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_RETURN_STATUS,^M<> MOVL TPA$L_PARAM(AP),R0 ; Get status INSV #STS$K_INFO,- #STS$V_SEVERITY,- #STS$S_SEVERITY,R0 ; Convert severity RET .PAGE .SBTTL TPA_PARAM_INPUT - Read input for a parameter ;++ ; Functional Description: ; This routine is called as an action routine to allow the user ; to enter an additional parameter during the parsing of the ; command line. For example, if the end of the command line is ; reached with some required parameters not specified, a ; transition on TPA$_EOS can call this action routine. This routine ; attempts to read more user input using LIB$GET_INPUT. If more ; input is obtained, we return a success. Otherwise, we return a ; failure status. The new input is inserted into the current ; command line at the current position in the parse. The new ; input is terminated with a blank to provide a delimiter. ; The parameter field of the TPARSE block contains the address of ; a descriptor for the prompt string. ; ; Calling Sequence: ; Called by LIB$TPARSE ; ; Input Parameters: ; AP - Address of TPARSE parameter block ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: ; LIB$GET_INPUT ; ; Completion Status: ; Returns SS$_NORMAL if more input successfully read. Returns error ; if no input obtained or if command buffer overflows. Signals any ; real errors from LIB$GET_INPUT or if buffer overflow. ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_PARAM_INPUT,^M ; Register usage: ; R0-R5 - Scratch. ; Get input line into scratch buffer. CALL LIB$GET_INPUT - TPA_TEMP_BUFFER,- @TPA$L_PARAM(AP),- TPA_TEMP_LEN ; Get line IF THEN IF THEN SIGNAL - CODE1=R0 ; Signal any real errors ENDIF RET ; Return failure ENDIF IF THEN CLRL R0 ; If nothing read, return failure RET ENDIF CALL STR$UPCASE - TPA_TEMP_BUFFER,- TPA_TEMP_BUFFER ; Upcase the input ; Insert the text we read into the user's buffer ADDW3 TPA_W_CMD_LEN,- TPA_TEMP_LEN,R0 ; Compute new length for command INCW R0 ; plus one for a blank MOVL TPA_GL_CMD_BUFFER,R1 ; Address of command buffer desc IF THEN ; Not enough space in buffer for entire command. Return error. SIGNAL - CODE1=R0 ; Signal error ELSE ; Shift remainder of string down and insert new text, followed by a blank MOVZWL TPA_TEMP_LEN,R1 ; Get length of new text INCL R1 ; plus one for blank ADDL3 TPA$L_STRINGPTR(AP),R1,R2 ; Compute destination of old text MOVC3 TPA$L_STRINGCNT(AP),- @TPA$L_STRINGPTR(AP),- (R2) ; Shift existing data MOVC3 TPA_TEMP_LEN,- @TPA_TEMP_BUFFER+DSC$A_POINTER,- @TPA$L_STRINGPTR(AP) ; Move in new data MOVB #^A/ /,(R3) ; Followed by blank. R3 set by MOVC3 MOVZWL TPA_TEMP_LEN,R1 ; Get length of text added INCL R1 ; plus blank ADDL2 R1,TPA$L_STRINGCNT(AP) ; Update descriptor in TPARSE block ADDW2 R1,TPA_W_CMD_LEN ; and in our records MOVZWL #SS$_NORMAL,R0 ; Return success ENDIF RET .PAGE .SBTTL TPA_PARSE_ERR - Signal error with location in line ;++ ; Functional Description: ; This routine is called as an action routine to issue a simple ; error message. The error condition is passed in the TPARSE ; block parameter field. The error is signalled along with the ; text of the remainder of the command line. The error message ; should end with the FAO string !/!_\!AS\ to print the remainder ; of the command line. ; ; Calling Sequence: ; Called by LIB$TPARSE ; ; Input Parameters: ; AP - Address of TPARSE block ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: NONE ; ; Completion Status: ; SS$_NORMAL is always returned. ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_PARSE_ERR,^M<> SIGNAL - CODE1=TPA$L_PARAM(AP),- F1= ; Signal the error MOVZWL #SS$_NORMAL,R0 ; Return success RET .PAGE .SBTTL TPA_UNTIL_BLANK - Match any single character except blank ;++ ; Functional Description: ; This action routine is intended to be called from a match of ; TPA$_ANY. It will return success (thus matching) any character ; except blank and /. It is useful for creating a substate which will ; match a string up to the next blank or qualifier (such as a filespec). ; Also included here are two action routines for turning off and on the ; recognition of blanks by LIB$TPARSE ; ; Calling Sequence: ; Called by LIB$TPARSE ; ; Input Parameters: ; AP - Address of TPARSE block ; ; Output Parameters: NONE ; ; Implicit Inputs: NONE ; ; Implicit Outputs: NONE ; ; Procedures called: NONE ; ; Completion Status: ; Returns unaltered R0 or zero. ; ; Side Effects: NONE ; ;-- CODE .ENTRY TPA_UNTIL_BLANK,^M<> IF OR - THEN CLRL R0 ; Stop matching on blank or slash ENDIF RET .ENTRY TPA_SET_BLANKS,^M<> ; Make blanks and tabs significant to LIB$TPARSE BISL2 #TPA$M_BLANKS,- TPA$L_OPTIONS(AP) ; Set blanks bit RET ; and return success .ENTRY TPA_CLR_BLANKS,^M<> ; Make blanks and tab invisible to LIB$TPARSE BICL2 #TPA$M_BLANKS,- TPA$L_OPTIONS(AP) ; Clear blanks bit RET ; and return success .END