Subversion Repositories SvarDOS

Rev

Rev 357 | Rev 364 | 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
#include "env.h"
9
 
10
 
357 mateuszvis 11
static int cmd_set(int argc, char const **argv, unsigned short env_seg, const char far *cmdline) {
352 mateuszvis 12
  char far *env = MK_FP(env_seg, 0);
13
  char buff[256];
14
  int i;
357 mateuszvis 15
  /* no arguments - display content */
16
  if (argc == 1) {
17
    while (*env != 0) {
18
      /* copy string to local buff for display */
19
      for (i = 0;; i++) {
20
        buff[i] = *env;
21
        env++;
22
        if (buff[i] == 0) break;
23
      }
24
      puts(buff);
352 mateuszvis 25
    }
357 mateuszvis 26
  } else if ((argc == 2) && (imatch(argv[1], "/?"))) {
27
    puts("TODO: help screen"); /* TODO */
361 mateuszvis 28
  } else { /* set variable (do not rely on argv, SET has its own rules...) */
357 mateuszvis 29
    const char far *ptr;
30
    char buff[256];
361 mateuszvis 31
    unsigned short i;
357 mateuszvis 32
    /* locate the first space */
33
    for (ptr = cmdline; *ptr != ' '; ptr++);
34
    /* now locate the first non-space: that's where the variable name begins */
35
    for (; *ptr == ' '; ptr++);
36
    /* copy variable to buff and switch it upercase */
37
    i = 0;
38
    for (; *ptr != '='; ptr++) {
39
      if (*ptr == '\r') goto syntax_err;
40
      buff[i] = *ptr;
41
      if ((buff[i] >= 'a') && (buff[i] <= 'z')) buff[i] -= ('a' - 'A');
42
      i++;
43
    }
44
 
361 mateuszvis 45
    /* copy value now */
357 mateuszvis 46
    while (*ptr != '\r') {
47
      buff[i++] = *ptr;
48
      ptr++;
49
    }
50
 
51
    /* terminate buff */
52
    buff[i] = 0;
53
 
361 mateuszvis 54
    /* commit variable to environment */
55
    i = env_setvar(env_seg, buff);
56
    if (i == ENV_INVSYNT) goto syntax_err;
57
    if (i == ENV_NOTENOM) puts("Not enough available space within the environment block");
352 mateuszvis 58
  }
357 mateuszvis 59
  return(-1);
352 mateuszvis 60
 
357 mateuszvis 61
  syntax_err:
62
 
63
  puts("Syntax error");
64
  return(-1);
352 mateuszvis 65
}