c3bb4c2242b73d4553e00bfbe5cc50dd49ae2cfd
[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 dataset *ds)
39 {
40   do
41     {
42       struct variable **v;
43       size_t nv;
44
45       size_t i;
46
47       if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
48         return CMD_FAILURE;
49
50       if (token != T_STRING)
51         {
52           msg (SE, _("String expected for variable label."));
53           free (v);
54           return CMD_FAILURE;
55         }
56       if (ds_length (&tokstr) > 255)
57         {
58           msg (SW, _("Truncating variable label to 255 characters."));
59           ds_truncate (&tokstr, 255);
60         }
61       for (i = 0; i < nv; i++)
62         {
63           if (v[i]->label)
64             free (v[i]->label);
65           v[i]->label = ds_xstrdup (&tokstr);
66         }
67
68       lex_get ();
69       while (token == '/')
70         lex_get ();
71       free (v);
72     }
73   while (token != '.');
74   return CMD_SUCCESS;
75 }
76
77
78
79 const char *
80 var_to_string(const struct variable *var)
81 {
82   if ( !var ) 
83     return 0;
84
85   return ( var->label ? var->label : var->name);
86 }