Subversion Repositories SvarDOS

Rev

Rev 519 | Rev 529 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 519 Rev 520
Line 164... Line 164...
164
; variables used to revert stdin/stdout to their initial state
164
; variables used to revert stdin/stdout to their initial state
165
OLD_STDOUT dw 0xffff
165
OLD_STDOUT dw 0xffff
166
OLD_STDIN  dw 0xffff
166
OLD_STDIN  dw 0xffff
167
 
167
 
168
 
168
 
-
 
169
; ****************************************************************************
169
; *** ROUTINES ***************************************************************
170
; *** ROUTINES ***************************************************************
-
 
171
; ****************************************************************************
170
 
172
 
171
 
-
 
-
 
173
; ----------------------------------------------------------------------------
172
; revert stdin/stdout redirections (if any) to their initial state
174
; revert stdin/stdout redirections (if any) to their initial state
173
; all memory accesses are CS-prefixes because this code may be called at
175
; all memory accesses are CS-prefixes because this code may be called at
174
; times when DS is out of whack.
176
; times when DS is out of whack.
175
REVERT_REDIR_IF_ANY:
177
REVERT_REDIR_IF_ANY:
176
; is stdout redirected?
178
; is stdout redirected?
Line 185... Line 187...
185
mov ah, 0x3e
187
mov ah, 0x3e
186
int 0x21
188
int 0x21
187
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
189
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
188
STDOUT_DONE:
190
STDOUT_DONE:
189
ret
191
ret
-
 
192
; ----------------------------------------------------------------------------
190
 
193
 
191
 
194
 
-
 
195
; ----------------------------------------------------------------------------
192
; redirect stdout if REDIR_OUTFIL points to something
196
; redirect stdout if REDIR_OUTFIL points to something
193
REDIR_OUTFILE_IF_REQUIRED:
197
REDIR_OUTFILE_IF_REQUIRED:
194
mov si, [REDIR_OUTFIL]
198
mov si, [REDIR_OUTFIL]
195
cmp si, 0xffff
199
cmp si, 0xffff
196
je NO_STDOUT_REDIR
200
je NO_STDOUT_REDIR
Line 200... Line 204...
200
xor cx, cx             ; file attribs when(if) file is created (0=normal)
204
xor cx, cx             ; file attribs when(if) file is created (0=normal)
201
mov dx, [REDIR_OUTAPPEND] ; action if file exist (0x11=open, 0x12=truncate)
205
mov dx, [REDIR_OUTAPPEND] ; action if file exist (0x11=open, 0x12=truncate)
202
int 0x21               ; ax=handle on success (CF clear)
206
int 0x21               ; ax=handle on success (CF clear)
203
mov [REDIR_OUTFIL], word 0xffff
207
mov [REDIR_OUTFIL], word 0xffff
204
jc NO_STDOUT_REDIR     ; TODO: abort with an error message instead
208
jc NO_STDOUT_REDIR     ; TODO: abort with an error message instead
-
 
209
 
-
 
210
; jump to end of file if flag was 0x11 (required for >> redirections)
-
 
211
cmp [REDIR_OUTAPPEND], word 0x11
-
 
212
jne SKIP_JMPEOF
-
 
213
mov bx, ax
-
 
214
mov ax, 0x4202         ; jump to position EOF - CX:DX in handle BX
-
 
215
xor cx, cx
-
 
216
xor dx, dx
-
 
217
int 0x21
-
 
218
mov ax, bx             ; put my handle back in ax, as expected by later code
-
 
219
SKIP_JMPEOF:
-
 
220
 
205
; duplicate current stdout so I can revert it later
221
; duplicate current stdout so I can revert it later
206
push ax                ; save my file handle in stack
222
push ax                ; save my file handle in stack
207
mov ah, 0x45           ; duplicate file handle BX
223
mov ah, 0x45           ; duplicate file handle BX
208
mov bx, 1              ; 1=stdout
224
mov bx, 1              ; 1=stdout
209
int 0x21               ; ax=new (duplicated) file handle
225
int 0x21               ; ax=new (duplicated) file handle
210
mov [OLD_STDOUT], ax   ; save the old handle in memory
226
mov [OLD_STDOUT], ax   ; save the old handle in memory
-
 
227
 
211
; redirect stdout to my file
228
; redirect stdout to my file
212
pop bx                 ; dst handle
229
pop bx                 ; dst handle
213
mov cx, 1              ; src handle (1=stdout)
230
mov cx, 1              ; src handle (1=stdout)
214
mov ah, 0x46           ; "redirect a handle"
231
mov ah, 0x46           ; "redirect a handle"
215
int 0x21
232
int 0x21
-
 
233
 
216
; close the original file handle, I no longer need it
234
; close the original file handle, I no longer need it
217
mov ah, 0x3e           ; close a file handle (handle in BX)
235
mov ah, 0x3e           ; close a file handle (handle in BX)
218
int 0x21
236
int 0x21
219
NO_STDOUT_REDIR:
237
NO_STDOUT_REDIR:
220
ret
238
ret
-
 
239
; ----------------------------------------------------------------------------