1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 #define _(msgid) gettext (msgid)
42 #include <readline/readline.h>
46 static char *history_file;
48 #if HAVE_READLINE_HISTORY_H
49 #include <readline/history.h>
50 #else /* no readline/history.h */
51 extern void add_history (char *);
52 extern void using_history (void);
53 extern int read_history (char *);
54 extern void stifle_history (int);
55 extern int write_history (char *);
56 #endif /* no readline/history.h */
57 #endif /* -lhistory */
60 static int read_console (void);
62 static bool initialised = false;
64 /* Initialize getl. */
66 readln_initialize (void)
70 rl_completion_entry_function = pspp_completion_function;
76 readln_uninitialize (void)
79 #if HAVE_LIBHISTORY && defined (unix)
81 write_history (history_file);
85 static bool welcomed = false;
87 /* Display a welcoming message. */
92 fputs ("PSPP is free software and you are welcome to distribute copies of "
93 "it\nunder certain conditions; type \"show copying.\" to see the "
94 "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show "
95 "warranty.\" for details.\n", stdout);
100 extern void perform_DO_REPEAT_substitutions (void);
102 /* Global variables. */
104 int getl_interactive;
108 extern struct cmd_set cmd;
112 /* Reads a single line into getl_buf from the list of files. Will not
113 read from the eof of one file to the beginning of another unless
114 the options field on the new file's getl_script is nonzero. Return
117 getl_read_line (void)
119 assert (initialised);
120 getl_mode = GETL_MODE_BATCH;
124 struct getl_script *s = getl_head;
126 ds_clear (&getl_buf);
132 if (!getl_handle_line_buffer ())
137 perform_DO_REPEAT_substitutions ();
138 if (getl_head->print)
139 tab_output_text (TAB_LEFT | TAT_FIX | TAT_PRINTF, "+%s",
140 ds_c_str (&getl_buf));
146 msg (VM (1), _("%s: Opening as syntax file."), s->fn);
147 s->f = fn_open (s->fn, "r");
151 msg (ME, _("Opening `%s': %s."), s->fn, strerror (errno));
157 if (!ds_gets (&getl_buf, s->f))
160 msg (ME, _("Reading `%s': %s."), s->fn, strerror (errno));
164 if (ds_length (&getl_buf) > 0 && ds_end (&getl_buf)[-1] == '\n')
165 ds_truncate (&getl_buf, ds_length (&getl_buf) - 1);
168 tab_output_text (TAB_LEFT | TAT_FIX, ds_c_str (&getl_buf));
172 /* Allows shebang invocation: `#! /usr/local/bin/pspp'. */
173 if (ds_c_str (&getl_buf)[0] == '#'
174 && ds_c_str (&getl_buf)[1] == '!')
180 if (getl_interactive == 0)
183 getl_mode = GETL_MODE_INTERACTIVE;
188 return read_console ();
192 /* PORTME: Adapt to your local system's idea of the terminal. */
195 #if HAVE_READLINE_READLINE_H
196 #include <readline/readline.h>
197 #else /* no readline/readline.h */
198 extern char *readline (char *);
199 #endif /* no readline/readline.h */
209 err_error_count = err_warning_count = 0;
210 err_already_flagged = 0;
216 history_file = tilde_expand (HISTORY_FILE);
219 read_history (history_file);
220 stifle_history (MAX_HISTORY);
222 #endif /* -lhistory */
226 case GETL_PRPT_STANDARD:
227 prompt = get_prompt ();
230 case GETL_PRPT_CONTINUATION:
231 prompt = get_cprompt ();
235 prompt = get_dprompt ();
243 line = readline (prompt);
252 ds_clear (&getl_buf);
253 ds_puts (&getl_buf, line);
259 #else /* no -lreadline */
265 err_error_count = err_warning_count = 0;
266 err_already_flagged = 0;
268 fputs (getl_prompt ? get_cprompt() : get_prompt(), stdout);
269 ds_clear (&getl_buf);
270 if (ds_gets (&getl_buf, stdin))
274 msg (FE, "stdin: fgets(): %s.", strerror (errno));
278 #endif /* no -lreadline */