1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/* $id$
$Locker: $ $Name: $ $State: Exp $
Execute an external program using DOS-4B-00
This file bases on EXEC.C of FreeCOM v0.81 beta 1.
$Log: exec.c,v $
Revision 1.4 2003/03/05 17:43:52 skaus
bugfix: cached NLS data not flushed
Revision 1.3 2002/11/12 18:31:57 skaus
add: save/restore session (swap context) {Tom Ehlert}
Revision 1.2 2002/04/02 18:09:31 skaus
add: XMS-Only Swap feature (FEATURE_XMS_SWAP) (Tom Ehlert)
Revision 1.1 2001/04/12 00:33:53 skaus
chg: new structure
chg: If DEBUG enabled, no available commands are displayed on startup
fix: PTCHSIZE also patches min extra size to force to have this amount
of memory available on start
bugfix: CALL doesn't reset options
add: PTCHSIZE to patch heap size
add: VSPAWN, /SWAP switch, .SWP resource handling
bugfix: COMMAND.COM A:\
bugfix: CALL: if swapOnExec == ERROR, no change of swapOnExec allowed
add: command MEMORY
bugfix: runExtension(): destroys command[-2]
add: clean.bat
add: localized CRITER strings
chg: use LNG files for hard-coded strings (hangForEver(), init.c)
via STRINGS.LIB
add: DEL.C, COPY.C, CBREAK.C: STRINGS-based prompts
add: fixstrs.c: prompts & symbolic keys
add: fixstrs.c: backslash escape sequences
add: version IDs to DEFAULT.LNG and validation to FIXSTRS.C
chg: splitted code apart into LIB\*.c and CMD\*.c
bugfix: IF is now using error system & STRINGS to report errors
add: CALL: /N
*/
#include "../config.h"
#include <assert.h>
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include "../include/command.h"
#include "../include/cswap.h"
#include "../include/nls.h"
/* align one byte */
#pragma option -a-
struct ExecBlock
{
word segOfEnv;
char far *cmdLine;
struct fcb far *fcb1,
far * fcb2;
};
/* default alignment */
#pragma option -a.
int lowLevelExec(char far * cmd, struct ExecBlock far * bl);
int exec(const char *cmd, char *cmdLine, const unsigned segOfEnv)
{
#ifdef FEATURE_XMS_SWAP
# define buf dosCMDTAIL
# define memcpy _fmemcpy
#else
unsigned char buf[128];
#endif
struct fcb fcb1,
fcb2;
struct ExecBlock execBlock;
int retval;
assert(cmd);
assert(cmdLine);
assert(strlen(cmdLine) <= 125);
invalidateNLSbuf();
/* generate Pascal string from the command line */
memcpy(&buf[1], cmdLine, buf[0] = strlen(cmdLine));
memcpy(&buf[1] + buf[0], "\xd", 2);
/* fill FCBs */
if ((cmdLine = parsfnm(cmdLine, &fcb1, 1)) != 0)
parsfnm(cmdLine, &fcb2, 1);
saveSession();
#ifdef FEATURE_XMS_SWAP
if(XMSisactive() && swapOnExec == TRUE) {
/* Copy the prepared values into the buffers in CSWAP.ASM module */
_fmemcpy(dosFCB1, &fcb1, sizeof(fcb1));
_fmemcpy(dosFCB2, &fcb2, sizeof(fcb1));
assert(strlen(cmd) < 128);
_fstrcpy(dosCMDNAME, cmd);
dosParamDosExec.envSeg = segOfEnv;
retval = XMSexec();
} else
#endif
{
/* fill execute structure */
execBlock.segOfEnv = segOfEnv;
execBlock.cmdLine = (char far *)buf;
execBlock.fcb1 = (struct fcb far *)&fcb1;
execBlock.fcb2 = (struct fcb far *)&fcb2;
retval = lowLevelExec((char far*)cmd, (struct ExecBlock far*)&execBlock);
}
restoreSession();
return decode_exec_result(retval);
}
|