Subversion Repositories SvarDOS

Rev

Rev 372 | Rev 387 | Go to most recent revision | Details | Compare with Previous | 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");
373 mateuszvis 13
    if (curpath == NULL) {
14
      outputnl("No Path");
15
    } else {
372 mateuszvis 16
      unsigned short i;
17
      for (i = 0;; i++) {
18
        buff[i] = curpath[i];
19
        if (buff[i] == 0) break;
20
      }
21
      outputnl(buff);
22
    }
23
    return(-1);
24
  }
25
 
26
  /* more than 1 parameter */
27
  if (p->argc > 1) {
28
    outputnl("Too many parameters");
29
    return(-1);
30
  }
31
 
32
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
33
 
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 ;) */
49
  if (imatch(p->argv[0], ";")) {
50
    env_dropvar(p->env_seg, "PATH");
51
    return(-1);
52
  }
53
 
54
  /* otherwise set PATH to whatever is passed on command-line */
55
  {
56
    unsigned short i;
57
    strcpy(buff, "PATH=");
58
    for (i = 0;; i++) {
59
      buff[i + 5] = p->argv[0][i];
60
      if (buff[i + 5] == '\r') break;
61
    }
62
    buff[i + 5] = 0;
63
    env_setvar(p->env_seg, buff);
64
  }
65
 
66
  return(-1);
67
}