@@ -25,11 +25,6 @@ Input *input;
2525char * prompt , * prompt2 ;
2626
2727Boolean 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}
0 commit comments