Subversion Repositories SvarDOS

Rev

Rev 373 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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