11345
|
1 |
--- popt-1.7/Makefile.am.orig 2007-12-21 19:40:03.495254000 +0900
|
|
2 |
+++ popt-1.7/Makefile.am 2007-12-21 19:42:56.088304000 +0900
|
|
3 |
@@ -15,13 +15,13 @@ noinst_HEADERS = findme.h poptint.h syst
|
|
4 |
|
|
5 |
noinst_PROGRAMS = test1 test2 test3
|
|
6 |
test1_SOURCES = test1.c
|
|
7 |
-test1_LDFLAGS = -all-static
|
|
8 |
+test1_LDFLAGS =
|
|
9 |
test1_LDADD = $(lib_LTLIBRARIES)
|
|
10 |
test2_SOURCES = test2.c
|
|
11 |
-test2_LDFLAGS = -all-static
|
|
12 |
+test2_LDFLAGS =
|
|
13 |
test2_LDADD = $(lib_LTLIBRARIES)
|
|
14 |
test3_SOURCES = test3.c
|
|
15 |
-test3_LDFLAGS = -all-static
|
|
16 |
+test3_LDFLAGS =
|
|
17 |
test3_LDADD = $(lib_LTLIBRARIES)
|
|
18 |
|
|
19 |
noinst_SCRIPTS = testit.sh
|
|
20 |
@@ -33,7 +33,7 @@ TESTS = testit.sh
|
|
21 |
|
|
22 |
include_HEADERS = popt.h
|
|
23 |
lib_LTLIBRARIES = libpopt.la
|
|
24 |
-libpopt_la_SOURCES = popt.c findme.c poptparse.c poptconfig.c popthelp.c
|
|
25 |
+libpopt_la_SOURCES = popt.c findme.c poptparse.c poptconfig.c popthelp.c poptint.c
|
|
26 |
|
|
27 |
man_MANS = popt.3
|
|
28 |
|
|
29 |
--- popt-1.7/configure.in.orig 2007-12-21 19:40:09.557770000 +0900
|
|
30 |
+++ popt-1.7/configure.in 2007-12-21 20:07:17.961454000 +0900
|
|
31 |
@@ -1,9 +1,8 @@
|
|
32 |
AC_INIT(popt.h)
|
|
33 |
AC_CANONICAL_SYSTEM
|
|
34 |
AC_PREREQ(2.12)
|
|
35 |
-AC_CONFIG_HEADERS
|
|
36 |
AM_INIT_AUTOMAKE(popt, 1.7)
|
|
37 |
-AM_CONFIG_HEADER(config.h)
|
|
38 |
+AC_CONFIG_HEADERS(config.h)
|
|
39 |
|
|
40 |
ALL_LINGUAS="cs da de es eu_ES fi fr gl hu id is it ja ko no pl pt pt_BR ro ru sk sl sr sv tr uk wa zh zh_CN.GB2312"
|
|
41 |
|
|
42 |
@@ -50,7 +49,7 @@ else
|
|
43 |
fi
|
|
44 |
AC_SUBST(TARGET)
|
|
45 |
|
|
46 |
-AC_CHECK_HEADERS(alloca.h float.h libintl.h mcheck.h unistd.h)
|
|
47 |
+AC_CHECK_HEADERS(alloca.h float.h libintl.h mcheck.h unistd.h langinfo.h)
|
|
48 |
AC_MSG_CHECKING(for /usr/ucblib in LIBS)
|
|
49 |
if test -d /usr/ucblib ; then
|
|
50 |
if test "$build" = "mips-sni-sysv4" ; then
|
|
51 |
@@ -73,10 +72,10 @@ then
|
|
52 |
AC_MSG_RESULT(yes)
|
|
53 |
fi
|
|
54 |
|
|
55 |
-AC_CHECK_FUNCS(strerror mtrace getuid geteuid)
|
|
56 |
AC_CHECK_FUNC(setreuid, [], [
|
|
57 |
AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null ;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
|
|
58 |
])
|
|
59 |
+AC_CHECK_FUNCS(getuid geteuid mtrace __secure_getenv setregid strerror iconv)
|
|
60 |
|
|
61 |
AM_GNU_GETTEXT
|
|
62 |
|
|
63 |
--- popt-1.7/popt.h.orig 2007-12-21 20:31:45.455134000 +0900
|
|
64 |
+++ popt-1.7/popt.h 2007-12-21 20:32:06.508963000 +0900
|
|
65 |
@@ -34,6 +34,8 @@
|
|
66 |
#define POPT_ARG_FLOAT 8 /*!< arg will be converted to float */
|
|
67 |
#define POPT_ARG_DOUBLE 9 /*!< arg will be converted to double */
|
|
68 |
|
|
69 |
+#define POPT_ARG_MAINCALL 10U /*!< return (*arg) (argc, argv) */
|
|
70 |
+
|
|
71 |
#define POPT_ARG_MASK 0x0000FFFF
|
|
72 |
/*@}*/
|
|
73 |
|
|
74 |
--- popt-1.7/popthelp.c.orig 2007-12-21 19:40:16.105761000 +0900
|
|
75 |
+++ popt-1.7/popthelp.c 2007-12-21 19:57:18.972191000 +0900
|
|
76 |
@@ -208,6 +208,8 @@ static void singleOptionHelp(FILE * fp,
|
|
77 |
char * defs = NULL;
|
|
78 |
char * left;
|
|
79 |
int nb = maxLeftCol + 1;
|
|
80 |
+ int displaypad = 0;
|
|
81 |
+ int xx;
|
|
82 |
|
|
83 |
/* Make sure there's more than enough room in target buffer. */
|
|
84 |
if (opt->longName) nb += strlen(opt->longName);
|
|
85 |
@@ -307,8 +309,25 @@ static void singleOptionHelp(FILE * fp,
|
|
86 |
break;
|
|
87 |
}
|
|
88 |
} else {
|
|
89 |
- *le++ = '=';
|
|
90 |
- strcpy(le, argDescrip); le += strlen(le);
|
|
91 |
+ size_t lelen;
|
|
92 |
+
|
|
93 |
+ *le++ = ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_MAINCALL)
|
|
94 |
+ ? ' ' : '=';
|
|
95 |
+ strcpy(le, argDescrip);
|
|
96 |
+ lelen = strlen(le);
|
|
97 |
+ le += lelen;
|
|
98 |
+
|
|
99 |
+#ifdef POPT_WCHAR_HACK
|
|
100 |
+ { const char * scopy = argDescrip;
|
|
101 |
+ mbstate_t t;
|
|
102 |
+ size_t n;
|
|
103 |
+
|
|
104 |
+ memset ((void *)&t, 0, sizeof (t)); /* In initial state. */
|
|
105 |
+ /* Determine number of characters. */
|
|
106 |
+ n = mbsrtowcs (NULL, &scopy, strlen(scopy), &t);
|
|
107 |
+ displaypad = (int) (lelen-n);
|
|
108 |
+ }
|
|
109 |
+#endif
|
|
110 |
}
|
|
111 |
if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
|
|
112 |
*le++ = ']';
|
|
113 |
@@ -317,9 +336,9 @@ static void singleOptionHelp(FILE * fp,
|
|
114 |
/*@=boundswrite@*/
|
|
115 |
|
|
116 |
if (help)
|
|
117 |
- fprintf(fp," %-*s ", maxLeftCol, left);
|
|
118 |
+ xx = POPT_fprintf(fp," %-*s ", (int)(maxLeftCol+displaypad), left);
|
|
119 |
else {
|
|
120 |
- fprintf(fp," %s\n", left);
|
|
121 |
+ xx = POPT_fprintf(fp," %s\n", left);
|
|
122 |
goto out;
|
|
123 |
}
|
|
124 |
|
|
125 |
@@ -335,22 +354,24 @@ static void singleOptionHelp(FILE * fp,
|
|
126 |
char format[16];
|
|
127 |
|
|
128 |
ch = help + lineLength - 1;
|
|
129 |
- while (ch > help && !isspace(*ch)) ch--;
|
|
130 |
+ while (ch > help && !_isspaceptr(ch))
|
|
131 |
+ ch = POPT_prev_char (ch);
|
|
132 |
if (ch == help) break; /* give up */
|
|
133 |
- while (ch > (help + 1) && isspace(*ch)) ch--;
|
|
134 |
+ while (ch > (help + 1) && _isspaceptr(ch))
|
|
135 |
+ ch = POPT_prev_char (ch);
|
|
136 |
ch++;
|
|
137 |
|
|
138 |
sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
|
|
139 |
/*@-formatconst@*/
|
|
140 |
- fprintf(fp, format, help, " ");
|
|
141 |
+ xx = POPT_fprintf(fp, format, help, " ");
|
|
142 |
/*@=formatconst@*/
|
|
143 |
help = ch;
|
|
144 |
- while (isspace(*help) && *help) help++;
|
|
145 |
+ while (_isspaceptr(help) && *help) help++;
|
|
146 |
helpLength = strlen(help);
|
|
147 |
}
|
|
148 |
/*@=boundsread@*/
|
|
149 |
|
|
150 |
- if (helpLength) fprintf(fp, "%s\n", help);
|
|
151 |
+ if (helpLength) xx = POPT_fprintf(fp, "%s\n", help);
|
|
152 |
|
|
153 |
out:
|
|
154 |
/*@-dependenttrans@*/
|
|
155 |
@@ -443,6 +464,7 @@ static void singleTableHelp(poptContext
|
|
156 |
{
|
|
157 |
const struct poptOption * opt;
|
|
158 |
const char *sub_transdom;
|
|
159 |
+ int xx;
|
|
160 |
|
|
161 |
if (table == poptAliasOptions) {
|
|
162 |
itemHelp(fp, con->aliases, con->numAliases, left, NULL);
|
|
163 |
@@ -466,7 +488,7 @@ static void singleTableHelp(poptContext
|
|
164 |
sub_transdom = translation_domain;
|
|
165 |
|
|
166 |
if (opt->descrip)
|
|
167 |
- fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
|
|
168 |
+ xx = POPT_fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
|
|
169 |
|
|
170 |
singleTableHelp(con, fp, opt->arg, left, sub_transdom);
|
|
171 |
}
|
|
172 |
--- popt-1.7/poptint.c.orig 1970-01-01 09:00:00.000000000 +0900
|
|
173 |
+++ popt-1.7/poptint.c 2007-12-21 19:57:56.997312000 +0900
|
|
174 |
@@ -0,0 +1,156 @@
|
|
175 |
+#include "system.h"
|
|
176 |
+#include <stdarg.h>
|
|
177 |
+#include "poptint.h"
|
|
178 |
+
|
|
179 |
+#ifdef HAVE_ICONV
|
|
180 |
+static /*@only@*/ /*@null@*/ char *
|
|
181 |
+strdup_locale_from_utf8 (/*@null@*/ char *buffer)
|
|
182 |
+ /*@*/
|
|
183 |
+{
|
|
184 |
+ char *codeset = NULL;
|
|
185 |
+ char *dest_str;
|
|
186 |
+ iconv_t fd;
|
|
187 |
+
|
|
188 |
+ if (buffer == NULL)
|
|
189 |
+ return NULL;
|
|
190 |
+
|
|
191 |
+#ifdef HAVE_LANGINFO_H
|
|
192 |
+/*@-type@*/
|
|
193 |
+ codeset = nl_langinfo (CODESET);
|
|
194 |
+/*@=type@*/
|
|
195 |
+#endif
|
|
196 |
+
|
|
197 |
+ if (codeset && strcmp(codeset, "UTF-8")
|
|
198 |
+ && (fd = iconv_open(codeset, "UTF-8")) != (iconv_t)-1)
|
|
199 |
+ {
|
|
200 |
+ char *pin = buffer;
|
|
201 |
+ char *pout = NULL;
|
|
202 |
+ size_t ib, ob, dest_size;
|
|
203 |
+ int done;
|
|
204 |
+ int is_error;
|
|
205 |
+ size_t err;
|
|
206 |
+ char *shift_pin = NULL;
|
|
207 |
+ int xx;
|
|
208 |
+
|
|
209 |
+ err = iconv(fd, NULL, &ib, &pout, &ob);
|
|
210 |
+ dest_size = ob = ib = strlen(buffer);
|
|
211 |
+ dest_str = pout = malloc((dest_size + 1) * sizeof(*dest_str));
|
|
212 |
+ if (dest_str)
|
|
213 |
+ *dest_str = '\0';
|
|
214 |
+ done = is_error = 0;
|
|
215 |
+ if (pout != NULL)
|
|
216 |
+ while (!done && !is_error) {
|
|
217 |
+ err = iconv(fd, &pin, &ib, &pout, &ob);
|
|
218 |
+
|
|
219 |
+ if (err == (size_t)-1) {
|
|
220 |
+ switch (errno) {
|
|
221 |
+ case EINVAL:
|
|
222 |
+ done = 1;
|
|
223 |
+ /*@switchbreak@*/ break;
|
|
224 |
+ case E2BIG:
|
|
225 |
+ { size_t used = pout - dest_str;
|
|
226 |
+ dest_size *= 2;
|
|
227 |
+ dest_str = realloc(dest_str, (dest_size + 1) * sizeof(*dest_str));
|
|
228 |
+ if (dest_str == NULL) {
|
|
229 |
+ is_error = 1;
|
|
230 |
+ continue;
|
|
231 |
+ }
|
|
232 |
+ pout = dest_str + used;
|
|
233 |
+ ob = dest_size - used;
|
|
234 |
+ } /*@switchbreak@*/ break;
|
|
235 |
+ case EILSEQ:
|
|
236 |
+ is_error = 1;
|
|
237 |
+ /*@switchbreak@*/ break;
|
|
238 |
+ default:
|
|
239 |
+ is_error = 1;
|
|
240 |
+ /*@switchbreak@*/ break;
|
|
241 |
+ }
|
|
242 |
+ } else {
|
|
243 |
+ if (shift_pin == NULL) {
|
|
244 |
+ shift_pin = pin;
|
|
245 |
+ pin = NULL;
|
|
246 |
+ ib = 0;
|
|
247 |
+ } else {
|
|
248 |
+ done = 1;
|
|
249 |
+ }
|
|
250 |
+ }
|
|
251 |
+ }
|
|
252 |
+ xx = iconv_close(fd);
|
|
253 |
+ if (pout)
|
|
254 |
+ *pout = '\0';
|
|
255 |
+ if (dest_str != NULL)
|
|
256 |
+ dest_str = xstrdup(dest_str);
|
|
257 |
+ } else {
|
|
258 |
+ dest_str = xstrdup(buffer);
|
|
259 |
+ }
|
|
260 |
+
|
|
261 |
+ return dest_str;
|
|
262 |
+}
|
|
263 |
+#endif
|
|
264 |
+
|
|
265 |
+/*@-mustmod@*/ /* LCL: can't see the ap modification. */
|
|
266 |
+static /*@only@*/ /*@null@*/ char *
|
|
267 |
+strdup_vprintf (const char *format, va_list ap)
|
|
268 |
+ /*@modifies ap @*/
|
|
269 |
+{
|
|
270 |
+ char *buffer;
|
|
271 |
+ char c;
|
|
272 |
+ va_list apc;
|
|
273 |
+ int xx;
|
|
274 |
+
|
|
275 |
+/*@-noeffectuncon -unrecog @*/
|
|
276 |
+ va_copy(apc, ap); /* XXX linux amd64/ppc needs a copy. */
|
|
277 |
+/*@=noeffectuncon =unrecog @*/
|
|
278 |
+
|
|
279 |
+ buffer = calloc(sizeof(*buffer), vsnprintf (&c, 1, format, ap) + 1);
|
|
280 |
+ if (buffer != NULL)
|
|
281 |
+ xx = vsprintf(buffer, format, apc);
|
|
282 |
+
|
|
283 |
+ va_end(apc);
|
|
284 |
+
|
|
285 |
+ return buffer;
|
|
286 |
+}
|
|
287 |
+/*@=mustmod@*/
|
|
288 |
+
|
|
289 |
+char *
|
|
290 |
+POPT_prev_char (const char *str)
|
|
291 |
+{
|
|
292 |
+ char *p = (char *)str;
|
|
293 |
+
|
|
294 |
+ while (1) {
|
|
295 |
+ p--;
|
|
296 |
+ if ((*p & 0xc0) != (char)0x80)
|
|
297 |
+ return (char *)p;
|
|
298 |
+ }
|
|
299 |
+}
|
|
300 |
+
|
|
301 |
+int
|
|
302 |
+POPT_fprintf (FILE* stream, const char *format, ...)
|
|
303 |
+{
|
|
304 |
+ int retval = 0;
|
|
305 |
+ va_list args;
|
|
306 |
+ char *buffer = NULL;
|
|
307 |
+#ifdef HAVE_ICONV
|
|
308 |
+ char *locale_str = NULL;
|
|
309 |
+#endif
|
|
310 |
+
|
|
311 |
+ va_start (args, format);
|
|
312 |
+ buffer = strdup_vprintf(format, args);
|
|
313 |
+ va_end (args);
|
|
314 |
+ if (buffer == NULL)
|
|
315 |
+ return retval;
|
|
316 |
+
|
|
317 |
+#ifdef HAVE_ICONV
|
|
318 |
+ locale_str = strdup_locale_from_utf8(buffer);
|
|
319 |
+ if (locale_str) {
|
|
320 |
+ retval = fprintf(stream, "%s", locale_str);
|
|
321 |
+ free(locale_str);
|
|
322 |
+ } else
|
|
323 |
+#endif
|
|
324 |
+ {
|
|
325 |
+ retval = fprintf(stream, "%s", buffer);
|
|
326 |
+ }
|
|
327 |
+ free (buffer);
|
|
328 |
+
|
|
329 |
+ return retval;
|
|
330 |
+}
|
|
331 |
--- popt-1.7/poptint.h.orig 2007-12-21 19:40:22.696680000 +0900
|
|
332 |
+++ popt-1.7/poptint.h 2007-12-21 20:00:39.593387000 +0900
|
|
333 |
@@ -113,4 +113,37 @@ struct poptContext_s {
|
|
334 |
|
|
335 |
#define N_(foo) foo
|
|
336 |
|
|
337 |
+#ifdef HAVE_ICONV
|
|
338 |
+#include <iconv.h>
|
|
339 |
+#if defined(__LCLINT__)
|
|
340 |
+/*@-declundef -incondefs @*/
|
|
341 |
+extern /*@only@*/ iconv_t iconv_open(const char *__tocode, const char *__fromcode)
|
|
342 |
+ /*@*/;
|
|
343 |
+
|
|
344 |
+extern size_t iconv(iconv_t __cd, /*@null@*/ char ** __inbuf,
|
|
345 |
+ /*@out@*/ size_t * __inbytesleft,
|
|
346 |
+ /*@out@*/ char ** __outbuf,
|
|
347 |
+ /*@out@*/ size_t * __outbytesleft)
|
|
348 |
+ /*@modifies __cd,
|
|
349 |
+ *__inbuf, *__inbytesleft, *__outbuf, *__outbytesleft @*/;
|
|
350 |
+
|
|
351 |
+extern int iconv_close(/*@only@*/ iconv_t __cd)
|
|
352 |
+ /*@modifies __cd @*/;
|
|
353 |
+/*@=declundef =incondefs @*/
|
|
354 |
+#endif
|
|
355 |
+#endif
|
|
356 |
+
|
|
357 |
+#ifdef HAVE_LANGINFO_H
|
|
358 |
+#include <langinfo.h>
|
|
359 |
+#if defined(__LCLINT__)
|
|
360 |
+/*@-declundef -incondefs @*/
|
|
361 |
+extern char *nl_langinfo (nl_item __item)
|
|
362 |
+ /*@*/;
|
|
363 |
+/*@=declundef =incondefs @*/
|
|
364 |
+#endif
|
|
365 |
+#endif
|
|
366 |
+
|
|
367 |
+int POPT_fprintf (FILE* steam, const char *format, ...);
|
|
368 |
+char *POPT_prev_char (const char *str);
|
|
369 |
+
|
|
370 |
#endif
|
|
371 |
--- popt-1.7/system.h.orig 2007-12-21 20:01:08.290683000 +0900
|
|
372 |
+++ popt-1.7/system.h 2007-12-21 20:01:59.455124000 +0900
|
|
373 |
@@ -13,6 +13,9 @@ extern __const __int32_t *__ctype_touppe
|
|
374 |
|
|
375 |
#include <ctype.h>
|
|
376 |
|
|
377 |
+/* XXX isspace(3) has i18n encoding signednesss issues on Solaris. */
|
|
378 |
+#define _isspaceptr(_chp) isspace((int)(*(unsigned char *)(_chp)))
|
|
379 |
+
|
|
380 |
#include <errno.h>
|
|
381 |
#include <fcntl.h>
|
|
382 |
#include <limits.h>
|