From: John Darrington Date: Tue, 5 Dec 2006 11:27:42 +0000 (+0000) Subject: Applied patch #5611 X-Git-Tag: v0.6.0~668 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65e61cc92b48297625bc71cf31b8a19e301eb6c1;p=pspp-builds.git Applied patch #5611 --- diff --git a/src/language/control/repeat.c b/src/language/control/repeat.c index 200b6bce..0a7da0a6 100644 --- a/src/language/control/repeat.c +++ b/src/language/control/repeat.c @@ -139,7 +139,7 @@ cmd_do_repeat (struct lexer *lexer, struct dataset *ds) block->parent.location = do_repeat_location; if (!ll_is_empty (&block->lines)) - getl_include_source (&block->parent); + getl_include_source (lex_get_source_stream (lexer), &block->parent); else pool_destroy (block->pool); @@ -310,7 +310,7 @@ parse_lines (struct lexer *lexer, struct repeat_block *block) ds_init_string (&text, lex_entire_line_ds (lexer)); /* Record file name. */ - cur_file_name = getl_source_name (); + cur_file_name = getl_source_name (lex_get_source_stream (lexer)); if (cur_file_name != NULL && (previous_file_name == NULL || !strcmp (cur_file_name, previous_file_name))) @@ -319,7 +319,7 @@ parse_lines (struct lexer *lexer, struct repeat_block *block) /* Create a line structure. */ line = pool_alloc (block->pool, sizeof *line); line->file_name = previous_file_name; - line->line_number = getl_source_location (); + line->line_number = getl_source_location (lex_get_source_stream (lexer)); ss_alloc_substring_pool (&line->text, ds_ss (&text), block->pool); line->syntax = syntax; diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index 907a77ce..b1c05c81 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -49,7 +49,7 @@ struct lexer { struct string line_buffer; - bool (*read_line) (struct string *, enum getl_syntax *); + struct source_stream *ss; int token; /* Current token. */ double tokval; /* T_POS_NUM, T_NEG_NUM: the token's value. */ @@ -93,14 +93,14 @@ static void dump_token (void); /* Initializes the lexer. */ struct lexer * -lex_create (bool (*read_line_func) (struct string *, enum getl_syntax *)) +lex_create (struct source_stream *ss) { struct lexer *lexer = xzalloc (sizeof (*lexer)); ds_init_empty (&lexer->tokstr); ds_init_empty (&lexer->put_tokstr); ds_init_empty (&lexer->line_buffer); - lexer->read_line = read_line_func; + lexer->ss = ss; if (!lex_get_line (lexer)) lexer->eof = true; @@ -108,6 +108,13 @@ lex_create (bool (*read_line_func) (struct string *, enum getl_syntax *)) return lexer; } +struct source_stream * +lex_get_source_stream (const struct lexer *lex) +{ + return lex->ss; +} + + void lex_destroy (struct lexer *lexer) { @@ -752,7 +759,7 @@ lex_discard_line (struct lexer *lexer) void lex_discard_rest_of_command (struct lexer *lexer) { - if (!getl_is_interactive ()) + if (!getl_is_interactive (lexer->ss)) { while (lexer->token != T_STOP && lexer->token != '.') lex_get (lexer); @@ -842,7 +849,7 @@ bool lex_get_line_raw (struct lexer *lexer, enum getl_syntax *syntax) { enum getl_syntax dummy; - bool ok = lexer->read_line (&lexer->line_buffer, + bool ok = getl_read_line (lexer->ss, &lexer->line_buffer, syntax != NULL ? syntax : &dummy); return ok; } @@ -976,13 +983,6 @@ lex_negative_to_dash (struct lexer *lexer) } } -/* We're not at eof any more. */ -void -lex_reset_eof (struct lexer *lexer) -{ - lexer->eof = false; -} - /* Skip a COMMENT command. */ void lex_skip_comment (struct lexer *lexer) diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h index 509173d9..6d91645c 100644 --- a/src/language/lexer/lexer.h +++ b/src/language/lexer/lexer.h @@ -30,10 +30,10 @@ struct lexer; /* Initialization. */ -struct lexer * lex_create (bool (*)(struct string *, enum getl_syntax *)); +struct lexer * lex_create (struct source_stream *); void lex_destroy (struct lexer *); - +struct source_stream * lex_get_source_stream (const struct lexer *); /* Common functions. */ @@ -93,7 +93,6 @@ const struct string *lex_tokstr (const struct lexer *); /* Really weird functions. */ void lex_negative_to_dash (struct lexer *); -void lex_reset_eof (struct lexer *); void lex_skip_comment (struct lexer *); #endif /* !lexer_h */ diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c index c812c972..9f666747 100644 --- a/src/language/utilities/include.c +++ b/src/language/utilities/include.c @@ -36,6 +36,7 @@ int cmd_include (struct lexer *lexer, struct dataset *ds UNUSED) { + struct source_stream *ss; char *found_fn; char *target_fn; @@ -52,13 +53,12 @@ cmd_include (struct lexer *lexer, struct dataset *ds UNUSED) target_fn = ds_cstr (lex_tokstr (lexer)); - found_fn = fn_search_path (target_fn, - getl_include_path (), - NULL); + ss = lex_get_source_stream (lexer); + found_fn = fn_search_path (target_fn, getl_include_path ( ss ), NULL); if (found_fn != NULL) { - getl_include_source (create_syntax_file_source (found_fn)); + getl_include_source (ss, create_syntax_file_source (found_fn)); free (found_fn); } else diff --git a/src/libpspp/getl.c b/src/libpspp/getl.c index 200e07e3..4a320960 100644 --- a/src/libpspp/getl.c +++ b/src/libpspp/getl.c @@ -40,66 +40,70 @@ struct getl_source 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 * -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 * -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. */ -void -getl_initialize (void) +struct source_stream * +create_source_stream (void) { - ll_init (&sources); - ds_init_cstr (&the_include_path, + struct source_stream *ss = xzalloc (sizeof (*ss)); + ll_init (&ss->sources); + ds_init_cstr (&ss->the_include_path, fn_getenv_default ("STAT_INCLUDE_PATH", include_path)); + return ss; } /* 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 -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 -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 ; - ll_push_head (&sources, &s->ll); + ll_push_head (&ss->sources, &s->ll); } /* 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 (&sources); + struct getl_source *current = current_source (ss); 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; - ll_push_head (&sources, &s->ll); + ll_push_head (&ss->sources, &s->ll); } /* 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 (&sources); + struct getl_source *s = current_source (ss); if ( s->interface->close ) s->interface->close (s->interface); - ll_pop_head (&sources); + ll_pop_head (&ss->sources); if (s->included_from != NULL) - current_source (&sources)->includes = NULL; + current_source (ss)->includes = NULL; free (s); } @@ -132,25 +136,25 @@ close_source (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 (&ss->sources)) { - const struct getl_source *s = current_source (&sources); + const struct getl_source *s = current_source (ss); if ( !s->interface->interactive (s->interface) ) - close_source (); + close_source (ss); } } /* 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 (&sources); + const struct getl_source *s = current_source (ss); - if (ll_is_empty (&sources) ) + if (ll_is_empty (&ss->sources) ) 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 * -getl_source_name (void) +getl_source_name (const struct source_stream *ss) { - const struct getl_source *s = current_source (&sources); + const struct getl_source *s = current_source (ss); - if ( ll_is_empty (&sources) ) + if ( ll_is_empty (&ss->sources) ) 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 -getl_source_location (void) +getl_source_location (const struct source_stream *ss) { - const struct getl_source *s = current_source (&sources); + const struct getl_source *s = current_source (ss); - if ( ll_is_empty (&sources) ) + if ( ll_is_empty (&ss->sources) ) return -1; if ( !s->interface->location ) @@ -191,11 +195,13 @@ getl_source_location (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); } @@ -203,11 +209,12 @@ getl_uninitialize (void) 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 -do_read_line (struct string *line, enum getl_syntax *syntax) +getl_read_line (struct source_stream *ss, struct string *line, + enum getl_syntax *syntax) { - while (!ll_is_empty (&sources)) + while (!ll_is_empty (&ss->sources)) { - struct getl_source *s = current_source (&sources); + struct getl_source *s = current_source (ss); ds_clear (line); if (s->interface->read (s->interface, line, syntax)) @@ -218,10 +225,10 @@ do_read_line (struct string *line, enum getl_syntax *syntax) s->interface->filter (s->interface, line, *syntax); s = s->included_from; } - + return true; } - close_source (); + close_source (ss); } return false; diff --git a/src/libpspp/getl.h b/src/libpspp/getl.h index 27faee64..f39f559c 100644 --- a/src/libpspp/getl.h +++ b/src/libpspp/getl.h @@ -23,12 +23,12 @@ #include #include -struct string; +struct string; struct getl_source; /* Syntax rules that apply to a given source line. */ -enum getl_syntax +enum getl_syntax { /* Each line that begins in column 1 starts a new command. A `+' or `-' in column 1 is ignored to allow visual @@ -41,14 +41,14 @@ enum getl_syntax GETL_INTERACTIVE }; -/* An abstract base class for objects which act as line buffers for the +/* An abstract base class for objects which act as line buffers for the PSPP. Ie anything which might contain content for the lexer */ -struct getl_interface +struct getl_interface { /* Returns true if the interface is interactive, that is, if it prompts a human user. This property is independent of the syntax mode returned by the read member function. */ - bool (*interactive) (const struct getl_interface *); + bool (*interactive) (const struct getl_interface *); /* Read a line the intended syntax mode from the interface. Returns true if succesful, false on failure or at end of @@ -71,24 +71,25 @@ struct getl_interface int (*location) (const struct getl_interface *); }; -void getl_initialize (void); -void getl_uninitialize (void); +struct source_stream; -void getl_clear_include_path (void); -void getl_add_include_dir (const char *); -const char * getl_include_path (void); +struct source_stream * create_source_stream (void); +void destroy_source_stream (struct source_stream *); -void getl_abort_noninteractive (void); -bool getl_is_interactive (void); +void getl_clear_include_path (struct source_stream *); +void getl_add_include_dir (struct source_stream *, const char *); +const char * getl_include_path (const struct source_stream *); -bool getl_read_line (bool *interactive); +void getl_abort_noninteractive (struct source_stream *); +bool getl_is_interactive (const struct source_stream *); -bool do_read_line (struct string *line, enum getl_syntax *syntax); +bool getl_read_line (struct source_stream *, struct string *, + enum getl_syntax *); -void getl_append_source (struct getl_interface *s) ; -void getl_include_source (struct getl_interface *s) ; +void getl_append_source (struct source_stream *, struct getl_interface *s) ; +void getl_include_source (struct source_stream *, struct getl_interface *s) ; -const char * getl_source_name (void); -int getl_source_location (void); +const char * getl_source_name (const struct source_stream *); +int getl_source_location (const struct source_stream *); #endif /* line-buffer.h */ diff --git a/src/libpspp/message.c b/src/libpspp/message.c index 24bb8e87..31a78d25 100644 --- a/src/libpspp/message.c +++ b/src/libpspp/message.c @@ -63,9 +63,12 @@ msg (enum msg_class class, const char *format, ...) msg_emit (&m); } +static struct source_stream *s_stream; + void -msg_init ( void (*handler) (const struct msg *) ) +msg_init (struct source_stream *ss, void (*handler) (const struct msg *) ) { + s_stream = ss; msg_handler = handler; } @@ -99,7 +102,7 @@ msg_destroy(struct msg *m) void msg_emit (struct msg *m) { - get_msg_location (&m->where); + get_msg_location (s_stream, &m->where); if (!messages_disabled) msg_handler (m); free (m->text); diff --git a/src/libpspp/message.h b/src/libpspp/message.h index ffafd999..ba35b351 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -85,8 +85,10 @@ struct msg char *text; /* Error text. */ }; +struct source_stream ; + /* Initialization. */ -void msg_init ( void (*handler) (const struct msg *) ); +void msg_init (struct source_stream *, void (*handler) (const struct msg *) ); void msg_done (void); diff --git a/src/libpspp/msg-locator.c b/src/libpspp/msg-locator.c index 5f7e5dd0..2bd7877c 100644 --- a/src/libpspp/msg-locator.c +++ b/src/libpspp/msg-locator.c @@ -71,7 +71,7 @@ msg_pop_msg_locator (const struct msg_locator *loc) /* Puts the current file and line number into LOC, or NULL and -1 if none. */ void -get_msg_location (struct msg_locator *loc) +get_msg_location (const struct source_stream *ss, struct msg_locator *loc) { if (nfile_loc) { @@ -79,7 +79,7 @@ get_msg_location (struct msg_locator *loc) } else { - loc->file_name = getl_source_name (); - loc->line_number = getl_source_location (); + loc->file_name = getl_source_name (ss); + loc->line_number = getl_source_location (ss); } } diff --git a/src/libpspp/msg-locator.h b/src/libpspp/msg-locator.h index b39ea6d2..63c2264b 100644 --- a/src/libpspp/msg-locator.h +++ b/src/libpspp/msg-locator.h @@ -31,6 +31,7 @@ void msg_push_msg_locator (const struct msg_locator *loc); item on top of the stack. */ void msg_pop_msg_locator (const struct msg_locator *loc); +struct source_stream ; /* Puts the current file and line number into LOC, or NULL and -1 if none. */ -void get_msg_location (struct msg_locator *loc); +void get_msg_location (const struct source_stream *ss, struct msg_locator *loc); diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index 77876b0f..6e5664f5 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -51,10 +51,10 @@ static GQueue *message_queue; void -message_dialog_init (void) +message_dialog_init (struct source_stream *ss) { message_queue = g_queue_new(); - msg_init (enqueue_msg); + msg_init (ss, enqueue_msg); } void diff --git a/src/ui/gui/message-dialog.h b/src/ui/gui/message-dialog.h index 74882b54..0b6c4bc6 100644 --- a/src/ui/gui/message-dialog.h +++ b/src/ui/gui/message-dialog.h @@ -24,7 +24,9 @@ #include -void message_dialog_init (void); +struct source_stream ; + +void message_dialog_init (struct source_stream *); void message_dialog_done (void); void popup_message(const struct msg *m); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index 6dd41b34..e8142199 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -77,6 +77,8 @@ PsppireVarStore *var_store = 0; void create_icon_factory (void); +static struct source_stream *the_source_stream ; + int main(int argc, char *argv[]) { @@ -116,8 +118,8 @@ main(int argc, char *argv[]) fmt_init(); settings_init(); - getl_initialize (); - message_dialog_init(); + the_source_stream = create_source_stream (); + message_dialog_init (the_source_stream); the_dictionary = psppire_dict_new(); @@ -168,7 +170,7 @@ main(int argc, char *argv[]) /* start the event loop */ gtk_main(); - getl_uninitialize (); + destroy_source_stream (the_source_stream); message_dialog_done(); settings_done(); diff --git a/src/ui/terminal/command-line.c b/src/ui/terminal/command-line.c index f7090a3e..ec7a9b22 100644 --- a/src/ui/terminal/command-line.c +++ b/src/ui/terminal/command-line.c @@ -50,11 +50,12 @@ static void usage (void); char *subst_vars (char *); + /* Parses the command line specified by ARGC and ARGV as received by main(). Returns true if normal execution should proceed, false if the command-line indicates that PSPP should exit. */ bool -parse_command_line (int argc, char **argv) +parse_command_line (int argc, char **argv, struct source_stream *ss) { static struct option long_options[] = { @@ -140,9 +141,9 @@ parse_command_line (int argc, char **argv) break; case 'I': if (optarg == NULL || !strcmp (optarg, "-")) - getl_clear_include_path (); + getl_clear_include_path (ss); else - getl_add_include_dir (optarg); + getl_add_include_dir (ss, optarg); break; case 'l': outp_list_classes (); @@ -195,7 +196,7 @@ parse_command_line (int argc, char **argv) char *pspprc_fn = fn_search_path ("rc", config_path, NULL); if (pspprc_fn != NULL) { - getl_append_source (create_syntax_file_source (pspprc_fn)); + getl_append_source (ss, create_syntax_file_source (pspprc_fn)); free (pspprc_fn); } @@ -206,12 +207,12 @@ parse_command_line (int argc, char **argv) outp_configure_macro (argv[i]); else { - getl_append_source (create_syntax_file_source (argv[i])); + getl_append_source (ss, create_syntax_file_source (argv[i])); syntax_files++; } if (!syntax_files || interactive_mode) - getl_append_source (create_readln_source () ); + getl_append_source (ss, create_readln_source () ); return true; } diff --git a/src/ui/terminal/command-line.h b/src/ui/terminal/command-line.h index c103b696..b6058d1c 100644 --- a/src/ui/terminal/command-line.h +++ b/src/ui/terminal/command-line.h @@ -22,6 +22,8 @@ #include -bool parse_command_line (int argc, char **argv); +struct source_stream ; + +bool parse_command_line (int argc, char **argv, struct source_stream *); #endif /* cmdline.h */ diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index 5b4ad2d3..f1dd21d3 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -76,6 +76,8 @@ void interrupt_handler(int sig); static struct dataset * the_dataset = NULL; static struct lexer *the_lexer; +static struct source_stream *the_source_stream ; + /* Program entry point. */ int @@ -95,18 +97,18 @@ main (int argc, char **argv) outp_init (); fn_init (); fh_init (); - getl_initialize (); + the_source_stream = create_source_stream (); prompt_init (); readln_initialize (); settings_init (); random_init (); the_dataset = create_dataset (); - if (parse_command_line (argc, argv)) + if (parse_command_line (argc, argv, the_source_stream)) { - msg_ui_init (); + msg_ui_init (the_source_stream); outp_read_devices (); - the_lexer = lex_create (do_read_line); + the_lexer = lex_create (the_source_stream); for (;;) { @@ -115,14 +117,15 @@ main (int argc, char **argv) ? CMD_STATE_DATA : CMD_STATE_INITIAL); if (result == CMD_EOF || result == CMD_FINISH) break; - if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ()) + if (result == CMD_CASCADING_FAILURE && + !getl_is_interactive (the_source_stream)) { msg (SE, _("Stopping syntax file processing here to avoid " "a cascade of dependent command failures.")); - getl_abort_noninteractive (); + getl_abort_noninteractive (the_source_stream); } else - check_msg_count (); + check_msg_count (the_source_stream); } } @@ -196,7 +199,7 @@ terminate (bool success) settings_done (); fh_done (); lex_destroy (the_lexer); - getl_uninitialize (); + destroy_source_stream (the_source_stream); prompt_done (); readln_uninitialize (); diff --git a/src/ui/terminal/msg-ui.c b/src/ui/terminal/msg-ui.c index 7cb652c0..6a67a6f1 100644 --- a/src/ui/terminal/msg-ui.c +++ b/src/ui/terminal/msg-ui.c @@ -53,7 +53,7 @@ msg_ui_set_error_file (const char *filename) } void -msg_ui_init (void) +msg_ui_init (struct source_stream *ss) { msg_file = stdout; @@ -69,7 +69,7 @@ msg_ui_init (void) msg_file = stdout; } } - msg_init (handle_msg); + msg_init (ss, handle_msg); } void @@ -81,13 +81,12 @@ msg_ui_done (void) fclose (msg_file); } - /* Checks whether we've had so many errors that it's time to quit processing this syntax file. */ void -check_msg_count (void) +check_msg_count (struct source_stream *ss) { - if (!getl_is_interactive ()) + if (!getl_is_interactive (ss)) { if (get_errorbreak () && error_count) msg (MN, _("Terminating execution of syntax file due to error.")); @@ -100,7 +99,7 @@ check_msg_count (void) else return; - getl_abort_noninteractive (); + getl_abort_noninteractive (ss); } } diff --git a/src/ui/terminal/msg-ui.h b/src/ui/terminal/msg-ui.h index 4eeec278..165bffed 100644 --- a/src/ui/terminal/msg-ui.h +++ b/src/ui/terminal/msg-ui.h @@ -22,10 +22,12 @@ #include +struct source_stream ; + void msg_ui_set_error_file (const char *filename); -void msg_ui_init (void); +void msg_ui_init (struct source_stream *); void msg_ui_done (void); -void check_msg_count (void); +void check_msg_count (struct source_stream *); void reset_msg_count (void); bool any_errors (void);