home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TASMSWAN.ZIP / PARAMS.ASM < prev    next >
Assembly Source File  |  1989-07-16  |  3KB  |  133 lines

  1. %TITLE  "Parse DOS command-line parameters"
  2.  
  3.     IDEAL
  4.     DOSSEG
  5.     MODEL    small
  6.  
  7. ;----- Equates
  8. TailLen        EQU    0080h
  9. CommandTail    EQU    0081h
  10.  
  11.     DATASEG
  12.  
  13. numParams    dw    ?
  14. params        db       128 DUP (?)
  15.  
  16.  
  17.     CODESEG
  18.  
  19.     PUBLIC    ParamCount, GetParams, GetOneParam
  20.  
  21. %NEWPAGE
  22. ;--------------------------------------------------------------------
  23. ;  Separators - private routine to check for blanks, tabs, and CRs
  24. ;--------------------------------------------------------------------
  25. ;    Input:
  26. ;        ds:si addresses character to check
  27. ;    Output: zf = 1 : (je) character is a blank, tab or cr
  28. ;               zf = 0 : (jne) character is not a separator
  29. ;    Registers:
  30. ;        al
  31. ;-------------------------------------------------------------------
  32. PROC    Separators
  33.     mov    al,[si]
  34.     cmp    al,020h
  35.     je    @@10
  36.     cmp    al,009h
  37.     je    @@10
  38.     cmp    al,00Dh
  39. @@10:
  40.     ret
  41. ENDP    Separators
  42. %NEWPAGE
  43. ;----------------------------------------------------------------------
  44. ;  ParamCount - returns number of parameters
  45. ;----------------------------------------------------------------------
  46. ;    Input:  none
  47. :    Output:
  48. ;        dx = number of command-line parameters
  49. ;                 NOTE: when calling GetOneParam, cx should be less than
  50. ;            the value returned in dx by ParamCount
  51. ;    Registers:  dx
  52. ;----------------------------------------------------------------------
  53. PROC    ParamCount
  54.     mov    dx,[numParams]
  55.     ret
  56. ENDP    ParamCount
  57. %NEWPAGE
  58. ;----------------------------------------------------------------------
  59. ; GetParams - get DOS command-line parameters
  60. ;----------------------------------------------------------------------
  61. ;    Input:  ds = Program Segment Prefix (PSP)
  62. ;        es = program's data segment
  63. ;            NOTE: until you change it,
  64. ;                  ds addresses the PSP when all *.EXE programs begin
  65. :    Output: global params filled with ASCIIZ strings
  66. ;        [numParams] = number of parameters
  67. ;               ds = program's data segment (es not changed)
  68. ;    Registers:   al,bx,dx,si,di,ds
  69. ;----------------------------------------------------------------------
  70. PROC    GetParams
  71.         xor      ch,ch
  72.         mov      cl,[ds:TailLen]
  73.         inc      cx
  74.         mov      si,CommandTail
  75.         mov      di, offset params
  76. @@10:
  77.     call    Separators
  78.     jne    @@20
  79.     inc    si
  80.     loop    @@10
  81. @@20:
  82.     push    cx
  83.     jcxz    @@30
  84.     cld
  85.     rep    movsb
  86. @@30:
  87.     push    es
  88.     pop    ds
  89.     pop    cx
  90.     xor    bx,bx
  91.     jcxz    @@60
  92.     mov    si, offset params
  93. @@40:
  94.     call    Separators
  95.     jne    @@50
  96.     mov    [byte ptr si],0
  97.     inc     bx
  98. @@50:
  99.     inc    si
  100.     loop     @@40
  101. @@60:
  102.     mov    [numParams], bx
  103.     ret
  104. ENDP    GetParams
  105.  
  106. %NEWPAGE
  107. ;----------------------------------------------------------------------
  108. ;  GetOneParam  - get one parameter address by number
  109. ;----------------------------------------------------------------------
  110. ;    Input:  cx = parameter number (0 = first)
  111. ;            NOTE: cx should always be less than the value
  112. ;                returned in dx by ParamCount
  113. :    Output:
  114. ;        di = offset of ASCIIZ string for this parameter
  115. ;    Registers:  al,cx,di
  116. ;----------------------------------------------------------------------
  117. PROC    GetOneParam
  118.     xor    al,al
  119.     mov    di, offset params
  120.     jcxz    @@99
  121.     cmp    cx, [numParams]
  122.     jae    @@99
  123.     cld
  124. @@10:
  125.     scasb
  126.     jnz    @@10
  127.     loop    @@10
  128. @@99:
  129.     ret
  130. ENDP    GetOneParam
  131.  
  132.     END
  133.