X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fterminal%2Fterminal-reader.c;h=b8c71447ce5c7563c6bde942f7bf9bde18767723;hb=c193302d89917211fc7cff16203a1787a295ee9a;hp=a3f33e725589a005f4b4d92a115d119e327614b4;hpb=0b0ca44889e637251cb5f2dbf3c7fdc4ec8b9bd7;p=pspp diff --git a/src/ui/terminal/terminal-reader.c b/src/ui/terminal/terminal-reader.c index a3f33e7255..b8c71447ce 100644 --- a/src/ui/terminal/terminal-reader.c +++ b/src/ui/terminal/terminal-reader.c @@ -26,18 +26,13 @@ #if HAVE_READLINE #include #include +#include static char *history_file; static char **complete_command_name (const char *, int, int); static char **dont_complete (const char *, int, int); static char *command_generator (const char *text, int state); - -static const bool have_readline = true; - -#else -static const bool have_readline = false; -static int rl_end; #endif @@ -51,7 +46,6 @@ static int rl_end; #include #include -#include "data/file-name.h" #include "data/settings.h" #include "language/command.h" #include "language/lexer/lexer.h" @@ -97,8 +91,8 @@ welcome (void) "it\nunder certain conditions; type \"show copying.\" to see the " "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show " "warranty.\" for details.\n", stdout); - puts (stat_version); - journal_enable (); + puts (announced_version); + journal_init (); } static struct terminal_reader * @@ -107,6 +101,42 @@ terminal_reader_cast (struct lex_reader *r) return UP_CAST (r, struct terminal_reader, reader); } + +/* Older libreadline versions do not provide rl_outstream. + However, it is almost always going to be the same as stdout. */ +#if ! HAVE_RL_OUTSTREAM +# define rl_outstream stdout +#endif + + +#if HAVE_READLINE +/* Similarly, rl_echo_signal_char is fairly recent. + We provide our own crude version if it is not present. */ +#if ! HAVE_RL_ECHO_SIGNAL_CHAR +static void +rl_echo_signal_char (int sig) +{ +#if HAVE_TERMIOS_H + struct termios t; + if (0 == tcgetattr (0, &t)) + { + cc_t c = t.c_cc[VINTR]; + + if (c >= 0 && c <= 'Z' - 'A') + fprintf (rl_outstream, "^%c", 'A' + c - 1); + else + fprintf (rl_outstream, "%c", c); + } + else +#endif + fprintf (rl_outstream, "^C"); + + fflush (rl_outstream); +} +#endif +#endif + + static size_t terminal_reader_read (struct lex_reader *r_, char *buf, size_t n, enum prompt_style prompt_style) @@ -177,7 +207,7 @@ terminal_reader_create (void) r = xzalloc (sizeof *r); r->reader.class = &terminal_reader_class; r->reader.syntax = LEX_SYNTAX_INTERACTIVE; - r->reader.error = LEX_ERROR_INTERACTIVE; + r->reader.error = LEX_ERROR_TERMINAL; r->reader.file_name = NULL; r->s = ss_empty (); r->offset = 0; @@ -215,21 +245,12 @@ readline_prompt (enum prompt_style style) } +#if HAVE_READLINE static int pfd[2]; static bool sigint_received ; -static void -handler (int sig) -{ - rl_end = 0; - - write (pfd[1], "x", 1); - rl_echo_signal_char (sig); -} - - -/* +/* A function similar to getc from stdio. However this one may be interrupted by SIGINT. If that happens it will return EOF and the global variable @@ -279,9 +300,15 @@ interruptible_getc (FILE *fp) return c; } +static void +handler (int sig) +{ + rl_end = 0; + write (pfd[1], "x", 1); + rl_echo_signal_char (sig); +} -#if HAVE_READLINE static void readline_init (void) @@ -317,7 +344,7 @@ readline_done (void) free (history_file); } -/* Prompt the user for a line of input and return it in LINE. +/* Prompt the user for a line of input and return it in LINE. Returns true if the LINE should be considered valid, false otherwise. */ static bool @@ -417,9 +444,9 @@ readline_read (struct substring *line, enum prompt_style style) fflush (stdout); ds_init_empty (&string); ds_read_line (&string, stdin, SIZE_MAX); - + *line = string.ss; - + return false; } #endif /* !HAVE_READLINE */