Lines 20-26
Link Here
|
20 |
* By default iconv is not used - this is the wrong interface. |
20 |
* By default iconv is not used - this is the wrong interface. |
21 |
* But if you want it, define USE_ICONV. |
21 |
* But if you want it, define USE_ICONV. |
22 |
*/ |
22 |
*/ |
23 |
#undef USE_ICONV |
|
|
24 |
|
23 |
|
25 |
#include <stdio.h> /* NULL */ |
24 |
#include <stdio.h> /* NULL */ |
26 |
|
25 |
|
Lines 31-36
Link Here
|
31 |
#include <locale.h> /* setlocale */ |
30 |
#include <locale.h> /* setlocale */ |
32 |
#include <langinfo.h> /* nl_langinfo */ |
31 |
#include <langinfo.h> /* nl_langinfo */ |
33 |
#include <iconv.h> /* iconv_open */ |
32 |
#include <iconv.h> /* iconv_open */ |
|
|
33 |
#include <errno.h> /* errno variable */ |
34 |
#include "man-iconv.h" /* get_converter */ |
34 |
#include "man-iconv.h" /* get_converter */ |
35 |
#include "util.h" /* my_strdup */ |
35 |
#include "util.h" /* my_strdup */ |
36 |
#include "man.h" /* debug */ |
36 |
#include "man.h" /* debug */ |
Lines 65-71
Link Here
|
65 |
return iconv_flags; |
65 |
return iconv_flags; |
66 |
} |
66 |
} |
67 |
|
67 |
|
68 |
static char * |
68 |
char * |
69 |
get_locale_charset (void) { |
69 |
get_locale_charset (void) { |
70 |
char *old_lc_ctype, *charset; |
70 |
char *old_lc_ctype, *charset; |
71 |
|
71 |
|
Lines 77-82
Link Here
|
77 |
return charset; |
77 |
return charset; |
78 |
} |
78 |
} |
79 |
|
79 |
|
|
|
80 |
char * |
81 |
convert_with_iconv (const char *from, const char *from_codeset, |
82 |
const char *to_codest) { |
83 |
size_t inbytes_remaining; |
84 |
size_t outbytes_remaining; |
85 |
size_t outbuf_size; |
86 |
char *dest, *outp; |
87 |
size_t len; |
88 |
const char *p; |
89 |
iconv_t cd; |
90 |
size_t err; |
91 |
p=from; |
92 |
if ((cd=iconv_open(to_codest, from_codeset))==(iconv_t)(-1)) |
93 |
return NULL; |
94 |
len=strlen(from); |
95 |
inbytes_remaining = len; |
96 |
outbuf_size = len + 1; /* + 1 for nul in case len == 1 */ |
97 |
outbytes_remaining = outbuf_size - 1; /* -1 for nul */ |
98 |
dest=outp=malloc(outbuf_size); |
99 |
again: |
100 |
err = iconv (cd, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining); |
101 |
if (err == (size_t) -1) { |
102 |
if (errno==E2BIG) { |
103 |
size_t used = outp - dest; |
104 |
|
105 |
outbuf_size *= 2; |
106 |
dest = realloc (dest, outbuf_size); |
107 |
|
108 |
outp = dest + used; |
109 |
outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */ |
110 |
|
111 |
goto again; |
112 |
} else { |
113 |
free(dest); |
114 |
dest=NULL; |
115 |
goto exit; |
116 |
} |
117 |
} |
118 |
exit: |
119 |
iconv_close(cd); |
120 |
outp[0]=0; |
121 |
return dest; |
122 |
} |
123 |
|
80 |
static char * |
124 |
static char * |
81 |
get_man_charset (const char *path) { |
125 |
get_man_charset (const char *path) { |
82 |
char *charset_env, *file, *path2, *p; |
126 |
char *charset_env, *file, *path2, *p; |