/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
Written by Ben Pfaff <blp@gnu.org>.
This program is free software; you can redistribute it and/or
#include <config.h>
#include "data-in.h"
-#include "message.h"
+#include <libpspp/assertion.h>
#include <math.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
-#include "message.h"
+#include <libpspp/message.h>
#include "calendar.h"
-#include "compiler.h"
+#include <libpspp/compiler.h>
#include "identifier.h"
-#include "magic.h"
-#include "misc.h"
+#include <libpspp/magic.h>
+#include <libpspp/misc.h>
#include "settings.h"
-#include "str.h"
+#include <libpspp/str.h>
#include "variable.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
-
-#include "debug-print.h"
\f
/* Specialized error routine. */
static void
vdls_error (const struct data_in *i, const char *format, va_list args)
{
- struct error e;
- struct string title;
+ struct msg m;
+ struct string text;
+ char format_string[FMT_STRING_LEN_MAX + 1];
if (i->flags & DI_IGNORE_ERROR)
return;
- ds_init (&title, 64);
+ ds_init_empty (&text);
if (i->f1 == i->f2)
- ds_printf (&title, _("(column %d"), i->f1);
+ ds_put_format (&text, _("(column %d"), i->f1);
else
- ds_printf (&title, _("(columns %d-%d"), i->f1, i->f2);
- ds_printf (&title, _(", field type %s) "), fmt_to_string (&i->format));
-
- e.class = DE;
- err_location (&e.where);
- e.title = ds_c_str (&title);
+ ds_put_format (&text, _("(columns %d-%d"), i->f1, i->f2);
+ ds_put_format (&text, _(", field type %s) "),
+ fmt_to_string (&i->format, format_string));
+ ds_put_vformat (&text, format, args);
- err_vmsg (&e, format, args);
+ m.category = MSG_DATA;
+ m.severity = MSG_ERROR;
+ m.text = ds_cstr (&text);
- ds_destroy (&title);
+ msg_emit (&m);
}
static void
i->e--;
}
-/* Returns nonzero if we're not at the end of the string being
+/* Returns true if we're not at the end of the string being
parsed. */
static inline bool
have_char (struct data_in *i)
}
else
sign = 1;
-
- if (type != FMT_DOT)
- {
- decimal = get_decimal();
- grouping = get_grouping();
- }
- else
- {
- decimal = get_grouping();
- grouping = get_decimal();
- }
+
+ decimal = fmt_decimal_char (type);
+ grouping = fmt_grouping_char (type);
i->v->f = SYSMIS;
num = 0.0;
return true;
}
+
static inline bool
parse_A (struct data_in *i)
{
buf_copy_rpad (i->v->s, i->format.w, i->s, i->e - i->s);
+
return true;
}
if (!have_char (i))
return true;
- dls_error (i, _("Trailing garbage \"%s\" following date."), i->s);
+ dls_error (i, _("Trailing garbage \"%.*s\" following date."),
+ (int) (i->e - i->s), i->s);
return false;
}
static void
default_result (struct data_in *i)
{
- const struct fmt_desc *const fmt = &formats[i->format.type];
-
/* Default to SYSMIS or blanks. */
- if (fmt->cat & FCAT_STRING)
+ if (fmt_is_string (i->format.type))
memset (i->v->s, ' ', i->format.w);
else
i->v->f = get_blanks();
bool
data_in (struct data_in *i)
{
- const struct fmt_desc *const fmt = &formats[i->format.type];
+ bool success;
- assert (check_input_specifier (&i->format, 0));
+ assert (fmt_check_input (&i->format));
/* Check that we've got a string to work with. */
if (i->e == i->s || i->format.w <= 0)
i->f2 = i->f1 + (i->e - i->s) - 1;
/* Make sure that the string isn't too long. */
- if (i->format.w > fmt->Imax_w)
+ if (i->format.w > fmt_max_input_width (i->format.type))
{
dls_error (i, _("Field too long (%d characters). Truncated after "
- "character %d."),
- i->format.w, fmt->Imax_w);
- i->format.w = fmt->Imax_w;
+ "character %d."),
+ i->format.w, fmt_max_input_width (i->format.type));
+ i->format.w = fmt_max_input_width (i->format.type);
}
- if (fmt->cat & FCAT_BLANKS_SYSMIS)
+ if (!(fmt_get_category (i->format.type)
+ & (FMT_CAT_STRING | FMT_CAT_BINARY | FMT_CAT_HEXADECIMAL)))
{
const char *cp;
}
}
- {
- static bool (*const handlers[FMT_NUMBER_OF_FORMATS])(struct data_in *) =
- {
- parse_numeric, parse_N, parse_numeric, parse_numeric,
- parse_numeric, parse_numeric, parse_numeric,
- parse_Z, parse_A, parse_AHEX, parse_IB, parse_P, parse_PIB,
- parse_PIBHEX, parse_PK, parse_RB, parse_RBHEX,
- NULL, NULL, NULL, NULL, NULL,
- parse_DATE, parse_EDATE, parse_SDATE, parse_ADATE, parse_JDATE,
- parse_QYR, parse_MOYR, parse_WKYR,
- parse_DATETIME, parse_TIME, parse_DTIME,
- parse_WKDAY, parse_MONTH,
- };
-
- bool (*handler)(struct data_in *);
- bool success;
-
- handler = handlers[i->format.type];
- assert (handler != NULL);
-
- success = handler (i);
- if (!success)
- default_result (i);
- return success;
- }
+ switch (i->format.type)
+ {
+ case FMT_F:
+ case FMT_COMMA:
+ case FMT_DOT:
+ case FMT_DOLLAR:
+ case FMT_PCT:
+ case FMT_E:
+ success = parse_numeric (i);
+ break;
+ case FMT_CCA:
+ case FMT_CCB:
+ case FMT_CCC:
+ case FMT_CCD:
+ case FMT_CCE:
+ NOT_REACHED ();
+ case FMT_N:
+ success = parse_N (i);
+ break;
+ case FMT_Z:
+ success = parse_Z (i);
+ break;
+ case FMT_P:
+ success = parse_P (i);
+ break;
+ case FMT_PK:
+ success = parse_PK (i);
+ break;
+ case FMT_IB:
+ success = parse_IB (i);
+ break;
+ case FMT_PIB:
+ success = parse_PIB (i);
+ break;
+ case FMT_PIBHEX:
+ success = parse_PIBHEX (i);
+ break;
+ case FMT_RB:
+ success = parse_RB (i);
+ break;
+ case FMT_RBHEX:
+ success = parse_RBHEX (i);
+ break;
+ case FMT_DATE:
+ success = parse_DATE (i);
+ break;
+ case FMT_ADATE:
+ success = parse_ADATE (i);
+ break;
+ case FMT_EDATE:
+ success = parse_EDATE (i);
+ break;
+ case FMT_JDATE:
+ success = parse_JDATE (i);
+ break;
+ case FMT_SDATE:
+ success = parse_SDATE (i);
+ break;
+ case FMT_QYR:
+ success = parse_QYR (i);
+ break;
+ case FMT_MOYR:
+ success = parse_MOYR (i);
+ break;
+ case FMT_WKYR:
+ success = parse_WKYR (i);
+ break;
+ case FMT_DATETIME:
+ success = parse_DATETIME (i);
+ break;
+ case FMT_TIME:
+ success = parse_TIME (i);
+ break;
+ case FMT_DTIME:
+ success = parse_DTIME (i);
+ break;
+ case FMT_WKDAY:
+ success = parse_WKDAY (i);
+ break;
+ case FMT_MONTH:
+ success = parse_MONTH (i);
+ break;
+ case FMT_A:
+ success = parse_A (i);
+ break;
+ case FMT_AHEX:
+ success = parse_AHEX (i);
+ break;
+ default:
+ NOT_REACHED ();
+ }
+ if (!success)
+ default_result (i);
+
+ return success;
}
\f
/* Utility function. */