; TITLE "PARSER - Syslib 4.0" NAME ('PARSER') ;================================================================ ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;---------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from Z3PRS1.Z80 Ver 1.1 by Richard Conn ; Date : 7 Jul 89 ; Version : 1.3 ; Module : Z3PRS1B ; Abstract: This module contains the routine PARSER which parses ; a Command Line returning various elements from an element ; from an element in a Command Line. ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC PARSER ; From SYSLIB Get.. EXT CAPSTR ; From Z3LIB Get.. EXT @INITF, @SCAN1 ; Definitions TFCB EQU 5CH ; FCB Buffer TFCB2 EQU 6CH ; 2nd FCB Buffer TBUFF EQU 80H ; Temporary Buffer CMDSEP EQU ';' ; Multiple Command Separator char .Z80 CSEG ;=============================================================== ; NAME - PARSER ; Entry: HL - Points to Null-terminated command line ; A = 0 if scan for DIR form before DU ; A = 1 if scan for DU form before DIR ; Exit : HL - Points to next command in Mult Comd Line ; DE - Points to FCB containing command name (header.COM) ; A = 0, Zero Flag Set (Z) if Ok ; A = Number of "?", Zero Reset (NZ) if Ambig FN ; Uses : AF,DE,HL ; Special Requirements: None ;=============================================================== PARSER: PUSH BC ; Save BC CALL PARSE ; Do the work LD HL,(TAILSV) ; Get ptr to command tail LD DE,TBUFF ; Copy tail into tbuff LD B,0 ; Set char count PUSH DE ; Save ptr to tbuff INC DE ; Pt to first char position SVTAIL: LD A,(HL) ; Get next char CALL ATEOL ; End of line? JR Z,SVT1 LD (DE),A ; Save char INC HL ; Pt to next INC DE INC B ; Increment char count JR SVTAIL SVT1: XOR A ; Store ending 0 LD (DE),A POP HL ; Get ptr to TBUFF LD (HL),B ; Set char count POP BC ; Restore BC LD HL,(NXTCHR) ; Pt to next char in HL LD DE,FCBDN ; Pt to FCB in DE ERRFLG EQU $+1 LD A,00 ; Get error flag in A (Inline modified) OR A ; Set Zero flag RET ;..... ; Main Routine ; Save DU/DIR order flag and capitalize input line PARSE: LD (DUFIRST),A ; 0 = DIR first, 0FFH = DU first CALL CAPSTR ; Capitalize line LD DE,FCBDN ; Point to Command FCB CALL @INITF ; ..and initialize it LD DE,TFCB ; Point to Token FCB CALL @INITF ; ..and initialize TFCB and TFCB2 LD DE,FCBDN ; Place Command Name into command FCB CALL SCANV ; ..Extract it LD (ERRFLG),A ; Save Error Flag (# of "?"s) EX DE,HL ; Preserve pointer in DE LD HL,FCBFT ; Point to FCB File Type field LD (HL),'C' ; ..and force type to "COM" INC HL LD (HL),'O' INC HL LD (HL),'M' EX DE,HL LD (TAILSV),HL ; Save ptr to Command Tail for later PUSH HL ; ..copy to TBUFF. Find End of Comnd Line CTAIL: LD A,(HL) ; Get char CALL ATEOL ; at EOL? INC HL ; Pt to next JR NZ,CTAIL ; ..loop if Not DEC HL ; Else back up to delimiter LD (NXTCHR),HL ; Save ptr to next line POP HL ; ..and get ptr to Command Tail CALL SKSP ; Skip over spaces RET Z ; ..done if EOL or end of command LD DE,TFCB ; Store First Token in TFCB CALL SCANV ; ..Extract it CALL SKSP ; Skip over spaces RET Z ; ..done if EOL or end of command LD DE,TFCB2 ; Stora Second Token in FCB ;..fall thru to extract it DUFIRST EQU $+1 SCANV: LD A,00 ; Get DU/DIR Flag (inline modified) CALL @SCAN1 ; ..and parse a token into the FCB ; Skip to space, char after =, or EOL. Quit with HL --> Next char in line PUSH AF ; Save # of Question Marks SCAN3: LD A,(HL) ; Get the current char CP CMDSEP ; Is it end of Command Line? JR Z,SCAN3X ; ..jump if so CP ' '+1 ; Is it Less than a space (including EOL)? JR C,SCAN3X ; ..jump if so 'cause Done INC HL ; Else Point to next CP '=' ; Equate? JR NZ,SCAN3 ; ..loop if Not SCAN3X: POP AF ; Restore # of Question Marks RET ; ..and return ;..... ; Skip over spaces pted to by HL ; On Return, Zero flag set means we hit EOL or CMDSEP SKSP: LD A,(HL) ; Get next char CP ' ' ; Is it a Space? RET NZ ; ..return if Not INC HL ; Else advance to next char JR SKSP ; ..and loop ;..... ; Set Zero Flag if End-Of-Line or Multiple Command Separator ATEOL: CP CMDSEP ; Is it the Mult Comnd Sep? RET Z OR A ; Is it EOL? RET ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!!!!!!!!!!! D A T A A R E A !!!!!!!!!!!!!!! ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DSEG ; Put unitialized data in DSEG NXTCHR: DEFS 2 ; Ptr to next char in command sequence TAILSV: DEFS 2 ; Ptr to command tail FCBDN: DEFS 9 ; FCB - Drive Byte, Name Field (8 bytes) FCBFT: DEFS 27 ; - Type Field (3 bytes), Data fields END