From 8ca9f57a797e425205e08bce8355cf953d6be16b Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Tue, 7 Apr 2015 22:22:56 +0100 Subject: edit shims: better naming, editline and vrl added --- edit-bsd.c | 91 ------------------------------------------------- edit-edit.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ edit-editline.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ edit-gnu.c | 87 ----------------------------------------------- edit-readline.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ edit-vrl.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 382 insertions(+), 178 deletions(-) delete mode 100644 edit-bsd.c create mode 100644 edit-edit.c create mode 100644 edit-editline.c delete mode 100644 edit-gnu.c create mode 100644 edit-readline.c create mode 100644 edit-vrl.c diff --git a/edit-bsd.c b/edit-bsd.c deleted file mode 100644 index c2a5260..0000000 --- a/edit-bsd.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "rc.h" - -#include - -#include - -#include "edit.h" - -bool editing = 1; - -struct cookie { - EditLine *el; - History *hist; -}; - -static char *prompt; - -void *edit_begin(int fd) { - FILE *f; - HistEvent he; - struct cookie *c; - - c = ealloc(sizeof *c); - if (fd == 0) - f = stdin; - else - f = fdopen(fd, "r"); - c->el = el_init("rc", f, stdout, stderr); - el_set(c->el, EL_SIGNAL, 0); - el_source(c->el, NULL); - - c->hist = history_init(); - history(c->hist, &he, H_SETSIZE, 20); - el_set(c->el, EL_HIST, history, c->hist); - - return c; -} - - -static void edit_catcher(int sig) { - write(2, "\n", 1); - rc_raise(eError); -} - -char *edit_alloc(void *cookie, size_t *count) { - 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); - return (char *)r; /* cast to avoid gcc warning */ -} - -static char *edit_prompter(EditLine *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) { - /* this function deliberately left blank */ -} - -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-edit.c b/edit-edit.c new file mode 100644 index 0000000..c2a5260 --- /dev/null +++ b/edit-edit.c @@ -0,0 +1,91 @@ +#include "rc.h" + +#include + +#include + +#include "edit.h" + +bool editing = 1; + +struct cookie { + EditLine *el; + History *hist; +}; + +static char *prompt; + +void *edit_begin(int fd) { + FILE *f; + HistEvent he; + struct cookie *c; + + c = ealloc(sizeof *c); + if (fd == 0) + f = stdin; + else + f = fdopen(fd, "r"); + c->el = el_init("rc", f, stdout, stderr); + el_set(c->el, EL_SIGNAL, 0); + el_source(c->el, NULL); + + c->hist = history_init(); + history(c->hist, &he, H_SETSIZE, 20); + el_set(c->el, EL_HIST, history, c->hist); + + return c; +} + + +static void edit_catcher(int sig) { + write(2, "\n", 1); + rc_raise(eError); +} + +char *edit_alloc(void *cookie, size_t *count) { + 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); + return (char *)r; /* cast to avoid gcc warning */ +} + +static char *edit_prompter(EditLine *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) { + /* this function deliberately left blank */ +} + +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-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 +#include + +#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-gnu.c deleted file mode 100644 index 6a997c5..0000000 --- a/edit-gnu.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "rc.h" - -#include -#include -#include -#include -#include - -#include "edit.h" - -bool editing = 1; - -struct cookie { - char *buffer; -}; - -void *edit_begin(int fd) { - List *hist; - struct cookie *c; - - rl_catch_signals = 0; - rl_completer_quote_characters = "'"; - rl_filename_quote_characters = "\t\n !#$&'()*;<=>?@[\\]^`{|}~"; - - 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); -} - -static char *prompt; - -char *edit_alloc(void *cookie, size_t *count) { - struct cookie *c = cookie; - void (*oldint)(int), (*oldquit)(int); - - oldint = sys_signal(SIGINT, edit_catcher); - oldquit = sys_signal(SIGQUIT, edit_catcher); - - c->buffer = readline(prompt); - - sys_signal(SIGINT, oldint); - sys_signal(SIGQUIT, oldquit); - - if (c->buffer) { - *count = strlen(c->buffer); - if (*count) - add_history(c->buffer); - c->buffer[*count] = '\n'; - ++*count; /* include the \n */ - } - return c->buffer; -} - -void edit_prompt(void *cookie, char *pr) { - prompt = pr; -} - -void edit_free(void *cookie) { - struct cookie *c = cookie; - - efree(c->buffer); - /* Set c->buffer to NULL, allowing us to "overfree" it. This - is a bit of a kludge, but it's otherwise hard to deal with - the case where a signal causes an early return from - readline. */ - c->buffer = NULL; -} - -void edit_end(void *cookie) { - struct cookie *c = cookie; - - efree(c); -} - -void edit_reset(void *cookie) { - rl_reset_terminal(NULL); -} diff --git a/edit-readline.c b/edit-readline.c new file mode 100644 index 0000000..6a997c5 --- /dev/null +++ b/edit-readline.c @@ -0,0 +1,87 @@ +#include "rc.h" + +#include +#include +#include +#include +#include + +#include "edit.h" + +bool editing = 1; + +struct cookie { + char *buffer; +}; + +void *edit_begin(int fd) { + List *hist; + struct cookie *c; + + rl_catch_signals = 0; + rl_completer_quote_characters = "'"; + rl_filename_quote_characters = "\t\n !#$&'()*;<=>?@[\\]^`{|}~"; + + 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); +} + +static char *prompt; + +char *edit_alloc(void *cookie, size_t *count) { + struct cookie *c = cookie; + void (*oldint)(int), (*oldquit)(int); + + oldint = sys_signal(SIGINT, edit_catcher); + oldquit = sys_signal(SIGQUIT, edit_catcher); + + c->buffer = readline(prompt); + + sys_signal(SIGINT, oldint); + sys_signal(SIGQUIT, oldquit); + + if (c->buffer) { + *count = strlen(c->buffer); + if (*count) + add_history(c->buffer); + c->buffer[*count] = '\n'; + ++*count; /* include the \n */ + } + return c->buffer; +} + +void edit_prompt(void *cookie, char *pr) { + prompt = pr; +} + +void edit_free(void *cookie) { + struct cookie *c = cookie; + + efree(c->buffer); + /* Set c->buffer to NULL, allowing us to "overfree" it. This + is a bit of a kludge, but it's otherwise hard to deal with + the case where a signal causes an early return from + readline. */ + c->buffer = NULL; +} + +void edit_end(void *cookie) { + struct cookie *c = cookie; + + efree(c); +} + +void edit_reset(void *cookie) { + rl_reset_terminal(NULL); +} 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 +#include + +#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); +} -- cgit v1.2.3