home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / PARSE.ASM < prev    next >
Assembly Source File  |  1994-10-31  |  6KB  |  224 lines

  1.     PAGE    66,132
  2. ;******************************** PARSE.LIB ***********************************
  3. ;
  4. ; PARSE_FIRST  - Parse first argument from command line
  5. ; PARSE_NEXT   - Parse next argument from command line
  6. ;
  7. ;------------------------------------------------------------------------------
  8.  
  9. LIBSEG           segment byte public "LIB"
  10.         assume cs:LIBSEG , ds:nothing
  11.  
  12. ;----------------------------------------------------------------------------
  13. .xlist
  14.     include  mac.inc
  15.     include  common.inc
  16. .list
  17. ;----------------------------------------------------------------------------
  18.     extrn    DEC_STR_TO_DWORD:far
  19.     extrn    lib_info:byte
  20. ;----------------------------------------------------------------------------
  21.  
  22. parse_ptr    dw    81h
  23. parameter_length dw    0    ;length of last parameter found
  24.  
  25. comment 
  26. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  PARSE  )
  27. PARSE_FIRST - parse first arguement from command line
  28. ;
  29. ; inputs: es:di = location to store parsed string
  30. ; output: es:di = (unchanged) parsed string ptr
  31. ;          cx = length of parsed string (0=no more parameters available)
  32. ;    bh,dx,ax   are set as specified by the flag value in -bh-
  33. ;          bh = 0 - end of parameters
  34. ;                 1 - single alpha parameter was found of form "\x". The
  35. ;                     "x" character was placed in register -bl-
  36. ;                2 - single numeric parameter was found of form "\n". The
  37. ;                     "n" binary value was placed in register -bl-
  38. ;                3 - compound alpha parameter of form "\x:yyyy" was found.
  39. ;                     register -bl- has "x" character.
  40. ;                 4 - compound numeric parameter of form "\x:nnnn" was found.
  41. ;                     register -bl- has "x" character, dx,ax has value of nnnn
  42. ;                 5 - found alpha string of form "\xxxxx"
  43. ;                 6 - found value of form "\nnnn".  The decimal value of
  44. ;               nnnn was placed in registers dx,ax
  45. ;                 7 - found alpha string of form "xxxx"
  46. ;                 8 - found numeric string of form "nnnn".  The decimal
  47. ;               value of nnnn was placed in registers dx,ax
  48. ;
  49. ;* * * * * * * * * * * * * *
  50. 
  51.     PUBLIC    PARSE_FIRST
  52. PARSE_FIRST    PROC    FAR
  53.     mov    cs:parse_ptr,81h    ;start parse at beginning
  54. PARSE_FIRST    ENDP
  55.  
  56. comment 
  57. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  PARSE  )
  58. PARSE_NEXT - parse next command line parameter
  59. ;
  60. ; inputs:  (see PARSE_FIRST)
  61. ; outputs: (see PARSE_FIRST)
  62. ;* * * * * * * * * * * * * *
  63. 
  64.     PUBLIC    PARSE_NEXT
  65. PARSE_NEXT    PROC    FAR
  66.     apush    si,di,bp,ds,es
  67.     cld
  68.     mov    ds,cs:lib_info.psp_seg
  69.     mov    si,cs:parse_ptr
  70.     mov    cx,0                ;set parameter lenght to zero
  71. ;
  72. ; registers: es:di = callers storage buffer
  73. ;         ds:si = command line parameter ptr
  74. ;        cx = 0
  75. ;
  76. parse_01:
  77.     lodsb                    ;get next parameter
  78.     cmp    al,0dh
  79.     je    parse_no_more            ;jmp if no parameters
  80.         cmp     al,' '
  81.     je    parse_01            ;jmp if leading space (ignore)
  82.     cmp    al,09
  83.     je    parse_01            ;jmp if tab (ignore)
  84. ;
  85. ; the character in -al- is valid, move string to callers buffer.
  86. ;
  87.     push    si
  88.     push    di
  89. parse_02:
  90.     stosb
  91.     inc    cx
  92.     lodsb
  93.         cmp     al,' '
  94.     je    parse_10            ;jmp if end of string found
  95.     cmp    al,0dh
  96.     je    parse_10            ;jmp if end of string found
  97.         cmp     al,'\'                          ;
  98.     je    parse_10            ;jmp if next string found
  99.     cmp    al,09h                ;tab?
  100.     jne    parse_02            ;jmp if string is still valid
  101. ;
  102. ; the next string has now been placed in the callers buffer, next begin decode
  103. ;
  104. parse_10:
  105.     mov    cs:parse_ptr,si
  106.     mov    cs:parameter_length,cx
  107.     mov    byte ptr es:[di],0        ;put zero at end of string
  108.     pop    di
  109.     pop    si
  110.     dec    si                ;move back to string start
  111. ;
  112. ; registers = ds:si - start of parameter
  113. ;
  114.     mov    al,byte ptr [si]        ;get initial char. again
  115.         cmp     al,'\'                          ;check if flag type char.
  116.     je    parse_slash            ;jmp if slash first char
  117. ;
  118. ; this string is either an alpha string or numeric string, determine which
  119. ;
  120.     call    DEC_STR_TO_DWORD
  121.     jc    parse_alpha               ;jmp if alpha found
  122. ;
  123. ; we have a numeric string of form "nnnn'.  The value is in dx,ax
  124. ;
  125.     mov    bh,8
  126.     jmp    parse_exit
  127. ;
  128. ; we have a alpha string of form "xxxx".
  129. ;
  130. parse_alpha:
  131.     mov    bh,7
  132.     jmp    parse_exit
  133. ;
  134. ; we have found an "\" at the beginning of this parameter, decode
  135. ;  ds:si - point at "\"
  136. ;
  137. parse_slash:
  138.         inc     si                      ;move past "\"
  139. ;
  140. ; check if single character after slash
  141. ;
  142.     mov    al,byte ptr [si+1]    ;get second char. of string
  143.         cmp     al,' '
  144.         je      single_char             ;jmp if parsing "\x"
  145.     cmp    al,09
  146.         je      single_char             ;jmp if parsing "\x"
  147.     cmp    al,0dh
  148.         je      single_char             ;jmp if parsing "\x"
  149.         cmp     al,'\'
  150.         je      single_char             ;jmp if parsing "\x"
  151. ;
  152. ; this parameter is of form "\xxxx" or "\x:yyyy"
  153. ;
  154.         cmp     al,':'
  155.         je      flag_plus               ;jmp if parsing "\x:xxxx"
  156. ;
  157. ; this parameter is of form "\xxxx", check if numeric or alpha
  158. ;
  159.     call    DEC_STR_TO_DWORD
  160.         jc     slash_alpha             ;jmp if parsing alpha "\xxxx"
  161. ;
  162. ; this parameter numeric of form "\nnnn".  dx,ax has value of nnnn
  163. ;
  164.     mov    bh,6
  165.     jmp    parse_exit
  166. ;
  167. ; this parameter is alpha of form "\xxxx"
  168. ;
  169. slash_alpha:
  170.     mov    bh,5
  171.     jmp    parse_exit
  172. ;
  173. ; this parameter is of form "\x:xxxx" check if alpha or numeric
  174. ;
  175. flag_plus:
  176.     mov    bl,byte ptr [si]    ;put flag in register -bl-
  177.         add     si,2                    ;move past "x:"
  178.     call    DEC_STR_TO_DWORD
  179.     jc    colin_alpha
  180. ;
  181. ; this parameter is of form "\x:nnnn".  The value nnnn is in dx,ax
  182. ;
  183.     mov    bh,4
  184.     jmp    parse_exit
  185. ;
  186. ; this parameter is of form "\x:yyyy".  The yyyy is an alpha string
  187. ;
  188. colin_alpha:
  189.     mov    bh,3
  190.     jmp    parse_exit
  191. ;
  192. ; we are parsing "\x".  Check if alpha or binary
  193. ;
  194. single_char:
  195.     call    DEC_STR_TO_DWORD
  196.     jc    single_alpha
  197. ;
  198. ; we are parseing "\n"
  199. ;
  200.     mov    bl,al                ;put value in register -bl-
  201.     mov    bh,2
  202.     jmp    parse_exit
  203. ;
  204. ; we are parsing "\x"
  205. ;
  206. single_alpha:
  207.     mov    bl,byte ptr [si]
  208.     mov    bh,1
  209.     jmp    parse_exit
  210.  
  211. parse_no_more:
  212.     mov    bh,0
  213. parse_exit:
  214.     mov    cx,cs:parameter_length
  215.     apop    es,ds,bp,di,si
  216.     retf
  217. PARSE_NEXT    ENDP
  218. ;------------------------------------------------------------------------------
  219.  
  220. LIBSEG    ENDS
  221.     end
  222.