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 / JSAGE / ZSUS / SUBSCRIP / ZSUS1-12.LZH / DATSTP13.LBR / PARSDS.MZC / PARSDS.MAC
Text File  |  1990-10-07  |  7KB  |  241 lines

  1. ; PARSDS.MAC
  2. ;
  3. ; Version 1.3 -- October 8, 1990 -- Gene Pizzetta
  4. ;    Corrected lingering bug that reported invalid date entry when
  5. ;    time spec ended in a colon (no minute) and was followed by
  6. ;    another command line parameter.
  7. ;
  8. ; Version 1.2 -- September 3, 1990 -- Gene Pizzetta
  9. ;    Modified from Carson Wilson's ZSPARSDS.Z80 module from ZSLIB 2.1.
  10. ;    Added ability to use '/' instead of '.' in date specs.  Made
  11. ;    parsing a little more robust in detecting illegal characters in
  12. ;    date spec.  Now finds time spec if preceded by only month and day
  13. ;    without final delimiter ('mm/dd' instead of 'mm/dd/').  Now requires
  14. ;    selection of European ('dd/mm/yy') or American ('mm/dd/yy') date
  15. ;    format via a public configuration byte in an external module.
  16. ;
  17. ; Version 1.1 -- February 2, 1990 -- Carson Wilson
  18. ;    Module ZSPARSDS.Z80 from ZSLIB 2.1.  Code shortened, thanks to
  19. ;    suggestions by Howard Goldstein.
  20. ;
  21. ; Version 1.0 -- January 21, 1990 -- Carson Wilson
  22. ;     Purpose:  Parse command line datespec.
  23.  
  24.     public    parsds
  25.  
  26.                 ; EurDat is an external configuration
  27.     extrn    EurDat        ; ..byte -- non-zero selects dd/mm/yy,
  28.                 ; ..zero selects mm/dd/yy
  29.  
  30.     extrn    isbcdd        ; ZSLIB
  31.  
  32.     extrn    eval10, eval16,isdigit    ; SYSLIB
  33.  
  34.     MACLIB    Z80        ; extended Intel mnemonics
  35. ;
  36. ; PARSDS - Parse command line datespec.
  37. ;
  38. ; Entry:  HL = address of null-terminated datespec (14 characters or less).
  39. ;      DE = address of memory buffer (5 bytes), may be initialized with
  40. ;        default datespec.
  41. ;
  42. ; Exit:      Zero flag set (Z) if memory buffer at DE contains BCD date/time:
  43. ;        A = 0 if no wildcards or illegal characters encountered.
  44. ;        A = '*' (2Ah) if wildcards encountered.
  45. ;        A = character, if illegal character encountered in datespec.
  46. ;      Zero flag reset (NZ) and A = FFh if entry or parsed datespec was 
  47. ;        invalid (out of range).
  48. ;
  49. ; Uses:      AF.
  50. ;
  51. ; Notes:  If EurDat is non-zero, the command line datespec takes the
  52. ;      following forms:
  53. ;        {dd{.mm{.yy{ hh{:mm}}}}}<null>  - real time
  54. ;      or
  55. ;        {dd{.mm{.yy{ +nnnn}}}}<null>    - relative time
  56. ;
  57. ;      If EurDat is zero, the command line datespec takes the
  58. ;      following forms:
  59. ;        {mm{/dd{/yy{ hh{:mm}}}}}<null>  - real time
  60. ;      or
  61. ;        {mm{/dd{/yy{ +nnnn}}}}<null>    - relative time
  62. ;
  63. ;      All items in braces are optional.  Each date or time item may
  64. ;      be two ASCII digits or less.  If no digits are entered, the
  65. ;      pre-initialized entry buffer values are checked for validity and
  66. ;      returned.  For example, if '//yy' or '..yy' are entered, only
  67. ;      the year byte in the entry buffer will be changed.  Wildcards
  68. ;      ("*", "?", or "??") are also allowed.  If wildcards are detected,
  69. ;      they are stored as ASCII "*" (2Ah) and A = 2Ah on return.  Your
  70. ;      application can handle wildcards as you see fit.
  71. ;
  72. PARSDS:    push    b
  73.     push    h
  74.     push    d
  75.  
  76.     mov    b,d
  77.     mov    c,e
  78.     inx    b        ; BC --> storage + 1 (month)
  79.       lda    EurDat
  80.       ora    a
  81.       jrz    Skip1
  82.       inx    b
  83. Skip1:    dcx    h        ; prepare for GetNxt
  84. ;
  85. ; Test month (or day if EurDat)
  86. ;
  87.     call    GetNxt        ; get next datespec character or abort
  88.     cpi    '.'        ; got character, use default month?
  89.     jrz    TestDy        ; (yes)
  90.     cpi    '/'
  91.     jrz    TestDy
  92.     call    TstWld        ; no, test for wild month
  93.     jrz    TstMon        ; (yes)
  94.     call    isdigit        ; digit?
  95.     jnz    ErExit        ; (no)
  96.     call    eval16        ; must be day spec.  SYSLIB evaluate 
  97.                 ; ..ASCII hex to binary & pt. HL to next
  98. TstMon:    stax    b        ; save value or '*'
  99.     mov    a,m        ; get next
  100.     cpi    '.'        ; day spec?
  101.     jrz    TestDy
  102.     cpi    '/'
  103.     jnz    Exit        ; no, done
  104. ;
  105. TestDy:    lda    EurDat
  106.     ora    a
  107.     jrz    Skip2
  108.     dcx    b
  109.     jr    Skip3
  110. Skip2:    inx    b        ; point to day
  111. Skip3:    call    GetNxt        ; get/abort 
  112.     cpi    '.'        ; got character, use default day?
  113.     jrz    TestYr        ; (yes)
  114.     cpi    '/'
  115.     jrz    TestYr
  116.     call    TstWld        ; no, wild day?    
  117.     jrz    TestD1        ; (yes)
  118.     call    isdigit        ; digit?
  119.     jnz    ErExit        ; (no)
  120.     call    eval16        ; evaluate day
  121. TestD1:    stax    b        ; save value or '*'
  122.     mov    a,m
  123.     cpi    ' '
  124.     jrz    TestH0
  125.     cpi    '.'        ; got year?
  126.     jrz    TestYr
  127.     cpi    '/'
  128.     jrnz    Exit        ; (no, check time)
  129. ;
  130. TestYr:    dcx    b        ; point to year
  131.     lda    EurDat
  132.     ora    a
  133.     jrnz    Skip4
  134.     dcx    b
  135. Skip4:    call    GetNxt        ; get/abort
  136.     cpi    ' '        ; use default year?
  137.     jrz    TestHr        ; (yes)
  138.     call    TstWld        ; no, wild year?
  139.     jrz    TestY1        ; (yes)
  140.     call    isdigit        ; digit?
  141.     jrnz    ErExit        ; (no)
  142.     call    eval16        ; evaluate year
  143. TestY1:    stax    b        ; save value or '*'
  144.     mov    a,m
  145.     cpi    ' '        ; got hour?
  146.     jrnz    Exit        ; (no, done)
  147. ;
  148. TestHr:    inx    b        ; point to hour
  149.     inx    b
  150. TestH0:    inx    b
  151. TestH1:    call    GetNxt        ; get next command character
  152.     cpi    ' '        ; skip extra spaces
  153.     jrz    TestH1
  154.     cpi    '+'        ; relative time?
  155.     jrnz    TestH2        ; (no)
  156.     inx    h        ; point to relative time spec
  157.     call    eval10        ; get +nnnn value to DE
  158.     setb    7,d        ; flag as relative
  159.     mov    a,d
  160.     stax    b        ; store value
  161.     mov    a,e
  162.     inx    b
  163.     stax    b        ; store value
  164.     jr    Exit        ; done with parse
  165. ;
  166. TestH2:    cpi    ':'        ; use default hour?
  167.     jrz    TestMn        ; (yes)
  168.     call    TstWld        ; no, wild hour?
  169.     jrz    TestH3        ; (yes)
  170.     call    isdigit        ; digit?
  171.     jrnz    Exit        ; (no, we must be through)
  172.     call    eval16        ; get hour
  173. TestH3:    stax    b        ; save value or '*'
  174.     mov    a,m
  175.     cpi    ':'        ; got minute?
  176.     jrnz    Exit        ; (no, done)
  177. ;
  178. TestMn:    inx    b        ; point to minute
  179.     call    GetNxt        ; minute or wildcard
  180.     cpi    ' '
  181.     jrz    Exit
  182.     call    TstWld        ; wild minute?
  183.     jrz    TestM1        ; (yes)
  184.     call    isdigit        ; digit?
  185.     jrnz    ErExit        ; (no)
  186.     call    eval16        ; evaluate minute
  187. TestM1:    stax    b        ; save value or '*'
  188. ;
  189. Exit:    pop    d        ; point to stored date
  190.     xchg            ; check value at HL
  191.     call    isbcdd
  192.     xchg            ; restore DE
  193.     pop    h
  194.     pop    b
  195.     ret            ; return (Z) if date OK.
  196. ;
  197. ErExit:    pop    d
  198.     pop    h
  199.     pop    b
  200.     ret
  201. ;
  202. ; Subroutines . . .
  203. ;
  204. ; GetNxt -- get next datespec character 
  205. ; Entry:  HL = address of next datespec position - 1
  206. ; Exit:   If null terminator found, quit
  207. ;      Else: HL incremented
  208. ;        A = character at HL
  209. ;
  210. GetNxt:    inx    h        ; next input
  211.     mov    a,m
  212.     ora    a        ; done?
  213.     rnz            ; (no)
  214.     pop    d        ; yes, remove return address
  215.     jr    Exit        ; ..and exit parse
  216. ;
  217. ; TstWld -- test for wildcard character ("*" or "?") at HL
  218. ; Entry:  A = character at HL
  219. ;      BC = address of next datespec storage
  220. ; Exit:      Zero flag set (Z) if wildcard character found
  221. ;        A = "*"
  222. ;        HL = address of next non-wild character
  223. ;      Zero flag reset (NZ) if not wildcard character
  224. ; Uses:      A, HL, if wildcard character found; otherwise none.
  225. ;
  226. TstWld:    cpi    '*'
  227.     jrz    TestW1
  228.     cpi    '?'
  229.     rnz            ; (not wildcard)
  230. TestW1:    call    EatWld        ; skip consecutive wildcards
  231.     xra    a        ; set (Z) for wildcard found
  232.     mvi    a,'*'
  233.     ret
  234. ;
  235. EatWld:    inx    h        ; point HL to next non-matching character
  236.     cmp    m
  237.     jrz    EatWld
  238.     ret
  239. ;
  240.     end
  241.