summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c9
-rw-r--r--src/readline.c2
-rw-r--r--src/syscmd.c51
3 files changed, 52 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index f163558..f2764d5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,4 @@
+
/* Aplwc - A Programming Language With Constraints
*
* Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com>
@@ -56,19 +57,19 @@ main(int argc, char *argv[])
}
}
- struct aplwc *aplwc = aplwc_new();
+ struct aplwc *aplwc = aplwc_new(malloc, free, realloc);
init_syscmds(aplwc);
init_readline(aplwc);
char *line;
- while(line = readline(" ")){
+ while(aplwc_running(aplwc) && (line = readline(" "))){
if(strlen(line) == 0)
continue;
add_history(line);
- printf(_("You typed: %s\n"), line);
+ aplwc_run_line(aplwc, line);
free(line);
}
- printf(_("bye\n"));
+ printf(_("Bye\n"));
}
static void
diff --git a/src/readline.c b/src/readline.c
index bda4df9..f03bbdb 100644
--- a/src/readline.c
+++ b/src/readline.c
@@ -24,7 +24,6 @@
static struct aplwc *aplwc;
static char **completions;
-static int completion_index;
static char **complete(const char *, int, int);
static char *get_completion(const char *, int);
@@ -52,5 +51,6 @@ complete(const char *text, int start, int end)
static char *
get_completion(const char *text, int state)
{
+ (void)text;
return completions[state];
}
diff --git a/src/syscmd.c b/src/syscmd.c
index 6c3d2e5..8c3a88a 100644
--- a/src/syscmd.c
+++ b/src/syscmd.c
@@ -19,18 +19,59 @@
*/
#include <config.h>
+#include <string.h>
#include "syscmd.h"
+#include "nls.h"
+
+static void syscmd_version(struct aplwc *, struct aplwc_syscmd *, char *);
+static void syscmd_exit(struct aplwc *, struct aplwc_syscmd *, char *);
+static void syscmd_stats(struct aplwc *, struct aplwc_syscmd *, char *);
static struct aplwc_syscmd syscmds[] = {
- {.name = "help"},
- {.name = "version"},
- {.name = "reset"},
- {.name = "exit"},
+ {
+ .name = "version",
+ .run = syscmd_version
+ },
+ {
+ .name = "exit",
+ .run = syscmd_exit
+ },
+ {
+ .name = "stats",
+ .run = syscmd_stats
+ },
};
void
init_syscmds(struct aplwc *aplwc)
{
- for(int i = 0; i < (sizeof(syscmds)/sizeof(*syscmds)); i++)
+ for(size_t i = 0; i < (sizeof(syscmds)/sizeof(*syscmds)); i++)
aplwc_register_syscmd(aplwc, &syscmds[i]);
}
+
+static void
+syscmd_version(struct aplwc *aplwc, struct aplwc_syscmd *syscmd, char *input)
+{
+ if(strlen(input) > 0)
+ aplwc_syscmd_error(aplwc, syscmd, _("Unexpected: %s"));
+ else
+ aplwc_syscmd_output(aplwc, syscmd, _("Version 0"));
+}
+
+static void
+syscmd_exit(struct aplwc *aplwc, struct aplwc_syscmd *syscmd, char *input)
+{
+ if(strlen(input) > 0)
+ aplwc_syscmd_error(aplwc, syscmd, _("Unexpected: %s"));
+ else
+ aplwc_exit(aplwc);
+}
+
+static void
+syscmd_stats(struct aplwc *aplwc, struct aplwc_syscmd *syscmd, char *input)
+{
+ if(strlen(input) > 0)
+ aplwc_syscmd_error(aplwc, syscmd, _("Unexpected: %s"));
+ else
+ aplwc_syscmd_output(aplwc, syscmd, _("Stats...\nMore stats..."));
+}