w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

status.c (3967B)


      1 
      2 #include <string.h>
      3 #include <gc.h>
      4 #define New_N(type,n) ((type*)GC_MALLOC((n)*sizeof(type)))
      5 
      6 #include "wc.h"
      7 #ifdef USE_UNICODE
      8 #include "ucs.h"
      9 #endif
     10 
     11 wc_option WcOption = {
     12     WC_OPT_DETECT_ON,	/* auto_detect */
     13     WC_TRUE,		/* use_combining */
     14     WC_TRUE,		/* use_language_tag */
     15     WC_TRUE,		/* ucs_conv */
     16     WC_FALSE,		/* pre_conv */
     17     WC_TRUE,		/* fix_width_conv */
     18     WC_FALSE,		/* use_gb12345_map */
     19     WC_FALSE,		/* use_jisx0201 */
     20     WC_FALSE,		/* use_jisc6226 */
     21     WC_FALSE,		/* use_jisx0201k */
     22     WC_FALSE,		/* use_jisx0212 */
     23     WC_FALSE,		/* use_jisx0213 */
     24     WC_TRUE,		/* strict_iso2022 */
     25     WC_FALSE,		/* gb18030_as_ucs */
     26     WC_FALSE,		/* no_replace */
     27     WC_TRUE,		/* use_wide */
     28     WC_FALSE,		/* east_asian_width */
     29 };
     30 
     31 static wc_status output_st;
     32 static wc_option output_option;
     33 static wc_bool output_set = WC_FALSE;
     34 
     35 #define wc_option_cmp(opt1, opt2) \
     36     memcmp((void *)(opt1), (void *)(opt2), sizeof(wc_option))
     37 
     38 void
     39 wc_input_init(wc_ces ces, wc_status *st)
     40 {
     41     wc_gset *gset;
     42     int i, g;
     43 
     44     st->ces_info = &WcCesInfo[WC_CES_INDEX(ces)];
     45     gset = st->ces_info->gset;
     46 
     47     st->state = 0;
     48     st->g0_ccs = 0;
     49     st->g1_ccs = 0;
     50     st->design[0] = gset[0].ccs;
     51     st->design[1] = gset[1].ccs;	/* for ISO-2022-JP/EUC-JP */ 
     52     st->design[2] = 0;
     53     st->design[3] = 0;
     54     st->gl = 0;
     55     st->gr = 1;
     56     st->ss = 0;
     57 
     58     for (i = 0; gset[i].ccs; i++) {
     59 	if (gset[i].init) {
     60 	    g = gset[i].g & 0x03;
     61 	    if (! st->design[g])
     62 		st->design[g] = gset[i].ccs;
     63 	}
     64     }
     65 
     66 #ifdef USE_UNICODE
     67     st->tag = NULL;
     68     st->ntag = 0;
     69 #endif
     70 }
     71 
     72 void
     73 wc_output_init(wc_ces ces, wc_status *st)
     74 {
     75     wc_gset *gset;
     76 #ifdef USE_UNICODE
     77     size_t i, n, nw;
     78 #endif
     79 
     80     if (output_set && ces == output_st.ces_info->id &&
     81 	! wc_option_cmp(&WcOption, &output_option)) {
     82 	*st = output_st;
     83 	return;
     84     }
     85 
     86     st->state = 0;
     87     st->ces_info = &WcCesInfo[WC_CES_INDEX(ces)];
     88     gset = st->ces_info->gset;
     89 
     90     st->g0_ccs = ((ces == WC_CES_ISO_2022_JP || ces == WC_CES_ISO_2022_JP_2 ||
     91 	ces == WC_CES_ISO_2022_JP_3) && WcOption.use_jisx0201)
     92 	? WC_CCS_JIS_X_0201 : gset[0].ccs;
     93     st->g1_ccs = ((ces == WC_CES_ISO_2022_JP || ces == WC_CES_ISO_2022_JP_2 ||
     94 	ces == WC_CES_ISO_2022_JP_3) && WcOption.use_jisc6226)
     95 	? WC_CCS_JIS_C_6226 : gset[1].ccs;
     96     st->design[0] = st->g0_ccs;
     97     st->design[1] = 0;
     98     st->design[2] = 0;
     99     st->design[3] = 0;
    100     st->gl = 0;
    101     st->gr = 0;
    102     st->ss = 0;
    103 
    104     if (ces & WC_CES_T_ISO_2022)
    105 	wc_create_gmap(st);
    106 
    107 #ifdef USE_UNICODE
    108     st->tag = NULL;
    109     st->ntag = 0;
    110 
    111     if (! WcOption.ucs_conv) {
    112 	st->tlist = NULL;
    113 	st->tlistw = NULL;
    114     } else {
    115 
    116     for (i = n = nw = 0; gset[i].ccs; i++) {
    117 	if (WC_CCS_IS_WIDE(gset[i].ccs))
    118 	    nw++;
    119 	else
    120 	    n++;
    121     }
    122     st->tlist = New_N(wc_table *, n + 1);
    123     st->tlistw = New_N(wc_table *, nw + 1);
    124     for (i = n = nw = 0; gset[i].ccs; i++) {
    125 	if (WC_CCS_IS_WIDE(gset[i].ccs)) {
    126 	    switch (gset[i].ccs) {
    127 	    case WC_CCS_JIS_X_0212:
    128 		if (! WcOption.use_jisx0212)
    129 		    continue;
    130 		break;
    131 	    case WC_CCS_JIS_X_0213_1:
    132 	    case WC_CCS_JIS_X_0213_2:
    133 		if (! WcOption.use_jisx0213)
    134 		    continue;
    135 		break;
    136 	    case WC_CCS_GB_2312:
    137 		if (WcOption.use_gb12345_map &&
    138 		    ces != WC_CES_GBK && ces != WC_CES_GB18030) {
    139 		    st->tlistw[nw++] = wc_get_ucs_table(WC_CCS_GB_12345);
    140 		    continue;
    141 		}
    142 		break;
    143 	    }
    144 	    st->tlistw[nw++] = wc_get_ucs_table(gset[i].ccs);
    145 	} else {
    146 	    switch (gset[i].ccs) {
    147 	    case WC_CCS_JIS_X_0201K:
    148 		if (! WcOption.use_jisx0201k)
    149 		    continue;
    150 		break;
    151 	    }
    152 	    st->tlist[n++] = wc_get_ucs_table(gset[i].ccs);
    153 	}
    154     }
    155     st->tlist[n] = NULL;
    156     st->tlistw[nw] = NULL;
    157     }
    158 #endif
    159 
    160     output_st = *st;
    161     output_set = WC_TRUE;
    162     output_option = WcOption;
    163 }
    164 
    165 wc_bool
    166 wc_ces_has_ccs(wc_ccs ccs, wc_status *st)
    167 {
    168     wc_gset *gset = st->ces_info->gset;
    169     int i;
    170 
    171     for (i = 0; gset[i].ccs; i++) {
    172 	if (ccs == gset[i].ccs)
    173 	    return WC_TRUE;
    174     }
    175     return WC_FALSE;
    176 }