Subversion Repositories SvarDOS

Rev

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

Rev 537 Rev 543
Line 79... Line 79...
79
 
79
 
80
; revert stdin/stdout redirections (if any) to their initial state
80
; revert stdin/stdout redirections (if any) to their initial state
81
call REVERT_REDIR_IF_ANY
81
call REVERT_REDIR_IF_ANY
82
 
82
 
83
; redirect stdout if required
83
; redirect stdout if required
84
call REDIR_OUTFILE_IF_REQUIRED
84
call REDIR_INOUTFILE_IF_REQUIRED
85
 
85
 
86
; should I executed command.com or a pre-set application?
86
; should I executed command.com or a pre-set application?
87
or [EXECPROG], byte 0
87
or [EXECPROG], byte 0
88
jz EXEC_COMMAND_COM
88
jz EXEC_COMMAND_COM
89
 
89
 
Line 199... Line 199...
199
; close the old handle (still in bx)
199
; close the old handle (still in bx)
200
mov ah, 0x3e
200
mov ah, 0x3e
201
int 0x21
201
int 0x21
202
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
202
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
203
STDOUT_DONE:
203
STDOUT_DONE:
-
 
204
 
-
 
205
; is stdin redirected?
-
 
206
mov bx, [OLD_STDIN]
-
 
207
cmp bx, 0xffff
-
 
208
je STDIN_DONE
-
 
209
; revert the stdout handle (dst in BX already)
-
 
210
xor cx, cx       ; src handle (0=stdin)
-
 
211
mov ah, 0x46     ; redirect a handle
-
 
212
int 0x21
-
 
213
; close the old handle (still in bx)
-
 
214
mov ah, 0x3e
-
 
215
int 0x21
-
 
216
mov [OLD_STDIN], word 0xffff ; mark stdin as "not redirected"
-
 
217
STDIN_DONE:
-
 
218
 
204
ret
219
ret
205
; ----------------------------------------------------------------------------
220
; ----------------------------------------------------------------------------
206
 
221
 
207
 
222
 
208
; ----------------------------------------------------------------------------
223
; ----------------------------------------------------------------------------
209
; redirect stdout if REDIR_OUTFIL points to something
224
; redirect stdout if REDIR_OUTFIL points to something
210
REDIR_OUTFILE_IF_REQUIRED:
225
REDIR_INOUTFILE_IF_REQUIRED:
211
mov si, [REDIR_OUTFIL]
226
mov si, [REDIR_OUTFIL]
212
cmp si, 0xffff
227
cmp si, 0xffff
213
je NO_STDOUT_REDIR
228
je NO_STDOUT_REDIR
214
add si, EXECPROG       ; si=output file
229
add si, EXECPROG       ; si=output file
215
mov ax, 0x6c00         ; Extended Open/Create
230
mov ax, 0x6c00         ; Extended Open/Create
Line 246... Line 261...
246
 
261
 
247
; close the original file handle, I no longer need it
262
; close the original file handle, I no longer need it
248
mov ah, 0x3e           ; close a file handle (handle in BX)
263
mov ah, 0x3e           ; close a file handle (handle in BX)
249
int 0x21
264
int 0x21
250
NO_STDOUT_REDIR:
265
NO_STDOUT_REDIR:
-
 
266
 
-
 
267
; *** redirect stdin if REDIR_INFIL points to something ***
-
 
268
mov dx, [REDIR_INFIL]
-
 
269
cmp dx, 0xffff
-
 
270
je NO_STDIN_REDIR
-
 
271
add dx, EXECPROG       ; ds:dx=file
-
 
272
mov ax, 0x3d00         ; open file for read
-
 
273
int 0x21               ; ax=handle on success (CF clear)
-
 
274
mov [REDIR_INFIL], word 0xffff
-
 
275
jc NO_STDIN_REDIR      ; TODO: abort with an error message instead
-
 
276
 
-
 
277
; duplicate current stdin so I can revert it later
-
 
278
push ax                ; save my file handle in stack
-
 
279
mov ah, 0x45           ; duplicate file handle BX
-
 
280
xor bx, bx             ; 0=stdin
-
 
281
int 0x21               ; ax=new (duplicated) file handle
-
 
282
mov [OLD_STDIN], ax    ; save the old handle in memory
-
 
283
 
-
 
284
; redirect stdout to my file
-
 
285
pop bx                 ; dst handle
-
 
286
xor cx, cx             ; src handle (0=stdin)
-
 
287
mov ah, 0x46           ; "redirect a handle"
-
 
288
int 0x21
-
 
289
 
-
 
290
; close the original file handle, I no longer need it
-
 
291
mov ah, 0x3e           ; close a file handle (handle in BX)
-
 
292
int 0x21
-
 
293
NO_STDIN_REDIR:
251
ret
294
ret
252
; ----------------------------------------------------------------------------
295
; ----------------------------------------------------------------------------