diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lsh_main_func.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lsh_main_func.c b/src/lsh_main_func.c index c144238..fdaa011 100644 --- a/src/lsh_main_func.c +++ b/src/lsh_main_func.c @@ -45,12 +45,32 @@ char *lsh_read_line(void) } } +//this needs to be rewritten/moved for better memory management. eg not writing to getenv or a pointer to a string that must not be modified +//eg dont use token=some pointer char *handle_vars(char *token){ token=&token[0]; if (token[0] == '$'){ token=&token[1]; - token=getenv(token); + if(getenv(token)){ + token=getenv(token); + } else { + token=""; + } + } + /* + if (token[0] == '~'){ + token=&token[1]; + char *orig = (char*)malloc(sizeof(char) * ( strlen(token) + strlen(getenv("HOME") + 1))); + strcpy(orig,token); + + strcpy(token,getenv("home")) has a weird doubling memory thing i dont understand + strcpy(token,getenv("HOME")); + + strcat(token,orig); + printf("TOK: %s\n\n",token); + free(orig); } + */ return token; } |
