#include <language/command.h>
#include <language/lexer/lexer.h>
#include <libpspp/alloc.h>
+#include <libpspp/assertion.h>
#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/str.h>
function;
/* INTERACTIVE. */
- bool (*interactive) (struct string *line, const char *prompt);
+ bool (*interactive) (struct string *line, enum getl_prompt_style);
}
u;
static struct string getl_include_path;
-struct string getl_buf;
static void close_source (void);
static void init_prompts (void);
static void uninit_prompts (void);
-static const char *get_prompt (void);
+static enum getl_prompt_style get_prompt_style (void);
+
/* Initialize getl. */
void
getl_initialize (void)
{
- ds_create (&getl_include_path,
- fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
- ds_init (&getl_buf);
+ ds_init_cstr (&getl_include_path,
+ fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
init_prompts ();
}
+
/* Delete everything from the include path. */
void
getl_clear_include_path (void)
getl_add_include_dir (const char *path)
{
if (ds_length (&getl_include_path))
- ds_putc (&getl_include_path, ':');
+ ds_put_char (&getl_include_path, ':');
- ds_puts (&getl_include_path, path);
+ ds_put_cstr (&getl_include_path, path);
}
/* Appends source S to the list of source files. */
/* Creates an interactive source with the given FUNCTION. */
static struct getl_source *
create_interactive_source (bool (*function) (struct string *line,
- const char *prompt))
+ enum getl_prompt_style))
{
struct getl_source *s = xmalloc (sizeof *s);
s->fn = NULL;
{
if (cur_source != NULL)
{
- char *found_fn = fn_search_path (fn, ds_c_str (&getl_include_path),
+ char *found_fn = fn_search_path (fn, ds_cstr (&getl_include_path),
fn_dir_name (cur_source->fn));
if (found_fn != NULL)
{
obtained or false at end of file. */
void
getl_append_interactive (bool (*function) (struct string *line,
- const char *prompt))
+ enum getl_prompt_style))
{
append_source (create_interactive_source (function));
}
/* File locator stack. */
static const struct msg_locator **file_loc;
+
static int nfile_loc, mfile_loc;
\f
/* Close getl. */
{
while (cur_source != NULL)
close_source ();
- ds_destroy (&getl_buf);
ds_destroy (&getl_include_path);
free(file_loc);
file_loc = NULL;
nfile_loc--;
}
-/* Puts the current file and line number in F, or NULL and -1 if
+/* Puts the current file and line number into LOC, or NULL and -1 if
none. */
void
-msg_location (struct msg_locator *loc)
+get_msg_location (struct msg_locator *loc)
{
if (nfile_loc)
*loc = *file_loc[nfile_loc - 1];
do
{
s->ln++;
- if (!ds_gets (line, s->u.syntax_file))
+ if (!ds_read_line (line, s->u.syntax_file))
{
if (ferror (s->u.syntax_file))
msg (ME, _("Reading `%s': %s."), s->fn, strerror (errno));
}
ds_chomp (line, '\n');
}
- while (s->ln == 1 && !memcmp (ds_c_str (line), "#!", 2));
+ while (s->ln == 1 && !memcmp (ds_cstr (line), "#!", 2));
/* Echo to listing file, if configured to do so. */
if (get_echo ())
- tab_output_text (TAB_LEFT | TAB_FIX, ds_c_str (line));
+ tab_output_text (TAB_LEFT | TAB_FIX, ds_cstr (line));
return true;
}
case FUNCTION:
return s->u.function.read (line, &s->fn, &s->ln, s->u.function.aux);
case INTERACTIVE:
- return s->u.interactive (line, get_prompt ());
+ return s->u.interactive (line, get_prompt_style ());
}
- abort ();
+ NOT_REACHED ();
}
/* Reads a single line into LINE.
If INTERACTIVE is non-null, then when true is returned
*INTERACTIVE will be set to true if the line was obtained
interactively, false otherwise. */
-static bool
+bool
do_read_line (struct string *line, bool *interactive)
{
while (cur_source != NULL)
return false;
}
-/* Reads a single line into getl_buf.
- Returns true when a line has been read, false at end of input.
- If INTERACTIVE is non-null, then when true is returned
- *INTERACTIVE will be set to true if the line was obtained
- interactively, false otherwise. */
-bool
-getl_read_line (bool *interactive)
-{
- return do_read_line (&getl_buf, interactive);
-}
\f
/* Current prompts in each style. */
static char *prompts[GETL_PROMPT_CNT];
}
/* Returns the current prompt. */
-static const char *
-get_prompt (void)
+static enum getl_prompt_style
+get_prompt_style (void)
{
- return prompts[current_style];
+ return current_style;
}