summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--edit-edit.c (renamed from edit-bsd.c)0
-rw-r--r--edit-editline.c100
-rw-r--r--edit-readline.c (renamed from edit-gnu.c)0
-rw-r--r--edit-vrl.c104
4 files changed, 204 insertions, 0 deletions
diff --git a/edit-bsd.c b/edit-edit.c
index c2a5260..c2a5260 100644
--- a/edit-bsd.c
+++ b/edit-edit.c
diff --git a/edit-editline.c b/edit-editline.c
new file mode 100644
index 0000000..85e3f40
--- /dev/null
+++ b/edit-editline.c
@@ -0,0 +1,100 @@
+#include "rc.h"
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "editline.h"
+
+bool editing = 1;
+
+struct cookie {
+ char *buffer;
+};
+
+static char *prompt;
+
+void *edit_begin(int fd) {
+ List *hist;
+ struct cookie *c;
+
+ hist = varlookup("history");
+ if (hist != NULL)
+ if (read_history(hist->w) != 0 &&
+ errno != ENOENT) /* ignore if missing */
+ uerror(hist->w);
+
+ c = ealloc(sizeof *c);
+ c->buffer = NULL;
+ return c;
+}
+
+/*
+static void edit_catcher(int sig) {
+ write(2, "\n", 1);
+ rc_raise(eError);
+}
+
+*/
+
+char *edit_alloc(void *cookie, size_t *count) {
+ struct cookie *c = cookie;
+/*
+ const char *r;
+ HistEvent he;
+ struct cookie *c = cookie;
+ void (*oldint)(int), (*oldquit)(int);
+
+ oldint = sys_signal(SIGINT, edit_catcher);
+ oldquit = sys_signal(SIGQUIT, edit_catcher);
+
+ r = el_gets(c->el, count);
+
+ sys_signal(SIGINT, oldint);
+ sys_signal(SIGQUIT, oldquit);
+
+ if (r)
+ history(c->hist, &he, H_ENTER, r);
+*/
+
+ c->buffer = readline(prompt);
+ if (c->buffer) {
+ *count = strlen(c->buffer);
+ c->buffer[*count] = '\n';
+ ++*count;
+ }
+ return c->buffer;
+}
+
+/*
+static char *edit_prompter(ne *e) {
+ return prompt;
+}
+*/
+
+void edit_prompt(void *cookie, char *pr) {
+ //struct cookie *c = cookie;
+
+ prompt = pr;
+ //el_set(c->el, EL_PROMPT, edit_prompter);
+}
+
+void edit_free(void *cookie) {
+ struct cookie *c = cookie;
+
+ efree(c->buffer);
+ c->buffer = NULL; /* allow "overfrees" */
+}
+
+void edit_end(void *cookie) {
+ //struct cookie *c = cookie;
+
+ //el_end(c->el);
+ //history_end(c->hist);
+ //efree(c);
+}
+
+void edit_reset(void *cookie) {
+ //struct cookie *c = cookie;
+
+ //el_set(c->el, EL_TERMINAL, NULL);
+}
diff --git a/edit-gnu.c b/edit-readline.c
index 6a997c5..6a997c5 100644
--- a/edit-gnu.c
+++ b/edit-readline.c
diff --git a/edit-vrl.c b/edit-vrl.c
new file mode 100644
index 0000000..5c8ab5a
--- /dev/null
+++ b/edit-vrl.c
@@ -0,0 +1,104 @@
+#include "rc.h"
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "edit.h"
+
+extern char *readline(char *);
+extern void add_history(char *);
+
+bool editing = 1;
+
+struct cookie {
+ char *buffer;
+};
+
+static char *prompt;
+
+void *edit_begin(int fd) {
+ List *hist;
+ struct cookie *c;
+
+
+ hist = varlookup("history");
+ if (hist != NULL)
+ ;
+ /* XXX will need to loop calling add_history() */
+
+ c = ealloc(sizeof *c);
+ c->buffer = NULL;
+ return c;
+}
+
+/*
+static void edit_catcher(int sig) {
+ write(2, "\n", 1);
+ rc_raise(eError);
+}
+
+*/
+
+char *edit_alloc(void *cookie, size_t *count) {
+ struct cookie *c = cookie;
+/*
+ const char *r;
+ HistEvent he;
+ struct cookie *c = cookie;
+ void (*oldint)(int), (*oldquit)(int);
+
+ oldint = sys_signal(SIGINT, edit_catcher);
+ oldquit = sys_signal(SIGQUIT, edit_catcher);
+
+ r = el_gets(c->el, count);
+
+ sys_signal(SIGINT, oldint);
+ sys_signal(SIGQUIT, oldquit);
+
+ if (r)
+ history(c->hist, &he, H_ENTER, r);
+*/
+
+ c->buffer = readline(prompt);
+ if (c->buffer) {
+ add_history(c->buffer);
+ *count = strlen(c->buffer);
+ c->buffer[*count] = '\n';
+ ++*count;
+ }
+ return c->buffer;
+}
+
+/*
+static char *edit_prompter(ne *e) {
+ return prompt;
+}
+*/
+
+void edit_prompt(void *cookie, char *pr) {
+ //struct cookie *c = cookie;
+
+ prompt = pr;
+ //el_set(c->el, EL_PROMPT, edit_prompter);
+}
+
+void edit_free(void *cookie) {
+ struct cookie *c = cookie;
+
+ efree(c->buffer);
+ c->buffer = NULL; /* allow "overfrees" */
+}
+
+void edit_end(void *cookie) {
+ //struct cookie *c = cookie;
+
+ //el_end(c->el);
+ //history_end(c->hist);
+ //efree(c);
+}
+
+void edit_reset(void *cookie) {
+ //struct cookie *c = cookie;
+
+ //el_set(c->el, EL_TERMINAL, NULL);
+}