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_basic_word_break_characters = "\n";
61 rl_attempted_completion_function = pspp_attempted_completion_function;
63 if (history_file == NULL)
65 history_file = tilde_expand ("~/.pspp_history");
67 read_history (history_file);
76 readln_uninitialize (void)
80 #if HAVE_READLINE && unix
81 if (history_file != NULL)
82 write_history (history_file);
86 /* Display a welcoming message. */
90 static bool welcomed = false;
94 fputs ("PSPP is free software and you are welcome to distribute copies of "
95 "it\nunder certain conditions; type \"show copying.\" to see the "
96 "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show "
97 "warranty.\" for details.\n", stdout);
100 #if HAVE_READLINE && unix
101 if (history_file == NULL)
103 history_file = tilde_expand ("~/.pspp_history");
105 read_history (history_file);
106 stifle_history (500);
111 /* Gets a line from the user and stores it into LINE.
112 Prompts the user with PROMPT.
113 Returns true if successful, false at end of file.
114 Suitable for passing to getl_append_interactive(). */
116 readln_read (struct string *line, const char *prompt)
129 string = readline (prompt);
135 add_history (string);
136 ds_assign_cstr (line, string);
141 fputs (prompt, stdout);
143 if (ds_read_line (line, stdin))
145 ds_chomp (line, '\n');