projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Windows build: Adapted icon names to org.fsf.pspp naming
[pspp]
/
src
/
ui
/
terminal
/
terminal-reader.c
diff --git
a/src/ui/terminal/terminal-reader.c
b/src/ui/terminal/terminal-reader.c
index 2f2a533d1577f4d6cf46a95e3f60cd1b26ce7dd8..3225678e8707b28a0dba95064d93fae4abf6b6f0 100644
(file)
--- a/
src/ui/terminal/terminal-reader.c
+++ b/
src/ui/terminal/terminal-reader.c
@@
-22,6
+22,7
@@
#include <stdbool.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
+#include "libpspp/str.h"
#if HAVE_READLINE
#include <readline/readline.h>
#if HAVE_READLINE
#include <readline/readline.h>
@@
-188,14
+189,12
@@
static struct lex_reader_class terminal_reader_class =
struct lex_reader *
terminal_reader_create (void)
{
struct lex_reader *
terminal_reader_create (void)
{
- struct terminal_reader *r;
-
if (!n_terminal_readers++)
readline_init ();
if (!n_terminal_readers++)
readline_init ();
-
r = xzalloc (sizeof *
r);
+
struct terminal_reader *r = XZALLOC (struct terminal_reade
r);
r->reader.class = &terminal_reader_class;
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 ();
r->reader.error = LEX_ERROR_TERMINAL;
r->reader.file_name = NULL;
r->s = ss_empty ();
@@
-228,6
+227,9
@@
readline_prompt (enum prompt_style style)
case PROMPT_DO_REPEAT:
return "DO REPEAT> ";
case PROMPT_DO_REPEAT:
return "DO REPEAT> ";
+
+ case PROMPT_DEFINE:
+ return "DEFINE> ";
}
NOT_REACHED ();
}
NOT_REACHED ();
@@
-264,13
+266,13
@@
interruptible_getc (FILE *fp)
max_fd = (max_fd > fd) ? max_fd : fd;
FD_SET (fd, &what);
ret = select (max_fd + 1, &what, NULL, NULL, &timeout);
max_fd = (max_fd > fd) ? max_fd : fd;
FD_SET (fd, &what);
ret = select (max_fd + 1, &what, NULL, NULL, &timeout);
- if (
ret == -1 && errno != EINTR)
+ if (ret == -1 && errno != EINTR)
{
perror ("Select failed");
continue;
}
{
perror ("Select failed");
continue;
}
- if (ret > 0
)
+ if (ret > 0)
{
if (FD_ISSET (pfd[0], &what))
{
{
if (FD_ISSET (pfd[0], &what))
{
@@
-302,10
+304,10
@@
handler (int sig)
static void
readline_init (void)
{
static void
readline_init (void)
{
- if (
0 != pipe2 (pfd, O_NONBLOCK))
+ if (0 != pipe2 (pfd, O_NONBLOCK))
perror ("Cannot create pipe");
perror ("Cannot create pipe");
- if (
SIG_ERR == signal (SIGINT, handler))
+ if (SIG_ERR == signal (SIGINT, handler))
perror ("Cannot add signal handler");
rl_catch_signals = 0;
perror ("Cannot add signal handler");
rl_catch_signals = 0;
@@
-327,7
+329,7
@@
readline_init (void)
static void
readline_done (void)
{
static void
readline_done (void)
{
- if (history_file != NULL && false == settings_get_testing_mode ()
)
+ if (history_file != NULL && false == settings_get_testing_mode ())
write_history (history_file);
clear_history ();
free (history_file);
write_history (history_file);
clear_history ();
free (history_file);
@@
-408,14
+410,26
@@
command_generator (const char *text, int state)
if (state == 0)
cmd = NULL;
name = cmd_complete (text, &cmd);
if (state == 0)
cmd = NULL;
name = cmd_complete (text, &cmd);
- return
name ? xstrdup (name) : NULL
;
+ return
xstrdup_if_nonnull (name)
;
}
#else /* !HAVE_READLINE */
}
#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)
{
static void
readline_init (void)
{
+ if (SIG_ERR == signal (SIGINT, handler))
+ perror ("Cannot add signal handler");
}
static void
}
static void
@@
-423,19
+437,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;
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;
fflush (stdout);
ds_init_empty (&string);
ds_read_line (&string, stdin, SIZE_MAX);
*line = string.ss;
- return
fals
e;
+ return
tru
e;
}
#endif /* !HAVE_READLINE */
}
#endif /* !HAVE_READLINE */