]> granicus.if.org Git - php/commitdiff
- Add support for CP850 encoding (patch by Denis Giffeler)
authorMoriyoshi Koizumi <moriyoshi@php.net>
Wed, 18 Mar 2009 17:44:25 +0000 (17:44 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Wed, 18 Mar 2009 17:44:25 +0000 (17:44 +0000)
14 files changed:
NEWS
Zend/zend_multibyte.c
ext/mbstring/config.m4
ext/mbstring/libmbfl/filters/Makefile.am
ext/mbstring/libmbfl/filters/Makefile.bcc32
ext/mbstring/libmbfl/filters/mbfilter_cp850.c [new file with mode: 0644]
ext/mbstring/libmbfl/filters/mbfilter_cp850.h [new file with mode: 0644]
ext/mbstring/libmbfl/filters/unicode_table_cp850.h [new file with mode: 0644]
ext/mbstring/libmbfl/mbfl/mbfl_consts.h
ext/mbstring/libmbfl/mbfl/mbfl_convert.c
ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
ext/mbstring/libmbfl/mbfl/mbfl_encoding.h
ext/mbstring/libmbfl/mbfl/mbfl_ident.c
ext/mbstring/mbstring.dsp

diff --git a/NEWS b/NEWS
index 790ff0a501e43a9ad2351b1c09251cad4436b2c5..35afa63d8786baf6bda2195c72edd3592634dcf0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ PHP                                                                        NEWS
 - Added LIBXML_LOADED_VERSION constant (libxml2 version currently used). (Rob)
 - Added JSON_FORCE_OBJECT flag to json_encode(). (Scott, Richard Quadling)
 
+- Added support for CP850 encoding in mbstring extension.
+  (Denis Giffeler, Moriyoshi)
+
 - Fixed bug #47678 (Allow loadExtension to be disabled in SQLite3). (Scott)
 - Fixed bug #47664 (get_class returns NULL instead of FALSE). (Dmitry)
 - Fixed bug #47593 (interface_exists() returns false when using absolute 
index a057c6995a4aaf10dfb8bb2f6dd22e3019a041b3..2f39c172efe91cc28524497df4420e4a008d6277 100644 (file)
@@ -453,6 +453,15 @@ static zend_encoding encoding_armscii8 = {
        1
 };
 
+static const char *cp850_aliases[] = {"IBM850", NULL};
+static zend_encoding encoding_cp850 = {
+       NULL,
+       NULL,
+       "CP850",
+       (const char *(*)[])&cp850_aliases,
+       1
+};
+
 static zend_encoding *zend_encoding_table[] = {
        &encoding_ucs4,
        &encoding_ucs4be,
@@ -501,6 +510,7 @@ static zend_encoding *zend_encoding_table[] = {
        &encoding_koi8u,
        &encoding_armscii8,
        &encoding_cp1254,
+       &encoding_cp850,
        NULL
 };
 
index 0336121c2075da29d4b20d8965e41b2e0dacc512..6c79ba39736fb999f6e7f3afa9d876d8e0b97703 100644 (file)
@@ -271,6 +271,7 @@ AC_DEFUN([PHP_MBSTRING_SETUP_LIBMBFL], [
      libmbfl/filters/mbfilter_utf8.c
      libmbfl/filters/mbfilter_uuencode.c
      libmbfl/filters/mbfilter_koi8u.c
+     libmbfl/filters/mbfilter_cp850.c
      libmbfl/mbfl/mbfilter.c
      libmbfl/mbfl/mbfilter_8bit.c
      libmbfl/mbfl/mbfilter_pass.c
index 8fa046f923697a296cda99a22b7ba1684404a62c..802af4e61db735ab4d31d333c730c280e5d00b5a 100644 (file)
@@ -52,6 +52,7 @@ libmbfl_filters_la_SOURCES=mbfilter_cp936.c \
        mbfilter_koi8r.c \
        mbfilter_koi8u.c \
        mbfilter_armscii8.c \
+       mbfilter_cp850.c \
        html_entities.c \
        cp932_table.h \
        html_entities.h \
@@ -105,6 +106,7 @@ libmbfl_filters_la_SOURCES=mbfilter_cp936.c \
        mbfilter_utf8.h \
        mbfilter_uuencode.h \
        mbfilter_cp51932.h \
+       mbfilter_cp850.h \
        unicode_prop.h \
        unicode_table_big5.h \
        unicode_table_cns11643.h \
@@ -131,6 +133,7 @@ libmbfl_filters_la_SOURCES=mbfilter_cp936.c \
        unicode_table_koi8r.h \
        unicode_table_koi8u.h \
        unicode_table_armscii8.h \
+       unicode_table_cp850.h \
        unicode_table_uhc.h
 
 mbfilter_iso8859_2.c: unicode_table_iso8859_2.h
index 302436f11a31cdd344807430e931b0817e422549..841c09632a4888587b083e3d1656298acacffdeb 100644 (file)
@@ -49,7 +49,8 @@ OBJS=mbfilter_cp936.obj \
        mbfilter_koi8r.obj \
        mbfilter_koi8u.obj \
        html_entities.obj \
-       mbfilter_armscii8.obj
+       mbfilter_armscii8.obj \
+       mbfilter_cp850.obj
 
 all: $(OBJS)
 
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp850.c b/ext/mbstring/libmbfl/filters/mbfilter_cp850.c
new file mode 100644 (file)
index 0000000..5388c04
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * "streamable kanji code filter and converter"
+ * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
+ *
+ * LICENSE NOTICES
+ *
+ * This file is part of "streamable kanji code filter and converter",
+ * which is distributed under the terms of GNU Lesser General Public 
+ * License (version 2) as published by the Free Software Foundation.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with "streamable kanji code filter and converter";
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA  02111-1307  USA
+ *
+ * The author of this part: Den V. Tsopa <tdv@edisoft.ru>
+ * Adaption for CP850: D. Giffeler <dg@artegic.de>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mbfilter.h"
+#include "mbfilter_cp850.h"
+#include "unicode_table_cp850.h"
+
+static int mbfl_filt_ident_cp850(int c, mbfl_identify_filter *filter);
+
+static const char *mbfl_encoding_cp850_aliases[] = {"CP850", "CP-850", "IBM-850", NULL};
+
+const mbfl_encoding mbfl_encoding_cp850 = {
+       mbfl_no_encoding_cp850,
+       "CP850",
+       "CP850",
+       (const char *(*)[])&mbfl_encoding_cp850_aliases,
+       NULL,
+       MBFL_ENCTYPE_SBCS
+};
+
+const struct mbfl_identify_vtbl vtbl_identify_cp850 = {
+       mbfl_no_encoding_cp850,
+       mbfl_filt_ident_common_ctor,
+       mbfl_filt_ident_common_dtor,
+       mbfl_filt_ident_cp850
+};
+
+const struct mbfl_convert_vtbl vtbl_wchar_cp850 = {
+       mbfl_no_encoding_wchar,
+       mbfl_no_encoding_cp850,
+       mbfl_filt_conv_common_ctor,
+       mbfl_filt_conv_common_dtor,
+       mbfl_filt_conv_wchar_cp850,
+       mbfl_filt_conv_common_flush
+};
+
+const struct mbfl_convert_vtbl vtbl_cp850_wchar = {
+       mbfl_no_encoding_cp850,
+       mbfl_no_encoding_wchar,
+       mbfl_filt_conv_common_ctor,
+       mbfl_filt_conv_common_dtor,
+       mbfl_filt_conv_cp850_wchar,
+       mbfl_filt_conv_common_flush
+};
+
+#define CK(statement)  do { if ((statement) < 0) return (-1); } while (0)
+
+/*
+ * cp850 => wchar
+ */
+int
+mbfl_filt_conv_cp850_wchar(int c, mbfl_convert_filter *filter)
+{
+       int s;
+
+       if (c >= 0 && c < cp850_ucs_table_min) {
+               s = c;
+       } else if (c >= cp850_ucs_table_min && c < 0x100) {
+               s = cp850_ucs_table[c - cp850_ucs_table_min];
+               if (s <= 0) {
+                       s = c;
+                       s &= MBFL_WCSPLANE_MASK;
+                       s |= MBFL_WCSPLANE_CP850;
+               }
+       } else {
+               s = c;
+               s &= MBFL_WCSGROUP_MASK;
+               s |= MBFL_WCSGROUP_THROUGH;
+       }
+
+       CK((*filter->output_function)(s, filter->data));
+
+       return c;
+}
+
+/*
+ * wchar => cp850
+ */
+int
+mbfl_filt_conv_wchar_cp850(int c, mbfl_convert_filter *filter)
+{
+       int s, n;
+
+       if (c < 0x80) {
+               s = c;
+       } else {
+               s = -1;
+               n = cp850_ucs_table_len-1;
+               while (n >= 0) {
+                       if (c == cp850_ucs_table[n]) {
+                               s = cp850_ucs_table_min + n;
+                               break;
+                       }
+                       n--;
+               }
+               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_CP850) {
+                       s = c & MBFL_WCSPLANE_MASK;
+               }
+       }
+
+       if (s >= 0) {
+               CK((*filter->output_function)(s, filter->data));
+       } else {
+               if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
+                       CK(mbfl_filt_conv_illegal_output(c, filter));
+               }
+       }
+
+       return c;
+}
+
+static int mbfl_filt_ident_cp850(int c, mbfl_identify_filter *filter)
+{
+       if (c >= 0x80 && c < 0xff)
+               filter->flag = 0;
+       else
+               filter->flag = 1; /* not it */
+       return c;       
+}
+
+
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp850.h b/ext/mbstring/libmbfl/filters/mbfilter_cp850.h
new file mode 100644 (file)
index 0000000..a1e0f9c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * "streamable kanji code filter and converter"
+ * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
+ *
+ * LICENSE NOTICES
+ *
+ * This file is part of "streamable kanji code filter and converter",
+ * which is distributed under the terms of GNU Lesser General Public 
+ * License (version 2) as published by the Free Software Foundation.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with "streamable kanji code filter and converter";
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA  02111-1307  USA
+ *
+ * The author of this part: Den V. Tsopa <tdv@edisoft.ru>
+ * Adaption for CP850: D. Giffeler <dg@artegic.de>
+ *
+ */
+
+#ifndef MBFL_MBFILTER_CP850_H
+#define MBFL_MBFILTER_CP850_H
+
+extern const mbfl_encoding mbfl_encoding_cp850;
+extern const struct mbfl_identify_vtbl vtbl_identify_cp850;
+extern const struct mbfl_convert_vtbl vtbl_wchar_cp850;
+extern const struct mbfl_convert_vtbl vtbl_cp850_wchar;
+
+int mbfl_filt_conv_cp850_wchar(int c, mbfl_convert_filter *filter);
+int mbfl_filt_conv_wchar_cp850(int c, mbfl_convert_filter *filter);
+
+#endif /* MBFL_MBFILTER_CP850_H */
diff --git a/ext/mbstring/libmbfl/filters/unicode_table_cp850.h b/ext/mbstring/libmbfl/filters/unicode_table_cp850.h
new file mode 100644 (file)
index 0000000..6c60ae0
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * "streamable kanji code filter and converter"
+ * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
+ *
+ * LICENSE NOTICES
+ *
+ * This file is part of "streamable kanji code filter and converter",
+ * which is distributed under the terms of GNU Lesser General Public 
+ * License (version 2) as published by the Free Software Foundation.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with "streamable kanji code filter and converter";
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA  02111-1307  USA
+ *
+ * The author of this part: Den V. Tsopa <tdv@edisoft.ru>
+ * Adaption for CP850: D. Giffeler <dg@artegic.de>
+ *
+ */
+
+#ifndef UNICODE_TABLE_CP850_H
+#define UNICODE_TABLE_CP850_H
+
+/* cp850_DOS to Unicode table */
+static const unsigned short cp850_ucs_table[] = {
+  0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7
+, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5
+, 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9
+, 0x00ff, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x00d7, 0x0192
+, 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba
+, 0x00bf, 0x00ae, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb
+, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00c1, 0x00c2, 0x00c0
+, 0x00a9, 0x2563, 0x2551, 0x2557, 0x255d, 0x00a2, 0x00a5, 0x2510
+, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x00e3, 0x00c3
+, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x00a4
+, 0x00f0, 0x00d0, 0x00ca, 0x00cb, 0x00c8, 0x0131, 0x00cd, 0x00ce
+, 0x00cf, 0x2518, 0x250c, 0x2588, 0x2584, 0x00a6, 0x00cc, 0x2580
+, 0x00d3, 0x00df, 0x00d4, 0x00d2, 0x00f5, 0x00d5, 0x00b5, 0x00fe
+, 0x00de, 0x00da, 0x00db, 0x00d9, 0x00fd, 0x00dd, 0x00af, 0x00b4
+, 0x00ad, 0x00b1, 0x2017, 0x00be, 0x00b6, 0x00a7, 0x00f7, 0x00b8
+, 0x00b0, 0x00a8, 0x00b7, 0x00b9, 0x00b3, 0x00b2, 0x25a0, 0x00a0
+};
+static const int cp850_ucs_table_min = 0x80;
+static const int cp850_ucs_table_len = (sizeof (cp850_ucs_table) / sizeof (unsigned short));
+static const int cp850_ucs_table_max = 0x80 + (sizeof (cp850_ucs_table) / sizeof (unsigned short));
+
+#endif /* UNICODE_TABLE_CP850_H */
index afb5680d68067b9bf8341023450e962080b2e19e..b6c0bb2d871a6d03453f00d58e9b994f77fab70c 100644 (file)
@@ -79,6 +79,7 @@
 #define MBFL_WCSPLANE_ARMSCII8                 0x70fb0000
 #define MBFL_WCSPLANE_KOI8U            0x70fc0000
 #define MBFL_WCSPLANE_CP1254           0x70fd0000              /*  00h - FFh */
+#define MBFL_WCSPLANE_CP850            0x70fe0000              /*  00h - FFh */
 #define MBFL_WCSGROUP_MASK                0xffffff
 #define MBFL_WCSGROUP_UCS4MAX          0x70000000
 #define MBFL_WCSGROUP_WCHARMAX         0x78000000
index 63003d0f0a661fb80e97a7355ec0aaf79b1f51b7..725a674b390ac960cd6af3db88e12d24d3983ae7 100644 (file)
@@ -93,6 +93,7 @@
 #include "filters/mbfilter_ucs2.h"
 #include "filters/mbfilter_htmlent.h"
 #include "filters/mbfilter_armscii8.h"
+#include "filters/mbfilter_cp850.h"
 
 static void mbfl_convert_filter_reset_vtbl(mbfl_convert_filter *filter);
 
@@ -223,6 +224,8 @@ const struct mbfl_convert_vtbl *mbfl_convert_filter_list[] = {
        &vtbl_wchar_byte2le,
        &vtbl_armscii8_wchar,
        &vtbl_wchar_armscii8,
+       &vtbl_cp850_wchar,
+       &vtbl_wchar_cp850,
        &vtbl_pass,
        NULL
 };
index 51cea89a909d1a5457872d7dcf026b60ed8002be..76956f05305270a03b33c5836f97a7661a4bd336 100644 (file)
 #include "filters/mbfilter_ucs2.h"
 #include "filters/mbfilter_htmlent.h"
 #include "filters/mbfilter_armscii8.h"
+#include "filters/mbfilter_cp850.h"
 
 #ifndef HAVE_STRCASECMP
 #ifdef HAVE_STRICMP
@@ -186,6 +187,7 @@ static const mbfl_encoding *mbfl_encoding_ptr_list[] = {
        &mbfl_encoding_koi8r,
        &mbfl_encoding_koi8u,
        &mbfl_encoding_armscii8,
+       &mbfl_encoding_cp850,
        NULL
 };
 
index b3b1750463b06e2ff910054ef234c4dbd66147cb..2599e1107e75f8017dc983865c5ba80d4fa23236 100644 (file)
@@ -103,6 +103,7 @@ enum mbfl_no_encoding {
        mbfl_no_encoding_koi8u,
        mbfl_no_encoding_8859_16,
        mbfl_no_encoding_armscii8,
+       mbfl_no_encoding_cp850,
        mbfl_no_encoding_charset_max
 };
 
index bcfd4b2accc61f85789a205509645a284b997cf0..4f3bd5c58dfddf59c6a3b24dc90f8f0b4d787d1e 100644 (file)
@@ -92,6 +92,7 @@
 #include "filters/mbfilter_ucs2.h"
 #include "filters/mbfilter_htmlent.h"
 #include "filters/mbfilter_armscii8.h"
+#include "filters/mbfilter_cp850.h"
 
 static const struct mbfl_identify_vtbl vtbl_identify_false = {
        mbfl_no_encoding_pass,
@@ -140,6 +141,7 @@ static const struct mbfl_identify_vtbl *mbfl_identify_filter_list[] = {
        &vtbl_identify_8859_14,
        &vtbl_identify_8859_15,
        &vtbl_identify_armscii8,
+       &vtbl_identify_cp850,
        &vtbl_identify_false,
        NULL
 };
index 629b0bd4d94c7973eedb6921948196e0694eaf31..2e050c6d2018b4d06a2af9519d738d6c1ddaa319 100644 (file)
@@ -374,6 +374,10 @@ SOURCE=.\libmbfl\filters\mbfilter_armscii8.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\libmbfl\filters\mbfilter_cp850.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\libmbfl\mbfl\mbfilter_pass.c\r
 # End Source File\r
 # Begin Source File\r
@@ -687,6 +691,10 @@ SOURCE=.\libmbfl\filters\mbfilter_armscii8.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\libmbfl\filters\mbfilter_cp850.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\libmbfl\mbfl\mbfilter_pass.h\r
 # End Source File\r
 # Begin Source File\r
@@ -911,6 +919,10 @@ SOURCE=.\libmbfl\filters\unicode_table_armscii8.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\libmbfl\filters\unicode_table_cp850.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\libmbfl\filters\unicode_table_uhc.h\r
 # End Source File\r
 # End Group\r