Subversion Repositories SvarDOS

Rev

Rev 462 | Rev 989 | Go to most recent revision | 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
 *
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
 
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)) {
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");
533 mateuszvis 45
    return(CMD_OK);
387 mateuszvis 46
  }
47
 
372 mateuszvis 48
  /* no parameter - display current path */
49
  if (p->argc == 0) {
50
    char far *curpath = env_lookup(p->env_seg, "PATH");
373 mateuszvis 51
    if (curpath == NULL) {
52
      outputnl("No Path");
53
    } else {
372 mateuszvis 54
      unsigned short i;
55
      for (i = 0;; i++) {
56
        buff[i] = curpath[i];
57
        if (buff[i] == 0) break;
58
      }
59
      outputnl(buff);
60
    }
533 mateuszvis 61
    return(CMD_FAIL);
372 mateuszvis 62
  }
63
 
64
  /* more than 1 parameter */
65
  if (p->argc > 1) {
66
    outputnl("Too many parameters");
533 mateuszvis 67
    return(CMD_FAIL);
372 mateuszvis 68
  }
69
 
70
  /* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
71
 
72
  /* reset the PATH string (PATH ;) */
73
  if (imatch(p->argv[0], ";")) {
74
    env_dropvar(p->env_seg, "PATH");
533 mateuszvis 75
    return(CMD_OK);
372 mateuszvis 76
  }
77
 
78
  /* otherwise set PATH to whatever is passed on command-line */
79
  {
80
    unsigned short i;
81
    strcpy(buff, "PATH=");
82
    for (i = 0;; i++) {
83
      buff[i + 5] = p->argv[0][i];
462 mateuszvis 84
      if (buff[i + 5] == 0) break;
372 mateuszvis 85
    }
86
    env_setvar(p->env_seg, buff);
87
  }
88
 
533 mateuszvis 89
  return(CMD_OK);
372 mateuszvis 90
}