Subversion Repositories SvarDOS

Rev

Rev 1730 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1730 Rev 1797
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-2024 Mateusz Viste
4
 * Copyright (C) 2021-2024 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,
10
 * and/or sell copies of the Software, and to permit persons to whom the
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
12
 *
13
 * The above copyright notice and this permission notice shall be included in
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
14
 * all copies or substantial portions of the Software.
15
 *
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
/* entry point for internal commands, it matches internal commands and
25
/* entry point for internal commands, it matches internal commands and
26
 * executes them.
26
 * executes them.
27
 *
27
 *
28
 * returns one of the following values:
28
 * returns one of the following values:
29
 *   CMD_OK               command executed successfully
29
 *   CMD_OK               command executed successfully
30
 *   CMD_FAIL             command ended in error
30
 *   CMD_FAIL             command ended in error
31
 *   CMD_CHANGED          command-line has been modified (used by IF)
31
 *   CMD_CHANGED          command-line has been modified (used by IF)
32
 *   CMD_CHANGED_BY_CALL  command-line has been modified by CALL
32
 *   CMD_CHANGED_BY_CALL  command-line has been modified by CALL
33
 *   CMD_CHANGED_BY_LH    command-line has been modified by LOADHIGH
33
 *   CMD_CHANGED_BY_LH    command-line has been modified by LOADHIGH
34
 *   CMD_NOTFOUND         command unrecognized
34
 *   CMD_NOTFOUND         command unrecognized
35
 */
35
 */
36
 
36
 
37
#include <i86.h>
37
#include <i86.h>
38
#include <malloc.h> /* _fmalloc() */
38
#include <malloc.h> /* _fmalloc() */
39
#include <stdio.h>
39
#include <stdio.h>
40
#include <stdlib.h>
40
#include <stdlib.h>
41
#include <string.h>
41
#include <string.h>
42
 
42
 
43
#include "svarlang.lib/svarlang.h"
43
#include "svarlang.lib/svarlang.h"
44
 
44
 
45
#include "env.h"
45
#include "env.h"
46
#include "helpers.h"
46
#include "helpers.h"
47
#include "redir.h"
47
#include "redir.h"
48
#include "rmodinit.h"
48
#include "rmodinit.h"
49
#include "sayonara.h"
49
#include "sayonara.h"
50
 
50
 
51
#include "cmd.h"
51
#include "cmd.h"
52
 
52
 
53
 
53
 
54
/* struct used to pass all necessary information to the sub-commands */
54
/* struct used to pass all necessary information to the sub-commands */
55
struct cmd_funcparam {
55
struct cmd_funcparam {
56
  int argc;                 /* number of arguments */
56
  int argc;                 /* number of arguments */
57
  const char *argv[128];    /* pointers to each argument */
57
  const char *argv[128];    /* pointers to each argument */
58
  char argvbuf[256];        /* buffer that hold data pointed out by argv[] */
58
  char argvbuf[256];        /* buffer that hold data pointed out by argv[] */
59
  unsigned short env_seg;   /* segment of environment block */
59
  unsigned short env_seg;   /* segment of environment block */
60
  struct rmod_props far *rmod; /* rmod settings */
60
  struct rmod_props far *rmod; /* rmod settings */
61
  unsigned short argoffset; /* offset of cmdline where first argument starts */
61
  unsigned short argoffset; /* offset of cmdline where first argument starts */
62
  const char *cmdline;      /* original cmdline (terminated by a NULL) */
62
  const char *cmdline;      /* original cmdline (terminated by a NULL) */
63
  unsigned short BUFFERSZ;  /* avail space in BUFFER */
63
  unsigned short BUFFERSZ;  /* avail space in BUFFER */
64
  char BUFFER[1];           /* a buffer for whatever is needed (must be last) */
64
  char BUFFER[1];           /* a buffer for whatever is needed (must be last) */
65
};
65
};
66
 
66
 
67
 
67
 
68
/* scans argv for the presence of a "/?" parameter.
68
/* scans argv for the presence of a "/?" parameter.
69
 * returns 1 if found, 0 otherwise
69
 * returns 1 if found, 0 otherwise
70
 * this is used by most sub-commands to detect /? invocations */
