parent
b770a618e0
commit
980a1c42ab
18
src/env.c
18
src/env.c
|
@ -279,17 +279,27 @@ void printColored(const char* code)
|
|||
{
|
||||
int c = 0;
|
||||
int depth = 0;
|
||||
int isQuote = 0;
|
||||
printf("[%dm", getColor(depth));
|
||||
while (code[c]) {
|
||||
if (code[c] == '(') {
|
||||
if (code[c] == '(' && !isQuote) {
|
||||
depth += 1;
|
||||
printf("[%dm", getColor(depth));
|
||||
} else if (code[c] == ')') {
|
||||
} else if (code[c] == ')' && !isQuote) {
|
||||
depth -= 1;
|
||||
printf(")[%dm", getColor(depth));
|
||||
c++;
|
||||
continue;
|
||||
} else if (code[c] == '=' && code[c + 1] == '>') {
|
||||
} else if (code[c] == '"') {
|
||||
isQuote = !isQuote;
|
||||
if (isQuote) {
|
||||
printf("[%dm\"", teal);
|
||||
} else {
|
||||
printf("\"[%dm", getColor(depth));
|
||||
}
|
||||
c++;
|
||||
continue;
|
||||
} else if (code[c] == '=' && code[c + 1] == '>' && !isQuote) {
|
||||
printf("[1m=>[0;%dm", getColor(depth));
|
||||
c += 2;
|
||||
continue;
|
||||
|
@ -459,6 +469,8 @@ struct Environment defaultEnv()
|
|||
pf(printEnvO),
|
||||
pf(systemCall),
|
||||
pf(loadFile),
|
||||
pf(cd),
|
||||
pf(cwd),
|
||||
pf(takeInput),
|
||||
pf(readFileToObject),
|
||||
pf(getEnvVar),
|
||||
|
|
|
@ -12,17 +12,15 @@
|
|||
|
||||
(def nl (ch 10))
|
||||
|
||||
(def conf (cat (env "HOME") "/.pebblisp.pbl"))
|
||||
(def config (cat (env "HOME") "/.pebblisp.pbl"))
|
||||
|
||||
(def reload (fn () (loadfile conf)))
|
||||
(def reload (fn () (loadfile config)))
|
||||
|
||||
(def hour (fn (ti) (
|
||||
(def h (% ti.hour 12))
|
||||
(if (= 0 h) 12 h)
|
||||
)))
|
||||
|
||||
(def pwd (fn () (env "PWD")))
|
||||
|
||||
(def zero (fn (num) (cat (if (< num 10) "0" "") num)))
|
||||
|
||||
(def clock (fn (ti) (cat (hour ti) ":" (zero ti.minute) ":" (zero ti.sec))))
|
||||
|
@ -31,6 +29,6 @@
|
|||
(def ti (time))
|
||||
|
||||
(cat nl
|
||||
bold red "[sage] " blue (clock) " " reset cyan (pwd) nl
|
||||
bold red "[sage] " blue (clock) " " reset cyan (cwd) nl
|
||||
bold green "pebblisp ~> " reset)
|
||||
)))
|
||||
|
|
|
@ -626,7 +626,7 @@ void repl(struct Environment* env)
|
|||
continue;
|
||||
}
|
||||
add_history(buf);
|
||||
if (buf[0] == '?' && (buf[1] == ' ' || buf[1] == '\0')) {
|
||||
if ((buf[0] == 'c' && buf[1] == 'd') || (buf[0] == '?' && (buf[1] == ' ' || buf[1] == '\0'))) {
|
||||
char* oldBuf = buf;
|
||||
buf = malloc(sizeof(char) * strlen(buf + 3));
|
||||
sprintf(buf, "(%s)", oldBuf);
|
||||
|
@ -706,7 +706,7 @@ int main(int argc, const char* argv[])
|
|||
Object o = parseEval("(def prompt \"pebblisp::> \")", &env);
|
||||
cleanObject(&o);
|
||||
|
||||
const char * const home = getenv("HOME");
|
||||
const char* const home = getenv("HOME");
|
||||
char config[strlen(home) + 15];
|
||||
sprintf(config, "%s/.pebblisp.pbl", home);
|
||||
readFile(config, &env);
|
||||
|
|
17
src/plfunc.c
17
src/plfunc.c
|
@ -346,6 +346,8 @@ BASIC_COMPARISON(and, &&)
|
|||
|
||||
#ifdef STANDALONE
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
Object print(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -391,6 +393,20 @@ Object loadFile(Object* params, int length, struct Environment* env)
|
|||
return numberObject(1);
|
||||
}
|
||||
|
||||
Object cd(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
checkTypes(cd)
|
||||
|
||||
return numberObject(chdir(params[0].string));
|
||||
}
|
||||
|
||||
Object cwd(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
char c[128];
|
||||
getcwd(c, sizeof(c));
|
||||
return nullTerminated(c);
|
||||
}
|
||||
|
||||
Object systemCall(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
checkTypes(systemCall)
|
||||
|
@ -454,6 +470,7 @@ Object getEnvVar(Object* params, int length, struct Environment* env)
|
|||
#include <time.h>
|
||||
|
||||
int timeStructDefinition = -1;
|
||||
|
||||
Object getTime(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
if (timeStructDefinition == -1) {
|
||||
|
|
10
src/plfunc.h
10
src/plfunc.h
|
@ -223,6 +223,16 @@ tfn(loadFile, "loadfile",
|
|||
"=> 0"
|
||||
);
|
||||
|
||||
tfn(cd, "cd",
|
||||
({ isStringy, NULL }),
|
||||
"Change the current directory."
|
||||
);
|
||||
|
||||
tfn(cwd, "cwd",
|
||||
({ isStringy }),
|
||||
"Get the current directory."
|
||||
);
|
||||
|
||||
/// @code
|
||||
/// () => STRING
|
||||
/// STRING => STRING
|
||||
|
|
Loading…
Reference in New Issue