Subversion Repositories SvarDOS

Rev

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

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