karl@sugar.UUCP (11/29/87)
Am I having fun yet? Here's the context diffs for a new command, 'set-environment', which lets one set environment variables within uEMACS (you can already read them with the &env function) Usage: set-environment environment_variable_name value example: set-environment HOME "/usr/karl" cooler example: set-environment PATH &cat &env PATH ":/usr/local/bin" Note that the code is well behaved in that it follows the uEMACS #ifdef for environment variable support, ENVFUNC. 'putenv' is the key library routine that must exist for this to work. *** efunc.orig Sun Nov 29 01:45:11 1987 --- efunc.h Sun Nov 29 01:51:51 1987 *************** *** 196,197 #endif #if PROC --- 196,200 ----- #endif + #if ENVFUNC + extern int setenv(); /* set o.s. environment variable */ + #endif #if PROC *************** *** 389,390 {"set", setvar}, #if CRYPT --- 392,396 ----- {"set", setvar}, + #if ENVFUNC + {"set-environment", setenv}, + #endif #if CRYPT *** eval.orig Sat Nov 28 18:36:23 1987 --- eval.c Sun Nov 29 02:58:08 1987 *************** *** 31,36 static char result[2 * NSTRING]; /* string result */ char *flook(); /* look file up on path */ char *xlat(); /* translate a char string */ #if ENVFUNC char *getenv(); /* get environment string */ #endif --- 31,37 ----- static char result[2 * NSTRING]; /* string result */ char *flook(); /* look file up on path */ char *xlat(); /* translate a char string */ + int itmp; /* tmp variable */ #if ENVFUNC char *getenv(); /* get environment string */ #endif *************** *** 334,339 /* and return it */ return(status); } findvar(var, vd, size) /* find a variables type and name */ --- 337,384 ----- /* and return it */ return(status); } + + #if ENVFUNC + int setenv(f, n) /* set an o.s. environment variable */ + int f; /* default flag */ + int n; /* numeric arg (can overide prompted value) */ + { + register int status; /* status return */ + VDESC vd; /* variable num/type */ + char var[NVSIZE+1]; /* name of variable to fetch */ + char value[NSTRING]; /* value to set variable to */ + char *envstr; + + /* first get the variable to set.. */ + if (clexec == FALSE) { + status = mlreply("Environment variable to set: ", &var[0], NVSIZE); + if (status != TRUE) + return(status); + } else { /* macro line argument */ + /* grab token and skip it */ + execstr = token(execstr, var, NVSIZE + 1); + } + + /* var contains the variable name text */ + + /* get the value for that variable */ + if (f == TRUE) + strcpy(value, itoa(n)); + else { + status = mlreply("Value: ", &value[0], NSTRING); + if (status != TRUE) + return(status); + } + + /* allocate memory for the new environment variable */ + if ((envstr = malloc(strlen(var) + strlen(value) + 2)) == NULL) + return(FALSE); + /* format the environment string */ + sprintf(envstr,"%s=%s",var,value); + /* and set the appropriate value */ + return(!putenv(envstr)); + } + #endif findvar(var, vd, size) /* find a variables type and name */ --