projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
data_out function to dynamically allocate return value.
[pspp-builds.git]
/
src
/
language
/
data-io
/
list.q
diff --git
a/src/language/data-io/list.q
b/src/language/data-io/list.q
index 135dcc4c954ceec0a762f8c5b0e995d0916744b8..b5a16f265481e8d4d5bc0c957a3412235da3e039 100644
(file)
--- a/
src/language/data-io/list.q
+++ b/
src/language/data-io/list.q
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ 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
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
@@
-16,22
+16,24
@@
#include <config.h>
#include <config.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "intprops.h"
#include <stdio.h>
#include <stdlib.h>
#include "intprops.h"
-#include "size_max.h"
+#include "xmalloca.h"
+
#include <data/casegrouper.h>
#include <data/casereader.h>
#include <data/dictionary.h>
#include <data/data-out.h>
#include <data/format.h>
#include <data/procedure.h>
#include <data/casegrouper.h>
#include <data/casereader.h>
#include <data/dictionary.h>
#include <data/data-out.h>
#include <data/format.h>
#include <data/procedure.h>
+#include <data/short-names.h>
#include <data/variable.h>
#include <language/command.h>
#include <language/dictionary/split-file.h>
#include <language/lexer/lexer.h>
#include <data/variable.h>
#include <language/command.h>
#include <language/dictionary/split-file.h>
#include <language/lexer/lexer.h>
-#include <libpspp/alloc.h>
#include <libpspp/compiler.h>
#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/compiler.h>
#include <libpspp/message.h>
#include <libpspp/message.h>
@@
-42,6
+44,7
@@
#include <output/table.h>
#include "minmax.h"
#include <output/table.h>
#include "minmax.h"
+#include "xalloc.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-80,7
+83,7
@@
static unsigned n_chars_width (struct outp_driver *d);
static void write_line (struct outp_driver *d, const char *s);
/* Other functions. */
static void write_line (struct outp_driver *d, const char *s);
/* Other functions. */
-static void list_case (struct ccase *, casenumber case_idx,
+static void list_case (
const
struct ccase *, casenumber case_idx,
const struct dataset *);
static void determine_layout (void);
static void clean_up (void);
const struct dataset *);
static void determine_layout (void);
static void clean_up (void);
@@
-148,7
+151,7
@@
cmd_list (struct lexer *lexer, struct dataset *ds)
cmd.last = LONG_MAX;
if (!cmd.sbc_variables)
dict_get_vars (dict, &cmd.v_variables, &cmd.n_variables,
cmd.last = LONG_MAX;
if (!cmd.sbc_variables)
dict_get_vars (dict, &cmd.v_variables, &cmd.n_variables,
-
(1u << DC_SYSTEM) | (1u << DC_SCRATCH)
);
+
DC_SYSTEM | DC_SCRATCH
);
if (cmd.n_variables == 0)
{
msg (SE, _("No variables specified."));
if (cmd.n_variables == 0)
{
msg (SE, _("No variables specified."));
@@
-233,15
+236,15
@@
cmd_list (struct lexer *lexer, struct dataset *ds)
casegrouper_get_next_group (grouper, &group);
casereader_destroy (group))
{
casegrouper_get_next_group (grouper, &group);
casereader_destroy (group))
{
- struct ccase c;
+ struct ccase
*
c;
write_all_headers (group, ds);
write_all_headers (group, ds);
- for (;
casereader_read (group, &c); case_destroy (&
c))
+ for (;
(c = casereader_read (group)) != NULL; case_unref (
c))
{
case_idx++;
if (case_idx >= cmd.first && case_idx <= cmd.last
&& (case_idx - cmd.first) % cmd.step == 0)
{
case_idx++;
if (case_idx >= cmd.first && case_idx <= cmd.last
&& (case_idx - cmd.first) % cmd.step == 0)
- list_case (
&
c, case_idx, ds);
+ list_case (c, case_idx, ds);
}
}
ok = casegrouper_destroy (grouper);
}
}
ok = casegrouper_destroy (grouper);
@@
-262,12
+265,13
@@
static void
write_all_headers (struct casereader *input, const struct dataset *ds)
{
struct outp_driver *d;
write_all_headers (struct casereader *input, const struct dataset *ds)
{
struct outp_driver *d;
- struct ccase c;
+ struct ccase
*
c;
- if (!casereader_peek (input, 0, &c))
+ c = casereader_peek (input, 0);
+ if (c == NULL)
return;
return;
- output_split_file_values (ds,
&
c);
- case_
destroy (&
c);
+ output_split_file_values (ds, c);
+ case_
unref (
c);
for (d = outp_drivers (NULL); d; d = outp_drivers (d))
{
for (d = outp_drivers (NULL); d; d = outp_drivers (d))
{
@@
-462,8
+466,8
@@
write_fallback_headers (struct outp_driver *d)
int line_number = 0;
const char *Line = _("Line");
int line_number = 0;
const char *Line = _("Line");
- char *leader =
local_alloc
(strlen (Line)
-
+ INT_STRLEN_BOUND (line_number) + 1 + 1);
+ char *leader =
xmalloca
(strlen (Line)
+ + INT_STRLEN_BOUND (line_number) + 1 + 1);
while (index < cmd.n_variables)
{
while (index < cmd.n_variables)
{
@@
-505,7
+509,7
@@
write_fallback_headers (struct outp_driver *d)
}
{
}
{
- char varname[
LONG
_NAME_LEN + 2];
+ char varname[
VAR
_NAME_LEN + 2];
snprintf (varname, sizeof varname,
" %s", var_get_name (cmd.v_variables[index]));
write_varname (d, varname, leader_width);
snprintf (varname, sizeof varname,
" %s", var_get_name (cmd.v_variables[index]));
write_varname (d, varname, leader_width);
@@
-517,7
+521,7
@@
write_fallback_headers (struct outp_driver *d)
d->cp_x = 0;
d->cp_y += d->font_height;
d->cp_x = 0;
d->cp_y += d->font_height;
-
local_free
(leader);
+
freea
(leader);
}
/* There are three possible layouts for the LIST procedure:
}
/* There are three possible layouts for the LIST procedure:
@@
-646,7
+650,8
@@
determine_layout (void)
/* Writes case C to output. */
static void
/* Writes case C to output. */
static void
-list_case (struct ccase *c, casenumber case_idx, const struct dataset *ds)
+list_case (const struct ccase *c, casenumber case_idx,
+ const struct dataset *ds)
{
struct dictionary *dict = dataset_dict (ds);
struct outp_driver *d;
{
struct dictionary *dict = dataset_dict (ds);
struct outp_driver *d;
@@
-701,18
+706,21
@@
list_case (struct ccase *c, casenumber case_idx, const struct dataset *ds)
if (fmt_is_string (print->type)
|| dict_contains_var (dict, v))
{
if (fmt_is_string (print->type)
|| dict_contains_var (dict, v))
{
- data_out (case_data (c, v), print,
- ds_put_uninit (&line_buffer, print->w));
+ char *s = data_out (case_data (c, v), print);
+ ds_put_cstr (&line_buffer, s);
+ free (s);
}
else
{
}
else
{
+ char *s;
union value case_idx_value;
case_idx_value.f = case_idx;
union value case_idx_value;
case_idx_value.f = case_idx;
- data_out (&case_idx_value, print,
- ds_put_uninit (&line_buffer,print->w));
+ s = data_out (&case_idx_value, print);
+ ds_put_cstr (&line_buffer, s);
+ free (s);
}
}
- ds_put_char(&line_buffer, ' ');
+ ds_put_char
(&line_buffer, ' ');
}
if (!n_lines_remaining (d))
}
if (!n_lines_remaining (d))
@@
-735,20
+743,21
@@
list_case (struct ccase *c, casenumber case_idx, const struct dataset *ds)
{
const struct variable *v = cmd.v_variables[column];
const struct fmt_spec *print = var_get_print_format (v);
{
const struct variable *v = cmd.v_variables[column];
const struct fmt_spec *print = var_get_print_format (v);
- char
buf[256]
;
+ char
*s = NULL
;
if (fmt_is_string (print->type)
|| dict_contains_var (dict, v))
if (fmt_is_string (print->type)
|| dict_contains_var (dict, v))
-
data_out (case_data (c, v), print, buf
);
+
s = data_out (case_data (c, v), print
);
else
{
union value case_idx_value;
case_idx_value.f = case_idx;
else
{
union value case_idx_value;
case_idx_value.f = case_idx;
-
data_out (&case_idx_value, print, buf
);
+
s = data_out (&case_idx_value, print
);
}
fputs (" <TD>", x->file);
}
fputs (" <TD>", x->file);
- html_put_cell_contents (d, TAB_FIX, ss_buffer (buf, print->w));
+ html_put_cell_contents (d, TAB_FIX, ss_buffer (s, print->w));
+ free (s);
fputs ("</TD>\n", x->file);
}
fputs ("</TD>\n", x->file);
}