⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rxdoscmd.asm

📁 dos source
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        ;  Usage:                                                       ;
        ;   ds:si  command line beginning with a count                  ;
        ;          (this fct does not rely on CR at end of buffer)      ;
        ;   ss:di  argument array                                       ;
        ;          (returns a pointer into the command line at the      ;
        ;           start of each argument.  Multiple switches are      ;
        ;           detected by testing the get command switch char).   ;
        ;   cx     max number of arguments allowed                      ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   zr     if no arguments passed                               ;
        ;...............................................................;

_BuildArgArray:

        Entry
        ddef _commandLine, ds, si
        ddef __argarray, ss, di                         ; (maxArgArray) arguments
        def _args, cx

        setES ss

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  scan argument
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_buildArgArray_06:
        mov ch, ' '                                     ; pretend previous char is a space

_buildArgArray_08:
        lodsb                                           ; get character
        or al, al                                       ; end of line ?
        jz _buildArgArray_36                            ; yes, end of arg -->

        cmp al, ' '                                     ; space ?
        jz _buildArgArray_14                            ; yes, arg separator -->
        cmp al, byte ptr [ _SwitchChar ]                ; switch character ?
        jz _buildArgArray_18                            ; yes, record argument -->

        call _CmndParse_SeparatorCheck                  ; parse break ?
        jz _buildArgArray_18                            ; yes -->

        cmp ch, ' '                                     ; previous also a space ?
        jz _buildArgArray_18                            ; yes, continue scanning -->

_buildArgArray_14:
        mov ch, al                                      ; save previous character
        jmp _buildArgArray_08                           ; continue scanning -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  record argument
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_buildArgArray_18:
        mov ch, al                                      ; save possible string terminator

        push ax
        mov ax, si
        dec ax
        stosw                                           ; store argument pointer
        pop ax
        dec word ptr [ _args ][ bp ]                    ; more args allowed ?
        jle _buildArgArray_36                           ; no -->

        cmp ch, singleQuote
        jz _buildArgArray_30
        cmp ch, doubleQuote
        jz _buildArgArray_30

        cmp ch, '\'                                     ; path info ?
        jz _buildArgArray_24                            ; not a word breaker -->
        cmp ch, byte ptr [ _SwitchChar ]                ; switch character ?
        jz _buildArgArray_24                            ; yes, keep as part of word -->
        call _CmndParse_SeparatorCheck                  ; parse break ?
        jnz _buildArgArray_24                           ; if not a separator -->

        mov ch, ' '                                     ; indicate argument break

_buildArgArray_24:
        jmp _buildArgArray_08                           ; continue scanning -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  set inside string mode
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_buildArgArray_30:
        lodsb                                           ; get character
        or al, al                                       ; end of line ?
        jz _buildArgArray_36                            ; yes, end of arg -->
        cmp al, ch                                      ; string terminator ?
        jnz _buildArgArray_30                           ; no, continue saving -->
        jmp _buildArgArray_06

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_buildArgArray_36:
        mov word ptr ss:[ di ], 0000                    ; add null table terminator
        mov word ptr ss:[ di+2 ], 0000                  ; two nulls is complete end

        mov di, word ptr [ __argarray. _pointer ][ bp ]
        cmp word ptr [ di ], 0000                       ; args passed ?
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Split Args                                                   ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  This routine detects and corrects concatenated args.         ;
        ;                                                               ;
        ;  Some args are passed in the arg array as a single arg but    ;
        ;  in fact they need to be split up, as in 'cd..'               ;
        ;                                                               ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   di     pointer to args array                                ;
        ;...............................................................;

SplitArgs:

        Entry
        def __argarray, di                              ; pointer to args

        mov si, word ptr [ di ]                         ; get arg
        or si, si                                       ; args passed ?
        jz _SplitArgs_36                                ; none -->

_SplitArgs_08:
        lodsb
        or al, al                                       ; null ?
        jz _SplitArgs_36                                ; end of search -->
        cmp al, ' '+1                                   ; space or other break ?
        jc _SplitArgs_36                                ; end of search -->
        cmp al, '='                                     ; if = in arg, 
        jz _SplitArgs_36                                ; no need to continue ->
        cmp al, '\'                                     ; dir break ?
        jz _SplitArgs_12                                ; yes, insert arg -->
        cmp al, '.'                                     ; period break ?
        jnz _SplitArgs_08                               ; continue if none of the above -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  Insert Arg
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_SplitArgs_12:
        mov ax, si                                      ; set arg
        dec ax

