parent
ce6c536567
commit
803935c637
18
src/env.c
18
src/env.c
|
@ -282,13 +282,18 @@ void printColored(const char* code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* getHelp(const char* symbol)
|
fn(help,
|
||||||
{
|
"Displays help text for the given function.\n"
|
||||||
|
"Currently requires the function name as a string, but future syntactic sugar may\n"
|
||||||
|
"loosen this requirement.\n"
|
||||||
|
"(? \"+\") => \"(+ 1 2) => 3\""
|
||||||
|
) {
|
||||||
|
const char* symbol = params[0].string;
|
||||||
for (int i = 0; i < currentHelp; i++) {
|
for (int i = 0; i < currentHelp; i++) {
|
||||||
struct helpText h = helpTexts[i];
|
struct helpText h = helpTexts[i];
|
||||||
if (strcmp(symbol, h.symbol) == 0) {
|
if (strcmp(symbol, h.symbol) == 0) {
|
||||||
char* text = calloc(sizeof(char), 1024);
|
Object text = withLen(1024, TYPE_STRING);
|
||||||
char* textCursor = text;
|
char* textCursor = text.string;
|
||||||
textCursor += sprintf(textCursor, "%s", h.help);
|
textCursor += sprintf(textCursor, "%s", h.help);
|
||||||
for (int ti = 0; ti < h.testCount; ti += 2) {
|
for (int ti = 0; ti < h.testCount; ti += 2) {
|
||||||
const char* test = h.tests[ti];
|
const char* test = h.tests[ti];
|
||||||
|
@ -303,10 +308,7 @@ char* getHelp(const char* symbol)
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char* notFound = "Help not found!";
|
return nullTerminated("Help not found!");
|
||||||
char* help = malloc(sizeof(char) * (strlen(notFound) + 1));
|
|
||||||
sprintf(help, "%s", notFound);
|
|
||||||
return help;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fnn(segfault, "seg", "Induces a segfault.")
|
fnn(segfault, "seg", "Induces a segfault.")
|
||||||
|
|
|
@ -49,9 +49,6 @@ struct StructDef* getStructAt(int i);
|
||||||
|
|
||||||
void addStructDef(struct StructDef def);
|
void addStructDef(struct StructDef def);
|
||||||
|
|
||||||
/// Needs to be freed!
|
|
||||||
char* getHelp(const char* symbol);
|
|
||||||
|
|
||||||
void printColored(const char* code);
|
void printColored(const char* code);
|
||||||
|
|
||||||
int runTests(int detailed);
|
int runTests(int detailed);
|
||||||
|
|
|
@ -610,6 +610,7 @@ void repl(struct Environment* env)
|
||||||
size_t length;
|
size_t length;
|
||||||
char *output = stringObj(&o, &length);
|
char *output = stringObj(&o, &length);
|
||||||
printColored(output);
|
printColored(output);
|
||||||
|
free(output);
|
||||||
printf("[0m\n");
|
printf("[0m\n");
|
||||||
cleanObject(&o);
|
cleanObject(&o);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -620,7 +621,7 @@ void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env)
|
||||||
{
|
{
|
||||||
Object args = listObject();
|
Object args = listObject();
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
nf_addToList(&args, stringFromSlice(argv[i], strlen(argv[i])));
|
nf_addToList(&args, nullTerminated(argv[i]));
|
||||||
}
|
}
|
||||||
addToEnv(env, "args", args);
|
addToEnv(env, "args", args);
|
||||||
}
|
}
|
||||||
|
|
10
src/plfunc.c
10
src/plfunc.c
|
@ -443,16 +443,6 @@ Object systemCall(Object* params, int length, struct Environment* env)
|
||||||
return numberObject(255);
|
return numberObject(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object help(Object* params, int length, struct Environment* env)
|
|
||||||
{
|
|
||||||
Object symbol = params[0];
|
|
||||||
|
|
||||||
char* help = getHelp(symbol.string);
|
|
||||||
Object helpText = newObject(TYPE_STRING);
|
|
||||||
helpText.string = help;
|
|
||||||
return helpText;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* readFileToString(FILE* input)
|
char* readFileToString(FILE* input)
|
||||||
{
|
{
|
||||||
size_t capacity = 128;
|
size_t capacity = 128;
|
||||||
|
|
|
@ -195,14 +195,6 @@ fn(takeInput,
|
||||||
"`(def x (input \">> \"))` wait for input, but prompt the user with '>> '.\n"
|
"`(def x (input \">> \"))` wait for input, but prompt the user with '>> '.\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
/// STRING => STRING
|
|
||||||
fn(help,
|
|
||||||
"Displays help text for the given function.\n"
|
|
||||||
"Currently requires the function name as a string, but future syntactic sugar may\n"
|
|
||||||
"loosen this requirement.\n"
|
|
||||||
"(? \"+\") => \"(+ 1 2) => 3\""
|
|
||||||
);
|
|
||||||
|
|
||||||
tfn(readFileToObject,
|
tfn(readFileToObject,
|
||||||
({ isStringy, isStringy }),
|
({ isStringy, isStringy }),
|
||||||
"Read a file into a string object."
|
"Read a file into a string object."
|
||||||
|
|
10
src/web.c
10
src/web.c
|
@ -54,7 +54,7 @@ add_query_param(void* queryParamsV, enum MHD_ValueKind kind, const char* key,
|
||||||
(void) kind; /* Unused. Silent compiler warning. */
|
(void) kind; /* Unused. Silent compiler warning. */
|
||||||
Object* queryParams = queryParamsV;
|
Object* queryParams = queryParamsV;
|
||||||
|
|
||||||
Object pair = startList(stringFromSlice(key, strlen(key)));
|
Object pair = startList(nullTerminated(key));
|
||||||
Object parsed;
|
Object parsed;
|
||||||
if (isDigit(value[0])) {
|
if (isDigit(value[0])) {
|
||||||
parsed = parseEval(value, NULL);
|
parsed = parseEval(value, NULL);
|
||||||
|
@ -73,6 +73,10 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
|
||||||
const char* version, const char* upload_data,
|
const char* version, const char* upload_data,
|
||||||
size_t* upload_data_size, void** con_cls)
|
size_t* upload_data_size, void** con_cls)
|
||||||
{
|
{
|
||||||
|
(void) cls; /* Unused. Silence compiler warning. */
|
||||||
|
(void) upload_data_size; /* Unused. Silence compiler warning. */
|
||||||
|
(void) con_cls; /* Unused. Silence compiler warning. */
|
||||||
|
|
||||||
char* page = NULL;
|
char* page = NULL;
|
||||||
printf("%s :: %s URL: '%s'\n", method, version, url);
|
printf("%s :: %s URL: '%s'\n", method, version, url);
|
||||||
if (upload_data) {
|
if (upload_data) {
|
||||||
|
@ -107,10 +111,6 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
|
||||||
page = "<html><body><h1>404, Dumbass.</h1></body></html>";
|
page = "<html><body><h1>404, Dumbass.</h1></body></html>";
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) cls; /* Unused. Silent compiler warning. */
|
|
||||||
(void) upload_data_size; /* Unused. Silent compiler warning. */
|
|
||||||
(void) con_cls; /* Unused. Silent compiler warning. */
|
|
||||||
|
|
||||||
struct MHD_Response* response = MHD_create_response_from_buffer(
|
struct MHD_Response* response = MHD_create_response_from_buffer(
|
||||||
strlen(page), (void*) page, MHD_RESPMEM_PERSISTENT);
|
strlen(page), (void*) page, MHD_RESPMEM_PERSISTENT);
|
||||||
HttpResult ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
HttpResult ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||||
|
|
|
@ -10,8 +10,10 @@ fn(startServer,
|
||||||
|
|
||||||
fn(addGetRoute,
|
fn(addGetRoute,
|
||||||
"Note: Implementation bugs currently prevent using an inline lambda.\n"
|
"Note: Implementation bugs currently prevent using an inline lambda.\n"
|
||||||
" (def homepage (fn () (\"Hello, world!\")));(get \"/\" homepage)\n"
|
" (def homepage (fn () (\"Hello, world!\")))\n"
|
||||||
" (def queryPage (fn (req) (req's queryParams)));(get \"/x\" queryPage)\n"
|
" (get \"/\" homepage)\n"
|
||||||
|
" (def queryPage (fn (req) (req's queryParams)))\n"
|
||||||
|
" (get \"/x\" queryPage)\n"
|
||||||
" (serve)\n"
|
" (serve)\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue