Created
November 3, 2017 13:25
-
-
Save FedericoPonzi/a481246ade686deacf68d81773ccc295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "inc/env.h" | |
Env **environment; | |
/** | |
* This sould be a K-V hashmap. I will rewrite it someday (maybe) | |
*/ | |
/** | |
* Init the envorionment | |
*/ | |
void initEnv() | |
{ | |
environment = calloc('\0', sizeof(Env**)); | |
addEnv("shell", "path/myshell"); | |
} | |
Env* createVar(char *k, char* v){ | |
Env* new = calloc('\0', sizeof(Env)); | |
new->k = k; | |
new->v = v; | |
return new; | |
} | |
/** | |
* Adds an element to the internal environment | |
* Updates k if it is already present | |
*/ | |
void addEnv(char* k, char* v) | |
{ | |
Env** temp = environment; | |
while(*temp != NULL && (strcmp((*temp)->k, k) != 0)) { | |
temp = &((*temp)->next); | |
} | |
if(*temp != NULL){ | |
(*temp)->v = v; | |
return; | |
} | |
*temp = createVar(k, v); | |
} | |
/** | |
* For debugging | |
*/ | |
void showEnv() | |
{ | |
Env *it = *environment; | |
printf("Show environment:\n"); | |
while (it != NULL) | |
{ | |
printf("%s: %s\n", it->k, it->v); | |
it = it -> next; | |
} | |
} | |
void clearEnv() | |
{ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment