Back to index

php5  5.3.10
mbfilter_ascii.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_ascii.h"
00037 
00038 static int mbfl_filt_ident_ascii(int c, mbfl_identify_filter *filter);
00039 
00040 static const char *mbfl_encoding_ascii_aliases[] = {"ANSI_X3.4-1968", "iso-ir-6", "ANSI_X3.4-1986", "ISO_646.irv:1991", "US-ASCII", "ISO646-US", "us", "IBM367", "cp367", "csASCII", NULL};
00041 
00042 const mbfl_encoding mbfl_encoding_ascii = {
00043        mbfl_no_encoding_ascii,
00044        "ASCII",
00045        "US-ASCII", /* preferred MIME name */
00046        (const char *(*)[])&mbfl_encoding_ascii_aliases,
00047        NULL,
00048        MBFL_ENCTYPE_SBCS
00049 };
00050 
00051 const struct mbfl_identify_vtbl vtbl_identify_ascii = {
00052        mbfl_no_encoding_ascii,
00053        mbfl_filt_ident_common_ctor,
00054        mbfl_filt_ident_common_dtor,
00055        mbfl_filt_ident_ascii
00056 };
00057 
00058 const struct mbfl_convert_vtbl vtbl_ascii_wchar = {
00059        mbfl_no_encoding_ascii,
00060        mbfl_no_encoding_wchar,
00061        mbfl_filt_conv_common_ctor,
00062        mbfl_filt_conv_common_dtor,
00063        mbfl_filt_conv_ascii_wchar,
00064        mbfl_filt_conv_common_flush
00065 };
00066 
00067 const struct mbfl_convert_vtbl vtbl_wchar_ascii = {
00068        mbfl_no_encoding_wchar,
00069        mbfl_no_encoding_ascii,
00070        mbfl_filt_conv_common_ctor,
00071        mbfl_filt_conv_common_dtor,
00072        mbfl_filt_conv_wchar_ascii,
00073        mbfl_filt_conv_common_flush
00074 };
00075 
00076 #define CK(statement)       do { if ((statement) < 0) return (-1); } while (0)
00077 
00078 /*
00079  * ASCII => wchar
00080  */
00081 int mbfl_filt_conv_ascii_wchar(int c, mbfl_convert_filter *filter)
00082 {
00083        return (*filter->output_function)(c, filter->data);
00084 }
00085 
00086 
00087 /*
00088  * wchar => ASCII
00089  */
00090 int mbfl_filt_conv_wchar_ascii(int c, mbfl_convert_filter *filter)
00091 {
00092        if (c >= 0 && c < 0x80) {
00093               CK((*filter->output_function)(c, filter->data));
00094        } else {
00095               if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
00096                      CK(mbfl_filt_conv_illegal_output(c, filter));
00097               }
00098        }
00099 
00100        return c;
00101 }
00102 
00103 static int mbfl_filt_ident_ascii(int c, mbfl_identify_filter *filter)
00104 {
00105        if (c >= 0x20 && c < 0x80) {
00106               ;
00107        } else if (c == 0x0d || c == 0x0a || c == 0x09 || c == 0) {    /* CR or LF or HTAB or null */
00108               ;
00109        } else {
00110               filter->flag = 1;
00111        }
00112 
00113        return c;
00114 }