icewm/src/Makefile.in | 2 +- icewm/src/env.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ icewm/src/env.h | 17 +++++++++++++ icewm/src/wmprog.cc | 3 ++ icewm/src/yconfig.cc | 2 + 5 files changed, 84 insertions(+), 1 deletions(-) diff --git a/icewm/src/Makefile.in b/icewm/src/Makefile.in index 1b7b07b..302d7cd 100644 --- a/icewm/src/Makefile.in +++ b/icewm/src/Makefile.in @@ -52,7 +52,7 @@ libice_OBJS = ref.o \ yapp.o yxapp.o ytimer.o ywindow.o ypaint.o ypopup.o \ misc.o ycursor.o ysocket.o \ ypaths.o ypixbuf.o ylocale.o yarray.o ypipereader.o \ - yxembed.o yconfig.o yprefs.o \ + yxembed.o yconfig.o yprefs.o env.o \ yfont.o yfontcore.o yfontxft.o \ yimage.o \ ytooltip.o # FIXME diff --git a/icewm/src/env.cc b/icewm/src/env.cc new file mode 100644 index 0000000..45da985 --- /dev/null +++ b/icewm/src/env.cc @@ -0,0 +1,61 @@ +/* Clinton Work - November 29, 1999 - Expand environment variables. */ + +#include "env.h" +#include + +/* +int main(int argc, char **argv) + { + char cmd[256]; + + if (argc < 2) + { + fprintf(stderr,"Syntax: env prog\n"); + exit(1); + } + strcpy(cmd,argv[1]); + + printf("Before: %s\n",cmd); + printf("After: %s\n", envExpand(cmd) ); + } +*/ + +/* +This function takes the given strings and expands any environment variables +within it. +*/ +char * envExpand(char *str) + { + char var[64], result[1024] = ""; + char *cur = str, *name, *env, *add = result; + while (cur && *cur) + { + /* Start of environment variable. */ + if ( (*cur == '$') && (*(cur+1) != '$') ) + { + name = var; + cur++; + /* Name must have alpha-num characters. */ + while(*cur && isalpha(*cur)) + { *name++ = *cur++; } + *name = '\0'; +/* printf("name = %s\n",name); */ + env = getenv(var); + /* If the env variable exists. */ + if (env != NULL) + { + strcat(result,env); + add += strlen(env); + } + } + else if ( (*cur == '$') && (*(cur+1) == '$') ) + { *add++ = '$'; cur +=2; continue; } + + *add++ = *cur++; + } + + *add = '\0'; +/* printf("Result: %s\n",result); */ + strcpy(str,result); + return(str); + } diff --git a/icewm/src/env.h b/icewm/src/env.h new file mode 100644 index 0000000..b448b49 --- /dev/null +++ b/icewm/src/env.h @@ -0,0 +1,17 @@ + +#ifndef FIX_ENV_H +#define FIX_ENV_H + +#include +#include +#include +#include + +extern "C" { + +char * envExpand(char *str); + +} + +#endif + diff --git a/icewm/src/wmprog.cc b/icewm/src/wmprog.cc index 4f115f0..9840984 100644 --- a/icewm/src/wmprog.cc +++ b/icewm/src/wmprog.cc @@ -29,6 +29,7 @@ #include "wmtaskbar.h" #include "yicon.h" #include "intl.h" +#include "env.h" extern bool parseKey(const char *arg, KeySym *key, unsigned int *mod); @@ -282,6 +283,8 @@ char *parseMenus(char *data, ObjectContainer *container) { #ifndef LITE if (icons[0] != '-') icon = YIcon::getIcon(icons); #endif + envExpand(command); + DProgram * prog = DProgram::newProgram(name, icon, word[1] == 'e', word[1] == 'u' ? wmclass : 0, diff --git a/icewm/src/yconfig.cc b/icewm/src/yconfig.cc index 5537742..9d00280 100644 --- a/icewm/src/yconfig.cc +++ b/icewm/src/yconfig.cc @@ -7,6 +7,7 @@ #include "sysdep.h" #include "binascii.h" #include "intl.h" +#include "env.h" char * findPath(const char *path, int mode, const char *name, bool /*path_relative*/) { /// TODO #warning "fix limited path length" @@ -329,6 +330,7 @@ char *parseOption(cfoption *options, char *str) { if (p == 0) break; + envExpand(argument); p = setOption(options, name, argument, append, p); delete[] argument;