; PARSE.MAC - 5/12/86 - Command line parser. .z80 maclib TNC.LIB entry parse,dofcb,getcmd,ckname entry fcb,fcb1,fcb2,fcb3,opt1,opt2 entry fcb1r,fcb2r,fcb3r entry flds,f1l,f2l,f3l,f4l,f5l,f6l,f7l entry f1st,f2st,f3st,f4st,f5st,f6st,f7st external getdat,cmd,cmdlen,cmdtyp,ucase,@fill external ascitb,c.file asciictl tncdefs dseg ; File control blocks fcb: ds fcbsize fcb1: ds fcbsize fcb1r equ fcb1+33 fcb2: ds fcbsize fcb2r equ fcb2+33 fcb3: ds fcbsize fcb3r equ fcb3+33 flds: ds 1 ; # of fields found ; Starting addresses of fields in cmd f1st: ds 2 f2st: ds 2 f3st: ds 2 f4st: ds 2 f5st: ds 2 f6st: ds 2 f7st: ds 2 ; Length of fields in cmd f1l: ds 1 f2l: ds 1 f3l: ds 1 f4l: ds 1 f5l: ds 1 f6l: ds 1 f7l: ds 1 ; Options - the first 2 chars in the first field of cmd. opt1: ds 1 opt2: ds 1 cseg ; Check the name in the file control block at (HL). ; Return zero set if not legal file name. ckname: inc hl ; Point to first char of file name ld c,11 ; Length of file + extension ld d,0 cknamb: ld e,(hl) push hl ld hl,ascitb add hl,de ld a,(hl) pop hl and c.file ret z ; No good inc hl dec c jr nz,cknamb retnz ; Name is ok dseg tfcb: ds 2 start: ds 2 len: ds 1 fst: ds 2 fl: ds 1 cseg parse: xor a ld (flds),a ; Count fields found movb len,cmdlen lxim start,cmd call gtfld movw f1st,fst movb f1l,fl ex de,hl ld hl,fcb1 call dofcb call gtfld movw f2st,fst movb f2l,fl ex de,hl ld hl,fcb2 call dofcb call gtfld movw f3st,fst movb f3l,fl ex de,hl ld hl,fcb3 call dofcb call gtfld movw f4st,fst movb f4l,fl call gtfld movw f5st,fst movb f5l,fl call gtfld movw f6st,fst movb f6l,fl call gtfld movw f7st,fst movb f7l,fl ret ; Eat leading blanks. eat: ld a,(len) or a ret z ld hl,(start) ld a,(hl) cp ' ' jr z,eata cp tab ret nz eata: inc hl ld (start),hl ld hl,len dec (hl) jr eat ; Get the next field. gtfld: lxim fst,0 ; Assume no field mvim fl,0 call eat ; Eat any leading blanks ret z ; No more chars to parse. ld hl,flds inc (hl) ; Count the field movw fst,start ; First char in field ld c,0 ; Count chars in field ld a,(len) ; Chars left in cmd ld b,a gtflda: ld a,(hl) ; Char cp ' ' ; Blank? jr z,gtfldb ; Yes, end of field cp tab ; Tab? jr z,gtfldb ; Yes, end of field inc hl inc c dec b jr nz,gtflda ; Keep counting gtfldb: ld a,c ld (fl),a ; Field length ld a,b ld (len),a ; Chars remaining in cmd ld (start),hl ; Next char in cmd ret ; Parse next text lump in cmd into an fcb. ; Input: tfcb has address of fcb. ; fst has address of field start ; fl has number of characters in field. dofcb: ld (tfcb),hl ; Save address of fcb ld (fst),de ; Save text location ld (fl),a ; Save text length call inifcb ; Initialize the fcb ld a,(fl) or a ; Empty field? ret z ; Yes ld b,a ; (B) = chars remaining in field ld de,(fst) ; First char in field ld hl,(tfcb) ; (HL) point to fcb inc hl ; Point to first char of file cp 1 ; One char? jr z,fname ; Yes, must be file name inc de ; Point to 2nd char in cmd ld a,(de) dec de ; Point to 1st char in cmd cp ':' ; 2nd char is : ? jr nz,fname ; No, must be file name ld a,(de) ; Get drive call ucase ; Uppercase it inc de ; Point to : inc de ; Point to 1st char file sub 'A'-1 dec hl ld (hl),a ; Drive # to fcb inc hl dec b dec b ; Transfer file name from cmd to fcb. fname: ld c,8 ; 8 chars in file name fnamea: ld a,b or a jr z,done dec b ld a,(de) call ucase inc de cp '.' jr z,fext dec c jp m,fnamea ld (hl),a inc hl jr fnamea ; Transfer file type from cmd to fcb. fext: ld hl,(tfcb) push bc ld bc,9 add hl,bc pop bc ld c,3 fexta: ld a,b or a jr z,done dec b ld a,(de) call ucase inc de dec c jp m,fexta ld (hl),a inc hl jr fexta done: ld hl,(tfcb) inc hl ld a,(hl) cp '*' jr nz,ckext ld c,8 ckfila: ld (hl),'?' inc hl dec c jr nz,ckfila ckext: ld hl,(tfcb) ld bc,9 add hl,bc ld a,(hl) cp '*' ret nz ld c,3 ckexta: ld (hl),'?' inc hl dec c jr nz,ckexta ret ; Initialize fcb at (tfcb) with (zero, 11 blanks, 24 zeros). inifcb: ld hl,(tfcb) ld (hl),0 inc hl fill ,11,' ' fill ,24,0 ret ; Get a line from the current console, parse into 5 fields. getcmd: call getdat call parse movb opt1,fcb1+1 movb opt2,fcb1+2 ld a,(cmdtyp) ret end