Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 93664 | Differences between
and this patch

Collapse All | Expand All

(-)man-1.6d-orig/src/gripes.c (-3 / +37 lines)
Lines 4-9 Link Here
4
4
5
#include "gripes.h"
5
#include "gripes.h"
6
#include "man.h"		/* for progname */
6
#include "man.h"		/* for progname */
7
#include "man-iconv.h" /*for get_locale_charset */
7
8
8
extern char *msg[];
9
extern char *msg[];
9
10
Lines 113-139 Link Here
113
			"man: internal error - cannot find message %d\n", n);
114
			"man: internal error - cannot find message %d\n", n);
114
		exit (1);
115
		exit (1);
115
        }
116
        }
117
116
	return s;
118
	return s;
117
}
119
}
118
120
119
#endif /* NONLS */
121
#endif /* NONLS */
120
122
121
void
123
void
122
gripe (int n, ...) {
124
gripe (int n, ...) {	
123
    va_list p;
125
    va_list p;
126
    char *mes;
127
    char *conv_mes;
128
    int free_mes;
124
129
125
    va_start(p, n);
130
    va_start(p, n);
126
    vfprintf (stderr, getmsg(n), p);
131
    mes=getmsg(n);
132
#ifdef USE_ICONV	
133
    free_mes=1;
134
    if ((conv_mes=convert_with_iconv(mes, "UTF-8", 
135
				     get_locale_charset()))==NULL) {
136
#endif			
137
	    conv_mes=mes;
138
	    free_mes=0;
139
#ifdef USE_ICONV		
140
    }
141
#endif
142
    vfprintf (stderr, conv_mes, p);
127
    va_end(p);
143
    va_end(p);
128
    fflush (stderr);
144
    fflush (stderr);
145
    if (free_mes)
146
	    free(conv_mes);
129
}
147
}
130
148
131
void
149
void
132
fatal (int n, ...) {
150
fatal (int n, ...) {
133
    va_list p;
151
    va_list p;
152
    char *mes, *conv_mes;
153
    int free_mes;
154
134
    fprintf (stderr, "%s: ", progname);
155
    fprintf (stderr, "%s: ", progname);
135
    va_start(p, n);
156
    va_start(p, n);
136
    vfprintf (stderr, getmsg(n), p);
157
    mes=getmsg(n);
158
#ifdef USE_ICONV	
159
    free_mes=1;
160
    if ((conv_mes=convert_with_iconv(mes, "UTF-8", 
161
				     get_locale_charset()))==NULL) {
162
#endif			
163
	    conv_mes=mes;
164
	    free_mes=0;
165
#ifdef USE_ICONV		
166
    }
167
#endif
168
    vfprintf (stderr, conv_mes, p);
137
    va_end(p);
169
    va_end(p);
170
    if (free_mes)
171
	    free(conv_mes);
138
    exit (1);
172
    exit (1);
139
}
173
}
(-)man-1.6d-orig/src/Makefile.in (-1 / +1 lines)
Lines 17-23 Link Here
17
17
18
pager = @pager@
18
pager = @pager@
19
19
20
DEFS = @DEFS@
20
DEFS = @DEFS@ -DUSE_ICONV
21
CWARN = -Wall -Wstrict-prototypes -Wmissing-prototypes
21
CWARN = -Wall -Wstrict-prototypes -Wmissing-prototypes
22
CWARNNP = -Wall
22
CWARNNP = -Wall
23
23
(-)man-1.6d-orig/src/man-iconv.c (-2 / +46 lines)
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;
(-)man-1.6d-orig/src/man-iconv.h (+12 lines)
Line 1 Link Here
1
#ifndef MAN_ICONV_H
2
#define MAN_ICONV_H
3
1
extern const char *get_converter (const char *path);
4
extern const char *get_converter (const char *path);
5
6
#ifdef USE_ICONV
7
extern char *get_locale_charset (void);
8
extern char *convert_with_iconv (const char *from, 
9
				 const char *from_codeset, 
10
				 const char *to_codest);
11
#endif
12
13
#endif/*MAN_ICONV_H*/

Return to bug 93664