/* 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. */
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)
{
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;
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);
enum fmt_type;
union value;
-bool data_in (struct substring input, enum legacy_encoding,
+bool data_in (struct substring input, const char *encoding,
enum fmt_type, int implied_decimals,
int first_column, int last_column,
union value *output, int width);
/* Same as data_out, and additionally recodes the output from
native form into the given legacy character ENCODING. */
void
-data_out_legacy (const union value *input, enum legacy_encoding encoding,
+data_out_legacy (const union value *input, const char *encoding,
const struct fmt_spec *format, char *output)
{
static data_out_converter_func *const converters[FMT_NUMBER_OF_FORMATS] =
assert (fmt_check_output (format));
converters[format->type] (input, format, output);
- if (encoding != LEGACY_NATIVE
+ if (0 != strcmp (encoding, LEGACY_NATIVE)
&& fmt_get_category (format->type) != FMT_CAT_BINARY)
legacy_recode (LEGACY_NATIVE, output, encoding, output, format->w);
}
void data_out (const union value *, const struct fmt_spec *, char *);
-void data_out_legacy (const union value *, enum legacy_encoding,
+void data_out_legacy (const union value *, const char *encoding,
const struct fmt_spec *, char *);
#endif /* data-out.h */
/* FH_REF_FILE only. */
char *file_name; /* File name as provided by user. */
enum fh_mode mode; /* File mode. */
- enum legacy_encoding encoding;/* File encoding. */
+ const char *encoding; /* File encoding. */
/* FH_REF_FILE and FH_REF_INLINE only. */
size_t record_width; /* Length of fixed-format records. */
}
/* Returns the encoding of characters read from HANDLE. */
-enum legacy_encoding
+const char *
fh_get_legacy_encoding (const struct file_handle *handle)
{
assert (handle->referent & (FH_REF_FILE | FH_REF_INLINE));
enum fh_mode mode; /* File mode. */
size_t record_width; /* Length of fixed-format records. */
size_t tab_width; /* Tab width, 0=do not expand tabs. */
- enum legacy_encoding encoding;/* ASCII or EBCDIC? */
+ const char *encoding; /* ASCII or EBCDIC? */
};
void fh_init (void);
/* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
size_t fh_get_record_width (const struct file_handle *);
size_t fh_get_tab_width (const struct file_handle *);
-enum legacy_encoding fh_get_legacy_encoding (const struct file_handle *);
+const char *fh_get_legacy_encoding (const struct file_handle *);
/* Properties of FH_REF_SCRATCH file handles. */
struct scratch_handle *fh_get_scratch_handle (const struct file_handle *);
parse_fixed (const struct data_parser *parser, struct dfm_reader *reader,
struct ccase *c)
{
- enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *encoding = dfm_reader_get_legacy_encoding (reader);
struct field *f;
int row;
parse_delimited_span (const struct data_parser *parser,
struct dfm_reader *reader, struct ccase *c)
{
- enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *encoding = dfm_reader_get_legacy_encoding (reader);
struct string tmp = DS_EMPTY_INITIALIZER;
struct field *f;
parse_delimited_no_span (const struct data_parser *parser,
struct dfm_reader *reader, struct ccase *c)
{
- enum legacy_encoding encoding = dfm_reader_get_legacy_encoding (reader);
+ const char *encoding = dfm_reader_get_legacy_encoding (reader);
struct string tmp = DS_EMPTY_INITIALIZER;
struct substring s;
struct field *f;
}
/* Returns the legacy character encoding of data read from READER. */
-enum legacy_encoding
+const char *
dfm_reader_get_legacy_encoding (const struct dfm_reader *reader)
{
return fh_get_legacy_encoding (reader->fh);
unsigned dfm_eof (struct dfm_reader *);
struct substring dfm_get_record (struct dfm_reader *);
void dfm_expand_tabs (struct dfm_reader *);
-enum legacy_encoding dfm_reader_get_legacy_encoding (
- const struct dfm_reader *);
+const char *dfm_reader_get_legacy_encoding (const struct dfm_reader *);
int dfm_get_percent_read (const struct dfm_reader *);
/* Line control. */
}
/* Returns the legacy character encoding of data written to WRITER. */
-enum legacy_encoding
+const char *
dfm_writer_get_legacy_encoding (const struct dfm_writer *writer)
{
return fh_get_legacy_encoding (writer->fh);
bool dfm_close_writer (struct dfm_writer *);
bool dfm_write_error (const struct dfm_writer *);
bool dfm_put_record (struct dfm_writer *, const char *rec, size_t len);
-enum legacy_encoding dfm_writer_get_legacy_encoding (
- const struct dfm_writer *);
+const char *dfm_writer_get_legacy_encoding (const struct dfm_writer *);
#endif /* data-writer.h */
properties.mode = FH_MODE_VARIABLE;
break;
case FH_360:
- properties.encoding = LEGACY_EBCDIC;
+ properties.encoding = "PSPP-LEGACY-EBCDIC";
if (cmd.recform == FH_FIXED || cmd.recform == FH_F)
properties.mode = FH_MODE_FIXED;
else if (cmd.recform == FH_VARIABLE || cmd.recform == FH_V)
struct pool *pool; /* Stores related data. */
bool eject; /* Eject page before printing? */
bool include_prefix; /* Prefix lines with space? */
- enum legacy_encoding encoding; /* Encoding to use for output. */
+ const char *encoding; /* Encoding to use for output. */
struct dfm_writer *writer; /* Output file, NULL=listing file. */
struct ll_list specs; /* List of struct prt_out_specs. */
size_t record_cnt; /* Number of records to write. */
else
{
ds_put_substring (&trns->line, ds_ss (&spec->string));
- if (trns->encoding != LEGACY_NATIVE)
+ if (0 != strcmp (trns->encoding, LEGACY_NATIVE))
{
size_t length = ds_length (&spec->string);
char *data = ss_data (ds_tail (&trns->line, length));
static const char ebcdic_to_ascii[256];
void
-legacy_recode (enum legacy_encoding from, const char *src,
- enum legacy_encoding to, char *dst,
+legacy_recode (const char *from, const char *src,
+ const char *to, char *dst,
size_t size)
{
- if (from != to)
+ if (0 != strcmp (from, to))
{
const char *table;
size_t i;
- table = from == LEGACY_ASCII ? ascii_to_ebcdic : ebcdic_to_ascii;
+ table = (0 == strcmp (from, "PSPP-LEGACY-ASCII")) ? ascii_to_ebcdic : ebcdic_to_ascii;
for (i = 0; i < size; i++)
dst[i] = table[(unsigned char) src[i]];
}
}
char
-legacy_to_native (enum legacy_encoding from, char c)
+legacy_to_native (const char *from, char c)
{
legacy_recode (from, &c, LEGACY_NATIVE, &c, 1);
return c;
}
char
-legacy_from_native (enum legacy_encoding to, char c)
+legacy_from_native (const char *to, char c)
{
legacy_recode (LEGACY_NATIVE, &c, to, &c, 1);
return c;
#include <stddef.h>
#include <libpspp/compiler.h>
-/* A legacy character encoding.
- This exists only to handle the specific legacy EBCDIC-to-ASCII
- recoding that MODE=360 file handles perform. */
-enum legacy_encoding
- {
- LEGACY_ASCII, /* ASCII or similar character set. */
- LEGACY_EBCDIC, /* IBM EBCDIC character set. */
-
- /* Native character set. */
+
#if 'A' == 0x41
- LEGACY_NATIVE = LEGACY_ASCII
+#define LEGACY_NATIVE "PSPP-LEGACY-ASCII"
#elif 'A' == 0xc1
- LEGACY_NATIVE = LEGACY_EBCDIC
+#define LEGACY_NATIVE "PSPP-LEGACY-EBCDIC"
#else
#error Cannot detect native character set.
#endif
- };
-void legacy_recode (enum legacy_encoding, const char *src,
- enum legacy_encoding, char *dst, size_t);
-char legacy_to_native (enum legacy_encoding from, char) PURE_FUNCTION;
-char legacy_from_native (enum legacy_encoding to, char) PURE_FUNCTION;
+
+
+void legacy_recode (const char *from, const char *src,
+ const char *to, char *dst, size_t);
+char legacy_to_native (const char *from, char) PURE_FUNCTION;
+char legacy_from_native (const char *to, char) PURE_FUNCTION;
#endif /* libpspp/legacy-encoding.h */