X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fgetl.c;h=302cd9137ddbc7b748ae07c9c4c34103ffecbf86;hb=6ed74d8699a65ef63f04ccef33ab1c8600d6eb9f;hp=4a320960226d8f2db2c7ec4c43bef6a931b1376d;hpb=65e61cc92b48297625bc71cf31b8a19e301eb6c1;p=pspp-builds.git diff --git a/src/libpspp/getl.c b/src/libpspp/getl.c index 4a320960..302cd913 100644 --- a/src/libpspp/getl.c +++ b/src/libpspp/getl.c @@ -1,46 +1,44 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. - Written by Ben Pfaff . +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -#include + along with this program. If not, see . */ #include +#include + #include "getl.h" #include #include #include -#include -#include +#include "xalloc.h" struct getl_source { struct getl_source *included_from; /* File that this is nested inside. */ struct getl_source *includes; /* File nested inside this file. */ - + struct ll ll; /* Element in the sources list */ struct getl_interface *interface; + enum syntax_mode syntax_mode; + enum error_mode error_mode; }; -struct source_stream +struct source_stream { struct ll_list sources ; /* List of source files. */ @@ -60,14 +58,38 @@ current_source (const struct source_stream *ss) return ll_data (ll, struct getl_source, ll ); } +enum syntax_mode +source_stream_current_syntax_mode (const struct source_stream *ss) +{ + struct getl_source *cs = current_source (ss); + + return cs->syntax_mode; +} + + + +enum error_mode +source_stream_current_error_mode (const struct source_stream *ss) +{ + struct getl_source *cs = current_source (ss); + + return cs->error_mode; +} + + + /* Initialize getl. */ struct source_stream * -create_source_stream (void) +create_source_stream (const char *initial_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)); +#endif + ds_init_cstr (&ss->the_include_path, initial_include_path); + return ss; } @@ -90,18 +112,26 @@ getl_add_include_dir (struct source_stream *ss, const char *path) /* Appends source S to the list of source files. */ void -getl_append_source (struct source_stream *ss, struct getl_interface *i) +getl_append_source (struct source_stream *ss, + struct getl_interface *i, + enum syntax_mode syntax_mode, + enum error_mode err_mode) { struct getl_source *s = xzalloc (sizeof ( struct getl_source )); s->interface = i ; + s->syntax_mode = syntax_mode; + s->error_mode = err_mode; - ll_push_head (&ss->sources, &s->ll); + ll_push_tail (&ss->sources, &s->ll); } /* Nests source S within the current source file. */ void -getl_include_source (struct source_stream *ss, struct getl_interface *i) +getl_include_source (struct source_stream *ss, + struct getl_interface *i, + enum syntax_mode syntax_mode, + enum error_mode err_mode) { struct getl_source *current = current_source (ss); struct getl_source *s = xzalloc (sizeof ( struct getl_source )); @@ -110,19 +140,21 @@ getl_include_source (struct source_stream *ss, struct getl_interface *i) s->included_from = current ; s->includes = NULL; + s->syntax_mode = syntax_mode; + s->error_mode = err_mode; current->includes = s; ll_push_head (&ss->sources, &s->ll); } -/* Closes the current source, and move the current source to the +/* Closes the current source, and move the current source to the next file in the chain. */ static void close_source (struct source_stream *ss) { struct getl_source *s = current_source (ss); - if ( s->interface->close ) + if ( s->interface->close ) s->interface->close (s->interface); ll_pop_head (&ss->sources); @@ -136,13 +168,13 @@ close_source (struct source_stream *ss) /* Closes all sources until an interactive source is encountered. */ void -getl_abort_noninteractive (struct source_stream *ss) +getl_abort_noninteractive (struct source_stream *ss) { while ( ! ll_is_empty (&ss->sources)) { const struct getl_source *s = current_source (ss); - - if ( !s->interface->interactive (s->interface) ) + + if ( !s->interface->interactive (s->interface) ) close_source (ss); } } @@ -150,17 +182,17 @@ getl_abort_noninteractive (struct source_stream *ss) /* Returns true if the current source is interactive, false otherwise. */ bool -getl_is_interactive (const struct source_stream *ss) +getl_is_interactive (const struct source_stream *ss) { const struct getl_source *s = current_source (ss); - if (ll_is_empty (&ss->sources) ) + if (ll_is_empty (&ss->sources) ) return false; return s->interface->interactive (s->interface); } -/* Returns the name of the current source, or NULL if there is no +/* Returns the name of the current source, or NULL if there is no current source */ const char * getl_source_name (const struct source_stream *ss) @@ -170,7 +202,7 @@ getl_source_name (const struct source_stream *ss) if ( ll_is_empty (&ss->sources) ) return NULL; - if ( ! s->interface->name ) + if ( ! s->interface->name ) return NULL; return s->interface->name (s->interface); @@ -207,22 +239,22 @@ destroy_source_stream (struct source_stream *ss) /* Reads a single line into LINE. Returns true when a line has been read, false at end of input. - On success, sets *SYNTAX to the style of the syntax read. */ +*/ bool -getl_read_line (struct source_stream *ss, struct string *line, - enum getl_syntax *syntax) +getl_read_line (struct source_stream *ss, struct string *line) { + assert (ss != NULL); while (!ll_is_empty (&ss->sources)) { struct getl_source *s = current_source (ss); ds_clear (line); - if (s->interface->read (s->interface, line, syntax)) + if (s->interface->read (s->interface, line)) { while (s) { if (s->interface->filter) - s->interface->filter (s->interface, line, *syntax); + s->interface->filter (s->interface, line); s = s->included_from; }