02110-1301, USA. */
#include <config.h>
-#include "sys-file-reader.h"
-#include "sfm-private.h"
-#include "message.h"
+
#include <stdlib.h>
-#include <ctype.h>
#include <errno.h>
#include <float.h>
-#include <setjmp.h>
-#include "alloc.h"
+#include <c-ctype.h>
+
+#include <libpspp/alloc.h>
+#include <libpspp/message.h>
+#include <libpspp/compiler.h>
+#include <libpspp/magic.h>
+#include <libpspp/misc.h>
+#include <libpspp/str.h>
+
+#include "sys-file-reader.h"
+#include "sfm-private.h"
#include "case.h"
#include "dictionary.h"
-#include "message.h"
#include "file-handle-def.h"
-#include "filename.h"
+#include "file-name.h"
#include "format.h"
-#include "magic.h"
-#include "misc.h"
#include "value-labels.h"
-#include "str.h"
#include "variable.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
-#include "debug-print.h"
-
/* System file reader. */
struct sfm_reader
{
/* Reverse the byte order of 32-bit integer *X. */
static inline void
-bswap_int32 (int32 *x_)
+bswap_int32 (int32_t *x_)
{
char *x = (char *) x_;
bswap (x + 0, x + 3);
static int read_header (struct sfm_reader *,
struct dictionary *, struct sfm_read_info *);
-static int parse_format_spec (struct sfm_reader *, int32,
+static int parse_format_spec (struct sfm_reader *, int32_t,
struct fmt_spec *, const struct variable *);
static int read_value_labels (struct sfm_reader *, struct dictionary *,
struct variable **var_by_idx);
/* Read records of types 3, 4, 6, and 7. */
for (;;)
{
- int32 rec_type;
+ int32_t rec_type;
assertive_buf_read (r, &rec_type, sizeof rec_type, 0);
if (r->reverse_endian)
{
struct
{
- int32 subtype P;
- int32 size P;
- int32 count P;
+ int32_t subtype P;
+ int32_t size P;
+ int32_t count P;
}
data;
unsigned long bytes;
{
struct
{
- int32 measure P;
- int32 width P;
- int32 align P;
+ int32_t measure P;
+ int32_t width P;
+ int32_t align P;
}
params;
case 999:
{
- int32 filler;
+ int32_t filler;
assertive_buf_read (r, &filler, sizeof filler, 0);
goto success;
static int
read_machine_int32_info (struct sfm_reader *r, int size, int count)
{
- int32 data[8];
+ int32_t data[8];
int file_bigendian;
int i;
- if (size != sizeof (int32) || count != 8)
+ if (size != sizeof (int32_t) || count != 8)
lose ((ME, _("%s: Bad size (%d) or count (%d) field on record type 7, "
"subtype 3. Expected size %d, count 8."),
- fh_get_filename (r->fh), size, count, sizeof (int32)));
+ fh_get_filename (r->fh), size, count, sizeof (int32_t)));
assertive_buf_read (r, data, sizeof data, 0);
if (r->reverse_endian)
/* Check eye-category.her string. */
memcpy (prod_name, hdr.prod_name, sizeof hdr.prod_name);
for (i = 0; i < 60; i++)
- if (!isprint ((unsigned char) prod_name[i]))
+ if (!c_isprint ((unsigned char) prod_name[i]))
prod_name[i] = ' ';
for (i = 59; i >= 0; i--)
- if (!isgraph ((unsigned char) prod_name[i]))
+ if (!c_isgraph ((unsigned char) prod_name[i]))
{
prod_name[i] = '\0';
break;
int i;
for (i = sizeof hdr.file_label - 1; i >= 0; i--)
- if (!isspace ((unsigned char) hdr.file_label[i])
- && hdr.file_label[i] != 0)
- {
- char *label = xmalloc (i + 2);
- memcpy (label, hdr.file_label, i + 1);
- label[i + 1] = 0;
- dict_set_label (dict, label);
- free (label);
- break;
- }
+ {
+ if (!c_isspace ((unsigned char) hdr.file_label[i])
+ && hdr.file_label[i] != 0)
+ {
+ char *label = xmalloc (i + 2);
+ memcpy (label, hdr.file_label, i + 1);
+ label[i + 1] = 0;
+ dict_set_label (dict, label);
+ free (label);
+ break;
+ }
+ }
}
if (info)
info->case_cnt = hdr.case_cnt;
for (cp = &prod_name[skip_amt]; cp < &prod_name[60]; cp++)
- if (isgraph ((unsigned char) *cp))
+ if (c_isgraph ((unsigned char) *cp))
break;
strcpy (info->product, cp);
}
"-3, -2, 0, 1, 2, or 3."), fh_get_filename (r->fh), i));
/* Copy first character of variable name. */
- if (!isalpha ((unsigned char) sv.name[0])
- && sv.name[0] != '@' && sv.name[0] != '#')
+ if (sv.name[0] == '@' || sv.name[0] == '#')
lose ((ME, _("%s: position %d: Variable name begins with invalid "
"character."),
fh_get_filename (r->fh), i));
- if (islower ((unsigned char) sv.name[0]))
- msg (MW, _("%s: position %d: Variable name begins with lowercase letter "
- "%c."),
- fh_get_filename (r->fh), i, sv.name[0]);
- if (sv.name[0] == '#')
- msg (MW, _("%s: position %d: Variable name begins with octothorpe "
- "(`#'). Scratch variables should not appear in system "
- "files."),
- fh_get_filename (r->fh), i);
- name[0] = toupper ((unsigned char) (sv.name[0]));
+
+ name[0] = sv.name[0];
/* Copy remaining characters of variable name. */
for (j = 1; j < SHORT_NAME_LEN; j++)
{
int c = (unsigned char) sv.name[j];
- if (isspace (c))
+ if (c == ' ')
break;
- else if (islower (c))
- {
- msg (MW, _("%s: position %d: Variable name character %d is "
- "lowercase letter %c."),
- fh_get_filename (r->fh), i, j + 1, sv.name[j]);
- name[j] = toupper ((unsigned char) (c));
- }
- else if (isalnum (c) || c == '.' || c == '@'
- || c == '#' || c == '$' || c == '_')
+ else
name[j] = c;
- else
- lose ((ME, _("%s: position %d: character `\\%03o' (%c) is not valid in a "
- "variable name."),
- fh_get_filename (r->fh), i, c, c));
}
name[j] = 0;
- if ( ! var_is_valid_name(name, false) )
+ if ( ! var_is_plausible_name(name, false) )
lose ((ME, _("%s: Invalid variable name `%s' within system file."),
fh_get_filename (r->fh), name));
/* Create variable. */
-
vv = (*var_by_idx)[i] = dict_create_var (dict, name, sv.type);
if (vv == NULL)
lose ((ME, _("%s: Duplicate variable name `%s' within system file."),
if (sv.has_var_label == 1)
{
/* Disk buffer. */
- int32 len;
+ int32_t len;
/* Read length of label. */
assertive_buf_read (r, &len, sizeof len, 0);
if ( len != 0 )
{
/* Read label into variable structure. */
- vv->label = buf_read (r, NULL, ROUND_UP (len, sizeof (int32)), len + 1);
+ vv->label = buf_read (r, NULL, ROUND_UP (len, sizeof (int32_t)), len + 1);
if (vv->label == NULL)
goto error;
vv->label[len] = '\0';
/* Translates the format spec from sysfile format to internal
format. */
static int
-parse_format_spec (struct sfm_reader *r, int32 s,
+parse_format_spec (struct sfm_reader *r, int32_t s,
struct fmt_spec *f, const struct variable *v)
{
f->type = translate_fmt ((s >> 16) & 0xff);
};
struct label *labels = NULL;
- int32 n_labels; /* Number of labels. */
+ int32_t n_labels; /* Number of labels. */
struct variable **var = NULL; /* Associated variables. */
- int32 n_vars; /* Number of associated variables. */
+ int32_t n_vars; /* Number of associated variables. */
int i;
if (r->reverse_endian)
bswap_int32 (&n_labels);
- if ( n_labels >= ((int32) ~0) / sizeof *labels)
+ if ( n_labels >= ((int32_t) ~0) / sizeof *labels)
{
corrupt_msg(MW, _("%s: Invalid number of labels: %d. Ignoring labels."),
fh_get_filename (r->fh), n_labels);
/* Read record type of type 4 record. */
{
- int32 rec_type;
+ int32_t rec_type;
assertive_buf_read (r, &rec_type, sizeof rec_type, 0);
if (r->reverse_endian)
var = xnmalloc (n_vars, sizeof *var);
for (i = 0; i < n_vars; i++)
{
- int32 var_idx;
+ int32_t var_idx;
struct variable *v;
/* Read variable index, check range. */
static int
read_documents (struct sfm_reader *r, struct dictionary *dict)
{
- int32 line_cnt;
+ int32_t line_cnt;
char *documents;
if (dict_get_documents (dict) != NULL)
return false;
return true;
}
+