Subversion Repositories SvarDOS

Rev

Rev 372 | Rev 387 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 372 Rev 373
1
/*
1
/*
2
 * path
2
 * path
3
 *
3
 *
4
 * Displays or sets a search path for executable files.
4
 * Displays or sets a search path for executable files.
5
 */
5
 */
6
 
6
 
7
static int cmd_path(struct cmd_funcparam *p) {
7
static int cmd_path(struct cmd_funcparam *p) {
8
  char *buff = p->BUFFER;
8
  char *buff = p->BUFFER;
9
 
9
 
10
  /* no parameter - display current path */
10
  /* no parameter - display current path */
11
  if (p->argc == 0) {
11
  if (p->argc == 0) {
12
    char far *curpath = env_lookup(p->env_seg, "PATH");
12
    char far *curpath = env_lookup(p->env_seg, "PATH");
13
    if (curpath != NULL) {
13
    if (curpath == NULL) {
-
 
14
      outputnl("No Path");
-
 
15
    } else {
14
      unsigned short i;
16
      unsigned short i;
15
      for (i = 0;; i++) {
17
      for (i = 0;; i++) {
16
        buff[i] = curpath[i];
18
        buff[i] = curpath[i];
17
        if (buff[i] == 0) break;
19
        if (buff[i] == 0) break;
18
      }
20
      }
19
      outputnl(buff);
21
      outputnl(buff);
20
    }
22
    }
21
    return(-1);
23
    return(-1);
22
  }
24
  }
23
 
25
 
24
  /* more than 1 parameter */
26
  /* more than 1 parameter */
25
  if (p->argc > 1) {
27
  if (p->argc > 1) {
26
    outputnl("Too many parameters");
28
    outputnl("Too many parameters");
27
    return(-1);
29
    return(-1);
28
  }
30
  }
29
 
31
 
30
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
32
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
31
 
33
 
32
  /* help screen (/?) */
34
  /* help screen (/?) */
33
  if (imatch(p->argv[0], "/?")) {
35
  if (imatch(p->argv[0], "/?")) {
34
    output("Displays or sets a search path for executable files.\r\n"
36
    output("Displays or sets a search path for executable files.\r\n"
35
           "\r\n"
37
           "\r\n"
36
           "PATH [[drive:]path[;...]]\r\n"
38
           "PATH [[drive:]path[;...]]\r\n"
37
           "PATH ;\r\n"
39
           "PATH ;\r\n"
38
           "\r\n"
40
           "\r\n"
39
           "Type PATH ; to clear all search-path settings and direct DOS to search\r\n"
41
           "Type PATH ; to clear all search-path settings and direct DOS to search\r\n"
40
           "only in the current directory.\r\n"
42
           "only in the current directory.\r\n"
41
           "\r\n"
43
           "\r\n"
42
           "Type PATH without parameters to display the current path.\r\n");
44
           "Type PATH without parameters to display the current path.\r\n");
43
    return(-1);
45
    return(-1);
44
  }
46
  }
45
 
47
 
46
  /* reset the PATH string (PATH ;) */
48
  /* reset the PATH string (PATH ;) */
47
  if (imatch(p->argv[0], ";")) {
49
  if (imatch(p->argv[0], ";")) {
48
    env_dropvar(p->env_seg, "PATH");
50
    env_dropvar(p->env_seg, "PATH");
49
    return(-1);
51
    return(-1);
50
  }
52
  }
51
 
53
 
52
  /* otherwise set PATH to whatever is passed on command-line */
54
  /* otherwise set PATH to whatever is passed on command-line */
53
  {
55
  {
54
    unsigned short i;
56
    unsigned short i;
55
    strcpy(buff, "PATH=");
57
    strcpy(buff, "PATH=");
56
    for (i = 0;; i++) {
58
    for (i = 0;; i++) {
57
      buff[i + 5] = p->argv[0][i];
59
      buff[i + 5] = p->argv[0][i];
58
      if (buff[i + 5] == '\r') break;
60
      if (buff[i + 5] == '\r') break;
59
    }
61
    }
60
    buff[i + 5] = 0;
62
    buff[i + 5] = 0;
61
    outputnl("---");
-
 
62
    outputnl(buff);
-
 
63
    outputnl("---");
-
 
64
    env_setvar(p->env_seg, buff);
63
    env_setvar(p->env_seg, buff);
65
  }
64
  }
66
 
65
 
67
  return(-1);
66
  return(-1);
68
}
67
}
69
 
68