Subversion Repositories SvarDOS

Rev

Rev 989 | Details | Compare with Previous | Last modification | View Log | RSS feed

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