home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / OKTIMDAT.ZIP / ARGC.ASM next >
Encoding:
Assembly Source File  |  1988-10-29  |  2.1 KB  |  50 lines

  1. Title   ArgC.ASM --- Return Command Line Argument Count
  2. Comment ~
  3.         Treats blanks and tabs as whitespace
  4.            and carriage return as terminator.
  5.  
  6.         Call With:     ES:BX = Command Line
  7.  
  8.         Returns:          AX = Argument Count=>1
  9.                        Other Registers Preserved
  10.         ~
  11. cr        equ  0Dh            ;ASCII Carriage Return
  12. lf        equ  0Ah            ;ASCII Line Feed
  13. tab       equ  09h            ;ASCII Tab
  14. blank     equ  20h            ;ASCII Space
  15. quote     equ  22h            ;ASCII Quote
  16.           .MODEL    SMALL
  17.           .CODE
  18.      PUBLIC    ArgC
  19. ArgC Proc
  20.           Push BX             ;Preserve Pointer
  21.           Push CX             ;and Counter
  22.           Mov  AX,1           ;Insure => 1 Argument
  23. ArgC1:    Mov  CX,-1          ;Set Outside Argument Flag
  24. ArgC2:    Inc  BX             ;If Next Command Line Character
  25.           Cmp  Byte Ptr ES:[BX],quote
  26.           Jz   ArgC3          ;Is Quote Then Parse Quotation
  27.           Cmp  Byte Ptr ES:[BX],cr ;Else If Carriage Return
  28.           Jz   ArgC5          ;Then Command Line Is Done
  29.           Cmp  Byte Ptr ES:[BX],blank
  30.           Jz   ArgC1          ;Else If Space or Tab
  31.           Cmp  Byte Ptr ES:[BX],tab
  32.           Jz   ArgC1          ;Then Outside Argument
  33.           Jcxz ArgC2          ;Else If Inside Continue Parsing
  34.           Inc  AX             ;Else Count Start of New Argument
  35.           Not  CX             ;Clear Flag to Inside Argument
  36.           Jmp  Short ArgC2    ;Begin Parsing Un-Quoted Argument
  37. ArgC3:    Inc  AX             ;Count Quoted String as Argument
  38. ArgC4:    Inc  BX             ;If Next Command Line Character
  39.           Cmp  Byte Ptr ES:[BX],cr ;Is a Carriage Return
  40.           Jz   ArgC5          ;Then Command Line Is Done
  41.           Cmp  Byte Ptr ES:[BX],quote
  42.           Jnz  ArgC4          ;Else Continue Until Ending Quote
  43.           Jmp  Short ArgC1    ;Then Resume Outside Parsing
  44.  
  45. ArgC5:    Pop  CX             ;Restore Counter
  46.           Pop  BX             ;and Pointer and
  47.           Ret                 ;Return Argument Count [AX]
  48. ArgC Endp
  49.           END
  50.