70
 * this is used by most sub-commands to detect /? invocations */
71
static int cmd_ishlp(const struct cmd_funcparam *p) {
71
static int cmd_ishlp(const struct cmd_funcparam *p) {
72
  int i;
72
  int i;
73
  for (i = 0; i < p->argc; i++) {
73
  for (i = 0; i < p->argc; i++) {
74
    if ((p->argv[i][0] == '/') && (p->argv[i][1] == '?')) return(1);
74
    if ((p->argv[i][0] == '/') && (p->argv[i][1] == '?')) return(1);
75
  }
75
  }
76
  return(0);
76
  return(0);
77
}
77
}
78
 
78
 
79
#include "cmd/break.c"
79
#include "cmd/break.c"
80
#include "cmd/call.c"
80
#include "cmd/call.c"
81
#include "cmd/cd.c"
81
#include "cmd/cd.c"
82
#include "cmd/chcp.c"
82
#include "cmd/chcp.c"
83
#include "cmd/cls.c"
83
#include "cmd/cls.c"
84
#include "cmd/copy.c"
84
#include "cmd/copy.c"
85
#include "cmd/ctty.c"
85
#include "cmd/ctty.c"
86
#include "cmd/date.c"
86
#include "cmd/date.c"
87
#include "cmd/del.c"
87
#include "cmd/del.c"
88
#include "cmd/for.c"
88
#include "cmd/for.c"
89
#include "cmd/goto.c"
89
#include "cmd/goto.c"
90
#include "cmd/if.c"
90
#include "cmd/if.c"
91
#include "cmd/vol.c"     /* must be included before dir.c due to dependency */
91
#include "cmd/vol.c"     /* must be included before dir.c due to dependency */
92
#include "cmd/dir.c"
92
#include "cmd/dir.c"
93
#include "cmd/echo.c"
93
#include "cmd/echo.c"
94
#include "cmd/exit.c"
94
#include "cmd/exit.c"
95
#include "cmd/loadhigh.c"
95
#include "cmd/loadhigh.c"
96
#include "cmd/ln.c"
96
#include "cmd/ln.c"
97
#include "cmd/mkdir.c"
97
#include "cmd/mkdir.c"
98
#include "cmd/path.c"
98
#include "cmd/path.c"
99
#include "cmd/pause.c"
99
#include "cmd/pause.c"
100
#include "cmd/prompt.c"
100
#include "cmd/prompt.c"
101
#include "cmd/rem.c"
101
#include "cmd/rem.c"
102
#include "cmd/rename.c"
102
#include "cmd/rename.c"
103
#include "cmd/rmdir.c"
103
#include "cmd/rmdir.c"
104
#include "cmd/set.c"
104
#include "cmd/set.c"
105
#include "cmd/shift.c"
105
#include "cmd/shift.c"
106
#include "cmd/time.c"
106
#include "cmd/time.c"
107
#include "cmd/truename.c"
107
#include "cmd/truename.c"
108
#include "cmd/type.c"
108
#include "cmd/type.c"
109
#include "cmd/ver.c"
109
#include "cmd/ver.c"
110
#include "cmd/verify.c"
110
#include "cmd/verify.c"
111
 
111
 
112
 
112
 
113
struct CMD_ID {
113
struct CMD_ID {
114
  const char *cmd;
114
  const char *cmd;
115
  enum cmd_result (*func_ptr)(struct cmd_funcparam *); /* pointer to handling function */
115
  enum cmd_result (*func_ptr)(struct cmd_funcparam *); /* pointer to handling function */
116
};
116
};
117
 
117
 
