diff --git a/src/Makefile b/src/Makefile index 72a2b82..71655b2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,11 +9,15 @@ SCRIPTDIR ?= /usr/local/share/pebblisp mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) -GCC_COM ?= gcc -g -O0 -Wall -o $(exe) -D WEBSERVER -D STANDALONE -DSCRIPTDIR=\"$(SCRIPTDIR)\" +GCC_ARGS ?= -g -Wall -o $(exe) -D WEBSERVER -D STANDALONE -DSCRIPTDIR=\"$(SCRIPTDIR)\" +GCC_COM ?= gcc -O0 $(GCC_ARGS) all: $(GCC_COM) $(file_libs) && echo && ./tests.sh +release: + gcc -O3 $(GCC_ARGS) $(file_libs) && strip ./$(exe) && echo && ./tests.sh + notest: $(GCC_COM) $(file_libs) diff --git a/src/env.c b/src/env.c index 6522d9d..122581b 100644 --- a/src/env.c +++ b/src/env.c @@ -440,6 +440,7 @@ struct Environment defaultEnv() pf(loadFile), pf(takeInput), pf(readFileToObject), + pf(getEnvVar), pf(help) #endif }; diff --git a/src/pebblisp.c b/src/pebblisp.c index 9360e1e..bf3d3b7 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -391,7 +391,8 @@ Result readSeq(struct Slice* tokens) nf_addToList(&res, cloneObject(r.obj)); tokens = r.slices; cleanObject(&r.obj); - forceString = next->text[0] == '?' || (strncmp(next->text, "def", 3) == 0); + forceString = next->text[0] == '?' + || (strncmp(next->text, "def", 3) == 0); } } @@ -700,8 +701,9 @@ int main(int argc, const char* argv[]) Object o = parseEval("(def prompt \"pebblisp::> \")", &env); cleanObject(&o); - char config[strlen(getenv("HOME")) + 15]; - sprintf(config, "%s/.pebblisp.pbl", getenv("HOME")); + const char * const home = getenv("HOME"); + char config[strlen(home) + 15]; + sprintf(config, "%s/.pebblisp.pbl", home); readFile(config, &env); if (argc >= 2) { diff --git a/src/plfunc.c b/src/plfunc.c index 2b4f7f0..fe32b18 100644 --- a/src/plfunc.c +++ b/src/plfunc.c @@ -486,6 +486,12 @@ Object readFileToObject(Object* params, int length, struct Environment* env) return string; } +Object getEnvVar(Object* params, int length, struct Environment* env) +{ + checkTypes(getEnvVar) + return nullTerminated(getenv(params[0].string)); +} + #include int timeStructDefinition = -1; diff --git a/src/plfunc.h b/src/plfunc.h index 3573faa..bddc764 100644 --- a/src/plfunc.h +++ b/src/plfunc.h @@ -240,6 +240,12 @@ tfn(readFileToObject, "rf", "Read a file into a string object." ); +tfn(getEnvVar, "env", + ({ isStringy, isStringy }), + "Get a variable from the current environment\n" + "(env HOME) => /home/sagevaillancourt" +); + fn(getTime, "time", "Get a struct of the current time with fields (minute hour sec)." );