Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
-/* AIX requires this to be the first thing in the file. */
#include <config.h>
-#if __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
-#pragma alloca
-#else
-#ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#endif
-#endif
-#endif
-#endif
-
+#include "pfm.h"
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include "hash.h"
#include "magic.h"
#include "misc.h"
-#include "pfm.h"
#include "str.h"
#include "value-labels.h"
#include "var.h"
static int
corrupt_msg (struct file_handle *h, const char *format,...)
- __attribute__ ((format (printf, 2, 3)));
+ PRINTF_FORMAT (2, 3);
/* Displays a corruption error. */
static int
fclose (ext->file);
if (ext && ext->dict)
- free_dictionary (ext->dict);
+ dict_destroy (ext->dict);
free (ext);
h->class = NULL;
h->ext = NULL;
}
/* Read an integer and return its value, or NOT_INT on failure. */
-int
+static int
read_int (struct file_handle *h)
{
double f = read_float (h);
convert_format (struct file_handle *h, int fmt[3], struct fmt_spec *v,
struct variable *vv)
{
- if (fmt[0] < 0
- || (size_t) fmt[0] >= sizeof translate_fmt / sizeof *translate_fmt)
- lose ((h, _("%s: Bad format specifier byte %d."), vv->name, fmt[0]));
-
- v->type = translate_fmt[fmt[0]];
+ v->type = translate_fmt (fmt[0]);
+ if (v->type == -1)
+ lose ((h, _("%s: Bad format specifier byte (%d)."), vv->name, fmt[0]));
v->w = fmt[1];
v->d = fmt[2];
read_variables (struct file_handle *h)
{
struct pfm_fhuser_ext *ext = h->ext;
+ char *weight_name = NULL;
int i;
if (!match (68 /* 4 */))
corrupt_msg (h, _("Unexpected flag value %d."), x);
}
- ext->dict = new_dictionary (0);
+ ext->dict = dict_create ();
if (match (70 /* 6 */))
{
- char *name = read_string (h);
- if (!name)
+ weight_name = read_string (h);
+ if (!weight_name)
goto lossage;
- strcpy (ext->dict->weight_var, name);
- asciify (ext->dict->weight_var);
+ asciify (weight_name);
+ if (strlen (weight_name) > 8)
+ {
+ corrupt_msg (h, _("Weight variable name (%s) truncated."),
+ weight_name);
+ weight_name[8] = '\0';
+ }
}
for (i = 0; i < ext->nvars; i++)
if (width < 0 || width > 255)
lose ((h, "Bad width %d for variable %s.", width, name));
- v = create_variable (ext->dict, name, width ? ALPHA : NUMERIC, width);
+ v = dict_create_var (ext->dict, name, width);
v->get.fv = v->fv;
if (v == NULL)
lose ((h, _("Duplicate variable name %s."), name));
asciify (v->label);
}
}
- ext->case_size = ext->dict->nval;
- if (ext->dict->weight_var[0] != 0
- && !find_dict_variable (ext->dict, ext->dict->weight_var))
- lose ((h, _("Weighting variable %s not present in dictionary."),
- ext->dict->weight_var));
+ if (weight_name != NULL)
+ {
+ struct variable *weight_var = dict_lookup_var (ext->dict, weight_name);
+ if (weight_var == NULL)
+ lose ((h, _("Weighting variable %s not present in dictionary."),
+ weight_name));
+ free (weight_name);
+
+ dict_set_weight (ext->dict, weight_var);
+ }
return 1;
lossage:
+ free (weight_name);
return 0;
}
goto lossage;
asciify (name);
- v[i] = find_dict_variable (ext->dict, name);
+ v[i] = dict_lookup_var (ext->dict, name);
if (v[i] == NULL)
lose ((h, _("Unknown variable %s while parsing value labels."), name));
/* Translate a case in data file format to a case in active file
format. */
- for (i = 0; i < dict->nvar; i++)
+ for (i = 0; i < dict_get_var_cnt (dict); i++)
{
- struct variable *v = dict->var[i];
+ struct variable *v = dict_get_var (dict, i);
if (v->get.fv == -1)
continue;