Subversion Repositories SvarDOS

Rev

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

Rev 543 Rev 575
Line 1... Line 1...
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021 Mateusz Viste
4
 * Copyright (C) 2021-2022 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 49... Line 49...
49
    xor cx, cx /* file attributes */
49
    xor cx, cx /* file attributes */
50
    int 0x21
50
    int 0x21
51
    jnc CLOSEFILE
51
    jnc CLOSEFILE
52
    mov err, ax
52
    mov err, ax
53
    jmp DONE
53
    jmp DONE
54
    /* close file handle */
54
    /* close file handle (handle still in BX) */
55
    CLOSEFILE:
55
    CLOSEFILE:
56
    mov ah, 0x3e
-
 
57
    mov bx, ax
56
    mov bx, ax
-
 
57
    mov ah, 0x3e
58
    int 0x21
58
    int 0x21
59
    DONE:
59
    DONE:
60
  }
60
  }
61
  return(err);
61
  return(err);
62
}
62
}
63
 
63
 
64
#include <stdio.h>
-
 
-
 
64
 
65
/* parse commandline and performs necessary redirections. cmdline is
65
/* parse commandline and performs necessary redirections. cmdline is
66
 * modified so all redirections are cut out.
66
 * modified so all redirections are cut out.
67
 * piped commands are move to awaitingcmd for later execution
67
 * piped commands are moved to awaitingcmd for later execution
68
 * returns 0 on success, DOS err on failure */
68
 * returns 0 on success, DOS err on failure */
69
unsigned short redir_parsecmd(struct redir_data *d, char *cmdline, char far *awaitingcmd) {
69
unsigned short redir_parsecmd(struct redir_data *d, char *cmdline, char far *awaitingcmd) {
70
  unsigned short i;
70
  unsigned short i;
71
  unsigned short pipescount = 0;
71
  unsigned short pipescount = 0;
72
 
72
 
Line 220... Line 220...
220
 
220
 
221
/* restores previous stdout handle if is has been redirected */
221
/* restores previous stdout handle if is has been redirected */
222
void redir_revert(void) {
222
void redir_revert(void) {
223
  _asm {
223
  _asm {
224
    /* if oldstdout is 0xffff then not redirected */
224
    /* if oldstdout is 0xffff then not redirected */
225
    cmp word ptr [oldstdout], 0xffff
-
 
226
    je DONE
-
 
227
    /* redirect the stdout handle */
-
 
228
    mov bx, [oldstdout] /* dst handle */
225
    mov bx, [oldstdout] /* dst handle */
-
 
226
    cmp bx, 0xffff
-
 
227
    je DONE
-
 
228
    /* redirect the stdout handle (handle already in BX) */
229
    mov cx, 1           /* src handle (1=stdout) */
229
    mov cx, 1           /* src handle (1=stdout) */
230
    mov ah, 0x46        /* redirect a handle */
230
    mov ah, 0x46        /* redirect a handle */
231
    int 0x21
231
    int 0x21
232
    /* close old handle (in bx already) */
232
    /* close old handle (in bx already) */
233
    mov ah, 0x3e
233
    mov ah, 0x3e