; Library: ZSLIB ; Version: 2.1 ; Module: ZSPARSDS ; Version: 1.1 ; Author: Carson Wilson ; Date: February 2, 1990 ; Changes: Code shortened, thanks to suggestions by Howard Goldstein. ; Version: 1.0 ; Author: Carson Wilson ; Date: January 21, 1990 ; Purpose: Parse command line datespec. PUBLIC PARSDS EXTRN ISBCDD ; ZSLIB EXTRN EVAL10, EVAL16 ; SYSLIB ; ; PARSDS - Parse command line datespec. ; ; Entry: - points to null-terminated datespec (14 characters ; or less). ; - points to memory area (5 bytes). ; Exit: - (Z) if memory at DE initialized to BCD date/time: ; A = '*' (2Ah) if wildcards used. ; A = 00h if no wildcards used. ; - (NZ) and A = 0FFh if entry or parsed datespec was ; invalid (out of range). ; Uses: . ; Notes: The command line datespec takes the following forms: ; ; [dd[.mm[.yy[ hh[:mm]]]]] - real time ; OR ; [dd[.mm[.yy[ +nnnn]]]] - relative time ; ; All items in square brackets are optional. Each date or time ; item may be two ASCII digits or less. If no digits are ; entered, the entry buffer values are checked for validity and ; returned. Wildcards ("*", "?", or "??") are also allowed. If ; wildcards are detected, they are stored as ASCII "*" (2A hex) ; and A = 2A hex on return. ; PARSDS: push bc push hl push de ld b,d ld c,e inc bc ; BC --> storage + 3 inc bc inc bc dec hl ; Prep. for GETNDC ; Test day call GETNDC ; Get next datespec char. or abort cp '.' ; Got character. Use default day? jr z,TESTMON ; Yes call TESTWILD ; No. Test for wild day ;jr z,TESTDY1 ; Wildcard found and stored, A = next call nz,EVAL16 ; No, must be day spec. SYSLIB evaluate ; ..ASCII hex to binary & pt. HL to next ld (bc),a ; Save value or '*' TESTDY1: ld a,(hl) ; Get next cp '.' ; Month spec? jr nz,EXIT ; No, done TESTMON: call GETNDC ; Get/abort cp '.' ; Got char. Use default month? jr z,TESTYR ; Yes call TESTWILD ; No. Wild month? ;jr z,TESTMON1 ; Yes call nz,EVAL16 ; No, evaluate month ld (bc),a ; Save value or '*' ;TESTMON1: ld a,(hl) cp '.' ; Got year? jr nz,EXIT ; No, done TESTYR: call GETNDC ; Get/abort cp ' ' ; Use default year? jr z,TESTHR ; Yes call TESTWILD ; No. Wild year? ;jr z,TESTYR1 ; Yes call nz,EVAL16 ; No, eval year ld (bc),a ; Save value or '*' ;TESTYR1: ld a,(hl) cp ' ' ; Got hour? jr nz,EXIT ; No, done TESTHR: inc bc inc bc inc bc ; Point to hour storage TESTHR1:call GETNDC1 ; Get next command char. cp ' ' ; Skip extra spaces jr z,TESTHR1 cp '+' ; Relative time? jr nz,TESTHR2 ; No inc hl ; Point to rel. time spec. call EVAL10 ; Get +nnnn value to DE set 7,d ; Flag as relative ld a,d ld (bc),a ; Store value ld a,e inc bc ld (bc),a ; Store value jr EXIT ; Done with parse TESTHR2: cp ':' ; Use default hour? jr z,TESTMIN ; Yes call TESTWILD ; No. Wild hour? ;jr z,TESTHR3 ; Yes. call nz,EVAL16 ; No, get hour ld (bc),a ; Save value or '*' ;TESTHR3: ld a,(hl) cp ':' ; Got minute? jr nz,EXIT ; No, done TESTMIN: inc bc call GETNDC1 ; Minute or wildcard call TESTWILD ; Wild minute? ;jr z,EXIT ; Yes call nz,EVAL16 ; No, evaluate minute ld (bc),a ; Save value or '*' EXIT: pop de ; Point to stored date ex de,hl ; Check value at HL call ISBCDD ex de,hl ; Restore DE pop hl pop bc ret ; Return (Z) if date OK. ; ------------------------------------------------------- ; ; Subroutines ; ; ; GETNDC - GET Next Datespec Char. ; ; Entry: HL points to next datespec position - 1. ; Exit: If null terminator found, quit. ; Else: ; BC decremented. ; HL incremented. ; A = character at HL. ; GETNDC: dec bc ; Next storage (date) GETNDC1:inc hl ; Next input ld a,(hl) or a ; Done? ret nz ; No pop de ; Yes. Remove return address jr EXIT ; ..and exit parse. ; ; TESTWILD - Test for wildcard character ("*" or "?") at (HL) ; ; Entry: A = (HL) ; BC --> next datespec storage ; Exit: (Z) - A = "*" ; - (HL) = next non-wild char. ; - Uses: A, HL. ; (NZ) - All registers preserved ; TESTWILD: cp '*' jr z,TESTW1 cp '?' ret nz ; Not wildcard. TESTW1: call GOBBLE ; Skip consecutive wildcards xor a ; Set (Z) for wildcard found ld a,'*' ret GOBBLE: ; Point HL to next non-matching char. inc hl cp (hl) jr z,GOBBLE ret end ; End ZSPARSDS.Z80