/[ascend]/trunk/ascend/utilities/ascEnvVar.c
ViewVC logotype

Diff of /trunk/ascend/utilities/ascEnvVar.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2524 by jpye, Thu Jan 19 21:36:01 2012 UTC revision 2525 by jpye, Thu Jan 19 22:01:31 2012 UTC
# Line 313  int Asc_PutEnv(CONST char *envstring) Line 313  int Asc_PutEnv(CONST char *envstring)
313    
314    putenvstring = g_path_var;    putenvstring = g_path_var;
315    SNPRINTF(putenvstring, MAX_ENV_VAR_LENGTH, "%s", envstring);    SNPRINTF(putenvstring, MAX_ENV_VAR_LENGTH, "%s", envstring);
316    
317    /* trim leading whitespace */    /* trim leading whitespace */
318    while (isspace(putenvstring[0])) {    while(isspace(putenvstring[0])) {
319      putenvstring++;      putenvstring++;
320    }    }
321    
322    /* locate '=' or EOS, counting whitespace along the way */    /* locate '=' or EOS, counting whitespace along the way */
323    for (c = 0; putenvstring[c] !='\0' && putenvstring[c] != '='; c++) {    for(c = 0; putenvstring[c] !='\0' && putenvstring[c] != '='; c++){
324      if (isspace(putenvstring[c])) {      if(isspace(putenvstring[c])){
325        spcseen++;        spcseen++;
326      }      }
327    }    }
328    
329    /* check for empty rhs */    /* check for empty rhs */
330    if (putenvstring[c] == '\0') {    if(putenvstring[c] == '\0'){
331      return 1;      return 1;
332    }    }
333    rhs = c;    rhs = c;
334    
335    if(c == 0){    if(c == 0){
336      /* '=' is at start of strong */      /* '=' is at start of string */
337      return 1;      return 1;
338    }    }
339    
340    /* backup space before = */    /* backup space before = */
341    while (isspace(putenvstring[c-1])) {    while(isspace(putenvstring[c-1])){
342      c--;      c--;
343      spcseen--;      spcseen--;
344    }    }
345    /* check for no spaces in keepname */    /* check for no spaces in keepname */
346    if (spcseen) {    if(spcseen){
347      return 1;      return 1;
348    }    }
349    keepname = ASC_NEW_ARRAY(char,c+1);    keepname = ASC_NEW_ARRAY(char,c+1);
350    if (keepname == NULL) {    if(keepname == NULL){
351      return 1;      return 1;
352    }    }
353    strncpy(keepname,putenvstring,c);    strncpy(keepname,putenvstring,c);
354    keepname[c] = '\0';    keepname[c] = '\0';
355    /* delete the old variable if it was already assigned */    /* delete the old variable if it was already assigned */
356    ev = FindEnvVar(keepname);    ev = FindEnvVar(keepname);
357    if (ev!=NULL) {    if(ev!=NULL){
358      DeleteEnvVar(keepname);      DeleteEnvVar(keepname);
359    }    }
360    ev = CreateEnvVar(keepname);    ev = CreateEnvVar(keepname);
361    if (ev == NULL) {  
362      if(ev == NULL){
363      ascfree(keepname);      ascfree(keepname);
364      return 1;      return 1;
365    }    }
# Line 363  int Asc_PutEnv(CONST char *envstring) Line 367  int Asc_PutEnv(CONST char *envstring)
367    AppendEnvVar(g_env_list,ev);    AppendEnvVar(g_env_list,ev);
368    path = putenvstring + rhs + 1; /* got past the '=' */    path = putenvstring + rhs + 1; /* got past the '=' */
369    
370    while( isspace( *path ) ) {    while(isspace(*path)){
371      path++;      path++;
372    }    }
373    while( *path != '\0' ) {    while(*path != '\0'){
374      length = 0;      length = 0;
375      /* copy the directory from path to the g_path_var */      /* copy the directory from path to the g_path_var */
376      while(( *path != PATHDIV ) && ( *path != '\0' )) {      while((*path != PATHDIV) && (*path != '\0')){
377        g_path_var[length++] = *(path++);        g_path_var[length++] = *(path++);
378      }      }
379      while (( length > 0 ) && isspace(g_path_var[length-1])) {      while((length > 0) && isspace(g_path_var[length-1])){
380        length--;        length--;
381      }      }
382      if ( length > 0) {      if(length > 0){
383        g_path_var[length++] = '\0';        g_path_var[length++] = '\0';
384        if (Asc_AppendPath(keepname,g_path_var)!=0) {        if(Asc_AppendPath(keepname,g_path_var)!=0) {
385          return 1;          return 1;
386        }        }
387      }      }
388      while( isspace(*path) || ( *path == PATHDIV ) ) path++;      while(isspace(*path) || ( *path == PATHDIV))path++;
389    }    }
390    return 0;    return 0;
391  }  }

Legend:
Removed from v.2524  
changed lines
  Added in v.2525

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22