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
22 #include "read-line.h"
31 #include <data/file-name.h>
32 #include <data/file-name.h>
33 #include <data/settings.h>
34 #include <language/command.h>
35 #include <libpspp/message.h>
36 #include <libpspp/str.h>
37 #include <libpspp/version.h>
38 #include <output/table.h>
41 #define _(msgid) gettext (msgid)
45 #include <readline/readline.h>
46 #include <readline/history.h>
48 static char *history_file;
49 #endif /* HAVE_READLINE */
51 static bool initialised = false;
53 /* Initialize getl. */
55 readln_initialize (void)
60 rl_completion_entry_function = pspp_completion_function;
62 if (history_file == NULL)
64 history_file = tilde_expand ("~/.pspp_history");
66 read_history (history_file);
75 readln_uninitialize (void)
79 #if HAVE_READLINE && unix
80 if (history_file != NULL)
81 write_history (history_file);
85 /* Display a welcoming message. */
89 static bool welcomed = false;
93 fputs ("PSPP is free software and you are welcome to distribute copies of "
94 "it\nunder certain conditions; type \"show copying.\" to see the "
95 "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show "
96 "warranty.\" for details.\n", stdout);
99 #if HAVE_READLINE && unix
100 if (history_file == NULL)
102 history_file = tilde_expand ("~/.pspp_history");
104 read_history (history_file);
105 stifle_history (500);
110 /* Gets a line from the user and stores it into LINE.
111 Prompts the user with PROMPT.
112 Returns true if successful, false at end of file.
113 Suitable for passing to getl_append_interactive(). */
115 readln_read (struct string *line, const char *prompt)
128 string = readline (prompt);
134 add_history (string);
135 ds_assign_c_str (line, string);
140 fputs (prompt, stdout);
142 if (ds_gets (line, stdin))
144 ds_chomp (line, '\n');