projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed buglet in file open action.
[pspp]
/
src
/
libpspp
/
getl.c
diff --git
a/src/libpspp/getl.c
b/src/libpspp/getl.c
index 1c18733dce23e778b5a73548f8608efd82459352..e2452c548f171ea120b61fae44562482d53e851b 100644
(file)
--- a/
src/libpspp/getl.c
+++ b/
src/libpspp/getl.c
@@
-1,6
+1,5
@@
/* PSPP - computes sample statistics.
Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
/* PSPP - computes sample statistics.
Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@
-18,7
+17,6
@@
02110-1301, USA. */
#include <stdlib.h>
02110-1301, USA. */
#include <stdlib.h>
-
#include <config.h>
#include "getl.h"
#include <config.h>
#include "getl.h"
@@
-28,8
+26,6
@@
#include <libpspp/version.h>
#include <libpspp/alloc.h>
#include <libpspp/version.h>
#include <libpspp/alloc.h>
-#include <data/file-name.h>
-
struct getl_source
{
struct getl_source *included_from; /* File that this is nested inside. */
struct getl_source
{
struct getl_source *included_from; /* File that this is nested inside. */
@@
-40,66
+36,74
@@
struct getl_source
struct getl_interface *interface;
};
struct getl_interface *interface;
};
-/* List of source files. */
-static struct ll_list sources ;
+struct source_stream
+ {
+ struct ll_list sources ; /* List of source files. */
-static struct string the_include_path;
+ struct string the_include_path;
+ };
const char *
const char *
-getl_include_path (
void
)
+getl_include_path (
const struct source_stream *ss
)
{
{
- return ds_cstr (&the_include_path);
+ return ds_cstr (&
ss->
the_include_path);
}
static struct getl_source *
}
static struct getl_source *
-current_source (
struct ll_list *list
)
+current_source (
const struct source_stream *ss
)
{
{
- const struct ll *ll = ll_head (
list
);
+ const struct ll *ll = ll_head (
&ss->sources
);
return ll_data (ll, struct getl_source, ll );
}
/* Initialize getl. */
return ll_data (ll, struct getl_source, ll );
}
/* Initialize getl. */
-void
-
getl_initialize (void
)
+struct source_stream *
+
create_source_stream (const char *initial_include_path
)
{
{
- ll_init (&sources);
- ds_init_cstr (&the_include_path,
+ struct source_stream *ss = xzalloc (sizeof (*ss));
+ ll_init (&ss->sources);
+#if 0
+ ds_init_cstr (&ss->the_include_path,
fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
+#endif
+ ds_init_cstr (&ss->the_include_path, initial_include_path);
+
+ return ss;
}
/* Delete everything from the include path. */
void
}
/* Delete everything from the include path. */
void
-getl_clear_include_path (
void
)
+getl_clear_include_path (
struct source_stream *ss
)
{
{
- ds_clear (&the_include_path);
+ ds_clear (&
ss->
the_include_path);
}
/* Add to the include path. */
void
}
/* Add to the include path. */
void
-getl_add_include_dir (const char *path)
+getl_add_include_dir (
struct source_stream *ss,
const char *path)
{
{
- if (ds_length (&the_include_path))
- ds_put_char (&the_include_path, ':');
+ if (ds_length (&
ss->
the_include_path))
+ ds_put_char (&
ss->
the_include_path, ':');
- ds_put_cstr (&the_include_path, path);
+ ds_put_cstr (&
ss->
the_include_path, path);
}
/* Appends source S to the list of source files. */
void
}
/* Appends source S to the list of source files. */
void
-getl_append_source (struct getl_interface *i)
+getl_append_source (struct
source_stream *ss, struct
getl_interface *i)
{
struct getl_source *s = xzalloc (sizeof ( struct getl_source ));
s->interface = i ;
{
struct getl_source *s = xzalloc (sizeof ( struct getl_source ));
s->interface = i ;
- ll_push_head (&sources, &s->ll);
+ ll_push_head (&s
s->s
ources, &s->ll);
}
/* Nests source S within the current source file. */
void
}
/* Nests source S within the current source file. */
void
-getl_include_source (struct getl_interface *i)
+getl_include_source (struct
source_stream *ss, struct
getl_interface *i)
{
{
- struct getl_source *current = current_source (
&source
s);
+ struct getl_source *current = current_source (
s
s);
struct getl_source *s = xzalloc (sizeof ( struct getl_source ));
s->interface = i;
struct getl_source *s = xzalloc (sizeof ( struct getl_source ));
s->interface = i;
@@
-108,23
+112,23
@@
getl_include_source (struct getl_interface *i)
s->includes = NULL;
current->includes = s;
s->includes = NULL;
current->includes = s;
- ll_push_head (&sources, &s->ll);
+ ll_push_head (&s
s->s
ources, &s->ll);
}
/* Closes the current source, and move the current source to the
next file in the chain. */
static void
}
/* Closes the current source, and move the current source to the
next file in the chain. */
static void
-close_source (
void
)
+close_source (
struct source_stream *ss
)
{
{
- struct getl_source *s = current_source (
&source
s);
+ struct getl_source *s = current_source (
s
s);
if ( s->interface->close )
s->interface->close (s->interface);
if ( s->interface->close )
s->interface->close (s->interface);
- ll_pop_head (&sources);
+ ll_pop_head (&s
s->s
ources);
if (s->included_from != NULL)
if (s->included_from != NULL)
- current_source (
&source
s)->includes = NULL;
+ current_source (
s
s)->includes = NULL;
free (s);
}
free (s);
}
@@
-132,25
+136,25
@@
close_source (void)
/* Closes all sources until an interactive source is
encountered. */
void
/* Closes all sources until an interactive source is
encountered. */
void
-getl_abort_noninteractive (
void
)
+getl_abort_noninteractive (
struct source_stream *ss
)
{
{
- while ( ! ll_is_empty (&sources))
+ while ( ! ll_is_empty (&s
s->s
ources))
{
{
- const struct getl_source *s = current_source (
&source
s);
+ const struct getl_source *s = current_source (
s
s);
if ( !s->interface->interactive (s->interface) )
if ( !s->interface->interactive (s->interface) )
- close_source ();
+ close_source (
ss
);
}
}
/* Returns true if the current source is interactive,
false otherwise. */
bool
}
}
/* Returns true if the current source is interactive,
false otherwise. */
bool
-getl_is_interactive (
void
)
+getl_is_interactive (
const struct source_stream *ss
)
{
{
- const struct getl_source *s = current_source (
&source
s);
+ const struct getl_source *s = current_source (
s
s);
- if (ll_is_empty (&sources) )
+ if (ll_is_empty (&s
s->s
ources) )
return false;
return s->interface->interactive (s->interface);
return false;
return s->interface->interactive (s->interface);
@@
-159,11
+163,11
@@
getl_is_interactive (void)
/* Returns the name of the current source, or NULL if there is no
current source */
const char *
/* Returns the name of the current source, or NULL if there is no
current source */
const char *
-getl_source_name (
void
)
+getl_source_name (
const struct source_stream *ss
)
{
{
- const struct getl_source *s = current_source (
&source
s);
+ const struct getl_source *s = current_source (
s
s);
- if ( ll_is_empty (&sources) )
+ if ( ll_is_empty (&s
s->s
ources) )
return NULL;
if ( ! s->interface->name )
return NULL;
if ( ! s->interface->name )
@@
-175,11
+179,11
@@
getl_source_name (void)
/* Returns the location within the current source, or -1 if there is
no current source */
int
/* Returns the location within the current source, or -1 if there is
no current source */
int
-getl_source_location (
void
)
+getl_source_location (
const struct source_stream *ss
)
{
{
- const struct getl_source *s = current_source (
&source
s);
+ const struct getl_source *s = current_source (
s
s);
- if ( ll_is_empty (&sources) )
+ if ( ll_is_empty (&s
s->s
ources) )
return -1;
if ( !s->interface->location )
return -1;
if ( !s->interface->location )
@@
-191,42
+195,40
@@
getl_source_location (void)
/* Close getl. */
void
/* Close getl. */
void
-
getl_uninitialize (void
)
+
destroy_source_stream (struct source_stream *ss
)
{
{
- while ( !ll_is_empty (&sources))
- close_source ();
- ds_destroy (&the_include_path);
+ while ( !ll_is_empty (&ss->sources))
+ close_source (ss);
+ ds_destroy (&ss->the_include_path);
+
+ free (ss);
}
/* Reads a single line into LINE.
Returns true when a line has been read, false at end of input.
}
/* Reads a single line into LINE.
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. */
+ On success, sets *SYNTAX to the style of the syntax read. */
bool
bool
-do_read_line (struct string *line, bool *interactive)
+getl_read_line (struct source_stream *ss, struct string *line,
+ enum getl_syntax *syntax)
{
{
- while (!ll_is_empty (&sources))
+ while (!ll_is_empty (&s
s->s
ources))
{
{
- struct getl_source *s = current_source (
&source
s);
+ struct getl_source *s = current_source (
s
s);
ds_clear (line);
ds_clear (line);
- if (s->interface->read (s->interface, line))
+ if (s->interface->read (s->interface, line
, syntax
))
{
{
- if (interactive != NULL)
- *interactive = s->interface->interactive (s->interface);
-
while (s)
{
if (s->interface->filter)
while (s)
{
if (s->interface->filter)
- s->interface->filter (s->interface, line);
+ s->interface->filter (s->interface, line
, *syntax
);
s = s->included_from;
}
s = s->included_from;
}
-
+
return true;
}
return true;
}
- close_source ();
+ close_source (
ss
);
}
return false;
}
return false;