rc

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

commit ab7361a7ff91a9a79bd02e06f20ded42ee2a5bcc
parent 535d086f6efb24eeaf9a0b2d8269e97a88c12f29
Author: Toby Goodwin <toby@paccrat.org>
Date:   Tue,  7 Apr 2015 23:54:45 +0100

readline completion: now mainly working

Diffstat:
Medit-readline.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/edit-readline.c b/edit-readline.c @@ -14,13 +14,61 @@ struct cookie { char *buffer; }; +/* teach readline how to quote a filename in rc */ +static char *quote(char *text, int type, char *qp) { + char *p, *r; + + /* worst case: string is entirely quote characters each of which will + * be doubled, plus space for initial and final quotes and \0 */ + p = r = malloc(strlen(text) * 2 + 3); + if (!r) return 0; + /* supply opening quote unless already there */ + if (*qp != '\'') + *p++ = '\''; + while (*text) { + if (*text == '\'') + *p++ = '\''; /* double existing quote */ + *p++ = *text++; + } + if (type == SINGLE_MATCH) + *p++ = '\''; + *p = '\0'; + return r; +} + +char *unquote(char *text, int unused) { + char *p, *r; + + p = r = malloc(strlen(text) + 1); + if (!r) return 0; + while (*text) { + *p++ = *text++; + if (*(text - 1) == '\'' && *text == '\'') ++text; + } + *p = '\0'; + return r; +} +static char **complete(const char *text, int start, int end) { + //fprintf(stderr, "completer called on %s with %d and %d", text, start, end); + /* we can look at rl_line_buffer to see whether to complete as a + * command or a filename (should we do variables too?). for now, assume + * it's a filename */ + /* it's a filename: let readline do it's default thing */ + return 0; +} + void *edit_begin(int fd) { List *hist; struct cookie *c; rl_catch_signals = 0; rl_completer_quote_characters = "'"; + rl_basic_word_break_characters = " \t\n`@$><=;|&{("; + rl_basic_quote_characters = ""; rl_filename_quote_characters = "\t\n !#$&'()*;<=>?@[\\]^`{|}~"; + rl_filename_quoting_function = quote; + rl_filename_dequoting_function = unquote; + rl_attempted_completion_function = complete; hist = varlookup("history"); if (hist != NULL)