[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[formatting i18n 05/14] i18n: Introduce C_ENCODING as replacement for LE
From: |
Ben Pfaff |
Subject: |
[formatting i18n 05/14] i18n: Introduce C_ENCODING as replacement for LEGACY_NATIVE. |
Date: |
Sat, 19 Feb 2011 17:42:17 -0800 |
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.
---
src/data/data-in.c | 8 ++++----
src/data/data-out.c | 6 +++---
src/data/file-handle-def.c | 7 ++++---
src/language/data-io/print.c | 8 ++++----
src/language/expressions/helpers.h | 1 +
src/language/expressions/operations.def | 6 +++---
src/language/lexer/value-parser.c | 6 +++---
src/language/xforms/recode.c | 5 +++--
src/libpspp/i18n.h | 5 +++++
src/libpspp/legacy-encoding.c | 6 +++---
src/libpspp/legacy-encoding.h | 11 +----------
src/output/tab.c | 7 ++++---
src/ui/gui/text-data-import-dialog.c | 4 ++--
src/ui/syntax-gen.c | 6 +++---
14 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/src/data/data-in.c b/src/data/data-in.c
index 45ff609..03b25fe 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 94a6130..ca5fcec 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 d025ff6..2d69e25 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 <libpspp/compiler.h>
#include <libpspp/hmap.h>
+#include <libpspp/i18n.h>
#include <libpspp/ll.h>
#include <libpspp/message.h>
#include <libpspp/str.h>
@@ -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 ada59c3..a07ca2d 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 cb59c20..59be400 100644
--- a/src/language/expressions/helpers.h
+++ b/src/language/expressions/helpers.h
@@ -22,6 +22,7 @@
#include <data/vector.h>
#include <language/expressions/public.h>
#include <libpspp/compiler.h>
+#include <libpspp/i18n.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/str.h>
diff --git a/src/language/expressions/operations.def
b/src/language/expressions/operations.def
index bdb6ed2..207551b 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 51addbb..649bbf2 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 236b498..62cf387 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 f1d4d4a..e016eab 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 18a6219..bbbf8a2 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 c6ae0ab..560cbf8 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 <libpspp/compiler.h>
-#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 e4ff158..fd46855 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 <data/dictionary.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
+#include <libpspp/i18n.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <output/driver.h>
@@ -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 298fd18..e5c48fd 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 9221eae..d829d80 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);
--
1.7.2.3
- [formatting i18n 04/14] i18n: New function recode_byte()., (continued)
- [formatting i18n 04/14] i18n: New function recode_byte()., Ben Pfaff, 2011/02/19
- [formatting i18n 10/14] format: Count prefix and suffix width in terms of display columns., Ben Pfaff, 2011/02/19
- [formatting i18n 08/14] data-out: Make each converter responsible for storing null terminator., Ben Pfaff, 2011/02/19
- [formatting i18n 12/14] pool: Support NULL pool argument to pool_alloc_unaligned()., Ben Pfaff, 2011/02/19
- [formatting i18n 14/14] data-out: Add test for non-ASCII custom currency formats., Ben Pfaff, 2011/02/19
- [formatting i18n 11/14] data-out: Reorganize output_Z() to be more easily understood., Ben Pfaff, 2011/02/19
- [formatting i18n 02/14] CROSSTABS: Eliminate redundant data copying., Ben Pfaff, 2011/02/19
- [formatting i18n 06/14] legacy-encoding: Remove., Ben Pfaff, 2011/02/19
- [formatting i18n 07/14] format: Increase abstraction of fmt_number_style., Ben Pfaff, 2011/02/19
- [formatting i18n 09/14] format: Create a new "struct fmt_affix" for prefix and suffix strings., Ben Pfaff, 2011/02/19
- [formatting i18n 05/14] i18n: Introduce C_ENCODING as replacement for LEGACY_NATIVE.,
Ben Pfaff <=
- [formatting i18n 13/14] data-out: Optimize and fix some bad assumptions., Ben Pfaff, 2011/02/19
- Re: [formatting i18n 00/14] Fix i18n of formatted data, Ben Pfaff, 2011/02/23