Subversion Repositories SvarDOS

Rev

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

Rev 1137 Rev 1138
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
 * set [varname[=value]]
26
 * set [varname[=value]]
27
 *
27
 *
28
 * value cannot contain any '=' character, but it can contain spaces
28
 * value cannot contain any '=' character, but it can contain spaces
29
 * varname can also contain spaces
29
 * varname can also contain spaces
30
 */
30
 */
31
 
31
 
32
 
32
 
33
static enum cmd_result cmd_set(struct cmd_funcparam *p) {
33
static enum cmd_result cmd_set(struct cmd_funcparam *p) {
34
  char far *env = MK_FP(p->env_seg, 0);
34
  char far *env = MK_FP(p->env_seg, 0);
35
  char *buff = p->BUFFER;
35
  char *buff = p->BUFFER;
36
 
36
 
37
  if (cmd_ishlp(p)) {
37
  if (cmd_ishlp(p)) {
38
    nls_outputnl(23,0); /* "Displays, sets, or removes DOS environment variables"); */
38
    nls_outputnl(23,0); /* "Displays, sets, or removes DOS environment variables"); */
39
    outputnl("");
39
    outputnl("");
40
    nls_outputnl(23,1); /* "SET [variable=[string]]" */
40
    nls_outputnl(23,1); /* "SET [variable=[string]]" */
41
    outputnl("");
41
    outputnl("");
42
    nls_outputnl(23,2); /* "variable  Specifies the environment-variable name" */
42
    nls_outputnl(23,2); /* "variable  Specifies the environment-variable name" */
43
    nls_outputnl(23,3); /* "string    Specifies a series of characters to assign to the variable" */
43
    nls_outputnl(23,3); /* "string    Specifies a series of characters to assign to the variable" */
44
    outputnl("");
44
    outputnl("");
45
    nls_outputnl(23,4); /* "Type SET without parameters to display the current environment variables." */
45
    nls_outputnl(23,4); /* "Type SET without parameters to display the current environment variables." */
46
    return(CMD_OK);
46
    return(CMD_OK);
47
  }
47
  }
48
 
48
 
49
  /* no arguments - display content */
49
  /* no arguments - display content */
50
  if (p->argc == 0) {
50
  if (p->argc == 0) {
51
    while (*env != 0) {
51
    while (*env != 0) {
52
      unsigned short i;
52
      unsigned short i;
53
      /* copy string to local buff for display */
53
      /* copy string to local buff for display */
54
      for (i = 0;; i++) {
54
      for (i = 0;; i++) {
55
        buff[i] = *env;
55
        buff[i] = *env;
56
        env++;
56
        env++;
57
        if (buff[i] == 0) break;
57
        if (buff[i] == 0) break;
58
      }
58
      }
59
      outputnl(buff);
59
      outputnl(buff);
60
    }
60
    }
61
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
61
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
62
    const char far *ptr;
62
    const char far *ptr;
63
    unsigned short i;
63
    unsigned short i;
64
 
64
 
-
 
65
    /* locate the first space (note that cmdline separators should be sanitized
65
    /* locate the first space or tab */
66
     * to space only by now) */
66
    for (ptr = p->cmdline; ((*ptr != ' ') && (*ptr != '\t')); ptr++);
67
    for (ptr = p->cmdline; *ptr != ' '; ptr++);
67
 
68
 
68
    /* now locate the first non-space/non-tab: that's where the variable name begins */
69
    /* now locate the first non-space: that's where the variable name begins */
69
    for (; ((*ptr == ' ') || (*ptr == '\t')); ptr++);
70
    for (; *ptr == ' '; ptr++);
70
 
71
 
71
    /* copy variable name to buff */
72
    /* copy variable name to buff */
72
    i = 0;
73
    i = 0;
73
    for (; *ptr != '='; ptr++) {
74
    for (; *ptr != '='; ptr++) {
74
      if (*ptr == 0) goto syntax_err;
75
      if (*ptr == 0) goto syntax_err;
75
      buff[i++] = *ptr;
76
      buff[i++] = *ptr;
76
    }
77
    }
77
 
78
 
78
    /* make variable name all caps (country-dependend) */
79
    /* make variable name all caps (country-dependend) */
79
    buff[i] = 0;
80
    buff[i] = 0;
80
    nls_strtoup(buff);
81
    nls_strtoup(buff);
81
 
82
 
82
    /* copy value now */
83
    /* copy value now */
83
    while (*ptr != 0) {
84
    while (*ptr != 0) {
84
      buff[i++] = *ptr;
85
      buff[i++] = *ptr;
85
      ptr++;
86
      ptr++;
86
    }
87
    }
87
 
88
 
88
    /* terminate buff */
89
    /* terminate buff */
89
    buff[i] = 0;
90
    buff[i] = 0;
90
 
91
 
91
    /* commit variable to environment */
92
    /* commit variable to environment */
92
    i = env_setvar(p->env_seg, buff);
93
    i = env_setvar(p->env_seg, buff);
93
    if (i == ENV_INVSYNT) goto syntax_err;
94
    if (i == ENV_INVSYNT) goto syntax_err;
94
    if (i == ENV_NOTENOM) {
95
    if (i == ENV_NOTENOM) {
95
      nls_outputnl(23,5); /* "Not enough available space within the environment block" */
96
      nls_outputnl(23,5); /* "Not enough available space within the environment block" */
96
      return(CMD_FAIL);
97
      return(CMD_FAIL);
97
    }
98
    }
98
  }
99
  }
99
  return(CMD_OK);
100
  return(CMD_OK);
100
 
101
 
101
  syntax_err:
102
  syntax_err:
102
 
103
 
103
  nls_outputnl(0,1); /* "Invalid syntax" */
104
  nls_outputnl(0,1); /* "Invalid syntax" */
104
  return(CMD_FAIL);
105
  return(CMD_FAIL);
105
}
106
}
106
 
107