118
const struct CMD_ID INTERNAL_CMDS[] = {
118
const struct CMD_ID INTERNAL_CMDS[] = {
119
  {"BREAK",   cmd_break},
119
  {"BREAK",   cmd_break},
120
  {"CALL",    cmd_call},
120
  {"CALL",    cmd_call},
121
  {"CD",      cmd_cd},
121
  {"CD",      cmd_cd},
122
  {"CHCP",    cmd_chcp},
122
  {"CHCP",    cmd_chcp},
123
  {"CHDIR",   cmd_cd},
123
  {"CHDIR",   cmd_cd},
124
  {"CLS",     cmd_cls},
124
  {"CLS",     cmd_cls},
125
  {"COPY",    cmd_copy},
125
  {"COPY",    cmd_copy},
126
  {"CTTY",    cmd_ctty},
126
  {"CTTY",    cmd_ctty},
127
  {"DATE",    cmd_date},
127
  {"DATE",    cmd_date},
128
  {"DEL",     cmd_del},
128
  {"DEL",     cmd_del},
129
  {"DIR",     cmd_dir},
129
  {"DIR",     cmd_dir},
130
  {"ECHO",    cmd_echo},
130
  {"ECHO",    cmd_echo},
131
  {"ERASE",   cmd_del},
131
  {"ERASE",   cmd_del},
132
  {"EXIT",    cmd_exit},
132
  {"EXIT",    cmd_exit},
133
  {"FOR",     cmd_for},
133
  {"FOR",     cmd_for},
134
  {"GOTO",    cmd_goto},
134
  {"GOTO",    cmd_goto},
135
  {"IF",      cmd_if},
135
  {"IF",      cmd_if},
136
  {"LH",      cmd_loadhigh},
136
  {"LH",      cmd_loadhigh},
137
  {"LN",      cmd_ln},
137
  {"LN",      cmd_ln},
138
  {"LOADHIGH",cmd_loadhigh},
138
  {"LOADHIGH",cmd_loadhigh},
139
  {"MD",      cmd_mkdir},
139
  {"MD",      cmd_mkdir},
140
  {"MKDIR",   cmd_mkdir},
140
  {"MKDIR",   cmd_mkdir},
141
  {"PAUSE",   cmd_pause},
141
  {"PAUSE",   cmd_pause},
142
  {"PATH",    cmd_path},
142
  {"PATH",    cmd_path},
143
  {"PROMPT",  cmd_prompt},
143
  {"PROMPT",  cmd_prompt},
144
  {"RD",      cmd_rmdir},
144
  {"RD",      cmd_rmdir},
145
  {"REM",     cmd_rem},
145
  {"REM",     cmd_rem},
146
  {"REN",     cmd_rename},
146
  {"REN",     cmd_rename},
147
  {"RENAME",  cmd_rename},
147
  {"RENAME",  cmd_rename},
148
  {"RMDIR",   cmd_rmdir},
148
  {"RMDIR",   cmd_rmdir},
149
  {"SET",     cmd_set},
149
  {"SET",     cmd_set},
150
  {"SHIFT",   cmd_shift},
150
  {"SHIFT",   cmd_shift},
151
  {"TIME",    cmd_time},
151
  {"TIME",    cmd_time},
152
  {"TRUENAME",cmd_truename},
152
  {"TRUENAME",cmd_truename},
153
  {"TYPE",    cmd_type},
153
  {"TYPE",    cmd_type},
154
  {"VER",     cmd_ver},
154
  {"VER",     cmd_ver},
155
  {"VERIFY",  cmd_verify},
155
  {"VERIFY",  cmd_verify},
156
  {"VOL",     cmd_vol},
156
  {"VOL",     cmd_vol},
157
  {NULL,      NULL}
157
  {NULL,      NULL}
158
};
158
};
159
 
159
 
160
 
160
 
161
/* NULL if cmdline is not matching an internal command, otherwise returns a
161
/* NULL if cmdline is not matching an internal command, otherwise returns a
162
 * pointer to a CMD_ID struct */
162
 * pointer to a CMD_ID struct */
