+Sun Oct 23 19:28:08 2005 Ben Pfaff <blp@gnu.org>
+
+ Work to get rid of GCC 4.0 warnings, part 1.
+
+ In many files, change count parameters to parse_variables(),
+ etc. from `int' to `size_t'. Also change related variables and
+ struct members. Also change messages as needed (e.g. %d to %u
+ with cast to unsigned). Also change arithmetic as necessary
+ (e.g. n >= m - 1 to n + 1 >= m).
+
+ * crosstabs.q: (crs_custom_tables) Check for size_t overflow in
+ multiplication.
+
+ * q2c.c: (dump_declarations) Generate code for size_t instead of
+ int.
+
Thu Oct 20 18:18:40 2005 Ben Pfaff <blp@gnu.org>
* output.c: (outp_read_devices) Fix message.
struct agr_func
{
const char *name; /* Aggregation function name. */
- int n_args; /* Number of arguments. */
+ size_t n_args; /* Number of arguments. */
int alpha_type; /* When given ALPHA arguments, output type. */
struct fmt_spec format; /* Format spec if alpha_type != ALPHA. */
};
{
char **dest;
char **dest_label;
- int n_dest;
+ size_t n_dest;
int include_missing;
const struct agr_func *function;
union value arg[2];
struct variable **src;
- int n_src;
+ size_t n_src;
- int i;
+ size_t i;
dest = NULL;
dest_label = NULL;
/* Parse the list of target variables. */
while (!lex_match ('='))
{
- int n_dest_prev = n_dest;
+ size_t n_dest_prev = n_dest;
if (!parse_DATA_LIST_vars (&dest, &n_dest,
PV_APPEND | PV_SINGLE | PV_NO_SCRATCH))
like `unknown variable t'. */
if (n_src != n_dest)
{
- msg (SE, _("Number of source variables (%d) does not match "
- "number of target variables (%d)."),
- n_src, n_dest);
+ msg (SE, _("Number of source variables (%u) does not match "
+ "number of target variables (%u)."),
+ (unsigned) n_src, (unsigned) n_dest);
goto error;
}
if (iter->function & FSTRING)
{
- int n_args;
- int i;
+ size_t n_args;
+ size_t i;
n_args = agr_func_tab[iter->function & FUNC].n_args;
for (i = 0; i < n_args; i++)
struct trns_header h;
struct pool *owner; /* Contains AUTORECODE specs. */
struct arc_spec *specs; /* AUTORECODE specifications. */
- int spec_cnt; /* Number of specifications. */
+ size_t spec_cnt; /* Number of specifications. */
};
/* Descending or ascending sort order. */
char **dst_names; /* Target variable names. */
struct variable **dst_vars; /* Target variables. */
struct hsh_table **src_values; /* `union value's of source vars. */
- int var_cnt; /* Number of variables. */
+ size_t var_cnt; /* Number of variables. */
struct pool *src_values_pool; /* Pool used by src_values. */
enum direction direction; /* Sort order. */
int print; /* Print mapping table if nonzero. */
cmd_autorecode (void)
{
struct autorecode_pgm arc;
- int dst_cnt;
- int i;
+ size_t dst_cnt;
+ size_t i;
arc.src_vars = NULL;
arc.dst_names = NULL;
goto lossage;
if (dst_cnt != arc.var_cnt)
{
- int i;
+ size_t i;
- msg (SE, _("Source variable count (%d) does not match "
- "target variable count (%d)."), arc.var_cnt, dst_cnt);
+ msg (SE, _("Source variable count (%u) does not match "
+ "target variable count (%u)."),
+ (unsigned) arc.var_cnt, (unsigned) dst_cnt);
for (i = 0; i < dst_cnt; i++)
free (arc.dst_names[i]);
free (arc->src_vars);
if (arc->dst_names != NULL)
{
- int i;
+ size_t i;
for (i = 0; i < arc->var_cnt; i++)
free (arc->dst_names[i]);
free (arc->dst_vars);
if (arc->src_values != NULL)
{
- int i;
+ size_t i;
for (i = 0; i < arc->var_cnt; i++)
hsh_destroy (arc->src_values[i]);
{
struct autorecode_trns *t;
struct pool *pool;
- int i;
+ size_t i;
pool = pool_create ();
t = xmalloc (sizeof *t);
int case_idx UNUSED)
{
struct autorecode_trns *t = (struct autorecode_trns *) trns;
- int i;
+ size_t i;
for (i = 0; i < t->spec_cnt; i++)
{
autorecode_trns_free (struct trns_header * trns)
{
struct autorecode_trns *t = (struct autorecode_trns *) trns;
- int i;
+ size_t i;
for (i = 0; i < t->spec_cnt; i++)
hsh_destroy (t->specs[i].items);
autorecode_proc_func (struct ccase *c, void *arc_)
{
struct autorecode_pgm *arc = arc_;
- int i;
+ size_t i;
for (i = 0; i < arc->var_cnt; i++)
{
{
struct cor_set *next;
struct variable **v1, **v2;
- int nv1, nv2;
+ size_t nv1, nv2;
};
struct cor_set *cor_list, *cor_last;
cor_custom_variables (struct cmd_correlations *cmd UNUSED)
{
struct variable **v1, **v2;
- int nv1, nv2;
+ size_t nv1, nv2;
struct cor_set *cor;
/* Ensure that this is a VARIABLES subcommand. */
/* variables to count */
struct variable **v;
- int n;
+ size_t n;
/* values to count */
int missing; /* (numeric only)
static int
parse_numeric_criteria (struct counting * c)
{
- int n = 0;
- int m = 0;
+ size_t n = 0;
+ size_t m = 0;
c->crit.n = 0;
c->missing = 0;
for (;;)
{
struct cnt_num *cur;
- if (n >= m - 1)
+ if (n + 1 >= m)
{
m += 16;
c->crit.n = xrealloc (c->crit.n, m * sizeof (struct cnt_num));
{
int len = 0;
- int n = 0;
- int m = 0;
+ size_t n = 0;
+ size_t m = 0;
- int i;
+ size_t i;
for (i = 0; i < c->n; i++)
if (c->v[i]->width > len)
for (;;)
{
struct cnt_str *cur;
- if (n >= m - 1)
+ if (n + 1 >= m)
{
m += 16;
c->crit.n = xrealloc (c->crit.n, m * sizeof (struct cnt_str));
count_numeric (struct counting * cnt, struct ccase * c)
{
int counter = 0;
- int i;
+ size_t i;
for (i = 0; i < cnt->n; i++)
{
count_string (struct counting * cnt, struct ccase * c)
{
int counter = 0;
- int i;
+ size_t i;
for (i = 0; i < cnt->n; i++)
{
struct var_set *var_set;
int n_by;
struct variable ***by = NULL;
- int *by_nvar = NULL;
- int nx = 1;
+ size_t *by_nvar = NULL;
+ size_t nx = 1;
int success = 0;
/* Ensure that this is a TABLES subcommand. */
if (!parse_var_set_vars (var_set, &by[n_by], &by_nvar[n_by],
PV_NO_DUPLICATE | PV_NO_SCRATCH))
goto done;
+ if (xalloc_oversized (nx, by_nvar[n_by]))
+ {
+ msg (SE, _("Too many crosstabulation variables or dimensions."));
+ goto done;
+ }
nx *= by_nvar[n_by];
n_by++;
if (!lex_match (T_BY))
{
- if (n_by < 1)
+ if (n_by < 2)
{
lex_error (_("expecting BY"));
goto done;
int *by_iter = xcalloc (n_by, sizeof *by_iter);
int i;
- xtab = xrealloc (xtab, sizeof *xtab * (nxtab + nx));
+ xtab = xnrealloc (xtab, sizeof *xtab, nxtab + nx);
for (i = 0; i < nx; i++)
{
struct crosstab *x;
for (;;)
{
- int orig_nv = variables_cnt;
- int i;
+ size_t orig_nv = variables_cnt;
+ size_t i;
long min, max;
struct fixed_parsing_state
{
char **name; /* Variable names. */
- int name_cnt; /* Number of names. */
+ size_t name_cnt; /* Number of names. */
int recno; /* Index of current record. */
int sc; /* 1-based column number of starting column for
parse_fixed (struct data_list_pgm *dls)
{
struct fixed_parsing_state fx;
- int i;
+ size_t i;
fx.recno = 0;
fx.sc = 1;
{
struct fmt_spec input, output;
char **name;
- int name_cnt;
+ size_t name_cnt;
int width;
- int i;
+ size_t i;
if (!parse_DATA_LIST_vars (&name, &name_cnt, PV_NONE))
return 0;
parse_repeating_data (struct dls_var_spec **first, struct dls_var_spec **last)
{
struct fixed_parsing_state fx;
- int i;
+ size_t i;
fx.recno = 0;
fx.sc = 1;
/* Z-score functions. */
static int try_name (struct dsc_proc *dsc, char *name);
static int generate_z_varname (struct dsc_proc *dsc, char *z_name,
- const char *name, int *z_cnt);
+ const char *name, size_t *z_cnt);
static void dump_z_table (struct dsc_proc *);
static void setup_z_trns (struct dsc_proc *);
{
struct dsc_proc *dsc;
struct variable **vars = NULL;
- int var_cnt = 0;
+ size_t var_cnt = 0;
int save_z_scores = 0;
- int z_cnt = 0;
- int i;
+ size_t z_cnt = 0;
+ size_t i;
/* Create and initialize dsc. */
dsc = xmalloc (sizeof *dsc);
{
if (save_z_scores)
{
- int gen_cnt = 0;
+ size_t gen_cnt = 0;
for (i = 0; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] == 0)
static int
try_name (struct dsc_proc *dsc, char *name)
{
- int i;
+ size_t i;
if (dict_lookup_var (default_dict, name) != NULL)
return 0;
copies the new name into Z_NAME. On failure, returns zero. */
static int
generate_z_varname (struct dsc_proc *dsc, char *z_name,
- const char *var_name, int *z_cnt)
+ const char *var_name, size_t *z_cnt)
{
char name[LONG_NAME_LEN + 1];
static void
dump_z_table (struct dsc_proc *dsc)
{
- int cnt = 0;
+ size_t cnt = 0;
struct tab_table *t;
{
- int i;
+ size_t i;
for (i = 0; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] != '\0')
tab_dim (t, tab_natural_dimensions);
{
- int i, y;
+ size_t i, y;
for (i = 0, y = 1; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] != '\0')
setup_z_trns (struct dsc_proc *dsc)
{
struct dsc_trns *t;
- int cnt, i;
+ size_t cnt, i;
for (cnt = i = 0; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] != '\0')
struct dsc_proc *dsc = dsc_;
struct casereader *reader;
struct ccase c;
- int i;
+ size_t i;
for (i = 0; i < dsc->var_cnt; i++)
{
static int
listwise_missing (struct dsc_proc *dsc, const struct ccase *c)
{
- int i;
+ size_t i;
for (i = 0; i < dsc->var_cnt; i++)
{
static void
display (struct dsc_proc *dsc)
{
- int i, j;
+ size_t i;
int nc;
struct tab_table *t;
for (i = 0; i < dsc->var_cnt; i++)
{
struct dsc_var *dv = &dsc->vars[i];
+ size_t j;
nc = 0;
tab_text (t, nc++, i + 1, TAB_LEFT, dv->v->name);
exclude ordinary, system, and/or scratch variables. */
void
dict_get_vars (const struct dictionary *d, struct variable ***vars,
- int *cnt, unsigned exclude_classes)
+ size_t *cnt, unsigned exclude_classes)
{
size_t count;
size_t i;
size_t dict_get_var_cnt (const struct dictionary *);
struct variable *dict_get_var (const struct dictionary *, size_t idx);
void dict_get_vars (const struct dictionary *,
- struct variable ***vars, int *cnt,
+ struct variable ***vars, size_t *cnt,
unsigned exclude_classes);
struct variable *dict_create_var (struct dictionary *, const char *,
static struct variable **dependent_vars;
-static int n_dependent_vars;
+static size_t n_dependent_vars;
struct factor
if ( cmd.sbc_plot)
{
- int v;
+ size_t v;
struct factor_statistics **fs = fctr->fs ;
void
factor_calc(struct ccase *c, int case_no, double weight, int case_missing)
{
- int v;
+ size_t v;
struct factor *fctr = factors;
while ( fctr)
hsh_probe(fctr->fstats, (void *) &key );
if ( !*ffs ) {
- int i;
+ size_t i;
(*ffs) = create_factor_statistics (n_dependent_vars,
&key[0], &key[1]);
for ( i = 0 ; i < n_dependent_vars ; ++i )
if ( totals )
{
- int i;
+ size_t i;
for ( i = 0 ; i < n_dependent_vars ; ++i )
{
metrics_destroy(&totals[i]);
}
struct fixed_string
-copy_string (struct expression *e, const unsigned char *old, size_t length)
+copy_string (struct expression *e, const char *old, size_t length)
{
struct fixed_string s = alloc_string (e, length);
memcpy (s.string, old, length);
struct fixed_string alloc_string (struct expression *, size_t length);
struct fixed_string copy_string (struct expression *,
- const unsigned char *, size_t length);
+ const char *, size_t length);
static inline bool
is_valid (double d)
if (token == T_ID && lex_look_ahead () == 'T')
{
struct variable **vars;
- int var_cnt;
- int i;
+ size_t var_cnt;
+ size_t i;
if (!parse_variables (default_dict, &vars, &var_cnt, PV_SINGLE))
goto fail;
{
struct variable **var; /* Variables to transpose. */
int *idx_to_fv; /* var[]->index to compacted sink case fv. */
- int var_cnt; /* Number of elements in `var'. */
+ size_t var_cnt; /* Number of elements in `var'. */
int case_cnt; /* Pre-flip case count. */
size_t case_size; /* Post-flip bytes per case. */
if (flip->new_names)
{
- int i;
+ size_t i;
for (i = 0; i < flip->var_cnt; i++)
if (flip->var[i] == flip->new_names)
flip_sink_create (struct flip_pgm *flip)
{
struct flip_sink_info *info = xmalloc (sizeof *info);
- int i;
+ size_t i;
info->flip = flip;
info->output_buf = xmalloc (sizeof *info->output_buf * flip->var_cnt);
{
struct flip_sink_info *info = sink->aux;
struct flip_pgm *flip = info->flip;
- int i;
+ size_t i;
flip->case_cnt++;
{
unsigned long read_cases = min (flip->case_cnt - case_idx,
case_capacity);
- int i;
+ size_t i;
if (read_cases != fread (input_buf, case_bytes, read_cases, input_file))
msg (FE, _("Error reading FLIP file: %s."), strerror (errno));
{
struct flip_pgm *flip = source->aux;
union value *input_buf;
- int i;
+ size_t i;
input_buf = xmalloc (sizeof *input_buf * flip->case_cnt);
for (i = 0; i < flip->var_cnt; i++)
{
/* Variables. */
struct variable **v;
- int cv;
+ size_t cv;
/* Format to set the variables to. */
struct fmt_spec f;
int type;
/* Counter. */
- int i;
+ size_t i;
for (;;)
{
static int normal; /* FIXME */
/* Variables for which to calculate statistics. */
-static int n_variables;
+static size_t n_variables;
static struct variable **v_variables;
/* Arenas used to store semi-permanent storage. */
calc (struct ccase *c, void *aux UNUSED)
{
double weight;
- int i;
+ size_t i;
int bad_warn = 1;
weight = dict_get_case_weight (default_dict, c, &bad_warn);
static void
precalc (void *aux UNUSED)
{
- int i;
+ size_t i;
pool_destroy (gen_pool);
gen_pool = pool_create ();
static void
postcalc (void *aux UNUSED)
{
- int i;
+ size_t i;
for (i = 0; i < n_variables; i++)
{
int mode;
int min = 0, max = 0;
- int old_n_variables = n_variables;
- int i;
+ size_t old_n_variables = n_variables;
+ size_t i;
lex_match ('=');
if (token != T_ALL && (token != T_ID
|| token == T_ID)
for (;;)
{
- int i;
+ size_t i;
/* Max, current size of list; list itself. */
int nl, ml;
double *dl;
/* Variable list. */
- int n;
+ size_t n;
struct variable **v;
if (!parse_variables (default_dict, &v, &n,
static bool
rename_variables (struct dictionary *dict)
{
- int i;
+ size_t i;
int success = 0;
struct variable **v;
char **new_names;
- int nv, nn;
+ size_t nv, nn;
char *err_name;
int group;
group = 1;
while (lex_match ('('))
{
- int old_nv = nv;
+ size_t old_nv = nv;
if (!parse_variables (dict, &v, &nv, PV_NO_DUPLICATE | PV_APPEND))
goto done;
msg (SE, _("Number of variables on left side of `=' (%d) does not "
"match number of variables on right side (%d), in "
"parenthesized group %d of RENAME subcommand."),
- nv - old_nv, nn - old_nv, group);
+ (unsigned) (nv - old_nv), (unsigned) (nn - old_nv), group);
goto done;
}
if (!lex_force_match (')'))
drop_variables (struct dictionary *dict)
{
struct variable **v;
- int nv;
+ size_t nv;
lex_match ('=');
if (!parse_variables (dict, &v, &nv, PV_NONE))
keep_variables (struct dictionary *dict)
{
struct variable **v;
- int nv;
- int i;
+ size_t nv;
+ size_t i;
lex_match ('=');
if (!parse_variables (dict, &v, &nv, PV_NONE))
struct mtf_file *head; /* First file mentioned on FILE or TABLE. */
struct mtf_file *tail; /* Last file mentioned on FILE or TABLE. */
- int by_cnt; /* Number of variables on BY subcommand. */
+ size_t by_cnt; /* Number of variables on BY subcommand. */
/* Names of FIRST, LAST variables. */
char first[LONG_NAME_LEN + 1], last[LONG_NAME_LEN + 1];
for (iter = mtf.head; iter != NULL; iter = iter->next)
{
- int i;
+ size_t i;
iter->by = xmalloc (sizeof *iter->by * mtf.by_cnt);
FILE *prologue_file;
char *buf = NULL;
- int buf_size = 0;
+ size_t buf_size = 0;
if (prologue_fn == NULL)
{
struct variable *v_indep;
/* Number of dependent variables */
- int n_dep;
+ size_t n_dep;
/* The dependent variables */
struct variable **v_dep;
void
levene(const struct casefile *cf,
- struct variable *v_indep, int n_dep, struct variable **v_dep,
+ struct variable *v_indep, size_t n_dep, struct variable **v_dep,
enum lev_missing missing, is_missing_func value_is_missing)
{
struct casereader *r;
static void
levene_precalc (const struct levene_info *l)
{
- int i;
+ size_t i;
lz = xmalloc (sizeof (struct lz_stats ) * l->n_dep ) ;
static int
levene_calc (const struct ccase *c, void *_l)
{
- int i;
+ size_t i;
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
const union value *gv = case_data (c, l->v_indep->fv);
static void
levene_postcalc (void *_l)
{
- int v;
+ size_t v;
struct levene_info *l = (struct levene_info *) _l;
static void
levene2_precalc (void *_l)
{
- int v;
+ size_t v;
struct levene_info *l = (struct levene_info *) _l;
static int
levene2_calc (const struct ccase *c, void *_l)
{
- int i;
+ size_t i;
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
static void
levene2_postcalc (void *_l)
{
- int v;
+ size_t v;
struct levene_info *l = (struct levene_info *) _l;
void levene(const struct casefile *cf,
- struct variable *v_indep, int n_dep, struct variable **v_dep,
+ struct variable *v_indep, size_t n_dep, struct variable **v_dep,
enum lev_missing, is_missing_func);
#include "misc.h"
#include "htmlP.h"
#include "output.h"
+#include "size_max.h"
#include "som.h"
#include "tab.h"
#include "var.h"
struct list_ext
{
int type; /* 0=Values and labels fit across the page. */
- int n_vertical; /* Number of labels to list vertically. */
- int header_rows; /* Number of header rows. */
+ size_t n_vertical; /* Number of labels to list vertically. */
+ size_t header_rows; /* Number of header rows. */
char **header; /* The header itself. */
};
static char *line_buf;
/* TTY-style output functions. */
-static int n_lines_remaining (struct outp_driver *d);
-static int n_chars_width (struct outp_driver *d);
+static unsigned n_lines_remaining (struct outp_driver *d);
+static unsigned n_chars_width (struct outp_driver *d);
static void write_line (struct outp_driver *d, char *s);
/* Other functions. */
/* Returns the number of text lines that can fit on the remainder of
the page. */
-static inline int
+static inline unsigned
n_lines_remaining (struct outp_driver *d)
{
int diff;
/* Returns the number of fixed-width character that can fit across the
page. */
-static inline int
+static inline unsigned
n_chars_width (struct outp_driver *d)
{
return d->width / d->fixed_width;
{
if (dict_get_weight (default_dict) != NULL)
{
- int i;
+ size_t i;
for (i = 0; i < cmd.n_variables; i++)
if (cmd.v_variables[i] == dict_get_weight (default_dict))
fputs ("<TABLE BORDER=1>\n <TR>\n", x->file.file);
{
- int i;
+ size_t i;
for (i = 0; i < cmd.n_variables; i++)
fprintf (x->file.file, " <TH><I><B>%s</B></I></TH>\n",
/* Design the header. */
if (!prc->header)
{
- int i, x;
-
+ size_t i;
+ size_t x;
+
/* Allocate, initialize header. */
prc->header = xmalloc (sizeof (char *) * prc->header_rows);
{
for (i = x = 0; i < prc->n_vertical; i++)
{
struct variable *v = cmd.v_variables[i];
- int j;
+ size_t j;
memset (&prc->header[prc->header_rows - 1][x], '-', v->print.w);
x += v->print.w - 1;
- for (j = 0; j < (int) strlen (v->name); j++)
+ for (j = 0; j < strlen (v->name); j++)
prc->header[strlen (v->name) - j - 1][x] = v->name[j];
x += 2;
}
}
/* Write out the header, in back-to-front order except for the last line. */
- {
- int i;
-
- for (i = prc->header_rows - 2; i >= 0; i--)
- write_line (d, prc->header[i]);
- write_line (d, prc->header[prc->header_rows - 1]);
- }
+ if (prc->header_rows >= 2)
+ {
+ size_t i;
+
+ for (i = prc->header_rows - 1; i-- != 0; )
+ write_line (d, prc->header[i]);
+ }
+ write_line (d, prc->header[prc->header_rows - 1]);
}
if (d->class->special == 0)
{
struct list_ext *prc = d->prc;
- int i;
+ size_t i;
if (prc->header)
{
for (d = outp_drivers (NULL); d; d = outp_drivers (d))
{
- int column; /* Current column. */
+ size_t column; /* Current column. */
int width; /* Accumulated width. */
int height; /* Height of vertical names. */
int max_width; /* Page width. */
if (width <= max_width && height <= SHORT_NAME_LEN)
{
#ifndef NDEBUG
- prc->n_vertical = -1;
+ prc->n_vertical = SIZE_MAX;
#endif
- for (column = cmd.n_variables - 1; column >= 0; column--)
+ for (column = cmd.n_variables; column-- != 0; )
{
struct variable *v = cmd.v_variables[column];
int trial_width = (width - v->print.w
}
width = trial_width;
}
- assert(prc->n_vertical != -1);
+ assert (prc->n_vertical != SIZE_MAX);
prc->n_vertical = cmd.n_variables;
/* Finally determine the length of the headers. */
column < prc->n_vertical;
column++)
prc->header_rows = max (prc->header_rows,
- (int) strlen (cmd.v_variables[column]->name));
+ strlen (cmd.v_variables[column]->name));
prc->header_rows++;
d->class->text_set_font_by_name (d, "FIXED");
struct variable *single_split; /* Single SPLIT FILE variable. */
/* Factor variables. */
- int n_factors; /* Number of factor variables. */
+ size_t n_factors; /* Number of factor variables. */
struct variable **factors; /* Factor variables. */
int is_per_factor[PROX + 1]; /* Is there per-factor data? */
if (lex_match_id ("VARIABLES"))
{
char **v;
- int nv;
+ size_t nv;
if (seen & 1)
{
goto lossage;
{
- int i;
+ size_t i;
for (i = 0; i < nv; i++)
if (!strcasecmp (v[i], "VARNAME_"))
}
{
- int i;
+ size_t i;
for (i = 0; i < nv; i++)
{
else
{
struct variable **split;
- int n;
+ size_t n;
if (!parse_variables (default_dict, &split, &n, PV_NO_DUPLICATE))
goto lossage;
}
seen |= 4;
- if (!parse_variables (default_dict, &mx->factors, &mx->n_factors, PV_NONE))
+ if (!parse_variables (default_dict, &mx->factors, &mx->n_factors,
+ PV_NONE))
goto lossage;
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
{
system file output. */
{
struct variable **v;
- int nv;
+ size_t nv;
dict_get_vars (default_dict, &v, &nv, 0);
qsort (v, nv, sizeof *v, compare_variables_by_mxd_var_type);
nr.mx = mx;
nr.data = NULL;
- nr.factor_values = xmalloc (sizeof *nr.factor_values * mx->n_factors * mx->cells);
+ nr.factor_values = xmalloc (sizeof *nr.factor_values
+ * mx->n_factors * mx->cells);
nr.max_cell_idx = 0;
nr.split_values = xmalloc (sizeof *nr.split_values
* dict_get_split_cnt (default_dict));
}
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
{
for (cell = 0; cell < mx->cells; cell++)
{
{
- int factor;
+ size_t factor;
for (factor = 0; factor < mx->n_factors; factor++)
{
int content;
{
- int factor;
+ size_t factor;
for (factor = 0; factor < mx->n_factors; factor++)
case_data_rw (c, mx->factors[factor]->fv)->f = SYSMIS;
for (iter = wr->data; iter; iter = iter->next)
{
{
- int factor;
+ size_t factor;
for (factor = 0; factor < mx->n_factors; factor++)
case_data_rw (c, mx->factors[factor]->fv)->f
wr->content = -1;
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
{
mechanism. */
if (wr->current)
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
if (factor_values[i] != wr->current->factors[i])
for (iter = wr->data; iter; iter = iter->next)
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
if (factor_values[i] != iter->factors[i])
{
struct factor_data *new = pool_alloc (mx->container, sizeof *new);
- new->factors = pool_alloc (mx->container, sizeof *new->factors * mx->n_factors);
+ new->factors = pool_alloc (mx->container,
+ sizeof *new->factors * mx->n_factors);
{
- int i;
+ size_t i;
for (i = 0; i < mx->n_factors; i++)
new->factors[i] = factor_values[i];
/* TABLES: Variable lists for each dimension. */
int n_dim; /* Number of dimensions. */
-int *nv_dim; /* Number of variables in each dimension. */
+size_t *nv_dim; /* Number of variables in each dimension. */
struct variable ***v_dim; /* Variables in each dimension. */
/* VARIABLES: List of variables. */
do
{
- int nvl;
+ size_t nvl;
struct variable **vl;
if (!parse_var_set_vars (var_set, &vl, &nvl,
cmd_missing_values (void)
{
struct variable **v;
- int nv;
+ size_t nv;
int retval = CMD_PART_SUCCESS_MAYBE;
bool deferred_errors = false;
while (token != '.')
{
- int i;
-
+ size_t i;
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
goto done;
if (lex_match_id ("REORDER"))
{
struct variable **v = NULL;
- int nv = 0;
+ size_t nv = 0;
if (already_encountered & 1)
{
do
{
struct ordering ordering;
- int prev_nv = nv;
+ size_t prev_nv = nv;
ordering.forward = ordering.positional = 1;
if (lex_match_id ("FORWARD"));
lex_match ('=');
do
{
- int prev_nv_1 = vm.rename_cnt;
- int prev_nv_2 = vm.rename_cnt;
+ size_t prev_nv_1 = vm.rename_cnt;
+ size_t prev_nv_2 = vm.rename_cnt;
if (!lex_match ('('))
{
else if (lex_match_id ("KEEP"))
{
struct variable **keep_vars, **all_vars, **drop_vars;
- int keep_cnt, all_cnt, drop_cnt;
+ size_t keep_cnt, all_cnt, drop_cnt;
if (already_encountered & 4)
{
compare_variables_given_ordering, &forward_positional_ordering);
dict_get_vars (default_dict, &all_vars, &all_cnt, 0);
+ assert (all_cnt >= keep_cnt);
drop_cnt = all_cnt - keep_cnt;
drop_vars = xmalloc (drop_cnt * sizeof *keep_vars);
else if (lex_match_id ("DROP"))
{
struct variable **drop_vars;
- int drop_cnt;
+ size_t drop_cnt;
if (already_encountered & 4)
{
struct variable **keep_vars;
struct variable **drop_vars;
size_t keep_cnt, drop_cnt;
- int all_cnt;
+ size_t all_cnt;
struct var_renaming *var_renaming;
int valid;
compare_variables_given_ordering, &forward_positional_ordering);
/* Keep variables, in index order. */
+ assert (all_cnt >= drop_cnt);
keep_cnt = all_cnt - drop_cnt;
keep_vars = xmalloc (keep_cnt * sizeof *keep_vars);
if (set_difference (all_vars, all_cnt,
int
cmd_numeric (void)
{
- int i;
+ size_t i;
/* Names of variables to create. */
char **v;
- int nv;
+ size_t nv;
/* Format spec for variables to create. f.type==-1 if default is to
be used. */
int
cmd_string (void)
{
- int i;
+ size_t i;
/* Names of variables to create. */
char **v;
- int nv;
+ size_t nv;
/* Format spec for variables to create. */
struct fmt_spec f;
cmd_leave (void)
{
struct variable **v;
- int nv;
+ size_t nv;
- int i;
+ size_t i;
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
return CMD_FAILURE;
static struct variable *indep_var;
/* Number of dependent variables */
-static int n_vars;
+static size_t n_vars;
/* The dependent variables */
static struct variable **vars;
void
output_oneway(void)
{
-
- int i;
+ size_t i;
short *bad_contrast ;
bad_contrast = xmalloc ( sizeof (short) * cmd.sbc_contrast );
static void
show_anova_table(void)
{
- int i;
+ size_t i;
int n_cols =7;
- int n_rows = n_vars * 3 + 1;
+ size_t n_rows = n_vars * 3 + 1;
struct tab_table *t;
static void
show_descriptives(void)
{
- int v;
+ size_t v;
int n_cols =10;
struct tab_table *t;
int row;
static void
show_homogeneity(void)
{
- int v;
+ size_t v;
int n_cols = 5;
- int n_rows = n_vars + 1;
+ size_t n_rows = n_vars + 1;
struct tab_table *t;
static void
show_contrast_tests(short *bad_contrast)
{
- int v;
+ size_t v;
int n_cols = 8;
- int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
+ size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
struct tab_table *t;
static void
precalc ( struct cmd_oneway *cmd UNUSED )
{
- int i=0;
+ size_t i=0;
for(i=0; i< n_vars ; ++i)
{
casereader_read (r, &c) ;
case_destroy (&c))
{
- int i;
+ size_t i;
const double weight =
dict_get_case_weight(default_dict,&c,&bad_weight_warn);
void
postcalc ( struct cmd_oneway *cmd UNUSED )
{
- int i=0;
+ size_t i=0;
for(i = 0; i < n_vars ; ++i)
static struct
{
struct variable **v; /* variable list */
- int nv; /* number of variables in list */
- int cv; /* number of variables from list used up so far
+ size_t nv; /* number of variables in list */
+ size_t cv; /* number of variables from list used up so far
by the FORTRAN-like format specifiers */
int recno; /* current 1-based record number */
else
{
/* User wants dictionary format specifiers. */
- int i;
+ size_t i;
lex_match ('*');
for (i = 0; i < fx.nv; i++)
static int
fixed_parse_compatible (void)
{
- int dividend;
+ int individual_var_width;
int type;
- int i;
+ size_t i;
type = fx.v[0]->type;
for (i = 1; i < fx.nv; i++)
if ((fx.lc - fx.fc + 1) % fx.nv)
{
- msg (SE, _("The %d columns %d-%d can't be evenly divided into %d "
- "fields."), fx.lc - fx.fc + 1, fx.fc + 1, fx.lc + 1, fx.nv);
+ msg (SE, _("The %d columns %d-%d can't be evenly divided into %u "
+ "fields."),
+ fx.lc - fx.fc + 1, fx.fc + 1, fx.lc + 1, (unsigned) fx.nv);
return 0;
}
- dividend = (fx.lc - fx.fc + 1) / fx.nv;
- fx.spec.u.v.f.w = dividend;
+ individual_var_width = (fx.lc - fx.fc + 1) / fx.nv;
+ fx.spec.u.v.f.w = individual_var_width;
if (!check_output_specifier (&fx.spec.u.v.f, true)
|| !check_specifier_type (&fx.spec.u.v.f, type, true))
return 0;
fx.spec.type = PRT_VAR;
for (i = 0; i < fx.nv; i++)
{
- fx.spec.fc = fx.fc + dividend * i;
+ fx.spec.fc = fx.fc + individual_var_width * i;
fx.spec.u.v.v = fx.v[i];
append_var_spec (&fx.spec);
}
break;
case SBC_VARLIST:
- dump (0, "int %sn_%s;", st_lower (sbc->prefix),
+ dump (0, "size_t %sn_%s;", st_lower (sbc->prefix),
st_lower (sbc->name));
dump (0, "struct variable **%sv_%s;", st_lower (sbc->prefix),
st_lower (sbc->name));
static struct rank_spec *rank_specs;
-static int n_rank_specs;
+static size_t n_rank_specs;
static struct sort_criteria *sc;
static struct variable **group_vars;
-static int n_group_vars;
+static size_t n_group_vars;
static struct cmd_rank cmd;
int
cmd_rank(void)
{
- int i;
+ size_t i;
n_rank_specs = 0;
if ( !parse_rank(&cmd) )
union value sysmis; /* Coding for SYSMIS (if src is numeric). */
struct coding *map; /* Coding for other values. */
- int nmap, mmap; /* Length of map, max capacity of map. */
+ size_t nmap, mmap; /* Length of map, max capacity of map. */
};
/* RECODE transformation. */
int
cmd_recode (void)
{
- int i;
+ size_t i;
/* Transformation that we're constructing. */
struct rcd_var *rcd;
/* Variables in the current part of the recoding. */
struct variable **v;
- int nv;
+ size_t nv;
/* Parses each specification between slashes. */
head = rcd = xmalloc (sizeof *rcd);
for (;;)
{
/* Get the input value (before the `='). */
- int mark = rcd->nmap;
+ size_t mark = rcd->nmap;
int code = parse_src_spec (rcd, type, max_src_width);
if (!code)
goto lossage;
if (lex_match_id ("INTO"))
{
char **names;
- int nnames;
+ size_t nnames;
int success = 0;
for (i = 0; i < nnames; i++)
free (names[i]);
free (names);
- msg (SE, _("%d variable(s) cannot be recoded into "
- "%d variable(s). Specify the same number "
+ msg (SE, _("%u variable(s) cannot be recoded into "
+ "%u variable(s). Specify the same number "
"of variables as input and output variables."),
- nv, nnames);
+ (unsigned) nv, (unsigned) nnames);
goto lossage;
}
if (!v)
{
msg (SE, _("There is no string variable named "
- "%s. (All string variables specified "
- "on INTO must already exist. Use the "
- "STRING command to create a string "
- "variable.)"), names[i]);
+ "%s. (All string variables specified "
+ "on INTO must already exist. Use the "
+ "STRING command to create a string "
+ "variable.)"),
+ names[i]);
goto INTO_fail;
}
if (v->type != ALPHA)
{
msg (SE, _("Type mismatch between input and output "
- "variables. Output variable %s is not "
- "a string variable, but all the input "
- "variables are string variables."), v->name);
+ "variables. Output variable %s is not "
+ "a string variable, but all the input "
+ "variables are string variables."),
+ v->name);
goto INTO_fail;
}
if (v->width > (int) max_dst_width)
for (;;)
{
- if (rcd->nmap >= rcd->mmap - 1)
+ if (rcd->nmap + 1 >= rcd->mmap)
{
rcd->mmap += 16;
rcd->map = xrealloc (rcd->map, rcd->mmap * sizeof *rcd->map);
static void
recode_trns_free (struct trns_header * t)
{
- int i;
+ size_t i;
struct rcd_var *head, *next;
head = ((struct recode_trns *) t)->codings;
string_to_long (const char *nptr, int width, const char **endptr)
{
int negative;
- register unsigned long int cutoff;
- register unsigned int cutlim;
- register unsigned long int i;
- register const char *s;
- register unsigned char c;
+ unsigned long int cutoff;
+ unsigned int cutlim;
+ unsigned long int i;
+ const char *s;
+ unsigned char c;
const char *save;
s = nptr;
static double
convert_to_double (const char *s, int width)
{
- register const char *end = &s[width];
+ const char *end = &s[width];
short int sign;
static void
reg_stats_r (pspp_linreg_cache * c)
{
- struct table *t;
+ struct tab_table *t;
int n_rows = 2;
int n_cols = 5;
double rsq;
}
static void
-run_regression (const struct casefile *cf, void *cmd_)
+run_regression (const struct casefile *cf, void *cmd_ UNUSED)
{
size_t i;
size_t k;
{
struct variable **rename_vars = NULL;
char **rename_new_names = NULL;
- int rename_cnt = 0;
+ size_t rename_cnt = 0;
char *err_name;
int status = CMD_FAILURE;
- int i;
-
if (temporary != 0)
{
msg (SE, _("RENAME VARS may not be used after TEMPORARY. "
do
{
- int prev_nv_1 = rename_cnt;
- int prev_nv_2 = rename_cnt;
+ size_t prev_nv_1 = rename_cnt;
+ size_t prev_nv_2 = rename_cnt;
if (!lex_match ('('))
{
goto lossage;
if (prev_nv_1 != rename_cnt)
{
+ size_t i;
+
msg (SE, _("Differing number of variables in old name list "
- "(%d) and in new name list (%d)."),
- rename_cnt - prev_nv_2, prev_nv_1 - prev_nv_2);
+ "(%u) and in new name list (%u)."),
+ (unsigned) rename_cnt - prev_nv_2,
+ (unsigned) prev_nv_1 - prev_nv_2);
for (i = 0; i < prev_nv_1; i++)
free (rename_new_names[i]);
free (rename_new_names);
free (rename_vars);
if (rename_new_names != NULL)
{
+ size_t i;
for (i = 0; i < rename_cnt; i++)
free (rename_new_names[i]);
free (rename_new_names);
static int
parse_ids (struct repeat_entry * e)
{
- int i;
- int n = 0;
+ size_t i;
+ size_t n = 0;
e->type = 1;
e->replacement = NULL;
do
{
char **names;
- int nnames;
+ size_t nnames;
if (!parse_mixed_vars (&names, &nnames, PV_NONE))
return 0;
*/
struct sort_criteria *
sort_parse_criteria (const struct dictionary *dict,
- struct variable ***vars, int *var_cnt,
+ struct variable ***vars, size_t *var_cnt,
bool *saw_direction,
const int *terminators
)
do
{
- int prev_var_cnt = *var_cnt;
+ size_t prev_var_cnt = *var_cnt;
enum sort_direction direction;
/* Variables. */
struct dictionary;
struct sort_criteria *sort_parse_criteria (const struct dictionary *,
- struct variable ***, int *,
+ struct variable ***, size_t *,
bool *saw_direction,
const int *terminators
);
else
{
struct variable **v;
- int n;
+ size_t n;
/* For now, ignore SEPARATE and LAYERED. */
lex_match_id ("SEPARATE") || lex_match_id ("LAYERED");
static void display_macros (void);
static void display_documents (void);
-static void display_variables (struct variable **, int, int);
+static void display_variables (struct variable **, size_t, int);
static void display_vectors (int sorted);
int
int sorted;
/* Variables to display. */
- int n;
+ size_t n;
struct variable **vl;
if (lex_match_id ("MACROS"))
if (as == AS_SCRATCH)
{
- int i, m;
+ size_t i, m;
for (i = 0, m = n; i < n; i++)
if (dict_class_from_id (vl[i]->name) != DC_SCRATCH)
{
}
static void
-display_variables (struct variable **vl, int n, int as)
+display_variables (struct variable **vl, size_t n, int as)
{
struct variable **vp = vl; /* Variable pointer. */
struct tab_table *t;
int nr; /* Number of rows. */
int pc; /* `Position column' */
int r; /* Current row. */
- int i;
+ size_t i;
_as = as;
switch (as)
#include <stdlib.h>
#include <math.h>
#include "alloc.h"
-#include "str.h"
#include "case.h"
+#include "casefile.h"
#include "command.h"
#include "dictionary.h"
-#include "lexer.h"
#include "error.h"
+#include "group_proc.h"
+#include "hash.h"
+#include "levene.h"
+#include "lexer.h"
#include "magic.h"
#include "misc.h"
-#include "tab.h"
+#include "size_max.h"
#include "som.h"
+#include "str.h"
+#include "tab.h"
#include "value-labels.h"
#include "var.h"
#include "vfm.h"
-#include "hash.h"
-#include "group_proc.h"
-#include "casefile.h"
-#include "levene.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
tts_custom_pairs (struct cmd_t_test *cmd UNUSED)
{
struct variable **vars;
- int n_vars;
- int n_pairs_local;
+ size_t n_vars;
+ size_t n_pairs_local;
- int n_before_WITH ;
- int n_after_WITH = -1;
+ size_t n_before_WITH;
+ size_t n_after_WITH = SIZE_MAX;
int paired ; /* Was the PAIRED keyword given ? */
lex_match('=');
}
assert (n_vars);
- n_before_WITH=0;
+ n_before_WITH = 0;
if (lex_match (T_WITH))
{
n_before_WITH = n_vars;
n_before_WITH, n_after_WITH );
return 0;
}
- n_pairs_local=n_before_WITH;
+ n_pairs_local = n_before_WITH;
}
else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
{
- n_pairs_local=n_before_WITH * n_after_WITH ;
+ n_pairs_local = n_before_WITH * n_after_WITH ;
}
else /* Neither WITH nor PAIRED keyword given */
{
}
/* how many ways can you pick 2 from n_vars ? */
- n_pairs_local = n_vars * (n_vars -1 ) /2 ;
+ n_pairs_local = n_vars * (n_vars - 1) / 2;
}
{
int i;
- assert(n_pairs_local == n_vars/2);
- for (i = 0; i < n_pairs_local ; ++i)
+ assert(n_pairs_local == n_vars / 2);
+ for (i = 0; i < n_pairs_local; ++i)
{
- pairs[i].v[n_pairs+0] = vars[i];
- pairs[i].v[n_pairs+1] = vars[i+n_pairs_local];
+ pairs[i].v[n_pairs] = vars[i];
+ pairs[i].v[n_pairs + 1] = vars[i + n_pairs_local];
}
}
else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
{
int i,j;
- int p=n_pairs;
+ size_t p = n_pairs;
for(i=0 ; i < n_before_WITH ; ++i )
{
}
else /* Neither WITH nor PAIRED given */
{
- int i,j;
- int p=n_pairs;
+ size_t i,j;
+ size_t p=n_pairs;
for(i=0 ; i < n_vars ; ++i )
{
/* Implementation of the Test Results box struct */
-void trbox_base_init(struct trbox *self,int n_vars, int cols);
+void trbox_base_init(struct trbox *self,size_t n_vars, int cols);
void trbox_base_finalize(struct trbox *trb);
void trbox_independent_samples_init(struct trbox *trb,
/* Base initializer for the generalized trbox */
void
-trbox_base_init(struct trbox *self, int data_rows, int cols)
+trbox_base_init(struct trbox *self, size_t data_rows, int cols)
{
- const int rows = 3 + data_rows;
+ const size_t rows = 3 + data_rows;
self->finalize = trbox_base_finalize;
self->t = tab_create (cols, rows, 0);
/* Declarations. */
static int do_value_labels (int);
-static int verify_val_labs (struct variable **vars, int var_cnt);
-static void erase_labels (struct variable **vars, int var_cnt);
-static int get_label (struct variable **vars, int var_cnt);
+static int verify_val_labs (struct variable **vars, size_t var_cnt);
+static void erase_labels (struct variable **vars, size_t var_cnt);
+static int get_label (struct variable **vars, size_t var_cnt);
\f
/* Stubs. */
do_value_labels (int erase)
{
struct variable **vars; /* Variable list. */
- int var_cnt; /* Number of variables. */
+ size_t var_cnt; /* Number of variables. */
int parse_err=0; /* true if error parsing variables */
lex_match ('/');
/* Verifies that none of the VAR_CNT variables in VARS are long
string variables. */
static int
-verify_val_labs (struct variable **vars, int var_cnt)
+verify_val_labs (struct variable **vars, size_t var_cnt)
{
- int i;
+ size_t i;
for (i = 0; i < var_cnt; i++)
{
/* Erases all the labels for the VAR_CNT variables in VARS. */
static void
-erase_labels (struct variable **vars, int var_cnt)
+erase_labels (struct variable **vars, size_t var_cnt)
{
- int i;
+ size_t i;
/* Erase old value labels if desired. */
for (i = 0; i < var_cnt; i++)
/* Parse all the labels for the VAR_CNT variables in VARS and add
the specified labels to those variables. */
static int
-get_label (struct variable **vars, int var_cnt)
+get_label (struct variable **vars, size_t var_cnt)
{
/* Parse all the labels and add them to the variables. */
do
{
union value value;
char *label;
- int i;
+ size_t i;
/* Set value. */
if (vars[0]->type == ALPHA)
do
{
struct variable **v;
- int nv;
+ size_t nv;
- int i;
+ size_t i;
enum alignment align;
do
{
struct variable **v;
- int nv;
- int i;
+ size_t nv;
+ size_t i;
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
return CMD_PART_SUCCESS_MAYBE;
do
{
struct variable **v;
- int nv;
+ size_t nv;
enum measure level;
- int i;
+ size_t i;
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
return CMD_PART_SUCCESS_MAYBE;
int
cmd_variable_labels (void)
{
- struct variable **v;
- int nv;
-
- int i;
-
do
{
+ struct variable **v;
+ size_t nv;
+
+ size_t i;
+
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
return CMD_PART_SUCCESS_MAYBE;
struct variable *var_set_get_var (const struct var_set *vs, size_t idx);
struct variable *var_set_lookup_var (const struct var_set *vs,
const char *name);
-int var_set_lookup_var_idx (const struct var_set *vs, const char *name);
+bool var_set_lookup_var_idx (const struct var_set *vs, const char *name,
+ size_t *idx);
void var_set_destroy (struct var_set *vs);
\f
/* Variable parsers. */
struct variable *parse_variable (void);
struct variable *parse_dict_variable (const struct dictionary *);
-int parse_variables (const struct dictionary *, struct variable ***, int *,
+int parse_variables (const struct dictionary *, struct variable ***, size_t *,
int opts);
-int parse_var_set_vars (const struct var_set *, struct variable ***, int *,
+int parse_var_set_vars (const struct var_set *, struct variable ***, size_t *,
int opts);
-int parse_DATA_LIST_vars (char ***names, int *cnt, int opts);
-int parse_mixed_vars (char ***names, int *cnt, int opts);
+int parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts);
+int parse_mixed_vars (char ***names, size_t *cnt, int opts);
#include <config.h>
#include "var.h"
#include <ctype.h>
+#include <stdbool.h>
#include <stdlib.h>
#include "alloc.h"
#include "bitvector.h"
#include "hash.h"
#include "lexer.h"
#include "misc.h"
+#include "size_max.h"
#include "str.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
-/* Parses a name as a variable within VS and returns the
- variable's index if successful. On failure emits an error
- message and returns a null pointer. */
-static int
-parse_vs_variable_idx (const struct var_set *vs)
+/* Parses a name as a variable within VS. Sets *IDX to the
+ variable's index and returns true if successful. On failure
+ emits an error message and returns false. */
+static bool
+parse_vs_variable_idx (const struct var_set *vs, size_t *idx)
{
- int idx;
-
+ assert (idx != NULL);
+
if (token != T_ID)
{
lex_error (_("expecting variable name"));
- return -1;
+ return false;
+ }
+ else if (var_set_lookup_var_idx (vs, tokid, idx))
+ {
+ lex_get ();
+ return true;
+ }
+ else
+ {
+ msg (SE, _("%s is not a variable name."), tokid);
+ return false;
}
-
- idx = var_set_lookup_var_idx (vs, tokid);
- if (idx < 0)
- msg (SE, _("%s is not a variable name."), tokid);
- lex_get ();
-
- return idx;
}
/* Parses a name as a variable within VS and returns the variable
static struct variable *
parse_vs_variable (const struct var_set *vs)
{
- int idx = parse_vs_variable_idx (vs);
- return idx >= 0 ? var_set_get_var (vs, idx) : NULL;
+ size_t idx;
+ return parse_vs_variable_idx (vs, &idx) ? var_set_get_var (vs, idx) : NULL;
}
/* Parses a variable name in dictionary D and returns the
successful. */
int
parse_variables (const struct dictionary *d, struct variable ***var,
- int *cnt, int opts)
+ size_t *cnt, int opts)
{
struct var_set *vs;
int success;
dictionary class, and returns nonzero. Returns zero on
failure. */
static int
-parse_var_idx_class (const struct var_set *vs, int *idx,
+parse_var_idx_class (const struct var_set *vs, size_t *idx,
enum dict_class *class)
{
- *idx = parse_vs_variable_idx (vs);
- if (*idx < 0)
+ if (!parse_vs_variable_idx (vs, idx))
return 0;
*class = dict_class_from_id (var_set_get_var (vs, *idx)->name);
PV_OPTS, which also affects what variables are allowed in
appropriate ways. */
static void
-add_variable (struct variable ***v, int *nv, int *mv,
+add_variable (struct variable ***v, size_t *nv, size_t *mv,
char *included, int pv_opts,
- const struct var_set *vs, int idx)
+ const struct var_set *vs, size_t idx)
{
struct variable *add = var_set_get_var (vs, idx);
duplicates if indicated by PV_OPTS, which also affects what
variables are allowed in appropriate ways. */
static void
-add_variables (struct variable ***v, int *nv, int *mv, char *included,
+add_variables (struct variable ***v, size_t *nv, size_t *mv, char *included,
int pv_opts,
const struct var_set *vs, int first_idx, int last_idx,
enum dict_class class)
{
- int i;
+ size_t i;
for (i = first_idx; i <= last_idx; i++)
if (dict_class_from_id (var_set_get_var (vs, i)->name) == class)
nonzero and *v is non-NULL. */
int
parse_var_set_vars (const struct var_set *vs,
- struct variable ***v, int *nv,
+ struct variable ***v, size_t *nv,
int pv_opts)
{
- int mv;
+ size_t mv;
char *included;
assert (vs != NULL);
if (!(pv_opts & PV_DUPLICATE))
{
- int i;
+ size_t i;
included = xcalloc (var_set_get_cnt (vs), sizeof *included);
for (i = 0; i < *nv; i++)
do
{
enum dict_class class;
- int first_idx;
+ size_t first_idx;
if (!parse_var_idx_class (vs, &first_idx, &class))
goto fail;
if (!lex_match (T_TO))
- add_variable (v, nv, &mv, included, pv_opts,
- vs, first_idx);
+ add_variable (v, nv, &mv, included, pv_opts, vs, first_idx);
else
{
- int last_idx;
+ size_t last_idx;
enum dict_class last_class;
struct variable *first_var, *last_var;
/* Parses a list of variable names according to the DATA LIST version
of the TO convention. */
int
-parse_DATA_LIST_vars (char ***names, int *nnames, int pv_opts)
+parse_DATA_LIST_vars (char ***names, size_t *nnames, int pv_opts)
{
int n1, n2;
int d1, d2;
int n;
- int nvar, mvar;
+ size_t nvar, mvar;
char name1[LONG_NAME_LEN + 1], name2[LONG_NAME_LEN + 1];
char root1[LONG_NAME_LEN + 1], root2[LONG_NAME_LEN + 1];
int success = 0;
existing and the rest are to be created. Same args as
parse_DATA_LIST_vars(). */
int
-parse_mixed_vars (char ***names, int *nnames, int pv_opts)
+parse_mixed_vars (char ***names, size_t *nnames, int pv_opts)
{
- int i;
+ size_t i;
assert (names != NULL);
assert (nnames != NULL);
if (token == T_ALL || dict_lookup_var (default_dict, tokid) != NULL)
{
struct variable **v;
- int nv;
+ size_t nv;
if (!parse_variables (default_dict, &v, &nv, PV_NONE))
goto fail;
{
size_t (*get_cnt) (const struct var_set *);
struct variable *(*get_var) (const struct var_set *, size_t idx);
- int (*lookup_var_idx) (const struct var_set *, const char *);
+ bool (*lookup_var_idx) (const struct var_set *, const char *, size_t *);
void (*destroy) (struct var_set *);
void *aux;
};
struct variable *
var_set_lookup_var (const struct var_set *vs, const char *name)
{
- int idx = var_set_lookup_var_idx (vs, name);
- return idx >= 0 ? var_set_get_var (vs, idx) : NULL;
+ size_t idx;
+ return (var_set_lookup_var_idx (vs, name, &idx)
+ ? var_set_get_var (vs, idx)
+ : NULL);
}
-/* Returns the index in VS of the variable named NAME, or -1 if
- VS contains no variable with that name. */
-int
-var_set_lookup_var_idx (const struct var_set *vs, const char *name)
+/* If VS contains a variable named NAME, sets *IDX to its index
+ and returns true. Otherwise, returns false. */
+bool
+var_set_lookup_var_idx (const struct var_set *vs, const char *name,
+ size_t *idx)
{
assert (vs != NULL);
assert (name != NULL);
- assert (strlen (name) <= LONG_NAME_LEN );
+ assert (strlen (name) <= LONG_NAME_LEN);
- return vs->lookup_var_idx (vs, name);
+ return vs->lookup_var_idx (vs, name, idx);
}
/* Destroys VS. */
return dict_get_var (d, idx);
}
-/* Returns the index of the variable in VS named NAME, or -1 if
- VS contains no variable with that name. */
-static int
-dict_var_set_lookup_var_idx (const struct var_set *vs, const char *name)
+/* If VS contains a variable named NAME, sets *IDX to its index
+ and returns true. Otherwise, returns false. */
+static bool
+dict_var_set_lookup_var_idx (const struct var_set *vs, const char *name,
+ size_t *idx)
{
struct dictionary *d = vs->aux;
struct variable *v = dict_lookup_var (d, name);
- return v != NULL ? v->index : -1;
+ if (v != NULL)
+ {
+ *idx = v->index;
+ return true;
+ }
+ else
+ return false;
}
/* Destroys VS. */
return (struct variable *) avs->var[idx];
}
-/* Returns the index of the variable in VS named NAME, or -1 if
- VS contains no variable with that name. */
-static int
-array_var_set_lookup_var_idx (const struct var_set *vs, const char *name)
+/* If VS contains a variable named NAME, sets *IDX to its index
+ and returns true. Otherwise, returns false. */
+static bool
+array_var_set_lookup_var_idx (const struct var_set *vs, const char *name,
+ size_t *idx)
{
struct array_var_set *avs = vs->aux;
struct variable v, *vp, *const *vpp;
strcpy (v.name, name);
vp = &v;
vpp = hsh_find (avs->name_tab, &vp);
- return vpp != NULL ? vpp - avs->var : -1;
+ if (vpp != NULL)
+ {
+ *idx = vpp - avs->var;
+ return true;
+ }
+ else
+ return false;
}
/* Destroys VS. */
{
/* Long form. */
struct variable **v;
- int nv;
+ size_t nv;
if (strchr (vecnames, '\0')[1])
{