Subversion Repositories SvarDOS

Rev

Rev 1731 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1731 Rev 1732
Line 136... Line 136...
136
 */
136
 */
137
int env_setvar(unsigned short env_seg, const char *v) {
137
int env_setvar(unsigned short env_seg, const char *v) {
138
  unsigned short envlen;
138
  unsigned short envlen;
139
  unsigned short vlen, veqpos;
139
  unsigned short vlen, veqpos;
140
  char far *env = MK_FP(env_seg, 0);
140
  char far *env = MK_FP(env_seg, 0);
141
 
-
 
142
  /* remove variable from environment, if already set */
141
  char far *alreadyexists;
143
  env_dropvar(env_seg, v);
142
  unsigned short alreadyexistslen;
144
 
143
 
145
  /* compute v length and find the position of the eq sign */
144
  /* compute v length and find the position of the eq sign */
146
  veqpos = 0xffff;
145
  veqpos = 0xffff;
147
  for (vlen = 0; v[vlen] != 0; vlen++) {
146
  for (vlen = 0; v[vlen] != 0; vlen++) {
148
    if (v[vlen] == '=') {
147
    if (v[vlen] == '=') {
149
      if (veqpos != 0xffff) return(ENV_INVSYNT); /* equal sign is forbidden in value */
148
      if (veqpos != 0xffff) return(ENV_INVSYNT); /* equal sign is forbidden in value */
150
      veqpos = vlen;
149
      veqpos = vlen;
151
    }
150
    }
152
  }
151
  }
153
 
152
 
154
  /* if variable empty, stop here */
-
 
155
  if (veqpos == vlen - 1) return(ENV_SUCCESS);
-
 
156
 
-
 
157
  /* get length of the current environment */
153
  /* get length of the current environment */
158
  envlen = env_getcurlen(env_seg);
154
  envlen = env_getcurlen(env_seg);
159
 
155
 
-
 
156
  /* does the variable already exist? */
-
 
157
  alreadyexists = env_lookup(env_seg, v);
-
 
158
  alreadyexistslen = 0;
-
 
159
  if (alreadyexists != NULL) {
-
 
160
    while (alreadyexists[alreadyexistslen] != 0) alreadyexistslen++;
-
 
161
  }
-
 
162
 
160
  /* do I have enough env space for the new var? */
163
  /* do I have enough env space for the new var? */
161
  if (envlen + vlen + 2 >= env_allocsz(env_seg)) return(ENV_NOTENOM);
164
  if (envlen + vlen + 3 - alreadyexistslen >= env_allocsz(env_seg)) {
-
 
165
    return(ENV_NOTENOM);
-
 
166
  }
-
 
167
 
-
 
168
  /* remove variable from environment if already set and recompute environment's length */
-
 
169
  env_dropvar(env_seg, v);
-
 
170
  envlen = env_getcurlen(env_seg);
-
 
171
 
-
 
172
  /* if variable empty, stop here */
-
 
173
  if (veqpos == vlen - 1) return(ENV_SUCCESS);
162
 
174
 
163
  /* write the new variable (with its NULL terminator) to environment tail */
175
  /* write the new variable (with its NULL terminator) to environment tail */
164
  _fmemcpy(env + envlen, v, vlen + 1);
176
  _fmemcpy(env + envlen, v, vlen + 1);
165
 
177
 
166
  /* add the environment's NULL terminator */
178
  /* add the environment's NULL terminator */