Back to index

php5  5.3.10
Defines | Functions | Variables
mbfilter_hz.c File Reference
#include "mbfilter.h"
#include "mbfilter_hz.h"
#include "unicode_table_cp936.h"

Go to the source code of this file.

Defines

#define CK(statement)   do { if ((statement) < 0) return (-1); } while (0)

Functions

static int mbfl_filt_ident_hz (int c, mbfl_identify_filter *filter)
int mbfl_filt_conv_hz_wchar (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_wchar_hz (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_any_hz_flush (mbfl_convert_filter *filter)

Variables

const mbfl_encoding mbfl_encoding_hz

Define Documentation

#define CK (   statement)    do { if ((statement) < 0) return (-1); } while (0)

Definition at line 75 of file mbfilter_hz.c.


Function Documentation

int mbfl_filt_conv_any_hz_flush ( mbfl_convert_filter *  filter)

Definition at line 213 of file mbfilter_hz.c.

{
       /* back to latin */
       if ((filter->status & 0xff00) != 0) {
              CK((*filter->output_function)(0x7e, filter->data));            /* ~ */
              CK((*filter->output_function)(0x7d, filter->data));            /* '{' */
       }
       filter->status &= 0xff;
       return 0;
}
int mbfl_filt_conv_hz_wchar ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 81 of file mbfilter_hz.c.

{
       int c1, s, w;

       switch (filter->status & 0xf) {
/*     case 0x00:     ASCII */
/*     case 0x10:     GB2312 */
       case 0:
              if (c == 0x7e) {
                     filter->status += 2;
              } else if (filter->status == 0x10 && c > 0x20 && c < 0x7f) {   /* DBCS first char */
                     filter->cache = c;
                     filter->status += 1;
              } else if (c >= 0 && c < 0x80) {          /* latin, CTLs */
                     CK((*filter->output_function)(c, filter->data));
              } else {
                     w = c & MBFL_WCSGROUP_MASK;
                     w |= MBFL_WCSGROUP_THROUGH;
                     CK((*filter->output_function)(w, filter->data));
              }
              break;

/*     case 0x11:     GB2312 second char */
       case 1:
              filter->status &= ~0xf;
              c1 = filter->cache;
              if (c1 > 0x20 && c1 < 0x7f && c > 0x20 && c < 0x7f) {
                     s = (c1 - 1)*192 + c + 0x40; /* GB2312 */
                     if (s >= 0 && s < cp936_ucs_table_size) {
                            w = cp936_ucs_table[s];
                     } else {
                            w = 0;
                     }
                     if (w <= 0) {
                            w = (c1 << 8) | c;
                            w &= MBFL_WCSPLANE_MASK;
                            w |= MBFL_WCSPLANE_GB2312;
                     }
                     CK((*filter->output_function)(w, filter->data));
              } else if ((c >= 0 && c < 0x21) || c == 0x7f) {         /* CTLs */
                     CK((*filter->output_function)(c, filter->data));
              } else {
                     w = (c1 << 8) | c;
                     w &= MBFL_WCSGROUP_MASK;
                     w |= MBFL_WCSGROUP_THROUGH;
                     CK((*filter->output_function)(w, filter->data));
              }
              break;

       /* '~' */
       case 2:
              if (c == 0x7d) {            /* '}' */
                     filter->status = 0x0;
              } else if (c == 0x7b) {            /* '{' */
                     filter->status = 0x10;
              } else if (c == 0x7e) { /* '~' */
                     filter->status = 0x0;
                     CK((*filter->output_function)(0x007e, filter->data));
              }
              break;

       default:
              filter->status = 0;
              break;
       }

       return c;
}
int mbfl_filt_conv_wchar_hz ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 154 of file mbfilter_hz.c.

{
       int s;

       s = 0;
       if (c >= ucs_a1_cp936_table_min && c < ucs_a1_cp936_table_max) {
              s = ucs_a1_cp936_table[c - ucs_a1_cp936_table_min];
       } else if (c >= ucs_a2_cp936_table_min && c < ucs_a2_cp936_table_max) {
              s = ucs_a2_cp936_table[c - ucs_a2_cp936_table_min];
       } else if (c >= ucs_a3_cp936_table_min && c < ucs_a3_cp936_table_max) {
              s = ucs_a3_cp936_table[c - ucs_a3_cp936_table_min];
       } else if (c >= ucs_i_cp936_table_min && c < ucs_i_cp936_table_max) {
              s = ucs_i_cp936_table[c - ucs_i_cp936_table_min];
       } else if (c >= ucs_hff_cp936_table_min && c < ucs_hff_cp936_table_max) {
              s = ucs_hff_cp936_table[c - ucs_hff_cp936_table_min];
       }
       if (s & 0x8000) {
              s -= 0x8080;
       }

       if (s <= 0) {
              if (c == 0) {
                     s = 0;
              } else if (s <= 0) {
                     s = -1;
              }
       } else if ((s >= 0x80 && s < 0x2121) || (s > 0x8080)) {
              s = -1;
       }
       if (s >= 0) {
              if (s < 0x80) { /* ASCII */
                     if ((filter->status & 0xff00) != 0) {
                            CK((*filter->output_function)(0x7e, filter->data));            /* '~' */
                            CK((*filter->output_function)(0x7d, filter->data));            /* '}' */
                     }
                     filter->status = 0;
                     if (s == 0x7e){
                            CK((*filter->output_function)(0x7e, filter->data));
                     }
                     CK((*filter->output_function)(s, filter->data));
              } else { /* GB 2312-80 */
                     if ((filter->status & 0xff00) != 0x200) {
                            CK((*filter->output_function)(0x7e, filter->data));            /* '~' */
                            CK((*filter->output_function)(0x7b, filter->data));            /* '{' */
                     }
                     filter->status = 0x200;
                     CK((*filter->output_function)((s >> 8) & 0x7f, filter->data));
                     CK((*filter->output_function)(s & 0x7f, filter->data));
              }
       } else {
              if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
                     CK(mbfl_filt_conv_illegal_output(c, filter));
              }
       }

       return c;
}

Here is the call graph for this function:

static int mbfl_filt_ident_hz ( int  c,
mbfl_identify_filter *  filter 
) [static]

Definition at line 224 of file mbfilter_hz.c.

{
       switch (filter->status & 0xf) {
/*     case 0x00:     ASCII */
/*     case 0x10:     GB2312 */
       case 0:
              if (c == 0x7e) {
                     filter->status += 2;
              } else if (filter->status == 0x10 && c > 0x20 && c < 0x7f) {          /* DBCS first char */
                     filter->status += 1;
              } else if (c >= 0 && c < 0x80) {          /* latin, CTLs */
                     ;
              } else {
                     filter->flag = 1;    /* bad */
              }
              break;

/*     case 0x11:     GB2312 second char */
       case 1:
              filter->status &= ~0xf;
              if (c < 0x21 || c > 0x7e) {        /* bad */
                     filter->flag = 1;
              }
              break;

       case 2:
              if (c == 0x7d) {            /* '}' */
                     filter->status = 0;
              } else if (c == 0x7b) {            /* '{' */
                     filter->status = 0x10;
              } else if (c == 0x7e) {            /* '~' */
                     filter->status = 0;
              } else {
                     filter->flag = 1;    /* bad */
                     filter->status &= ~0xf;
              }
              break;

       default:
              filter->status = 0;
              break;
       }

       return c;
}

Variable Documentation

Initial value:

Definition at line 41 of file mbfilter_hz.c.