Subversion Repositories SvarDOS

Rev

Rev 397 | Rev 435 | 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
 * set [varname[=value]]
26
 * set [varname[=value]]
3
 *
27
 *
4
 * value cannot contain any '=' character, but it can contain spaces
28
 * value cannot contain any '=' character, but it can contain spaces
5
 * varname can also contain spaces
29
 * varname can also contain spaces
6
 */
30
 */
7
 
31
 
8
 
32
 
9
static int cmd_set(struct cmd_funcparam *p) {
33
static int cmd_set(struct cmd_funcparam *p) {
10
  char far *env = MK_FP(p->env_seg, 0);
34
  char far *env = MK_FP(p->env_seg, 0);
11
  char *buff = p->BUFFER;
35
  char *buff = p->BUFFER;
12
 
36
 
13
  if (cmd_ishlp(p)) {
37
  if (cmd_ishlp(p)) {
14
    outputnl("Displays, sets, or removes DOS environment variables");
38
    outputnl("Displays, sets, or removes DOS environment variables");
15
    outputnl("");
39
    outputnl("");
16
    outputnl("SET [variable=[string]]");
40
    outputnl("SET [variable=[string]]");
17
    outputnl("");
41
    outputnl("");
18
    outputnl("variable  Specifies the environment-variable name");
42
    outputnl("variable  Specifies the environment-variable name");
19
    outputnl("string    Specifies a series of characters to assign to the variable");
43
    outputnl("string    Specifies a series of characters to assign to the variable");
20
    outputnl("");
44
    outputnl("");
21
    outputnl("Type SET without parameters to display the current environment variables.");
45
    outputnl("Type SET without parameters to display the current environment variables.");
22
  }
46
  }
23
 
47
 
24
  /* no arguments - display content */
48
  /* no arguments - display content */
25
  if (p->argc == 0) {
49
  if (p->argc == 0) {
26
    while (*env != 0) {
50
    while (*env != 0) {
27
      unsigned short i;
51
      unsigned short i;
28
      /* copy string to local buff for display */
52
      /* copy string to local buff for display */
29
      for (i = 0;; i++) {
53
      for (i = 0;; i++) {
30
        buff[i] = *env;
54
        buff[i] = *env;
31
        env++;
55
        env++;
32
        if (buff[i] == 0) break;
56
        if (buff[i] == 0) break;
33
      }
57
      }
34
      outputnl(buff);
58
      outputnl(buff);
35
    }
59
    }
36
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
60
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
37
    const char far *ptr;
61
    const char far *ptr;
38
    unsigned short i;
62
    unsigned short i;
39
    /* locate the first space */
63
    /* locate the first space */
40
    for (ptr = p->cmdline; *ptr != ' '; ptr++);
64
    for (ptr = p->cmdline; *ptr != ' '; ptr++);
41
    /* now locate the first non-space: that's where the variable name begins */
65
    /* now locate the first non-space: that's where the variable name begins */
42
    for (; *ptr == ' '; ptr++);
66
    for (; *ptr == ' '; ptr++);
43
    /* copy variable to buff and switch it upercase */
67
    /* copy variable to buff and switch it upercase */
44
    i = 0;
68
    i = 0;
45
    for (; *ptr != '='; ptr++) {
69
    for (; *ptr != '='; ptr++) {
46
      if (*ptr == '\r') goto syntax_err;
70
      if (*ptr == '\r') goto syntax_err;
47
      buff[i] = *ptr;
71
      buff[i] = *ptr;
48
      if ((buff[i] >= 'a') && (buff[i] <= 'z')) buff[i] -= ('a' - 'A');
72
      if ((buff[i] >= 'a') && (buff[i] <= 'z')) buff[i] -= ('a' - 'A');
49
      i++;
73
      i++;
50
    }
74
    }
51
 
75
 
52
    /* copy value now */
76
    /* copy value now */
53
    while (*ptr != '\r') {
77
    while (*ptr != '\r') {
54
      buff[i++] = *ptr;
78
      buff[i++] = *ptr;
55
      ptr++;
79
      ptr++;
56
    }
80
    }
57
 
81
 
58
    /* terminate buff */
82
    /* terminate buff */
59
    buff[i] = 0;
83
    buff[i] = 0;
60
 
84
 
61
    /* commit variable to environment */
85
    /* commit variable to environment */
62
    i = env_setvar(p->env_seg, buff);
86
    i = env_setvar(p->env_seg, buff);
63
    if (i == ENV_INVSYNT) goto syntax_err;
87
    if (i == ENV_INVSYNT) goto syntax_err;
64
    if (i == ENV_NOTENOM) outputnl("Not enough available space within the environment block");
88
    if (i == ENV_NOTENOM) outputnl("Not enough available space within the environment block");
65
  }
89
  }
66
  return(-1);
90
  return(-1);
67
 
91
 
68
  syntax_err:
92
  syntax_err:
69
 
93
 
70
  outputnl("Syntax error");
94
  outputnl("Syntax error");
71
  return(-1);
95
  return(-1);
72
}
96
}
73
 
97