Subversion Repositories SvarDOS

Rev

Rev 989 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 989 Rev 1140
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-2022 Mateusz Viste
4
 * Copyright (C) 2021-2022 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 enum cmd_result 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
    nls_outputnl(27,0); /* "Displays or sets a search path for executable files." */
36
    nls_outputnl(27,0); /* "Displays or sets a search path for executable files." */
37
    outputnl("");
37
    outputnl("");
38
    nls_outputnl(27,1); /* "PATH [[drive:]path[;...]]" */
38
    nls_outputnl(27,1); /* "PATH [[drive:]path[;...]]" */
39
    outputnl("PATH ;");
39
    outputnl("PATH ;");
40
    outputnl("");
40
    outputnl("");
41
    nls_outputnl(27,2); /* "Type PATH ; to clear all search-path settings and (...)" */
41
    nls_outputnl(27,2); /* "Type PATH ; to clear all search-path settings and (...)" */
42
    outputnl("");
42
    outputnl("");
43
    nls_outputnl(27,3); /* "Type PATH without parameters to display the current path." */
43
    nls_outputnl(27,3); /* "Type PATH without parameters to display the current path." */
44
    return(CMD_OK);
44
    return(CMD_OK);
45
  }
45
  }
46
 
46
 
47
  /* no parameter - display current path */
47
  /* no parameter - display current path */
48
  if (p->argc == 0) {
48
  if (p->argc == 0) {
49
    char far *curpath = env_lookup(p->env_seg, "PATH");
49
    char far *curpath = env_lookup(p->env_seg, "PATH");
50
    if (curpath == NULL) {
50
    if (curpath == NULL) {
51
      nls_outputnl(27,4); /* "No Path" */
51
      nls_outputnl(27,4); /* "No Path" */
52
    } else {
52
    } else {
53
      unsigned short i;
53
      unsigned short i;
54
      for (i = 0;; i++) {
54
      for (i = 0;; i++) {
55
        buff[i] = curpath[i];
55
        buff[i] = curpath[i];
56
        if (buff[i] == 0) break;
56
        if (buff[i] == 0) break;
57
      }
57
      }
58
      outputnl(buff);
58
      outputnl(buff);
59
    }
59
    }
60
    return(CMD_FAIL);
60
    return(CMD_FAIL);
61
  }
61
  }
62
 
62
 
63
  /* more than 1 parameter */
63
  /* more than 1 parameter */
64
  if (p->argc > 1) {
64
  if (p->argc > 1) {
65
    nls_outputnl(0,4); /* "Too many parameters" */
65
    nls_outputnl(0,4); /* "Too many parameters" */
66
    return(CMD_FAIL);
66
    return(CMD_FAIL);
67
  }
67
  }
68
 
68
 
69
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
69
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
70
 
70
 
71
  /* reset the PATH string (PATH ;) */
71
  /* reset the PATH string (PATH ;) */
72
  if (imatch(p->argv[0], ";")) {
72
  if (imatch(p->argv[0], ";")) {
73
    env_dropvar(p->env_seg, "PATH");
73
    env_dropvar(p->env_seg, "PATH");
74
    return(CMD_OK);
74
    return(CMD_OK);
75
  }
75
  }
76
 
76
 
77
  /* otherwise set PATH to whatever is passed on command-line */
77
  /* otherwise set PATH to whatever is passed on command-line */
78
  {
78
  {
79
    unsigned short i;
79
    unsigned short i;
80
    strcpy(buff, "PATH=");
80
    strcpy(buff, "PATH=");
81
    for (i = 0;; i++) {
81
    for (i = 0;; i++) {
82
      buff[i + 5] = p->argv[0][i];
82
      buff[i + 5] = p->argv[0][i];
83
      if (buff[i + 5] == 0) break;
83
      if (buff[i + 5] == 0) break;
84
    }
84
    }
-
 
85
    nls_strtoup(buff); /* upcase path, ref: https://osdn.net/projects/svardos/ticket/44146 */
85
    env_setvar(p->env_seg, buff);
86
    env_setvar(p->env_seg, buff);
86
  }
87
  }
87
 
88
 
88
  return(CMD_OK);
89
  return(CMD_OK);
89
}
90
}
90
 
91