_SplitArgs_16:
        inc di
        inc di
        xchg ax, word ptr [ di ]                        ; push arg
        or ax, ax                                       ; end of table ?
        jnz _SplitArgs_16                               ; not yet -->

        cmp word ptr [ di+2 ], 0000                     ; 2nd null follows ?
        jnz _SplitArgs_16                               ; no, keep inserting -->

        mov word ptr [ di+2 ], ax                       ; make sure we put two NULLS
        mov word ptr [ di+4 ], ax                       ; 

_SplitArgs_36:
        getarg di, __argarray                           ; pointer to args
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Command Parse Separator Check                                ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   al     character from parser                                ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   zr     is a separator character                             ;
        ;...............................................................;

_CmndParse_SeparatorCheck:

        push si
        mov si, offset _CmndParse_Separators 

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  lookup
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_CmndParse_SepCheck_08:
        cmp byte ptr cs:[ si ], 0
        jz _CmndParse_SepCheck_12
        cmp al, byte ptr cs:[ si ]
        jz _CmndParse_SepCheck_16

        inc si
        jmp _CmndParse_SepCheck_08

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  exit
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_CmndParse_SepCheck_12:
        or al, al                                       ; non-zero if end of table 

_CmndParse_SepCheck_16:
        pop si
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Scan and Assign Redirection                                  ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  argument array                                       ;
        ;   ss:bx  pointer to Execution Control Block                   ;
        ;...............................................................;

_assignRedirectedDevices:

        Entry
        def __argarray, di                              ; argument array
        def __contargarray, di                          ; continue argument array
        def __execCtrlBlock, bx                         ; execution control block

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  scan remainder of command line for pipe, stdin and stdout args
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_assignRedirect_06:
        getarg di, __contargarray                       ; continue argument array

_assignRedirect_08:
        mov si, word ptr [ di ]
        or si, si                                       ; end of args ?
        ifz _assignRedirect_36                          ; yes -->

        mov ax, word ptr [ si ]                         ; get arg assignment
        cmp ax, '>>'                                    ; append to stdout ?
        ifz _assignRedirect_AppendStdOut                ; yes -->
        cmp al, '>'                                     ; stdout ?
        jz _assignRedirect_StdOut                       ; yes -->
        cmp al, '<'                                     ; stdin ?
        jz _assignRedirect_StdIn                        ; yes -->
        cmp al, '|'                                     ; pipe ?
        jz _assignRedirect_Pipe                         ; yes -->

        inc di
        inc di                                          ; advance over command index
        jmp _assignRedirect_08                          ; go to next -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  stdout
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_assignRedirect_StdOut:
        mov byte ptr [ si ], 00                         ; set a null at terminator
        storarg __contargarray, di                      ; continue argument array
        call deleteArg                                  ; kill '>' arg

        mov bx, word ptr [ __execCtrlBlock ][ bp ]      ; execution control block
        lea dx, offset [ exCtrlStdOutFileName ][ bx ]   ; offset to filename
        call _asgnGetFileName                           ; arg to [dx]

        xor cx, cx
        Int21 CreateFile                                ; if not found, create 
        ifc _assignRedirect_Error                       ; just display error -->

        push ax
        mov bx, ax
        mov cx, STDOUT
        call _assignGetCurrHandle
        getarg di, __execCtrlBlock
        mov word ptr [ exCtrlStdOutHandle ][ di ], ax   ; save old handle
        Int21 ForceFileHandle                           ; redirect stdout

        pop bx                                          ; this close frees file handle after 
        Int21 CloseFile                                 ; force replicate handle
        jmp _assignRedirect_06

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  stdin
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_assignRedirect_StdIn:
        mov byte ptr [ si ], 00                         ; set a null at terminator
        storarg __contargarray, di                      ; continue argument array
        call deleteArg                                  ; kill '<' arg

        mov bx, word ptr [ __execCtrlBlock ][ bp ]      ; execution control block
        lea dx, offset [ exCtrlStdInFileName ][ bx ]    ; offset to filename
        call _asgnGetFileName                           ; arg to [dx]

        Int21 OpenFile, OPEN_ACCESS_READONLY            ; try to open file
        ifc _assignRedirect_Error                       ; just display error -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -