Subversion Repositories SvarDOS

Rev

Rev 378 | Rev 397 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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