Subversion Repositories SvarDOS

Rev

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

Rev 351 Rev 352
Line 51... Line 51...
51
#include <stdlib.h>
51
#include <stdlib.h>
52
#include <string.h>
52
#include <string.h>
53
 
53
 
54
#include <process.h>
54
#include <process.h>
55
 
55
 
-
 
56
#include "cmd.h"
-
 
57
#include "helpers.h"
56
#include "rmodinit.h"
58
#include "rmodinit.h"
57
 
59
 
58
struct config {
60
struct config {
59
  int locate;
61
  int locate;
60
  int install;
62
  int install;
61
  int envsiz;
63
  int envsiz;
62
} cfg;
64
} cfg;
63
 
65
 
64
 
66
 
65
/* returns zero if s1 starts with s2 */
-
 
66
static int strstartswith(const char *s1, const char *s2) {
-
 
67
  while (*s2 != 0) {
-
 
68
    if (*s1 != *s2) return(-1);
-
 
69
    s1++;
-
 
70
    s2++;
-
 
71
  }
-
 
72
  return(0);
-
 
73
}
-
 
74
 
-
 
75
 
-
 
76
static void parse_argv(struct config *cfg, int argc, char **argv) {
67
static void parse_argv(struct config *cfg, int argc, char **argv) {
77
  int i;
68
  int i;
78
  memset(cfg, 0, sizeof(*cfg));
69
  memset(cfg, 0, sizeof(*cfg));
79
 
70
 
80
  for (i = 1; i < argc; i++) {
71
  for (i = 1; i < argc; i++) {
Line 112... Line 103...
112
  argvlist[argc] = NULL;
103
  argvlist[argc] = NULL;
113
  return(argc);
104
  return(argc);
114
}
105
}
115
 
106
 
116
 
107
 
117
static void cmd_set(int argc, char const **argv, unsigned short env_seg) {
-
 
118
  char far *env = MK_FP(env_seg, 0);
-
 
119
  char buff[256];
-
 
120
  int i;
-
 
121
  while (*env != 0) {
-
 
122
    /* copy string to local buff for display */
-
 
123
    for (i = 0;; i++) {
-
 
124
      buff[i] = *env;
-
 
125
      env++;
-
 
126
      if (buff[i] == 0) break;
-
 
127
    }
-
 
128
    puts(buff);
-
 
129
  }
-
 
130
}
-
 
131
 
108
 
132
 
109
 
133
int main(int argc, char **argv) {
110
int main(int argc, char **argv) {
134
  struct config cfg;
111
  struct config cfg;
135
  unsigned short rmod_seg;
112
  unsigned short rmod_seg;
136
  unsigned short far *rmod_envseg;
113
  unsigned short far *rmod_envseg;
-
 
114
  int ecode = 0;
137
 
115
 
138
  parse_argv(&cfg, argc, argv);
116
  parse_argv(&cfg, argc, argv);
139
 
117
 
140
  rmod_seg = rmod_find();
118
  rmod_seg = rmod_find();
141
  if (rmod_seg == 0xffff) {
119
  if (rmod_seg == 0xffff) {
Line 218... Line 196...
218
    printf("got %u bytes of cmdline (%d args)\r\n", cmdline[-1], argcount);
196
    printf("got %u bytes of cmdline (%d args)\r\n", cmdline[-1], argcount);
219
    for (i = 0; i < argcount; i++) {
197
    for (i = 0; i < argcount; i++) {
220
      printf("arg #%d = '%s'\r\n", i, argvlist[i]);
198
      printf("arg #%d = '%s'\r\n", i, argvlist[i]);
221
    }
199
    }
222
 
200
 
223
    /* TODO is it an internal command? */
201
    /* is it about quitting? */
224
    if (strcmp(argvlist[0], "set") == 0) {
202
    if (imatch(argvlist[0], "exit")) break;
-
 
203
 
-
 
204
    /* try running it as an internal command */
225
      cmd_set(argcount, argvlist, *rmod_envseg);
205
    ecode = cmd_process(argcount, argvlist, *rmod_envseg);
226
      continue;
206
    if (ecode >= 0) continue;
227
    }
-
 
228
    if (strcmp(argvlist[0], "exit") == 0) break;
-
 
229
 
207
 
-
 
208
    /* must be an external command then */
230
    execvp(argvlist[0], argvlist);
209
    execvp(argvlist[0], argvlist);
231
 
210
 
232
    /* execvp() replaces the current process by the new one
211
    /* execvp() replaces the current process by the new one
233
    if I am still alive then external command failed to execute */
212
    if I am still alive then external command failed to execute */
234
    puts("Bad command or file name");
213
    puts("Bad command or file name");