-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012 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.
- 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 <http://www.gnu.org/licenses/>. */
-#include <data/case.h>
-#include <data/format.h>
-#include <data/procedure.h>
-#include <data/transformations.h>
-#include <data/variable.h>
-#include <language/command.h>
-#include <language/data-io/data-writer.h>
-#include <language/data-io/file-handle.h>
-#include <language/data-io/placement-parser.h>
-#include <language/lexer/format-parser.h>
-#include <language/lexer/lexer.h>
-#include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
-#include <libpspp/assertion.h>
-#include <libpspp/compiler.h>
-#include <libpspp/ll.h>
-#include <libpspp/message.h>
-#include <libpspp/misc.h>
-#include <libpspp/pool.h>
-#include <output/manager.h>
-#include <output/table.h>
+#include "data/case.h"
+#include "data/dataset.h"
+#include "data/data-out.h"
+#include "data/format.h"
+#include "data/transformations.h"
+#include "data/variable.h"
+#include "language/command.h"
+#include "language/data-io/data-writer.h"
+#include "language/data-io/file-handle.h"
+#include "language/data-io/placement-parser.h"
+#include "language/lexer/format-parser.h"
+#include "language/lexer/lexer.h"
+#include "language/lexer/variable-parser.h"
+#include "libpspp/assertion.h"
+#include "libpspp/compiler.h"
+#include "libpspp/i18n.h"
+#include "libpspp/ll.h"
+#include "libpspp/message.h"
+#include "libpspp/misc.h"
+#include "libpspp/pool.h"
+#include "output/tab.h"
+#include "output/text-item.h"
+
+#include "gl/xalloc.h"
struct fmt_spec format; /* Output spec. */
bool add_space; /* Add trailing space? */
bool sysmis_as_spaces; /* Output SYSMIS as spaces? */
struct fmt_spec format; /* Output spec. */
bool add_space; /* Add trailing space? */
bool sysmis_as_spaces; /* Output SYSMIS as spaces? */
struct pool *pool; /* Stores related data. */
bool eject; /* Eject page before printing? */
bool include_prefix; /* Prefix lines with space? */
struct pool *pool; /* Stores related data. */
bool eject; /* Eject page before printing? */
bool include_prefix; /* Prefix lines with space? */
struct dfm_writer *writer; /* Output file, NULL=listing file. */
struct ll_list specs; /* List of struct prt_out_specs. */
size_t record_cnt; /* Number of records to write. */
struct dfm_writer *writer; /* Output file, NULL=listing file. */
struct ll_list specs; /* List of struct prt_out_specs. */
size_t record_cnt; /* Number of records to write. */
enum which_formats, bool eject);
static trns_proc_func print_trns_proc;
static trns_free_func print_trns_free;
enum which_formats, bool eject);
static trns_proc_func print_trns_proc;
static trns_free_func print_trns_free;
-static bool parse_specs (struct pool *tmp_pool, struct print_trns *,
+static bool parse_specs (struct lexer *, struct pool *tmp_pool, struct print_trns *,
struct dictionary *dict, enum which_formats);
static void dump_table (struct print_trns *, const struct file_handle *);
\f
struct dictionary *dict, enum which_formats);
static void dump_table (struct print_trns *, const struct file_handle *);
\f
- return internal_cmd_print (ds, PRINT, false);
+ return internal_cmd_print (lexer, ds, PRINT, false);
- return internal_cmd_print (ds, WRITE, false);
+ return internal_cmd_print (lexer, ds, WRITE, false);
enum which_formats which_formats, bool eject)
{
bool print_table = 0;
struct print_trns *trns;
struct file_handle *fh = NULL;
enum which_formats which_formats, bool eject)
{
bool print_table = 0;
struct print_trns *trns;
struct file_handle *fh = NULL;
- trns->record_cnt = lex_integer ();
- lex_get ();
- lex_match (')');
+
+ free (encoding);
+ encoding = ss_xstrdup (lex_tokss (lexer));
+
+ lex_get (lexer);
+ }
+ else if (lex_match_id (lexer, "RECORDS"))
+ {
+ lex_match (lexer, T_EQUALS);
+ lex_match (lexer, T_LPAREN);
+ if (!lex_force_int (lexer))
+ goto error;
+ trns->record_cnt = lex_integer (lexer);
+ lex_get (lexer);
+ lex_match (lexer, T_RPAREN);
- if (!parse_specs (tmp_pool, trns, dataset_dict (ds), which_formats))
+ if (!parse_specs (lexer, tmp_pool, trns, dataset_dict (ds), which_formats))
add_transformation (ds, print_trns_proc, print_trns_free, trns);
pool_destroy (tmp_pool);
add_transformation (ds, print_trns_proc, print_trns_free, trns);
pool_destroy (tmp_pool);
-parse_specs (struct pool *tmp_pool, struct print_trns *trns,
- struct dictionary *dict,
+parse_specs (struct lexer *lexer, struct pool *tmp_pool, struct print_trns *trns,
+ struct dictionary *dict,
- if (token == T_STRING)
- ok = parse_string_argument (trns, record, &column);
+ if (lex_is_string (lexer))
+ ok = parse_string_argument (lexer, trns, record, &column);
- ok = parse_variable_argument (dict, trns, tmp_pool, &record, &column,
+ ok = parse_variable_argument (lexer, dict, trns, tmp_pool, &record, &column,
"subcommand."),
record, trns->record_cnt);
trns->record_cnt = record;
"subcommand."),
record, trns->record_cnt);
trns->record_cnt = record;
-parse_string_argument (struct print_trns *trns, int record, int *column)
+parse_string_argument (struct lexer *lexer, struct print_trns *trns, int record, int *column)
{
struct prt_out_spec *spec = pool_alloc (trns->pool, sizeof *spec);
spec->type = PRT_LITERAL;
spec->record = record;
spec->first_column = *column;
{
struct prt_out_spec *spec = pool_alloc (trns->pool, sizeof *spec);
spec->type = PRT_LITERAL;
spec->record = record;
spec->first_column = *column;
- if (!parse_column_range (&first_column, &last_column, &range_specified))
- return false;
+ if (!parse_column_range (lexer, 1,
+ &first_column, &last_column, &range_specified))
+ return false;
struct print_trns *trns, struct pool *tmp_pool,
int *record, int *column,
enum which_formats which_formats)
{
struct print_trns *trns, struct pool *tmp_pool,
int *record, int *column,
enum which_formats which_formats)
{
-
- if (!parse_variables_pool (tmp_pool, dict, &vars, &var_cnt, PV_DUPLICATE))
+
+ if (!parse_variables_const_pool (lexer, tmp_pool, dict,
+ &vars, &var_cnt, PV_DUPLICATE))
- if (!parse_var_placements (tmp_pool, var_cnt, false,
+ if (!parse_var_placements (lexer, tmp_pool, var_cnt, FMT_FOR_OUTPUT,
- struct variable *v = vars[i];
- formats[i] = which_formats == PRINT ? v->print : v->write;
+ const struct variable *v = vars[i];
+ formats[i] = (which_formats == PRINT
+ ? *var_get_print_format (v)
+ : *var_get_write_format (v));
for (f = formats; f < &formats[format_cnt]; f++)
if (!execute_placement_format (f, record, column))
{
for (f = formats; f < &formats[format_cnt]; f++)
if (!execute_placement_format (f, record, column))
{
/* This is a completely bizarre twist for compatibility:
WRITE outputs the system-missing value as a field
filled with spaces, instead of using the normal format
/* This is a completely bizarre twist for compatibility:
WRITE outputs the system-missing value as a field
filled with spaces, instead of using the normal format
- t = tab_create (4, spec_cnt + 1, 0);
- tab_columns (t, TAB_COL_DOWN, 1);
+ t = tab_create (4, spec_cnt + 1);
tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 3, spec_cnt);
tab_hline (t, TAL_2, 0, 3, 1);
tab_headers (t, 0, 0, 1, 0);
tab_box (t, TAL_1, TAL_1, TAL_0, TAL_1, 0, 0, 3, spec_cnt);
tab_hline (t, TAL_2, 0, 3, 1);
tab_headers (t, 0, 0, 1, 0);
tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Record"));
tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Columns"));
tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Format"));
tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Record"));
tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Columns"));
tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Format"));
- ll_for_each (spec, struct prt_out_spec, ll, &trns->specs)
+ ll_for_each (spec, struct prt_out_spec, ll, &trns->specs)
- tab_text (t, 0, row, TAB_LEFT | TAB_FIX | TAT_PRINTF, "\"%.*s\"",
- (int) ds_length (&spec->string), ds_data (&spec->string));
+ tab_text_format (t, 0, row, TAB_LEFT | TAB_FIX, "`%.*s'",
+ (int) ds_length (&spec->string),
+ ds_data (&spec->string));
- tab_text (t, 0, row, TAB_LEFT, spec->var->name);
+ tab_text (t, 0, row, TAB_LEFT, var_get_name (spec->var));
tab_text (t, 3, row, TAB_LEFT | TAB_FIX,
fmt_to_string (&spec->format, fmt_string));
width = spec->format.w;
tab_text (t, 3, row, TAB_LEFT | TAB_FIX,
fmt_to_string (&spec->format, fmt_string));
width = spec->format.w;
- tab_text (t, 1, row, TAT_PRINTF, "%d", spec->record);
- tab_text (t, 2, row, TAT_PRINTF, "%3d-%3d",
- spec->first_column, spec->first_column + width - 1);
+ tab_text_format (t, 1, row, 0, "%d", spec->record);
+ tab_text_format (t, 2, row, 0, "%3d-%3d",
+ spec->first_column, spec->first_column + width - 1);
- tab_title (t, ngettext ("Writing %d record to %s.",
- "Writing %d records to %s.", trns->record_cnt),
+ tab_title (t, ngettext ("Writing %zu record to %s.",
+ "Writing %zu records to %s.", trns->record_cnt),
- tab_title (t, ngettext ("Writing %d record.",
- "Writing %d records.", trns->record_cnt),
+ tab_title (t, ngettext ("Writing %zu record.",
+ "Writing %zu records.", trns->record_cnt),
- ds_put_char (&trns->line, ' ');
- ll_for_each (spec, struct prt_out_spec, ll, &trns->specs)
+ ds_put_byte (&trns->line, ' ');
+ ll_for_each (spec, struct prt_out_spec, ll, &trns->specs)
{
flush_records (trns, spec->record, &eject, &record);
{
flush_records (trns, spec->record, &eject, &record);
- const union value *input = case_data (c, spec->var->fv);
- char *output = ds_put_uninit (&trns->line, spec->format.w);
+ const union value *input = case_data (*c, spec->var);
- data_out (output, &spec->format, input);
+ data_out_recode (input, var_get_encoding (spec->var),
+ &spec->format, &trns->line, trns->encoding);
- ds_put_char (&trns->line, ' ');
+ ds_put_byte (&trns->line, encoded_space);
+ }
+ else
+ {
+ ds_put_substring (&trns->line, ds_ss (&spec->string));
+ if (0 != strcmp (trns->encoding, C_ENCODING))
+ {
+ size_t length = ds_length (&spec->string);
+ char *data = ss_data (ds_tail (&trns->line, length));
+ char *s = recode_string (trns->encoding, C_ENCODING, data, length);
+ memcpy (data, s, length);
+ free (s);
+ }
}
flush_records (trns, trns->record_cnt + 1, &eject, &record);
}
flush_records (trns, trns->record_cnt + 1, &eject, &record);
flush_records (struct print_trns *trns, int target_record,
bool *eject, int *record)
{
flush_records (struct print_trns *trns, int target_record,
bool *eject, int *record)
{