Back to index

php5  5.3.10
mbfilter_byte2.c
Go to the documentation of this file.
00001 /*
00002  * "streamable kanji code filter and converter"
00003  * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
00004  *
00005  * LICENSE NOTICES
00006  *
00007  * This file is part of "streamable kanji code filter and converter",
00008  * which is distributed under the terms of GNU Lesser General Public 
00009  * License (version 2) as published by the Free Software Foundation.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with "streamable kanji code filter and converter";
00018  * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
00019  * Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * The author of this file:
00022  *
00023  */
00024 /*
00025  * The source code included in this files was separated from mbfilter.c
00026  * by Moriyoshi Koizumi <moriyoshi@php.net> on 4 Dec 2002. The file
00027  * mbfilter.c is included in this package .
00028  *
00029  */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include "config.h"
00033 #endif
00034 
00035 #include "mbfilter.h"
00036 #include "mbfilter_byte2.h"
00037 
00038 const mbfl_encoding mbfl_encoding_byte2be = {
00039        mbfl_no_encoding_byte2be,
00040        "byte2be",
00041        NULL,
00042        NULL,
00043        NULL,
00044        MBFL_ENCTYPE_SBCS
00045 };
00046 
00047 const mbfl_encoding mbfl_encoding_byte2le = {
00048        mbfl_no_encoding_byte2le,
00049        "byte2le",
00050        NULL,
00051        NULL,
00052        NULL,
00053        MBFL_ENCTYPE_SBCS
00054 };
00055 
00056 const struct mbfl_convert_vtbl vtbl_byte2be_wchar = {
00057        mbfl_no_encoding_byte2be,
00058        mbfl_no_encoding_wchar,
00059        mbfl_filt_conv_common_ctor,
00060        mbfl_filt_conv_common_dtor,
00061        mbfl_filt_conv_byte2be_wchar,
00062        mbfl_filt_conv_common_flush
00063 };
00064 
00065 const struct mbfl_convert_vtbl vtbl_wchar_byte2be = {
00066        mbfl_no_encoding_wchar,
00067        mbfl_no_encoding_byte2be,
00068        mbfl_filt_conv_common_ctor,
00069        mbfl_filt_conv_common_dtor,
00070        mbfl_filt_conv_wchar_byte2be,
00071        mbfl_filt_conv_common_flush };
00072 
00073 const struct mbfl_convert_vtbl vtbl_byte2le_wchar = {
00074        mbfl_no_encoding_byte2le,
00075        mbfl_no_encoding_wchar,
00076        mbfl_filt_conv_common_ctor,
00077        mbfl_filt_conv_common_dtor,
00078        mbfl_filt_conv_byte2le_wchar,
00079        mbfl_filt_conv_common_flush };
00080 
00081 const struct mbfl_convert_vtbl vtbl_wchar_byte2le = {
00082        mbfl_no_encoding_wchar,
00083        mbfl_no_encoding_byte2le,
00084        mbfl_filt_conv_common_ctor,
00085        mbfl_filt_conv_common_dtor,
00086        mbfl_filt_conv_wchar_byte2le,
00087        mbfl_filt_conv_common_flush };
00088 
00089 #define CK(statement)       do { if ((statement) < 0) return (-1); } while (0)
00090 
00091 int mbfl_filt_conv_byte2be_wchar(int c, mbfl_convert_filter *filter)
00092 {
00093        int n;
00094 
00095        if (filter->status == 0) {
00096               filter->status = 1;
00097               n = (c & 0xff) << 8;
00098               filter->cache = n;
00099        } else {
00100               filter->status = 0;
00101               n = (c & 0xff) | filter->cache;
00102               CK((*filter->output_function)(n, filter->data));
00103        }
00104        return c;
00105 }
00106 
00107 int mbfl_filt_conv_wchar_byte2be(int c, mbfl_convert_filter *filter)
00108 {
00109        CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
00110        CK((*filter->output_function)(c & 0xff, filter->data));
00111        return c;
00112 }
00113 
00114 int mbfl_filt_conv_byte2le_wchar(int c, mbfl_convert_filter *filter)
00115 {
00116        int n;
00117 
00118        if (filter->status == 0) {
00119               filter->status = 1;
00120               n = c & 0xff;
00121               filter->cache = n;
00122        } else {
00123               filter->status = 0;
00124               n = ((c & 0xff) << 8) | filter->cache;
00125               CK((*filter->output_function)(n, filter->data));
00126        }
00127        return c;
00128 }
00129 
00130 int mbfl_filt_conv_wchar_byte2le(int c, mbfl_convert_filter *filter)
00131 {
00132        CK((*filter->output_function)(c & 0xff, filter->data));
00133        CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
00134        return c;
00135 }
00136 
00137