diff options
| author | Simon Tatham <anakin@pobox.com> | 2004-04-20 19:06:10 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2004-04-20 19:06:10 +0000 |
| commit | 089bea2c82140089291e23248d6f8ec9e48c8dfa (patch) | |
| tree | a9333917d6b64058480f3d5eda2167e9e789fa26 /bk_whlp.c | |
| parent | 7925293458ba258485640818663e31eb3ac23141 (diff) | |
| download | halibut-089bea2c82140089291e23248d6f8ec9e48c8dfa.zip halibut-089bea2c82140089291e23248d6f8ec9e48c8dfa.tar.gz halibut-089bea2c82140089291e23248d6f8ec9e48c8dfa.tar.bz2 halibut-089bea2c82140089291e23248d6f8ec9e48c8dfa.tar.xz | |
The Windows Help backend now uses libcharset to the maximum extent
it can. (Which isn't much, since I currently don't know how to
indicate that a help file is encoded in anything other than Win1252,
and so the only use I found for libcharset was to replace the
previous pathetic 8859-1 conversion so that extra things like the
trademark sign are supported.)
[originally from svn r4102]
Diffstat (limited to 'bk_whlp.c')
| -rw-r--r-- | bk_whlp.c | 78 |
1 files changed, 41 insertions, 37 deletions
@@ -676,45 +676,49 @@ static void whlp_rdaddwc(rdstringc *rs, word *text) { */ static int whlp_convert(wchar_t *s, int maxlen, char **result, int hard_spaces) { + wchar_t *s2; + char *ret; + int ok; + /* - * FIXME. Currently this is ISO8859-1 only. + * Enforce maxlen. */ - int doing = (result != 0); - int ok = TRUE; - char *p = NULL; - int plen = 0, psize = 0; - - if (maxlen <= 0) - maxlen = -1; - - for (; *s && maxlen != 0; s++, maxlen--) { - wchar_t c = *s; - char outc; - - if ((c >= 32 && c <= 126) || - (c >= 160 && c <= 255)) { - /* Char is OK. */ - if (c == 32 && hard_spaces) - outc = '\240'; - else - outc = (char)c; - } else { - /* Char is not OK. */ - ok = FALSE; - outc = 0xBF; /* approximate the good old DEC `uh?' */ - } - if (doing) { - if (plen >= psize) { - psize = plen + 256; - p = resize(p, psize); - } - p[plen++] = outc; - } - } - if (doing) { - p = resize(p, plen+1); - p[plen] = '\0'; - *result = p; + if (maxlen > 0 && ustrlen(s) > maxlen) { + s2 = mknewa(wchar_t, maxlen+1); + memcpy(s2, s, maxlen * sizeof(wchar_t)); + s2[maxlen] = L'\0'; + s = s2; + } else + s2 = NULL; + + /* + * We currently only support Win1252 in Windows Help files, + * because I don't know how to fiddle the character set + * designation in the |SYSTEM file to indicate anything else. + */ + + ret = utoa_careful_dup(s, CS_CP1252); + if (!ret) { + ok = FALSE; + ret = utoa_dup(s, CS_CP1252); + } else + ok = TRUE; + + /* + * Enforce hard_spaces. + */ + if (hard_spaces) { + char *p; + + for (p = ret; *p; p++) + if (*p == ' ') + *p = '\240'; } + + if (s2) + sfree(s2); + + *result = ret; + return ok; } |