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
27 #include "read-line.h"
38 #define _(msgid) gettext (msgid)
42 #include <readline/readline.h>
43 #include <readline/history.h>
45 static char *history_file;
46 #endif /* HAVE_READLINE */
48 static bool initialised = false;
50 /* Initialize getl. */
52 readln_initialize (void)
57 rl_completion_entry_function = pspp_completion_function;
59 if (history_file == NULL)
61 history_file = tilde_expand ("~/.pspp_history");
63 read_history (history_file);
72 readln_uninitialize (void)
76 #if HAVE_READLINE && unix
77 if (history_file != NULL)
78 write_history (history_file);
82 /* Display a welcoming message. */
86 static bool welcomed = false;
90 fputs ("PSPP is free software and you are welcome to distribute copies of "
91 "it\nunder certain conditions; type \"show copying.\" to see the "
92 "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show "
93 "warranty.\" for details.\n", stdout);
96 #if HAVE_READLINE && unix
97 if (history_file == NULL)
99 history_file = tilde_expand ("~/.pspp_history");
101 read_history (history_file);
102 stifle_history (500);
107 /* Gets a line from the user and stores it into LINE.
108 Prompts the user with PROMPT.
109 Returns true if successful, false at end of file.
110 Suitable for passing to getl_append_interactive(). */
112 readln_read (struct string *line, const char *prompt)
120 err_error_count = err_warning_count = 0;
121 err_already_flagged = 0;
126 string = readline (prompt);
132 add_history (string);
133 ds_replace (line, string);
138 fputs (prompt, stdout);
140 if (ds_gets (line, stdin))
142 ds_chomp (line, '\n');