5 /* Any pair of 32 bit hashes can be used. lookup3.c generates pairs, will do. */
6 #define _JLU3_jlu32lpair 1
7 #define jlu32lpair poptJlu32lpair
10 /*@-varuse +charint +ignoresigns @*/
11 /*@unchecked@*/ /*@observer@*/
12 static const unsigned char utf8_skip_data
[256] = {
13 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,
14 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,
15 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,
16 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,
17 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,
18 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,
19 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
20 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
22 /*@=varuse =charint =ignoresigns @*/
25 POPT_prev_char (const char *str
)
31 if (((unsigned)*p
& 0xc0) != (unsigned)0x80)
37 POPT_next_char (const char *str
)
43 if (((unsigned)*p
& 0xc0) != (unsigned)0x80)
49 #if !defined(POPT_fprintf) /* XXX lose all the goop ... */
51 #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
53 * Rebind a "UTF-8" codeset for popt's internal use.
56 POPT_dgettext(const char * dom
, const char * str
)
58 char * codeset
= NULL
;
62 dom
= textdomain(NULL
);
63 codeset
= bind_textdomain_codeset(dom
, NULL
);
64 bind_textdomain_codeset(dom
, "UTF-8");
65 retval
= dgettext(dom
, str
);
66 bind_textdomain_codeset(dom
, codeset
);
74 * Return malloc'd string converted from UTF-8 to current locale.
75 * @param istr input string (UTF-8 encoding assumed)
76 * @return localized string
78 static /*@only@*/ /*@null@*/ char *
79 strdup_locale_from_utf8 (/*@null@*/ char * istr
)
82 char * codeset
= NULL
;
89 #ifdef HAVE_LANGINFO_H
90 codeset
= nl_langinfo ((nl_item
)CODESET
);
93 if (codeset
!= NULL
&& strcmp(codeset
, "UTF-8") != 0
94 && (cd
= iconv_open(codeset
, "UTF-8")) != (iconv_t
)-1)
96 char * shift_pin
= NULL
;
97 size_t db
= strlen(istr
);
99 char * dstr
= malloc((db
+ 1) * sizeof(*dstr
));
108 err
= iconv(cd
, NULL
, NULL
, NULL
, NULL
);
111 err
= iconv(cd
, &pin
, &ib
, &pout
, &ob
);
112 if (err
!= (size_t)-1) {
113 if (shift_pin
== NULL
) {
122 { size_t used
= (size_t)(pout
- dstr
);
124 dstr
= realloc(dstr
, (db
+ 1) * sizeof(*dstr
));
130 } /*@switchbreak@*/ break;
134 /*@switchbreak@*/ break;
138 (void) iconv_close(cd
);
140 ostr
= xstrdup(dstr
);
143 ostr
= xstrdup(istr
);
150 POPT_fprintf (FILE * stream
, const char * format
, ...)
152 char * b
= NULL
, * ob
= NULL
;
156 #if defined(HAVE_VASPRINTF) && !defined(__LCLINT__)
157 va_start(ap
, format
);
158 if ((rc
= vasprintf(&b
, format
, ap
)) < 0)
162 size_t nb
= (size_t)1;
164 /* HACK: add +1 to the realloc no. of bytes "just in case". */
165 /* XXX Likely unneeded, the issues wrto vsnprintf(3) return b0rkage have
166 * to do with whether the final '\0' is counted (or not). The code
167 * below already adds +1 for the (possibly already counted) trailing NUL.
169 while ((b
= realloc(b
, nb
+1)) != NULL
) {
170 va_start(ap
, format
);
171 rc
= vsnprintf(b
, nb
, format
, ap
);
173 if (rc
> -1) { /* glibc 2.1 */
176 nb
= (size_t)(rc
+ 1); /* precise buffer length known */
177 } else /* glibc 2.0 */
178 nb
+= (nb
< (size_t)100 ? (size_t)100 : nb
);
186 ob
= strdup_locale_from_utf8(b
);
188 rc
= fprintf(stream
, "%s", ob
);
192 rc
= fprintf(stream
, "%s", b
);
199 #endif /* !defined(POPT_fprintf) */