w3m

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

jis.c (1421B)


      1 
      2 #include "wc.h"
      3 #include "jis.h"
      4 #include "search.h"
      5 #ifdef USE_UNICODE
      6 #include "ucs.h"
      7 #endif
      8 
      9 #include "map/jisx0201k_jisx0208.map"
     10 #include "map/jisx0208_jisx02131.map"
     11 
     12 wc_wchar_t
     13 wc_jisx0201k_to_jisx0208(wc_wchar_t cc)
     14 {
     15     cc.code = jisx0201k_jisx0208_map[cc.code & 0x7f];
     16     cc.ccs = cc.code ? WC_CCS_JIS_X_0208 : WC_CCS_UNKNOWN_W;
     17     return cc;
     18 }
     19 
     20 wc_wchar_t
     21 wc_jisx0212_to_jisx0213(wc_wchar_t cc)
     22 {
     23 #ifdef USE_UNICODE
     24     wc_wchar_t cc2;
     25     static wc_table *t1 = NULL;
     26     static wc_table *t2 = NULL;
     27 
     28     if (t1 == NULL) {
     29 	t1 = wc_get_ucs_table(WC_CCS_JIS_X_0213_1);
     30 	t2 = wc_get_ucs_table(WC_CCS_JIS_X_0213_2);
     31     }
     32     cc2 = wc_any_to_any(cc, t2);
     33     if (cc2.ccs == WC_CCS_JIS_X_0212)
     34 	return cc2;
     35     return wc_any_to_any(cc, t1);
     36 #else
     37     cc.ccs = WC_CCS_UNKNOWN_W;
     38     return cc;
     39 #endif
     40 }
     41 
     42 wc_wchar_t
     43 wc_jisx0213_to_jisx0212(wc_wchar_t cc)
     44 {
     45 #ifdef USE_UNICODE
     46     static wc_table *t = NULL;
     47 
     48     if (t == NULL)
     49 	t = wc_get_ucs_table(WC_CCS_JIS_X_0212);
     50     return wc_any_to_any(cc, t);
     51 #else
     52     cc.ccs = WC_CCS_UNKNOWN_W;
     53     return cc;
     54 #endif
     55 }
     56 
     57 wc_ccs
     58 wc_jisx0208_or_jisx02131(wc_uint16 code)
     59 {
     60     return wc_map_range_search(code & 0x7f7f,
     61 	jisx0208_jisx02131_map, N_jisx0208_jisx02131_map)
     62 	? WC_CCS_JIS_X_0213_1 : WC_CCS_JIS_X_0208;
     63 }
     64 
     65 wc_ccs
     66 wc_jisx0212_or_jisx02132(wc_uint16 code)
     67 {
     68     return wc_jisx0212_jisx02132_map[(code >> 8) & 0x7f]
     69 	? WC_CCS_JIS_X_0213_2 : WC_CCS_JIS_X_0212;
     70 }