~ubuntu-branches/ubuntu/karmic/alpine/karmic

« back to all changes in this revision

Viewing changes to pith/charconv/utf8.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2008-09-23 12:17:56 UTC
  • mfrom: (2.1.8 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080923121756-6u4x8bwq89qlzt32
Tags: 2.00+dfsg-2
Update to package description: note that Alpine is no longer in
alpha. (Closes: #499640)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#if !defined(lint) && !defined(DOS)
2
 
static char rcsid[] = "$Id: utf8.c 902 2008-01-08 17:04:58Z hubert@u.washington.edu $";
 
2
static char rcsid[] = "$Id: utf8.c 1019 2008-04-02 22:09:20Z hubert@u.washington.edu $";
3
3
#endif
4
4
 
5
5
/*
6
6
 * ========================================================================
7
 
 * Copyright 2006-2007 University of Washington
 
7
 * Copyright 2006-2008 University of Washington
8
8
 *
9
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
10
 * you may not use this file except in compliance with the License.
1924
1924
#if     PREREQ_FOR_SYS_TRANSLATION
1925
1925
        char *dcm;
1926
1926
 
1927
 
        dcm = nl_langinfo(CODESET);
 
1927
        dcm = nl_langinfo_codeset_wrapper();
1928
1928
        dcm = dcm ? dcm : "US-ASCII";
1929
1929
 
1930
1930
        init_utf8_display(0, NULL);
2117
2117
 
2118
2118
 
2119
2119
/*
 
2120
 * This function is only defined in this special case and so calls
 
2121
 * to it should be wrapped in the same macro conditionals.
 
2122
 *
 
2123
 * Returns the default display charset for a UNIX terminal emulator,
 
2124
 * it is what nl_langinfo(CODESET) should return but we need to
 
2125
 * wrap nl_langinfo because we know of strange behaving implementations.
 
2126
 */
 
2127
#if !defined(_WINDOWS) && HAVE_LANGINFO_H && defined(CODESET)
 
2128
char *
 
2129
nl_langinfo_codeset_wrapper(void)
 
2130
{
 
2131
    char *ret = NULL;
 
2132
 
 
2133
    ret = nl_langinfo(CODESET);
 
2134
    
 
2135
    /*
 
2136
     * If the value returned from nl_langinfo() is not a real charset,
 
2137
     * see if we can figure out what they meant. If we can't figure it
 
2138
     * out return NULL and let the caller decide what to do.
 
2139
     */
 
2140
    if(ret && *ret && !output_charset_is_supported(ret)){
 
2141
        if(!strcmp("ANSI_X3.4-1968", ret)
 
2142
           || !strcmp("ASCII", ret)
 
2143
           || !strcmp("C", ret)
 
2144
           || !strcmp("POSIX", ret))
 
2145
          ret = "US-ASCII";
 
2146
        else if(!strucmp(ret, "UTF8"))
 
2147
          ret = "UTF-8";
 
2148
        else if(!strucmp(ret, "EUCJP"))
 
2149
          ret = "EUC-JP";
 
2150
        else if(!strucmp(ret, "EUCKP"))
 
2151
          ret = "EUC-KP";
 
2152
        else if(!strucmp(ret, "SJIS"))
 
2153
          ret = "SHIFT-JIS";
 
2154
        else if(strstr(ret, "8859")){
 
2155
            char *p;
 
2156
 
 
2157
            /* check for digits after 8859 */
 
2158
            p = strstr(ret, "8859");
 
2159
            p += 4;
 
2160
            if(!isdigit(*p))
 
2161
              p++;
 
2162
 
 
2163
            if(isdigit(*p)){
 
2164
                static char buf[12];
 
2165
 
 
2166
                memset(buf, 0, sizeof(buf));
 
2167
                strncpy(buf, "ISO-8859-", sizeof(buf));
 
2168
                buf[9] = *p++;
 
2169
                if(isdigit(*p))
 
2170
                  buf[10] = *p;
 
2171
 
 
2172
                ret = buf;
 
2173
            }
 
2174
        }
 
2175
    }
 
2176
 
 
2177
    if(ret && !output_charset_is_supported(ret))
 
2178
      ret = NULL;
 
2179
 
 
2180
    return(ret);
 
2181
}
 
2182
#endif
 
2183
 
 
2184
 
 
2185
/*
2120
2186
 * Convert the "orig" string from UTF-8 to "charset". If no conversion is
2121
2187
 * needed the return value will point to orig. If a conversion is done,
2122
2188
 * the return string should be freed by the caller.
2228
2294
void
2229
2295
line_paint(int offset,                  /* current dot offset into vl */
2230
2296
           struct display_line *displ,
2231
 
           int passwd)                  /* flag to hide display of chars */
 
2297
           int *passwd)                 /* flag to hide display of chars */
2232
2298
{
2233
2299
    int i, w, w2, already_got_one = 0;
2234
2300
    int vfirst, vlast, dfirst, dlast, vi, di;
2235
2301
    int new_vbase;
2236
2302
    unsigned (*width_a_to_b)(UCS *, int, int);
2237
2303
 
2238
 
    if(passwd)
 
2304
    /*
 
2305
     * Set passwd to 10 in caller if you want to conceal the
 
2306
     * password but not print asterisks for feedback.
 
2307
     *
 
2308
     * Set passwd to 1 in caller to conceal by printing asterisks.
 
2309
     */
 
2310
    if(passwd && *passwd >= 10){        /* don't show asterisks */
 
2311
        if(*passwd > 10)
 
2312
          return;
 
2313
        else
 
2314
          *passwd = 11;         /* only blat once */
 
2315
 
 
2316
        i = 0;
 
2317
        (*displ->movecursor)(displ->row, displ->col);
 
2318
        while(i++ <= displ->dwid)
 
2319
          (*displ->writechar)(' ');
 
2320
 
 
2321
        (*displ->movecursor)(displ->row, displ->col);
 
2322
        return;
 
2323
    }
 
2324
 
 
2325
    if(passwd && *passwd)
2239
2326
      width_a_to_b = single_width_chars_a_to_b;
2240
2327
    else
2241
2328
      width_a_to_b = ucs4_str_width_a_to_b;
2317
2404
        displ->vbase = MAX(new_vbase, 0);
2318
2405
    }
2319
2406
 
2320
 
    if(displ->vbase == 1 && (passwd || wcellwidth(displ->vl[0]) == 1))
 
2407
    if(displ->vbase == 1 && ((passwd && *passwd) || wcellwidth(displ->vl[0]) == 1))
2321
2408
      displ->vbase = 0;
2322
2409
         
2323
2410
    vfirst = displ->vbase;
2354
2441
     * Copy the relevant part of the virtual line into the display line.
2355
2442
     */
2356
2443
    for(vi = vfirst, di = dfirst; vi <= vlast; vi++, di++)
2357
 
      if(passwd)
 
2444
      if(passwd && *passwd)
2358
2445
        displ->dl[di] = '*';            /* to conceal password */
2359
2446
      else
2360
2447
        displ->dl[di] = displ->vl[vi];