3cb6f5963f7fdea8ecc4f43bc63faa03891cd61c
[pspp-builds.git] / src / language / dictionary / variable-label.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
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.
9
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.
14
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
18    02110-1301, USA. */
19
20 #include <config.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/lexer/lexer.h>
29 #include <language/lexer/variable-parser.h>
30 #include <libpspp/alloc.h>
31 #include <libpspp/message.h>
32 #include <libpspp/str.h>
33
34 #include "gettext.h"
35 #define _(msgid) gettext (msgid)
36
37 int
38 cmd_variable_labels (struct lexer *lexer, struct dataset *ds)
39 {
40   do
41     {
42       struct variable **v;
43       struct string label;
44       size_t nv;
45
46       size_t i;
47
48       if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
49         return CMD_FAILURE;
50
51       if (lex_token (lexer) != T_STRING)
52         {
53           msg (SE, _("String expected for variable label."));
54           free (v);
55           return CMD_FAILURE;
56         }
57
58       ds_init_string (&label, lex_tokstr (lexer) );
59       if (ds_length (&label) > 255)
60         {
61           msg (SW, _("Truncating variable label to 255 characters."));
62           ds_truncate (&label, 255);
63         }
64       for (i = 0; i < nv; i++)
65         var_set_label (v[i], ds_cstr (&label));
66       ds_destroy (&label);
67
68       lex_get (lexer);
69       while (lex_token (lexer) == '/')
70         lex_get (lexer);
71       free (v);
72     }
73   while (lex_token (lexer) != '.');
74   return CMD_SUCCESS;
75 }
76
77
78