163
static const struct CMD_ID *cmd_match(const char *cmdline, unsigned short *argoffset) {
163
static const struct CMD_ID *cmd_match(const char *cmdline, unsigned short *argoffset) {
164
  unsigned short i;
164
  unsigned short i;
165
  char buff[10];
165
  char buff[10];
166
 
166
 
167
  /* copy command to buffer, until space, NULL, tab, return, dot, slash or backslash */
167
  /* copy command to buffer, until space, NULL, tab, return, dot, slash or backslash */
168
  for (i = 0; i < 9; i++) {
168
  for (i = 0; i < 9; i++) {
169
    if (cmdline[i] == ' ') break;
169
    if (cmdline[i] == ' ') break;
170
    if (cmdline[i] == 0) break;
170
    if (cmdline[i] == 0) break;
171
    if (cmdline[i] == '\t') break;
171
    if (cmdline[i] == '\t') break;
172
    if (cmdline[i] == '\r') break;
172
    if (cmdline[i] == '\r') break;
173
    if (cmdline[i] == '.') break;
173
    if (cmdline[i] == '.') break;
174
    if (cmdline[i] == '/') break;
174
    if (cmdline[i] == '/') break;
175
    if (cmdline[i] == '\\') break;
175
    if (cmdline[i] == '\\') break;
176
    buff[i] = cmdline[i];
176
    buff[i] = cmdline[i];
177
  }
177
  }
178
  buff[i] = 0;
178
  buff[i] = 0;
179
 
179
 
180
  /* advance to nearest non-space to find where arguments start */
180
  /* advance to nearest non-space to find where arguments start */
181
  while (cmdline[i] == ' ') i++;
181
  while (cmdline[i] == ' ') i++;
182
  *argoffset = i;
182
  *argoffset = i;
183
 
183
 
184
  /* try matching an internal command */
184
  /* try matching an internal command */
185
  for (i = 0; INTERNAL_CMDS[i].cmd != NULL; i++) {
185
  for (i = 0; INTERNAL_CMDS[i].cmd != NULL; i++) {
186
    /*printf("imatch(%s,%s)\r\n", buff, INTERNAL_CMDS[i].cmd); */
186
    /*printf("imatch(%s,%s)\r\n", buff, INTERNAL_CMDS[i].cmd); */
187
    if (imatch(buff, INTERNAL_CMDS[i].cmd)) {
187
    if (imatch(buff, INTERNAL_CMDS[i].cmd)) {
188
      /*printf("match cmd i=%u (buff=%s)\r\n", i, buff);*/
188
      /*printf("match cmd i=%u (buff=%s)\r\n", i, buff);*/
189
      return(&(INTERNAL_CMDS[i]));
189
      return(&(INTERNAL_CMDS[i]));
190
    }
190
    }
191
  }
191
  }
192
 
192
 
193
  return(NULL); /* command is not recognized as internal */
193
  return(NULL); /* command is not recognized as internal */
194
}
194
}
195
 
195
 
196
 
196
 
197
/* explodes a command into an array of arguments where last arg is NULL.
197
/* explodes a command into an array of arguments where last arg is NULL.
198
 * if argvlist is not NULL, it will be filled with pointers that point to buff
198
 * if argvlist is not NULL, it will be filled with pointers that point to buff
199
 * locations. buff is filled with all the arguments, each argument being
199
 * locations. buff is filled with all the arguments, each argument being
200
 * zero-separated. buff is terminated with an empty argument to mark the end
200
 * zero-separated. buff is terminated with an empty argument to mark the end
201
 * of arguments.
201
 * of arguments.
202
 * returns number of args */
202
 * returns number of args */
203
unsigned short cmd_explode(char *buff, const char far *s, char const **argvlist) {
203
unsigned short cmd_explode(char *buff, const char far *s, char const **argvlist) {
204
  int si = 0, argc = 0, i = 0;
204
  int si = 0, argc = 0, i = 0;
205
  for (;;) {
205
  for (;;) {
206
    /* skip to next non-space character */
206
    /* skip to next non-space character */
207
    while (s[si] == ' ') si++;
207
    while (s[si] == ' ') si++;
208
    /* end of string? */
208
    /* end of string? */
209
    if (s[si] == 0) break;
209
    if (s[si] == 0) break;
210
    /* set argv ptr */
210
    /* set argv ptr */
211
    if (argvlist) argvlist[argc] = buff + i;
211
    if (argvlist) argvlist[argc] = buff + i;
212
    argc++;
212
    argc++;
213
    /* find next arg delimiter (spc, null, slash or plus) while copying arg to local buffer */
213
    /* find next arg delimiter (spc, null, slash or plus) while copying arg to local buffer */
214
    do {
214
    do {
215
      buff[i++] = s[si++];
215
      buff[i++] = s[si++];
216
    } while (s[si] != ' ' && s[si] != 0 && s[si] != '/' && s[si] != '+');
216
    } while (s[si] != ' ' && s[si] != 0 && s[si] != '/' && s[si] != '+');
217
    buff[i++] = 0;
217
    buff[i++] = 0;
218
    /* is this end of string? */
218
    /* is this end of string? */
219
    if (s[si] == 0) break;
219
    if (s[si] == 0) break;
220
  }
220
  }
221
  buff[i] = 0; /* terminate with one extra zero to tell "this is the end of list" */
221
  buff[i] = 0; /* terminate with one extra zero to tell "this is the end of list" */
222
  if (argvlist) argvlist[argc] = NULL;
222
  if (argvlist) argvlist[argc] = NULL;
223
  return(argc);
223
  return(argc);
224
}
224
}
225
 
