From: Ben Pfaff Date: Sun, 13 Feb 2011 19:49:30 +0000 (-0800) Subject: i18n: Introduce C_ENCODING as replacement for LEGACY_NATIVE. X-Git-Tag: v0.7.7~51 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc19562deb692e6db3271eb0402e9f9c99e4cbcb;p=pspp-builds.git i18n: Introduce C_ENCODING as replacement for LEGACY_NATIVE. The LEGACY_NATIVE name seems a bit awkward for something that is just the name of the encoding for strings in C source code, that is, the C locale, so this commit renames it to C_ENCODING and moves it to i18n.h with the rest of the encoding-related functions. In addition, PSPP assumes in various places that the local system has ASCII-based locales. I don't think there's much point in pretending to support EBCDIC, so this commit removes that little bit of support. --- diff --git a/src/data/data-in.c b/src/data/data-in.c index 45ff6099..03b25fe7 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 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 @@ -116,7 +116,7 @@ data_in (struct substring input, const char *input_encoding, /* We're going to parse these into numbers. For this purpose we want to deal with them in the local "C" encoding. Any character not in that encoding wouldn't be valid anyhow. */ - dest_encoding = LEGACY_NATIVE; + dest_encoding = C_ENCODING; } else if (cat & (FMT_CAT_BINARY | FMT_CAT_LEGACY)) { @@ -130,7 +130,7 @@ data_in (struct substring input, const char *input_encoding, { /* We want the hex digits in the local "C" encoding, even though the result may not be in that encoding. */ - dest_encoding = LEGACY_NATIVE; + dest_encoding = C_ENCODING; } else { @@ -245,7 +245,7 @@ has_implied_decimals (struct substring input, const char *input_encoding, return false; } - s = recode_string (LEGACY_NATIVE, input_encoding, + s = recode_string (C_ENCODING, input_encoding, ss_data (input), ss_length (input)); retval = (format == FMT_Z ? strchr (s, '.') == NULL diff --git a/src/data/data-out.c b/src/data/data-out.c index 94a6130a..ca5fcece 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2011 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 @@ -104,10 +104,10 @@ data_out_legacy (const union value *input, const char *encoding, assert (fmt_check_output (format)); converters[format->type] (input, format, output); - if (0 != strcmp (encoding, LEGACY_NATIVE) + if (0 != strcmp (encoding, C_ENCODING) && fmt_get_category (format->type) != FMT_CAT_BINARY) { - char *s = recode_string (encoding, LEGACY_NATIVE, output, format->w ); + char *s = recode_string (encoding, C_ENCODING, output, format->w ); memcpy (output, s, format->w); free (s); } diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index d025ff6a..2d69e258 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 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 @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -260,7 +261,7 @@ const struct fh_properties * fh_default_properties (void) { static const struct fh_properties default_properties - = {FH_MODE_TEXT, 1024, 4, LEGACY_NATIVE}; + = {FH_MODE_TEXT, 1024, 4, C_ENCODING}; return &default_properties; } @@ -333,7 +334,7 @@ const char * fh_get_legacy_encoding (const struct file_handle *handle) { assert (handle->referent & (FH_REF_FILE | FH_REF_INLINE)); - return (handle->referent == FH_REF_FILE ? handle->encoding : LEGACY_NATIVE); + return (handle->referent == FH_REF_FILE ? handle->encoding : C_ENCODING); } /* Returns the scratch file handle associated with HANDLE. diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index ada59c30..a07ca2d8 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -454,7 +454,7 @@ print_trns_proc (void *trns_, struct ccase **c, casenumber case_num UNUSED) { struct print_trns *trns = trns_; bool eject = trns->eject; - char encoded_space = recode_byte (trns->encoding, LEGACY_NATIVE, ' '); + char encoded_space = recode_byte (trns->encoding, C_ENCODING, ' '); int record = 1; struct prt_out_spec *spec; @@ -479,11 +479,11 @@ print_trns_proc (void *trns_, struct ccase **c, casenumber case_num UNUSED) else { ds_put_substring (&trns->line, ds_ss (&spec->string)); - if (0 != strcmp (trns->encoding, LEGACY_NATIVE)) + if (0 != strcmp (trns->encoding, C_ENCODING)) { size_t length = ds_length (&spec->string); char *data = ss_data (ds_tail (&trns->line, length)); - char *s = recode_string (trns->encoding, LEGACY_NATIVE, data, length); + char *s = recode_string (trns->encoding, C_ENCODING, data, length); memcpy (data, s, length); free (s); } @@ -518,7 +518,7 @@ flush_records (struct print_trns *trns, int target_record, else leader = '1'; } - line[0] = recode_byte (trns->encoding, LEGACY_NATIVE, leader); + line[0] = recode_byte (trns->encoding, C_ENCODING, leader); if (trns->writer == NULL) tab_output_text (TAB_FIX, &line[1]); diff --git a/src/language/expressions/helpers.h b/src/language/expressions/helpers.h index cb59c206..59be4005 100644 --- a/src/language/expressions/helpers.h +++ b/src/language/expressions/helpers.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/language/expressions/operations.def b/src/language/expressions/operations.def index bdb6ed2b..207551b7 100644 --- a/src/language/expressions/operations.def +++ b/src/language/expressions/operations.def @@ -585,9 +585,9 @@ function NUMBER (string s, ni_format f) if (s.length > f->w) s.length = f->w; - error = data_in (s, LEGACY_NATIVE, f->type, &out, 0, NULL); + error = data_in (s, C_ENCODING, f->type, &out, 0, NULL); if (error == NULL) - data_in_imply_decimals (s, LEGACY_NATIVE, f->type, f->d, &out); + data_in_imply_decimals (s, C_ENCODING, f->type, f->d, &out); else { msg (SE, "Cannot parse `%.*s' as format %s: %s", @@ -607,7 +607,7 @@ absorb_miss string function STRING (x, no_format f) v.f = x; assert (!fmt_is_string (f->type)); - s = data_out (&v, LEGACY_NATIVE, f); + s = data_out (&v, C_ENCODING, f); dst = alloc_string (e, strlen (s)); strcpy (dst.string, s); free (s); diff --git a/src/language/lexer/value-parser.c b/src/language/lexer/value-parser.c index 51addbbe..649bbf24 100644 --- a/src/language/lexer/value-parser.c +++ b/src/language/lexer/value-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2009, 2010, 2011 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 @@ -25,6 +25,7 @@ #include "data/value.h" #include "language/lexer/lexer.h" #include "libpspp/cast.h" +#include "libpspp/i18n.h" #include "libpspp/message.h" #include "libpspp/str.h" @@ -106,8 +107,7 @@ parse_number (struct lexer *lexer, double *x, const enum fmt_type *format) assert (fmt_get_category (*format) != FMT_CAT_STRING); - if (!data_in_msg (lex_tokss (lexer), LEGACY_NATIVE, - *format, &v, 0, NULL)) + if (!data_in_msg (lex_tokss (lexer), C_ENCODING, *format, &v, 0, NULL)) return false; lex_get (lexer); diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index 236b4983..62cf387e 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2011 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 @@ -34,6 +34,7 @@ #include "libpspp/assertion.h" #include "libpspp/cast.h" #include "libpspp/compiler.h" +#include "libpspp/i18n.h" #include "libpspp/message.h" #include "libpspp/pool.h" #include "libpspp/str.h" @@ -632,7 +633,7 @@ find_src_string (struct recode_trns *trns, const uint8_t *value, char *error; error = data_in (ss_buffer (CHAR_CAST_BUG (char *, value), width), - LEGACY_NATIVE, FMT_F, &uv, 0, encoding); + C_ENCODING, FMT_F, &uv, 0, encoding); match = error == NULL; free (error); diff --git a/src/libpspp/i18n.h b/src/libpspp/i18n.h index f1d4d4a2..e016eab4 100644 --- a/src/libpspp/i18n.h +++ b/src/libpspp/i18n.h @@ -24,6 +24,11 @@ void i18n_init (void); #define UTF8 "UTF-8" +/* The encoding of literal strings in PSPP source code, as seen at execution + time. In fact this is likely to be some extended ASCII encoding, such as + UTF-8 or ISO-8859-1, but ASCII is adequate for our purposes. */ +#define C_ENCODING "ASCII" + struct pool; char recode_byte (const char *to, const char *from, char); diff --git a/src/libpspp/legacy-encoding.c b/src/libpspp/legacy-encoding.c index 18a62197..bbbf8a27 100644 --- a/src/libpspp/legacy-encoding.c +++ b/src/libpspp/legacy-encoding.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2011 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 @@ -24,7 +24,7 @@ char legacy_to_native (const char *from, char c) { char x; - char *s = recode_string (LEGACY_NATIVE, from, &c, 1); + char *s = recode_string (C_ENCODING, from, &c, 1); x = s[0]; free (s); return x; @@ -34,7 +34,7 @@ char legacy_from_native (const char *to, char c) { char x; - char *s = recode_string (to, LEGACY_NATIVE, &c, 1); + char *s = recode_string (to, C_ENCODING, &c, 1); x = s[0]; free (s); return x; diff --git a/src/libpspp/legacy-encoding.h b/src/libpspp/legacy-encoding.h index c6ae0ab4..560cbf87 100644 --- a/src/libpspp/legacy-encoding.h +++ b/src/libpspp/legacy-encoding.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2011 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 @@ -19,16 +19,7 @@ #include -#if 'A' == 0x41 -#define LEGACY_NATIVE "ASCII" -#elif 'A' == 0xc1 -#define LEGACY_NATIVE "EBCDIC-US" -#else -#error Cannot detect native character set. -#endif - 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 */ diff --git a/src/output/tab.c b/src/output/tab.c index e4ff158c..fd468557 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011 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 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -416,7 +417,7 @@ tab_fixed (struct tab_table *table, int c, int r, unsigned char opt, #endif double_value.f = val; - s = data_out_pool (&double_value, LEGACY_NATIVE, &f, table->container); + s = data_out_pool (&double_value, C_ENCODING, &f, table->container); table->cc[c + r * table->cf] = s + strspn (s, " "); table->ct[c + r * table->cf] = opt; @@ -458,7 +459,7 @@ tab_double (struct tab_table *table, int c, int r, unsigned char opt, #endif double_value.f = val; - s = data_out_pool (&double_value, LEGACY_NATIVE, fmt, table->container); + s = data_out_pool (&double_value, C_ENCODING, fmt, table->container); table->cc[c + r * table->cf] = s + strspn (s, " "); table->ct[c + r * table->cf] = opt; } diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index 298fd18d..e5c48fdb 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -32,6 +32,7 @@ #include "language/data-io/data-parser.h" #include "language/lexer/lexer.h" #include "libpspp/assertion.h" +#include "libpspp/i18n.h" #include "libpspp/message.h" #include "ui/gui/checkbox-treeview.h" #include "ui/gui/descriptives-dialog.h" @@ -1768,8 +1769,7 @@ parse_field (struct import_assistant *ia, { char *error; - error = data_in (field, LEGACY_NATIVE, in->type, &val, - var_get_width (var), + error = data_in (field, C_ENCODING, in->type, &val, var_get_width (var), dict_get_encoding (ia->formats.dict)); if (error != NULL) { diff --git a/src/ui/syntax-gen.c b/src/ui/syntax-gen.c index 9221eae4..d829d80a 100644 --- a/src/ui/syntax-gen.c +++ b/src/ui/syntax-gen.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2010 Free Software Foundation, Inc. + Copyright (C) 2008, 2010, 2011 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 @@ -27,6 +27,7 @@ #include "data/value.h" #include "libpspp/assertion.h" #include "libpspp/cast.h" +#include "libpspp/i18n.h" #include "libpspp/message.h" #include "libpspp/str.h" @@ -156,8 +157,7 @@ syntax_gen_number (struct string *output, s = data_out (&v_in, "FIXME", format); /* FIXME: UTF8 encoded strings will fail here */ - error = data_in (ss_cstr (s), LEGACY_NATIVE, - format->type, &v_out, 0, NULL); + error = data_in (ss_cstr (s), C_ENCODING, format->type, &v_out, 0, NULL); ok = error == NULL; free (error);