home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / SOURCE / ALL / CW / COMMAND.ASM < prev    next >
Assembly Source File  |  1993-07-06  |  4KB  |  172 lines

  1. ;==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
  2. ReadCommand    proc    near
  3. ;
  4. ;Read the command line tail for parameters.
  5. ;
  6. ;supports / or - or + as switch/option settings. Options and names may be in
  7. ;any order, text can be tagged onto options, names must be in correct sequence
  8. ;for current program.
  9. ;
  10. ;Each character ( 33 to 127) has an entry in OptionTable & OptionTable+128.
  11. ;
  12. ;The first entry is a byte, and is 0 for OFF & none-zero for ON.
  13. ;The second entry is a pointer to any additional text specified, 0 means none.
  14. ;Entries 0-32 are reserved for text not preceded by - or + or /. These are
  15. ;intended to be file names, but neadn't be.
  16. ;All text entries are 0 terminated.
  17. ;
  18. ;To test flag:- cmp OptionTable+'?',0    ;where ? is upper case character.
  19. ;To test text:- cmp w[offset OptionTable+128+('?'*2)],0
  20. ;To get text:-  mov bx,w[offset OptionTable+128+('?'*2)]
  21. ;
  22. ;To get first file name,  mov bx,w[offset OptionTable+128+0]
  23. ;       second            mov bx,w[offset OptionTable+128+2]
  24. ;
  25. ;The text gatherer will also accept : or = after the switch, eg,
  26. ;
  27. ;    Chop-Rob /aEJW1 test.pak
  28. ;    or
  29. ;    Chop-Rob /a:EJW1 test.pak
  30. ;    or
  31. ;    Chop-Rob /a=EJW1 test.pak
  32. ;
  33. ;Switches & file names may be in any position. Duplicate switch settings with
  34. ;text will store multiple text, but only the last will be addressable.
  35. ;
  36.     push    es
  37.     sys    Info        ;Get system selectors.
  38.     mov    es,bx
  39.     mov    edi,offset OptionText
  40.     mov    OptionPointer,edi
  41.     mov    esi,80h        ;/
  42.     xor    ecx,ecx
  43.     mov    cl,es:[esi]        ;get tail length
  44.     cmp    cl,2
  45.     jc    @@9        ;not long enough!
  46.     mov    edi,esi
  47.     add    edi,ecx
  48.     mov    es:b[edi+1],0    ;terminate the tail.
  49.     inc    si        ;skip length.
  50.     ;
  51. @@0:    mov    al,es:[esi]        ;need to skip leading spaces.
  52.     inc    si        ;/
  53.     or    al,al        ;/
  54.     jz    @@9        ;/
  55.     cmp    al,' '        ;/
  56.     jz    @@0        ;/
  57.     dec    si        ;/
  58.     ;
  59. @@1:    cmp    es:b[esi],'/'    ;option switch?
  60.     jz    @@Option        ;/
  61.     cmp    es:b[esi],'-'    ;/
  62.     jz    @@Option        ;/
  63.     cmp    es:b[esi],'+'    ;/
  64.     jz    @@Option        ;/
  65.     ;
  66. @@2:    xor    ebx,ebx        ;/
  67.     mov    bl,OptionCounter    ;Get file entry number.
  68.     inc    OptionCounter    ;/
  69.     shl    ebx,2        ;/
  70.     add    ebx,offset OptionTable+128 ;/
  71.     mov    edi,OptionPointer    ;Current free space pointer.
  72.     mov    [ebx],edi        ;update table entry.
  73.     ;
  74.     xor    cl,cl
  75. @@3:    cmp    es:b[esi],0        ;end of name?
  76.     jz    @@4        ;/
  77.     cmp    es:b[esi],' '    ;/
  78.     jz    @@4        ;/
  79.     mov    al,es:[esi]        ;Copy this character.
  80.     mov    [edi],al        ;/
  81.     inc    esi        ;/
  82.     inc    edi        ;/
  83.     mov    cl,1        ;flag SOMETHING found.
  84.     jmp    @@3        ;keep fetching them.
  85.     ;
  86. @@4:    mov    b[edi],0        ;Terminate the name.
  87.     inc    edi        ;/
  88.     mov    OptionPointer,edi    ;Update table pointer.
  89.     ;
  90.     or    cl,cl        ;Make sure we found something.
  91.     jnz    @@0        ;Go look for more info.
  92.     dec    OptionPointer
  93.     dec    OptionCounter    ;move pointer/counter back.
  94.     xor    ebx,ebx
  95.     mov    bl,OptionCounter    ;Get file entry number.
  96.     shl    ebx,2        ;/
  97.     add    ebx,offset OptionTable+128 ;/
  98.     mov    w[ebx],0        ;reset table entry.
  99.     jmp    @@0
  100.     ;
  101. @@Option:    mov    ah,es:[esi]        ;Get switch character.
  102.     inc    esi
  103. @@5:    cmp    es:b[esi],0        ;check for end of line.
  104.     jz    @@9        ;/
  105.     cmp    es:b[esi],' '    ;skip spaces.
  106.     jnz    @@6        ;/
  107.     inc    esi        ;/
  108.     jmp    @@5        ;/
  109.     ;
  110. @@6:    mov    al,es:[esi]        ;get the switched character.
  111.     and    al,127
  112.     inc    esi
  113.     cmp    al,61h        ; 'a'
  114.     jb    @@12
  115.     cmp    al,7Ah        ; 'z'
  116.     ja    @@12
  117.     and    al,5Fh        ;convert to upper case.
  118. @@12:    xor    ebx,ebx
  119.     mov    bl,al
  120.     add    ebx,offset OptionTable    ;Index into the table.
  121.     cmp    ah,'-'
  122.     jnz    @@7
  123.     xor    ah,ah        ;Convert '-' to zero.
  124. @@7:    mov    [ebx],ah        ;Set flag accordingly.
  125.     ;
  126.     cmp    es:b[esi],' '    ;check for assosiated text.
  127.     jz    @@0
  128.     cmp    es:b[esi],0
  129.     jz    @@9
  130.     cmp    es:b[esi],'='
  131.     jz    @@900
  132.     cmp    es:b[esi],':'    ;allow colon as seperator.
  133.     jnz    @@8
  134. @@900:    inc    esi        ;skip colon.
  135.     ;
  136. @@8:    xor    ebx,ebx
  137.     mov    bl,al        ;Get the option number again.
  138.     shl    ebx,2        ; &
  139.     add    ebx,offset OptionTable+128 ;index into the table.
  140.     mov    edi,OptionPointer    ;current position in the table.
  141.     mov    [ebx],edi        ;store pointer in the table.
  142.     ;
  143. @@10:    cmp    es:b[esi],0        ;end of line?
  144.     jz    @@9
  145.     cmp    es:b[esi],' '    ;end of text?
  146.     jz    @@11
  147.     mov    al,es:[esi]
  148.     mov    [edi],al
  149.     inc    esi
  150.     inc    edi
  151.     jmp    @@10
  152.     ;
  153. @@11:    mov    b[edi],0        ;terminate string.
  154.     inc    edi
  155.     mov    OptionPointer,edi    ;store new text pointer.
  156.     jmp    @@0        ;scan some more text.
  157. @@9:    mov    al,OptionCounter
  158.     xor    ah,ah
  159.     or    ax,ax        ;set flags for file names.
  160.     mov    ebx,d[OptionTable+128]    ;point to first file name.
  161.     pop    es
  162.     ret
  163. ;
  164. OptionCounter    db 0
  165. OptionTable    db 128 dup (0)
  166.     dd 128 dup (0)
  167. OptionPointer    dd ?
  168. OptionText    db 256 dup (0)
  169. ReadCommand    endp
  170.  
  171.  
  172.