Subversion Repositories SvarDOS

Rev

Rev 378 | Rev 397 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 mateuszvis 1
/*
357 mateuszvis 2
 * set [varname[=value]]
352 mateuszvis 3
 *
357 mateuszvis 4
 * value cannot contain any '=' character, but it can contain spaces
5
 * varname can also contain spaces
352 mateuszvis 6
 */
7
 
361 mateuszvis 8
 
372 mateuszvis 9
static int cmd_set(struct cmd_funcparam *p) {
364 mateuszvis 10
  char far *env = MK_FP(p->env_seg, 0);
372 mateuszvis 11
  char *buff = p->BUFFER;
387 mateuszvis 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
 
357 mateuszvis 24
  /* no arguments - display content */
364 mateuszvis 25
  if (p->argc == 0) {
357 mateuszvis 26
    while (*env != 0) {
372 mateuszvis 27
      unsigned short i;
357 mateuszvis 28
      /* copy string to local buff for display */
29
      for (i = 0;; i++) {
30
        buff[i] = *env;
31
        env++;
32
        if (buff[i] == 0) break;
33
      }
372 mateuszvis 34
      outputnl(buff);
352 mateuszvis 35
    }
361 mateuszvis 36
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
357 mateuszvis 37
    const char far *ptr;
361 mateuszvis 38
    unsigned short i;
357 mateuszvis 39
    /* locate the first space */
364 mateuszvis 40
    for (ptr = p->cmdline; *ptr != ' '; ptr++);
357 mateuszvis 41
    /* now locate the first non-space: that's where the variable name begins */
42
    for (; *ptr == ' '; ptr++);
43
    /* copy variable to buff and switch it upercase */
44
    i = 0;
45
    for (; *ptr != '='; ptr++) {
46
      if (*ptr == '\r') goto syntax_err;
47
      buff[i] = *ptr;
48
      if ((buff[i] >= 'a') && (buff[i] <= 'z')) buff[i] -= ('a' - 'A');
49
      i++;
50
    }
51
 
361 mateuszvis 52
    /* copy value now */
357 mateuszvis 53
    while (*ptr != '\r') {
54
      buff[i++] = *ptr;
55
      ptr++;
56
    }
57
 
58
    /* terminate buff */
59
    buff[i] = 0;
60
 
361 mateuszvis 61
    /* commit variable to environment */
364 mateuszvis 62
    i = env_setvar(p->env_seg, buff);
361 mateuszvis 63
    if (i == ENV_INVSYNT) goto syntax_err;
369 mateuszvis 64
    if (i == ENV_NOTENOM) outputnl("Not enough available space within the environment block");
352 mateuszvis 65
  }
357 mateuszvis 66
  return(-1);
352 mateuszvis 67
 
357 mateuszvis 68
  syntax_err:
69
 
369 mateuszvis 70
  outputnl("Syntax error");
357 mateuszvis 71
  return(-1);
352 mateuszvis 72
}