Line 37... |
Line 37... |
37 |
#include "env.h"
|
37 |
#include "env.h"
|
38 |
#include "helpers.h"
|
38 |
#include "helpers.h"
|
39 |
#include "rmodinit.h"
|
39 |
#include "rmodinit.h"
|
40 |
#include "sayonara.h"
|
40 |
#include "sayonara.h"
|
41 |
|
41 |
|
42 |
#define BUFFER_SIZE 2048 /* make sure this is not bigger than the static buffer in command.c */
|
- |
|
43 |
|
42 |
|
44 |
struct cmd_funcparam {
|
43 |
struct cmd_funcparam {
|
45 |
int argc; /* number of arguments */
|
44 |
int argc; /* number of arguments */
|
46 |
const char *argv[256]; /* pointers to each argument */
|
45 |
const char *argv[128]; /* pointers to each argument */
|
- |
|
46 |
char argvbuf[256]; /* buffer that hold data pointed out by argv[] */
|
47 |
unsigned short env_seg; /* segment of environment block */
|
47 |
unsigned short env_seg; /* segment of environment block */
|
48 |
struct rmod_props far *rmod; /* rmod settings */
|
48 |
struct rmod_props far *rmod; /* rmod settings */
|
49 |
unsigned short argoffset; /* offset of cmdline where first argument starts */
|
49 |
unsigned short argoffset; /* offset of cmdline where first argument starts */
|
50 |
const char *cmdline; /* original cmdline (terminated by a NULL) */
|
50 |
const char *cmdline; /* original cmdline (terminated by a NULL) */
|
- |
|
51 |
unsigned short BUFFERSZ; /* avail space in BUFFER */
|
51 |
char BUFFER[BUFFER_SIZE]; /* a buffer for whatever is needed */
|
52 |
char BUFFER[1]; /* a buffer for whatever is needed (must be last) */
|
52 |
};
|
53 |
};
|
53 |
|
54 |
|
54 |
/* scans argv for the presence of a "/?" parameter. returns 1 if found, 0 otherwise */
|
55 |
/* scans argv for the presence of a "/?" parameter. returns 1 if found, 0 otherwise */
|
55 |
static int cmd_ishlp(const struct cmd_funcparam *p) {
|
56 |
static int cmd_ishlp(const struct cmd_funcparam *p) {
|
56 |
int i;
|
57 |
int i;
|
Line 165... |
Line 166... |
165 |
}
|
166 |
}
|
166 |
|
167 |
|
167 |
|
168 |
|
168 |
/* explodes a command into an array of arguments where last arg is NULL
|
169 |
/* explodes a command into an array of arguments where last arg is NULL
|
169 |
* returns number of args */
|
170 |
* returns number of args */
|
170 |
unsigned short cmd_explode(char *buff, const char far *s, char const **argvlist) {
|
171 |
static unsigned short cmd_explode(char *buff, const char far *s, char const **argvlist) {
|
171 |
int si = 0, argc = 0, i = 0;
|
172 |
int si = 0, argc = 0, i = 0;
|
172 |
for (;;) {
|
173 |
for (;;) {
|
173 |
/* skip to next non-space character */
|
174 |
/* skip to next non-space character */
|
174 |
while (s[si] == ' ') si++;
|
175 |
while (s[si] == ' ') si++;
|
175 |
/* end of string? */
|
176 |
/* end of string? */
|
Line 187... |
Line 188... |
187 |
argvlist[argc] = NULL;
|
188 |
argvlist[argc] = NULL;
|
188 |
return(argc);
|
189 |
return(argc);
|
189 |
}
|
190 |
}
|
190 |
|
191 |
|
191 |
|
192 |
|
192 |
int cmd_process(struct rmod_props far *rmod, unsigned short env_seg, const char *cmdline, char *BUFFER) {
|
193 |
int cmd_process(struct rmod_props far *rmod, unsigned short env_seg, const char *cmdline, void *BUFFER, unsigned short BUFFERSZ) {
|
193 |
const struct CMD_ID *cmdptr;
|
194 |
const struct CMD_ID *cmdptr;
|
194 |
unsigned short argoffset;
|
195 |
unsigned short argoffset;
|
195 |
struct cmd_funcparam *p = (void *)BUFFER;
|
196 |
struct cmd_funcparam *p = (void *)BUFFER;
|
- |
|
197 |
p->BUFFERSZ = BUFFERSZ - sizeof(*p);
|
196 |
|
198 |
|
197 |
/* special case: is this a drive change? (like "E:") */
|
199 |
/* special case: is this a drive change? (like "E:") */
|
198 |
if ((cmdline[0] != 0) && (cmdline[1] == ':') && ((cmdline[2] == ' ') || (cmdline[2] == 0))) {
|
200 |
if ((cmdline[0] != 0) && (cmdline[1] == ':') && ((cmdline[2] == ' ') || (cmdline[2] == 0))) {
|
199 |
if (((cmdline[0] >= 'a') && (cmdline[0] <= 'z')) || ((cmdline[0] >= 'A') && (cmdline[0] <= 'Z'))) {
|
201 |
if (((cmdline[0] >= 'a') && (cmdline[0] <= 'z')) || ((cmdline[0] >= 'A') && (cmdline[0] <= 'Z'))) {
|
200 |
unsigned char drive = cmdline[0];
|
202 |
unsigned char drive = cmdline[0];
|
Line 226... |
Line 228... |
226 |
if (cmdptr == NULL) return(-2); /* command is not recognized as internal */
|
228 |
if (cmdptr == NULL) return(-2); /* command is not recognized as internal */
|
227 |
|
229 |
|
228 |
/* printf("recognized internal command: '%s', tail of command at offset %u\r\n", cmdptr->cmd, argoffset); */
|
230 |
/* printf("recognized internal command: '%s', tail of command at offset %u\r\n", cmdptr->cmd, argoffset); */
|
229 |
|
231 |
|
230 |
/* prepare function parameters and feed it to the cmd handling function */
|
232 |
/* prepare function parameters and feed it to the cmd handling function */
|
231 |
p->argc = cmd_explode(BUFFER + sizeof(*p), cmdline + argoffset, p->argv);
|
233 |
p->argc = cmd_explode(p->argvbuf, cmdline + argoffset, p->argv);
|
232 |
p->env_seg = env_seg;
|
234 |
p->env_seg = env_seg;
|
233 |
p->rmod = rmod;
|
235 |
p->rmod = rmod;
|
234 |
p->argoffset = argoffset;
|
236 |
p->argoffset = argoffset;
|
235 |
p->cmdline = cmdline;
|
237 |
p->cmdline = cmdline;
|
236 |
|
238 |
|