1 /* PSPP - computes sample statistics.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <data/procedure.h>
26 #include <language/command.h>
27 #include <language/data-io/data-writer.h>
28 #include <language/data-io/file-handle.h>
29 #include <language/expressions/public.h>
30 #include <language/lexer/lexer.h>
31 #include <output/manager.h>
32 #include <libpspp/message.h>
37 #define _(msgid) gettext (msgid)
39 /* PRINT SPACE transformation. */
40 struct print_space_trns
42 struct dfm_writer *writer; /* Output data file. */
43 struct expression *expr; /* Number of lines; NULL means 1. */
46 static trns_proc_func print_space_trns_proc;
47 static trns_free_func print_space_trns_free;
50 cmd_print_space (struct dataset *ds)
52 struct print_space_trns *trns;
53 struct file_handle *handle;
54 struct expression *expr;
55 struct dfm_writer *writer;
57 if (lex_match_id ("OUTFILE"))
61 handle = fh_parse (FH_REF_FILE);
71 expr = expr_parse (ds, EXPR_NUMBER);
75 lex_error (_("expecting end of command"));
84 writer = dfm_open_writer (handle);
94 trns = xmalloc (sizeof *trns);
95 trns->writer = writer;
98 add_transformation (ds,
99 print_space_trns_proc, print_space_trns_free, trns);
103 /* Executes a PRINT SPACE transformation. */
105 print_space_trns_proc (void *t_, struct ccase *c,
106 casenumber case_num UNUSED)
108 struct print_space_trns *trns = t_;
114 double f = expr_evaluate_num (trns->expr, c, case_num);
116 msg (SW, _("The expression on PRINT SPACE evaluated to the "
117 "system-missing value."));
118 else if (f < 0 || f > INT_MAX)
119 msg (SW, _("The expression on PRINT SPACE evaluated to %g."), f);
125 if (trns->writer == NULL)
128 dfm_put_record (trns->writer, " ", 1);
130 if (trns->writer != NULL && dfm_write_error (trns->writer))
132 return TRNS_CONTINUE;
135 /* Frees a PRINT SPACE transformation.
136 Returns true if successful, false if an I/O error occurred. */
138 print_space_trns_free (void *trns_)
140 struct print_space_trns *trns = trns_;
141 bool ok = dfm_close_writer (trns->writer);
142 expr_free (trns->expr);