w3m

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

priv.c (1416B)


      1 
      2 #include "wc.h"
      3 #include "wtf.h"
      4 
      5 Str
      6 wc_conv_from_priv1(Str is, wc_ces ces)
      7 {
      8     Str os;
      9     wc_uchar *sp = (wc_uchar *)is->ptr;
     10     wc_uchar *ep = sp + is->length;
     11     wc_uchar *p;
     12     wc_ccs ccs = WcCesInfo[WC_CCS_INDEX(ces)].gset[1].ccs;
     13 
     14     for (p = sp; p < ep && *p < 0x80; p++)
     15 	;
     16     if (p == ep)
     17 	return is;
     18     os = Strnew_size(is->length);
     19     if (p > sp)
     20 	Strcat_charp_n(os, is->ptr, (int)(p - sp));
     21 
     22     for (; p < ep; p++) {
     23 	if (*p & 0x80)
     24 	    wtf_push(os, ccs, (wc_uint32)*p);
     25 	else
     26 	    Strcat_char(os, (char)*p);
     27     }
     28     return os;
     29 }
     30 
     31 Str
     32 wc_char_conv_from_priv1(wc_uchar c, wc_status *st)
     33 {
     34     Str os = Strnew_size(1);
     35 
     36     if (c & 0x80)
     37 	wtf_push(os, st->ces_info->gset[1].ccs, (wc_uint32)c);
     38     else
     39 	Strcat_char(os, (char)c);
     40     return os;
     41 }
     42 
     43 Str
     44 wc_conv_from_ascii(Str is, wc_ces ces)
     45 {
     46     Str os;
     47     wc_uchar *sp = (wc_uchar *)is->ptr;
     48     wc_uchar *ep = sp + is->length;
     49     wc_uchar *p;
     50 
     51     for (p = sp; p < ep && *p < 0x80; p++)
     52 	;
     53     if (p == ep)
     54 	return is;
     55     os = Strnew_size(is->length);
     56     if (p > sp)
     57 	Strcat_charp_n(os, is->ptr, (int)(p - sp));
     58 
     59     for (; p < ep; p++) {
     60 	if (*p & 0x80)
     61 	    wtf_push_unknown(os, p, 1);
     62 	else
     63 	    Strcat_char(os, (char)*p);
     64     }
     65     return os;
     66 }
     67 
     68 void
     69 wc_push_to_raw(Str os, wc_wchar_t cc, wc_status *st)
     70 {
     71 
     72     switch (cc.ccs) {
     73     case WC_CCS_US_ASCII:
     74     case WC_CCS_RAW:
     75 	Strcat_char(os, (char)cc.code);
     76     }
     77     return;
     78 }