Subversion Repositories SvarDOS

Rev

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

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