Show
Ignore:
Timestamp:
03/27/08 23:35:21 (10 months ago)
Author:
karpet
Message:

whitespace only. again.

I am now using gnu indent rather than the original bsd version. My opts are below:

--no-blank-lines-after-declarations
--blank-lines-after-procedures
--no-blank-lines-after-commas
--break-before-boolean-operator
//--break-function-decl-args
//--break-function-decl-args-end
// long options above do not work. use short below instead.
-bfda
-bfde
--braces-on-if-line
--brace-indent4
--braces-after-struct-decl-line
--dont-cuddle-else
--comment-delimiters-on-blank-lines
--else-endif-column1
--no-space-after-casts
--declaration-indentation4
--paren-indentation4
--dont-format-first-column-comments
--dont-format-comments
--ignore-newlines

--line-length80
--indent-level4
--parameter-indentation5
--continue-at-parentheses
--no-space-after-function-call-names
--no-space-after-parentheses
--procnames-start-lines
--space-after-for
--space-after-if
--space-after-while
--dont-star-comments
--swallow-optional-blank-lines
--no-tabs

-TxmlChar?
-Tswish_ParserData
-Tswish_Config
-Tswish_3
-Tswish_Analyzer
-Tswish_Parser
-Tswish_DocInfo
-Tswish_TagStack
-Tswish_MetaName
-Tswish_Property

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/utf8.c

    r1913 r2103  
    1515 
    1616/* convert UTF-8 data to wide character */ 
    17 static int u8_toucs(u_int32_t *dest, int sz, char *src, int srcsz); 
     17static int u8_toucs( 
     18    u_int32_t * dest, 
     19    int sz, 
     20    char *src, 
     21    int srcsz 
     22); 
    1823 
    1924/* the opposite conversion */ 
    20 static int u8_toutf8(char *dest, int sz, u_int32_t *src, int srcsz); 
     25static int u8_toutf8( 
     26    char *dest, 
     27    int sz, 
     28    u_int32_t * src, 
     29    int srcsz 
     30); 
    2131 
    2232/* single character to UTF-8 */ 
    23 static int u8_wc_toutf8(char *dest, u_int32_t ch); 
     33static int u8_wc_toutf8( 
     34    char *dest, 
     35    u_int32_t ch 
     36); 
    2437 
    2538/* character number to byte offset */ 
    26 static int u8_offset(char *str, int charnum); 
     39static int u8_offset( 
     40    char *str, 
     41    int charnum 
     42); 
    2743 
    2844/* byte offset to character number */ 
    29 static int u8_charnum(char *s, int offset); 
     45static int u8_charnum( 
     46    char *s, 
     47    int offset 
     48); 
    3049 
    3150/* return next character, updating an index variable */ 
    32 static u_int32_t u8_nextchar(char *s, int *i); 
     51static u_int32_t u8_nextchar( 
     52    char *s, 
     53    int *i 
     54); 
    3355 
    3456/* move to next character */ 
    35 static void u8_inc(char *s, int *i); 
     57static void u8_inc( 
     58    char *s, 
     59    int *i 
     60); 
    3661 
    3762/* move to previous character */ 
    38 static void u8_dec(char *s, int *i); 
     63static void u8_dec( 
     64    char *s, 
     65    int *i 
     66); 
    3967 
    4068/* returns length of next utf-8 sequence */ 
    41 static int u8_seqlen(char *s); 
     69static int u8_seqlen( 
     70    char *s 
     71); 
    4272 
    4373/* assuming src points to the character after a backslash, read an 
    4474   escape sequence, storing the result in dest and returning the number of 
    4575   input characters processed */ 
    46 static int u8_read_escape_sequence(char *src, u_int32_t *dest); 
     76static int u8_read_escape_sequence( 
     77    char *src, 
     78    u_int32_t * dest 
     79); 
    4780 
    4881/* given a wide character, convert it to an ASCII escape sequence stored in 
    4982   buf, where buf is "sz" bytes. returns the number of characters output. */ 
    50 static int u8_escape_wchar(char *buf, int sz, u_int32_t ch); 
     83static int u8_escape_wchar( 
     84    char *buf, 
     85    int sz, 
     86    u_int32_t ch 
     87); 
    5188 
    5289/* convert a string "src" containing escape sequences to UTF-8 */ 
    53 static int u8_unescape(char *buf, int sz, char *src); 
     90static int u8_unescape( 
     91    char *buf, 
     92    int sz, 
     93    char *src 
     94); 
    5495 
    5596/* convert UTF-8 "src" to ASCII with escape sequences. 
    5697   if escape_quotes is nonzero, quote characters will be preceded by 
    5798   backslashes as well. */ 
    58 static int u8_escape(char *buf, int sz, char *src, int escape_quotes); 
     99static int u8_escape( 
     100    char *buf, 
     101    int sz, 
     102    char *src, 
     103    int escape_quotes 
     104); 
    59105 
    60106/* utility predicates used by the above */ 
    61 static int octal_digit(char c); 
    62 static int hex_digit(char c); 
     107static int octal_digit( 
     108    char c 
     109); 
     110static int hex_digit( 
     111    char c 
     112); 
    63113 
    64114/* return a pointer to the first occurrence of ch in s, or NULL if not 
    65115   found. character index of found character returned in *charn. */ 
    66 static char *u8_strchr(char *s, u_int32_t ch, int *charn); 
     116static char *u8_strchr( 
     117    char *s, 
     118    u_int32_t ch, 
     119    int *charn 
     120); 
    67121 
    68122/* same as the above, but searches a buffer of a given size instead of 
    69123   a NUL-terminated string. */ 
    70 static char *u8_memchr(char *s, u_int32_t ch, size_t sz, int *charn); 
     124static char *u8_memchr( 
     125    char *s, 
     126    u_int32_t ch, 
     127    size_t sz, 
     128    int *charn 
     129); 
    71130 
    72131/* count the number of characters in a UTF-8 string */ 
    73 static int u8_strlen(char *s); 
    74  
    75 static int u8_is_locale_utf8(char *locale); 
     132static int u8_strlen( 
     133    char *s 
     134); 
     135 
     136static int u8_is_locale_utf8( 
     137    char *locale 
     138); 
    76139 
    77140/* printf where the format string and arguments may be in UTF-8. 
    78141   you can avoid this function and just use ordinary printf() if the current 
    79142   locale is UTF-8. */ 
    80 static int u8_vprintf(char *fmt, va_list ap); 
    81 static int u8_printf(char *fmt, ...); 
    82  
     143static int u8_vprintf( 
     144    char *fmt, 
     145    va_list ap 
     146); 
     147static int u8_printf( 
     148    char *fmt, 
     149    ... 
     150); 
    83151 
    84152/* http://cprogramming.com/tutorial/utf8.c */ 
    85  
    86153 
    87154/* 
     
    108175#endif 
    109176 
    110  
    111177static const u_int32_t offsetsFromUTF8[6] = { 
    112178    0x00000000UL, 0x00003080UL, 0x000E2080UL, 
     
    115181 
    116182static const char trailingBytesForUTF8[256] = { 
    117     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    118     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    119     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    120     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    121     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    122     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
    123     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
    124     2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 
     183    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     184        0, 0, 0, 0, 0, 0, 0, 
     185    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     186        0, 0, 0, 0, 0, 0, 0, 
     187    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     188        0, 0, 0, 0, 0, 0, 0, 
     189    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     190        0, 0, 0, 0, 0, 0, 0, 
     191    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     192        0, 0, 0, 0, 0, 0, 0, 
     193    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     194        0, 0, 0, 0, 0, 0, 0, 
     195    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
     196        1, 1, 1, 1, 1, 1, 1, 
     197    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 
     198        4, 4, 4, 5, 5, 5, 5 
    125199}; 
    126200 
    127201/* returns length of next utf-8 sequence */ 
    128 static int u8_seqlen(char *s) 
     202static int 
     203u8_seqlen( 
     204    char *s 
     205
    129206{ 
    130207    return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1; 
     
    141218   if sz = srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space. 
    142219*/ 
    143 static int u8_toucs(u_int32_t *dest, int sz, char *src, int srcsz) 
     220static int 
     221u8_toucs( 
     222    u_int32_t * dest, 
     223    int sz, 
     224    char *src, 
     225    int srcsz 
     226
    144227{ 
    145228    u_int32_t ch; 
    146229    char *src_end = src + srcsz; 
    147230    int nb; 
    148     int i=0; 
    149  
    150     while (i < sz-1) { 
     231    int i = 0; 
     232 
     233    while (i < sz - 1) { 
    151234        nb = trailingBytesForUTF8[(unsigned char)*src]; 
    152235        if (srcsz == -1) { 
     
    160243        ch = 0; 
    161244        switch (nb) { 
    162             /* these fall through deliberately */ 
    163         case 3: ch += (unsigned char)*src++; ch <<= 6; 
    164         case 2: ch += (unsigned char)*src++; ch <<= 6; 
    165         case 1: ch += (unsigned char)*src++; ch <<= 6; 
    166         case 0: ch += (unsigned char)*src++; 
     245            /* 
     246               these fall through deliberately  
     247             */ 
     248        case 3: 
     249            ch += (unsigned char)*src++; 
     250            ch <<= 6; 
     251        case 2: 
     252            ch += (unsigned char)*src++; 
     253            ch <<= 6; 
     254        case 1: 
     255            ch += (unsigned char)*src++; 
     256            ch <<= 6; 
     257        case 0: 
     258            ch += (unsigned char)*src++; 
    167259        } 
    168260        ch -= offsetsFromUTF8[nb]; 
    169261        dest[i++] = ch; 
    170262    } 
    171  done_toucs: 
     263  done_toucs: 
    172264    dest[i] = 0; 
    173265    return i; 
     
    186278   the destination string will never be bigger than the source string. 
    187279*/ 
    188 static int u8_toutf8(char *dest, int sz, u_int32_t *src, int srcsz) 
     280static int 
     281u8_toutf8( 
     282    char *dest, 
     283    int sz, 
     284    u_int32_t * src, 
     285    int srcsz 
     286
    189287{ 
    190288    u_int32_t ch; 
     
    192290    char *dest_end = dest + sz; 
    193291 
    194     while (srcsz<0 ? src[i]!=0 : i < srcsz) { 
     292    while (srcsz < 0 ? src[i] != 0 : i < srcsz) { 
    195293        ch = src[i]; 
    196294        if (ch < 0x80) { 
     
    200298        } 
    201299        else if (ch < 0x800) { 
    202             if (dest >= dest_end-1) 
     300            if (dest >= dest_end - 1) 
    203301                return i; 
    204             *dest++ = (ch>>6) | 0xC0; 
     302            *dest++ = (ch >> 6) | 0xC0; 
    205303            *dest++ = (ch & 0x3F) | 0x80; 
    206304        } 
    207305        else if (ch < 0x10000) { 
    208             if (dest >= dest_end-2) 
     306            if (dest >= dest_end - 2) 
    209307                return i; 
    210             *dest++ = (ch>>12) | 0xE0; 
    211             *dest++ = ((ch>>6) & 0x3F) | 0x80; 
     308            *dest++ = (ch >> 12) | 0xE0; 
     309            *dest++ = ((ch >> 6) & 0x3F) | 0x80; 
    212310            *dest++ = (ch & 0x3F) | 0x80; 
    213311        } 
    214312        else if (ch < 0x110000) { 
    215             if (dest >= dest_end-3) 
     313            if (dest >= dest_end - 3) 
    216314                return i; 
    217             *dest++ = (ch>>18) | 0xF0; 
    218             *dest++ = ((ch>>12) & 0x3F) | 0x80; 
    219             *dest++ = ((ch>>6) & 0x3F) | 0x80; 
     315            *dest++ = (ch >> 18) | 0xF0; 
     316            *dest++ = ((ch >> 12) & 0x3F) | 0x80; 
     317            *dest++ = ((ch >> 6) & 0x3F) | 0x80; 
    220318            *dest++ = (ch & 0x3F) | 0x80; 
    221319        } 
     
    227325} 
    228326 
    229 static int u8_wc_toutf8(char *dest, u_int32_t ch) 
     327static int 
     328u8_wc_toutf8( 
     329    char *dest, 
     330    u_int32_t ch 
     331
    230332{ 
    231333    if (ch < 0x80) { 
     
    234336    } 
    235337    if (ch < 0x800) { 
    236         dest[0] = (ch>>6) | 0xC0; 
     338        dest[0] = (ch >> 6) | 0xC0; 
    237339        dest[1] = (ch & 0x3F) | 0x80; 
    238340        return 2; 
    239341    } 
    240342    if (ch < 0x10000) { 
    241         dest[0] = (ch>>12) | 0xE0; 
    242         dest[1] = ((ch>>6) & 0x3F) | 0x80; 
     343        dest[0] = (ch >> 12) | 0xE0; 
     344        dest[1] = ((ch >> 6) & 0x3F) | 0x80; 
    243345        dest[2] = (ch & 0x3F) | 0x80; 
    244346        return 3; 
    245347    } 
    246348    if (ch < 0x110000) { 
    247         dest[0] = (ch>>18) | 0xF0; 
    248         dest[1] = ((ch>>12) & 0x3F) | 0x80; 
    249         dest[2] = ((ch>>6) & 0x3F) | 0x80; 
     349        dest[0] = (ch >> 18) | 0xF0; 
     350        dest[1] = ((ch >> 12) & 0x3F) | 0x80; 
     351        dest[2] = ((ch >> 6) & 0x3F) | 0x80; 
    250352        dest[3] = (ch & 0x3F) | 0x80; 
    251353        return 4; 
     
    255357 
    256358/* charnum => byte offset */ 
    257 static int u8_offset(char *str, int charnum) 
    258 
    259     int offs=0; 
     359static int 
     360u8_offset( 
     361    char *str, 
     362    int charnum 
     363
     364
     365    int offs = 0; 
    260366 
    261367    while (charnum > 0 && str[offs]) { 
    262         (void)(isutf(str[++offs]) || isutf(str[++offs]) || 
    263                isutf(str[++offs]) || ++offs); 
     368        (void)(isutf(str[++offs]) || isutf(str[++offs]) || isutf(str[++offs]) 
     369               || ++offs); 
    264370        charnum--; 
    265371    } 
     
    268374 
    269375/* byte offset => charnum */ 
    270 static int u8_charnum(char *s, int offset) 
    271 
    272     int charnum = 0, offs=0; 
     376static int 
     377u8_charnum( 
     378    char *s, 
     379    int offset 
     380
     381
     382    int charnum = 0, offs = 0; 
    273383 
    274384    while (offs < offset && s[offs]) { 
    275         (void)(isutf(s[++offs]) || isutf(s[++offs]) || 
    276                isutf(s[++offs]) || ++offs); 
     385        (void)(isutf(s[++offs]) || isutf(s[++offs]) || isutf(s[++offs]) 
     386               || ++offs); 
    277387        charnum++; 
    278388    } 
     
    281391 
    282392/* number of characters */ 
    283 static int u8_strlen(char *s) 
     393static int 
     394u8_strlen( 
     395    char *s 
     396
    284397{ 
    285398    int count = 0; 
     
    293406 
    294407/* reads the next utf-8 sequence out of a string, updating an index */ 
    295 static u_int32_t u8_nextchar(char *s, int *i) 
     408static u_int32_t 
     409u8_nextchar( 
     410    char *s, 
     411    int *i 
     412
    296413{ 
    297414    u_int32_t ch = 0; 
     
    303420        sz++; 
    304421    } while (s[*i] && !isutf(s[*i])); 
    305     ch -= offsetsFromUTF8[sz-1]; 
     422    ch -= offsetsFromUTF8[sz - 1]; 
    306423 
    307424    return ch; 
    308425} 
    309426 
    310 static void u8_inc(char *s, int *i) 
    311 
    312     (void)(isutf(s[++(*i)]) || isutf(s[++(*i)]) || 
    313            isutf(s[++(*i)]) || ++(*i)); 
    314 
    315  
    316 static void u8_dec(char *s, int *i) 
    317 
    318     (void)(isutf(s[--(*i)]) || isutf(s[--(*i)]) || 
    319            isutf(s[--(*i)]) || --(*i)); 
    320 
    321  
    322 static int octal_digit(char c) 
     427static void 
     428u8_inc( 
     429    char *s, 
     430    int *i 
     431
     432
     433    (void)(isutf(s[++(*i)]) || isutf(s[++(*i)]) || isutf(s[++(*i)]) || ++(*i)); 
     434
     435 
     436static void 
     437u8_dec( 
     438    char *s, 
     439    int *i 
     440
     441
     442    (void)(isutf(s[--(*i)]) || isutf(s[--(*i)]) || isutf(s[--(*i)]) || --(*i)); 
     443
     444 
     445static int 
     446octal_digit( 
     447    char c 
     448
    323449{ 
    324450    return (c >= '0' && c <= '7'); 
    325451} 
    326452 
    327 static int hex_digit(char c) 
    328 
    329     return ((c >= '0' && c <= '9') || 
    330             (c >= 'A' && c <= 'F') || 
    331             (c >= 'a' && c <= 'f')); 
     453static int 
     454hex_digit( 
     455    char c 
     456
     457
     458    return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') 
     459            || (c >= 'a' && c <= 'f')); 
    332460} 
    333461 
    334462/* assumes that src points to the character after a backslash 
    335463   returns number of input characters processed */ 
    336 static int u8_read_escape_sequence(char *str, u_int32_t *dest) 
     464static int 
     465u8_read_escape_sequence( 
     466    char *str, 
     467    u_int32_t * dest 
     468
    337469{ 
    338470    u_int32_t ch; 
    339     char digs[9]="\0\0\0\0\0\0\0\0\0"; 
    340     int dno=0, i=1; 
    341  
    342     ch = (u_int32_t)str[0];    /* take literal character */ 
     471    char digs[9] = "\0\0\0\0\0\0\0\0\0"; 
     472    int dno = 0, i = 1; 
     473 
     474    ch = (u_int32_t) str[0];    /* take literal character */ 
    343475    if (str[0] == 'n') 
    344476        ch = L'\n'; 
     
    391523   example: u8_unescape(mybuf, 256, "hello\\u220e") 
    392524   note the double backslash is needed if called on a C string literal */ 
    393 static int u8_unescape(char *buf, int sz, char *src) 
    394 
    395     int c=0, amt; 
     525static int 
     526u8_unescape( 
     527    char *buf, 
     528    int sz, 
     529    char *src 
     530
     531
     532    int c = 0, amt; 
    396533    u_int32_t ch; 
    397534    char temp[4]; 
     
    403540        } 
    404541        else { 
    405             ch = (u_int32_t)*src; 
     542            ch = (u_int32_t) * src; 
    406543            amt = 1; 
    407544        } 
    408545        src += amt; 
    409546        amt = u8_wc_toutf8(temp, ch); 
    410         if (amt > sz-c) 
     547        if (amt > sz - c) 
    411548            break; 
    412549        memcpy(&buf[c], temp, amt); 
     
    418555} 
    419556 
    420 static int u8_escape_wchar(char *buf, int sz, u_int32_t ch) 
     557static int 
     558u8_escape_wchar( 
     559    char *buf, 
     560    int sz, 
     561    u_int32_t ch 
     562
    421563{ 
    422564    if (ch == L'\n') 
     
    439581        return snprintf(buf, sz, "\\x%hhX", (unsigned char)ch); 
    440582    else if (ch > 0xFFFF) 
    441         return snprintf(buf, sz, "\\U%.8X", (u_int32_t)ch); 
     583        return snprintf(buf, sz, "\\U%.8X", (u_int32_t) ch); 
    442584    else if (ch >= 0x80 && ch <= 0xFFFF) 
    443585        return snprintf(buf, sz, "\\u%.4hX", (unsigned short)ch); 
     
    446588} 
    447589 
    448 static int u8_escape(char *buf, int sz, char *src, int escape_quotes) 
    449 
    450     int c=0, i=0, amt; 
     590static int 
     591u8_escape( 
     592    char *buf, 
     593    int sz, 
     594    char *src, 
     595    int escape_quotes 
     596
     597
     598    int c = 0, i = 0, amt; 
    451599 
    452600    while (src[i] && c < sz) { 
     
    466614} 
    467615 
    468 static char *u8_strchr(char *s, u_int32_t ch, int *charn) 
    469 
    470     int i = 0, lasti=0; 
     616static char * 
     617u8_strchr( 
     618    char *s, 
     619    u_int32_t ch, 
     620    int *charn 
     621
     622
     623    int i = 0, lasti = 0; 
    471624    u_int32_t c; 
    472625 
     
    483636} 
    484637 
    485 static char *u8_memchr(char *s, u_int32_t ch, size_t sz, int *charn) 
    486 
    487     int i = 0, lasti=0; 
     638static char * 
     639u8_memchr( 
     640    char *s, 
     641    u_int32_t ch, 
     642    size_t sz, 
     643    int *charn 
     644
     645
     646    int i = 0, lasti = 0; 
    488647    u_int32_t c; 
    489648    int csz; 
     
    497656            csz++; 
    498657        } while (i < sz && !isutf(s[i])); 
    499         c -= offsetsFromUTF8[csz-1]; 
     658        c -= offsetsFromUTF8[csz - 1]; 
    500659 
    501660        if (c == ch) { 
     
    508667} 
    509668 
    510 static int u8_is_locale_utf8(char *locale) 
    511 
    512     /* this code based on libutf8 */ 
    513     const char* cp = locale; 
     669static int 
     670u8_is_locale_utf8( 
     671    char *locale 
     672
     673
     674    /* 
     675       this code based on libutf8  
     676     */ 
     677    const char *cp = locale; 
    514678 
    515679    for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++) { 
    516680        if (*cp == '.') { 
    517             const char* encoding = ++cp; 
    518             for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++) 
    519                 ; 
    520             if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5)) 
    521                 || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4))) 
    522                 return 1; /* it's UTF-8 */ 
     681            const char *encoding = ++cp; 
     682            for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++); 
     683            if ((cp - encoding == 5 && !strncmp(encoding, "UTF-8", 5)) 
     684                || (cp - encoding == 4 && !strncmp(encoding, "utf8", 4))) 
     685                return 1;       /* it's UTF-8 */ 
    523686            break; 
    524687        } 
     
    527690} 
    528691 
    529 static int u8_vprintf(char *fmt, va_list ap) 
    530 
    531     int cnt, sz=0; 
     692static int 
     693u8_vprintf( 
     694    char *fmt, 
     695    va_list ap 
     696
     697
     698    int cnt, sz = 0; 
    532699    char *buf; 
    533700    u_int32_t *wcs; 
    534701 
    535702    sz = 512; 
    536     buf = (char*)alloca(sz); 
    537  try_print: 
     703    buf = (char *)alloca(sz); 
     704  try_print: 
    538705    cnt = vsnprintf(buf, sz, fmt, ap); 
    539706    if (cnt >= sz) { 
    540         buf = (char*)alloca(cnt - sz + 1); 
     707        buf = (char *)alloca(cnt - sz + 1); 
    541708        sz = cnt + 1; 
    542709        goto try_print; 
    543710    } 
    544     wcs = (u_int32_t*)alloca((cnt+1) * sizeof(u_int32_t)); 
    545     cnt = u8_toucs(wcs, cnt+1, buf, cnt); 
    546     printf("%ls", (wchar_t*)wcs); 
     711    wcs = (u_int32_t *) alloca((cnt + 1) * sizeof(u_int32_t)); 
     712    cnt = u8_toucs(wcs, cnt + 1, buf, cnt); 
     713    printf("%ls", (wchar_t *) wcs); 
    547714    return cnt; 
    548715} 
    549716 
    550 static int u8_printf(char *fmt, ...) 
     717static int 
     718u8_printf( 
     719    char *fmt, 
     720    ... 
     721
    551722{ 
    552723    int cnt;