projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
(close_active_file) Remove unnecessary test.
[pspp]
/
src
/
getline.c
diff --git
a/src/getline.c
b/src/getline.c
index 89370b1332b3c9b5d9e50f1314bbedc78985910c..d0170980096160a65d7f26b756f5018cafc883e0 100644
(file)
--- a/
src/getline.c
+++ b/
src/getline.c
@@
-14,16
+14,17
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include "getline.h"
#include <config.h>
#include "getline.h"
-#include
<assert.h>
+#include
"error.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "alloc.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "alloc.h"
+#include "command.h"
#include "error.h"
#include "filename.h"
#include "lexer.h"
#include "error.h"
#include "filename.h"
#include "lexer.h"
@@
-43,6
+44,10
@@
int getl_welcomed;
int getl_mode;
int getl_prompt;
int getl_mode;
int getl_prompt;
+#if HAVE_LIBREADLINE
+#include <readline/readline.h>
+#endif
+
#if HAVE_LIBHISTORY
static char *history_file;
#if HAVE_LIBHISTORY
static char *history_file;
@@
-57,6
+62,9
@@
extern int write_history (char *);
#endif /* no readline/history.h */
#endif /* -lhistory */
#endif /* no readline/history.h */
#endif /* -lhistory */
+
+extern struct cmd_set cmd;
+
static struct string getl_include_path;
/* Number of levels of DO REPEAT structures we're nested inside. If
static struct string getl_include_path;
/* Number of levels of DO REPEAT structures we're nested inside. If
@@
-70,19
+78,25
@@
static int read_console (void);
void
getl_initialize (void)
{
void
getl_initialize (void)
{
- ds_create (
NULL,
&getl_include_path,
+ ds_create (&getl_include_path,
fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
- ds_init (NULL, &getl_buf, 256);
+ ds_init (&getl_buf, 256);
+#if HAVE_LIBREADLINE
+ rl_completion_entry_function = pspp_completion_function;
+#endif
}
/* Close getline. */
void
getl_uninitialize (void)
{
}
/* Close getline. */
void
getl_uninitialize (void)
{
+ getl_close_all();
#if HAVE_LIBHISTORY && defined (unix)
if (history_file)
write_history (history_file);
#endif
#if HAVE_LIBHISTORY && defined (unix)
if (history_file)
write_history (history_file);
#endif
+ ds_destroy (&getl_buf);
+ ds_destroy (&getl_include_path);
}
/* Returns a string that represents the directory that the syntax file
}
/* Returns a string that represents the directory that the syntax file
@@
-107,9
+121,9
@@
void
getl_add_include_dir (const char *path)
{
if (ds_length (&getl_include_path))
getl_add_include_dir (const char *path)
{
if (ds_length (&getl_include_path))
- ds_putc
har
(&getl_include_path, PATH_DELIMITER);
+ ds_putc (&getl_include_path, PATH_DELIMITER);
- ds_
concat
(&getl_include_path, path);
+ ds_
puts
(&getl_include_path, path);
}
/* Adds FN to the tail end of the list of script files to execute.
}
/* Adds FN to the tail end of the list of script files to execute.
@@
-152,7
+166,7
@@
getl_include (const char *fn)
{
char *cur_dir = getl_get_current_directory ();
{
char *cur_dir = getl_get_current_directory ();
- real_fn = fn_search_path (fn, ds_
value
(&getl_include_path), cur_dir);
+ real_fn = fn_search_path (fn, ds_
c_str
(&getl_include_path), cur_dir);
free (cur_dir);
}
free (cur_dir);
}
@@
-271,7
+285,7
@@
handle_line_buffer (void)
}
while (s->cur_line == NULL);
}
while (s->cur_line == NULL);
- ds_concat
_buffer
(&getl_buf, s->cur_line->line, s->cur_line->len);
+ ds_concat (&getl_buf, s->cur_line->line, s->cur_line->len);
/* Advance pointers. */
s->cur_line = s->cur_line->next;
/* Advance pointers. */
s->cur_line = s->cur_line->next;
@@
-307,7
+321,7
@@
getl_read_line (void)
perform_DO_REPEAT_substitutions ();
if (getl_head->print)
tab_output_text (TAB_LEFT | TAT_FIX | TAT_PRINTF, "+%s",
perform_DO_REPEAT_substitutions ();
if (getl_head->print)
tab_output_text (TAB_LEFT | TAT_FIX | TAT_PRINTF, "+%s",
- ds_
value
(&getl_buf));
+ ds_
c_str
(&getl_buf));
return 1;
}
return 1;
}
@@
-324,7
+338,7
@@
getl_read_line (void)
}
}
}
}
- if (!ds_get
line
(&getl_buf, s->f))
+ if (!ds_get
s
(&getl_buf, s->f))
{
if (ferror (s->f))
msg (ME, _("Reading `%s': %s."), s->fn, strerror (errno));
{
if (ferror (s->f))
msg (ME, _("Reading `%s': %s."), s->fn, strerror (errno));
@@
-334,14
+348,14
@@
getl_read_line (void)
if (ds_length (&getl_buf) > 0 && ds_end (&getl_buf)[-1] == '\n')
ds_truncate (&getl_buf, ds_length (&getl_buf) - 1);
if (ds_length (&getl_buf) > 0 && ds_end (&getl_buf)[-1] == '\n')
ds_truncate (&getl_buf, ds_length (&getl_buf) - 1);
- if (
set_echo
)
- tab_output_text (TAB_LEFT | TAT_FIX, ds_
value
(&getl_buf));
+ if (
get_echo()
)
+ tab_output_text (TAB_LEFT | TAT_FIX, ds_
c_str
(&getl_buf));
getl_head->ln++;
/* Allows shebang invocation: `#! /usr/local/bin/pspp'. */
getl_head->ln++;
/* Allows shebang invocation: `#! /usr/local/bin/pspp'. */
- if (ds_
value
(&getl_buf)[0] == '#'
- && ds_
value
(&getl_buf)[1] == '!')
+ if (ds_
c_str
(&getl_buf)[0] == '#'
+ && ds_
c_str
(&getl_buf)[1] == '!')
continue;
return 1;
continue;
return 1;
@@
-436,19
+450,20
@@
read_console (void)
switch (getl_prompt)
{
case GETL_PRPT_STANDARD:
switch (getl_prompt)
{
case GETL_PRPT_STANDARD:
- prompt =
set_prompt
;
+ prompt =
get_prompt()
;
break;
case GETL_PRPT_CONTINUATION:
break;
case GETL_PRPT_CONTINUATION:
- prompt =
set_cprompt
;
+ prompt =
get_cprompt()
;
break;
case GETL_PRPT_DATA:
break;
case GETL_PRPT_DATA:
- prompt =
set_dprompt
;
+ prompt =
get_dprompt()
;
break;
default:
assert (0);
break;
default:
assert (0);
+ abort ();
}
line = readline (prompt);
}
line = readline (prompt);
@@
-461,7
+476,9
@@
read_console (void)
#endif
ds_clear (&getl_buf);
#endif
ds_clear (&getl_buf);
- ds_concat (&getl_buf, line);
+ ds_puts (&getl_buf, line);
+
+ free (line);
return 1;
}
return 1;
}
@@
-472,9
+489,9
@@
read_console (void)
err_error_count = err_warning_count = 0;
err_already_flagged = 0;
err_error_count = err_warning_count = 0;
err_already_flagged = 0;
- fputs (getl_prompt ?
set_cprompt : set_prompt
, stdout);
+ fputs (getl_prompt ?
get_cprompt() : get_prompt()
, stdout);
ds_clear (&getl_buf);
ds_clear (&getl_buf);
- if (ds_get
line
(&getl_buf, stdin))
+ if (ds_get
s
(&getl_buf, stdin))
return 1;
if (ferror (stdin))
return 1;
if (ferror (stdin))