home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / PACKET / RLI120.ARK / PARSE.MAC < prev    next >
Text File  |  1986-08-12  |  5KB  |  279 lines

  1. ; PARSE.MAC - 5/12/86 - Command line parser.
  2.  
  3.     .z80
  4.     maclib    TNC.LIB
  5.  
  6.     entry        parse,dofcb,getcmd,ckname
  7.     entry        fcb,fcb1,fcb2,fcb3,opt1,opt2
  8.     entry        fcb1r,fcb2r,fcb3r
  9.     entry        flds,f1l,f2l,f3l,f4l,f5l,f6l,f7l
  10.     entry        f1st,f2st,f3st,f4st,f5st,f6st,f7st
  11.  
  12.     external    getdat,cmd,cmdlen,cmdtyp,ucase,@fill
  13.     external    ascitb,c.file
  14.  
  15.     asciictl
  16.     tncdefs
  17.  
  18.     dseg
  19. ; File control blocks
  20. fcb:    ds    fcbsize
  21. fcb1:    ds    fcbsize
  22. fcb1r    equ    fcb1+33
  23. fcb2:    ds    fcbsize
  24. fcb2r    equ    fcb2+33
  25. fcb3:    ds    fcbsize
  26. fcb3r    equ    fcb3+33
  27. flds:    ds    1        ; # of fields found
  28. ; Starting addresses of fields in cmd
  29. f1st:    ds    2
  30. f2st:    ds    2
  31. f3st:    ds    2
  32. f4st:    ds    2
  33. f5st:    ds    2
  34. f6st:    ds    2
  35. f7st:    ds    2
  36. ; Length of fields in cmd
  37. f1l:    ds    1
  38. f2l:    ds    1
  39. f3l:    ds    1
  40. f4l:    ds    1
  41. f5l:    ds    1
  42. f6l:    ds    1
  43. f7l:    ds    1
  44. ; Options - the first 2 chars in the first field of cmd.
  45. opt1:    ds    1
  46. opt2:    ds    1
  47.  
  48.     cseg
  49.  
  50. ; Check the name in the file control block at (HL).
  51. ; Return zero set if not legal file name.
  52.  
  53. ckname:    inc    hl        ; Point to first char of file name
  54.     ld    c,11        ; Length of file + extension
  55.     ld    d,0
  56. cknamb:    ld    e,(hl)
  57.     push    hl
  58.     ld    hl,ascitb
  59.     add    hl,de
  60.     ld    a,(hl)
  61.     pop    hl
  62.     and    c.file
  63.     ret    z        ; No good
  64.     inc    hl
  65.     dec    c
  66.     jr    nz,cknamb
  67.     retnz            ; Name is ok
  68.  
  69.     dseg
  70. tfcb:    ds    2
  71. start:    ds    2
  72. len:    ds    1
  73. fst:    ds    2
  74. fl:    ds    1
  75.  
  76.     cseg
  77. parse:    xor    a
  78.     ld    (flds),a        ; Count fields found
  79.     movb    len,cmdlen
  80.     lxim    start,cmd
  81.  
  82.     call    gtfld
  83.     movw    f1st,fst
  84.     movb    f1l,fl
  85.     ex    de,hl
  86.     ld    hl,fcb1
  87.     call    dofcb
  88.  
  89.     call    gtfld
  90.     movw    f2st,fst
  91.     movb    f2l,fl
  92.     ex    de,hl
  93.     ld    hl,fcb2
  94.     call    dofcb
  95.  
  96.     call    gtfld
  97.     movw    f3st,fst
  98.     movb    f3l,fl
  99.     ex    de,hl
  100.     ld    hl,fcb3
  101.     call    dofcb
  102.  
  103.     call    gtfld
  104.     movw    f4st,fst
  105.     movb    f4l,fl
  106.  
  107.     call    gtfld
  108.     movw    f5st,fst
  109.     movb    f5l,fl
  110.  
  111.     call    gtfld
  112.     movw    f6st,fst
  113.     movb    f6l,fl
  114.  
  115.     call    gtfld
  116.     movw    f7st,fst
  117.     movb    f7l,fl
  118.     ret
  119.  
  120. ; Eat leading blanks.
  121.  
  122. eat:    ld    a,(len)
  123.     or    a
  124.     ret    z
  125.     ld    hl,(start)
  126.     ld    a,(hl)
  127.     cp    ' '
  128.     jr    z,eata
  129.     cp    tab
  130.     ret    nz
  131. eata:    inc    hl
  132.     ld    (start),hl
  133.     ld    hl,len
  134.     dec    (hl)
  135.     jr    eat
  136.  
  137. ; Get the next field.
  138.  
  139. gtfld:    lxim    fst,0        ; Assume no field
  140.     mvim    fl,0
  141.     call    eat        ; Eat any leading blanks
  142.     ret    z        ; No more chars to parse.
  143.     ld    hl,flds
  144.     inc    (hl)        ; Count the field
  145.     movw    fst,start    ; First char in field
  146.     ld    c,0        ; Count chars in field
  147.     ld    a,(len)        ; Chars left in cmd
  148.     ld    b,a
  149. gtflda:    ld    a,(hl)        ; Char
  150.     cp    ' '        ; Blank?
  151.     jr    z,gtfldb    ; Yes, end of field
  152.     cp    tab        ; Tab?
  153.     jr    z,gtfldb    ; Yes, end of field
  154.     inc    hl
  155.     inc    c
  156.     dec    b
  157.     jr    nz,gtflda    ; Keep counting
  158. gtfldb:    ld    a,c
  159.     ld    (fl),a        ; Field length
  160.     ld    a,b
  161.     ld    (len),a        ; Chars remaining in cmd
  162.     ld    (start),hl    ; Next char in cmd
  163.     ret
  164.  
  165. ; Parse next text lump in cmd into an fcb.
  166. ; Input: tfcb has address of fcb.
  167. ;        fst has address of field start
  168. ;        fl has number of characters in field.
  169.  
  170. dofcb:    ld    (tfcb),hl    ; Save address of fcb
  171.     ld    (fst),de    ; Save text location
  172.     ld    (fl),a        ; Save text length
  173.     call    inifcb        ; Initialize the fcb
  174.     ld    a,(fl)
  175.     or    a        ; Empty field?
  176.     ret    z        ; Yes
  177.     ld    b,a        ; (B) = chars remaining in field
  178.     ld    de,(fst)    ; First char in field
  179.     ld    hl,(tfcb)    ; (HL) point to fcb
  180.     inc    hl        ; Point to first char of file
  181.     cp    1        ; One char?
  182.     jr    z,fname        ; Yes, must be file name
  183.     inc    de        ; Point to 2nd char in cmd
  184.     ld    a,(de)
  185.     dec    de        ; Point to 1st char in cmd
  186.     cp    ':'        ; 2nd char is : ?
  187.     jr    nz,fname    ; No, must be file name
  188.     ld    a,(de)        ; Get drive
  189.     call    ucase        ; Uppercase it
  190.     inc    de        ; Point to :
  191.     inc    de        ; Point to 1st char file
  192.     sub    'A'-1
  193.     dec    hl
  194.     ld    (hl),a        ; Drive # to fcb
  195.     inc    hl
  196.     dec    b
  197.     dec    b
  198.  
  199. ; Transfer file name from cmd to fcb.
  200.  
  201. fname:    ld    c,8        ; 8 chars in file name
  202. fnamea:    ld    a,b
  203.     or    a
  204.     jr    z,done
  205.     dec    b
  206.     ld    a,(de)
  207.     call    ucase
  208.     inc    de
  209.     cp    '.'
  210.     jr    z,fext
  211.     dec    c
  212.     jp    m,fnamea
  213.     ld    (hl),a
  214.     inc    hl
  215.     jr    fnamea
  216.  
  217. ; Transfer file type from cmd to fcb.
  218.  
  219. fext:    ld    hl,(tfcb)
  220.     push    bc
  221.     ld    bc,9
  222.     add    hl,bc
  223.     pop    bc
  224.     ld    c,3
  225. fexta:    ld    a,b
  226.     or    a
  227.     jr    z,done
  228.     dec    b
  229.     ld    a,(de)
  230.     call    ucase
  231.     inc    de
  232.     dec    c
  233.     jp    m,fexta
  234.     ld    (hl),a
  235.     inc    hl
  236.     jr    fexta
  237.  
  238. done:    ld    hl,(tfcb)
  239.     inc    hl
  240.     ld    a,(hl)
  241.     cp    '*'
  242.     jr    nz,ckext
  243.     ld    c,8
  244. ckfila:    ld    (hl),'?'
  245.     inc    hl
  246.     dec    c
  247.     jr    nz,ckfila
  248. ckext:    ld    hl,(tfcb)
  249.     ld    bc,9
  250.     add    hl,bc
  251.     ld    a,(hl)
  252.     cp    '*'
  253.     ret    nz
  254.     ld    c,3
  255. ckexta:    ld    (hl),'?'
  256.     inc    hl
  257.     dec    c
  258.     jr    nz,ckexta
  259.     ret
  260.  
  261. ; Initialize fcb at (tfcb) with (zero, 11 blanks, 24 zeros).
  262.  
  263. inifcb:    ld    hl,(tfcb)
  264.     ld    (hl),0
  265.     inc    hl
  266.     fill    ,11,' '
  267.     fill    ,24,0
  268.     ret
  269.  
  270. ; Get a line from the current console, parse into 5 fields.
  271.  
  272. getcmd:    call    getdat
  273.     call    parse
  274.     movb    opt1,fcb1+1
  275.     movb    opt2,fcb1+2
  276.     ld    a,(cmdtyp)
  277.     ret
  278.     end
  279.