X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fterminal%2Fterminal-reader.c;h=e418ec7e086375f0eb8d6606754595fdc3a23a1c;hb=320622191b3de640da6ba0e347a94d28493711ae;hp=c23fad186f86992b164b401792ed3a1300f1706c;hpb=96994a54e60e9c95b8bba54c2281acf7059b1203;p=pspp diff --git a/src/ui/terminal/terminal-reader.c b/src/ui/terminal/terminal-reader.c index c23fad186f..e418ec7e08 100644 --- a/src/ui/terminal/terminal-reader.c +++ b/src/ui/terminal/terminal-reader.c @@ -22,6 +22,7 @@ #include #include +#include "libpspp/str.h" #if HAVE_READLINE #include @@ -195,7 +196,7 @@ terminal_reader_create (void) r = xzalloc (sizeof *r); r->reader.class = &terminal_reader_class; - r->reader.syntax = LEX_SYNTAX_INTERACTIVE; + r->reader.syntax = SEG_MODE_INTERACTIVE; r->reader.error = LEX_ERROR_TERMINAL; r->reader.file_name = NULL; r->s = ss_empty (); @@ -228,6 +229,9 @@ readline_prompt (enum prompt_style style) case PROMPT_DO_REPEAT: return "DO REPEAT> "; + + case PROMPT_DEFINE: + return "DEFINE> "; } NOT_REACHED (); @@ -408,14 +412,26 @@ command_generator (const char *text, int state) if (state == 0) cmd = NULL; name = cmd_complete (text, &cmd); - return name ? xstrdup (name) : NULL; + return xstrdup_if_nonnull (name); } #else /* !HAVE_READLINE */ +static const char * the_prompt; + +static void +handler (int sig) +{ + if (the_prompt) + fputs (the_prompt, stdout); + fflush (stdout); +} + static void readline_init (void) { + if (SIG_ERR == signal (SIGINT, handler)) + perror ("Cannot add signal handler"); } static void @@ -423,19 +439,22 @@ readline_done (void) { } +/* 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 readline_read (struct substring *line, enum prompt_style style) { struct string string; - const char *prompt = readline_prompt (style); + the_prompt = readline_prompt (style); - fputs (prompt, stdout); + fputs (the_prompt, stdout); fflush (stdout); ds_init_empty (&string); ds_read_line (&string, stdin, SIZE_MAX); *line = string.ss; - return false; + return true; } #endif /* !HAVE_READLINE */