/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2010 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
msg (SE, _("`=' expected after variable list."));
goto done;
}
- if (!parse_DATA_LIST_vars (lexer, &new_names, &nn, PV_APPEND | PV_NO_SCRATCH))
+ if (!parse_DATA_LIST_vars (lexer, &new_names, &nn,
+ PV_APPEND | PV_NO_SCRATCH | PV_NO_DUPLICATE))
goto done;
if (nn != nv)
{
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2010 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
be used. */
struct fmt_spec f;
- if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
+ if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NO_DUPLICATE))
return CMD_FAILURE;
/* Get the optional format specification. */
do
{
- if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NONE))
+ if (!parse_DATA_LIST_vars (lexer, &v, &nv, PV_NO_DUPLICATE))
return CMD_FAILURE;
if (!lex_force_match (lexer, '(')
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2010 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
msg (SE, _("`=' expected between lists of new and old variable names."));
goto lossage;
}
- if (!parse_DATA_LIST_vars (lexer, &rename_new_names, &prev_nv_1, PV_APPEND))
+ if (!parse_DATA_LIST_vars (lexer, &rename_new_names, &prev_nv_1,
+ PV_APPEND | PV_NO_DUPLICATE))
goto lossage;
if (prev_nv_1 != rename_cnt)
{
#include "libpspp/misc.h"
#include "libpspp/pool.h"
#include "libpspp/str.h"
+#include "libpspp/stringi-set.h"
#include "gl/xalloc.h"
/* Parses a list of variable names according to the DATA LIST version
of the TO convention. */
bool
-parse_DATA_LIST_vars (struct lexer *lexer, char ***names, size_t *nnames, int pv_opts)
+parse_DATA_LIST_vars (struct lexer *lexer, char ***names,
+ size_t *nnames, int pv_opts)
{
int n1, n2;
int d1, d2;
size_t nvar, mvar;
char name1[VAR_NAME_LEN + 1], name2[VAR_NAME_LEN + 1];
char root1[VAR_NAME_LEN + 1], root2[VAR_NAME_LEN + 1];
+ struct stringi_set set;
int success = 0;
assert (names != NULL);
assert (nnames != NULL);
assert ((pv_opts & ~(PV_APPEND | PV_SINGLE
| PV_NO_SCRATCH | PV_NO_DUPLICATE)) == 0);
- /* FIXME: PV_NO_DUPLICATE is not implemented. */
+ stringi_set_init (&set);
if (pv_opts & PV_APPEND)
- nvar = mvar = *nnames;
+ {
+ nvar = mvar = *nnames;
+
+ if (pv_opts & PV_NO_DUPLICATE)
+ {
+ size_t i;
+
+ for (i = 0; i < nvar; i++)
+ stringi_set_insert (&set, (*names)[i]);
+ }
+ }
else
{
nvar = mvar = 0;
{
char name[VAR_NAME_LEN + 1];
sprintf (name, "%s%0*d", root1, d1, n);
+
+ if (pv_opts & PV_NO_DUPLICATE && !stringi_set_insert (&set, name))
+ {
+ msg (SE, _("Variable %s appears twice in variable list."),
+ name);
+ goto fail;
+ }
(*names)[nvar] = xstrdup (name);
nvar++;
}
fail:
*nnames = nvar;
+ stringi_set_destroy (&set);
if (!success)
{
int i;
size_t n_dest_prev = n_dest;
if (!parse_DATA_LIST_vars (lexer, &dest, &n_dest,
- PV_APPEND | PV_SINGLE | PV_NO_SCRATCH))
+ (PV_APPEND | PV_SINGLE | PV_NO_SCRATCH
+ | PV_NO_DUPLICATE)))
goto error;
/* Assign empty labels. */