home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / oparscmd.asm < prev    next >
Assembly Source File  |  1988-08-28  |  3KB  |  104 lines

  1.  
  2. ;    FILENAME: OPARSCMD.ASM
  3. ;    Copyright (c) 1988 by Borland International, Inc.
  4. ;
  5. ;    Description: This module implements the routine ParseCmd. ParseCmd 
  6. ;    parses the command line.
  7. ;    ASSEMBLY INSTRUCTIONS:  To assemble this module use the following  
  8. ;    TASM command line.     
  9. ;  
  10. ;        TASM oparscmd
  11.  
  12. include globals.inc
  13.  
  14. _TEXT   segment
  15.  
  16.     ParseCmd proc
  17.  
  18.     ;    Input 
  19.     ;        si - address of start of command line
  20.     ;        OptTab - Option Table
  21.     ;        Options - designates user set options
  22.     ;    Output
  23.     ;        command line processed
  24.     ;    Registers modified
  25.     ;        si, bx, ax, di
  26.  
  27.     push    ds              ;save current value of ds
  28.     push    ds              ;set es to point to current
  29.     pop     es              ;data segment
  30.  
  31.     mov     ax, PSP         ;set ds to point to the PSP
  32.     mov     ds, ax
  33.  
  34.     mov     si, 80h         ;command tail
  35.  
  36.     lea     di, CMDBUF      ;get the address of the local buffer
  37.     mov     cx, BUFLEN      ;get the size of the local buffer
  38.     rep     movsb           ;get a copy of the command-line arguments
  39.     pop     ds              ;reset ds to the data segment
  40.  
  41.     lea     si, CMDBUF      ;load si with the address of CMDBUF for the
  42.                             ;lodsb instruction
  43.     lodsb                   ;get number of bytes
  44.     cmp     al, 0           ;see if command tail exists
  45.     jnz     hastail
  46.     mov     al, '?'         ;force help screen
  47.     jmp     SHORT   parcmd1a
  48.  
  49. hastail:
  50.  
  51.     mov     bx, si
  52.     sub     ah, ah
  53.     add     bx, ax          ;BX points to end
  54.  
  55. parcmd1:
  56.     cmp     bx, si          ;check if done
  57.     je      parcmd5
  58.     lodsb                   ;get character
  59.  
  60.  
  61. parcmd1a:
  62.  
  63.     mov     mess1+16, al    ;put in message in case of error
  64.     lea     di, OptTab      ;start of table
  65.  
  66. parcmd2:
  67.     cmp     BYTE PTR [di], 0    ;check if end of table
  68.     je      parcmd6
  69.     cmp     al, [di]        ;check if option matches
  70.     je      parcmd3
  71.     add     di, 5           ;skip to next entry
  72.     jmp     parcmd2
  73.  
  74.     ;--- found matching option
  75.  
  76. parcmd3:
  77.     mov     ax, [di+1]      ;load command word
  78.     or      ax, ax          ;check if branch location
  79.     jnz     parcmd4
  80.     mov     ax, [di+3]      ;load option flag
  81.     xor     Options, ax     ;flip bits
  82.     jmp     parcmd1
  83.  
  84. parcmd4:
  85.     call    ax              ;branch to special routine
  86.     jmp     parcmd1
  87.  
  88.     ;--- finished
  89.  
  90. parcmd5:
  91.     ret
  92.  
  93.     ;--- bad option
  94.  
  95. parcmd6:
  96.     mov     al, 0           ;error number
  97.     call    ErrorExit       ;call error routine
  98.     ParseCmd endp
  99.  
  100. _TEXT    ends
  101.  
  102. end
  103.