Subversion Repositories SvarDOS

Rev

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

Rev 397 Rev 421
-
 
1
/* This file is part of the SvarCOM project and is published under the terms
-
 
2
 * of the MIT license.
-
 
3
 *
-
 
4
 * Copyright (C) 2021 Mateusz Viste
-
 
5
 *
-
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
-
 
7
 * copy of this software and associated documentation files (the "Software"),
-
 
8
 * to deal in the Software without restriction, including without limitation
-
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
-
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
-
 
11
 * Software is furnished to do so, subject to the following conditions:
-
 
12
 *
-
 
13
 * The above copyright notice and this permission notice shall be included in
-
 
14
 * all copies or substantial portions of the Software.
-
 
15
 *
-
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-
 
22
 * DEALINGS IN THE SOFTWARE.
-
 
23
 */
-
 
24
 
1
/*
25
/*
2
 * path
26
 * path
3
 *
27
 *
4
 * Displays or sets a search path for executable files.
28
 * Displays or sets a search path for executable files.
5
 */
29
 */
6
 
30
 
7
static int cmd_path(struct cmd_funcparam *p) {
31
static int cmd_path(struct cmd_funcparam *p) {
8
  char *buff = p->BUFFER;
32
  char *buff = p->BUFFER;
9
 
33
 
10
  /* help screen (/?) */
34
  /* help screen (/?) */
11
  if (cmd_ishlp(p)) {
35
  if (cmd_ishlp(p)) {
12
    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"
13
           "\r\n"
37
           "\r\n"
14
           "PATH [[drive:]path[;...]]\r\n"
38
           "PATH [[drive:]path[;...]]\r\n"
15
           "PATH ;\r\n"
39
           "PATH ;\r\n"
16
           "\r\n"
40
           "\r\n"
17
           "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"
18
           "only in the current directory.\r\n"
42
           "only in the current directory.\r\n"
19
           "\r\n"
43
           "\r\n"
20
           "Type PATH without parameters to display the current path.\r\n");
44
           "Type PATH without parameters to display the current path.\r\n");
21
    return(-1);
45
    return(-1);
22
  }
46
  }
23
 
47
 
24
  /* no parameter - display current path */
48
  /* no parameter - display current path */
25
  if (p->argc == 0) {
49
  if (p->argc == 0) {
26
    char far *curpath = env_lookup(p->env_seg, "PATH");
50
    char far *curpath = env_lookup(p->env_seg, "PATH");
27
    if (curpath == NULL) {
51
    if (curpath == NULL) {
28
      outputnl("No Path");
52
      outputnl("No Path");
29
    } else {
53
    } else {
30
      unsigned short i;
54
      unsigned short i;
31
      for (i = 0;; i++) {
55
      for (i = 0;; i++) {
32
        buff[i] = curpath[i];
56
        buff[i] = curpath[i];
33
        if (buff[i] == 0) break;
57
        if (buff[i] == 0) break;
34
      }
58
      }
35
      outputnl(buff);
59
      outputnl(buff);
36
    }
60
    }
37
    return(-1);
61
    return(-1);
38
  }
62
  }
39
 
63
 
40
  /* more than 1 parameter */
64
  /* more than 1 parameter */
41
  if (p->argc > 1) {
65
  if (p->argc > 1) {
42
    outputnl("Too many parameters");
66
    outputnl("Too many parameters");
43
    return(-1);
67
    return(-1);
44
  }
68
  }
45
 
69
 
46
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
70
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
47
 
71
 
48
  /* reset the PATH string (PATH ;) */
72
  /* reset the PATH string (PATH ;) */
49
  if (imatch(p->argv[0], ";")) {
73
  if (imatch(p->argv[0], ";")) {
50
    env_dropvar(p->env_seg, "PATH");
74
    env_dropvar(p->env_seg, "PATH");
51
    return(-1);
75
    return(-1);
52
  }
76
  }
53
 
77
 
54
  /* otherwise set PATH to whatever is passed on command-line */
78
  /* otherwise set PATH to whatever is passed on command-line */
55
  {
79
  {
56
    unsigned short i;
80
    unsigned short i;
57
    strcpy(buff, "PATH=");
81
    strcpy(buff, "PATH=");
58
    for (i = 0;; i++) {
82
    for (i = 0;; i++) {
59
      buff[i + 5] = p->argv[0][i];
83
      buff[i + 5] = p->argv[0][i];
60
      if (buff[i + 5] == '\r') break;
84
      if (buff[i + 5] == '\r') break;
61
    }
85
    }
62
    buff[i + 5] = 0;
86
    buff[i + 5] = 0;
63
    env_setvar(p->env_seg, buff);
87
    env_setvar(p->env_seg, buff);
64
  }
88
  }
65
 
89
 
66
  return(-1);
90
  return(-1);
67
}
91
}
68
 
92