rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit d000dc89db8f65db051a3d870bbc8f4d4edefd8d
parent 70a21186f92ee19a995080744ce9a320345c05cb
Author: tjg <tjg>
Date:   Thu, 25 Sep 2003 09:17:46 +0000

Initial revision

Diffstat:
Aedit-gnu.c | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/edit-gnu.c b/edit-gnu.c @@ -0,0 +1,38 @@ +#include "rc.h" + +#include <stdio.h> +#include <readline/readline.h> + +#include "jbwrap.h" + +struct Jbwrap rl_buf; +volatile sig_atomic_t rl_active; + +void edit_init(void *ignored) { + rl_catch_signals = 0; +} + +char *edit_getline(void *ignored, char *prompt) { + char *r = NULL; + int s; + + if ((s = sigsetjmp(rl_buf.j, 1)) == 0) { + rl_active = TRUE; + r = readline(prompt); + } else { + rl_free_line_state(); + rl_cleanup_after_signal(); + rl_active = FALSE; + rc_raise(eError); + } + + if (r) { + r = erealloc(r, strlen(r) + 2); /* 1 for \n + 1 for \0 */ + strcat(r, "\n"); + } + return r; +} + +void edit_free(void *ignored, void *buffer) { + efree(buffer); +}