225
 
226
 
226
 
-
 
227
/* asks DOS to change the current default drive, returns the current drive
-
 
228
 * (should be the same as d on success) */
-
 
229
static unsigned char _changedosdrive(unsigned char d);
-
 
230
#pragma aux _changedosdrive = \
-
 
231
"mov ah, 0x0e"   /* DOS 1+ - SELECT DRIVE (DL=drive, 00h=A:, 01h=B:, etc) */ \
-
 
232
"int 0x21" \
-
 
233
"mov ah, 0x19"     /* DOS 1+ - GET CURRENT DRIVE (drive in al) */ \
-
 
234
"int 0x21" \
-
 
235
parm [dl] \
-
 
236
modify [ah] \
-
 
237
value [al]
-
 
238
 
-
 
239
 
-
 
240
/* asks DOS to del a file, returns 0 on success */
-
 
241
static unsigned short _dosdelfile(const char near *f);
-
 
242
#pragma aux _dosdelfile = \
-
 
243
"mov ah, 0x41"  /* delete a file ; DS:DX = filename to delete */ \
-
 
244
"int 0x21" \
-
 
245
"jc DONE" \
-
 
246
"xor ax, ax" \
-
 
247
"DONE:" \
-
 
248
parm [dx] \
-
 
249
value [ax]
-
 
250
 
-
 
251
 
