X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fcontrol%2Frepeat.c;h=cd88a1e141884121f691b812a496a19fb77f698f;hb=173d1687aea88e0e5e1b1d8615ed68ebefb15d08;hp=bc8d5196c59a0edfb3db68ddac81cb392b517b85;hpb=d13a6e0157824a5dc125080295e86b5215d3a29d;p=pspp diff --git a/src/language/control/repeat.c b/src/language/control/repeat.c index bc8d5196c5..cd88a1e141 100644 --- a/src/language/control/repeat.c +++ b/src/language/control/repeat.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2007, 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. */ + along with this program. If not, see . */ #include @@ -31,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,6 +38,7 @@ #include #include "intprops.h" +#include "xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -51,7 +50,6 @@ struct repeat_line const char *file_name; /* File name. */ int line_number; /* Line number. */ struct substring text; /* Contents. */ - enum getl_syntax syntax; /* Syntax mode. */ }; /* The type of substitution made for a DO REPEAT macro. */ @@ -105,9 +103,9 @@ static int parse_strings (struct lexer *, struct repeat_macro *, struct pool *); static void do_repeat_filter (struct getl_interface *, - struct string *, enum getl_syntax); + struct string *); static bool do_repeat_read (struct getl_interface *, - struct string *, enum getl_syntax *); + struct string *); static void do_repeat_close (struct getl_interface *); static bool always_false (const struct getl_interface *); static const char *do_repeat_name (const struct getl_interface *); @@ -138,7 +136,11 @@ cmd_do_repeat (struct lexer *lexer, struct dataset *ds) block->parent.location = do_repeat_location; if (!ll_is_empty (&block->lines)) - getl_include_source (lex_get_source_stream (lexer), &block->parent); + getl_include_source (lex_get_source_stream (lexer), + &block->parent, + lex_current_syntax_mode (lexer), + lex_current_error_mode (lexer) + ); else pool_destroy (block->pool); @@ -167,12 +169,12 @@ parse_specification (struct lexer *lexer, struct repeat_block *block) if (!lex_force_id (lexer)) return false; if (dict_lookup_var (dict, lex_tokid (lexer))) - msg (SW, _("Dummy variable name \"%s\" hides dictionary " - "variable \"%s\"."), + msg (SW, _("Dummy variable name `%s' hides dictionary " + "variable `%s'."), lex_tokid (lexer), lex_tokid (lexer)); if (find_macro (block, ss_cstr (lex_tokid (lexer)))) { - msg (SE, _("Dummy variable name \"%s\" is given twice."), + msg (SE, _("Dummy variable name `%s' is given twice."), lex_tokid (lexer)); return false; } @@ -218,8 +220,8 @@ parse_specification (struct lexer *lexer, struct repeat_block *block) } else if (block->loop_cnt != count) { - msg (SE, _("Dummy variable \"%.*s\" had %d " - "substitutions, so \"%.*s\" must also, but %d " + msg (SE, _("Dummy variable `%.*s' had %d " + "substitutions, so `%.*s' must also, but %d " "were specified."), (int) ss_length (first_name), ss_data (first_name), block->loop_cnt, @@ -300,11 +302,10 @@ parse_lines (struct lexer *lexer, struct repeat_block *block) const char *cur_file_name; struct repeat_line *line; struct string text; - enum getl_syntax syntax; bool command_ends_before_line, command_ends_after_line; /* Retrieve an input line and make a copy of it. */ - if (!lex_get_line_raw (lexer, &syntax)) + if (!lex_get_line_raw (lexer)) return false; ds_init_string (&text, lex_entire_line_ds (lexer)); @@ -320,16 +321,17 @@ parse_lines (struct lexer *lexer, struct repeat_block *block) line->file_name = previous_file_name; 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; + /* Check whether the line contains a DO REPEAT or END REPEAT command. */ - lex_preprocess_line (&text, syntax, + lex_preprocess_line (&text, + lex_current_syntax_mode (lexer), &command_ends_before_line, &command_ends_after_line); if (recognize_do_repeat (ds_ss (&text))) { - if (get_syntax () == COMPATIBLE) + if (settings_get_syntax () == COMPATIBLE) msg (SE, _("DO REPEAT may not nest in compatibility mode.")); else nesting_level++; @@ -511,10 +513,10 @@ find_substitution (struct repeat_block *block, struct substring name) /* Makes appropriate DO REPEAT macro substitutions within the repeated lines. */ static void -do_repeat_filter (struct getl_interface *block_, - struct string *line, enum getl_syntax syntax UNUSED) +do_repeat_filter (struct getl_interface *interface, struct string *line) { - struct repeat_block *block = (struct repeat_block *) block_; + struct repeat_block *block + = UP_CAST (interface, struct repeat_block, parent); bool in_apos, in_quote, dot; struct substring input; struct string output; @@ -524,8 +526,7 @@ do_repeat_filter (struct getl_interface *block_, /* Strip trailing whitespace, check for & remove terminal dot. */ ds_rtrim (line, ss_cstr (CC_SPACES)); - dot = ds_chomp (line, get_endcmd ()); - + dot = ds_chomp (line, settings_get_endcmd ()); input = ds_ss (line); in_apos = in_quote = false; while ((c = ss_first (input)) != EOF) @@ -548,7 +549,7 @@ do_repeat_filter (struct getl_interface *block_, } } if (dot) - ds_put_char (&output, get_endcmd ()); + ds_put_char (&output, settings_get_endcmd ()); ds_swap (line, &output); ds_destroy (&output); @@ -557,7 +558,8 @@ do_repeat_filter (struct getl_interface *block_, static struct repeat_line * current_line (const struct getl_interface *interface) { - struct repeat_block *block = (struct repeat_block *) interface; + struct repeat_block *block + = UP_CAST (interface, struct repeat_block, parent); return (block->cur_line != ll_null (&block->lines) ? ll_data (block->cur_line, struct repeat_line, ll) : NULL); @@ -568,9 +570,10 @@ current_line (const struct getl_interface *interface) was obtained, false if the source is exhausted. */ static bool do_repeat_read (struct getl_interface *interface, - struct string *output, enum getl_syntax *syntax) + struct string *output) { - struct repeat_block *block = (struct repeat_block *) interface; + struct repeat_block *block + = UP_CAST (interface, struct repeat_block, parent); struct repeat_line *line; block->cur_line = ll_next (block->cur_line); @@ -585,16 +588,16 @@ do_repeat_read (struct getl_interface *interface, line = current_line (interface); ds_assign_substring (output, line->text); - *syntax = line->syntax; return true; } /* Frees a DO REPEAT block. Called by getl to close out the DO REPEAT block. */ static void -do_repeat_close (struct getl_interface *block_) +do_repeat_close (struct getl_interface *interface) { - struct repeat_block *block = (struct repeat_block *) block_; + struct repeat_block *block + = UP_CAST (interface, struct repeat_block, parent); pool_destroy (block->pool); }