Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 519 → Rev 520

/svarcom/trunk/redir.c
111,18 → 111,29
mov dx, [openflag] /* action if file exists (0x11=open, 0x12=truncate)*/
mov si, myptr /* ASCIIZ filename */
int 0x21 /* AX=handle on success (CF clear), otherwise dos err */
mov [handle], ax /* save the file handler */
jnc DUPSTDOUT
mov [errcode], ax
mov handle, ax /* save the file handler */
jnc JMPEOF
mov errcode, ax
jmp DONE
 
JMPEOF:
cmp openflag, word ptr 0x11
jne DUPSTDOUT
/* jump to the end of the file (required for >> redirections) */
mov ax, 0x4202 /* jump to position EOF - CX:DX in handle BX */
mov bx, handle
xor cx, cx
xor dx, dx
int 0x21
 
/* save (duplicate) current stdout so I can revert it later */
DUPSTDOUT:
/* save (duplicate) current stdout so I can revert it later */
mov ah, 0x45 /* duplicate file handle */
mov bx, 1 /* handle to dup (1=stdout) */
int 0x21 /* ax = new file handle */
mov [oldstdout], ax
mov oldstdout, ax
/* redirect the stdout handle */
mov bx, [handle] /* dst handle */
mov bx, handle /* dst handle */
mov cx, 1 /* src handle (1=stdout) */
mov ah, 0x46 /* redirect a handle */
int 0x21
/svarcom/trunk/rmod.asm
166,9 → 166,11
OLD_STDIN dw 0xffff
 
 
; ****************************************************************************
; *** ROUTINES ***************************************************************
; ****************************************************************************
 
 
; ----------------------------------------------------------------------------
; revert stdin/stdout redirections (if any) to their initial state
; all memory accesses are CS-prefixes because this code may be called at
; times when DS is out of whack.
187,8 → 189,10
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
STDOUT_DONE:
ret
; ----------------------------------------------------------------------------
 
 
; ----------------------------------------------------------------------------
; redirect stdout if REDIR_OUTFIL points to something
REDIR_OUTFILE_IF_REQUIRED:
mov si, [REDIR_OUTFIL]
202,6 → 206,18
int 0x21 ; ax=handle on success (CF clear)
mov [REDIR_OUTFIL], word 0xffff
jc NO_STDOUT_REDIR ; TODO: abort with an error message instead
 
; jump to end of file if flag was 0x11 (required for >> redirections)
cmp [REDIR_OUTAPPEND], word 0x11
jne SKIP_JMPEOF
mov bx, ax
mov ax, 0x4202 ; jump to position EOF - CX:DX in handle BX
xor cx, cx
xor dx, dx
int 0x21
mov ax, bx ; put my handle back in ax, as expected by later code
SKIP_JMPEOF:
 
; duplicate current stdout so I can revert it later
push ax ; save my file handle in stack
mov ah, 0x45 ; duplicate file handle BX
208,13 → 224,16
mov bx, 1 ; 1=stdout
int 0x21 ; ax=new (duplicated) file handle
mov [OLD_STDOUT], ax ; save the old handle in memory
 
; redirect stdout to my file
pop bx ; dst handle
mov cx, 1 ; src handle (1=stdout)
mov ah, 0x46 ; "redirect a handle"
int 0x21
 
; close the original file handle, I no longer need it
mov ah, 0x3e ; close a file handle (handle in BX)
int 0x21
NO_STDOUT_REDIR:
ret
; ----------------------------------------------------------------------------