227
enum cmd_result cmd_process(struct rmod_props far *rmod, unsigned short env_seg, const char *cmdline, void *BUFFER, unsigned short BUFFERSZ, const struct redir_data *redir, unsigned char delstdin) {
252
enum cmd_result cmd_process(struct rmod_props far *rmod, unsigned short env_seg, const char *cmdline, void *BUFFER, unsigned short BUFFERSZ, const struct redir_data *redir, unsigned char delstdin) {
228
  const struct CMD_ID *cmdptr;
253
  const struct CMD_ID *cmdptr;
229
  unsigned short argoffset;
254
  unsigned short argoffset;
230
  enum cmd_result cmdres;
255
  enum cmd_result cmdres;
231
  struct cmd_funcparam *p = (void *)BUFFER;
256
  struct cmd_funcparam *p = (void *)BUFFER;
232
  p->BUFFERSZ = BUFFERSZ - sizeof(*p);
257
  p->BUFFERSZ = BUFFERSZ - sizeof(*p);
233
 
258
 
234
  /* special case: is this a drive change? (like "E:") */
259
  /* special case: is this a drive change? (like "E:") */
235
  if ((cmdline[0] != 0) && (cmdline[1] == ':') && ((cmdline[2] == ' ') || (cmdline[2] == 0))) {
260
  if ((cmdline[0] != 0) && (cmdline[1] == ':') && ((cmdline[2] == ' ') || (cmdline[2] == 0))) {
236
    if (((cmdline[0] >= 'a') && (cmdline[0] <= 'z')) || ((cmdline[0] >= 'A') && (cmdline[0] <= 'Z'))) {
261
    if (((cmdline[0] >= 'a') && (cmdline[0] <= 'z')) || ((cmdline[0] >= 'A') && (cmdline[0] <= 'Z'))) {
237
      unsigned char drive = cmdline[0];
262
      unsigned char drive = cmdline[0];
238
      unsigned char curdrive = 0;
263
      unsigned char curdrive;
239
      if (drive >= 'a') {
264
      if (drive >= 'a') {
240
        drive -= 'a';
265
        drive -= 'a';
241
      } else {
266
      } else {
242
        drive -= 'A';
267
        drive -= 'A';
243
      }
268
      }
244
      _asm {
-
 
245
        push ax
-
 
246
        push dx
-
 
247
        mov ah, 0x0e     /* DOS 1+ - SELECT DEFAULT DRIVE */
-
 
248
        mov dl, drive    /* DL = new default drive (00h = A:, 01h = B:, etc) */
-
 
249
        int 0x21
-
 
250
        mov ah, 0x19     /* DOS 1+ - GET CURRENT DRIVE */
-
 
251
        int 0x21
-
 
252
        mov curdrive, al /* cur drive (0=A, 1=B, etc) */
269
      curdrive = _changedosdrive(drive);
253
        pop dx
-
 
254
        pop ax
-
 
255
      }
-
 
256
      if (curdrive == drive) return(CMD_OK);
270
      if (curdrive == drive) return(CMD_OK);
257
      nls_outputnl_doserr(0x0f);
271
      nls_outputnl_doserr(0x0f);
258
      return(CMD_FAIL);
272
      return(CMD_FAIL);
259
    }
273
    }
260
  }
274
  }
261
 
275
 
262
  /* try matching an internal command */
276
  /* try matching an internal command */
263
  cmdptr = cmd_match(cmdline, &argoffset);
277
  cmdptr = cmd_match(cmdline, &argoffset);
264
  if (cmdptr == NULL) return(CMD_NOTFOUND); /* command is not recognized as internal */
278
  if (cmdptr == NULL) return(CMD_NOTFOUND); /* command is not recognized as internal */
265
 
279
 
266
  /* printf("recognized internal command: '%s', tail of command at offset %u\r\n", cmdptr->cmd, argoffset); */
280
  /* printf("recognized internal command: '%s', tail of command at offset %u\r\n", cmdptr->cmd, argoffset); */
267
 
281
 
268
  /* apply redirections (if any) */
282
  /* apply redirections (if any) */
269
  if (redir_apply(redir) != 0) return(CMD_FAIL);
283
  if (redir_apply(redir) != 0) return(CMD_FAIL);
270
 
284
 
271
  /* prepare function parameters and feed it to the cmd handling function */
285
  /* prepare function parameters and feed it to the cmd handling function */
272
  p->argc = cmd_explode(p->argvbuf, cmdline + argoffset, p->argv);
286
  p->argc = cmd_explode(p->argvbuf, cmdline + argoffset, p->argv);
273
  p->env_seg = env_seg;
287
  p->env_seg = env_seg;
274
  p->rmod = rmod;
288
  p->rmod = rmod;
275
  p->argoffset = argoffset;
289
  p->argoffset = argoffset;
276
  p->cmdline = cmdline;
290
  p->cmdline = cmdline;
277
 
291
 
278
  cmdres = (cmdptr->func_ptr)(p);
292
  cmdres = (cmdptr->func_ptr)(p);
279
 
293
 
280
  /* cancel redirections */
294
  /* cancel redirections */
281
  redir_revert();
295
  redir_revert();
282
 
296
 
283
  /* delete stdin temporary file */
297
  /* delete stdin temporary file */
284
  if (delstdin) {
298
  if (delstdin) {
285
    const char *fname = redir->stdinfile;
299
    unsigned short doserr = _dosdelfile(redir->stdinfile);
286
    unsigned short doserr = 0;
-
 
287
    _asm {
-
 
288
      push ax
-
 
289
      push dx
-
 
290
      mov ah, 0x41  /* delete a file */
-
 
291
      mov dx, fname /* DS:DX - filename to delete */
-
 
292
      int 0x21
-
 
293
      jnc DONE
-
 
294
      mov doserr, ax
-
 
295
      DONE:
-
 
296
      pop dx
-
 
297
      pop ax
-
 
298
    }
-
 
299
    if (doserr) {
300
    if (doserr) {
300
      output(fname);
301
      output(redir->stdinfile);
301
      output(": ");
302
      output(": ");
302
      nls_outputnl_doserr(doserr);
303
      nls_outputnl_doserr(doserr);
303
    }
304
    }
304
  }
305
  }
305
 
306
 
306
  return(cmdres);
307
  return(cmdres);
307
}
308
}
308
 
309