projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change union value type to contain uint8_t types instead of char.
[pspp-builds.git]
/
src
/
data
/
data-in.c
diff --git
a/src/data/data-in.c
b/src/data/data-in.c
index 96a6ce01fdeb8e971d97021854864a8b12d707aa..7e7d087d51dcfa1ab9811715ff7354f106081bae 100644
(file)
--- a/
src/data/data-in.c
+++ b/
src/data/data-in.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006
, 2009
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-27,14
+27,17
@@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <limits.h>
#include "calendar.h"
#include "identifier.h"
#include "settings.h"
#include "value.h"
#include "calendar.h"
#include "identifier.h"
#include "settings.h"
#include "value.h"
+#include "format.h"
#include <libpspp/assertion.h>
#include <libpspp/legacy-encoding.h>
#include <libpspp/assertion.h>
#include <libpspp/legacy-encoding.h>
+#include <libpspp/i18n.h>
#include <libpspp/compiler.h>
#include <libpspp/integer-format.h>
#include <libpspp/message.h>
#include <libpspp/compiler.h>
#include <libpspp/integer-format.h>
#include <libpspp/message.h>
@@
-51,7
+54,7
@@
/* Information about parsing one data field. */
struct data_in
{
/* Information about parsing one data field. */
struct data_in
{
-
enum legacy_encoding encoding;
/* Encoding of source. */
+
const char *encoding;
/* Encoding of source. */
struct substring input; /* Source. */
enum fmt_type format; /* Input format. */
int implied_decimals; /* Number of implied decimal places. */
struct substring input; /* Source. */
enum fmt_type format; /* Input format. */
int implied_decimals; /* Number of implied decimal places. */
@@
-83,8
+86,9
@@
static int hexit_value (int c);
\f
/* Parses the characters in INPUT, which are encoded in the given
ENCODING, according to FORMAT. Stores the parsed
\f
/* Parses the characters in INPUT, which are encoded in the given
ENCODING, according to FORMAT. Stores the parsed
- representation in OUTPUT, which has the given WIDTH (0 for
- a numeric field, otherwise the string width).
+ representation in OUTPUT, which the caller must have
+ initialized with the given WIDTH (0 for a numeric field,
+ otherwise the string width).
If no decimal point is included in a numeric format, then
IMPLIED_DECIMALS decimal places are implied. Specify 0 if no
If no decimal point is included in a numeric format, then
IMPLIED_DECIMALS decimal places are implied. Specify 0 if no
@@
-97,7
+101,7
@@
static int hexit_value (int c);
FIRST_COLUMN plus the length of the input because of the
possibility of escaped quotes in strings, etc.) */
bool
FIRST_COLUMN plus the length of the input because of the
possibility of escaped quotes in strings, etc.) */
bool
-data_in (struct substring input,
enum legacy_encoding
encoding,
+data_in (struct substring input,
const char *
encoding,
enum fmt_type format, int implied_decimals,
int first_column, int last_column, union value *output, int width)
{
enum fmt_type format, int implied_decimals,
int first_column, int last_column, union value *output, int width)
{
@@
-113,7
+117,7
@@
data_in (struct substring input, enum legacy_encoding encoding,
assert ((width != 0) == fmt_is_string (format));
assert ((width != 0) == fmt_is_string (format));
- if (
encoding == LEGACY_NATIVE
+ if (
0 == strcmp (encoding, LEGACY_NATIVE)
|| fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING))
{
i.input = input;
|| fmt_get_category (format) & (FMT_CAT_BINARY | FMT_CAT_STRING))
{
i.input = input;
@@
-121,9
+125,12
@@
data_in (struct substring input, enum legacy_encoding encoding,
}
else
{
}
else
{
+ char *s;
ss_alloc_uninit (&i.input, ss_length (input));
ss_alloc_uninit (&i.input, ss_length (input));
- legacy_recode (encoding, ss_data (input), LEGACY_NATIVE,
- ss_data (i.input), ss_length (input));
+
+ s = recode_string (LEGACY_NATIVE, encoding, ss_data (input), ss_length (input));
+ memcpy (ss_data (i.input), s, ss_length (input));
+ free (s);
i.encoding = LEGACY_NATIVE;
copy = ss_data (i.input);
}
i.encoding = LEGACY_NATIVE;
copy = ss_data (i.input);
}
@@
-170,7
+177,10
@@
parse_number (struct data_in *i)
int save_errno;
char *tail;
int save_errno;
char *tail;
- assert (fmt_get_category (i->format) != FMT_CAT_CUSTOM);
+ if (fmt_get_category (i->format) == FMT_CAT_CUSTOM)
+ {
+ style = settings_get_style (FMT_F);
+ }
/* Trim spaces and check for missing value representation. */
if (trim_spaces_and_check_missing (i))
/* Trim spaces and check for missing value representation. */
if (trim_spaces_and_check_missing (i))
@@
-602,12
+612,14
@@
parse_A (struct data_in *i)
{
/* This is equivalent to buf_copy_rpad, except that we posibly
do a character set recoding in the middle. */
{
/* This is equivalent to buf_copy_rpad, except that we posibly
do a character set recoding in the middle. */
-
char *dst = i->output->s
;
+
uint8_t *dst = value_str_rw (i->output, i->width)
;
size_t dst_size = i->width;
const char *src = ss_data (i->input);
size_t src_size = ss_length (i->input);
size_t dst_size = i->width;
const char *src = ss_data (i->input);
size_t src_size = ss_length (i->input);
- legacy_recode (i->encoding, src, LEGACY_NATIVE, dst, MIN (src_size, dst_size));
+ char *s = recode_string (LEGACY_NATIVE, i->encoding, src, MIN (src_size, dst_size));
+ memcpy (dst, s, dst_size);
+ free (s);
if (dst_size > src_size)
memset (&dst[src_size], ' ', dst_size - src_size);
if (dst_size > src_size)
memset (&dst[src_size], ' ', dst_size - src_size);
@@
-618,6
+630,7
@@
parse_A (struct data_in *i)
static bool
parse_AHEX (struct data_in *i)
{
static bool
parse_AHEX (struct data_in *i)
{
+ uint8_t *s = value_str_rw (i->output, i->width);
size_t j;
for (j = 0; ; j++)
size_t j;
for (j = 0; ; j++)
@@
-632,7
+645,7
@@
parse_AHEX (struct data_in *i)
return false;
}
return false;
}
- if (
i->encoding != LEGACY_NATIVE
)
+ if (
0 != strcmp (i->encoding, LEGACY_NATIVE)
)
{
hi = legacy_to_native (i->encoding, hi);
lo = legacy_to_native (i->encoding, lo);
{
hi = legacy_to_native (i->encoding, hi);
lo = legacy_to_native (i->encoding, lo);
@@
-644,10
+657,10
@@
parse_AHEX (struct data_in *i)
}
if (j < i->width)
}
if (j < i->width)
-
i->output->
s[j] = hexit_value (hi) * 16 + hexit_value (lo);
+ s[j] = hexit_value (hi) * 16 + hexit_value (lo);
}
}
- memset (
i->output->s + j
, ' ', i->width - j);
+ memset (
&s[j]
, ' ', i->width - j);
return true;
}
return true;
}
@@
-1215,7
+1228,7
@@
static void
default_result (struct data_in *i)
{
if (fmt_is_string (i->format))
default_result (struct data_in *i)
{
if (fmt_is_string (i->format))
- memset (
i->output->s
, ' ', i->width);
+ memset (
value_str_rw (i->output, i->width)
, ' ', i->width);
else
i->output->f = settings_get_blanks ();
}
else
i->output->f = settings_get_blanks ();
}