Skip to content

Commit dd2fef1

Browse files
committed
Shove yet more readline logic into readline.c
1 parent 2eb69a1 commit dd2fef1

File tree

6 files changed

+149
-146
lines changed

6 files changed

+149
-146
lines changed

es.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,6 @@ extern List *runstring(const char *str, const char *name, int flags);
308308
#define run_printcmds 32 /* -x */
309309
#define run_lisptrees 64 /* -L and defined(LISPTREES) */
310310

311-
#if HAVE_READLINE
312-
extern Boolean resetterminal;
313-
#endif
314-
315311

316312
/* readline.c */
317313

@@ -321,7 +317,7 @@ extern void inithistory(void);
321317
extern void sethistory(char *file);
322318
extern void loghistory(char *cmd);
323319
extern void setmaxhistorylength(int length);
324-
extern void checkreloadhistory(void);
320+
extern void rlsetup(Boolean fromprim);
325321
#endif
326322

327323

history.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ static Buffer *histbuffer = NULL;
2323
* histbuffer -- build the history line during input and dump it as a gc-string
2424
*/
2525

26-
2726
extern void newhistbuffer() {
2827
assert(histbuffer == NULL);
2928
histbuffer = openbuffer(BUFSIZE);
@@ -48,10 +47,3 @@ extern char *dumphistbuffer() {
4847
s[len - 1] = '\0';
4948
return s;
5049
}
51-
52-
53-
/*
54-
* history file
55-
*/
56-
57-

input.c

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ Input *input;
2525
char *prompt, *prompt2;
2626

2727
Boolean ignoreeof = FALSE;
28-
Boolean resetterminal = FALSE;
29-
30-
#if HAVE_READLINE
31-
#include <readline/readline.h>
32-
#endif
3328

3429

3530
/*
@@ -143,13 +138,7 @@ static char *callreadline(char *prompt0) {
143138
char *r;
144139
if (prompt == NULL)
145140
prompt = ""; /* bug fix for readline 2.0 */
146-
checkreloadhistory();
147-
if (resetterminal) {
148-
rl_reset_terminal(NULL);
149-
resetterminal = FALSE;
150-
}
151-
if (RL_ISSTATE(RL_STATE_INITIALIZED))
152-
rl_reset_screen_size();
141+
rlsetup(FALSE);
153142
interrupted = FALSE;
154143
if (!setjmp(slowlabel)) {
155144
slow = TRUE;
@@ -454,106 +443,6 @@ extern Boolean isfromfd(void) {
454443
}
455444

456445

457-
/*
458-
* readline integration.
459-
*/
460-
#if HAVE_READLINE
461-
/* quote -- teach readline how to quote a word in es during completion */
462-
static char *quote(char *text, int type, char *qp) {
463-
char *p, *r;
464-
465-
/* worst-case size: string is 100% quote characters which will all be
466-
* doubled, plus initial and final quotes and \0 */
467-
p = r = ealloc(strlen(text) * 2 + 3);
468-
/* supply opening quote if not already present */
469-
if (*qp != '\'')
470-
*p++ = '\'';
471-
while (*text) {
472-
/* double any quotes for es quote-escaping rules */
473-
if (*text == '\'')
474-
*p++ = '\'';
475-
*p++ = *text++;
476-
}
477-
if (type == SINGLE_MATCH)
478-
*p++ = '\'';
479-
*p = '\0';
480-
return r;
481-
}
482-
483-
/* unquote -- teach es how to unquote a word */
484-
static char *unquote(char *text, int quote_char) {
485-
char *p, *r;
486-
487-
p = r = ealloc(strlen(text) + 1);
488-
while (*text) {
489-
*p++ = *text++;
490-
if (quote_char && *(text - 1) == '\'' && *text == '\'')
491-
++text;
492-
}
493-
*p = '\0';
494-
return r;
495-
}
496-
497-
static char *complprefix;
498-
static List *(*wordslistgen)(char *);
499-
500-
static char *list_completion_function(const char *text, int state) {
501-
static char **matches = NULL;
502-
static int matches_idx, matches_len;
503-
int i, rlen;
504-
char *result;
505-
506-
const int pfx_len = strlen(complprefix);
507-
508-
if (!state) {
509-
const char *name = &text[pfx_len];
510-
511-
Vector *vm = vectorize(wordslistgen((char *)name));
512-
matches = vm->vector;
513-
matches_len = vm->count;
514-
matches_idx = 0;
515-
}
516-
517-
if (!matches || matches_idx >= matches_len)
518-
return NULL;
519-
520-
rlen = strlen(matches[matches_idx]);
521-
result = ealloc(rlen + pfx_len + 1);
522-
for (i = 0; i < pfx_len; i++)
523-
result[i] = complprefix[i];
524-
strcpy(&result[pfx_len], matches[matches_idx]);
525-
result[rlen + pfx_len] = '\0';
526-
527-
matches_idx++;
528-
return result;
529-
}
530-
531-
char **builtin_completion(const char *text, int UNUSED start, int UNUSED end) {
532-
char **matches = NULL;
533-
534-
if (*text == '$') {
535-
wordslistgen = varswithprefix;
536-
complprefix = "$";
537-
switch (text[1]) {
538-
case '&':
539-
wordslistgen = primswithprefix;
540-
complprefix = "$&";
541-
break;
542-
case '^': complprefix = "$^"; break;
543-
case '#': complprefix = "$#"; break;
544-
}
545-
matches = rl_completion_matches(text, list_completion_function);
546-
}
547-
548-
/* ~foo => username. ~foo/bar already gets completed as filename. */
549-
if (!matches && *text == '~' && !strchr(text, '/'))
550-
matches = rl_completion_matches(text, rl_username_completion_function);
551-
552-
return matches;
553-
}
554-
#endif /* HAVE_READLINE */
555-
556-
557446
/*
558447
* initialization
559448
*/
@@ -566,20 +455,4 @@ extern void initinput(void) {
566455
globalroot(&error); /* parse errors */
567456
globalroot(&prompt); /* main prompt */
568457
globalroot(&prompt2); /* secondary prompt */
569-
570-
#if HAVE_READLINE
571-
rl_readline_name = "es";
572-
573-
/* these two word_break_characters exclude '&' due to primitive completion */
574-
rl_completer_word_break_characters = " \t\n\\'`$><=;|{()}";
575-
rl_basic_word_break_characters = " \t\n\\'`$><=;|{()}";
576-
rl_completer_quote_characters = "'";
577-
rl_special_prefixes = "$";
578-
579-
rl_attempted_completion_function = builtin_completion;
580-
581-
rl_filename_quote_characters = " \t\n\\`'$><=;|&{()}";
582-
rl_filename_quoting_function = quote;
583-
rl_filename_dequoting_function = unquote;
584-
#endif
585458
}

prim-etc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ static void loginput(char *input) {
169169

170170
PRIM(parse) {
171171
List *result;
172-
Tree *tree;
173172
Ref(char *, prompt1, NULL);
174173
Ref(char *, prompt2, NULL);
175174
Ref(List *, lp, list);
@@ -180,6 +179,8 @@ PRIM(parse) {
180179
}
181180
RefEnd(lp);
182181
newhistbuffer();
182+
183+
Ref(Tree *, tree, NULL);
183184
ExceptionHandler
184185
tree = parse(prompt1, prompt2);
185186
CatchException (e)
@@ -192,7 +193,7 @@ PRIM(parse) {
192193
? NULL
193194
: mklist(mkterm(NULL, mkclosure(gcmk(nThunk, tree), NULL)),
194195
NULL);
195-
RefEnd2(prompt2, prompt1);
196+
RefEnd3(prompt2, prompt1, tree);
196197
return result;
197198
}
198199

0 commit comments

Comments
 (0)