summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/uclibc
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2013-06-30 18:37:45 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-07-02 22:23:49 +0100
commit0ab7cfc8e9bcc3477a089f15d4fd0384d1e7fe13 (patch)
tree761b8b6ec5f0859b473fa24ff5a6772eb2928e9d /meta/recipes-core/uclibc
parent0188270f8cce65c4fb5937e0688c0ff70b0f2142 (diff)
downloadpoky-0ab7cfc8e9bcc3477a089f15d4fd0384d1e7fe13.tar.gz
uclibc: Remove 0.9.33 recipes
git recipes are stable enough and contains the fixes needed to run with modern systems e.g. systemd etc. Drop 0.9.33 We already use git as default. (From OE-Core rev: 05ae8f181e4e1699cf8e5d8bc20b3cbd4b532edf) Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/uclibc')
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33.inc23
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/argp-headers.patch583
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/argp-support.patch5192
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/compile-arm-fork-with-O2.patch21
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/define-MSG_CMSG_CLOEXEC.patch25
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/dup3.patch37
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/ldso_use_arm_dl_linux_resolve_in_thumb_mode.patch27
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/libc_symbols_include_bits_uclibc_config.patch23
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/mount.h-update.patch83
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/orign_path.patch185
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch407
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/powerpc_copysignl.patch113
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/remove_attribute_optimize_Os.patch179
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.distro190
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.machine14
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/uclibc-execvpe.patch163
-rw-r--r--meta/recipes-core/uclibc/uclibc-0.9.33/uclibc_enable_log2_test.patch35
-rw-r--r--meta/recipes-core/uclibc/uclibc-initial_0.9.33.bb36
-rw-r--r--meta/recipes-core/uclibc/uclibc_0.9.33.bb22
19 files changed, 0 insertions, 7358 deletions
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33.inc b/meta/recipes-core/uclibc/uclibc-0.9.33.inc
deleted file mode 100644
index 653f3c6206..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33.inc
+++ /dev/null
@@ -1,23 +0,0 @@
1SRCREV = "fec308fdfaf9f557ef5fb17c308c48259012b825"
2
3PR = "${INC_PR}.3"
4
5SRC_URI = "git://uclibc.org/uClibc.git;branch=${PV};protocol=git \
6 file://uClibc.machine \
7 file://uClibc.distro \
8 file://uclibc_enable_log2_test.patch \
9 file://ldso_use_arm_dl_linux_resolve_in_thumb_mode.patch \
10 file://powerpc_copysignl.patch \
11 file://argp-support.patch \
12 file://argp-headers.patch \
13 file://remove_attribute_optimize_Os.patch \
14 file://compile-arm-fork-with-O2.patch \
15 file://uclibc-execvpe.patch \
16 file://orign_path.patch \
17 file://dup3.patch \
18 file://define-MSG_CMSG_CLOEXEC.patch \
19 file://posix_fallocate.patch \
20 file://mount.h-update.patch \
21 "
22
23S = "${WORKDIR}/git"
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/argp-headers.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/argp-headers.patch
deleted file mode 100644
index b31b991846..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/argp-headers.patch
+++ /dev/null
@@ -1,583 +0,0 @@
1Added headers file needed by argp sources.
2
3Signed-off-by: Salvatore Cro <salvatore.cro at st.com>
4---
5 include/argp.h | 566 ++++++++++++++++++++++++++++++++++++++++++++
6 libc/argp/argp-fmtstream.h | 314 ++++++++++++++++++++++++
7 2 files changed, 880 insertions(+), 0 deletions(-)
8 create mode 100644 include/argp.h
9 create mode 100644 libc/argp/argp-fmtstream.h
10
11Upstream-Status: Pending
12
13Index: git/include/argp.h
14===================================================================
15--- /dev/null
16+++ git/include/argp.h
17@@ -0,0 +1,566 @@
18+/* Hierarchial argument parsing, layered over getopt.
19+ Copyright (C) 1995-1999, 2003, 2004, 2005, 2006, 2007, 2009
20+ Free Software Foundation, Inc.
21+ This file is part of the GNU C Library.
22+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
23+
24+ The GNU C Library is free software; you can redistribute it and/or
25+ modify it under the terms of the GNU Lesser General Public
26+ License as published by the Free Software Foundation; either
27+ version 2.1 of the License, or (at your option) any later version.
28+
29+ The GNU C Library is distributed in the hope that it will be useful,
30+ but WITHOUT ANY WARRANTY; without even the implied warranty of
31+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32+ Lesser General Public License for more details.
33+
34+ You should have received a copy of the GNU Lesser General Public
35+ License along with the GNU C Library; if not, write to the Free
36+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
37+ 02111-1307 USA.
38+
39+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
40+*/
41+
42+#ifndef _ARGP_H
43+#define _ARGP_H
44+
45+#include <stdio.h>
46+#include <ctype.h>
47+#include <limits.h>
48+
49+#define __need_error_t
50+#include <errno.h>
51+
52+#ifndef __const
53+# define __const const
54+#endif
55+
56+#ifndef __THROW
57+# define __THROW
58+#endif
59+#ifndef __NTH
60+# define __NTH(fct) fct __THROW
61+#endif
62+
63+#ifndef __attribute__
64+/* This feature is available in gcc versions 2.5 and later. */
65+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__)
66+# define __attribute__(Spec) /* empty */
67+# endif
68+/* The __-protected variants of `format' and `printf' attributes
69+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
70+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(__STRICT_ANSI__)
71+# define __format__ format
72+# define __printf__ printf
73+# endif
74+#endif
75+
76+/* GCC 2.95 and later have "__restrict"; C99 compilers have
77+ "restrict", and "configure" may have defined "restrict". */
78+#ifndef __restrict
79+# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
80+# if defined restrict || 199901L <= __STDC_VERSION__
81+# define __restrict restrict
82+# else
83+# define __restrict
84+# endif
85+# endif
86+#endif
87+
88+#ifndef __error_t_defined
89+typedef int error_t;
90+# define __error_t_defined
91+#endif
92+
93+#ifdef __cplusplus
94+extern "C" {
95+#endif
96+
97+/* A description of a particular option. A pointer to an array of
98+ these is passed in the OPTIONS field of an argp structure. Each option
99+ entry can correspond to one long option and/or one short option; more
100+ names for the same option can be added by following an entry in an option
101+ array with options having the OPTION_ALIAS flag set. */
102+struct argp_option
103+{
104+ /* The long option name. For more than one name for the same option, you
105+ can use following options with the OPTION_ALIAS flag set. */
106+ __const char *name;
107+
108+ /* What key is returned for this option. If > 0 and printable, then it's
109+ also accepted as a short option. */
110+ int key;
111+
112+ /* If non-NULL, this is the name of the argument associated with this
113+ option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
114+ __const char *arg;
115+
116+ /* OPTION_ flags. */
117+ int flags;
118+
119+ /* The doc string for this option. If both NAME and KEY are 0, This string
120+ will be printed outdented from the normal option column, making it
121+ useful as a group header (it will be the first thing printed in its
122+ group); in this usage, it's conventional to end the string with a `:'. */
123+ __const char *doc;
124+
125+ /* The group this option is in. In a long help message, options are sorted
126+ alphabetically within each group, and the groups presented in the order
127+ 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
128+ if this field 0 will inherit the group number of the previous entry, or
129+ zero if it's the first one, unless its a group header (NAME and KEY both
130+ 0), in which case, the previous entry + 1 is the default. Automagic
131+ options such as --help are put into group -1. */
132+ int group;
133+};
134+
135+/* The argument associated with this option is optional. */
136+#define OPTION_ARG_OPTIONAL 0x1
137+
138+/* This option isn't displayed in any help messages. */
139+#define OPTION_HIDDEN 0x2
140+
141+/* This option is an alias for the closest previous non-alias option. This
142+ means that it will be displayed in the same help entry, and will inherit
143+ fields other than NAME and KEY from the aliased option. */
144+#define OPTION_ALIAS 0x4
145+
146+/* This option isn't actually an option (and so should be ignored by the
147+ actual option parser), but rather an arbitrary piece of documentation that
148+ should be displayed in much the same manner as the options. If this flag
149+ is set, then the option NAME field is displayed unmodified (e.g., no `--'
150+ prefix is added) at the left-margin (where a *short* option would normally
151+ be displayed), and the documentation string in the normal place. For
152+ purposes of sorting, any leading whitespace and punctuation is ignored,
153+ except that if the first non-whitespace character is not `-', this entry
154+ is displayed after all options (and OPTION_DOC entries with a leading `-')
155+ in the same group. */
156+#define OPTION_DOC 0x8
157+
158+/* This option shouldn't be included in `long' usage messages (but is still
159+ included in help messages). This is mainly intended for options that are
160+ completely documented in an argp's ARGS_DOC field, in which case including
161+ the option in the generic usage list would be redundant. For instance,
162+ if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
163+ distinguish these two cases, -x should probably be marked
164+ OPTION_NO_USAGE. */
165+#define OPTION_NO_USAGE 0x10
166+
167+struct argp; /* fwd declare this type */
168+struct argp_state; /* " */
169+struct argp_child; /* " */
170+
171+/* The type of a pointer to an argp parsing function. */
172+typedef error_t (*argp_parser_t) (int __key, char *__arg,
173+ struct argp_state *__state);
174+
175+/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
176+ returns will simply be ignored. For user keys, this error will be turned
177+ into EINVAL (if the call to argp_parse is such that errors are propagated
178+ back to the user instead of exiting); returning EINVAL itself would result
179+ in an immediate stop to parsing in *all* cases. */
180+#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */
181+
182+/* Special values for the KEY argument to an argument parsing function.
183+ ARGP_ERR_UNKNOWN should be returned if they aren't understood.
184+
185+ The sequence of keys to a parsing function is either (where each
186+ uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):
187+
188+ INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
189+ or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
190+ or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized
191+
192+ The third case is where every parser returned ARGP_KEY_UNKNOWN for an
193+ argument, in which case parsing stops at that argument (returning the
194+ unparsed arguments to the caller of argp_parse if requested, or stopping
195+ with an error message if not).
196+
197+ If an error occurs (either detected by argp, or because the parsing
198+ function returned an error value), then the parser is called with
199+ ARGP_KEY_ERROR, and no further calls are made. */
200+
201+/* This is not an option at all, but rather a command line argument. If a
202+ parser receiving this key returns success, the fact is recorded, and the
203+ ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
204+ argument, a parser function decrements the NEXT field of the state it's
205+ passed, the option won't be considered processed; this is to allow you to
206+ actually modify the argument (perhaps into an option), and have it
207+ processed again. */
208+#define ARGP_KEY_ARG 0
209+/* There are remaining arguments not parsed by any parser, which may be found
210+ starting at (STATE->argv + STATE->next). If success is returned, but
211+ STATE->next left untouched, it's assumed that all arguments were consume,
212+ otherwise, the parser should adjust STATE->next to reflect any arguments
213+ consumed. */
214+#define ARGP_KEY_ARGS 0x1000006
215+/* There are no more command line arguments at all. */
216+#define ARGP_KEY_END 0x1000001
217+/* Because it's common to want to do some special processing if there aren't
218+ any non-option args, user parsers are called with this key if they didn't
219+ successfully process any non-option arguments. Called just before
220+ ARGP_KEY_END (where more general validity checks on previously parsed
221+ arguments can take place). */
222+#define ARGP_KEY_NO_ARGS 0x1000002
223+/* Passed in before any parsing is done. Afterwards, the values of each
224+ element of the CHILD_INPUT field, if any, in the state structure is
225+ copied to each child's state to be the initial value of the INPUT field. */
226+#define ARGP_KEY_INIT 0x1000003
227+/* Use after all other keys, including SUCCESS & END. */
228+#define ARGP_KEY_FINI 0x1000007
229+/* Passed in when parsing has successfully been completed (even if there are
230+ still arguments remaining). */
231+#define ARGP_KEY_SUCCESS 0x1000004
232+/* Passed in if an error occurs. */
233+#define ARGP_KEY_ERROR 0x1000005
234+
235+/* An argp structure contains a set of options declarations, a function to
236+ deal with parsing one, documentation string, a possible vector of child
237+ argp's, and perhaps a function to filter help output. When actually
238+ parsing options, getopt is called with the union of all the argp
239+ structures chained together through their CHILD pointers, with conflicts
240+ being resolved in favor of the first occurrence in the chain. */
241+struct argp
242+{
243+ /* An array of argp_option structures, terminated by an entry with both
244+ NAME and KEY having a value of 0. */
245+ __const struct argp_option *options;
246+
247+ /* What to do with an option from this structure. KEY is the key
248+ associated with the option, and ARG is any associated argument (NULL if
249+ none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
250+ returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
251+ parsing is stopped immediately, and that value is returned from
252+ argp_parse(). For special (non-user-supplied) values of KEY, see the
253+ ARGP_KEY_ definitions below. */
254+ argp_parser_t parser;
255+
256+ /* A string describing what other arguments are wanted by this program. It
257+ is only used by argp_usage to print the `Usage:' message. If it
258+ contains newlines, the strings separated by them are considered
259+ alternative usage patterns, and printed on separate lines (lines after
260+ the first are prefix by ` or: ' instead of `Usage:'). */
261+ __const char *args_doc;
262+
263+ /* If non-NULL, a string containing extra text to be printed before and
264+ after the options in a long help message (separated by a vertical tab
265+ `\v' character). */
266+ __const char *doc;
267+
268+ /* A vector of argp_children structures, terminated by a member with a 0
269+ argp field, pointing to child argps should be parsed with this one. Any
270+ conflicts are resolved in favor of this argp, or early argps in the
271+ CHILDREN list. This field is useful if you use libraries that supply
272+ their own argp structure, which you want to use in conjunction with your
273+ own. */
274+ __const struct argp_child *children;
275+
276+ /* If non-zero, this should be a function to filter the output of help
277+ messages. KEY is either a key from an option, in which case TEXT is
278+ that option's help text, or a special key from the ARGP_KEY_HELP_
279+ defines, below, describing which other help text TEXT is. The function
280+ should return either TEXT, if it should be used as-is, a replacement
281+ string, which should be malloced, and will be freed by argp, or NULL,
282+ meaning `print nothing'. The value for TEXT is *after* any translation
283+ has been done, so if any of the replacement text also needs translation,
284+ that should be done by the filter function. INPUT is either the input
285+ supplied to argp_parse, or NULL, if argp_help was called directly. */
286+ char *(*help_filter) (int __key, __const char *__text, void *__input);
287+
288+ /* If non-zero the strings used in the argp library are translated using
289+ the domain described by this string. Otherwise the currently installed
290+ default domain is used. */
291+ const char *argp_domain;
292+};
293+
294+/* Possible KEY arguments to a help filter function. */
295+#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
296+#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
297+#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
298+#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
299+ TEXT is NULL for this key. */
300+/* Explanatory note emitted when duplicate option arguments have been
301+ suppressed. */
302+#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
303+#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */
304+
305+/* When an argp has a non-zero CHILDREN field, it should point to a vector of
306+ argp_child structures, each of which describes a subsidiary argp. */
307+struct argp_child
308+{
309+ /* The child parser. */
310+ __const struct argp *argp;
311+
312+ /* Flags for this child. */
313+ int flags;
314+
315+ /* If non-zero, an optional header to be printed in help output before the
316+ child options. As a side-effect, a non-zero value forces the child
317+ options to be grouped together; to achieve this effect without actually
318+ printing a header string, use a value of "". */
319+ __const char *header;
320+
321+ /* Where to group the child options relative to the other (`consolidated')
322+ options in the parent argp; the values are the same as the GROUP field
323+ in argp_option structs, but all child-groupings follow parent options at
324+ a particular group level. If both this field and HEADER are zero, then
325+ they aren't grouped at all, but rather merged with the parent options
326+ (merging the child's grouping levels with the parents). */
327+ int group;
328+};
329+
330+/* Parsing state. This is provided to parsing functions called by argp,
331+ which may examine and, as noted, modify fields. */
332+struct argp_state
333+{
334+ /* The top level ARGP being parsed. */
335+ __const struct argp *root_argp;
336+
337+ /* The argument vector being parsed. May be modified. */
338+ int argc;
339+ char **argv;
340+
341+ /* The index in ARGV of the next arg that to be parsed. May be modified. */
342+ int next;
343+
344+ /* The flags supplied to argp_parse. May be modified. */
345+ unsigned flags;
346+
347+ /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
348+ number of the current arg, starting at zero, and incremented after each
349+ such call returns. At all other times, this is the number of such
350+ arguments that have been processed. */
351+ unsigned arg_num;
352+
353+ /* If non-zero, the index in ARGV of the first argument following a special
354+ `--' argument (which prevents anything following being interpreted as an
355+ option). Only set once argument parsing has proceeded past this point. */
356+ int quoted;
357+
358+ /* An arbitrary pointer passed in from the user. */
359+ void *input;
360+ /* Values to pass to child parsers. This vector will be the same length as
361+ the number of children for the current parser. */
362+ void **child_inputs;
363+
364+ /* For the parser's use. Initialized to 0. */
365+ void *hook;
366+
367+ /* The name used when printing messages. This is initialized to ARGV[0],
368+ or PROGRAM_INVOCATION_NAME if that is unavailable. */
369+ char *name;
370+
371+ /* Streams used when argp prints something. */
372+ FILE *err_stream; /* For errors; initialized to stderr. */
373+ FILE *out_stream; /* For information; initialized to stdout. */
374+
375+ void *pstate; /* Private, for use by argp. */
376+};
377+
378+/* Flags for argp_parse (note that the defaults are those that are
379+ convenient for program command line parsing): */
380+
381+/* Don't ignore the first element of ARGV. Normally (and always unless
382+ ARGP_NO_ERRS is set) the first element of the argument vector is
383+ skipped for option parsing purposes, as it corresponds to the program name
384+ in a command line. */
385+#define ARGP_PARSE_ARGV0 0x01
386+
387+/* Don't print error messages for unknown options to stderr; unless this flag
388+ is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
389+ name in the error messages. This flag implies ARGP_NO_EXIT (on the
390+ assumption that silent exiting upon errors is bad behaviour). */
391+#define ARGP_NO_ERRS 0x02
392+
393+/* Don't parse any non-option args. Normally non-option args are parsed by
394+ calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
395+ as the value. Since it's impossible to know which parse function wants to
396+ handle it, each one is called in turn, until one returns 0 or an error
397+ other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
398+ argp_parse returns prematurely (but with a return value of 0). If all
399+ args have been parsed without error, all parsing functions are called one
400+ last time with a key of ARGP_KEY_END. This flag needn't normally be set,
401+ as the normal behavior is to stop parsing as soon as some argument can't
402+ be handled. */
403+#define ARGP_NO_ARGS 0x04
404+
405+/* Parse options and arguments in the same order they occur on the command
406+ line -- normally they're rearranged so that all options come first. */
407+#define ARGP_IN_ORDER 0x08
408+
409+/* Don't provide the standard long option --help, which causes usage and
410+ option help information to be output to stdout, and exit (0) called. */
411+#define ARGP_NO_HELP 0x10
412+
413+/* Don't exit on errors (they may still result in error messages). */
414+#define ARGP_NO_EXIT 0x20
415+
416+/* Use the gnu getopt `long-only' rules for parsing arguments. */
417+#define ARGP_LONG_ONLY 0x40
418+
419+/* Turns off any message-printing/exiting options. */
420+#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
421+
422+/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
423+ FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
424+ index in ARGV of the first unparsed option is returned in it. If an
425+ unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
426+ routine returned a non-zero value, it is returned; otherwise 0 is
427+ returned. This function may also call exit unless the ARGP_NO_HELP flag
428+ is set. INPUT is a pointer to a value to be passed in to the parser. */
429+extern error_t argp_parse (__const struct argp *__restrict __argp,
430+ int __argc, char **__restrict __argv,
431+ unsigned __flags, int *__restrict __arg_index,
432+ void *__restrict __input);
433+
434+/* Global variables. */
435+
436+/* If defined or set by the user program to a non-zero value, then a default
437+ option --version is added (unless the ARGP_NO_HELP flag is used), which
438+ will print this string followed by a newline and exit (unless the
439+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
440+extern __const char *argp_program_version;
441+
442+/* If defined or set by the user program to a non-zero value, then a default
443+ option --version is added (unless the ARGP_NO_HELP flag is used), which
444+ calls this function with a stream to print the version to and a pointer to
445+ the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
446+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
447+extern void (*argp_program_version_hook) (FILE *__restrict __stream,
448+ struct argp_state *__restrict
449+ __state);
450+
451+/* If defined or set by the user program, it should point to string that is
452+ the bug-reporting address for the program. It will be printed by
453+ argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
454+ standard help messages), embedded in a sentence that says something like
455+ `Report bugs to ADDR.'. */
456+extern __const char *argp_program_bug_address;
457+
458+/* The exit status that argp will use when exiting due to a parsing error.
459+ If not defined or set by the user program, this defaults to EX_USAGE from
460+ <sysexits.h>. */
461+extern error_t argp_err_exit_status;
462+
463+/* Flags for argp_help. */
464+#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
465+#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
466+#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */
467+#define ARGP_HELP_LONG 0x08 /* a long help message. */
468+#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
469+#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
470+#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
471+#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
472+#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
473+ reflect ARGP_LONG_ONLY mode. */
474+
475+/* These ARGP_HELP flags are only understood by argp_state_help. */
476+#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
477+#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */
478+
479+/* The standard thing to do after a program command line parsing error, if an
480+ error message has already been printed. */
481+#define ARGP_HELP_STD_ERR \
482+ (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
483+/* The standard thing to do after a program command line parsing error, if no
484+ more specific error message has been printed. */
485+#define ARGP_HELP_STD_USAGE \
486+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
487+/* The standard thing to do in response to a --help option. */
488+#define ARGP_HELP_STD_HELP \
489+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
490+ | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
491+
492+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
493+ ARGP_HELP_*. */
494+extern void argp_help (__const struct argp *__restrict __argp,
495+ FILE *__restrict __stream,
496+ unsigned __flags, char *__restrict __name);
497+
498+/* The following routines are intended to be called from within an argp
499+ parsing routine (thus taking an argp_state structure as the first
500+ argument). They may or may not print an error message and exit, depending
501+ on the flags in STATE -- in any case, the caller should be prepared for
502+ them *not* to exit, and should return an appropiate error after calling
503+ them. [argp_usage & argp_error should probably be called argp_state_...,
504+ but they're used often enough that they should be short] */
505+
506+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
507+ from the set ARGP_HELP_*. */
508+extern void argp_state_help (__const struct argp_state *__restrict __state,
509+ FILE *__restrict __stream,
510+ unsigned int __flags);
511+/* Possibly output the standard usage message for ARGP to stderr and exit. */
512+extern void argp_usage (__const struct argp_state *__state);
513+
514+/* If appropriate, print the printf string FMT and following args, preceded
515+ by the program name and `:', to stderr, and followed by a `Try ... --help'
516+ message, then exit (1). */
517+extern void argp_error (__const struct argp_state *__restrict __state,
518+ __const char *__restrict __fmt, ...)
519+ __attribute__ ((__format__ (__printf__, 2, 3)));
520+/* Similar to the standard gnu error-reporting function error(), but will
521+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
522+ to STATE->err_stream. This is useful for argument parsing code that is
523+ shared between program startup (when exiting is desired) and runtime
524+ option parsing (when typically an error code is returned instead). The
525+ difference between this function and argp_error is that the latter is for
526+ *parsing errors*, and the former is for other problems that occur during
527+ parsing but don't reflect a (syntactic) problem with the input. */
528+extern void argp_failure (__const struct argp_state *__restrict __state,
529+ int __status, int __errnum,
530+ __const char *__restrict __fmt, ...)
531+ __attribute__ ((__format__ (__printf__, 4, 5)));
532+/* Returns true if the option OPT is a valid short option. */
533+extern int _option_is_short (__const struct argp_option *__opt) __THROW;
534+extern int __option_is_short (__const struct argp_option *__opt) __THROW;
535+
536+/* Returns true if the option OPT is in fact the last (unused) entry in an
537+ options array. */
538+extern int _option_is_end (__const struct argp_option *__opt) __THROW;
539+extern int __option_is_end (__const struct argp_option *__opt) __THROW;
540+
541+/* Return the input field for ARGP in the parser corresponding to STATE; used
542+ by the help routines. */
543+/* We think this should not be exported */
544+extern void *__argp_input (__const struct argp *__restrict __argp,
545+ __const struct argp_state *__restrict __state)
546+ __THROW;
547+
548+#ifdef __USE_EXTERN_INLINES
549+
550+# ifndef ARGP_EI
551+# define ARGP_EI __extern_inline
552+# endif
553+
554+ARGP_EI void
555+argp_usage (__const struct argp_state *__state)
556+{
557+ argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
558+}
559+
560+ARGP_EI int
561+__NTH (__option_is_short (__const struct argp_option *__opt))
562+{
563+ if (__opt->flags & OPTION_DOC)
564+ return 0;
565+ else
566+ {
567+ int __key = __opt->key;
568+ return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
569+ }
570+}
571+
572+ARGP_EI int
573+__NTH (__option_is_end (__const struct argp_option *__opt))
574+{
575+ return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
576+}
577+#endif /* Use extern inlines. */
578+
579+#ifdef __cplusplus
580+}
581+#endif
582+
583+#endif /* argp.h */
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/argp-support.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/argp-support.patch
deleted file mode 100644
index 3e9680f1fe..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/argp-support.patch
+++ /dev/null
@@ -1,5192 +0,0 @@
1From: Salvatore Cro <salvatore.cro at st.com>
2
3Argp is an advanced support for parsing unix-style argument vectors.
4In addition to the common getopt interface, it provides automatic response
5to `--help' and `--version' options and use of custom parser in conjunction
6with argp native option parser, among others.
7Argp support is required by elfutils package and prelink.
8
9In uClibc argp functionalities has been moved from C library to libuargp.so
10Further the libc.so linker script contains an AS_NEEDED entry so that
11it doesn't need to link libuargp.so explicitely.
12
13Signed-off-by: Salvatore Cro <salvatore.cro at st.com>
14Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono at st.com>
15Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>
16
17Upstream-Status: Pending
18
19---
20 Makefile.in | 8 +
21 Makerules | 8 +-
22 Rules.mak | 7 +
23 extra/Configs/Config.in | 17 +
24 libc/sysdeps/linux/common/bits/getopt_int.h | 136 ++
25 libc/unistd/getopt.c | 18 +-
26 libc/unistd/getopt_int.h | 134 --
27 libuargp/Makefile | 14 +
28 libuargp/Makefile.in | 76 ++
29 libuargp/argp-ba.c | 26 +
30 libuargp/argp-eexst.c | 32 +
31 libuargp/argp-fmtstream.c | 439 +++++++
32 libuargp/argp-fmtstream.h | 314 +++++
33 libuargp/argp-fs-xinl.c | 44 +
34 libuargp/argp-help.c | 1882 +++++++++++++++++++++++++++
35 libuargp/argp-parse.c | 949 ++++++++++++++
36 libuargp/argp-pv.c | 25 +
37 libuargp/argp-pvh.c | 32 +
38 libuargp/argp-xinl.c | 35 +
39 test/argp/Makefile | 7 +
40 test/argp/Makefile.in | 12 +
41 test/argp/argp-ex1.c | 15 +
42 test/argp/argp-ex2.c | 45 +
43 test/argp/argp-ex3.c | 153 +++
44 test/argp/argp-ex4.c | 167 +++
45 test/argp/argp-test.c | 209 +++
46 test/argp/bug-argp1.c | 26 +
47 test/argp/tst-argp1.c | 118 ++
48 test/argp/tst-argp2.c | 101 ++
49 29 files changed, 4911 insertions(+), 138 deletions(-)
50 create mode 100644 libc/sysdeps/linux/common/bits/getopt_int.h
51 delete mode 100644 libc/unistd/getopt_int.h
52 create mode 100644 libuargp/Makefile
53 create mode 100644 libuargp/Makefile.in
54 create mode 100644 libuargp/argp-ba.c
55 create mode 100644 libuargp/argp-eexst.c
56 create mode 100644 libuargp/argp-fmtstream.c
57 create mode 100644 libuargp/argp-fmtstream.h
58 create mode 100644 libuargp/argp-fs-xinl.c
59 create mode 100644 libuargp/argp-help.c
60 create mode 100644 libuargp/argp-parse.c
61 create mode 100644 libuargp/argp-pv.c
62 create mode 100644 libuargp/argp-pvh.c
63 create mode 100644 libuargp/argp-xinl.c
64 create mode 100644 test/argp/Makefile
65 create mode 100644 test/argp/Makefile.in
66 create mode 100644 test/argp/argp-ex1.c
67 create mode 100644 test/argp/argp-ex2.c
68 create mode 100644 test/argp/argp-ex3.c
69 create mode 100644 test/argp/argp-ex4.c
70 create mode 100644 test/argp/argp-test.c
71 create mode 100644 test/argp/bug-argp1.c
72 create mode 100644 test/argp/tst-argp1.c
73 create mode 100644 test/argp/tst-argp2.c
74
75Index: git/Makefile.in
76===================================================================
77--- git.orig/Makefile.in
78+++ git/Makefile.in
79@@ -48,6 +48,7 @@ include $(top_srcdir)libresolv/Makefile.
80 include $(top_srcdir)libutil/Makefile.in
81 include $(top_srcdir)libpthread/Makefile.in
82 include $(top_srcdir)librt/Makefile.in
83+include $(top_srcdir)libuargp/Makefile.in
84 include $(top_srcdir)libubacktrace/Makefile.in
85 include $(top_srcdir)extra/locale/Makefile.in
86
87@@ -230,6 +231,7 @@ HEADERS_RM- += sgtty.h
88 endif
89 HEADERS_RM-$(HAVE_SHARED) += dlfcn.h bits/dlfcn.h
90 HEADERS_RM-$(PTHREADS_DEBUG_SUPPORT) += thread_db.h
91+HEADERS_RM-$(UCLIBC_HAS_ARGP) += argp.h
92 HEADERS_RM-$(UCLIBC_HAS_BSD_ERR) += err.h
93 HEADERS_RM-$(UCLIBC_HAS_CRYPT) += crypt.h
94 HEADERS_RM-$(UCLIBC_HAS_EPOLL) += sys/epoll.h
95@@ -340,6 +342,12 @@ ifeq ($(UCLIBC_HAS_BACKTRACE),y)
96 echo "GROUP ( $(UBACKTRACE_ASNEEDED) )" >> $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
97 fi
98 endif
99+ifeq ($(UCLIBC_HAS_ARGP),y)
100+# Add the AS_NEEDED entry for libuargp.so
101+ if [ -f $(top_builddir)lib/libc.so -a -f $(PREFIX)$(RUNTIME_PREFIX)lib/$(SHARED_MAJORNAME) ] ; then \
102+ echo "GROUP ( $(UARGP_ASNEEDED) )" >> $(PREFIX)$(DEVEL_PREFIX)lib/libc.so; \
103+ fi
104+endif
105 ifeq ($(UCLIBC_HAS_THREADS),y)
106 ifneq ($(LINUXTHREADS_OLD),y)
107 ifeq ($(HARDWIRED_ABSPATH),y)
108Index: git/Makerules
109===================================================================
110--- git.orig/Makerules
111+++ git/Makerules
112@@ -32,12 +32,12 @@ shared_objs = $(libc-y:.o=.os) $(libc-sh
113 $(libpthread-so-y) $(libpthread-nonshared-y) $(libthread_db-so-y) \
114 $(libresolv-so-y) $(librt-so-y) \
115 $(ldso-y) \
116- $(libutil-so-y) $(libubacktrace-so-y)
117+ $(libutil-so-y) $(libubacktrace-so-y) $(libuargp-so-y)
118
119 ar_objs = $(libc-y) $(libc-static-y) $(libcrypt-a-y) \
120 $(libdl-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y) \
121 $(libpthread-a-y) $(libthread_db-a-y) \
122- $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y)
123+ $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y) $(libuargp-a-y)
124 ifeq ($(DOPIC),y)
125 ar_objs := $(ar_objs:.o=.os)
126 endif
127@@ -464,7 +464,7 @@ files.dep := $(libc-a-y) $(libc-so-y) $(
128 $(librt-a-y) $(librt-so-y) $(libresolv-a-y) $(libresolv-so-y) \
129 $(libcrypt-a-y) $(libcrypt-so-y) $(libutil-a-y) $(libutil-so-y) \
130 $(libnsl-a-y) $(libnsl-so-y) $(ldso-y) $(libdl-a-y) $(libdl-so-y) \
131- $(libubacktrace-a-y) $(libubacktrace-so-y)
132+ $(libubacktrace-a-y) $(libubacktrace-so-y) $(libuargp-so-y) $(libuargp-a-y)
133 .depends.dep := \
134 $(patsubst %.s,%.s.dep,$(filter %.s,$(files.dep))) \
135 $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \
136Index: git/Rules.mak
137===================================================================
138--- git.orig/Rules.mak
139+++ git/Rules.mak
140@@ -525,6 +525,13 @@ export UBACKTRACE_ASNEEDED:=$(shell $(LD
141 else
142 export UBACKTRACE_ASNEEDED:=""
143 endif
144+ifeq ($(UCLIBC_HAS_ARGP),y)
145+# Only used in installed libc.so linker script
146+UARGP_FULL_NAME := $(RUNTIME_PREFIX)lib/libuargp.so.$(MAJOR_VERSION)
147+export UARGP_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UARGP_FULL_NAME) )" || echo "$(UARGP_FULL_NAME)")
148+else
149+export UARGP_ASNEEDED:=""
150+endif
151 endif
152
153 # Add a bunch of extra pedantic annoyingly strict checks
154Index: git/extra/Configs/Config.in
155===================================================================
156--- git.orig/extra/Configs/Config.in
157+++ git/extra/Configs/Config.in
158@@ -1814,6 +1814,23 @@ config UCLIBC_HAS_GNU_GETSUBOPT
159 smaller SUSv3 compatible getsubopt().
160
161 Most people will answer Y.
162+
163+config UCLIBC_HAS_ARGP
164+ bool "Support argp (as standalone shared object)"
165+ default n
166+ help
167+ Argp is an interface for parsing unix-style argument vectors. Unlike
168+ the common getopt interface, it provides many advanced features in
169+ addition to parsing options, such as automatic output in response to
170+ `--help' and `--version' options.
171+ A library can export an argp option parser, which programs can easily
172+ use in conjunction with their own option parser.
173+ A new shared object "libuargp" is created. The "libc.so" linker script
174+ contains the AS_NEEDED entry for getting the libuargp linked automatically.
175+ Argp support is needed by elfutils libdw.
176+
177+ Most people can safely answer N.
178+
179 endmenu
180
181
182Index: git/libc/sysdeps/linux/common/bits/getopt_int.h
183===================================================================
184--- /dev/null
185+++ git/libc/sysdeps/linux/common/bits/getopt_int.h
186@@ -0,0 +1,136 @@
187+/* Internal declarations for getopt.
188+ Copyright (C) 1989-1994,1996-1999,2001,2003,2004
189+ Free Software Foundation, Inc.
190+ This file is part of the GNU C Library.
191+
192+ The GNU C Library is free software; you can redistribute it and/or
193+ modify it under the terms of the GNU Lesser General Public
194+ License as published by the Free Software Foundation; either
195+ version 2.1 of the License, or (at your option) any later version.
196+
197+ The GNU C Library is distributed in the hope that it will be useful,
198+ but WITHOUT ANY WARRANTY; without even the implied warranty of
199+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
200+ Lesser General Public License for more details.
201+
202+ You should have received a copy of the GNU Lesser General Public
203+ License along with the GNU C Library; if not, write to the Free
204+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
205+ 02111-1307 USA. */
206+
207+#ifndef _GETOPT_INT_H
208+#define _GETOPT_INT_H 1
209+
210+extern int _getopt_internal (int ___argc, char *const *___argv,
211+ const char *__shortopts,
212+ const struct option *__longopts, int *__longind,
213+ int __long_only) attribute_hidden;
214+
215+
216+/* Reentrant versions which can handle parsing multiple argument
217+ vectors at the same time. */
218+
219+/* For __ordering member */
220+enum {
221+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
222+};
223+
224+/* Data type for reentrant functions. */
225+
226+struct _getopt_data
227+{
228+ /* These have exactly the same meaning as the corresponding global
229+ variables, except that they are used for the reentrant
230+ versions of getopt. */
231+ int optind;
232+ int opterr;
233+ char *optarg;
234+ smalluint optopt; /* we store characters here, a byte is enough */
235+
236+ /* Internal members. */
237+
238+ /* True if the internal members have been initialized. */
239+ smallint __initialized;
240+
241+ /* Describe how to deal with options that follow non-option ARGV-elements.
242+
243+ If the caller did not specify anything,
244+ the default is REQUIRE_ORDER if the environment variable
245+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
246+
247+ REQUIRE_ORDER means don't recognize them as options;
248+ stop option processing when the first non-option is seen.
249+ This is what Unix does.
250+ This mode of operation is selected by either setting the environment
251+ variable POSIXLY_CORRECT, or using `+' as the first character
252+ of the list of option characters.
253+
254+ PERMUTE is the default. We permute the contents of ARGV as we
255+ scan, so that eventually all the non-options are at the end.
256+ This allows options to be given in any order, even with programs
257+ that were not written to expect this.
258+
259+ RETURN_IN_ORDER is an option available to programs that were
260+ written to expect options and other ARGV-elements in any order
261+ and that care about the ordering of the two. We describe each
262+ non-option ARGV-element as if it were the argument of an option
263+ with character code 1. Using `-' as the first character of the
264+ list of option characters selects this mode of operation.
265+
266+ The special argument `--' forces an end of option-scanning regardless
267+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
268+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
269+ smallint __ordering;
270+
271+ /* If the POSIXLY_CORRECT environment variable is set. */
272+ smallint __posixly_correct;
273+
274+ /* The next char to be scanned in the option-element
275+ in which the last option character we returned was found.
276+ This allows us to pick up the scan where we left off.
277+
278+ If this is zero, or a null string, it means resume the scan
279+ by advancing to the next ARGV-element. */
280+ char *__nextchar;
281+
282+
283+ /* Handle permutation of arguments. */
284+
285+ /* Describe the part of ARGV that contains non-options that have
286+ been skipped. `first_nonopt' is the index in ARGV of the first
287+ of them; `last_nonopt' is the index after the last of them. */
288+
289+ int __first_nonopt;
290+ int __last_nonopt;
291+
292+#if defined _LIBC && defined USE_NONOPTION_FLAGS
293+ int __nonoption_flags_max_len;
294+ int __nonoption_flags_len;
295+# endif
296+};
297+
298+/* The initializer is necessary to set OPTIND and OPTERR to their
299+ default values and to clear the initialization flag. */
300+#define _GETOPT_DATA_INITIALIZER { 1, 1 }
301+
302+#if 0 /* first is static on uClibc, the others not used */
303+extern int _getopt_internal_r (int ___argc, char *const *___argv,
304+ const char *__shortopts,
305+ const struct option *__longopts, int *__longind,
306+ int __long_only, struct _getopt_data *__data);
307+#endif
308+#if defined __UCLIBC_HAS_GNU_GETOPT__ || defined __UCLIBC_HAS_GETOPT_LONG__
309+#ifndef __need_getopt
310+extern int _getopt_long_r (int ___argc, char *const *___argv,
311+ const char *__shortopts,
312+ const struct option *__longopts, int *__longind,
313+ struct _getopt_data *__data);
314+
315+extern int _getopt_long_only_r (int ___argc, char *const *___argv,
316+ const char *__shortopts,
317+ const struct option *__longopts,
318+ int *__longind,
319+ struct _getopt_data *__data);
320+#endif
321+#endif
322+#endif /* getopt_int.h */
323Index: git/libc/unistd/getopt.c
324===================================================================
325--- git.orig/libc/unistd/getopt.c
326+++ git/libc/unistd/getopt.c
327@@ -119,7 +119,7 @@
328 they can distinguish the relative order of options and other arguments. */
329
330 #include <getopt.h>
331-#include "getopt_int.h"
332+#include <bits/getopt_int.h>
333
334
335 /* For communication from `getopt' to the caller.
336@@ -1183,6 +1183,15 @@ getopt_long (int argc, char *const *argv
337 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
338 }
339
340+int
341+_getopt_long_r (int argc, char *const *argv, const char *options,
342+ const struct option *long_options, int *opt_index,
343+ struct _getopt_data *d)
344+{
345+ return _getopt_internal_r (argc, argv, options, long_options, opt_index,
346+ 0, d);
347+}
348+
349 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
350 If an option that starts with '-' (not '--') doesn't match a long option,
351 but does match a short option, it is parsed as a short option
352@@ -1195,4 +1204,12 @@ getopt_long_only (int argc, char *const
353 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
354 }
355
356+int
357+_getopt_long_only_r (int argc, char *const *argv, const char *options,
358+ const struct option *long_options, int *opt_index,
359+ struct _getopt_data *d)
360+{
361+ return _getopt_internal_r (argc, argv, options, long_options, opt_index, 1, d);
362+}
363+
364 #endif /* Not ELIDE_CODE. */
365Index: git/libuargp/Makefile
366===================================================================
367--- /dev/null
368+++ git/libuargp/Makefile
369@@ -0,0 +1,14 @@
370+# Makefile for uClibc (libuargp)
371+#
372+# Copyright (C) 2010 STMicroelectronics Ltd
373+# Author(s): Filippo Arcidiacono <filippo.arcidiacono at st.com>
374+#
375+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
376+#
377+
378+top_srcdir=../
379+top_builddir=../
380+include $(top_builddir)Rules.mak
381+all: libs
382+include Makefile.in
383+include $(top_srcdir)Makerules
384Index: git/libuargp/Makefile.in
385===================================================================
386--- /dev/null
387+++ git/libuargp/Makefile.in
388@@ -0,0 +1,73 @@
389+# Makefile for uClibc (libuargp)
390+#
391+# Copyright (C) 2009, 2010 STMicroelectronics Ltd.
392+# Author(s): Salvatore Cro <salvatore.cro at st.com>
393+# - First implementation, embedded into libc
394+# Filippo Arcidiacono <filippo.arcidiacono at st.com>
395+# - Reworked for stand-alone libuargp implementation
396+
397+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
398+#
399+
400+CFLAGS-libuargp := -DNOT_IN_libc -DIS_IN_libuargp $(SSP_ALL_CFLAGS)
401+
402+LDFLAGS-libuargp.so := $(LDFLAGS)
403+
404+LIBS-libuargp.so := $(LIBS)
405+
406+libuargp_FULL_NAME := libuargp-$(VERSION).so
407+
408+libuargp_DIR := $(top_srcdir)libuargp
409+libuargp_OUT := $(top_builddir)libuargp
410+
411+libuargp_SRC-y :=
412+libuargp_SRC-$(UCLIBC_HAS_ARGP) := $(addsuffix .c,$(addprefix argp-, ba \
413+ eexst fmtstream fs-xinl help parse pv pvh xinl))
414+
415+CFLAGS-argp-xinl.c = -fgnu89-inline
416+
417+libuargp_SRC := $(addprefix $(libuargp_DIR)/,$(libuargp_SRC-y))
418+libuargp_OBJ := $(patsubst $(libuargp_DIR)/%.c,$(libuargp_OUT)/%.o,$(libuargp_SRC))
419+
420+libuargp_SRCS := $(libuargp_SRC)
421+libuargp_OBJS := $(libuargp_OBJ)
422+
423+ifeq ($(DOPIC),y)
424+libuargp-a-y := $(libuargp_OBJS:.o=.os)
425+else
426+libuargp-a-y := $(libuargp_OBJS)
427+endif
428+libuargp-so-y := $(libuargp_OBJS:.o=.os)
429+
430+lib-a-$(UCLIBC_HAS_ARGP) += $(top_builddir)lib/libuargp.a
431+lib-so-$(UCLIBC_HAS_ARGP) += $(top_builddir)lib/libuargp.so
432+
433+objclean-y += CLEAN_libuargp
434+
435+ifeq ($(DOMULTI),n)
436+ifeq ($(DOPIC),y)
437+$(top_builddir)lib/libuargp.so: $(top_builddir)lib/libuargp.a $(libc.depend)
438+else
439+$(top_builddir)lib/libuargp.so: $(libuargp_OUT)/libuargp_so.a $(libc.depend)
440+endif
441+ $(call link.so,$(libuargp_FULL_NAME),$(MAJOR_VERSION))
442+else
443+$(top_builddir)lib/libuargp.so: $(libuargp_OUT)/libuargp.oS $(libc.depend)
444+ $(call linkm.so,$(libuargp_FULL_NAME),$(MAJOR_VERSION))
445+endif
446+
447+$(libuargp_OUT)/libuargp_so.a: $(libuargp-so-y)
448+ $(Q)$(RM) $@
449+ $(do_ar)
450+
451+$(libuargp_OUT)/libuargp.oS: $(libuargp_SRCS)
452+ $(Q)$(RM) $@
453+ $(compile-m)
454+
455+$(top_builddir)lib/libuargp.a: $(libuargp-a-y)
456+ $(Q)$(INSTALL) -d $(dir $@)
457+ $(Q)$(RM) $@
458+ $(do_ar)
459+
460+CLEAN_libuargp:
461+ $(do_rm) $(addprefix $(libuargp_OUT)/*., o os oS a)
462Index: git/libuargp/argp-ba.c
463===================================================================
464--- /dev/null
465+++ git/libuargp/argp-ba.c
466@@ -0,0 +1,26 @@
467+/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
468+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
469+ This file is part of the GNU C Library.
470+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
471+
472+ The GNU C Library is free software; you can redistribute it and/or
473+ modify it under the terms of the GNU Lesser General Public
474+ License as published by the Free Software Foundation; either
475+ version 2.1 of the License, or (at your option) any later version.
476+
477+ The GNU C Library is distributed in the hope that it will be useful,
478+ but WITHOUT ANY WARRANTY; without even the implied warranty of
479+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
480+ Lesser General Public License for more details.
481+
482+ You should have received a copy of the GNU Lesser General Public
483+ License along with the GNU C Library; if not, write to the Free
484+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
485+ 02111-1307 USA. */
486+
487+/* If set by the user program, it should point to string that is the
488+ bug-reporting address for the program. It will be printed by argp_help if
489+ the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
490+ messages), embedded in a sentence that says something like `Report bugs to
491+ ADDR.'. */
492+const char *argp_program_bug_address;
493Index: git/libuargp/argp-eexst.c
494===================================================================
495--- /dev/null
496+++ git/libuargp/argp-eexst.c
497@@ -0,0 +1,32 @@
498+/* Default definition for ARGP_ERR_EXIT_STATUS
499+ Copyright (C) 1997 Free Software Foundation, Inc.
500+ This file is part of the GNU C Library.
501+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
502+
503+ The GNU C Library is free software; you can redistribute it and/or
504+ modify it under the terms of the GNU Lesser General Public
505+ License as published by the Free Software Foundation; either
506+ version 2.1 of the License, or (at your option) any later version.
507+
508+ The GNU C Library is distributed in the hope that it will be useful,
509+ but WITHOUT ANY WARRANTY; without even the implied warranty of
510+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
511+ Lesser General Public License for more details.
512+
513+ You should have received a copy of the GNU Lesser General Public
514+ License along with the GNU C Library; if not, write to the Free
515+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
516+ 02111-1307 USA. */
517+
518+#ifdef HAVE_CONFIG_H
519+# include <config.h>
520+#endif
521+
522+#include <sysexits.h>
523+
524+#include <argp.h>
525+
526+/* The exit status that argp will use when exiting due to a parsing error.
527+ If not defined or set by the user program, this defaults to EX_USAGE from
528+ <sysexits.h>. */
529+error_t argp_err_exit_status = EX_USAGE;
530Index: git/libuargp/argp-fmtstream.c
531===================================================================
532--- /dev/null
533+++ git/libuargp/argp-fmtstream.c
534@@ -0,0 +1,439 @@
535+/* Word-wrapping and line-truncating streams
536+ Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc.
537+ This file is part of the GNU C Library.
538+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
539+
540+ The GNU C Library is free software; you can redistribute it and/or
541+ modify it under the terms of the GNU Lesser General Public
542+ License as published by the Free Software Foundation; either
543+ version 2.1 of the License, or (at your option) any later version.
544+
545+ The GNU C Library is distributed in the hope that it will be useful,
546+ but WITHOUT ANY WARRANTY; without even the implied warranty of
547+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
548+ Lesser General Public License for more details.
549+
550+ You should have received a copy of the GNU Lesser General Public
551+ License along with the GNU C Library; if not, write to the Free
552+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
553+ 02111-1307 USA.
554+
555+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
556+*/
557+
558+/* This package emulates glibc `line_wrap_stream' semantics for systems that
559+ don't have that. */
560+
561+#ifdef HAVE_CONFIG_H
562+# include <config.h>
563+#endif
564+
565+#include <stdlib.h>
566+#include <string.h>
567+#include <errno.h>
568+#include <stdarg.h>
569+#include <ctype.h>
570+
571+#include "argp-fmtstream.h"
572+
573+#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
574+
575+#ifndef isblank
576+#define isblank(ch) ((ch)==' ' || (ch)=='\t')
577+#endif
578+
579+#if defined _LIBC && defined USE_IN_LIBIO
580+# include <wchar.h>
581+# include <libio/libioP.h>
582+# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
583+#else
584+# define __vsnprintf(s, l, f, a) vsnprintf (s, l, f, a)
585+#endif
586+
587+#define INIT_BUF_SIZE 200
588+#define PRINTF_SIZE_GUESS 150
589+
590+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
591+ written on it with LMARGIN spaces and limits them to RMARGIN columns
592+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
593+ replacing the whitespace before them with a newline and WMARGIN spaces.
594+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
595+ Returns NULL if there was an error. */
596+argp_fmtstream_t
597+__argp_make_fmtstream (FILE *stream,
598+ size_t lmargin, size_t rmargin, ssize_t wmargin)
599+{
600+ argp_fmtstream_t fs;
601+
602+ fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
603+ if (fs != NULL)
604+ {
605+ fs->stream = stream;
606+
607+ fs->lmargin = lmargin;
608+ fs->rmargin = rmargin;
609+ fs->wmargin = wmargin;
610+ fs->point_col = 0;
611+ fs->point_offs = 0;
612+
613+ fs->buf = (char *) malloc (INIT_BUF_SIZE);
614+ if (! fs->buf)
615+ {
616+ free (fs);
617+ fs = 0;
618+ }
619+ else
620+ {
621+ fs->p = fs->buf;
622+ fs->end = fs->buf + INIT_BUF_SIZE;
623+ }
624+ }
625+
626+ return fs;
627+}
628+#if 0
629+/* Not exported. */
630+#ifdef weak_alias
631+weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
632+#endif
633+#endif
634+
635+/* Flush FS to its stream, and free it (but don't close the stream). */
636+void
637+__argp_fmtstream_free (argp_fmtstream_t fs)
638+{
639+ __argp_fmtstream_update (fs);
640+ if (fs->p > fs->buf)
641+ {
642+#ifdef USE_IN_LIBIO
643+ __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
644+#else
645+ fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
646+#endif
647+ }
648+ free (fs->buf);
649+ free (fs);
650+}
651+#if 0
652+/* Not exported. */
653+#ifdef weak_alias
654+weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
655+#endif
656+#endif
657+
658+/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
659+ end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
660+void
661+__argp_fmtstream_update (argp_fmtstream_t fs)
662+{
663+ char *buf, *nl;
664+ size_t len;
665+
666+ /* Scan the buffer for newlines. */
667+ buf = fs->buf + fs->point_offs;
668+ while (buf < fs->p)
669+ {
670+ size_t r;
671+
672+ if (fs->point_col == 0 && fs->lmargin != 0)
673+ {
674+ /* We are starting a new line. Print spaces to the left margin. */
675+ const size_t pad = fs->lmargin;
676+ if (fs->p + pad < fs->end)
677+ {
678+ /* We can fit in them in the buffer by moving the
679+ buffer text up and filling in the beginning. */
680+ memmove (buf + pad, buf, fs->p - buf);
681+ fs->p += pad; /* Compensate for bigger buffer. */
682+ memset (buf, ' ', pad); /* Fill in the spaces. */
683+ buf += pad; /* Don't bother searching them. */
684+ }
685+ else
686+ {
687+ /* No buffer space for spaces. Must flush. */
688+ size_t i;
689+ for (i = 0; i < pad; i++)
690+ {
691+#ifdef USE_IN_LIBIO
692+ if (_IO_fwide (fs->stream, 0) > 0)
693+ putwc_unlocked (L' ', fs->stream);
694+ else
695+#endif
696+ putc_unlocked (' ', fs->stream);
697+ }
698+ }
699+ fs->point_col = pad;
700+ }
701+
702+ len = fs->p - buf;
703+ nl = memchr (buf, '\n', len);
704+
705+ if (fs->point_col < 0)
706+ fs->point_col = 0;
707+
708+ if (!nl)
709+ {
710+ /* The buffer ends in a partial line. */
711+
712+ if (fs->point_col + len < fs->rmargin)
713+ {
714+ /* The remaining buffer text is a partial line and fits
715+ within the maximum line width. Advance point for the
716+ characters to be written and stop scanning. */
717+ fs->point_col += len;
718+ break;
719+ }
720+ else
721+ /* Set the end-of-line pointer for the code below to
722+ the end of the buffer. */
723+ nl = fs->p;
724+ }
725+ else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
726+ {
727+ /* The buffer contains a full line that fits within the maximum
728+ line width. Reset point and scan the next line. */
729+ fs->point_col = 0;
730+ buf = nl + 1;
731+ continue;
732+ }
733+
734+ /* This line is too long. */
735+ r = fs->rmargin - 1;
736+
737+ if (fs->wmargin < 0)
738+ {
739+ /* Truncate the line by overwriting the excess with the
740+ newline and anything after it in the buffer. */
741+ if (nl < fs->p)
742+ {
743+ memmove (buf + (r - fs->point_col), nl, fs->p - nl);
744+ fs->p -= buf + (r - fs->point_col) - nl;
745+ /* Reset point for the next line and start scanning it. */
746+ fs->point_col = 0;
747+ buf += r + 1; /* Skip full line plus \n. */
748+ }
749+ else
750+ {
751+ /* The buffer ends with a partial line that is beyond the
752+ maximum line width. Advance point for the characters
753+ written, and discard those past the max from the buffer. */
754+ fs->point_col += len;
755+ fs->p -= fs->point_col - r;
756+ break;
757+ }
758+ }
759+ else
760+ {
761+ /* Do word wrap. Go to the column just past the maximum line
762+ width and scan back for the beginning of the word there.
763+ Then insert a line break. */
764+
765+ char *p, *nextline;
766+ int i;
767+
768+ p = buf + (r + 1 - fs->point_col);
769+ while (p >= buf && !isblank (*p))
770+ --p;
771+ nextline = p + 1; /* This will begin the next line. */
772+
773+ if (nextline > buf)
774+ {
775+ /* Swallow separating blanks. */
776+ if (p >= buf)
777+ do
778+ --p;
779+ while (p >= buf && isblank (*p));
780+ nl = p + 1; /* The newline will replace the first blank. */
781+ }
782+ else
783+ {
784+ /* A single word that is greater than the maximum line width.
785+ Oh well. Put it on an overlong line by itself. */
786+ p = buf + (r + 1 - fs->point_col);
787+ /* Find the end of the long word. */
788+ do
789+ ++p;
790+ while (p < nl && !isblank (*p));
791+ if (p == nl)
792+ {
793+ /* It already ends a line. No fussing required. */
794+ fs->point_col = 0;
795+ buf = nl + 1;
796+ continue;
797+ }
798+ /* We will move the newline to replace the first blank. */
799+ nl = p;
800+ /* Swallow separating blanks. */
801+ do
802+ ++p;
803+ while (isblank (*p));
804+ /* The next line will start here. */
805+ nextline = p;
806+ }
807+
808+ /* Note: There are a bunch of tests below for
809+ NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
810+ at the end of the buffer, and NEXTLINE is in fact empty (and so
811+ we need not be careful to maintain its contents). */
812+
813+ if ((nextline == buf + len + 1
814+ ? fs->end - nl < fs->wmargin + 1
815+ : nextline - (nl + 1) < fs->wmargin)
816+ && fs->p > nextline)
817+ {
818+ /* The margin needs more blanks than we removed. */
819+ if (fs->end - fs->p > fs->wmargin + 1)
820+ /* Make some space for them. */
821+ {
822+ size_t mv = fs->p - nextline;
823+ memmove (nl + 1 + fs->wmargin, nextline, mv);
824+ nextline = nl + 1 + fs->wmargin;
825+ len = nextline + mv - buf;
826+ *nl++ = '\n';
827+ }
828+ else
829+ /* Output the first line so we can use the space. */
830+ {
831+#if defined _LIBC && defined USE_IN_LIBIO
832+ __fxprintf (fs->stream, "%.*s\n",
833+ (int) (nl - fs->buf), fs->buf);
834+#else
835+ if (nl > fs->buf)
836+ fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
837+ putc_unlocked ('\n', fs->stream);
838+#endif
839+
840+ len += buf - fs->buf;
841+ nl = buf = fs->buf;
842+ }
843+ }
844+ else
845+ /* We can fit the newline and blanks in before
846+ the next word. */
847+ *nl++ = '\n';
848+
849+ if (nextline - nl >= fs->wmargin
850+ || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
851+ /* Add blanks up to the wrap margin column. */
852+ for (i = 0; i < fs->wmargin; ++i)
853+ *nl++ = ' ';
854+ else
855+ for (i = 0; i < fs->wmargin; ++i)
856+#ifdef USE_IN_LIBIO
857+ if (_IO_fwide (fs->stream, 0) > 0)
858+ putwc_unlocked (L' ', fs->stream);
859+ else
860+#endif
861+ putc_unlocked (' ', fs->stream);
862+
863+ /* Copy the tail of the original buffer into the current buffer
864+ position. */
865+ if (nl < nextline)
866+ memmove (nl, nextline, buf + len - nextline);
867+ len -= nextline - buf;
868+
869+ /* Continue the scan on the remaining lines in the buffer. */
870+ buf = nl;
871+
872+ /* Restore bufp to include all the remaining text. */
873+ fs->p = nl + len;
874+
875+ /* Reset the counter of what has been output this line. If wmargin
876+ is 0, we want to avoid the lmargin getting added, so we set
877+ point_col to a magic value of -1 in that case. */
878+ fs->point_col = fs->wmargin ? fs->wmargin : -1;
879+ }
880+ }
881+
882+ /* Remember that we've scanned as far as the end of the buffer. */
883+ fs->point_offs = fs->p - fs->buf;
884+}
885+
886+/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
887+ growing the buffer, or by flushing it. True is returned iff we succeed. */
888+int
889+__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
890+{
891+ if ((size_t) (fs->end - fs->p) < amount)
892+ {
893+ ssize_t wrote;
894+
895+ /* Flush FS's buffer. */
896+ __argp_fmtstream_update (fs);
897+
898+#if defined _LIBC && defined USE_IN_LIBIO
899+ __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
900+ wrote = fs->p - fs->buf;
901+#else
902+ wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
903+#endif
904+ if (wrote == fs->p - fs->buf)
905+ {
906+ fs->p = fs->buf;
907+ fs->point_offs = 0;
908+ }
909+ else
910+ {
911+ fs->p -= wrote;
912+ fs->point_offs -= wrote;
913+ memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
914+ return 0;
915+ }
916+
917+ if ((size_t) (fs->end - fs->buf) < amount)
918+ /* Gotta grow the buffer. */
919+ {
920+ size_t old_size = fs->end - fs->buf;
921+ size_t new_size = old_size + amount;
922+ char *new_buf;
923+
924+ if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
925+ {
926+ __set_errno (ENOMEM);
927+ return 0;
928+ }
929+
930+ fs->buf = new_buf;
931+ fs->end = new_buf + new_size;
932+ fs->p = fs->buf;
933+ }
934+ }
935+
936+ return 1;
937+}
938+
939+ssize_t
940+__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
941+{
942+ int out;
943+ size_t avail;
944+ size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
945+
946+ do
947+ {
948+ va_list args;
949+
950+ if (! __argp_fmtstream_ensure (fs, size_guess))
951+ return -1;
952+
953+ va_start (args, fmt);
954+ avail = fs->end - fs->p;
955+ out = __vsnprintf (fs->p, avail, fmt, args);
956+ va_end (args);
957+ if ((size_t) out >= avail)
958+ size_guess = out + 1;
959+ }
960+ while ((size_t) out >= avail);
961+
962+ fs->p += out;
963+
964+ return out;
965+}
966+#if 0
967+/* Not exported. */
968+#ifdef weak_alias
969+weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
970+#endif
971+#endif
972+
973+#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
974Index: git/libuargp/argp-fmtstream.h
975===================================================================
976--- /dev/null
977+++ git/libuargp/argp-fmtstream.h
978@@ -0,0 +1,314 @@
979+/* Word-wrapping and line-truncating streams.
980+ Copyright (C) 1997 Free Software Foundation, Inc.
981+ This file is part of the GNU C Library.
982+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
983+
984+ The GNU C Library is free software; you can redistribute it and/or
985+ modify it under the terms of the GNU Lesser General Public
986+ License as published by the Free Software Foundation; either
987+ version 2.1 of the License, or (at your option) any later version.
988+
989+ The GNU C Library is distributed in the hope that it will be useful,
990+ but WITHOUT ANY WARRANTY; without even the implied warranty of
991+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
992+ Lesser General Public License for more details.
993+
994+ You should have received a copy of the GNU Lesser General Public
995+ License along with the GNU C Library; if not, write to the Free
996+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
997+ 02111-1307 USA.
998+
999+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
1000+*/
1001+
1002+/* This package emulates glibc `line_wrap_stream' semantics for systems that
1003+ don't have that. If the system does have it, it is just a wrapper for
1004+ that. This header file is only used internally while compiling argp, and
1005+ shouldn't be installed. */
1006+
1007+#ifndef _ARGP_FMTSTREAM_H
1008+#define _ARGP_FMTSTREAM_H
1009+
1010+#include <stdio.h>
1011+#include <string.h>
1012+#include <unistd.h>
1013+
1014+#ifndef __attribute__
1015+/* This feature is available in gcc versions 2.5 and later. */
1016+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__)
1017+# define __attribute__(Spec) /* empty */
1018+# endif
1019+/* The __-protected variants of `format' and `printf' attributes
1020+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
1021+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(__STRICT_ANSI__)
1022+# define __format__ format
1023+# define __printf__ printf
1024+# endif
1025+#endif
1026+
1027+#if 0 /* uClibc: disabled */
1028+#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
1029+ || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
1030+/* line_wrap_stream is available, so use that. */
1031+#define ARGP_FMTSTREAM_USE_LINEWRAP
1032+#endif
1033+#else
1034+/* line_wrap stream NOT available */
1035+# undef ARGP_FMTSTREAM_USE_LINEWRAP
1036+#endif
1037+
1038+#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
1039+/* Just be a simple wrapper for line_wrap_stream; the semantics are
1040+ *slightly* different, as line_wrap_stream doesn't actually make a new
1041+ object, it just modifies the given stream (reversibly) to do
1042+ line-wrapping. Since we control who uses this code, it doesn't matter. */
1043+
1044+#include <linewrap.h>
1045+
1046+typedef FILE *argp_fmtstream_t;
1047+
1048+#define argp_make_fmtstream line_wrap_stream
1049+#define __argp_make_fmtstream line_wrap_stream
1050+#define argp_fmtstream_free line_unwrap_stream
1051+#define __argp_fmtstream_free line_unwrap_stream
1052+
1053+#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
1054+#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
1055+#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
1056+#define argp_fmtstream_puts(fs,str) fputs(str,fs)
1057+#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
1058+#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
1059+#define __argp_fmtstream_printf fprintf
1060+#define argp_fmtstream_printf fprintf
1061+
1062+#define __argp_fmtstream_lmargin line_wrap_lmargin
1063+#define argp_fmtstream_lmargin line_wrap_lmargin
1064+#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
1065+#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
1066+#define __argp_fmtstream_rmargin line_wrap_rmargin
1067+#define argp_fmtstream_rmargin line_wrap_rmargin
1068+#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
1069+#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
1070+#define __argp_fmtstream_wmargin line_wrap_wmargin
1071+#define argp_fmtstream_wmargin line_wrap_wmargin
1072+#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
1073+#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
1074+#define __argp_fmtstream_point line_wrap_point
1075+#define argp_fmtstream_point line_wrap_point
1076+
1077+#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
1078+/* Guess we have to define our own version. */
1079+
1080+#ifndef __const
1081+#define __const const
1082+#endif
1083+
1084+struct argp_fmtstream
1085+{
1086+ FILE *stream; /* The stream we're outputting to. */
1087+
1088+ size_t lmargin, rmargin; /* Left and right margins. */
1089+ ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
1090+
1091+ /* Point in buffer to which we've processed for wrapping, but not output. */
1092+ size_t point_offs;
1093+ /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
1094+ ssize_t point_col;
1095+
1096+ char *buf; /* Output buffer. */
1097+ char *p; /* Current end of text in BUF. */
1098+ char *end; /* Absolute end of BUF. */
1099+};
1100+
1101+typedef struct argp_fmtstream *argp_fmtstream_t;
1102+
1103+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
1104+ written on it with LMARGIN spaces and limits them to RMARGIN columns
1105+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
1106+ replacing the whitespace before them with a newline and WMARGIN spaces.
1107+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
1108+ Returns NULL if there was an error. */
1109+extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
1110+ size_t __lmargin,
1111+ size_t __rmargin,
1112+ ssize_t __wmargin);
1113+extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
1114+ size_t __lmargin,
1115+ size_t __rmargin,
1116+ ssize_t __wmargin);
1117+
1118+/* Flush __FS to its stream, and free it (but don't close the stream). */
1119+extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
1120+extern void argp_fmtstream_free (argp_fmtstream_t __fs);
1121+
1122+extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
1123+ __const char *__fmt, ...)
1124+ __attribute__ ((__format__ (printf, 2, 3)));
1125+extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
1126+ __const char *__fmt, ...)
1127+ __attribute__ ((__format__ (printf, 2, 3)));
1128+
1129+extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
1130+extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
1131+
1132+extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
1133+extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
1134+
1135+extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
1136+ __const char *__str, size_t __len);
1137+extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
1138+ __const char *__str, size_t __len);
1139+
1140+/* Access macros for various bits of state. */
1141+#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
1142+#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
1143+#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
1144+#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
1145+#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
1146+#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
1147+
1148+/* Set __FS's left margin to LMARGIN and return the old value. */
1149+extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
1150+ size_t __lmargin);
1151+extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
1152+ size_t __lmargin);
1153+
1154+/* Set __FS's right margin to __RMARGIN and return the old value. */
1155+extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
1156+ size_t __rmargin);
1157+extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
1158+ size_t __rmargin);
1159+
1160+/* Set __FS's wrap margin to __WMARGIN and return the old value. */
1161+extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
1162+ size_t __wmargin);
1163+extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
1164+ size_t __wmargin);
1165+
1166+/* Return the column number of the current output point in __FS. */
1167+extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
1168+extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
1169+
1170+/* Internal routines. */
1171+extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
1172+extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
1173+extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
1174+extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
1175+
1176+#ifdef __OPTIMIZE__
1177+/* Inline versions of above routines. */
1178+
1179+#if !_LIBC
1180+#define __argp_fmtstream_putc argp_fmtstream_putc
1181+#define __argp_fmtstream_puts argp_fmtstream_puts
1182+#define __argp_fmtstream_write argp_fmtstream_write
1183+#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
1184+#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
1185+#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
1186+#define __argp_fmtstream_point argp_fmtstream_point
1187+#define __argp_fmtstream_update _argp_fmtstream_update
1188+#define __argp_fmtstream_ensure _argp_fmtstream_ensure
1189+#endif
1190+
1191+#ifndef ARGP_FS_EI
1192+#define ARGP_FS_EI __extern_inline
1193+#endif
1194+
1195+ARGP_FS_EI size_t
1196+__argp_fmtstream_write (argp_fmtstream_t __fs,
1197+ __const char *__str, size_t __len)
1198+{
1199+ if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
1200+ {
1201+ memcpy (__fs->p, __str, __len);
1202+ __fs->p += __len;
1203+ return __len;
1204+ }
1205+ else
1206+ return 0;
1207+}
1208+
1209+ARGP_FS_EI int
1210+__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str)
1211+{
1212+ size_t __len = strlen (__str);
1213+ if (__len)
1214+ {
1215+ size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
1216+ return __wrote == __len ? 0 : -1;
1217+ }
1218+ else
1219+ return 0;
1220+}
1221+
1222+ARGP_FS_EI int
1223+__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
1224+{
1225+ if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
1226+ return *__fs->p++ = __ch;
1227+ else
1228+ return EOF;
1229+}
1230+
1231+/* Set __FS's left margin to __LMARGIN and return the old value. */
1232+ARGP_FS_EI size_t
1233+__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
1234+{
1235+ size_t __old;
1236+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1237+ __argp_fmtstream_update (__fs);
1238+ __old = __fs->lmargin;
1239+ __fs->lmargin = __lmargin;
1240+ return __old;
1241+}
1242+
1243+/* Set __FS's right margin to __RMARGIN and return the old value. */
1244+ARGP_FS_EI size_t
1245+__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
1246+{
1247+ size_t __old;
1248+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1249+ __argp_fmtstream_update (__fs);
1250+ __old = __fs->rmargin;
1251+ __fs->rmargin = __rmargin;
1252+ return __old;
1253+}
1254+
1255+/* Set FS's wrap margin to __WMARGIN and return the old value. */
1256+ARGP_FS_EI size_t
1257+__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
1258+{
1259+ size_t __old;
1260+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1261+ __argp_fmtstream_update (__fs);
1262+ __old = __fs->wmargin;
1263+ __fs->wmargin = __wmargin;
1264+ return __old;
1265+}
1266+
1267+/* Return the column number of the current output point in __FS. */
1268+ARGP_FS_EI size_t
1269+__argp_fmtstream_point (argp_fmtstream_t __fs)
1270+{
1271+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1272+ __argp_fmtstream_update (__fs);
1273+ return __fs->point_col >= 0 ? __fs->point_col : 0;
1274+}
1275+
1276+#if !_LIBC
1277+#undef __argp_fmtstream_putc
1278+#undef __argp_fmtstream_puts
1279+#undef __argp_fmtstream_write
1280+#undef __argp_fmtstream_set_lmargin
1281+#undef __argp_fmtstream_set_rmargin
1282+#undef __argp_fmtstream_set_wmargin
1283+#undef __argp_fmtstream_point
1284+#undef __argp_fmtstream_update
1285+#undef __argp_fmtstream_ensure
1286+#endif
1287+
1288+#endif /* __OPTIMIZE__ */
1289+
1290+#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
1291+
1292+#endif /* argp-fmtstream.h */
1293Index: git/libuargp/argp-fs-xinl.c
1294===================================================================
1295--- /dev/null
1296+++ git/libuargp/argp-fs-xinl.c
1297@@ -0,0 +1,44 @@
1298+/* Real definitions for extern inline functions in argp-fmtstream.h
1299+ Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
1300+ This file is part of the GNU C Library.
1301+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
1302+
1303+ The GNU C Library is free software; you can redistribute it and/or
1304+ modify it under the terms of the GNU Lesser General Public
1305+ License as published by the Free Software Foundation; either
1306+ version 2.1 of the License, or (at your option) any later version.
1307+
1308+ The GNU C Library is distributed in the hope that it will be useful,
1309+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1310+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1311+ Lesser General Public License for more details.
1312+
1313+ You should have received a copy of the GNU Lesser General Public
1314+ License along with the GNU C Library; if not, write to the Free
1315+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1316+ 02111-1307 USA. */
1317+
1318+#ifdef HAVE_CONFIG_H
1319+# include <config.h>
1320+#endif
1321+
1322+#define ARGP_FS_EI
1323+#undef __OPTIMIZE__
1324+#define __OPTIMIZE__ 1
1325+#include "argp-fmtstream.h"
1326+
1327+#if 0
1328+/* Not exported. */
1329+/* Add weak aliases. */
1330+#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias)
1331+
1332+weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc)
1333+weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts)
1334+weak_alias (__argp_fmtstream_write, argp_fmtstream_write)
1335+weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin)
1336+weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin)
1337+weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin)
1338+weak_alias (__argp_fmtstream_point, argp_fmtstream_point)
1339+
1340+#endif
1341+#endif
1342Index: git/libuargp/argp-help.c
1343===================================================================
1344--- /dev/null
1345+++ git/libuargp/argp-help.c
1346@@ -0,0 +1,1882 @@
1347+/* Hierarchial argument parsing help output
1348+ Copyright (C) 1995-2003, 2004, 2005, 2006, 2007
1349+ Free Software Foundation, Inc.
1350+ This file is part of the GNU C Library.
1351+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
1352+
1353+ The GNU C Library is free software; you can redistribute it and/or
1354+ modify it under the terms of the GNU Lesser General Public
1355+ License as published by the Free Software Foundation; either
1356+ version 2.1 of the License, or (at your option) any later version.
1357+
1358+ The GNU C Library is distributed in the hope that it will be useful,
1359+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1360+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1361+ Lesser General Public License for more details.
1362+
1363+ You should have received a copy of the GNU Lesser General Public
1364+ License along with the GNU C Library; if not, write to the Free
1365+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1366+ 02111-1307 USA.
1367+
1368+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
1369+*/
1370+
1371+#ifndef _GNU_SOURCE
1372+# define _GNU_SOURCE 1
1373+#endif
1374+
1375+#ifdef HAVE_CONFIG_H
1376+#include <config.h>
1377+#endif
1378+
1379+/* AIX requires this to be the first thing in the file. */
1380+#ifndef __GNUC__
1381+# if HAVE_ALLOCA_H || defined _LIBC
1382+# include <alloca.h>
1383+# else
1384+# ifdef _AIX
1385+#pragma alloca
1386+# else
1387+# ifndef alloca /* predefined by HP cc +Olibcalls */
1388+char *alloca ();
1389+# endif
1390+# endif
1391+# endif
1392+#endif
1393+
1394+#include <stddef.h>
1395+#include <stdlib.h>
1396+#include <string.h>
1397+#include <assert.h>
1398+#include <stdarg.h>
1399+#include <ctype.h>
1400+#include <limits.h>
1401+#ifdef _LIBC
1402+# include <wchar.h>
1403+#endif
1404+
1405+#include <features.h>
1406+#ifndef _
1407+/* This is for other GNU distributions with internationalized messages. */
1408+# if (defined HAVE_LIBINTL_H || defined _LIBC) && defined __UCLIBC_HAS_GETTEXT_AWARENESS__
1409+# include <libintl.h>
1410+# ifdef _LIBC
1411+# undef dgettext
1412+# define dgettext(domain, msgid) \
1413+ INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
1414+# endif
1415+# else
1416+# define dgettext(domain, msgid) (msgid)
1417+# endif
1418+#endif
1419+
1420+#ifndef _LIBC
1421+# if HAVE_STRERROR_R
1422+# if !HAVE_DECL_STRERROR_R
1423+char *strerror_r (int errnum, char *buf, size_t buflen);
1424+# endif
1425+# else
1426+# if !HAVE_DECL_STRERROR
1427+char *strerror (int errnum);
1428+# endif
1429+# endif
1430+#endif
1431+
1432+#include <argp.h>
1433+#include "argp-fmtstream.h"
1434+#include <stdbool.h>
1435+#include <stdint.h>
1436+
1437+#ifndef SIZE_MAX
1438+# define SIZE_MAX ((size_t) -1)
1439+#endif
1440+
1441+/* User-selectable (using an environment variable) formatting parameters.
1442+
1443+ These may be specified in an environment variable called `ARGP_HELP_FMT',
1444+ with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2
1445+ Where VALn must be a positive integer. The list of variables is in the
1446+ UPARAM_NAMES vector, below. */
1447+
1448+/* Default parameters. */
1449+#define DUP_ARGS 0 /* True if option argument can be duplicated. */
1450+#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */
1451+#define SHORT_OPT_COL 2 /* column in which short options start */
1452+#define LONG_OPT_COL 6 /* column in which long options start */
1453+#define DOC_OPT_COL 2 /* column in which doc options start */
1454+#define OPT_DOC_COL 29 /* column in which option text starts */
1455+#define HEADER_COL 1 /* column in which group headers are printed */
1456+#define USAGE_INDENT 12 /* indentation of wrapped usage lines */
1457+#define RMARGIN 79 /* right margin used for wrapping */
1458+
1459+/* User-selectable (using an environment variable) formatting parameters.
1460+ They must all be of type `int' for the parsing code to work. */
1461+struct uparams
1462+{
1463+ /* If true, arguments for an option are shown with both short and long
1464+ options, even when a given option has both, e.g. `-x ARG, --longx=ARG'.
1465+ If false, then if an option has both, the argument is only shown with
1466+ the long one, e.g., `-x, --longx=ARG', and a message indicating that
1467+ this really means both is printed below the options. */
1468+ int dup_args;
1469+
1470+ /* This is true if when DUP_ARGS is false, and some duplicate arguments have
1471+ been suppressed, an explanatory message should be printed. */
1472+ int dup_args_note;
1473+
1474+ /* Various output columns. */
1475+ int short_opt_col;
1476+ int long_opt_col;
1477+ int doc_opt_col;
1478+ int opt_doc_col;
1479+ int header_col;
1480+ int usage_indent;
1481+ int rmargin;
1482+};
1483+
1484+/* This is a global variable, as user options are only ever read once. */
1485+static struct uparams uparams = {
1486+ DUP_ARGS, DUP_ARGS_NOTE,
1487+ SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
1488+ USAGE_INDENT, RMARGIN
1489+};
1490+
1491+/* A particular uparam, and what the user name is. */
1492+struct uparam_name
1493+{
1494+ const char name[14]; /* User name. */
1495+ bool is_bool; /* Whether it's `boolean'. */
1496+ uint8_t uparams_offs; /* Location of the (int) field in UPARAMS. */
1497+};
1498+
1499+/* The name-field mappings we know about. */
1500+static const struct uparam_name uparam_names[] =
1501+{
1502+ { "dup-args", true, offsetof (struct uparams, dup_args) },
1503+ { "dup-args-note", true, offsetof (struct uparams, dup_args_note) },
1504+ { "short-opt-col", false, offsetof (struct uparams, short_opt_col) },
1505+ { "long-opt-col", false, offsetof (struct uparams, long_opt_col) },
1506+ { "doc-opt-col", false, offsetof (struct uparams, doc_opt_col) },
1507+ { "opt-doc-col", false, offsetof (struct uparams, opt_doc_col) },
1508+ { "header-col", false, offsetof (struct uparams, header_col) },
1509+ { "usage-indent", false, offsetof (struct uparams, usage_indent) },
1510+ { "rmargin", false, offsetof (struct uparams, rmargin) }
1511+};
1512+#define nuparam_names (sizeof (uparam_names) / sizeof (uparam_names[0]))
1513+
1514+/* Read user options from the environment, and fill in UPARAMS appropiately. */
1515+static void
1516+fill_in_uparams (const struct argp_state *state)
1517+{
1518+ const char *var = getenv ("ARGP_HELP_FMT");
1519+
1520+#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);
1521+
1522+ if (var)
1523+ /* Parse var. */
1524+ while (*var)
1525+ {
1526+ SKIPWS (var);
1527+
1528+ if (isalpha (*var))
1529+ {
1530+ size_t var_len;
1531+ const struct uparam_name *un;
1532+ int unspec = 0, val = 0;
1533+ const char *arg = var;
1534+
1535+ while (isalnum (*arg) || *arg == '-' || *arg == '_')
1536+ arg++;
1537+ var_len = arg - var;
1538+
1539+ SKIPWS (arg);
1540+
1541+ if (*arg == '\0' || *arg == ',')
1542+ unspec = 1;
1543+ else if (*arg == '=')
1544+ {
1545+ arg++;
1546+ SKIPWS (arg);
1547+ }
1548+
1549+ if (unspec)
1550+ {
1551+ if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
1552+ {
1553+ val = 0;
1554+ var += 3;
1555+ var_len -= 3;
1556+ }
1557+ else
1558+ val = 1;
1559+ }
1560+ else if (isdigit (*arg))
1561+ {
1562+ val = atoi (arg);
1563+ while (isdigit (*arg))
1564+ arg++;
1565+ SKIPWS (arg);
1566+ }
1567+
1568+ un = uparam_names;
1569+ size_t u;
1570+ for (u = 0; u < nuparam_names; ++un, ++u)
1571+ if (strlen (un->name) == var_len
1572+ && strncmp (var, un->name, var_len) == 0)
1573+ {
1574+ if (unspec && !un->is_bool)
1575+ argp_failure (state, 0, 0,
1576+ dgettext (state == NULL ? NULL
1577+ : state->root_argp->argp_domain,
1578+ "\
1579+%.*s: ARGP_HELP_FMT parameter requires a value"),
1580+ (int) var_len, var);
1581+ else
1582+ *(int *)((char *)&uparams + un->uparams_offs) = val;
1583+ break;
1584+ }
1585+ if (u == nuparam_names)
1586+ argp_failure (state, 0, 0,
1587+ dgettext (state == NULL ? NULL
1588+ : state->root_argp->argp_domain, "\
1589+%.*s: Unknown ARGP_HELP_FMT parameter"),
1590+ (int) var_len, var);
1591+
1592+ var = arg;
1593+ if (*var == ',')
1594+ var++;
1595+ }
1596+ else if (*var)
1597+ {
1598+ argp_failure (state, 0, 0,
1599+ dgettext (state == NULL ? NULL
1600+ : state->root_argp->argp_domain,
1601+ "Garbage in ARGP_HELP_FMT: %s"), var);
1602+ break;
1603+ }
1604+ }
1605+}
1606+
1607+/* Returns true if OPT hasn't been marked invisible. Visibility only affects
1608+ whether OPT is displayed or used in sorting, not option shadowing. */
1609+#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN))
1610+
1611+/* Returns true if OPT is an alias for an earlier option. */
1612+#define oalias(opt) ((opt)->flags & OPTION_ALIAS)
1613+
1614+/* Returns true if OPT is an documentation-only entry. */
1615+#define odoc(opt) ((opt)->flags & OPTION_DOC)
1616+
1617+/* Returns true if OPT is the end-of-list marker for a list of options. */
1618+#define oend(opt) __option_is_end (opt)
1619+
1620+/* Returns true if OPT has a short option. */
1621+#define oshort(opt) __option_is_short (opt)
1622+
1623+/*
1624+ The help format for a particular option is like:
1625+
1626+ -xARG, -yARG, --long1=ARG, --long2=ARG Documentation...
1627+
1628+ Where ARG will be omitted if there's no argument, for this option, or
1629+ will be surrounded by "[" and "]" appropiately if the argument is
1630+ optional. The documentation string is word-wrapped appropiately, and if
1631+ the list of options is long enough, it will be started on a separate line.
1632+ If there are no short options for a given option, the first long option is
1633+ indented slighly in a way that's supposed to make most long options appear
1634+ to be in a separate column.
1635+
1636+ For example, the following output (from ps):
1637+
1638+ -p PID, --pid=PID List the process PID
1639+ --pgrp=PGRP List processes in the process group PGRP
1640+ -P, -x, --no-parent Include processes without parents
1641+ -Q, --all-fields Don't elide unusable fields (normally if there's
1642+ some reason ps can't print a field for any
1643+ process, it's removed from the output entirely)
1644+ -r, --reverse, --gratuitously-long-reverse-option
1645+ Reverse the order of any sort
1646+ --session[=SID] Add the processes from the session SID (which
1647+ defaults to the sid of the current process)
1648+
1649+ Here are some more options:
1650+ -f ZOT, --foonly=ZOT Glork a foonly
1651+ -z, --zaza Snit a zar
1652+
1653+ -?, --help Give this help list
1654+ --usage Give a short usage message
1655+ -V, --version Print program version
1656+
1657+ The struct argp_option array for the above could look like:
1658+
1659+ {
1660+ {"pid", 'p', "PID", 0, "List the process PID"},
1661+ {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"},
1662+ {"no-parent", 'P', 0, 0, "Include processes without parents"},
1663+ {0, 'x', 0, OPTION_ALIAS},
1664+ {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
1665+ " if there's some reason ps can't"
1666+ " print a field for any process, it's"
1667+ " removed from the output entirely)" },
1668+ {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
1669+ {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
1670+ {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL,
1671+ "Add the processes from the session"
1672+ " SID (which defaults to the sid of"
1673+ " the current process)" },
1674+
1675+ {0,0,0,0, "Here are some more options:"},
1676+ {"foonly", 'f', "ZOT", 0, "Glork a foonly"},
1677+ {"zaza", 'z', 0, 0, "Snit a zar"},
1678+
1679+ {0}
1680+ }
1681+
1682+ Note that the last three options are automatically supplied by argp_parse,
1683+ unless you tell it not to with ARGP_NO_HELP.
1684+
1685+*/
1686+
1687+/* Returns true if CH occurs between BEG and END. */
1688+static int
1689+find_char (char ch, char *beg, char *end)
1690+{
1691+ while (beg < end)
1692+ if (*beg == ch)
1693+ return 1;
1694+ else
1695+ beg++;
1696+ return 0;
1697+}
1698+
1699+struct hol_cluster; /* fwd decl */
1700+
1701+struct hol_entry
1702+{
1703+ /* First option. */
1704+ const struct argp_option *opt;
1705+ /* Number of options (including aliases). */
1706+ unsigned num;
1707+
1708+ /* A pointers into the HOL's short_options field, to the first short option
1709+ letter for this entry. The order of the characters following this point
1710+ corresponds to the order of options pointed to by OPT, and there are at
1711+ most NUM. A short option recorded in a option following OPT is only
1712+ valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
1713+ probably been shadowed by some other entry). */
1714+ char *short_options;
1715+
1716+ /* Entries are sorted by their group first, in the order:
1717+ 1, 2, ..., n, 0, -m, ..., -2, -1
1718+ and then alphabetically within each group. The default is 0. */
1719+ int group;
1720+
1721+ /* The cluster of options this entry belongs to, or 0 if none. */
1722+ struct hol_cluster *cluster;
1723+
1724+ /* The argp from which this option came. */
1725+ const struct argp *argp;
1726+};
1727+
1728+/* A cluster of entries to reflect the argp tree structure. */
1729+struct hol_cluster
1730+{
1731+ /* A descriptive header printed before options in this cluster. */
1732+ const char *header;
1733+
1734+ /* Used to order clusters within the same group with the same parent,
1735+ according to the order in which they occurred in the parent argp's child
1736+ list. */
1737+ int index;
1738+
1739+ /* How to sort this cluster with respect to options and other clusters at the
1740+ same depth (clusters always follow options in the same group). */
1741+ int group;
1742+
1743+ /* The cluster to which this cluster belongs, or 0 if it's at the base
1744+ level. */
1745+ struct hol_cluster *parent;
1746+
1747+ /* The argp from which this cluster is (eventually) derived. */
1748+ const struct argp *argp;
1749+
1750+ /* The distance this cluster is from the root. */
1751+ int depth;
1752+
1753+ /* Clusters in a given hol are kept in a linked list, to make freeing them
1754+ possible. */
1755+ struct hol_cluster *next;
1756+};
1757+
1758+/* A list of options for help. */
1759+struct hol
1760+{
1761+ /* An array of hol_entry's. */
1762+ struct hol_entry *entries;
1763+ /* The number of entries in this hol. If this field is zero, the others
1764+ are undefined. */
1765+ unsigned num_entries;
1766+
1767+ /* A string containing all short options in this HOL. Each entry contains
1768+ pointers into this string, so the order can't be messed with blindly. */
1769+ char *short_options;
1770+
1771+ /* Clusters of entries in this hol. */
1772+ struct hol_cluster *clusters;
1773+};
1774+
1775+/* Create a struct hol from the options in ARGP. CLUSTER is the
1776+ hol_cluster in which these entries occur, or 0, if at the root. */
1777+static struct hol *
1778+make_hol (const struct argp *argp, struct hol_cluster *cluster)
1779+{
1780+ char *so;
1781+ const struct argp_option *o;
1782+ const struct argp_option *opts = argp->options;
1783+ struct hol_entry *entry;
1784+ unsigned num_short_options = 0;
1785+ struct hol *hol = malloc (sizeof (struct hol));
1786+
1787+ assert (hol);
1788+
1789+ hol->num_entries = 0;
1790+ hol->clusters = 0;
1791+
1792+ if (opts)
1793+ {
1794+ int cur_group = 0;
1795+
1796+ /* The first option must not be an alias. */
1797+ assert (! oalias (opts));
1798+
1799+ /* Calculate the space needed. */
1800+ for (o = opts; ! oend (o); o++)
1801+ {
1802+ if (! oalias (o))
1803+ hol->num_entries++;
1804+ if (oshort (o))
1805+ num_short_options++; /* This is an upper bound. */
1806+ }
1807+
1808+ hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
1809+ hol->short_options = malloc (num_short_options + 1);
1810+
1811+ assert (hol->entries && hol->short_options);
1812+#if SIZE_MAX <= UINT_MAX
1813+ assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
1814+#endif
1815+
1816+ /* Fill in the entries. */
1817+ so = hol->short_options;
1818+ for (o = opts, entry = hol->entries; ! oend (o); entry++)
1819+ {
1820+ entry->opt = o;
1821+ entry->num = 0;
1822+ entry->short_options = so;
1823+ entry->group = cur_group =
1824+ o->group
1825+ ? o->group
1826+ : ((!o->name && !o->key)
1827+ ? cur_group + 1
1828+ : cur_group);
1829+ entry->cluster = cluster;
1830+ entry->argp = argp;
1831+
1832+ do
1833+ {
1834+ entry->num++;
1835+ if (oshort (o) && ! find_char (o->key, hol->short_options, so))
1836+ /* O has a valid short option which hasn't already been used.*/
1837+ *so++ = o->key;
1838+ o++;
1839+ }
1840+ while (! oend (o) && oalias (o));
1841+ }
1842+ *so = '\0'; /* null terminated so we can find the length */
1843+ }
1844+
1845+ return hol;
1846+}
1847+
1848+/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the
1849+ associated argp child list entry), INDEX, and PARENT, and return a pointer
1850+ to it. ARGP is the argp that this cluster results from. */
1851+static struct hol_cluster *
1852+hol_add_cluster (struct hol *hol, int group, const char *header, int index,
1853+ struct hol_cluster *parent, const struct argp *argp)
1854+{
1855+ struct hol_cluster *cl = malloc (sizeof (struct hol_cluster));
1856+ if (cl)
1857+ {
1858+ cl->group = group;
1859+ cl->header = header;
1860+
1861+ cl->index = index;
1862+ cl->parent = parent;
1863+ cl->argp = argp;
1864+ cl->depth = parent ? parent->depth + 1 : 0;
1865+
1866+ cl->next = hol->clusters;
1867+ hol->clusters = cl;
1868+ }
1869+ return cl;
1870+}
1871+
1872+/* Free HOL and any resources it uses. */
1873+static void
1874+hol_free (struct hol *hol)
1875+{
1876+ struct hol_cluster *cl = hol->clusters;
1877+
1878+ while (cl)
1879+ {
1880+ struct hol_cluster *next = cl->next;
1881+ free (cl);
1882+ cl = next;
1883+ }
1884+
1885+ if (hol->num_entries > 0)
1886+ {
1887+ free (hol->entries);
1888+ free (hol->short_options);
1889+ }
1890+
1891+ free (hol);
1892+}
1893+
1894+static int
1895+hol_entry_short_iterate (const struct hol_entry *entry,
1896+ int (*func)(const struct argp_option *opt,
1897+ const struct argp_option *real,
1898+ const char *domain, void *cookie),
1899+ const char *domain, void *cookie)
1900+{
1901+ unsigned nopts;
1902+ int val = 0;
1903+ const struct argp_option *opt, *real = entry->opt;
1904+ char *so = entry->short_options;
1905+
1906+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
1907+ if (oshort (opt) && *so == opt->key)
1908+ {
1909+ if (!oalias (opt))
1910+ real = opt;
1911+ if (ovisible (opt))
1912+ val = (*func)(opt, real, domain, cookie);
1913+ so++;
1914+ }
1915+
1916+ return val;
1917+}
1918+
1919+static __inline__ int
1920+__attribute__ ((always_inline))
1921+hol_entry_long_iterate (const struct hol_entry *entry,
1922+ int (*func)(const struct argp_option *opt,
1923+ const struct argp_option *real,
1924+ const char *domain, void *cookie),
1925+ const char *domain, void *cookie)
1926+{
1927+ unsigned nopts;
1928+ int val = 0;
1929+ const struct argp_option *opt, *real = entry->opt;
1930+
1931+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
1932+ if (opt->name)
1933+ {
1934+ if (!oalias (opt))
1935+ real = opt;
1936+ if (ovisible (opt))
1937+ val = (*func)(opt, real, domain, cookie);
1938+ }
1939+
1940+ return val;
1941+}
1942+
1943+/* Iterator that returns true for the first short option. */
1944+static __inline__ int
1945+until_short (const struct argp_option *opt, const struct argp_option *real,
1946+ const char *domain, void *cookie)
1947+{
1948+ return oshort (opt) ? opt->key : 0;
1949+}
1950+
1951+/* Returns the first valid short option in ENTRY, or 0 if there is none. */
1952+static char
1953+hol_entry_first_short (const struct hol_entry *entry)
1954+{
1955+ return hol_entry_short_iterate (entry, until_short,
1956+ entry->argp->argp_domain, 0);
1957+}
1958+
1959+/* Returns the first valid long option in ENTRY, or 0 if there is none. */
1960+static const char *
1961+hol_entry_first_long (const struct hol_entry *entry)
1962+{
1963+ const struct argp_option *opt;
1964+ unsigned num;
1965+ for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
1966+ if (opt->name && ovisible (opt))
1967+ return opt->name;
1968+ return 0;
1969+}
1970+
1971+/* Returns the entry in HOL with the long option name NAME, or 0 if there is
1972+ none. */
1973+static struct hol_entry *
1974+hol_find_entry (struct hol *hol, const char *name)
1975+{
1976+ struct hol_entry *entry = hol->entries;
1977+ unsigned num_entries = hol->num_entries;
1978+
1979+ while (num_entries-- > 0)
1980+ {
1981+ const struct argp_option *opt = entry->opt;
1982+ unsigned num_opts = entry->num;
1983+
1984+ while (num_opts-- > 0)
1985+ if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
1986+ return entry;
1987+ else
1988+ opt++;
1989+
1990+ entry++;
1991+ }
1992+
1993+ return 0;
1994+}
1995+
1996+/* If an entry with the long option NAME occurs in HOL, set it's special
1997+ sort position to GROUP. */
1998+static void
1999+hol_set_group (struct hol *hol, const char *name, int group)
2000+{
2001+ struct hol_entry *entry = hol_find_entry (hol, name);
2002+ if (entry)
2003+ entry->group = group;
2004+}
2005+
2006+/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1.
2007+ EQ is what to return if GROUP1 and GROUP2 are the same. */
2008+static int
2009+group_cmp (int group1, int group2, int eq)
2010+{
2011+ if (group1 == group2)
2012+ return eq;
2013+ else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0))
2014+ return group1 - group2;
2015+ else
2016+ return group2 - group1;
2017+}
2018+
2019+/* Compare clusters CL1 & CL2 by the order that they should appear in
2020+ output. */
2021+static int
2022+hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
2023+{
2024+ /* If one cluster is deeper than the other, use its ancestor at the same
2025+ level, so that finding the common ancestor is straightforward. */
2026+ while (cl1->depth > cl2->depth)
2027+ cl1 = cl1->parent;
2028+ while (cl2->depth > cl1->depth)
2029+ cl2 = cl2->parent;
2030+
2031+ /* Now reduce both clusters to their ancestors at the point where both have
2032+ a common parent; these can be directly compared. */
2033+ while (cl1->parent != cl2->parent)
2034+ cl1 = cl1->parent, cl2 = cl2->parent;
2035+
2036+ return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index);
2037+}
2038+
2039+/* Return the ancestor of CL that's just below the root (i.e., has a parent
2040+ of 0). */
2041+static struct hol_cluster *
2042+hol_cluster_base (struct hol_cluster *cl)
2043+{
2044+ while (cl->parent)
2045+ cl = cl->parent;
2046+ return cl;
2047+}
2048+
2049+/* Return true if CL1 is a child of CL2. */
2050+static int
2051+hol_cluster_is_child (const struct hol_cluster *cl1,
2052+ const struct hol_cluster *cl2)
2053+{
2054+ while (cl1 && cl1 != cl2)
2055+ cl1 = cl1->parent;
2056+ return cl1 == cl2;
2057+}
2058+
2059+/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail
2060+ that should be used for comparisons, and returns true iff it should be
2061+ treated as a non-option. */
2062+static int
2063+canon_doc_option (const char **name)
2064+{
2065+ int non_opt;
2066+ /* Skip initial whitespace. */
2067+ while (isspace (**name))
2068+ (*name)++;
2069+ /* Decide whether this looks like an option (leading `-') or not. */
2070+ non_opt = (**name != '-');
2071+ /* Skip until part of name used for sorting. */
2072+ while (**name && !isalnum (**name))
2073+ (*name)++;
2074+ return non_opt;
2075+}
2076+
2077+/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
2078+ listing. */
2079+static int
2080+hol_entry_cmp (const struct hol_entry *entry1,
2081+ const struct hol_entry *entry2)
2082+{
2083+ /* The group numbers by which the entries should be ordered; if either is
2084+ in a cluster, then this is just the group within the cluster. */
2085+ int group1 = entry1->group, group2 = entry2->group;
2086+
2087+ if (entry1->cluster != entry2->cluster)
2088+ {
2089+ /* The entries are not within the same cluster, so we can't compare them
2090+ directly, we have to use the appropiate clustering level too. */
2091+ if (! entry1->cluster)
2092+ /* ENTRY1 is at the `base level', not in a cluster, so we have to
2093+ compare it's group number with that of the base cluster in which
2094+ ENTRY2 resides. Note that if they're in the same group, the
2095+ clustered option always comes laster. */
2096+ return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
2097+ else if (! entry2->cluster)
2098+ /* Likewise, but ENTRY2's not in a cluster. */
2099+ return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1);
2100+ else
2101+ /* Both entries are in clusters, we can just compare the clusters. */
2102+ return hol_cluster_cmp (entry1->cluster, entry2->cluster);
2103+ }
2104+ else if (group1 == group2)
2105+ /* The entries are both in the same cluster and group, so compare them
2106+ alphabetically. */
2107+ {
2108+ int short1 = hol_entry_first_short (entry1);
2109+ int short2 = hol_entry_first_short (entry2);
2110+ int doc1 = odoc (entry1->opt);
2111+ int doc2 = odoc (entry2->opt);
2112+ const char *long1 = hol_entry_first_long (entry1);
2113+ const char *long2 = hol_entry_first_long (entry2);
2114+
2115+ if (doc1)
2116+ doc1 = long1 != NULL && canon_doc_option (&long1);
2117+ if (doc2)
2118+ doc2 = long2 != NULL && canon_doc_option (&long2);
2119+
2120+ if (doc1 != doc2)
2121+ /* `documentation' options always follow normal options (or
2122+ documentation options that *look* like normal options). */
2123+ return doc1 - doc2;
2124+ else if (!short1 && !short2 && long1 && long2)
2125+ /* Only long options. */
2126+ return strcasecmp (long1, long2);
2127+ else
2128+ /* Compare short/short, long/short, short/long, using the first
2129+ character of long options. Entries without *any* valid
2130+ options (such as options with OPTION_HIDDEN set) will be put
2131+ first, but as they're not displayed, it doesn't matter where
2132+ they are. */
2133+ {
2134+ char first1 = short1 ? short1 : long1 ? *long1 : 0;
2135+ char first2 = short2 ? short2 : long2 ? *long2 : 0;
2136+#ifdef _tolower
2137+ int lower_cmp = _tolower (first1) - _tolower (first2);
2138+#else
2139+ int lower_cmp = tolower (first1) - tolower (first2);
2140+#endif
2141+ /* Compare ignoring case, except when the options are both the
2142+ same letter, in which case lower-case always comes first. */
2143+ return lower_cmp ? lower_cmp : first2 - first1;
2144+ }
2145+ }
2146+ else
2147+ /* Within the same cluster, but not the same group, so just compare
2148+ groups. */
2149+ return group_cmp (group1, group2, 0);
2150+}
2151+
2152+/* Version of hol_entry_cmp with correct signature for qsort. */
2153+static int
2154+hol_entry_qcmp (const void *entry1_v, const void *entry2_v)
2155+{
2156+ return hol_entry_cmp (entry1_v, entry2_v);
2157+}
2158+
2159+/* Sort HOL by group and alphabetically by option name (with short options
2160+ taking precedence over long). Since the sorting is for display purposes
2161+ only, the shadowing of options isn't effected. */
2162+static void
2163+hol_sort (struct hol *hol)
2164+{
2165+ if (hol->num_entries > 0)
2166+ qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry),
2167+ hol_entry_qcmp);
2168+}
2169+
2170+/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow
2171+ any in MORE with the same name. */
2172+static void
2173+hol_append (struct hol *hol, struct hol *more)
2174+{
2175+ struct hol_cluster **cl_end = &hol->clusters;
2176+
2177+ /* Steal MORE's cluster list, and add it to the end of HOL's. */
2178+ while (*cl_end)
2179+ cl_end = &(*cl_end)->next;
2180+ *cl_end = more->clusters;
2181+ more->clusters = 0;
2182+
2183+ /* Merge entries. */
2184+ if (more->num_entries > 0)
2185+ {
2186+ if (hol->num_entries == 0)
2187+ {
2188+ hol->num_entries = more->num_entries;
2189+ hol->entries = more->entries;
2190+ hol->short_options = more->short_options;
2191+ more->num_entries = 0; /* Mark MORE's fields as invalid. */
2192+ }
2193+ else
2194+ /* Append the entries in MORE to those in HOL, taking care to only add
2195+ non-shadowed SHORT_OPTIONS values. */
2196+ {
2197+ unsigned left;
2198+ char *so, *more_so;
2199+ struct hol_entry *e;
2200+ unsigned num_entries = hol->num_entries + more->num_entries;
2201+ struct hol_entry *entries =
2202+ malloc (num_entries * sizeof (struct hol_entry));
2203+ unsigned hol_so_len = strlen (hol->short_options);
2204+ char *short_options =
2205+ malloc (hol_so_len + strlen (more->short_options) + 1);
2206+
2207+ assert (entries && short_options);
2208+#if SIZE_MAX <= UINT_MAX
2209+ assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry));
2210+#endif
2211+
2212+ mempcpy (mempcpy (entries, hol->entries,
2213+ hol->num_entries * sizeof (struct hol_entry)),
2214+ more->entries,
2215+ more->num_entries * sizeof (struct hol_entry));
2216+
2217+ mempcpy (short_options, hol->short_options, hol_so_len);
2218+
2219+ /* Fix up the short options pointers from HOL. */
2220+ for (e = entries, left = hol->num_entries; left > 0; e++, left--)
2221+ e->short_options += (short_options - hol->short_options);
2222+
2223+ /* Now add the short options from MORE, fixing up its entries
2224+ too. */
2225+ so = short_options + hol_so_len;
2226+ more_so = more->short_options;
2227+ for (left = more->num_entries; left > 0; e++, left--)
2228+ {
2229+ int opts_left;
2230+ const struct argp_option *opt;
2231+
2232+ e->short_options = so;
2233+
2234+ for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
2235+ {
2236+ int ch = *more_so;
2237+ if (oshort (opt) && ch == opt->key)
2238+ /* The next short option in MORE_SO, CH, is from OPT. */
2239+ {
2240+ if (! find_char (ch, short_options,
2241+ short_options + hol_so_len))
2242+ /* The short option CH isn't shadowed by HOL's options,
2243+ so add it to the sum. */
2244+ *so++ = ch;
2245+ more_so++;
2246+ }
2247+ }
2248+ }
2249+
2250+ *so = '\0';
2251+
2252+ free (hol->entries);
2253+ free (hol->short_options);
2254+
2255+ hol->entries = entries;
2256+ hol->num_entries = num_entries;
2257+ hol->short_options = short_options;
2258+ }
2259+ }
2260+
2261+ hol_free (more);
2262+}
2263+
2264+/* Inserts enough spaces to make sure STREAM is at column COL. */
2265+static void
2266+indent_to (argp_fmtstream_t stream, unsigned col)
2267+{
2268+ int needed = col - __argp_fmtstream_point (stream);
2269+ while (needed-- > 0)
2270+ __argp_fmtstream_putc (stream, ' ');
2271+}
2272+
2273+/* Output to STREAM either a space, or a newline if there isn't room for at
2274+ least ENSURE characters before the right margin. */
2275+static void
2276+space (argp_fmtstream_t stream, size_t ensure)
2277+{
2278+ if (__argp_fmtstream_point (stream) + ensure
2279+ >= __argp_fmtstream_rmargin (stream))
2280+ __argp_fmtstream_putc (stream, '\n');
2281+ else
2282+ __argp_fmtstream_putc (stream, ' ');
2283+}
2284+
2285+/* If the option REAL has an argument, we print it in using the printf
2286+ format REQ_FMT or OPT_FMT depending on whether it's a required or
2287+ optional argument. */
2288+static void
2289+arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
2290+ const char *domain, argp_fmtstream_t stream)
2291+{
2292+ if (real->arg)
2293+ {
2294+ if (real->flags & OPTION_ARG_OPTIONAL)
2295+ __argp_fmtstream_printf (stream, opt_fmt,
2296+ dgettext (domain, real->arg));
2297+ else
2298+ __argp_fmtstream_printf (stream, req_fmt,
2299+ dgettext (domain, real->arg));
2300+ }
2301+}
2302+
2303+/* Helper functions for hol_entry_help. */
2304+
2305+/* State used during the execution of hol_help. */
2306+struct hol_help_state
2307+{
2308+ /* PREV_ENTRY should contain the previous entry printed, or 0. */
2309+ struct hol_entry *prev_entry;
2310+
2311+ /* If an entry is in a different group from the previous one, and SEP_GROUPS
2312+ is true, then a blank line will be printed before any output. */
2313+ int sep_groups;
2314+
2315+ /* True if a duplicate option argument was suppressed (only ever set if
2316+ UPARAMS.dup_args is false). */
2317+ int suppressed_dup_arg;
2318+};
2319+
2320+/* Some state used while printing a help entry (used to communicate with
2321+ helper functions). See the doc for hol_entry_help for more info, as most
2322+ of the fields are copied from its arguments. */
2323+struct pentry_state
2324+{
2325+ const struct hol_entry *entry;
2326+ argp_fmtstream_t stream;
2327+ struct hol_help_state *hhstate;
2328+
2329+ /* True if nothing's been printed so far. */
2330+ int first;
2331+
2332+ /* If non-zero, the state that was used to print this help. */
2333+ const struct argp_state *state;
2334+};
2335+
2336+/* If a user doc filter should be applied to DOC, do so. */
2337+static const char *
2338+filter_doc (const char *doc, int key, const struct argp *argp,
2339+ const struct argp_state *state)
2340+{
2341+ if (argp && argp->help_filter)
2342+ /* We must apply a user filter to this output. */
2343+ {
2344+ void *input = __argp_input (argp, state);
2345+ return (*argp->help_filter) (key, doc, input);
2346+ }
2347+ else
2348+ /* No filter. */
2349+ return doc;
2350+}
2351+
2352+/* Prints STR as a header line, with the margin lines set appropiately, and
2353+ notes the fact that groups should be separated with a blank line. ARGP is
2354+ the argp that should dictate any user doc filtering to take place. Note
2355+ that the previous wrap margin isn't restored, but the left margin is reset
2356+ to 0. */
2357+static void
2358+print_header (const char *str, const struct argp *argp,
2359+ struct pentry_state *pest)
2360+{
2361+ const char *tstr = dgettext (argp->argp_domain, str);
2362+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state);
2363+
2364+ if (fstr)
2365+ {
2366+ if (*fstr)
2367+ {
2368+ if (pest->hhstate->prev_entry)
2369+ /* Precede with a blank line. */
2370+ __argp_fmtstream_putc (pest->stream, '\n');
2371+ indent_to (pest->stream, uparams.header_col);
2372+ __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col);
2373+ __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col);
2374+ __argp_fmtstream_puts (pest->stream, fstr);
2375+ __argp_fmtstream_set_lmargin (pest->stream, 0);
2376+ __argp_fmtstream_putc (pest->stream, '\n');
2377+ }
2378+
2379+ pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */
2380+ }
2381+
2382+ if (fstr != tstr)
2383+ free ((char *) fstr);
2384+}
2385+
2386+/* Inserts a comma if this isn't the first item on the line, and then makes
2387+ sure we're at least to column COL. If this *is* the first item on a line,
2388+ prints any pending whitespace/headers that should precede this line. Also
2389+ clears FIRST. */
2390+static void
2391+comma (unsigned col, struct pentry_state *pest)
2392+{
2393+ if (pest->first)
2394+ {
2395+ const struct hol_entry *pe = pest->hhstate->prev_entry;
2396+ const struct hol_cluster *cl = pest->entry->cluster;
2397+
2398+ if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group)
2399+ __argp_fmtstream_putc (pest->stream, '\n');
2400+
2401+ if (cl && cl->header && *cl->header
2402+ && (!pe
2403+ || (pe->cluster != cl
2404+ && !hol_cluster_is_child (pe->cluster, cl))))
2405+ /* If we're changing clusters, then this must be the start of the
2406+ ENTRY's cluster unless that is an ancestor of the previous one
2407+ (in which case we had just popped into a sub-cluster for a bit).
2408+ If so, then print the cluster's header line. */
2409+ {
2410+ int old_wm = __argp_fmtstream_wmargin (pest->stream);
2411+ print_header (cl->header, cl->argp, pest);
2412+ __argp_fmtstream_set_wmargin (pest->stream, old_wm);
2413+ }
2414+
2415+ pest->first = 0;
2416+ }
2417+ else
2418+ __argp_fmtstream_puts (pest->stream, ", ");
2419+
2420+ indent_to (pest->stream, col);
2421+}
2422+
2423+/* Print help for ENTRY to STREAM. */
2424+static void
2425+hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
2426+ argp_fmtstream_t stream, struct hol_help_state *hhstate)
2427+{
2428+ unsigned num;
2429+ const struct argp_option *real = entry->opt, *opt;
2430+ char *so = entry->short_options;
2431+ int have_long_opt = 0; /* We have any long options. */
2432+ /* Saved margins. */
2433+ int old_lm = __argp_fmtstream_set_lmargin (stream, 0);
2434+ int old_wm = __argp_fmtstream_wmargin (stream);
2435+ /* PEST is a state block holding some of our variables that we'd like to
2436+ share with helper functions. */
2437+ struct pentry_state pest = { entry, stream, hhstate, 1, state };
2438+
2439+ if (! odoc (real))
2440+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2441+ if (opt->name && ovisible (opt))
2442+ {
2443+ have_long_opt = 1;
2444+ break;
2445+ }
2446+
2447+ /* First emit short options. */
2448+ __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
2449+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2450+ if (oshort (opt) && opt->key == *so)
2451+ /* OPT has a valid (non shadowed) short option. */
2452+ {
2453+ if (ovisible (opt))
2454+ {
2455+ comma (uparams.short_opt_col, &pest);
2456+ __argp_fmtstream_putc (stream, '-');
2457+ __argp_fmtstream_putc (stream, *so);
2458+ if (!have_long_opt || uparams.dup_args)
2459+ arg (real, " %s", "[%s]",
2460+ state == NULL ? NULL : state->root_argp->argp_domain,
2461+ stream);
2462+ else if (real->arg)
2463+ hhstate->suppressed_dup_arg = 1;
2464+ }
2465+ so++;
2466+ }
2467+
2468+ /* Now, long options. */
2469+ if (odoc (real))
2470+ /* A `documentation' option. */
2471+ {
2472+ __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col);
2473+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2474+ if (opt->name && ovisible (opt))
2475+ {
2476+ comma (uparams.doc_opt_col, &pest);
2477+ /* Calling gettext here isn't quite right, since sorting will
2478+ have been done on the original; but documentation options
2479+ should be pretty rare anyway... */
2480+ __argp_fmtstream_puts (stream,
2481+ dgettext (state == NULL ? NULL
2482+ : state->root_argp->argp_domain,
2483+ opt->name));
2484+ }
2485+ }
2486+ else
2487+ /* A real long option. */
2488+ {
2489+ __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
2490+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2491+ if (opt->name && ovisible (opt))
2492+ {
2493+ comma (uparams.long_opt_col, &pest);
2494+ __argp_fmtstream_printf (stream, "--%s", opt->name);
2495+ arg (real, "=%s", "[=%s]",
2496+ state == NULL ? NULL : state->root_argp->argp_domain, stream);
2497+ }
2498+ }
2499+
2500+ /* Next, documentation strings. */
2501+ __argp_fmtstream_set_lmargin (stream, 0);
2502+
2503+ if (pest.first)
2504+ {
2505+ /* Didn't print any switches, what's up? */
2506+ if (!oshort (real) && !real->name)
2507+ /* This is a group header, print it nicely. */
2508+ print_header (real->doc, entry->argp, &pest);
2509+ else
2510+ /* Just a totally shadowed option or null header; print nothing. */
2511+ goto cleanup; /* Just return, after cleaning up. */
2512+ }
2513+ else
2514+ {
2515+ const char *tstr = real->doc ? dgettext (state == NULL ? NULL
2516+ : state->root_argp->argp_domain,
2517+ real->doc) : 0;
2518+ const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
2519+ if (fstr && *fstr)
2520+ {
2521+ unsigned int col = __argp_fmtstream_point (stream);
2522+
2523+ __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col);
2524+ __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col);
2525+
2526+ if (col > (unsigned int) (uparams.opt_doc_col + 3))
2527+ __argp_fmtstream_putc (stream, '\n');
2528+ else if (col >= (unsigned int) uparams.opt_doc_col)
2529+ __argp_fmtstream_puts (stream, " ");
2530+ else
2531+ indent_to (stream, uparams.opt_doc_col);
2532+
2533+ __argp_fmtstream_puts (stream, fstr);
2534+ }
2535+ if (fstr && fstr != tstr)
2536+ free ((char *) fstr);
2537+
2538+ /* Reset the left margin. */
2539+ __argp_fmtstream_set_lmargin (stream, 0);
2540+ __argp_fmtstream_putc (stream, '\n');
2541+ }
2542+
2543+ hhstate->prev_entry = entry;
2544+
2545+cleanup:
2546+ __argp_fmtstream_set_lmargin (stream, old_lm);
2547+ __argp_fmtstream_set_wmargin (stream, old_wm);
2548+}
2549+
2550+/* Output a long help message about the options in HOL to STREAM. */
2551+static void
2552+hol_help (struct hol *hol, const struct argp_state *state,
2553+ argp_fmtstream_t stream)
2554+{
2555+ unsigned num;
2556+ struct hol_entry *entry;
2557+ struct hol_help_state hhstate = { 0, 0, 0 };
2558+
2559+ for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
2560+ hol_entry_help (entry, state, stream, &hhstate);
2561+
2562+ if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
2563+ {
2564+ const char *tstr = dgettext (state == NULL ? NULL
2565+ : state->root_argp->argp_domain, "\
2566+Mandatory or optional arguments to long options are also mandatory or \
2567+optional for any corresponding short options.");
2568+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
2569+ state ? state->root_argp : 0, state);
2570+ if (fstr && *fstr)
2571+ {
2572+ __argp_fmtstream_putc (stream, '\n');
2573+ __argp_fmtstream_puts (stream, fstr);
2574+ __argp_fmtstream_putc (stream, '\n');
2575+ }
2576+ if (fstr && fstr != tstr)
2577+ free ((char *) fstr);
2578+ }
2579+}
2580+
2581+/* Helper functions for hol_usage. */
2582+
2583+/* If OPT is a short option without an arg, append its key to the string
2584+ pointer pointer to by COOKIE, and advance the pointer. */
2585+static int
2586+add_argless_short_opt (const struct argp_option *opt,
2587+ const struct argp_option *real,
2588+ const char *domain, void *cookie)
2589+{
2590+ char **snao_end = cookie;
2591+ if (!(opt->arg || real->arg)
2592+ && !((opt->flags | real->flags) & OPTION_NO_USAGE))
2593+ *(*snao_end)++ = opt->key;
2594+ return 0;
2595+}
2596+
2597+/* If OPT is a short option with an arg, output a usage entry for it to the
2598+ stream pointed at by COOKIE. */
2599+static int
2600+usage_argful_short_opt (const struct argp_option *opt,
2601+ const struct argp_option *real,
2602+ const char *domain, void *cookie)
2603+{
2604+ argp_fmtstream_t stream = cookie;
2605+ const char *arg = opt->arg;
2606+ int flags = opt->flags | real->flags;
2607+
2608+ if (! arg)
2609+ arg = real->arg;
2610+
2611+ if (arg && !(flags & OPTION_NO_USAGE))
2612+ {
2613+ arg = dgettext (domain, arg);
2614+
2615+ if (flags & OPTION_ARG_OPTIONAL)
2616+ __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
2617+ else
2618+ {
2619+ /* Manually do line wrapping so that it (probably) won't
2620+ get wrapped at the embedded space. */
2621+ space (stream, 6 + strlen (arg));
2622+ __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
2623+ }
2624+ }
2625+
2626+ return 0;
2627+}
2628+
2629+/* Output a usage entry for the long option opt to the stream pointed at by
2630+ COOKIE. */
2631+static int
2632+usage_long_opt (const struct argp_option *opt,
2633+ const struct argp_option *real,
2634+ const char *domain, void *cookie)
2635+{
2636+ argp_fmtstream_t stream = cookie;
2637+ const char *arg = opt->arg;
2638+ int flags = opt->flags | real->flags;
2639+
2640+ if (! arg)
2641+ arg = real->arg;
2642+
2643+ if (! (flags & OPTION_NO_USAGE))
2644+ {
2645+ if (arg)
2646+ {
2647+ arg = dgettext (domain, arg);
2648+ if (flags & OPTION_ARG_OPTIONAL)
2649+ __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
2650+ else
2651+ __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
2652+ }
2653+ else
2654+ __argp_fmtstream_printf (stream, " [--%s]", opt->name);
2655+ }
2656+
2657+ return 0;
2658+}
2659+
2660+/* Print a short usage description for the arguments in HOL to STREAM. */
2661+static void
2662+hol_usage (struct hol *hol, argp_fmtstream_t stream)
2663+{
2664+ if (hol->num_entries > 0)
2665+ {
2666+ unsigned nentries;
2667+ struct hol_entry *entry;
2668+ char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1);
2669+ char *snao_end = short_no_arg_opts;
2670+
2671+ /* First we put a list of short options without arguments. */
2672+ for (entry = hol->entries, nentries = hol->num_entries
2673+ ; nentries > 0
2674+ ; entry++, nentries--)
2675+ hol_entry_short_iterate (entry, add_argless_short_opt,
2676+ entry->argp->argp_domain, &snao_end);
2677+ if (snao_end > short_no_arg_opts)
2678+ {
2679+ *snao_end++ = 0;
2680+ __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts);
2681+ }
2682+
2683+ /* Now a list of short options *with* arguments. */
2684+ for (entry = hol->entries, nentries = hol->num_entries
2685+ ; nentries > 0
2686+ ; entry++, nentries--)
2687+ hol_entry_short_iterate (entry, usage_argful_short_opt,
2688+ entry->argp->argp_domain, stream);
2689+
2690+ /* Finally, a list of long options (whew!). */
2691+ for (entry = hol->entries, nentries = hol->num_entries
2692+ ; nentries > 0
2693+ ; entry++, nentries--)
2694+ hol_entry_long_iterate (entry, usage_long_opt,
2695+ entry->argp->argp_domain, stream);
2696+ }
2697+}
2698+
2699+/* Make a HOL containing all levels of options in ARGP. CLUSTER is the
2700+ cluster in which ARGP's entries should be clustered, or 0. */
2701+static struct hol *
2702+argp_hol (const struct argp *argp, struct hol_cluster *cluster)
2703+{
2704+ const struct argp_child *child = argp->children;
2705+ struct hol *hol = make_hol (argp, cluster);
2706+ if (child)
2707+ while (child->argp)
2708+ {
2709+ struct hol_cluster *child_cluster =
2710+ ((child->group || child->header)
2711+ /* Put CHILD->argp within its own cluster. */
2712+ ? hol_add_cluster (hol, child->group, child->header,
2713+ child - argp->children, cluster, argp)
2714+ /* Just merge it into the parent's cluster. */
2715+ : cluster);
2716+ hol_append (hol, argp_hol (child->argp, child_cluster)) ;
2717+ child++;
2718+ }
2719+ return hol;
2720+}
2721+
2722+/* Calculate how many different levels with alternative args strings exist in
2723+ ARGP. */
2724+static size_t
2725+argp_args_levels (const struct argp *argp)
2726+{
2727+ size_t levels = 0;
2728+ const struct argp_child *child = argp->children;
2729+
2730+ if (argp->args_doc && strchr (argp->args_doc, '\n'))
2731+ levels++;
2732+
2733+ if (child)
2734+ while (child->argp)
2735+ levels += argp_args_levels ((child++)->argp);
2736+
2737+ return levels;
2738+}
2739+
2740+/* Print all the non-option args documented in ARGP to STREAM. Any output is
2741+ preceded by a space. LEVELS is a pointer to a byte vector the length
2742+ returned by argp_args_levels; it should be initialized to zero, and
2743+ updated by this routine for the next call if ADVANCE is true. True is
2744+ returned as long as there are more patterns to output. */
2745+static int
2746+argp_args_usage (const struct argp *argp, const struct argp_state *state,
2747+ char **levels, int advance, argp_fmtstream_t stream)
2748+{
2749+ char *our_level = *levels;
2750+ int multiple = 0;
2751+ const struct argp_child *child = argp->children;
2752+ const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
2753+ const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
2754+
2755+ if (fdoc)
2756+ {
2757+ const char *cp = fdoc;
2758+ nl = strchrnul (cp, '\n');
2759+ if (*nl != '\0')
2760+ /* This is a `multi-level' args doc; advance to the correct position
2761+ as determined by our state in LEVELS, and update LEVELS. */
2762+ {
2763+ int i;
2764+ multiple = 1;
2765+ for (i = 0; i < *our_level; i++)
2766+ cp = nl + 1, nl = strchrnul (cp, '\n');
2767+ (*levels)++;
2768+ }
2769+
2770+ /* Manually do line wrapping so that it (probably) won't get wrapped at
2771+ any embedded spaces. */
2772+ space (stream, 1 + nl - cp);
2773+
2774+ __argp_fmtstream_write (stream, cp, nl - cp);
2775+ }
2776+ if (fdoc && fdoc != tdoc)
2777+ free ((char *)fdoc); /* Free user's modified doc string. */
2778+
2779+ if (child)
2780+ while (child->argp)
2781+ advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
2782+
2783+ if (advance && multiple)
2784+ {
2785+ /* Need to increment our level. */
2786+ if (*nl)
2787+ /* There's more we can do here. */
2788+ {
2789+ (*our_level)++;
2790+ advance = 0; /* Our parent shouldn't advance also. */
2791+ }
2792+ else if (*our_level > 0)
2793+ /* We had multiple levels, but used them up; reset to zero. */
2794+ *our_level = 0;
2795+ }
2796+
2797+ return !advance;
2798+}
2799+
2800+/* Print the documentation for ARGP to STREAM; if POST is false, then
2801+ everything preceeding a `\v' character in the documentation strings (or
2802+ the whole string, for those with none) is printed, otherwise, everything
2803+ following the `\v' character (nothing for strings without). Each separate
2804+ bit of documentation is separated a blank line, and if PRE_BLANK is true,
2805+ then the first is as well. If FIRST_ONLY is true, only the first
2806+ occurrence is output. Returns true if anything was output. */
2807+static int
2808+argp_doc (const struct argp *argp, const struct argp_state *state,
2809+ int post, int pre_blank, int first_only,
2810+ argp_fmtstream_t stream)
2811+{
2812+ const char *text;
2813+ const char *inp_text;
2814+ void *input = 0;
2815+ int anything = 0;
2816+ size_t inp_text_limit = 0;
2817+ const char *doc = dgettext (argp->argp_domain, argp->doc);
2818+ const struct argp_child *child = argp->children;
2819+
2820+ if (doc)
2821+ {
2822+ char *vt = strchr (doc, '\v');
2823+ inp_text = post ? (vt ? vt + 1 : 0) : doc;
2824+ inp_text_limit = (!post && vt) ? (vt - doc) : 0;
2825+ }
2826+ else
2827+ inp_text = 0;
2828+
2829+ if (argp->help_filter)
2830+ /* We have to filter the doc strings. */
2831+ {
2832+ if (inp_text_limit)
2833+ /* Copy INP_TEXT so that it's nul-terminated. */
2834+ inp_text = strndup (inp_text, inp_text_limit);
2835+ input = __argp_input (argp, state);
2836+ text =
2837+ (*argp->help_filter) (post
2838+ ? ARGP_KEY_HELP_POST_DOC
2839+ : ARGP_KEY_HELP_PRE_DOC,
2840+ inp_text, input);
2841+ }
2842+ else
2843+ text = (const char *) inp_text;
2844+
2845+ if (text)
2846+ {
2847+ if (pre_blank)
2848+ __argp_fmtstream_putc (stream, '\n');
2849+
2850+ if (text == inp_text && inp_text_limit)
2851+ __argp_fmtstream_write (stream, inp_text, inp_text_limit);
2852+ else
2853+ __argp_fmtstream_puts (stream, text);
2854+
2855+ if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))
2856+ __argp_fmtstream_putc (stream, '\n');
2857+
2858+ anything = 1;
2859+ }
2860+
2861+ if (text && text != inp_text)
2862+ free ((char *) text); /* Free TEXT returned from the help filter. */
2863+ if (inp_text && inp_text_limit && argp->help_filter)
2864+ free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */
2865+
2866+ if (post && argp->help_filter)
2867+ /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */
2868+ {
2869+ text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input);
2870+ if (text)
2871+ {
2872+ if (anything || pre_blank)
2873+ __argp_fmtstream_putc (stream, '\n');
2874+ __argp_fmtstream_puts (stream, text);
2875+ free ((char *) text);
2876+ if (__argp_fmtstream_point (stream)
2877+ > __argp_fmtstream_lmargin (stream))
2878+ __argp_fmtstream_putc (stream, '\n');
2879+ anything = 1;
2880+ }
2881+ }
2882+
2883+ if (child)
2884+ while (child->argp && !(first_only && anything))
2885+ anything |=
2886+ argp_doc ((child++)->argp, state,
2887+ post, anything || pre_blank, first_only,
2888+ stream);
2889+
2890+ return anything;
2891+}
2892+
2893+/* Output a usage message for ARGP to STREAM. If called from
2894+ argp_state_help, STATE is the relevent parsing state. FLAGS are from the
2895+ set ARGP_HELP_*. NAME is what to use wherever a `program name' is
2896+ needed. */
2897+static void
2898+_help (const struct argp *argp, const struct argp_state *state, FILE *stream,
2899+ unsigned flags, char *name)
2900+{
2901+ int anything = 0; /* Whether we've output anything. */
2902+ struct hol *hol = 0;
2903+ argp_fmtstream_t fs;
2904+
2905+ if (! stream)
2906+ return;
2907+
2908+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
2909+ flockfile (stream);
2910+#endif
2911+
2912+ fill_in_uparams (state);
2913+
2914+ fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
2915+ if (! fs)
2916+ {
2917+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
2918+ funlockfile (stream);
2919+#endif
2920+ return;
2921+ }
2922+
2923+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
2924+ {
2925+ hol = argp_hol (argp, 0);
2926+
2927+ /* If present, these options always come last. */
2928+ hol_set_group (hol, "help", -1);
2929+ hol_set_group (hol, "version", -1);
2930+
2931+ hol_sort (hol);
2932+ }
2933+
2934+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))
2935+ /* Print a short `Usage:' message. */
2936+ {
2937+ int first_pattern = 1, more_patterns;
2938+ size_t num_pattern_levels = argp_args_levels (argp);
2939+ char *pattern_levels = alloca (num_pattern_levels);
2940+
2941+ memset (pattern_levels, 0, num_pattern_levels);
2942+
2943+ do
2944+ {
2945+ int old_lm;
2946+ int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);
2947+ char *levels = pattern_levels;
2948+
2949+ if (first_pattern)
2950+ __argp_fmtstream_printf (fs, "%s %s",
2951+ dgettext (argp->argp_domain, "Usage:"),
2952+ name);
2953+ else
2954+ __argp_fmtstream_printf (fs, "%s %s",
2955+ dgettext (argp->argp_domain, " or: "),
2956+ name);
2957+
2958+ /* We set the lmargin as well as the wmargin, because hol_usage
2959+ manually wraps options with newline to avoid annoying breaks. */
2960+ old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent);
2961+
2962+ if (flags & ARGP_HELP_SHORT_USAGE)
2963+ /* Just show where the options go. */
2964+ {
2965+ if (hol->num_entries > 0)
2966+ __argp_fmtstream_puts (fs, dgettext (argp->argp_domain,
2967+ " [OPTION...]"));
2968+ }
2969+ else
2970+ /* Actually print the options. */
2971+ {
2972+ hol_usage (hol, fs);
2973+ flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */
2974+ }
2975+
2976+ more_patterns = argp_args_usage (argp, state, &levels, 1, fs);
2977+
2978+ __argp_fmtstream_set_wmargin (fs, old_wm);
2979+ __argp_fmtstream_set_lmargin (fs, old_lm);
2980+
2981+ __argp_fmtstream_putc (fs, '\n');
2982+ anything = 1;
2983+
2984+ first_pattern = 0;
2985+ }
2986+ while (more_patterns);
2987+ }
2988+
2989+ if (flags & ARGP_HELP_PRE_DOC)
2990+ anything |= argp_doc (argp, state, 0, 0, 1, fs);
2991+
2992+ if (flags & ARGP_HELP_SEE)
2993+ {
2994+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\
2995+Try `%s --help' or `%s --usage' for more information.\n"),
2996+ name, name);
2997+ anything = 1;
2998+ }
2999+
3000+ if (flags & ARGP_HELP_LONG)
3001+ /* Print a long, detailed help message. */
3002+ {
3003+ /* Print info about all the options. */
3004+ if (hol->num_entries > 0)
3005+ {
3006+ if (anything)
3007+ __argp_fmtstream_putc (fs, '\n');
3008+ hol_help (hol, state, fs);
3009+ anything = 1;
3010+ }
3011+ }
3012+
3013+ if (flags & ARGP_HELP_POST_DOC)
3014+ /* Print any documentation strings at the end. */
3015+ anything |= argp_doc (argp, state, 1, anything, 0, fs);
3016+
3017+ if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address)
3018+ {
3019+ if (anything)
3020+ __argp_fmtstream_putc (fs, '\n');
3021+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,
3022+ "Report bugs to %s.\n"),
3023+ argp_program_bug_address);
3024+ anything = 1;
3025+ }
3026+
3027+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3028+ funlockfile (stream);
3029+#endif
3030+
3031+ if (hol)
3032+ hol_free (hol);
3033+
3034+ __argp_fmtstream_free (fs);
3035+}
3036+
3037+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
3038+ ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */
3039+void argp_help (const struct argp *argp, FILE *stream,
3040+ unsigned flags, char *name)
3041+{
3042+ _help (argp, 0, stream, flags, name);
3043+}
3044+
3045+char *
3046+__argp_short_program_name (void)
3047+{
3048+# ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
3049+/*
3050+ * uClibc provides both program_invocation_name and
3051+ * program_invocation_short_name
3052+ */
3053+ return (char *) program_invocation_short_name;
3054+# else
3055+ /* FIXME: What now? Miles suggests that it is better to use NULL,
3056+ but currently the value is passed on directly to fputs_unlocked,
3057+ so that requires more changes. */
3058+# if __GNUC__
3059+# warning No reasonable value to return
3060+# endif /* __GNUC__ */
3061+ return "";
3062+# endif
3063+}
3064+
3065+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
3066+ from the set ARGP_HELP_*. */
3067+void
3068+argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
3069+{
3070+ if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream)
3071+ {
3072+ if (state && (state->flags & ARGP_LONG_ONLY))
3073+ flags |= ARGP_HELP_LONG_ONLY;
3074+
3075+ _help (state ? state->root_argp : 0, state, stream, flags,
3076+ state ? state->name : __argp_short_program_name ());
3077+
3078+ if (!state || ! (state->flags & ARGP_NO_EXIT))
3079+ {
3080+ if (flags & ARGP_HELP_EXIT_ERR)
3081+ exit (argp_err_exit_status);
3082+ if (flags & ARGP_HELP_EXIT_OK)
3083+ exit (0);
3084+ }
3085+ }
3086+}
3087+
3088+/* If appropriate, print the printf string FMT and following args, preceded
3089+ by the program name and `:', to stderr, and followed by a `Try ... --help'
3090+ message, then exit (1). */
3091+void
3092+argp_error (const struct argp_state *state, const char *fmt, ...)
3093+{
3094+ if (!state || !(state->flags & ARGP_NO_ERRS))
3095+ {
3096+ FILE *stream = state ? state->err_stream : stderr;
3097+
3098+ if (stream)
3099+ {
3100+ va_list ap;
3101+
3102+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3103+ flockfile (stream);
3104+#endif
3105+
3106+ va_start (ap, fmt);
3107+
3108+#if defined _LIBC && defined USE_IN_LIBIO
3109+ char *buf;
3110+
3111+ if (_IO_vasprintf (&buf, fmt, ap) < 0)
3112+ buf = NULL;
3113+
3114+ __fxprintf (stream, "%s: %s\n",
3115+ state ? state->name : __argp_short_program_name (), buf);
3116+
3117+ free (buf);
3118+#else
3119+ fputs_unlocked (state ? state->name : __argp_short_program_name (),
3120+ stream);
3121+ putc_unlocked (':', stream);
3122+ putc_unlocked (' ', stream);
3123+
3124+ vfprintf (stream, fmt, ap);
3125+
3126+ putc_unlocked ('\n', stream);
3127+#endif
3128+
3129+ argp_state_help (state, stream, ARGP_HELP_STD_ERR);
3130+
3131+ va_end (ap);
3132+
3133+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3134+ funlockfile (stream);
3135+#endif
3136+ }
3137+ }
3138+}
3139+
3140+/* Similar to the standard gnu error-reporting function error(), but will
3141+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
3142+ to STATE->err_stream. This is useful for argument parsing code that is
3143+ shared between program startup (when exiting is desired) and runtime
3144+ option parsing (when typically an error code is returned instead). The
3145+ difference between this function and argp_error is that the latter is for
3146+ *parsing errors*, and the former is for other problems that occur during
3147+ parsing but don't reflect a (syntactic) problem with the input. */
3148+void
3149+argp_failure (const struct argp_state *state, int status, int errnum,
3150+ const char *fmt, ...)
3151+{
3152+ if (!state || !(state->flags & ARGP_NO_ERRS))
3153+ {
3154+ FILE *stream = state ? state->err_stream : stderr;
3155+
3156+ if (stream)
3157+ {
3158+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3159+ flockfile (stream);
3160+#endif
3161+
3162+#if defined _LIBC && defined USE_IN_LIBIO
3163+ __fxprintf (stream, "%s",
3164+ state ? state->name : __argp_short_program_name ());
3165+#else
3166+ fputs_unlocked (state ? state->name : __argp_short_program_name (),
3167+ stream);
3168+#endif
3169+
3170+ if (fmt)
3171+ {
3172+ va_list ap;
3173+
3174+ va_start (ap, fmt);
3175+#if defined _LIBC && defined USE_IN_LIBIO
3176+ char *buf;
3177+
3178+ if (_IO_vasprintf (&buf, fmt, ap) < 0)
3179+ buf = NULL;
3180+
3181+ __fxprintf (stream, ": %s", buf);
3182+
3183+ free (buf);
3184+#else
3185+ putc_unlocked (':', stream);
3186+ putc_unlocked (' ', stream);
3187+
3188+ vfprintf (stream, fmt, ap);
3189+#endif
3190+
3191+ va_end (ap);
3192+ }
3193+
3194+ if (errnum)
3195+ {
3196+#if (defined _LIBC && defined USE_IN_LIBIO) || defined HAVE_STRERROR_R
3197+ char buf[200];
3198+#endif
3199+#if defined _LIBC && defined USE_IN_LIBIO
3200+ __fxprintf (stream, ": %s",
3201+ strerror_r (errnum, buf, sizeof (buf)));
3202+#else
3203+ putc_unlocked (':', stream);
3204+ putc_unlocked (' ', stream);
3205+# ifdef HAVE_STRERROR_R
3206+ fputs (strerror_r (errnum, buf, sizeof (buf)), stream);
3207+# else
3208+ fputs (strerror (errnum), stream);
3209+# endif
3210+#endif
3211+ }
3212+
3213+#ifdef USE_IN_LIBIO
3214+ if (_IO_fwide (stream, 0) > 0)
3215+ putwc_unlocked (L'\n', stream);
3216+ else
3217+#endif
3218+ putc_unlocked ('\n', stream);
3219+
3220+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3221+ funlockfile (stream);
3222+#endif
3223+
3224+ if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
3225+ exit (status);
3226+ }
3227+ }
3228+}
3229Index: git/libuargp/argp-parse.c
3230===================================================================
3231--- /dev/null
3232+++ git/libuargp/argp-parse.c
3233@@ -0,0 +1,949 @@
3234+/* Hierarchial argument parsing, layered over getopt
3235+ Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
3236+ This file is part of the GNU C Library.
3237+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
3238+
3239+ The GNU C Library is free software; you can redistribute it and/or
3240+ modify it under the terms of the GNU Lesser General Public
3241+ License as published by the Free Software Foundation; either
3242+ version 2.1 of the License, or (at your option) any later version.
3243+
3244+ The GNU C Library is distributed in the hope that it will be useful,
3245+ but WITHOUT ANY WARRANTY; without even the implied warranty of
3246+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3247+ Lesser General Public License for more details.
3248+
3249+ You should have received a copy of the GNU Lesser General Public
3250+ License along with the GNU C Library; if not, write to the Free
3251+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3252+ 02111-1307 USA.
3253+
3254+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
3255+*/
3256+
3257+#ifdef HAVE_CONFIG_H
3258+#include <config.h>
3259+#endif
3260+
3261+/* AIX requires this to be the first thing in the file. */
3262+#ifndef __GNUC__
3263+# if HAVE_ALLOCA_H || defined _LIBC
3264+# include <alloca.h>
3265+# else
3266+# ifdef _AIX
3267+#pragma alloca
3268+# else
3269+# ifndef alloca /* predefined by HP cc +Olibcalls */
3270+char *alloca ();
3271+# endif
3272+# endif
3273+# endif
3274+#endif
3275+
3276+#include <stdlib.h>
3277+#include <string.h>
3278+#include <unistd.h>
3279+#include <limits.h>
3280+#include <getopt.h>
3281+#include <bits/getopt_int.h>
3282+
3283+#include <features.h>
3284+#ifndef _
3285+/* This is for other GNU distributions with internationalized messages.
3286+ When compiling libc, the _ macro is predefined. */
3287+# if (defined HAVE_LIBINTL_H || defined _LIBC) && defined __UCLIBC_HAS_GETTEXT_AWARENESS__
3288+# include <libintl.h>
3289+# ifdef _LIBC
3290+# undef dgettext
3291+# define dgettext(domain, msgid) \
3292+ INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
3293+# endif
3294+# else
3295+# define dgettext(domain, msgid) (msgid)
3296+# define gettext(msgid) (msgid)
3297+# endif
3298+#endif
3299+#ifndef N_
3300+# define N_(msgid) (msgid)
3301+#endif
3302+
3303+#include <argp.h>
3304+
3305+/* Getopt return values. */
3306+#define KEY_END (-1) /* The end of the options. */
3307+#define KEY_ARG 1 /* A non-option argument. */
3308+#define KEY_ERR '?' /* An error parsing the options. */
3309+
3310+/* The meta-argument used to prevent any further arguments being interpreted
3311+ as options. */
3312+#define QUOTE "--"
3313+
3314+/* The number of bits we steal in a long-option value for our own use. */
3315+#define GROUP_BITS CHAR_BIT
3316+
3317+/* The number of bits available for the user value. */
3318+#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS)
3319+#define USER_MASK ((1 << USER_BITS) - 1)
3320+
3321+/* EZ alias for ARGP_ERR_UNKNOWN. */
3322+#define EBADKEY ARGP_ERR_UNKNOWN
3323+
3324+/* Default options. */
3325+
3326+/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
3327+ for one second intervals, decrementing _ARGP_HANG until it's zero. Thus
3328+ you can force the program to continue by attaching a debugger and setting
3329+ it to 0 yourself. */
3330+static volatile int _argp_hang;
3331+
3332+#define OPT_PROGNAME -2
3333+#define OPT_USAGE -3
3334+#define OPT_HANG -4
3335+
3336+static const struct argp_option argp_default_options[] =
3337+{
3338+ {"help", '?', 0, 0, N_("Give this help list"), -1},
3339+ {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message")},
3340+ {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name")},
3341+ {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
3342+ N_("Hang for SECS seconds (default 3600)")},
3343+ {0, 0}
3344+};
3345+
3346+static error_t
3347+argp_default_parser (int key, char *arg, struct argp_state *state)
3348+{
3349+ switch (key)
3350+ {
3351+ case '?':
3352+ argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
3353+ break;
3354+ case OPT_USAGE:
3355+ argp_state_help (state, state->out_stream,
3356+ ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
3357+ break;
3358+
3359+ case OPT_PROGNAME: /* Set the program name. */
3360+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
3361+ program_invocation_name = arg;
3362+#endif
3363+ /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
3364+ __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
3365+ to be that, so we have to be a bit careful here.] */
3366+
3367+ /* Update what we use for messages. */
3368+ state->name = strrchr (arg, '/');
3369+ if (state->name)
3370+ state->name++;
3371+ else
3372+ state->name = arg;
3373+
3374+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
3375+ program_invocation_short_name = state->name;
3376+#endif
3377+
3378+ if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
3379+ == ARGP_PARSE_ARGV0)
3380+ /* Update what getopt uses too. */
3381+ state->argv[0] = arg;
3382+
3383+ break;
3384+
3385+ case OPT_HANG:
3386+ _argp_hang = atoi (arg ? arg : "3600");
3387+ while (_argp_hang-- > 0)
3388+ sleep (1);
3389+ break;
3390+
3391+ default:
3392+ return EBADKEY;
3393+ }
3394+ return 0;
3395+}
3396+
3397+static const struct argp argp_default_argp =
3398+ {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
3399+
3400+
3401+static const struct argp_option argp_version_options[] =
3402+{
3403+ {"version", 'V', 0, 0, N_("Print program version"), -1},
3404+ {0, 0}
3405+};
3406+
3407+static error_t
3408+argp_version_parser (int key, char *arg, struct argp_state *state)
3409+{
3410+ switch (key)
3411+ {
3412+ case 'V':
3413+ if (argp_program_version_hook)
3414+ (*argp_program_version_hook) (state->out_stream, state);
3415+ else if (argp_program_version)
3416+ fprintf (state->out_stream, "%s\n", argp_program_version);
3417+ else
3418+ argp_error (state, dgettext (state->root_argp->argp_domain,
3419+ "(PROGRAM ERROR) No version known!?"));
3420+ if (! (state->flags & ARGP_NO_EXIT))
3421+ exit (0);
3422+ break;
3423+ default:
3424+ return EBADKEY;
3425+ }
3426+ return 0;
3427+}
3428+
3429+static const struct argp argp_version_argp =
3430+ {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
3431+
3432+/* Returns the offset into the getopt long options array LONG_OPTIONS of a
3433+ long option with called NAME, or -1 if none is found. Passing NULL as
3434+ NAME will return the number of options. */
3435+static int
3436+find_long_option (struct option *long_options, const char *name)
3437+{
3438+ struct option *l = long_options;
3439+ while (l->name != NULL)
3440+ if (name != NULL && strcmp (l->name, name) == 0)
3441+ return l - long_options;
3442+ else
3443+ l++;
3444+ if (name == NULL)
3445+ return l - long_options;
3446+ else
3447+ return -1;
3448+}
3449+
3450+
3451+/* The state of a `group' during parsing. Each group corresponds to a
3452+ particular argp structure from the tree of such descending from the top
3453+ level argp passed to argp_parse. */
3454+struct group
3455+{
3456+ /* This group's parsing function. */
3457+ argp_parser_t parser;
3458+
3459+ /* Which argp this group is from. */
3460+ const struct argp *argp;
3461+
3462+ /* Points to the point in SHORT_OPTS corresponding to the end of the short
3463+ options for this group. We use it to determine from which group a
3464+ particular short options is from. */
3465+ char *short_end;
3466+
3467+ /* The number of non-option args sucessfully handled by this parser. */
3468+ unsigned args_processed;
3469+
3470+ /* This group's parser's parent's group. */
3471+ struct group *parent;
3472+ unsigned parent_index; /* And the our position in the parent. */
3473+
3474+ /* These fields are swapped into and out of the state structure when
3475+ calling this group's parser. */
3476+ void *input, **child_inputs;
3477+ void *hook;
3478+};
3479+
3480+/* Call GROUP's parser with KEY and ARG, swapping any group-specific info
3481+ from STATE before calling, and back into state afterwards. If GROUP has
3482+ no parser, EBADKEY is returned. */
3483+static error_t
3484+group_parse (struct group *group, struct argp_state *state, int key, char *arg)
3485+{
3486+ if (group->parser)
3487+ {
3488+ error_t err;
3489+ state->hook = group->hook;
3490+ state->input = group->input;
3491+ state->child_inputs = group->child_inputs;
3492+ state->arg_num = group->args_processed;
3493+ err = (*group->parser)(key, arg, state);
3494+ group->hook = state->hook;
3495+ return err;
3496+ }
3497+ else
3498+ return EBADKEY;
3499+}
3500+
3501+struct parser
3502+{
3503+ const struct argp *argp;
3504+
3505+ /* SHORT_OPTS is the getopt short options string for the union of all the
3506+ groups of options. */
3507+ char *short_opts;
3508+ /* LONG_OPTS is the array of getop long option structures for the union of
3509+ all the groups of options. */
3510+ struct option *long_opts;
3511+ /* OPT_DATA is the getopt data used for the re-entrant getopt. */
3512+ struct _getopt_data opt_data;
3513+
3514+ /* States of the various parsing groups. */
3515+ struct group *groups;
3516+ /* The end of the GROUPS array. */
3517+ struct group *egroup;
3518+ /* An vector containing storage for the CHILD_INPUTS field in all groups. */
3519+ void **child_inputs;
3520+
3521+ /* True if we think using getopt is still useful; if false, then
3522+ remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is
3523+ cleared whenever getopt returns KEY_END, but may be set again if the user
3524+ moves the next argument pointer backwards. */
3525+ int try_getopt;
3526+
3527+ /* State block supplied to parsing routines. */
3528+ struct argp_state state;
3529+
3530+ /* Memory used by this parser. */
3531+ void *storage;
3532+};
3533+
3534+/* The next usable entries in the various parser tables being filled in by
3535+ convert_options. */
3536+struct parser_convert_state
3537+{
3538+ struct parser *parser;
3539+ char *short_end;
3540+ struct option *long_end;
3541+ void **child_inputs_end;
3542+};
3543+
3544+/* Converts all options in ARGP (which is put in GROUP) and ancestors
3545+ into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and
3546+ CVT->LONG_END are the points at which new options are added. Returns the
3547+ next unused group entry. CVT holds state used during the conversion. */
3548+static struct group *
3549+convert_options (const struct argp *argp,
3550+ struct group *parent, unsigned parent_index,
3551+ struct group *group, struct parser_convert_state *cvt)
3552+{
3553+ /* REAL is the most recent non-alias value of OPT. */
3554+ const struct argp_option *real = argp->options;
3555+ const struct argp_child *children = argp->children;
3556+
3557+ if (real || argp->parser)
3558+ {
3559+ const struct argp_option *opt;
3560+
3561+ if (real)
3562+ for (opt = real; !__option_is_end (opt); opt++)
3563+ {
3564+ if (! (opt->flags & OPTION_ALIAS))
3565+ /* OPT isn't an alias, so we can use values from it. */
3566+ real = opt;
3567+
3568+ if (! (real->flags & OPTION_DOC))
3569+ /* A real option (not just documentation). */
3570+ {
3571+ if (__option_is_short (opt))
3572+ /* OPT can be used as a short option. */
3573+ {
3574+ *cvt->short_end++ = opt->key;
3575+ if (real->arg)
3576+ {
3577+ *cvt->short_end++ = ':';
3578+ if (real->flags & OPTION_ARG_OPTIONAL)
3579+ *cvt->short_end++ = ':';
3580+ }
3581+ *cvt->short_end = '\0'; /* keep 0 terminated */
3582+ }
3583+
3584+ if (opt->name
3585+ && find_long_option (cvt->parser->long_opts, opt->name) < 0)
3586+ /* OPT can be used as a long option. */
3587+ {
3588+ cvt->long_end->name = opt->name;
3589+ cvt->long_end->has_arg =
3590+ (real->arg
3591+ ? (real->flags & OPTION_ARG_OPTIONAL
3592+ ? optional_argument
3593+ : required_argument)
3594+ : no_argument);
3595+ cvt->long_end->flag = 0;
3596+ /* we add a disambiguating code to all the user's
3597+ values (which is removed before we actually call
3598+ the function to parse the value); this means that
3599+ the user loses use of the high 8 bits in all his
3600+ values (the sign of the lower bits is preserved
3601+ however)... */
3602+ cvt->long_end->val =
3603+ ((opt->key | real->key) & USER_MASK)
3604+ + (((group - cvt->parser->groups) + 1) << USER_BITS);
3605+
3606+ /* Keep the LONG_OPTS list terminated. */
3607+ (++cvt->long_end)->name = NULL;
3608+ }
3609+ }
3610+ }
3611+
3612+ group->parser = argp->parser;
3613+ group->argp = argp;
3614+ group->short_end = cvt->short_end;
3615+ group->args_processed = 0;
3616+ group->parent = parent;
3617+ group->parent_index = parent_index;
3618+ group->input = 0;
3619+ group->hook = 0;
3620+ group->child_inputs = 0;
3621+
3622+ if (children)
3623+ /* Assign GROUP's CHILD_INPUTS field some space from
3624+ CVT->child_inputs_end.*/
3625+ {
3626+ unsigned num_children = 0;
3627+ while (children[num_children].argp)
3628+ num_children++;
3629+ group->child_inputs = cvt->child_inputs_end;
3630+ cvt->child_inputs_end += num_children;
3631+ }
3632+
3633+ parent = group++;
3634+ }
3635+ else
3636+ parent = 0;
3637+
3638+ if (children)
3639+ {
3640+ unsigned index = 0;
3641+ while (children->argp)
3642+ group =
3643+ convert_options (children++->argp, parent, index++, group, cvt);
3644+ }
3645+
3646+ return group;
3647+}
3648+
3649+/* Find the merged set of getopt options, with keys appropiately prefixed. */
3650+static void
3651+parser_convert (struct parser *parser, const struct argp *argp, int flags)
3652+{
3653+ struct parser_convert_state cvt;
3654+
3655+ cvt.parser = parser;
3656+ cvt.short_end = parser->short_opts;
3657+ cvt.long_end = parser->long_opts;
3658+ cvt.child_inputs_end = parser->child_inputs;
3659+
3660+ if (flags & ARGP_IN_ORDER)
3661+ *cvt.short_end++ = '-';
3662+ else if (flags & ARGP_NO_ARGS)
3663+ *cvt.short_end++ = '+';
3664+ *cvt.short_end = '\0';
3665+
3666+ cvt.long_end->name = NULL;
3667+
3668+ parser->argp = argp;
3669+
3670+ if (argp)
3671+ parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
3672+ else
3673+ parser->egroup = parser->groups; /* No parsers at all! */
3674+}
3675+
3676+/* Lengths of various parser fields which we will allocated. */
3677+struct parser_sizes
3678+{
3679+ size_t short_len; /* Getopt short options string. */
3680+ size_t long_len; /* Getopt long options vector. */
3681+ size_t num_groups; /* Group structures we allocate. */
3682+ size_t num_child_inputs; /* Child input slots. */
3683+};
3684+
3685+/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of
3686+ argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by
3687+ the maximum lengths of the resulting merged getopt short options string and
3688+ long-options array, respectively. */
3689+static void
3690+calc_sizes (const struct argp *argp, struct parser_sizes *szs)
3691+{
3692+ const struct argp_child *child = argp->children;
3693+ const struct argp_option *opt = argp->options;
3694+
3695+ if (opt || argp->parser)
3696+ {
3697+ szs->num_groups++;
3698+ if (opt)
3699+ {
3700+ int num_opts = 0;
3701+ while (!__option_is_end (opt++))
3702+ num_opts++;
3703+ szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */
3704+ szs->long_len += num_opts;
3705+ }
3706+ }
3707+
3708+ if (child)
3709+ while (child->argp)
3710+ {
3711+ calc_sizes ((child++)->argp, szs);
3712+ szs->num_child_inputs++;
3713+ }
3714+}
3715+
3716+
3717+extern char * __argp_short_program_name (void);
3718+/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */
3719+static error_t
3720+parser_init (struct parser *parser, const struct argp *argp,
3721+ int argc, char **argv, int flags, void *input)
3722+{
3723+ error_t err = 0;
3724+ struct group *group;
3725+ struct parser_sizes szs;
3726+ struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
3727+
3728+ szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
3729+ szs.long_len = 0;
3730+ szs.num_groups = 0;
3731+ szs.num_child_inputs = 0;
3732+
3733+ if (argp)
3734+ calc_sizes (argp, &szs);
3735+
3736+ /* Lengths of the various bits of storage used by PARSER. */
3737+#define GLEN (szs.num_groups + 1) * sizeof (struct group)
3738+#define CLEN (szs.num_child_inputs * sizeof (void *))
3739+#define LLEN ((szs.long_len + 1) * sizeof (struct option))
3740+#define SLEN (szs.short_len + 1)
3741+
3742+ parser->storage = malloc (GLEN + CLEN + LLEN + SLEN);
3743+ if (! parser->storage)
3744+ return ENOMEM;
3745+
3746+ parser->groups = parser->storage;
3747+ parser->child_inputs = parser->storage + GLEN;
3748+ parser->long_opts = parser->storage + GLEN + CLEN;
3749+ parser->short_opts = parser->storage + GLEN + CLEN + LLEN;
3750+ parser->opt_data = opt_data;
3751+
3752+ memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
3753+ parser_convert (parser, argp, flags);
3754+
3755+ memset (&parser->state, 0, sizeof (struct argp_state));
3756+ parser->state.root_argp = parser->argp;
3757+ parser->state.argc = argc;
3758+ parser->state.argv = argv;
3759+ parser->state.flags = flags;
3760+ parser->state.err_stream = stderr;
3761+ parser->state.out_stream = stdout;
3762+ parser->state.next = 0; /* Tell getopt to initialize. */
3763+ parser->state.pstate = parser;
3764+
3765+ parser->try_getopt = 1;
3766+
3767+ /* Call each parser for the first time, giving it a chance to propagate
3768+ values to child parsers. */
3769+ if (parser->groups < parser->egroup)
3770+ parser->groups->input = input;
3771+ for (group = parser->groups;
3772+ group < parser->egroup && (!err || err == EBADKEY);
3773+ group++)
3774+ {
3775+ if (group->parent)
3776+ /* If a child parser, get the initial input value from the parent. */
3777+ group->input = group->parent->child_inputs[group->parent_index];
3778+
3779+ if (!group->parser
3780+ && group->argp->children && group->argp->children->argp)
3781+ /* For the special case where no parsing function is supplied for an
3782+ argp, propagate its input to its first child, if any (this just
3783+ makes very simple wrapper argps more convenient). */
3784+ group->child_inputs[0] = group->input;
3785+
3786+ err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
3787+ }
3788+ if (err == EBADKEY)
3789+ err = 0; /* Some parser didn't understand. */
3790+
3791+ if (err)
3792+ return err;
3793+
3794+ if (parser->state.flags & ARGP_NO_ERRS)
3795+ {
3796+ parser->opt_data.opterr = 0;
3797+ if (parser->state.flags & ARGP_PARSE_ARGV0)
3798+ /* getopt always skips ARGV[0], so we have to fake it out. As long
3799+ as OPTERR is 0, then it shouldn't actually try to access it. */
3800+ parser->state.argv--, parser->state.argc++;
3801+ }
3802+ else
3803+ parser->opt_data.opterr = 1; /* Print error messages. */
3804+
3805+ if (parser->state.argv == argv && argv[0])
3806+ /* There's an argv[0]; use it for messages. */
3807+ {
3808+ char *short_name = strrchr (argv[0], '/');
3809+ parser->state.name = short_name ? short_name + 1 : argv[0];
3810+ }
3811+ else
3812+ parser->state.name = __argp_short_program_name ();
3813+
3814+ return 0;
3815+}
3816+
3817+/* Free any storage consumed by PARSER (but not PARSER itself). */
3818+static error_t
3819+parser_finalize (struct parser *parser,
3820+ error_t err, int arg_ebadkey, int *end_index)
3821+{
3822+ struct group *group;
3823+
3824+ if (err == EBADKEY && arg_ebadkey)
3825+ /* Suppress errors generated by unparsed arguments. */
3826+ err = 0;
3827+
3828+ if (! err)
3829+ {
3830+ if (parser->state.next == parser->state.argc)
3831+ /* We successfully parsed all arguments! Call all the parsers again,
3832+ just a few more times... */
3833+ {
3834+ for (group = parser->groups;
3835+ group < parser->egroup && (!err || err==EBADKEY);
3836+ group++)
3837+ if (group->args_processed == 0)
3838+ err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
3839+ for (group = parser->egroup - 1;
3840+ group >= parser->groups && (!err || err==EBADKEY);
3841+ group--)
3842+ err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
3843+
3844+ if (err == EBADKEY)
3845+ err = 0; /* Some parser didn't understand. */
3846+
3847+ /* Tell the user that all arguments are parsed. */
3848+ if (end_index)
3849+ *end_index = parser->state.next;
3850+ }
3851+ else if (end_index)
3852+ /* Return any remaining arguments to the user. */
3853+ *end_index = parser->state.next;
3854+ else
3855+ /* No way to return the remaining arguments, they must be bogus. */
3856+ {
3857+ if (!(parser->state.flags & ARGP_NO_ERRS)
3858+ && parser->state.err_stream)
3859+ fprintf (parser->state.err_stream,
3860+ dgettext (parser->argp->argp_domain,
3861+ "%s: Too many arguments\n"),
3862+ parser->state.name);
3863+ err = EBADKEY;
3864+ }
3865+ }
3866+
3867+ /* Okay, we're all done, with either an error or success; call the parsers
3868+ to indicate which one. */
3869+
3870+ if (err)
3871+ {
3872+ /* Maybe print an error message. */
3873+ if (err == EBADKEY)
3874+ /* An appropriate message describing what the error was should have
3875+ been printed earlier. */
3876+ argp_state_help (&parser->state, parser->state.err_stream,
3877+ ARGP_HELP_STD_ERR);
3878+
3879+ /* Since we didn't exit, give each parser an error indication. */
3880+ for (group = parser->groups; group < parser->egroup; group++)
3881+ group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
3882+ }
3883+ else
3884+ /* Notify parsers of success, and propagate back values from parsers. */
3885+ {
3886+ /* We pass over the groups in reverse order so that child groups are
3887+ given a chance to do there processing before passing back a value to
3888+ the parent. */
3889+ for (group = parser->egroup - 1
3890+ ; group >= parser->groups && (!err || err == EBADKEY)
3891+ ; group--)
3892+ err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
3893+ if (err == EBADKEY)
3894+ err = 0; /* Some parser didn't understand. */
3895+ }
3896+
3897+ /* Call parsers once more, to do any final cleanup. Errors are ignored. */
3898+ for (group = parser->egroup - 1; group >= parser->groups; group--)
3899+ group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
3900+
3901+ if (err == EBADKEY)
3902+ err = EINVAL;
3903+
3904+ free (parser->storage);
3905+
3906+ return err;
3907+}
3908+
3909+/* Call the user parsers to parse the non-option argument VAL, at the current
3910+ position, returning any error. The state NEXT pointer is assumed to have
3911+ been adjusted (by getopt) to point after this argument; this function will
3912+ adjust it correctly to reflect however many args actually end up being
3913+ consumed. */
3914+static error_t
3915+parser_parse_arg (struct parser *parser, char *val)
3916+{
3917+ /* Save the starting value of NEXT, first adjusting it so that the arg
3918+ we're parsing is again the front of the arg vector. */
3919+ int index = --parser->state.next;
3920+ error_t err = EBADKEY;
3921+ struct group *group;
3922+ int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */
3923+
3924+ /* Try to parse the argument in each parser. */
3925+ for (group = parser->groups
3926+ ; group < parser->egroup && err == EBADKEY
3927+ ; group++)
3928+ {
3929+ parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */
3930+ key = ARGP_KEY_ARG;
3931+ err = group_parse (group, &parser->state, key, val);
3932+
3933+ if (err == EBADKEY)
3934+ /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
3935+ {
3936+ parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */
3937+ key = ARGP_KEY_ARGS;
3938+ err = group_parse (group, &parser->state, key, 0);
3939+ }
3940+ }
3941+
3942+ if (! err)
3943+ {
3944+ if (key == ARGP_KEY_ARGS)
3945+ /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
3946+ changed by the user, *all* arguments should be considered
3947+ consumed. */
3948+ parser->state.next = parser->state.argc;
3949+
3950+ if (parser->state.next > index)
3951+ /* Remember that we successfully processed a non-option
3952+ argument -- but only if the user hasn't gotten tricky and set
3953+ the clock back. */
3954+ (--group)->args_processed += (parser->state.next - index);
3955+ else
3956+ /* The user wants to reparse some args, give getopt another try. */
3957+ parser->try_getopt = 1;
3958+ }
3959+
3960+ return err;
3961+}
3962+
3963+/* Call the user parsers to parse the option OPT, with argument VAL, at the
3964+ current position, returning any error. */
3965+static error_t
3966+parser_parse_opt (struct parser *parser, int opt, char *val)
3967+{
3968+ /* The group key encoded in the high bits; 0 for short opts or
3969+ group_number + 1 for long opts. */
3970+ int group_key = opt >> USER_BITS;
3971+ error_t err = EBADKEY;
3972+
3973+ if (group_key == 0)
3974+ /* A short option. By comparing OPT's position in SHORT_OPTS to the
3975+ various starting positions in each group's SHORT_END field, we can
3976+ determine which group OPT came from. */
3977+ {
3978+ struct group *group;
3979+ char *short_index = strchr (parser->short_opts, opt);
3980+
3981+ if (short_index)
3982+ for (group = parser->groups; group < parser->egroup; group++)
3983+ if (group->short_end > short_index)
3984+ {
3985+ err = group_parse (group, &parser->state, opt,
3986+ parser->opt_data.optarg);
3987+ break;
3988+ }
3989+ }
3990+ else
3991+ /* A long option. We use shifts instead of masking for extracting
3992+ the user value in order to preserve the sign. */
3993+ err =
3994+ group_parse (&parser->groups[group_key - 1], &parser->state,
3995+ (opt << GROUP_BITS) >> GROUP_BITS,
3996+ parser->opt_data.optarg);
3997+
3998+ if (err == EBADKEY)
3999+ /* At least currently, an option not recognized is an error in the
4000+ parser, because we pre-compute which parser is supposed to deal
4001+ with each option. */
4002+ {
4003+ static const char bad_key_err[] =
4004+ N_("(PROGRAM ERROR) Option should have been recognized!?");
4005+ if (group_key == 0)
4006+ argp_error (&parser->state, "-%c: %s", opt,
4007+ dgettext (parser->argp->argp_domain, bad_key_err));
4008+ else
4009+ {
4010+ struct option *long_opt = parser->long_opts;
4011+ while (long_opt->val != opt && long_opt->name)
4012+ long_opt++;
4013+ argp_error (&parser->state, "--%s: %s",
4014+ long_opt->name ? long_opt->name : "???",
4015+ dgettext (parser->argp->argp_domain, bad_key_err));
4016+ }
4017+ }
4018+
4019+ return err;
4020+}
4021+
4022+/* Parse the next argument in PARSER (as indicated by PARSER->state.next).
4023+ Any error from the parsers is returned, and *ARGP_EBADKEY indicates
4024+ whether a value of EBADKEY is due to an unrecognized argument (which is
4025+ generally not fatal). */
4026+static error_t
4027+parser_parse_next (struct parser *parser, int *arg_ebadkey)
4028+{
4029+ int opt;
4030+ error_t err = 0;
4031+
4032+ if (parser->state.quoted && parser->state.next < parser->state.quoted)
4033+ /* The next argument pointer has been moved to before the quoted
4034+ region, so pretend we never saw the quoting `--', and give getopt
4035+ another chance. If the user hasn't removed it, getopt will just
4036+ process it again. */
4037+ parser->state.quoted = 0;
4038+
4039+ if (parser->try_getopt && !parser->state.quoted)
4040+ /* Give getopt a chance to parse this. */
4041+ {
4042+ /* Put it back in OPTIND for getopt. */
4043+ parser->opt_data.optind = parser->state.next;
4044+ /* Distinguish KEY_ERR from a real option. */
4045+ parser->opt_data.optopt = KEY_END;
4046+ if (parser->state.flags & ARGP_LONG_ONLY)
4047+ opt = _getopt_long_only_r (parser->state.argc, parser->state.argv,
4048+ parser->short_opts, parser->long_opts, 0,
4049+ &parser->opt_data);
4050+ else
4051+ opt = _getopt_long_r (parser->state.argc, parser->state.argv,
4052+ parser->short_opts, parser->long_opts, 0,
4053+ &parser->opt_data);
4054+ /* And see what getopt did. */
4055+ parser->state.next = parser->opt_data.optind;
4056+
4057+ if (opt == KEY_END)
4058+ /* Getopt says there are no more options, so stop using
4059+ getopt; we'll continue if necessary on our own. */
4060+ {
4061+ parser->try_getopt = 0;
4062+ if (parser->state.next > 1
4063+ && strcmp (parser->state.argv[parser->state.next - 1], QUOTE)
4064+ == 0)
4065+ /* Not only is this the end of the options, but it's a
4066+ `quoted' region, which may have args that *look* like
4067+ options, so we definitely shouldn't try to use getopt past
4068+ here, whatever happens. */
4069+ parser->state.quoted = parser->state.next;
4070+ }
4071+ else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END)
4072+ /* KEY_ERR can have the same value as a valid user short
4073+ option, but in the case of a real error, getopt sets OPTOPT
4074+ to the offending character, which can never be KEY_END. */
4075+ {
4076+ *arg_ebadkey = 0;
4077+ return EBADKEY;
4078+ }
4079+ }
4080+ else
4081+ opt = KEY_END;
4082+
4083+ if (opt == KEY_END)
4084+ {
4085+ /* We're past what getopt considers the options. */
4086+ if (parser->state.next >= parser->state.argc
4087+ || (parser->state.flags & ARGP_NO_ARGS))
4088+ /* Indicate that we're done. */
4089+ {
4090+ *arg_ebadkey = 1;
4091+ return EBADKEY;
4092+ }
4093+ else
4094+ /* A non-option arg; simulate what getopt might have done. */
4095+ {
4096+ opt = KEY_ARG;
4097+ parser->opt_data.optarg = parser->state.argv[parser->state.next++];
4098+ }
4099+ }
4100+
4101+ if (opt == KEY_ARG)
4102+ /* A non-option argument; try each parser in turn. */
4103+ err = parser_parse_arg (parser, parser->opt_data.optarg);
4104+ else
4105+ err = parser_parse_opt (parser, opt, parser->opt_data.optarg);
4106+
4107+ if (err == EBADKEY)
4108+ *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG);
4109+
4110+ return err;
4111+}
4112+
4113+/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
4114+ FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
4115+ index in ARGV of the first unparsed option is returned in it. If an
4116+ unknown option is present, EINVAL is returned; if some parser routine
4117+ returned a non-zero value, it is returned; otherwise 0 is returned. */
4118+error_t
4119+argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
4120+ int *end_index, void *input)
4121+{
4122+ error_t err;
4123+ struct parser parser;
4124+
4125+ /* If true, then err == EBADKEY is a result of a non-option argument failing
4126+ to be parsed (which in some cases isn't actually an error). */
4127+ int arg_ebadkey = 0;
4128+
4129+ if (! (flags & ARGP_NO_HELP))
4130+ /* Add our own options. */
4131+ {
4132+ struct argp_child *child = alloca (4 * sizeof (struct argp_child));
4133+ struct argp *top_argp = alloca (sizeof (struct argp));
4134+
4135+ /* TOP_ARGP has no options, it just serves to group the user & default
4136+ argps. */
4137+ memset (top_argp, 0, sizeof (*top_argp));
4138+ top_argp->children = child;
4139+
4140+ memset (child, 0, 4 * sizeof (struct argp_child));
4141+
4142+ if (argp)
4143+ (child++)->argp = argp;
4144+ (child++)->argp = &argp_default_argp;
4145+ if (argp_program_version || argp_program_version_hook)
4146+ (child++)->argp = &argp_version_argp;
4147+ child->argp = 0;
4148+
4149+ argp = top_argp;
4150+ }
4151+
4152+ /* Construct a parser for these arguments. */
4153+ err = parser_init (&parser, argp, argc, argv, flags, input);
4154+
4155+ if (! err)
4156+ /* Parse! */
4157+ {
4158+ while (! err)
4159+ err = parser_parse_next (&parser, &arg_ebadkey);
4160+ err = parser_finalize (&parser, err, arg_ebadkey, end_index);
4161+ }
4162+
4163+ return err;
4164+}
4165+
4166+/* Return the input field for ARGP in the parser corresponding to STATE; used
4167+ by the help routines. */
4168+void *
4169+__argp_input (const struct argp *argp, const struct argp_state *state)
4170+{
4171+ if (state)
4172+ {
4173+ struct group *group;
4174+ struct parser *parser = state->pstate;
4175+
4176+ for (group = parser->groups; group < parser->egroup; group++)
4177+ if (group->argp == argp)
4178+ return group->input;
4179+ }
4180+
4181+ return 0;
4182+}
4183Index: git/libuargp/argp-pv.c
4184===================================================================
4185--- /dev/null
4186+++ git/libuargp/argp-pv.c
4187@@ -0,0 +1,25 @@
4188+/* Default definition for ARGP_PROGRAM_VERSION.
4189+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4190+ This file is part of the GNU C Library.
4191+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4192+
4193+ The GNU C Library is free software; you can redistribute it and/or
4194+ modify it under the terms of the GNU Lesser General Public
4195+ License as published by the Free Software Foundation; either
4196+ version 2.1 of the License, or (at your option) any later version.
4197+
4198+ The GNU C Library is distributed in the hope that it will be useful,
4199+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4200+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4201+ Lesser General Public License for more details.
4202+
4203+ You should have received a copy of the GNU Lesser General Public
4204+ License along with the GNU C Library; if not, write to the Free
4205+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4206+ 02111-1307 USA. */
4207+
4208+/* If set by the user program to a non-zero value, then a default option
4209+ --version is added (unless the ARGP_NO_HELP flag is used), which will
4210+ print this this string followed by a newline and exit (unless the
4211+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
4212+const char *argp_program_version;
4213Index: git/libuargp/argp-pvh.c
4214===================================================================
4215--- /dev/null
4216+++ git/libuargp/argp-pvh.c
4217@@ -0,0 +1,32 @@
4218+/* Default definition for ARGP_PROGRAM_VERSION_HOOK.
4219+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4220+ This file is part of the GNU C Library.
4221+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4222+
4223+ The GNU C Library is free software; you can redistribute it and/or
4224+ modify it under the terms of the GNU Lesser General Public
4225+ License as published by the Free Software Foundation; either
4226+ version 2.1 of the License, or (at your option) any later version.
4227+
4228+ The GNU C Library is distributed in the hope that it will be useful,
4229+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4230+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4231+ Lesser General Public License for more details.
4232+
4233+ You should have received a copy of the GNU Lesser General Public
4234+ License along with the GNU C Library; if not, write to the Free
4235+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4236+ 02111-1307 USA. */
4237+
4238+#ifdef HAVE_CONFIG_H
4239+#include <config.h>
4240+#endif
4241+
4242+#include <argp.h>
4243+
4244+/* If set by the user program to a non-zero value, then a default option
4245+ --version is added (unless the ARGP_NO_HELP flag is used), which calls
4246+ this function with a stream to print the version to and a pointer to the
4247+ current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
4248+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
4249+void (*argp_program_version_hook) (FILE *stream, struct argp_state *state);
4250Index: git/libuargp/argp-xinl.c
4251===================================================================
4252--- /dev/null
4253+++ git/libuargp/argp-xinl.c
4254@@ -0,0 +1,35 @@
4255+/* Real definitions for extern inline functions in argp.h
4256+ Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc.
4257+ This file is part of the GNU C Library.
4258+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4259+
4260+ The GNU C Library is free software; you can redistribute it and/or
4261+ modify it under the terms of the GNU Lesser General Public
4262+ License as published by the Free Software Foundation; either
4263+ version 2.1 of the License, or (at your option) any later version.
4264+
4265+ The GNU C Library is distributed in the hope that it will be useful,
4266+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4267+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4268+ Lesser General Public License for more details.
4269+
4270+ You should have received a copy of the GNU Lesser General Public
4271+ License along with the GNU C Library; if not, write to the Free
4272+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4273+ 02111-1307 USA. */
4274+
4275+#ifdef HAVE_CONFIG_H
4276+# include <config.h>
4277+#endif
4278+
4279+#if defined _LIBC || defined HAVE_FEATURES_H
4280+# include <features.h>
4281+#endif
4282+
4283+#ifndef __USE_EXTERN_INLINES
4284+# define __USE_EXTERN_INLINES 1
4285+#endif
4286+#define ARGP_EI
4287+#undef __OPTIMIZE__
4288+#define __OPTIMIZE__ 1
4289+#include <argp.h>
4290Index: git/test/argp/Makefile
4291===================================================================
4292--- /dev/null
4293+++ git/test/argp/Makefile
4294@@ -0,0 +1,7 @@
4295+# uClibc argp tests
4296+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
4297+
4298+top_builddir=../../
4299+include ../Rules.mak
4300+-include Makefile.in
4301+include ../Test.mak
4302Index: git/test/argp/Makefile.in
4303===================================================================
4304--- /dev/null
4305+++ git/test/argp/Makefile.in
4306@@ -0,0 +1,12 @@
4307+# uClibc argp tests
4308+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
4309+
4310+TESTS := $(addprefix argp-, ex1 ex2 ex3 ex4 test) \
4311+ bug-argp1 tst-argp1 tst-argp2
4312+
4313+EXTRA_LDFLAGS = -luargp
4314+
4315+OPTS_argp-ex3 = ARG1 ARG2
4316+OPTS_argp-ex4 = ARG1 string1 string2 string3
4317+OPTS_bug-argp1 = -- --help
4318+
4319Index: git/test/argp/argp-ex1.c
4320===================================================================
4321--- /dev/null
4322+++ git/test/argp/argp-ex1.c
4323@@ -0,0 +1,15 @@
4324+/* Argp example #1 -- a minimal program using argp */
4325+
4326+/* This is (probably) the smallest possible program that
4327+ uses argp. It won't do much except give an error
4328+ messages and exit when there are any arguments, and print
4329+ a (rather pointless) messages for --help. */
4330+
4331+#include <stdlib.h>
4332+#include <argp.h>
4333+
4334+int main (int argc, char **argv)
4335+{
4336+ argp_parse (0, argc, argv, 0, 0, 0);
4337+ exit (0);
4338+}
4339Index: git/test/argp/argp-ex2.c
4340===================================================================
4341--- /dev/null
4342+++ git/test/argp/argp-ex2.c
4343@@ -0,0 +1,45 @@
4344+/* Argp example #2 -- a pretty minimal program using argp */
4345+
4346+/* This program doesn't use any options or arguments, but uses
4347+ argp to be compliant with the GNU standard command line
4348+ format.
4349+
4350+ In addition to making sure no arguments are given, and
4351+ implementing a --help option, this example will have a
4352+ --version option, and will put the given documentation string
4353+ and bug address in the --help output, as per GNU standards.
4354+
4355+ The variable ARGP contains the argument parser specification;
4356+ adding fields to this structure is the way most parameters are
4357+ passed to argp_parse (the first three fields are usually used,
4358+ but not in this small program). There are also two global
4359+ variables that argp knows about defined here,
4360+ ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
4361+ global variables because they will almost always be constant
4362+ for a given program, even if it uses different argument
4363+ parsers for various tasks). */
4364+
4365+#include <stdlib.h>
4366+#include <argp.h>
4367+
4368+const char *argp_program_version =
4369+ "argp-ex2 1.0";
4370+const char *argp_program_bug_address =
4371+ "<bug-gnu-utils@@gnu.org>";
4372+
4373+/* Program documentation. */
4374+static char doc[] =
4375+ "Argp example #2 -- a pretty minimal program using argp";
4376+
4377+/* Our argument parser. The @code{options}, @code{parser}, and
4378+ @code{args_doc} fields are zero because we have neither options or
4379+ arguments; @code{doc} and @code{argp_program_bug_address} will be
4380+ used in the output for @samp{--help}, and the @samp{--version}
4381+ option will print out @code{argp_program_version}. */
4382+static struct argp argp = { 0, 0, 0, doc };
4383+
4384+int main (int argc, char **argv)
4385+{
4386+ argp_parse (&argp, argc, argv, 0, 0, 0);
4387+ exit (0);
4388+}
4389Index: git/test/argp/argp-ex3.c
4390===================================================================
4391--- /dev/null
4392+++ git/test/argp/argp-ex3.c
4393@@ -0,0 +1,153 @@
4394+/* Argp example #3 -- a program with options and arguments using argp */
4395+
4396+/* This program uses the same features as example 2, and uses options and
4397+ arguments.
4398+
4399+ We now use the first four fields in ARGP, so here's a description of them:
4400+ OPTIONS -- A pointer to a vector of struct argp_option (see below)
4401+ PARSER -- A function to parse a single option, called by argp
4402+ ARGS_DOC -- A string describing how the non-option arguments should look
4403+ DOC -- A descriptive string about this program; if it contains a
4404+ vertical tab character (\v), the part after it will be
4405+ printed *following* the options
4406+
4407+ The function PARSER takes the following arguments:
4408+ KEY -- An integer specifying which option this is (taken
4409+ from the KEY field in each struct argp_option), or
4410+ a special key specifying something else; the only
4411+ special keys we use here are ARGP_KEY_ARG, meaning
4412+ a non-option argument, and ARGP_KEY_END, meaning
4413+ that all arguments have been parsed
4414+ ARG -- For an option KEY, the string value of its
4415+ argument, or NULL if it has none
4416+ STATE-- A pointer to a struct argp_state, containing
4417+ various useful information about the parsing state; used here
4418+ are the INPUT field, which reflects the INPUT argument to
4419+ argp_parse, and the ARG_NUM field, which is the number of the
4420+ current non-option argument being parsed
4421+ It should return either 0, meaning success, ARGP_ERR_UNKNOWN, meaning the
4422+ given KEY wasn't recognized, or an errno value indicating some other
4423+ error.
4424+
4425+ Note that in this example, main uses a structure to communicate with the
4426+ parse_opt function, a pointer to which it passes in the INPUT argument to
4427+ argp_parse. Of course, it's also possible to use global variables
4428+ instead, but this is somewhat more flexible.
4429+
4430+ The OPTIONS field contains a pointer to a vector of struct argp_option's;
4431+ that structure has the following fields (if you assign your option
4432+ structures using array initialization like this example, unspecified
4433+ fields will be defaulted to 0, and need not be specified):
4434+ NAME -- The name of this option's long option (may be zero)
4435+ KEY -- The KEY to pass to the PARSER function when parsing this option,
4436+ *and* the name of this option's short option, if it is a
4437+ printable ascii character
4438+ ARG -- The name of this option's argument, if any
4439+ FLAGS -- Flags describing this option; some of them are:
4440+ OPTION_ARG_OPTIONAL -- The argument to this option is optional
4441+ OPTION_ALIAS -- This option is an alias for the
4442+ previous option
4443+ OPTION_HIDDEN -- Don't show this option in --help output
4444+ DOC -- A documentation string for this option, shown in --help output
4445+
4446+ An options vector should be terminated by an option with all fields zero. */
4447+
4448+#include <stdlib.h>
4449+#include <argp.h>
4450+
4451+const char *argp_program_version =
4452+ "argp-ex3 1.0";
4453+const char *argp_program_bug_address =
4454+ "<bug-gnu-utils@@gnu.org>";
4455+
4456+/* Program documentation. */
4457+static char doc[] =
4458+ "Argp example #3 -- a program with options and arguments using argp";
4459+
4460+/* A description of the arguments we accept. */
4461+static char args_doc[] = "ARG1 ARG2";
4462+
4463+/* The options we understand. */
4464+static struct argp_option options[] = {
4465+ {"verbose", 'v', 0, 0, "Produce verbose output" },
4466+ {"quiet", 'q', 0, 0, "Don't produce any output" },
4467+ {"silent", 's', 0, OPTION_ALIAS },
4468+ {"output", 'o', "FILE", 0,
4469+ "Output to FILE instead of standard output" },
4470+ { 0 }
4471+};
4472+
4473+/* Used by @code{main} to communicate with @code{parse_opt}. */
4474+struct arguments
4475+{
4476+ char *args[2]; /* @var{arg1} & @var{arg2} */
4477+ int silent, verbose;
4478+ char *output_file;
4479+};
4480+
4481+/* Parse a single option. */
4482+static error_t
4483+parse_opt (int key, char *arg, struct argp_state *state)
4484+{
4485+ /* Get the @var{input} argument from @code{argp_parse}, which we
4486+ know is a pointer to our arguments structure. */
4487+ struct arguments *arguments = state->input;
4488+
4489+ switch (key)
4490+ {
4491+ case 'q': case 's':
4492+ arguments->silent = 1;
4493+ break;
4494+ case 'v':
4495+ arguments->verbose = 1;
4496+ break;
4497+ case 'o':
4498+ arguments->output_file = arg;
4499+ break;
4500+
4501+ case ARGP_KEY_ARG:
4502+ if (state->arg_num >= 2)
4503+ /* Too many arguments. */
4504+ argp_usage (state);
4505+
4506+ arguments->args[state->arg_num] = arg;
4507+
4508+ break;
4509+
4510+ case ARGP_KEY_END:
4511+ if (state->arg_num < 2)
4512+ /* Not enough arguments. */
4513+ argp_usage (state);
4514+ break;
4515+
4516+ default:
4517+ return ARGP_ERR_UNKNOWN;
4518+ }
4519+ return 0;
4520+}
4521+
4522+/* Our argp parser. */
4523+static struct argp argp = { options, parse_opt, args_doc, doc };
4524+
4525+int main (int argc, char **argv)
4526+{
4527+ struct arguments arguments;
4528+
4529+ /* Default values. */
4530+ arguments.silent = 0;
4531+ arguments.verbose = 0;
4532+ arguments.output_file = "-";
4533+
4534+ /* Parse our arguments; every option seen by @code{parse_opt} will
4535+ be reflected in @code{arguments}. */
4536+ argp_parse (&argp, argc, argv, 0, 0, &arguments);
4537+
4538+ printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n"
4539+ "VERBOSE = %s\nSILENT = %s\n",
4540+ arguments.args[0], arguments.args[1],
4541+ arguments.output_file,
4542+ arguments.verbose ? "yes" : "no",
4543+ arguments.silent ? "yes" : "no");
4544+
4545+ exit (0);
4546+}
4547Index: git/test/argp/argp-ex4.c
4548===================================================================
4549--- /dev/null
4550+++ git/test/argp/argp-ex4.c
4551@@ -0,0 +1,167 @@
4552+/* Argp example #4 -- a program with somewhat more complicated options */
4553+
4554+/* This program uses the same features as example 3, but has more
4555+ options, and somewhat more structure in the -help output. It
4556+ also shows how you can `steal' the remainder of the input
4557+ arguments past a certain point, for programs that accept a
4558+ list of items. It also shows the special argp KEY value
4559+ ARGP_KEY_NO_ARGS, which is only given if no non-option
4560+ arguments were supplied to the program.
4561+
4562+ For structuring the help output, two features are used,
4563+ *headers* which are entries in the options vector with the
4564+ first four fields being zero, and a two part documentation
4565+ string (in the variable DOC), which allows documentation both
4566+ before and after the options; the two parts of DOC are
4567+ separated by a vertical-tab character ('\v', or '\013'). By
4568+ convention, the documentation before the options is just a
4569+ short string saying what the program does, and that afterwards
4570+ is longer, describing the behavior in more detail. All
4571+ documentation strings are automatically filled for output,
4572+ although newlines may be included to force a line break at a
4573+ particular point. All documentation strings are also passed to
4574+ the `gettext' function, for possible translation into the
4575+ current locale. */
4576+
4577+#include <stdlib.h>
4578+#include <error.h>
4579+#include <argp.h>
4580+
4581+const char *argp_program_version =
4582+ "argp-ex4 1.0";
4583+const char *argp_program_bug_address =
4584+ "<bug-gnu-utils@@prep.ai.mit.edu>";
4585+
4586+/* Program documentation. */
4587+static char doc[] =
4588+ "Argp example #4 -- a program with somewhat more complicated\
4589+options\
4590+\vThis part of the documentation comes *after* the options;\
4591+ note that the text is automatically filled, but it's possible\
4592+ to force a line-break, e.g.\n<-- here.";
4593+
4594+/* A description of the arguments we accept. */
4595+static char args_doc[] = "ARG1 [STRING...]";
4596+
4597+/* Keys for options without short-options. */
4598+#define OPT_ABORT 1 /* --abort */
4599+
4600+/* The options we understand. */
4601+static struct argp_option options[] = {
4602+ {"verbose", 'v', 0, 0, "Produce verbose output" },
4603+ {"quiet", 'q', 0, 0, "Don't produce any output" },
4604+ {"silent", 's', 0, OPTION_ALIAS },
4605+ {"output", 'o', "FILE", 0,
4606+ "Output to FILE instead of standard output" },
4607+
4608+ {0,0,0,0, "The following options should be grouped together:" },
4609+ {"repeat", 'r', "COUNT", OPTION_ARG_OPTIONAL,
4610+ "Repeat the output COUNT (default 10) times"},
4611+ {"abort", OPT_ABORT, 0, 0, "Abort before showing any output"},
4612+
4613+ { 0 }
4614+};
4615+
4616+/* Used by @code{main} to communicate with @code{parse_opt}. */
4617+struct arguments
4618+{
4619+ char *arg1; /* @var{arg1} */
4620+ char **strings; /* [@var{string}@dots{}] */
4621+ int silent, verbose, abort; /* @samp{-s}, @samp{-v}, @samp{--abort} */
4622+ char *output_file; /* @var{file} arg to @samp{--output} */
4623+ int repeat_count; /* @var{count} arg to @samp{--repeat} */
4624+};
4625+
4626+/* Parse a single option. */
4627+static error_t
4628+parse_opt (int key, char *arg, struct argp_state *state)
4629+{
4630+ /* Get the @code{input} argument from @code{argp_parse}, which we
4631+ know is a pointer to our arguments structure. */
4632+ struct arguments *arguments = state->input;
4633+
4634+ switch (key)
4635+ {
4636+ case 'q': case 's':
4637+ arguments->silent = 1;
4638+ break;
4639+ case 'v':
4640+ arguments->verbose = 1;
4641+ break;
4642+ case 'o':
4643+ arguments->output_file = arg;
4644+ break;
4645+ case 'r':
4646+ arguments->repeat_count = arg ? atoi (arg) : 10;
4647+ break;
4648+ case OPT_ABORT:
4649+ arguments->abort = 1;
4650+ break;
4651+
4652+ case ARGP_KEY_NO_ARGS:
4653+ argp_usage (state);
4654+
4655+ case ARGP_KEY_ARG:
4656+ /* Here we know that @code{state->arg_num == 0}, since we
4657+ force argument parsing to end before any more arguments can
4658+ get here. */
4659+ arguments->arg1 = arg;
4660+
4661+ /* Now we consume all the rest of the arguments.
4662+ @code{state->next} is the index in @code{state->argv} of the
4663+ next argument to be parsed, which is the first @var{string}
4664+ we're interested in, so we can just use
4665+ @code{&state->argv[state->next]} as the value for
4666+ arguments->strings.
4667+
4668+ @emph{In addition}, by setting @code{state->next} to the end
4669+ of the arguments, we can force argp to stop parsing here and
4670+ return. */
4671+ arguments->strings = &state->argv[state->next];
4672+ state->next = state->argc;
4673+
4674+ break;
4675+
4676+ default:
4677+ return ARGP_ERR_UNKNOWN;
4678+ }
4679+ return 0;
4680+}
4681+
4682+/* Our argp parser. */
4683+static struct argp argp = { options, parse_opt, args_doc, doc };
4684+
4685+int main (int argc, char **argv)
4686+{
4687+ int i, j;
4688+ struct arguments arguments;
4689+
4690+ /* Default values. */
4691+ arguments.silent = 0;
4692+ arguments.verbose = 0;
4693+ arguments.output_file = "-";
4694+ arguments.repeat_count = 1;
4695+ arguments.abort = 0;
4696+
4697+ /* Parse our arguments; every option seen by @code{parse_opt} will be
4698+ reflected in @code{arguments}. */
4699+ argp_parse (&argp, argc, argv, 0, 0, &arguments);
4700+
4701+ if (arguments.abort)
4702+ error (10, 0, "ABORTED");
4703+
4704+ for (i = 0; i < arguments.repeat_count; i++)
4705+ {
4706+ printf ("ARG1 = %s\n", arguments.arg1);
4707+ printf ("STRINGS = ");
4708+ for (j = 0; arguments.strings[j]; j++)
4709+ printf (j == 0 ? "%s" : ", %s", arguments.strings[j]);
4710+ printf ("\n");
4711+ printf ("OUTPUT_FILE = %s\nVERBOSE = %s\nSILENT = %s\n",
4712+ arguments.output_file,
4713+ arguments.verbose ? "yes" : "no",
4714+ arguments.silent ? "yes" : "no");
4715+ }
4716+
4717+ exit (0);
4718+}
4719Index: git/test/argp/argp-test.c
4720===================================================================
4721--- /dev/null
4722+++ git/test/argp/argp-test.c
4723@@ -0,0 +1,209 @@
4724+/* Test program for argp argument parser
4725+ Copyright (C) 1997 Free Software Foundation, Inc.
4726+ This file is part of the GNU C Library.
4727+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4728+
4729+ The GNU C Library is free software; you can redistribute it and/or
4730+ modify it under the terms of the GNU Lesser General Public
4731+ License as published by the Free Software Foundation; either
4732+ version 2.1 of the License, or (at your option) any later version.
4733+
4734+ The GNU C Library is distributed in the hope that it will be useful,
4735+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4736+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4737+ Lesser General Public License for more details.
4738+
4739+ You should have received a copy of the GNU Lesser General Public
4740+ License along with the GNU C Library; if not, write to the Free
4741+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4742+ 02111-1307 USA. */
4743+
4744+#ifdef HAVE_CONFIG_H
4745+#include <config.h>
4746+#endif
4747+
4748+#include <stdlib.h>
4749+#include <time.h>
4750+#include <string.h>
4751+#include <argp.h>
4752+
4753+const char *argp_program_version = "argp-test 1.0";
4754+
4755+struct argp_option sub_options[] =
4756+{
4757+ {"subopt1", 's', 0, 0, "Nested option 1"},
4758+ {"subopt2", 'S', 0, 0, "Nested option 2"},
4759+
4760+ { 0, 0, 0, 0, "Some more nested options:", 10},
4761+ {"subopt3", 'p', 0, 0, "Nested option 3"},
4762+
4763+ {"subopt4", 'q', 0, 0, "Nested option 4", 1},
4764+
4765+ {0}
4766+};
4767+
4768+static const char sub_args_doc[] = "STRING...\n-";
4769+static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser.";
4770+
4771+static error_t
4772+sub_parse_opt (int key, char *arg, struct argp_state *state)
4773+{
4774+ switch (key)
4775+ {
4776+ case ARGP_KEY_NO_ARGS:
4777+ printf ("NO SUB ARGS\n");
4778+ break;
4779+ case ARGP_KEY_ARG:
4780+ printf ("SUB ARG: %s\n", arg);
4781+ break;
4782+
4783+ case 's' : case 'S': case 'p': case 'q':
4784+ printf ("SUB KEY %c\n", key);
4785+ break;
4786+
4787+ default:
4788+ return ARGP_ERR_UNKNOWN;
4789+ }
4790+ return 0;
4791+}
4792+
4793+static char *
4794+sub_help_filter (int key, const char *text, void *input)
4795+{
4796+ if (key == ARGP_KEY_HELP_EXTRA)
4797+ return strdup ("This is some extra text from the sub parser (note that it \
4798+is preceded by a blank line).");
4799+ else
4800+ return (char *)text;
4801+}
4802+
4803+static struct argp sub_argp = {
4804+ sub_options, sub_parse_opt, sub_args_doc, sub_doc, 0, sub_help_filter
4805+};
4806+
4807+/* Structure used to communicate with the parsing functions. */
4808+struct params
4809+{
4810+ unsigned foonly; /* Value parsed for foonly. */
4811+ unsigned foonly_default; /* Default value for it. */
4812+};
4813+
4814+#define OPT_PGRP 1
4815+#define OPT_SESS 2
4816+
4817+struct argp_option options[] =
4818+{
4819+ {"pid", 'p', "PID", 0, "List the process PID"},
4820+ {"pgrp", OPT_PGRP,"PGRP",0, "List processes in the process group PGRP"},
4821+ {"no-parent", 'P', 0, 0, "Include processes without parents"},
4822+ {0, 'x', 0, OPTION_ALIAS},
4823+ {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
4824+ " if there's some reason ps can't"
4825+ " print a field for any process, it's"
4826+ " removed from the output entirely)" },
4827+ {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
4828+ {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
4829+ {"session", OPT_SESS,"SID", OPTION_ARG_OPTIONAL,
4830+ "Add the processes from the session"
4831+ " SID (which defaults to the sid of"
4832+ " the current process)" },
4833+
4834+ {0,0,0,0, "Here are some more options:"},
4835+ {"foonly", 'f', "ZOT", OPTION_ARG_OPTIONAL, "Glork a foonly"},
4836+ {"zaza", 'z', 0, 0, "Snit a zar"},
4837+
4838+ {0}
4839+};
4840+
4841+static const char args_doc[] = "STRING";
4842+static const char doc[] = "Test program for argp."
4843+ "\vThis doc string comes after the options."
4844+ "\nHey! Some manual formatting!"
4845+ "\nThe current time is: %s";
4846+
4847+static void
4848+popt (int key, char *arg)
4849+{
4850+ char buf[10];
4851+ if (isprint (key))
4852+ sprintf (buf, "%c", key);
4853+ else
4854+ sprintf (buf, "%d", key);
4855+ if (arg)
4856+ printf ("KEY %s: %s\n", buf, arg);
4857+ else
4858+ printf ("KEY %s\n", buf);
4859+}
4860+
4861+static error_t
4862+parse_opt (int key, char *arg, struct argp_state *state)
4863+{
4864+ struct params *params = state->input;
4865+
4866+ switch (key)
4867+ {
4868+ case ARGP_KEY_NO_ARGS:
4869+ printf ("NO ARGS\n");
4870+ break;
4871+
4872+ case ARGP_KEY_ARG:
4873+ if (state->arg_num > 0)
4874+ return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */
4875+ printf ("ARG: %s\n", arg);
4876+ break;
4877+
4878+ case 'f':
4879+ if (arg)
4880+ params->foonly = atoi (arg);
4881+ else
4882+ params->foonly = params->foonly_default;
4883+ popt (key, arg);
4884+ break;
4885+
4886+ case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q':
4887+ case 'r': case OPT_SESS: case 'z':
4888+ popt (key, arg);
4889+ break;
4890+
4891+ default:
4892+ return ARGP_ERR_UNKNOWN;
4893+ }
4894+ return 0;
4895+}
4896+
4897+static char *
4898+help_filter (int key, const char *text, void *input)
4899+{
4900+ char *new_text;
4901+ struct params *params = input;
4902+
4903+ if (key == ARGP_KEY_HELP_POST_DOC && text)
4904+ {
4905+ time_t now = time (0);
4906+ asprintf (&new_text, text, ctime (&now));
4907+ }
4908+ else if (key == 'f')
4909+ /* Show the default for the --foonly option. */
4910+ asprintf (&new_text, "%s (ZOT defaults to %x)",
4911+ text, params->foonly_default);
4912+ else
4913+ new_text = (char *)text;
4914+
4915+ return new_text;
4916+}
4917+
4918+static struct argp_child argp_children[] = { { &sub_argp }, { 0 } };
4919+static struct argp argp = {
4920+ options, parse_opt, args_doc, doc, argp_children, help_filter
4921+};
4922+
4923+int
4924+main (int argc, char **argv)
4925+{
4926+ struct params params;
4927+ params.foonly = 0;
4928+ params.foonly_default = random ();
4929+ argp_parse (&argp, argc, argv, 0, 0, &params);
4930+ printf ("After parsing: foonly = %x\n", params.foonly);
4931+ return 0;
4932+}
4933Index: git/test/argp/bug-argp1.c
4934===================================================================
4935--- /dev/null
4936+++ git/test/argp/bug-argp1.c
4937@@ -0,0 +1,26 @@
4938+#include <argp.h>
4939+
4940+
4941+static const struct argp_option test_options[] =
4942+{
4943+ { NULL, 'a', NULL, OPTION_DOC, NULL },
4944+ { NULL, 'b', NULL, OPTION_DOC, NULL },
4945+ { NULL, 0, NULL, 0, NULL }
4946+};
4947+
4948+static struct argp test_argp =
4949+{
4950+ test_options
4951+};
4952+
4953+
4954+static int
4955+do_test (int argc, char *argv[])
4956+{
4957+ int i;
4958+ argp_parse (&test_argp, argc, argv, 0, &i, NULL);
4959+ return 0;
4960+}
4961+
4962+#define TEST_FUNCTION do_test (argc, argv)
4963+#include "../test-skeleton.c"
4964Index: git/test/argp/tst-argp1.c
4965===================================================================
4966--- /dev/null
4967+++ git/test/argp/tst-argp1.c
4968@@ -0,0 +1,118 @@
4969+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4970+ This file is part of the GNU C Library.
4971+ Contributed by Ulrich Drepper <drepper at redhat.com>, 2002.
4972+
4973+ The GNU C Library is free software; you can redistribute it and/or
4974+ modify it under the terms of the GNU Lesser General Public
4975+ License as published by the Free Software Foundation; either
4976+ version 2.1 of the License, or (at your option) any later version.
4977+
4978+ The GNU C Library is distributed in the hope that it will be useful,
4979+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4980+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4981+ Lesser General Public License for more details.
4982+
4983+ You should have received a copy of the GNU Lesser General Public
4984+ License along with the GNU C Library; if not, write to the Free
4985+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4986+ 02111-1307 USA. */
4987+
4988+#include <argp.h>
4989+
4990+
4991+
4992+
4993+#define OPT_TO_THREAD 300
4994+#define OPT_TO_PROCESS 301
4995+#define OPT_SYNC_SIGNAL 302
4996+#define OPT_SYNC_JOIN 303
4997+#define OPT_TOPLEVEL 304
4998+
4999+
5000+static const struct argp_option test_options[] =
5001+ {
5002+ { NULL, 0, NULL, 0, "\
5003+This is a test for threads so we allow ther user to selection the number of \
5004+threads which are used at any one time. Independently the total number of \
5005+rounds can be selected. This is the total number of threads which will have \
5006+run when the process terminates:" },
5007+ { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
5008+ { "starts", 's', "NUMBER", 0, "Total number of working threads" },
5009+ { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
5010+ "Number of toplevel threads which start the other threads; this \
5011+implies --sync-join" },
5012+
5013+ { NULL, 0, NULL, 0, "\
5014+Each thread can do one of two things: sleep or do work. The latter is 100% \
5015+CPU bound. The work load is the probability a thread does work. All values \
5016+from zero to 100 (inclusive) are valid. How often each thread repeats this \
5017+can be determined by the number of rounds. The work cost determines how long \
5018+each work session (not sleeping) takes. If it is zero a thread would \
5019+effectively nothing. By setting the number of rounds to zero the thread \
5020+does no work at all and pure thread creation times can be measured." },
5021+ { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
5022+ { "workcost", 'c', "NUMBER", 0,
5023+ "Factor in the cost of each round of working" },
5024+ { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
5025+
5026+ { NULL, 0, NULL, 0, "\
5027+There are a number of different methods how thread creation can be \
5028+synchronized. Synchronization is necessary since the number of concurrently \
5029+running threads is limited." },
5030+ { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
5031+ "Synchronize using a signal (default)" },
5032+ { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
5033+
5034+ { NULL, 0, NULL, 0, "\
5035+One parameter for each threads execution is the size of the stack. If this \
5036+parameter is not used the system's default stack size is used. If many \
5037+threads are used the stack size should be chosen quite small." },
5038+ { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
5039+ { "guardsize", 'g', "BYTES", 0,
5040+ "Size of stack guard area; must fit into the stack" },
5041+
5042+ { NULL, 0, NULL, 0, "Signal options:" },
5043+ { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
5044+ { "to-process", OPT_TO_PROCESS, NULL, 0,
5045+ "Send signal to process (default)" },
5046+
5047+ { NULL, 0, NULL, 0, "Administrative options:" },
5048+ { "progress", 'p', NULL, 0, "Show signs of progress" },
5049+ { "timing", 'T', NULL, 0,
5050+ "Measure time from startup to the last thread finishing" },
5051+ { NULL, 0, NULL, 0, NULL }
5052+ };
5053+
5054+/* Prototype for option handler. */
5055+static error_t parse_opt (int key, char *arg, struct argp_state *state);
5056+
5057+/* Data structure to communicate with argp functions. */
5058+static struct argp argp =
5059+{
5060+ test_options, parse_opt
5061+};
5062+
5063+
5064+static int
5065+do_test (void)
5066+{
5067+ int argc = 2;
5068+ char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL };
5069+ int remaining;
5070+
5071+ /* Parse and process arguments. */
5072+ argp_parse (&argp, argc, argv, 0, &remaining, NULL);
5073+
5074+ return 0;
5075+}
5076+
5077+
5078+/* Handle program arguments. */
5079+static error_t
5080+parse_opt (int key, char *arg, struct argp_state *state)
5081+{
5082+ return ARGP_ERR_UNKNOWN;
5083+}
5084+
5085+#define TEST_FUNCTION do_test ()
5086+#include "../test-skeleton.c"
5087Index: git/test/argp/tst-argp2.c
5088===================================================================
5089--- /dev/null
5090+++ git/test/argp/tst-argp2.c
5091@@ -0,0 +1,101 @@
5092+/* Copyright (C) 2007 Free Software Foundation, Inc.
5093+ This file is part of the GNU C Library.
5094+ Contributed by Jakub Jelinek <jakub at redhat.com>, 2007.
5095+
5096+ The GNU C Library is free software; you can redistribute it and/or
5097+ modify it under the terms of the GNU Lesser General Public
5098+ License as published by the Free Software Foundation; either
5099+ version 2.1 of the License, or (at your option) any later version.
5100+
5101+ The GNU C Library is distributed in the hope that it will be useful,
5102+ but WITHOUT ANY WARRANTY; without even the implied warranty of
5103+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5104+ Lesser General Public License for more details.
5105+
5106+ You should have received a copy of the GNU Lesser General Public
5107+ License along with the GNU C Library; if not, write to the Free
5108+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
5109+ 02111-1307 USA. */
5110+
5111+#include <argp.h>
5112+
5113+static const struct argp_option opt1[] =
5114+ {
5115+ { "opt1", '1', "NUMBER", 0, "Option 1" },
5116+ { NULL, 0, NULL, 0, NULL }
5117+ };
5118+
5119+static const struct argp_option opt2[] =
5120+ {
5121+ { "opt2", '2', "NUMBER", 0, "Option 2" },
5122+ { NULL, 0, NULL, 0, NULL }
5123+ };
5124+
5125+static const struct argp_option opt3[] =
5126+ {
5127+ { "opt3", '3', "NUMBER", 0, "Option 3" },
5128+ { NULL, 0, NULL, 0, NULL }
5129+ };
5130+
5131+static const struct argp_option opt4[] =
5132+ {
5133+ { "opt4", '4', "NUMBER", 0, "Option 4" },
5134+ { NULL, 0, NULL, 0, NULL }
5135+ };
5136+
5137+static const struct argp_option opt5[] =
5138+ {
5139+ { "opt5", '5', "NUMBER", 0, "Option 5" },
5140+ { NULL, 0, NULL, 0, NULL }
5141+ };
5142+
5143+static struct argp argp5 =
5144+ {
5145+ opt5, NULL, "args doc5", "doc5", NULL, NULL, NULL
5146+ };
5147+
5148+static struct argp argp4 =
5149+ {
5150+ opt4, NULL, "args doc4", "doc4", NULL, NULL, NULL
5151+ };
5152+
5153+static struct argp argp3 =
5154+ {
5155+ opt3, NULL, "args doc3", "doc3", NULL, NULL, NULL
5156+ };
5157+
5158+static struct argp_child children2[] =
5159+ {
5160+ { &argp4, 0, "child3", 3 },
5161+ { &argp5, 0, "child4", 4 },
5162+ { NULL, 0, NULL, 0 }
5163+ };
5164+
5165+static struct argp argp2 =
5166+ {
5167+ opt2, NULL, "args doc2", "doc2", children2, NULL, NULL
5168+ };
5169+
5170+static struct argp_child children1[] =
5171+ {
5172+ { &argp2, 0, "child1", 1 },
5173+ { &argp3, 0, "child2", 2 },
5174+ { NULL, 0, NULL, 0 }
5175+ };
5176+
5177+static struct argp argp1 =
5178+ {
5179+ opt1, NULL, "args doc1", "doc1", children1, NULL, NULL
5180+ };
5181+
5182+
5183+static int
5184+do_test (void)
5185+{
5186+ argp_help (&argp1, stdout, ARGP_HELP_LONG, (char *) "tst-argp2");
5187+ return 0;
5188+}
5189+
5190+
5191+#define TEST_FUNCTION do_test ()
5192+#include "../test-skeleton.c"
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/compile-arm-fork-with-O2.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/compile-arm-fork-with-O2.patch
deleted file mode 100644
index 15ee0ca156..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/compile-arm-fork-with-O2.patch
+++ /dev/null
@@ -1,21 +0,0 @@
1When compiling in thumb mode for arm with -Os gcc gives up since it can not find registers
2to spill. So we use -O2 option for compiling fork.c It may be addressable in gcc.
3
4Signed-off-by: Khem Raj <raj.khem@gmail.com>
5
6Upstream-Status: Pending
7
8diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch b/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
9index 329d8a9..41e3646 100644
10--- a/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
11+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
12@@ -30,3 +30,9 @@ CFLAGS-OMIT-libc-lowlevellock.c = -DNOT_IN_libc -DIS_IN_libpthread
13 # This macro should be alternatively implemented in THUMB
14 # assembly.
15 ASFLAGS-vfork.S = -marm
16+
17+# For arm fork.c does not compile with -Os when in compiling
18+# in thumb1 mode
19+ifeq ($(COMPILE_IN_THUMB_MODE),y)
20+CFLAGS-fork.c = -O2
21+endif
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/define-MSG_CMSG_CLOEXEC.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/define-MSG_CMSG_CLOEXEC.patch
deleted file mode 100644
index 4e900f3931..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/define-MSG_CMSG_CLOEXEC.patch
+++ /dev/null
@@ -1,25 +0,0 @@
1Add definition of MSG_WAITFORONE and MSG_CMSG_CLOEXEC
2
3Upstream-Status: Pending
4
5Index: git/libc/sysdeps/linux/common/bits/socket.h
6===================================================================
7--- git.orig/libc/sysdeps/linux/common/bits/socket.h 2012-01-26 23:23:21.537456132 -0800
8+++ git/libc/sysdeps/linux/common/bits/socket.h 2012-01-26 23:25:10.125461388 -0800
9@@ -235,8 +235,15 @@
10 #define MSG_ERRQUEUE MSG_ERRQUEUE
11 MSG_NOSIGNAL = 0x4000, /* Do not generate SIGPIPE. */
12 #define MSG_NOSIGNAL MSG_NOSIGNAL
13- MSG_MORE = 0x8000 /* Sender will send more. */
14+ MSG_MORE = 0x8000, /* Sender will send more. */
15 #define MSG_MORE MSG_MORE
16+ MSG_WAITFORONE = 0x10000, /* Wait for at least one packet to return.*/
17+#define MSG_WAITFORONE MSG_WAITFORONE
18+
19+ MSG_CMSG_CLOEXEC = 0x40000000 /* Set close_on_exit for file
20+ descriptor received through
21+ SCM_RIGHTS. */
22+#define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC
23 };
24
25
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/dup3.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/dup3.patch
deleted file mode 100644
index 481f23b2c4..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/dup3.patch
+++ /dev/null
@@ -1,37 +0,0 @@
1Implement dup3()
2
3Upstream-Status: Pending
4
5Index: git/libc/sysdeps/linux/common/dup3.c
6===================================================================
7--- /dev/null 1970-01-01 00:00:00.000000000 +0000
8+++ git/libc/sysdeps/linux/common/dup3.c 2012-01-27 07:40:52.802900849 -0800
9@@ -0,0 +1,15 @@
10+/* vi: set sw=4 ts=4: */
11+/*
12+ * dup3() for uClibc
13+ *
14+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
15+ *
16+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
17+ */
18+
19+#include <sys/syscall.h>
20+#include <unistd.h>
21+
22+
23+_syscall3(int, dup3, int, oldfd, int, newfd, int, flags)
24+libc_hidden_def(dup3)
25Index: git/include/unistd.h
26===================================================================
27--- git.orig/include/unistd.h 2012-01-27 01:19:17.521792781 -0800
28+++ git/include/unistd.h 2012-01-27 07:40:03.106898447 -0800
29@@ -512,6 +512,8 @@
30 /* Duplicate FD to FD2, closing FD2 and making it open on the same file. */
31 extern int dup2 (int __fd, int __fd2) __THROW;
32 libc_hidden_proto(dup2)
33+extern int dup3 (int __fd, int __fd2, int __flags) __THROW;
34+libc_hidden_proto(dup3)
35
36 /* NULL-terminated array of "NAME=VALUE" environment variables. */
37 extern char **__environ;
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/ldso_use_arm_dl_linux_resolve_in_thumb_mode.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/ldso_use_arm_dl_linux_resolve_in_thumb_mode.patch
deleted file mode 100644
index d44accadbb..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/ldso_use_arm_dl_linux_resolve_in_thumb_mode.patch
+++ /dev/null
@@ -1,27 +0,0 @@
1resolver code should always be in arm mode
2
3Signed-off-by: Khem Raj <raj.khem@gmail.com>
4
5Upstream-Status: Pending
6
7Index: uClibc/ldso/ldso/arm/resolve.S
8===================================================================
9--- uClibc.orig/ldso/ldso/arm/resolve.S 2009-03-20 12:03:32.000000000 -0700
10+++ uClibc/ldso/ldso/arm/resolve.S 2009-03-20 12:04:23.000000000 -0700
11@@ -97,7 +97,6 @@
12
13 .text
14 .align 4 @ 16 byte boundary and there are 32 bytes below (arm case)
15- #if !defined(__thumb__) || defined(__thumb2__)
16 .arm
17 .globl _dl_linux_resolve
18 .type _dl_linux_resolve,%function
19@@ -129,7 +128,7 @@
20 #else
21 mov pc,ip
22 #endif
23-#else
24+#if 0
25 @ In the thumb case _dl_linux_resolver is thumb. If a bl is used
26 @ from arm code the linker will insert a stub call which, with
27 @ binutils 2.16, is not PIC. Since this code is accessed by an
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/libc_symbols_include_bits_uclibc_config.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/libc_symbols_include_bits_uclibc_config.patch
deleted file mode 100644
index 2995a6b930..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/libc_symbols_include_bits_uclibc_config.patch
+++ /dev/null
@@ -1,23 +0,0 @@
1Avoid build warnings
2
3Upstream-Status: Pending
4
5Index: git/include/libc-symbols.h
6===================================================================
7--- git.orig/include/libc-symbols.h 2011-07-05 17:04:41.171219323 -0700
8+++ git/include/libc-symbols.h 2011-07-05 22:50:36.851661478 -0700
9@@ -48,10 +48,12 @@
10
11 */
12
13-#include <bits/uClibc_arch_features.h>
14-
15 /* Enable declarations of GNU extensions, since we are compiling them. */
16 #define _GNU_SOURCE 1
17+#define __need_uClibc_config_h
18+#include <bits/uClibc_config.h>
19+#undef __need_uClibc_config_h
20+#include <bits/uClibc_arch_features.h>
21
22 /* Prepare for the case that `__builtin_expect' is not available. */
23 #if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/mount.h-update.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/mount.h-update.patch
deleted file mode 100644
index 41a410c84c..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/mount.h-update.patch
+++ /dev/null
@@ -1,83 +0,0 @@
1Signed-off-by: Khem Raj <raj.khem@gmail.com>
2Upstream-Status: Pending
3
4sync mount.h with glibc
5
6Index: git/include/sys/mount.h
7===================================================================
8--- git.orig/include/sys/mount.h 2012-08-23 21:26:51.038825295 -0700
9+++ git/include/sys/mount.h 2012-08-23 21:27:09.914826014 -0700
10@@ -1,5 +1,5 @@
11 /* Header file for mounting/unmount Linux filesystems.
12- Copyright (C) 1996,1997,1998,1999,2000,2004 Free Software Foundation, Inc.
13+ Copyright (C) 1996-2000, 2004, 2010 Free Software Foundation, Inc.
14 This file is part of the GNU C Library.
15
16 The GNU C Library is free software; you can redistribute it and/or
17@@ -47,23 +47,46 @@
18 #define MS_REMOUNT MS_REMOUNT
19 MS_MANDLOCK = 64, /* Allow mandatory locks on an FS. */
20 #define MS_MANDLOCK MS_MANDLOCK
21- S_WRITE = 128, /* Write on file/directory/symlink. */
22-#define S_WRITE S_WRITE
23- S_APPEND = 256, /* Append-only file. */
24-#define S_APPEND S_APPEND
25- S_IMMUTABLE = 512, /* Immutable file. */
26-#define S_IMMUTABLE S_IMMUTABLE
27+ MS_DIRSYNC = 128, /* Directory modifications are synchronous. */
28+#define MS_DIRSYNC MS_DIRSYNC
29 MS_NOATIME = 1024, /* Do not update access times. */
30 #define MS_NOATIME MS_NOATIME
31 MS_NODIRATIME = 2048, /* Do not update directory access times. */
32 #define MS_NODIRATIME MS_NODIRATIME
33 MS_BIND = 4096, /* Bind directory at different place. */
34 #define MS_BIND MS_BIND
35+ MS_MOVE = 8192,
36+#define MS_MOVE MS_MOVE
37+ MS_REC = 16384,
38+#define MS_REC MS_REC
39+ MS_SILENT = 32768,
40+#define MS_SILENT MS_SILENT
41+ MS_POSIXACL = 1 << 16, /* VFS does not apply the umask. */
42+#define MS_POSIXACL MS_POSIXACL
43+ MS_UNBINDABLE = 1 << 17, /* Change to unbindable. */
44+#define MS_UNBINDABLE MS_UNBINDABLE
45+ MS_PRIVATE = 1 << 18, /* Change to private. */
46+#define MS_PRIVATE MS_PRIVATE
47+ MS_SLAVE = 1 << 19, /* Change to slave. */
48+#define MS_SLAVE MS_SLAVE
49+ MS_SHARED = 1 << 20, /* Change to shared. */
50+#define MS_SHARED MS_SHARED
51+ MS_RELATIME = 1 << 21, /* Update atime relative to mtime/ctime. */
52+#define MS_RELATIME MS_RELATIME
53+ MS_KERNMOUNT = 1 << 22, /* This is a kern_mount call. */
54+#define MS_KERNMOUNT MS_KERNMOUNT
55+ MS_I_VERSION = 1 << 23, /* Update inode I_version field. */
56+#define MS_I_VERSION MS_I_VERSION
57+ MS_STRICTATIME = 1 << 24, /* Always perform atime updates. */
58+#define MS_STRICTATIME MS_STRICTATIME
59+ MS_ACTIVE = 1 << 30,
60+#define MS_ACTIVE MS_ACTIVE
61+ MS_NOUSER = 1 << 31
62+#define MS_NOUSER MS_NOUSER
63 };
64
65 /* Flags that can be altered by MS_REMOUNT */
66-#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME \
67- |MS_NODIRATIME)
68+#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION)
69
70
71 /* Magic mount flag number. Has to be or-ed to the flag values. */
72@@ -100,8 +123,10 @@
73 #define MNT_FORCE MNT_FORCE
74 MNT_DETACH = 2, /* Just detach from the tree. */
75 #define MNT_DETACH MNT_DETACH
76- MNT_EXPIRE = 4 /* Mark for expiry. */
77+ MNT_EXPIRE = 4, /* Mark for expiry. */
78 #define MNT_EXPIRE MNT_EXPIRE
79+ UMOUNT_NOFOLLOW = 8 /* Don't follow symlink on umount. */
80+#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
81 };
82
83
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/orign_path.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/orign_path.patch
deleted file mode 100644
index c9c15a34b7..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/orign_path.patch
+++ /dev/null
@@ -1,185 +0,0 @@
1Patch is backported from
2http://lists.busybox.net/pipermail/uclibc/2011-March/045003.html
3
4Upstream-Status: Pending
5
6Index: git/ldso/ldso/dl-elf.c
7===================================================================
8--- git.orig/ldso/ldso/dl-elf.c 2012-01-23 19:18:58.000000000 -0800
9+++ git/ldso/ldso/dl-elf.c 2012-01-23 21:52:06.144646590 -0800
10@@ -133,53 +133,60 @@
11 * in uClibc/ldso/util/ldd.c */
12 static struct elf_resolve *
13 search_for_named_library(const char *name, unsigned rflags, const char *path_list,
14- struct dyn_elf **rpnt)
15+ struct dyn_elf **rpnt, const char* origin)
16 {
17- char *path, *path_n, *mylibname;
18+ char *mylibname;
19+ const char *p, *pn;
20 struct elf_resolve *tpnt;
21- int done;
22+ int plen;
23
24 if (path_list==NULL)
25 return NULL;
26
27- /* We need a writable copy of this string, but we don't
28- * need this allocated permanently since we don't want
29- * to leak memory, so use alloca to put path on the stack */
30- done = _dl_strlen(path_list);
31- path = alloca(done + 1);
32-
33 /* another bit of local storage */
34 mylibname = alloca(2050);
35
36- _dl_memcpy(path, path_list, done+1);
37-
38 /* Unlike ldd.c, don't bother to eliminate double //s */
39
40 /* Replace colons with zeros in path_list */
41 /* : at the beginning or end of path maps to CWD */
42 /* :: anywhere maps CWD */
43 /* "" maps to CWD */
44- done = 0;
45- path_n = path;
46- do {
47- if (*path == 0) {
48- *path = ':';
49- done = 1;
50+ for (p = path_list; p != NULL; p = pn) {
51+ pn = _dl_strchr(p + 1, ':');
52+ if (pn != NULL) {
53+ plen = pn - p;
54+ pn++;
55+ } else
56+ plen = _dl_strlen(p);
57+
58+ if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) {
59+ int olen;
60+ if (rflags && plen != 7)
61+ continue;
62+ if (origin == NULL)
63+ continue;
64+ for (olen = _dl_strlen(origin) - 1; olen >= 0 && origin[olen] != '/'; olen--)
65+ ;
66+ if (olen <= 0)
67+ continue;
68+ _dl_memcpy(&mylibname[0], origin, olen);
69+ _dl_memcpy(&mylibname[olen], p + 7, plen - 7);
70+ mylibname[olen + plen - 7] = 0;
71+ } else if (plen != 0) {
72+ _dl_memcpy(mylibname, p, plen);
73+ mylibname[plen] = 0;
74+ } else {
75+ _dl_strcpy(mylibname, ".");
76 }
77- if (*path == ':') {
78- *path = 0;
79- if (*path_n)
80- _dl_strcpy(mylibname, path_n);
81- else
82- _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
83- _dl_strcat(mylibname, "/");
84- _dl_strcat(mylibname, name);
85- if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
86- return tpnt;
87- path_n = path+1;
88- }
89- path++;
90- } while (!done);
91+ _dl_strcat(mylibname, "/");
92+ _dl_strcat(mylibname, name);
93+
94+ tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname);
95+ if (tpnt != NULL)
96+ return tpnt;
97+ }
98+
99 return NULL;
100 }
101
102@@ -231,8 +238,10 @@
103 if (pnt) {
104 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
105 _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
106- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
107+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt,
108+ tpnt->libname)) != NULL)
109 return tpnt1;
110+
111 }
112 #endif
113
114@@ -240,7 +249,7 @@
115 /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
116 if (_dl_library_path) {
117 _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
118- if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt)) != NULL)
119+ if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt, NULL)) != NULL)
120 {
121 return tpnt1;
122 }
123@@ -254,7 +263,7 @@
124 if (pnt) {
125 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
126 _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
127- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
128+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, NULL)) != NULL)
129 return tpnt1;
130 }
131 #endif
132@@ -288,7 +297,7 @@
133 /* Look for libraries wherever the shared library loader
134 * was installed */
135 _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
136- tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt);
137+ tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt, NULL);
138 if (tpnt1 != NULL)
139 return tpnt1;
140 #endif
141@@ -301,7 +310,7 @@
142 #ifndef __LDSO_CACHE_SUPPORT__
143 ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
144 #endif
145- , rpnt);
146+ , rpnt, NULL);
147 if (tpnt1 != NULL)
148 return tpnt1;
149
150Index: git/ldso/ldso/ldso.c
151===================================================================
152--- git.orig/ldso/ldso/ldso.c 2012-01-23 19:18:58.000000000 -0800
153+++ git/ldso/ldso/ldso.c 2012-01-23 21:34:11.152594621 -0800
154@@ -407,6 +407,20 @@
155 return p - list;
156 }
157
158+static void _dl_setup_progname(const char *argv0)
159+{
160+ char image[PATH_MAX];
161+ ssize_t s;
162+
163+ s = _dl_readlink("/proc/self/exe", image, sizeof(image));
164+ if (s > 0 && image[0] == '/') {
165+ image[s] = 0;
166+ _dl_progname = _dl_strdup(image);
167+ } else if (argv0) {
168+ _dl_progname = argv0;
169+ }
170+}
171+
172 void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
173 ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
174 DL_GET_READY_TO_RUN_EXTRA_PARMS)
175@@ -458,9 +472,7 @@
176 * been fixed up by now. Still no function calls outside of this
177 * library, since the dynamic resolver is not yet ready.
178 */
179- if (argv[0]) {
180- _dl_progname = argv[0];
181- }
182+ _dl_setup_progname(argv[0]);
183
184 #ifndef __LDSO_STANDALONE_SUPPORT__
185 if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch
deleted file mode 100644
index b55fbbd6e0..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch
+++ /dev/null
@@ -1,407 +0,0 @@
1Delivered-To: raj.khem@gmail.com
2Received: by 10.152.129.134 with SMTP id nw6csp47712lab;
3 Tue, 17 Apr 2012 00:30:48 -0700 (PDT)
4Received: by 10.68.216.167 with SMTP id or7mr34112133pbc.140.1334647840512;
5 Tue, 17 Apr 2012 00:30:40 -0700 (PDT)
6Return-Path: <uclibc-bounces@uclibc.org>
7Received: from hemlock.osuosl.org (hemlock.osuosl.org. [140.211.166.133])
8 by mx.google.com with ESMTP id gr10si13305623pbc.339.2012.04.17.00.30.39;
9 Tue, 17 Apr 2012 00:30:40 -0700 (PDT)
10Received-SPF: neutral (google.com: 140.211.166.133 is neither permitted nor denied by best guess record for domain of uclibc-bounces@uclibc.org) client-ip=140.211.166.133;
11Authentication-Results: mx.google.com; spf=neutral (google.com: 140.211.166.133 is neither permitted nor denied by best guess record for domain of uclibc-bounces@uclibc.org) smtp.mail=uclibc-bounces@uclibc.org; dkim=neutral (body hash did not verify) header.i=@gmail.com
12Received: from localhost (localhost [127.0.0.1])
13 by hemlock.osuosl.org (Postfix) with ESMTP id 7C494A0277;
14 Tue, 17 Apr 2012 07:30:39 +0000 (UTC)
15X-Virus-Scanned: amavisd-new at osuosl.org
16Received: from hemlock.osuosl.org ([127.0.0.1])
17 by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
18 with ESMTP id ZsSp5xE48GwC; Tue, 17 Apr 2012 07:30:34 +0000 (UTC)
19Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34])
20 by hemlock.osuosl.org (Postfix) with ESMTP id 1C4F5A0274;
21 Tue, 17 Apr 2012 07:30:33 +0000 (UTC)
22X-Original-To: uclibc@lists.busybox.net
23Delivered-To: uclibc@osuosl.org
24Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137])
25 by ash.osuosl.org (Postfix) with ESMTP id 17FDE8F75B
26 for <uclibc@lists.busybox.net>; Tue, 17 Apr 2012 07:30:32 +0000 (UTC)
27Received: from localhost (localhost [127.0.0.1])
28 by fraxinus.osuosl.org (Postfix) with ESMTP id 07B491016A1
29 for <uclibc@lists.busybox.net>; Tue, 17 Apr 2012 07:30:32 +0000 (UTC)
30X-Virus-Scanned: amavisd-new at osuosl.org
31Received: from fraxinus.osuosl.org ([127.0.0.1])
32 by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
33 with ESMTP id XKP7jhcUijp4 for <uclibc@lists.busybox.net>;
34 Tue, 17 Apr 2012 07:30:27 +0000 (UTC)
35X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6
36Received: from mail-we0-f174.google.com (mail-we0-f174.google.com
37 [74.125.82.174])
38 by fraxinus.osuosl.org (Postfix) with ESMTPS id 2CC0B100190
39 for <uclibc@uclibc.org>; Tue, 17 Apr 2012 07:30:26 +0000 (UTC)
40Received: by wejx9 with SMTP id x9so5218587wej.33
41 for <uclibc@uclibc.org>; Tue, 17 Apr 2012 00:30:25 -0700 (PDT)
42DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
43 h=from:to:cc:subject:date:message-id:x-mailer;
44 bh=vadTQ1GL81XLDadHLtwCrcdL0YvVNNbIuISfTaQphgg=;
45 b=KkyW95PC1TUTmwGt+iBJ8p0FfGtTPAsTlXmul/1iH2p21itEpWkU+WcVd2jBH+jc6L
46 gzf4d6K1pmmfscdbPY3OkpFfvO/v/E4KYN7JmeI+fX1NY+gLBSHhExAVhM1Opue9z09V
47 54MrEMtlIA9Wo/5QPd1+W7o9gXHYEnMkoqYYZLmfPlG3+pCXZ6RP36fOZnSV44BQgOFz
48 KBqn7XLo6nxgP5X/+JuEe4stvCrI9/66nX30u/Sh77a9poj5pp8hQZmtIpbbm3xRKGnM
49 Fi72jNCq/0nHh3M7eMqn+rvwi1JQjk/90zWNv8v5ShAKqSJVrfqLVN72KjTJtXfLOqbL
50 e2qA==
51Received: by 10.216.133.72 with SMTP id p50mr8903959wei.78.1334647825412;
52 Tue, 17 Apr 2012 00:30:25 -0700 (PDT)
53Received: from s42.loc (85-127-86-115.dynamic.xdsl-line.inode.at.
54 [85.127.86.115])
55 by mx.google.com with ESMTPS id n20sm40466274wiw.5.2012.04.17.00.30.23
56 (version=TLSv1/SSLv3 cipher=OTHER);
57 Tue, 17 Apr 2012 00:30:24 -0700 (PDT)
58Received: from cow by s42.loc with local (Exim 4.77)
59 (envelope-from <rep.dot.nop@gmail.com>)
60 id 1SK2rm-0008Pl-V3; Tue, 17 Apr 2012 09:30:23 +0200
61From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
62To: uclibc@uclibc.org
63Subject: [PATCH,CFT] libc: add posix_fallocate()
64Date: Tue, 17 Apr 2012 09:30:15 +0200
65Message-Id: <1334647815-32315-1-git-send-email-rep.dot.nop@gmail.com>
66X-Mailer: git-send-email 1.7.9.1
67X-BeenThere: uclibc@uclibc.org
68X-Mailman-Version: 2.1.14
69Precedence: list
70List-Id: "Discussion and development of uClibc \(the embedded C library\)"
71 <uclibc.uclibc.org>
72List-Unsubscribe: <http://lists.busybox.net/mailman/options/uclibc>,
73 <mailto:uclibc-request@uclibc.org?subject=unsubscribe>
74List-Archive: <http://lists.busybox.net/pipermail/uclibc>
75List-Post: <mailto:uclibc@uclibc.org>
76List-Help: <mailto:uclibc-request@uclibc.org?subject=help>
77List-Subscribe: <http://lists.busybox.net/mailman/listinfo/uclibc>,
78 <mailto:uclibc-request@uclibc.org?subject=subscribe>
79MIME-Version: 1.0
80Content-Type: text/plain; charset="us-ascii"
81Content-Transfer-Encoding: 7bit
82Errors-To: uclibc-bounces@uclibc.org
83Sender: uclibc-bounces@uclibc.org
84
85Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
86Upstream-Status: Pending
87---
88 include/fcntl.h | 4 +-
89 libc/sysdeps/linux/common/Makefile.in | 3 +-
90 libc/sysdeps/linux/common/bits/kernel-features.h | 8 ++
91 libc/sysdeps/linux/common/posix_fallocate.c | 43 ++++++++
92 libc/sysdeps/linux/common/posix_fallocate64.c | 39 +++++++
93 libc/sysdeps/linux/common/stubs.c | 4 +
94 test/.gitignore | 1 +
95 test/unistd/Makefile.in | 3 +
96 test/unistd/tst-posix_fallocate.c | 121 ++++++++++++++++++++++
97 9 files changed, 222 insertions(+), 4 deletions(-)
98 create mode 100644 libc/sysdeps/linux/common/posix_fallocate.c
99 create mode 100644 libc/sysdeps/linux/common/posix_fallocate64.c
100 create mode 100644 test/unistd/tst-posix_fallocate.c
101
102Index: git/include/fcntl.h
103===================================================================
104--- git.orig/include/fcntl.h 2012-09-02 17:00:26.000000000 -0700
105+++ git/include/fcntl.h 2012-09-02 17:01:51.567076705 -0700
106@@ -210,9 +210,7 @@
107
108 #endif
109
110-#if 0 /* && defined __UCLIBC_HAS_ADVANCED_REALTIME__ */
111-
112-/* FIXME -- uClibc should probably implement these... */
113+#if defined __UCLIBC_HAS_ADVANCED_REALTIME__
114
115 /* Reserve storage for the data of the file associated with FD.
116
117Index: git/libc/sysdeps/linux/common/Makefile.in
118===================================================================
119--- git.orig/libc/sysdeps/linux/common/Makefile.in 2012-09-02 17:00:26.000000000 -0700
120+++ git/libc/sysdeps/linux/common/Makefile.in 2012-09-02 17:03:02.739079369 -0700
121@@ -81,7 +81,7 @@
122 sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
123 sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c
124 # clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typed_mem_get_info|pthread_mutex_timedlock|sem_timedwait
125-CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
126+CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c posix_fallocate.c posix_fallocate64.c
127 CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c
128 CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c
129 CSRC-$(UCLIBC_HAS_XATTR) += xattr.c
130Index: git/libc/sysdeps/linux/common/bits/kernel-features.h
131===================================================================
132--- git.orig/libc/sysdeps/linux/common/bits/kernel-features.h 2012-09-02 17:00:26.000000000 -0700
133+++ git/libc/sysdeps/linux/common/bits/kernel-features.h 2012-09-02 17:01:51.567076705 -0700
134@@ -494,6 +494,14 @@
135 # define __ASSUME_PRIVATE_FUTEX 1
136 #endif
137
138+/* Support for fallocate was added in 2.6.23,
139+ on s390 only after 2.6.23-rc1, on alpha only after 2.6.33-rc1. */
140+#if __LINUX_KERNEL_VERSION >= 0x020617 \
141+ && (!defined __s390__ || __LINUX_KERNEL_VERSION >= 0x020618) \
142+ && (!defined __alpha__ || __LINUX_KERNEL_VERSION >= 0x020621)
143+# define __ASSUME_FALLOCATE 1
144+#endif
145+
146 /* getcpu is a syscall for x86-64 since 3.1. */
147 #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
148 # define __ASSUME_GETCPU_SYSCALL 1
149Index: git/libc/sysdeps/linux/common/posix_fallocate.c
150===================================================================
151--- /dev/null 1970-01-01 00:00:00.000000000 +0000
152+++ git/libc/sysdeps/linux/common/posix_fallocate.c 2012-09-02 17:01:51.579076667 -0700
153@@ -0,0 +1,43 @@
154+/* vi: set sw=4 ts=4: */
155+/*
156+ * posix_fallocate() for uClibc
157+ * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
158+ *
159+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
160+ *
161+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
162+ */
163+
164+#include <sys/syscall.h>
165+#include <fcntl.h>
166+#include <bits/kernel-features.h>
167+#include <stdint.h>
168+
169+#if defined __NR_fallocate
170+int posix_fallocate(int fd, __off_t offset, __off_t len)
171+{
172+ int ret;
173+
174+# if __WORDSIZE == 32
175+ uint32_t off_low = offset;
176+ uint32_t len_low = len;
177+ /* may assert that these >>31 are 0 */
178+ uint32_t zero = 0;
179+ INTERNAL_SYSCALL_DECL(err);
180+ ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
181+ __LONG_LONG_PAIR (zero, off_low),
182+ __LONG_LONG_PAIR (zero, len_low)));
183+# elif __WORDSIZE == 64
184+ INTERNAL_SYSCALL_DECL(err);
185+ ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, 0, offset, len));
186+# else
187+# error your machine is neither 32 bit or 64 bit ... it must be magical
188+#endif
189+ if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
190+ return INTERNAL_SYSCALL_ERRNO (ret, err);
191+ return 0;
192+}
193+# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
194+strong_alias(posix_fallocate,posix_fallocate64)
195+# endif
196+#endif
197Index: git/libc/sysdeps/linux/common/posix_fallocate64.c
198===================================================================
199--- /dev/null 1970-01-01 00:00:00.000000000 +0000
200+++ git/libc/sysdeps/linux/common/posix_fallocate64.c 2012-09-02 17:01:51.579076667 -0700
201@@ -0,0 +1,39 @@
202+/* vi: set sw=4 ts=4: */
203+/*
204+ * posix_fallocate() for uClibc
205+ * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
206+ *
207+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
208+ *
209+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
210+ */
211+
212+#include <sys/syscall.h>
213+#include <fcntl.h>
214+#include <bits/kernel-features.h>
215+#include <stdint.h>
216+
217+#if defined __NR_fallocate
218+
219+# if __WORDSIZE == 64
220+/* Can use normal posix_fallocate() */
221+# elif __WORDSIZE == 32
222+int posix_fallocate64(int fd, __off64_t offset, __off64_t len)
223+{
224+ int ret;
225+ uint32_t off_low = offset & 0xffffffff;
226+ uint32_t off_high = offset >> 32;
227+ uint32_t len_low = len & 0xffffffff;
228+ uint32_t len_high = len >> 32;
229+ INTERNAL_SYSCALL_DECL(err);
230+ ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
231+ __LONG_LONG_PAIR (off_high, off_low),
232+ __LONG_LONG_PAIR (len_high, len_low)));
233+ if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
234+ return INTERNAL_SYSCALL_ERRNO (ret, err);
235+ return 0;
236+}
237+# else
238+# error your machine is neither 32 bit or 64 bit ... it must be magical
239+# endif
240+#endif
241Index: git/libc/sysdeps/linux/common/stubs.c
242===================================================================
243--- git.orig/libc/sysdeps/linux/common/stubs.c 2012-09-02 17:00:26.000000000 -0700
244+++ git/libc/sysdeps/linux/common/stubs.c 2012-09-02 17:01:51.579076667 -0700
245@@ -209,6 +209,10 @@
246 make_stub(madvise)
247 #endif
248
249+#if !defined __NR_fallocate && defined __UCLIBC_HAS_ADVANCED_REALTIME__
250+make_ret_stub(posix_fallocate)
251+#endif
252+
253 #if !defined __NR_modify_ldt && defined __UCLIBC_LINUX_SPECIFIC__
254 make_stub(modify_ldt)
255 #endif
256Index: git/test/.gitignore
257===================================================================
258--- git.orig/test/.gitignore 2012-09-02 17:00:26.000000000 -0700
259+++ git/test/.gitignore 2012-09-02 17:01:51.579076667 -0700
260@@ -302,6 +302,7 @@
261 unistd/getopt
262 unistd/getopt_long
263 unistd/tstgetopt
264+unistd/tst-posix_fallocate
265 unistd/tst-preadwrite
266 unistd/tst-preadwrite64
267 unistd/vfork
268Index: git/test/unistd/Makefile.in
269===================================================================
270--- git.orig/test/unistd/Makefile.in 2012-09-02 17:00:26.000000000 -0700
271+++ git/test/unistd/Makefile.in 2012-09-02 17:01:51.579076667 -0700
272@@ -4,6 +4,9 @@
273 ifeq ($(UCLIBC_HAS_LFS),)
274 TESTS_DISABLED := tst-preadwrite64
275 endif
276+ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),)
277+TESTS_DISABLED := tst-posix_fallocate
278+endif
279 OPTS_getopt := -abcXXX -9
280 OPTS_getopt_long := --add XXX --delete YYY --verbose
281 ifeq ($(UCLIBC_HAS_GNU_GETOPT),y)
282Index: git/test/unistd/tst-posix_fallocate.c
283===================================================================
284--- /dev/null 1970-01-01 00:00:00.000000000 +0000
285+++ git/test/unistd/tst-posix_fallocate.c 2012-09-02 17:01:51.579076667 -0700
286@@ -0,0 +1,121 @@
287+#include <fcntl.h>
288+#include <sys/stat.h>
289+
290+static void do_prepare (void);
291+#define PREPARE(argc, argv) do_prepare ()
292+static int do_test (void);
293+#define TEST_FUNCTION do_test ()
294+#include <test-skeleton.c>
295+
296+static int fd;
297+#ifndef O_LARGEFILE
298+# error no O_LARGEFILE
299+#endif
300+static void
301+do_prepare (void)
302+{
303+ fd = create_temp_file ("tst-posix_fallocate.", NULL);
304+ if (fd == -1)
305+ {
306+ printf ("cannot create temporary file: %m\n");
307+ exit (1);
308+ }
309+}
310+
311+
312+static int
313+do_test (void)
314+{
315+ struct stat64 st;
316+
317+ if (fstat64 (fd, &st) != 0)
318+ {
319+ puts ("1st fstat failed");
320+ return 1;
321+ }
322+
323+ if (st.st_size != 0)
324+ {
325+ puts ("file not created with size 0");
326+ return 1;
327+ }
328+
329+ if (posix_fallocate (fd, 512, 768) != 0)
330+ {
331+ puts ("1st posix_fallocate call failed");
332+ return 1;
333+ }
334+
335+ if (fstat64 (fd, &st) != 0)
336+ {
337+ puts ("2nd fstat failed");
338+ return 1;
339+ }
340+
341+ if (st.st_size != 512 + 768)
342+ {
343+ printf ("file size after 1st posix_fallocate call is %llu, expected %u\n",
344+ (unsigned long long int) st.st_size, 512u + 768u);
345+ return 1;
346+ }
347+
348+ if (posix_fallocate (fd, 0, 1024) != 0)
349+ {
350+ puts ("2nd posix_fallocate call failed");
351+ return 1;
352+ }
353+
354+ if (fstat64 (fd, &st) != 0)
355+ {
356+ puts ("3rd fstat failed");
357+ return 1;
358+ }
359+
360+ if (st.st_size != 512 + 768)
361+ {
362+ puts ("file size changed in 2nd posix_fallocate");
363+ return 1;
364+ }
365+
366+ if (posix_fallocate (fd, 2048, 64) != 0)
367+ {
368+ puts ("3rd posix_fallocate call failed");
369+ return 1;
370+ }
371+
372+ if (fstat64 (fd, &st) != 0)
373+ {
374+ puts ("4th fstat failed");
375+ return 1;
376+ }
377+
378+ if (st.st_size != 2048 + 64)
379+ {
380+ printf ("file size after 3rd posix_fallocate call is %llu, expected %u\n",
381+ (unsigned long long int) st.st_size, 2048u + 64u);
382+ return 1;
383+ }
384+
385+ if (posix_fallocate64 (fd, 4097ULL, 4294967295ULL + 2ULL) != 0)
386+ {
387+ puts ("4th posix_fallocate call failed");
388+ return 1;
389+ }
390+
391+ if (fstat64 (fd, &st) != 0)
392+ {
393+ puts ("5th fstat failed");
394+ return 1;
395+ }
396+
397+ if (st.st_size != 4097ULL + 4294967295ULL + 2ULL)
398+ {
399+ printf ("file size after 4th posix_fallocate call is %llu, expected %u\n",
400+ (unsigned long long int) st.st_size, 4097ULL + 4294967295ULL + 2ULL);
401+ return 1;
402+ }
403+
404+ close (fd);
405+
406+ return 0;
407+}
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/powerpc_copysignl.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/powerpc_copysignl.patch
deleted file mode 100644
index 3fa10af4db..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/powerpc_copysignl.patch
+++ /dev/null
@@ -1,113 +0,0 @@
1Add ppc copysignl implementation
2
3Upstream-Status: Pending
4
5Signed-off-by: Khem Raj <raj.khem@gmail.com>
6
7Index: git/libc/sysdeps/linux/powerpc/Makefile.arch
8===================================================================
9--- git.orig/libc/sysdeps/linux/powerpc/Makefile.arch
10+++ git/libc/sysdeps/linux/powerpc/Makefile.arch
11@@ -5,7 +5,7 @@
12 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
13 #
14
15-CSRC := __syscall_error.c pread_write.c ioctl.c
16+CSRC := __syscall_error.c pread_write.c ioctl.c copysignl.c
17
18 ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),y)
19 CSRC += posix_fadvise.c posix_fadvise64.c
20Index: git/libc/sysdeps/linux/powerpc/copysignl.c
21===================================================================
22--- /dev/null
23+++ git/libc/sysdeps/linux/powerpc/copysignl.c
24@@ -0,0 +1,89 @@
25+/* s_copysignl.c -- long double version of s_copysign.c.
26+ * Conversion to long double by Ulrich Drepper,
27+ * Cygnus Support, drepper@cygnus.com.
28+ */
29+
30+/*
31+ * ====================================================
32+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
33+ *
34+ * Developed at SunPro, a Sun Microsystems, Inc. business.
35+ * Permission to use, copy, modify, and distribute this
36+ * software is freely granted, provided that this notice
37+ * is preserved.
38+ * ====================================================
39+ */
40+
41+/*
42+ * copysignl(long double x, long double y)
43+ * copysignl(x,y) returns a value with the magnitude of x and
44+ * with the sign bit of y.
45+ */
46+
47+#include <endian.h>
48+#include <stdint.h>
49+
50+#if __FLOAT_WORD_ORDER == BIG_ENDIAN
51+
52+typedef union
53+{
54+ long double value;
55+ struct
56+ {
57+ int sign_exponent:16;
58+ unsigned int empty:16;
59+ uint32_t msw;
60+ uint32_t lsw;
61+ } parts;
62+} ieee_long_double_shape_type;
63+
64+#endif
65+
66+#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
67+
68+typedef union
69+{
70+ long double value;
71+ struct
72+ {
73+ uint32_t lsw;
74+ uint32_t msw;
75+ int sign_exponent:16;
76+ unsigned int empty:16;
77+ } parts;
78+} ieee_long_double_shape_type;
79+
80+#endif
81+
82+/* Get int from the exponent of a long double. */
83+
84+#define GET_LDOUBLE_EXP(exp,d) \
85+do { \
86+ ieee_long_double_shape_type ge_u; \
87+ ge_u.value = (d); \
88+ (exp) = ge_u.parts.sign_exponent; \
89+} while (0)
90+
91+/* Set exponent of a long double from an int. */
92+
93+#define SET_LDOUBLE_EXP(d,exp) \
94+do { \
95+ ieee_long_double_shape_type se_u; \
96+ se_u.value = (d); \
97+ se_u.parts.sign_exponent = (exp); \
98+ (d) = se_u.value; \
99+} while (0)
100+
101+long double copysignl(long double x, long double y);
102+libc_hidden_proto(copysignl);
103+
104+long double copysignl(long double x, long double y)
105+{
106+ uint32_t es1,es2;
107+ GET_LDOUBLE_EXP(es1,x);
108+ GET_LDOUBLE_EXP(es2,y);
109+ SET_LDOUBLE_EXP(x,(es1&0x7fff)|(es2&0x8000));
110+ return x;
111+}
112+
113+libc_hidden_def(copysignl);
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/remove_attribute_optimize_Os.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/remove_attribute_optimize_Os.patch
deleted file mode 100644
index bee251c335..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/remove_attribute_optimize_Os.patch
+++ /dev/null
@@ -1,179 +0,0 @@
1Dont support localised optimizations this helps to have a global -O level
2
3Signed-off-by: Khem Raj <raj.khem@gmail.com>
4Upstream-Status: Pending
5
6Index: git/libpthread/nptl/pthread_mutex_timedlock.c
7===================================================================
8--- git.orig/libpthread/nptl/pthread_mutex_timedlock.c
9+++ git/libpthread/nptl/pthread_mutex_timedlock.c
10@@ -29,7 +29,9 @@
11 * error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
12 */
13 int
14+#ifndef __OPTIMIZE__
15 attribute_optimize("Os")
16+#endif
17 pthread_mutex_timedlock (
18 pthread_mutex_t *mutex,
19 const struct timespec *abstime)
20Index: git/libc/sysdeps/linux/powerpc/bits/mathinline.h
21===================================================================
22--- git.orig/libc/sysdeps/linux/powerpc/bits/mathinline.h
23+++ git/libc/sysdeps/linux/powerpc/bits/mathinline.h
24@@ -27,7 +27,7 @@
25 #ifdef __cplusplus
26 # define __MATH_INLINE __inline
27 #else
28-# define __MATH_INLINE extern __inline
29+# define __MATH_INLINE __extern_inline
30 #endif /* __cplusplus */
31
32 #if defined __GNUC__ && !defined _SOFT_FLOAT
33Index: git/libc/sysdeps/linux/alpha/bits/mathinline.h
34===================================================================
35--- git.orig/libc/sysdeps/linux/alpha/bits/mathinline.h
36+++ git/libc/sysdeps/linux/alpha/bits/mathinline.h
37@@ -25,7 +25,7 @@
38 #ifdef __cplusplus
39 # define __MATH_INLINE __inline
40 #else
41-# define __MATH_INLINE extern __inline
42+# define __MATH_INLINE __extern_inline
43 #endif
44
45 #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
46Index: git/libc/sysdeps/linux/common/bits/socket.h
47===================================================================
48--- git.orig/libc/sysdeps/linux/common/bits/socket.h
49+++ git/libc/sysdeps/linux/common/bits/socket.h
50@@ -302,7 +302,7 @@ extern struct cmsghdr *__cmsg_nxthdr (st
51 libc_hidden_proto(__cmsg_nxthdr)
52 #ifdef __USE_EXTERN_INLINES
53 # ifndef _EXTERN_INLINE
54-# define _EXTERN_INLINE extern __inline
55+# define _EXTERN_INLINE __extern_inline
56 # endif
57 _EXTERN_INLINE struct cmsghdr *
58 __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
59Index: git/libc/sysdeps/linux/i386/bits/mathinline.h
60===================================================================
61--- git.orig/libc/sysdeps/linux/i386/bits/mathinline.h
62+++ git/libc/sysdeps/linux/i386/bits/mathinline.h
63@@ -26,7 +26,7 @@
64 #ifdef __cplusplus
65 # define __MATH_INLINE __inline
66 #else
67-# define __MATH_INLINE extern __inline
68+# define __MATH_INLINE __extern_inline
69 #endif
70
71
72Index: git/libc/sysdeps/linux/ia64/bits/mathinline.h
73===================================================================
74--- git.orig/libc/sysdeps/linux/ia64/bits/mathinline.h
75+++ git/libc/sysdeps/linux/ia64/bits/mathinline.h
76@@ -24,7 +24,7 @@
77 #ifdef __cplusplus
78 # define __MATH_INLINE __inline
79 #else
80-# define __MATH_INLINE extern __inline
81+# define __MATH_INLINE __extern_inline
82 #endif
83
84 #if defined __USE_ISOC99 && defined __GNUC__ && __GNUC__ >= 2
85Index: git/libc/sysdeps/linux/m68k/bits/mathinline.h
86===================================================================
87--- git.orig/libc/sysdeps/linux/m68k/bits/mathinline.h
88+++ git/libc/sysdeps/linux/m68k/bits/mathinline.h
89@@ -92,7 +92,7 @@
90 # ifdef __cplusplus
91 # define __m81_inline __inline
92 # else
93-# define __m81_inline extern __inline
94+# define __m81_inline __extern_inline
95 # endif
96 # define __M81_MATH_INLINES 1
97 #endif
98@@ -351,14 +351,14 @@ __inline_functions (long double,l)
99 /* Note that there must be no whitespace before the argument passed for
100 NAME, to make token pasting work correctly with -traditional. */
101 # define __inline_forward_c(rettype, name, args1, args2) \
102-extern __inline rettype __attribute__((__const__)) \
103+__extern_inline rettype __attribute__((__const__)) \
104 name args1 \
105 { \
106 return __CONCAT(__,name) args2; \
107 }
108
109 # define __inline_forward(rettype, name, args1, args2) \
110-extern __inline rettype name args1 \
111+__extern_inline rettype name args1 \
112 { \
113 return __CONCAT(__,name) args2; \
114 }
115Index: git/libc/sysdeps/linux/mips/bits/socket.h
116===================================================================
117--- git.orig/libc/sysdeps/linux/mips/bits/socket.h
118+++ git/libc/sysdeps/linux/mips/bits/socket.h
119@@ -307,7 +307,7 @@ extern struct cmsghdr *__cmsg_nxthdr (st
120 libc_hidden_proto(__cmsg_nxthdr)
121 #ifdef __USE_EXTERN_INLINES
122 # ifndef _EXTERN_INLINE
123-# define _EXTERN_INLINE extern __inline
124+# define _EXTERN_INLINE __extern_inline
125 # endif
126 _EXTERN_INLINE struct cmsghdr *
127 __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
128Index: git/libc/sysdeps/linux/mips/sys/tas.h
129===================================================================
130--- git.orig/libc/sysdeps/linux/mips/sys/tas.h
131+++ git/libc/sysdeps/linux/mips/sys/tas.h
132@@ -30,7 +30,7 @@ extern int _test_and_set (int *p, int v)
133 #ifdef __USE_EXTERN_INLINES
134
135 # ifndef _EXTERN_INLINE
136-# define _EXTERN_INLINE extern __inline
137+# define _EXTERN_INLINE __extern_inline
138 # endif
139
140 _EXTERN_INLINE int
141Index: git/libc/sysdeps/linux/sparc/bits/mathinline.h
142===================================================================
143--- git.orig/libc/sysdeps/linux/sparc/bits/mathinline.h
144+++ git/libc/sysdeps/linux/sparc/bits/mathinline.h
145@@ -131,7 +131,7 @@
146 # ifdef __cplusplus
147 # define __MATH_INLINE __inline
148 # else
149-# define __MATH_INLINE extern __inline
150+# define __MATH_INLINE __extern_inline
151 # endif /* __cplusplus */
152
153 /* The gcc, version 2.7 or below, has problems with all this inlining
154Index: git/libc/sysdeps/linux/sparc/bits/socket.h
155===================================================================
156--- git.orig/libc/sysdeps/linux/sparc/bits/socket.h
157+++ git/libc/sysdeps/linux/sparc/bits/socket.h
158@@ -292,7 +292,7 @@ extern struct cmsghdr *__cmsg_nxthdr (st
159 libc_hidden_proto(__cmsg_nxthdr)
160 #ifdef __USE_EXTERN_INLINES
161 # ifndef _EXTERN_INLINE
162-# define _EXTERN_INLINE extern __inline
163+# define _EXTERN_INLINE __extern_inline
164 # endif
165 _EXTERN_INLINE struct cmsghdr *
166 __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
167Index: git/libc/sysdeps/linux/x86_64/bits/mathinline.h
168===================================================================
169--- git.orig/libc/sysdeps/linux/x86_64/bits/mathinline.h
170+++ git/libc/sysdeps/linux/x86_64/bits/mathinline.h
171@@ -25,7 +25,7 @@
172 #ifdef __cplusplus
173 # define __MATH_INLINE __inline
174 #else
175-# define __MATH_INLINE extern __inline
176+# define __MATH_INLINE __extern_inline
177 #endif
178
179
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.distro b/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.distro
deleted file mode 100644
index c33bf8e7c4..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.distro
+++ /dev/null
@@ -1,190 +0,0 @@
1#
2# General Library Settings
3#
4# HAVE_NO_PIC is not set
5# DOPIC is not set
6# HAVE_NO_SHARED is not set
7# ARCH_HAS_NO_LDSO is not set
8HAVE_SHARED=y
9# FORCE_SHAREABLE_TEXT_SEGMENTS is not set
10LDSO_LDD_SUPPORT=y
11LDSO_CACHE_SUPPORT=y
12# LDSO_PRELOAD_FILE_SUPPORT is not set
13LDSO_BASE_FILENAME="ld.so"
14# UCLIBC_STATIC_LDCONFIG is not set
15LDSO_RUNPATH=y
16UCLIBC_CTOR_DTOR=y
17LDSO_GNU_HASH_SUPPORT=y
18# HAS_NO_THREADS is not set
19UCLIBC_HAS_THREADS=y
20UCLIBC_HAS_THREADS_NATIVE=y
21PTHREADS_DEBUG_SUPPORT=y
22# LINUXTHREADS_OLD is not set
23UCLIBC_HAS_LFS=y
24# MALLOC is not set
25# MALLOC_SIMPLE is not set
26MALLOC_STANDARD=y
27MALLOC_GLIBC_COMPAT=y
28UCLIBC_DYNAMIC_ATEXIT=y
29COMPAT_ATEXIT=y
30UCLIBC_SUSV3_LEGACY=y
31UCLIBC_SUSV3_LEGACY_MACROS=y
32UCLIBC_SUSV4_LEGACY=y
33UCLIBC_HAS_SHADOW=y
34UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y
35UCLIBC_HAS___PROGNAME=y
36UNIX98PTY_ONLY=y
37ASSUME_DEVPTS=y
38UCLIBC_HAS_LIBUTIL=y
39UCLIBC_HAS_TM_EXTENSIONS=y
40UCLIBC_HAS_TZ_CACHING=y
41UCLIBC_HAS_TZ_FILE=y
42UCLIBC_HAS_TZ_FILE_READ_MANY=y
43UCLIBC_TZ_FILE_PATH="/etc/TZ"
44
45#
46# Advanced Library Settings
47#
48UCLIBC_PWD_BUFFER_SIZE=256
49UCLIBC_GRP_BUFFER_SIZE=256
50
51#
52# Networking Support
53#
54UCLIBC_HAS_IPV6=y
55UCLIBC_HAS_RPC=y
56UCLIBC_HAS_FULL_RPC=y
57# UCLIBC_HAS_REENTRANT_RPC is not set
58UCLIBC_USE_NETLINK=y
59UCLIBC_SUPPORT_AI_ADDRCONFIG=y
60
61UCLIBC_HAS_BSD_RES_CLOSE=y
62UCLIBC_HAS_LIBRESOLV_STUB=y
63UCLIBC_HAS_LIBNSL_STUB=y
64
65#
66# String and Stdio Support
67#
68UCLIBC_HAS_STRING_GENERIC_OPT=y
69UCLIBC_HAS_STRING_ARCH_OPT=y
70UCLIBC_HAS_CTYPE_TABLES=y
71UCLIBC_HAS_CTYPE_SIGNED=y
72# UCLIBC_HAS_CTYPE_UNSAFE is not set
73UCLIBC_HAS_CTYPE_CHECKED=y
74# UCLIBC_HAS_CTYPE_ENFORCED is not set
75UCLIBC_HAS_WCHAR=y
76# UCLIBC_HAS_LOCALE is not set
77UCLIBC_HAS_HEXADECIMAL_FLOATS=y
78UCLIBC_HAS_GLIBC_CUSTOM_PRINTF=y
79UCLIBC_PRINTF_SCANF_POSITIONAL_ARGS=9
80UCLIBC_HAS_SCANF_GLIBC_A_FLAG=y
81# UCLIBC_HAS_STDIO_BUFSIZ_NONE is not set
82UCLIBC_HAS_STDIO_BUFSIZ_256=y
83# UCLIBC_HAS_STDIO_BUFSIZ_512 is not set
84# UCLIBC_HAS_STDIO_BUFSIZ_1024 is not set
85# UCLIBC_HAS_STDIO_BUFSIZ_2048 is not set
86# UCLIBC_HAS_STDIO_BUFSIZ_4096 is not set
87# UCLIBC_HAS_STDIO_BUFSIZ_8192 is not set
88UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE=y
89# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4 is not set
90# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8 is not set
91# UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT is not set
92UCLIBC_HAS_STDIO_GETC_MACRO=y
93UCLIBC_HAS_STDIO_PUTC_MACRO=y
94UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION=y
95# UCLIBC_HAS_FOPEN_LARGEFILE_MODE is not set
96UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE=y
97UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y
98UCLIBC_HAS_PRINTF_M_SPEC=y
99UCLIBC_HAS_ERRNO_MESSAGES=y
100# UCLIBC_HAS_SYS_ERRLIST is not set
101UCLIBC_HAS_SIGNUM_MESSAGES=y
102# UCLIBC_HAS_SYS_SIGLIST is not set
103UCLIBC_HAS_GNU_GETOPT=y
104UCLIBC_HAS_GNU_GETSUBOPT=y
105
106#
107# Big and Tall
108#
109UCLIBC_HAS_REGEX=y
110# UCLIBC_HAS_REGEX_OLD is not set
111UCLIBC_HAS_FNMATCH=y
112# UCLIBC_HAS_FNMATCH_OLD is not set
113UCLIBC_HAS_WORDEXP=y
114UCLIBC_HAS_NFTW=y
115UCLIBC_HAS_FTW=y
116UCLIBC_HAS_FTS=y
117UCLIBC_HAS_GLOB=y
118UCLIBC_HAS_GNU_GLOB=y
119
120#
121# Library Installation Options
122#
123SHARED_LIB_LOADER_PREFIX="/lib"
124RUNTIME_PREFIX="/"
125DEVEL_PREFIX="//usr"
126
127#
128# Security options
129#
130# UCLIBC_BUILD_PIE is not set
131# UCLIBC_HAS_ARC4RANDOM is not set
132# HAVE_NO_SSP is not set
133# UCLIBC_HAS_SSP is not set
134UCLIBC_BUILD_RELRO=y
135UCLIBC_BUILD_NOW=y
136UCLIBC_BUILD_NOEXECSTACK=y
137
138#
139# uClibc development/debugging options
140#
141CROSS_COMPILER_PREFIX=""
142UCLIBC_EXTRA_CFLAGS=""
143# DODEBUG is not set
144# DODEBUG_PT is not set
145# DOSTRIP is not set
146# DOASSERTS is not set
147# SUPPORT_LD_DEBUG is not set
148# SUPPORT_LD_DEBUG_EARLY is not set
149# UCLIBC_MALLOC_DEBUGGING is not set
150UCLIBC_HAS_BACKTRACE=y
151WARNINGS="-Wall"
152# EXTRA_WARNINGS is not set
153# DOMULTI is not set
154# UCLIBC_MJN3_ONLY is not set
155
156# math stuff for perl
157DO_C99_MATH=y
158UCLIBC_HAS_LONG_DOUBLE_MATH=y
159UCLIBC_HAS_FENV=y
160UCLIBC_LINUX_SPECIFIC=y
161UCLIBC_HAS_REALTIME=y
162UCLIBC_HAS_ADVANCED_REALTIME=y
163UCLIBC_HAS_NETWORK_SUPPORT=y
164UCLIBC_HAS_SOCKET=y
165UCLIBC_HAS_BSD_ERR=y
166UCLIBC_HAS_SYSLOG=y
167UCLIBC_HAS_CRYPT=y
168UCLIBC_HAS_CRYPT_IMPL=y
169UCLIBC_HAS_GNU_ERROR=y
170UCLIBC_HAS_PTY=y
171UCLIBC_BSD_SPECIFIC=y
172UCLIBC_HAS_EPOLL=y
173UCLIBC_HAS_FLOATS=y
174
175# The below option is needed for ARM since depending
176# upong what intruction set is chosen this will be
177# enabled. As such it is harmless and will be punted
178# by menuconfig for other arches.
179
180# COMPILE_IN_THUMB_MODE is not set
181
182# needed by systemd
183UCLIBC_HAS_UTMPX=y
184UCLIBC_LINUX_MODULE_26=y
185UCLIBC_HAS_RESOLVER_SUPPORT=y
186# needed for LTP
187UCLIBC_SUSV4_LEGACY=y
188UCLIBC_HAS_OBSOLETE_BSD_SIGNAL=y
189DO_XSI_MATH=y
190UCLIBC_SV4_DEPRECATED=y
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.machine b/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.machine
deleted file mode 100644
index 595f444dac..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/uClibc.machine
+++ /dev/null
@@ -1,14 +0,0 @@
1#
2# Automatically generated make config: don't edit
3# Version: 0.9.32-git
4# Mon Jul 19 01:34:29 2010
5#
6#
7# Using ELF file format
8#
9FORCE_OPTIONS_FOR_ARCH=y
10ARCH_HAS_MMU=y
11ARCH_USE_MMU=y
12KERNEL_HEADERS="/usr/include"
13HAVE_DOT_CONFIG=y
14
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc-execvpe.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc-execvpe.patch
deleted file mode 100644
index fe191fc496..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc-execvpe.patch
+++ /dev/null
@@ -1,163 +0,0 @@
1From d20556adadea03bff0bba051172caf0314a35471 Mon Sep 17 00:00:00 2001
2From: Henning Heinold <heinold@inf.fu-berlin.de>
3Date: Sat, 4 Jun 2011 21:23:15 +0200
4Subject: [PATCH 2/2] libc: add non standard execvpe function
5
6
7Signed-off-by: Henning Heinold <heinold@inf.fu-berlin.de>
8---
9 include/unistd.h | 6 ++++++
10 libc/unistd/exec.c | 38 +++++++++++++++++++++++++++++++++-----
11 libc/unistd/execvpe.c | 7 +++++++
12 3 files changed, 46 insertions(+), 5 deletions(-)
13 create mode 100644 libc/unistd/execvpe.c
14
15
16Upstream-Status: Pending
17
18diff --git a/include/unistd.h b/include/unistd.h
19index 9568790..070e4f2 100644
20--- a/include/unistd.h
21+++ b/include/unistd.h
22@@ -557,6 +557,12 @@ extern int execvp (__const char *__file, char *__const __argv[])
23 __THROW __nonnull ((1));
24 libc_hidden_proto(execvp)
25
26+/* Execute FILE, searching in the `PATH' environment variable if it contains
27+ no slashes, with arguments ARGV and environment from a pointer */
28+extern int execvpe (__const char *__file, char *__const __argv[], char *__const __envp[])
29+ __THROW __nonnull ((1));
30+libc_hidden_proto(execvpe)
31+
32 /* Execute FILE, searching in the `PATH' environment variable if
33 it contains no slashes, with all arguments after FILE until a
34 NULL pointer and environment from `environ'. */
35diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
36index 7d24072..802a174 100644
37--- a/libc/unistd/exec.c
38+++ b/libc/unistd/exec.c
39@@ -32,6 +32,8 @@
40 /**********************************************************************/
41 #define EXEC_FUNC_COMMON 0
42 #define EXEC_FUNC_EXECVP 1
43+#define EXEC_FUNC_EXECVPE 2
44+
45 #if defined(__ARCH_USE_MMU__)
46
47 /* We have an MMU, so use alloca() to grab space for buffers and arg lists. */
48@@ -58,6 +60,7 @@
49 * execle(a) -> execve(-)
50 * execv(-) -> execve(-)
51 * execvp(a) -> execve(-)
52+ * execvpe(a) -> execve(-)
53 */
54
55 # define EXEC_ALLOC_SIZE(VAR) /* nothing to do */
56@@ -219,15 +222,18 @@ libc_hidden_def(execlp)
57
58 #endif
59 /**********************************************************************/
60-#ifdef L_execvp
61+#if defined (L_execvp) || defined(L_execvpe)
62
63
64 /* Use a default path that matches glibc behavior, since SUSv3 says
65 * this is implementation-defined. The default is current working dir,
66 * /bin, and then /usr/bin. */
67 static const char default_path[] = ":/bin:/usr/bin";
68-
69+#if defined (L_execvp)
70 int execvp(const char *path, char *const argv[])
71+#elif defined (L_execvpe)
72+int execvpe(const char *path, char *const argv[], char *const envp[])
73+#endif
74 {
75 char *buf = NULL;
76 char *p;
77@@ -245,7 +251,11 @@ int execvp(const char *path, char *const argv[])
78 }
79
80 if (strchr(path, '/')) {
81+#if defined (L_execvp)
82 execve(path, argv, __environ);
83+#elif defined (L_execvpe)
84+ execve(path, argv, envp);
85+#endif
86 if (errno == ENOEXEC) {
87 char **nargv;
88 EXEC_ALLOC_SIZE(size2) /* Do NOT add a semicolon! */
89@@ -254,11 +264,19 @@ int execvp(const char *path, char *const argv[])
90 /* Need the dimension - 1. We omit counting the trailing
91 * NULL but we actually omit the first entry. */
92 for (n=0 ; argv[n] ; n++) {}
93+#if defined (L_execvp)
94 nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVP);
95+#elif defined (L_execvpe)
96+ nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, EXEC_FUNC_EXECVPE);
97+#endif
98 nargv[0] = argv[0];
99 nargv[1] = (char *)path;
100 memcpy(nargv+2, argv+1, n*sizeof(char *));
101+#if defined (L_execvp)
102 execve("/bin/sh", nargv, __environ);
103+#elif defined (L_execvpe)
104+ execve("/bin/sh", nargv, envp);
105+#endif
106 EXEC_FREE(nargv, size2);
107 }
108 } else {
109@@ -277,8 +295,11 @@ int execvp(const char *path, char *const argv[])
110 return -1;
111 }
112 len = (FILENAME_MAX - 1) - plen;
113-
114+#if defined (L_execvp)
115 buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVP);
116+#elif defined (L_execvpe)
117+ buf = EXEC_ALLOC(FILENAME_MAX, size, EXEC_FUNC_EXECVPE);
118+#endif
119 {
120 int seen_small = 0;
121 s0 = buf + len;
122@@ -300,8 +321,11 @@ int execvp(const char *path, char *const argv[])
123 s[plen-1] = '/';
124 }
125
126+#if defined (L_execvp)
127 execve(s, argv, __environ);
128-
129+#elif defined (L_execvpe)
130+ execve(s, argv, envp);
131+#endif
132 seen_small = 1;
133
134 if (errno == ENOEXEC) {
135@@ -325,7 +349,11 @@ int execvp(const char *path, char *const argv[])
136
137 return -1;
138 }
139+#if defined (L_execvp)
140 libc_hidden_def(execvp)
141-
142+#elif defined (L_execvpe)
143+libc_hidden_def(execvpe)
144 #endif
145+
146+#endif /* #if defined (L_execvp) || defined(L_execvpe) */
147 /**********************************************************************/
148diff --git a/libc/unistd/execvpe.c b/libc/unistd/execvpe.c
149new file mode 100644
150index 0000000..5c1ce06
151--- /dev/null
152+++ b/libc/unistd/execvpe.c
153@@ -0,0 +1,7 @@
154+/* Copyright (C) 2011 Hennning Heinold <heinold@inf.fu-berlin.de>
155+ *
156+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
157+ */
158+
159+#define L_execvpe
160+#include "exec.c"
161--
1621.7.5.3
163
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc_enable_log2_test.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc_enable_log2_test.patch
deleted file mode 100644
index 37a59884b8..0000000000
--- a/meta/recipes-core/uclibc/uclibc-0.9.33/uclibc_enable_log2_test.patch
+++ /dev/null
@@ -1,35 +0,0 @@
1uclibc now has log2 so enable the tests
2
3Signed-off-by: Khem Raj <raj.khem@gmail.com>
4Upstream-Status: Pending
5
6Index: uClibc/test/math/libm-test.inc
7===================================================================
8--- uClibc/test/math/libm-test.inc (revision 23784)
9+++ uClibc/test/math/libm-test.inc (working copy)
10@@ -3414,7 +3414,6 @@
11 }
12
13
14-#if 0
15 static void
16 log2_test (void)
17 {
18@@ -3444,7 +3443,6 @@
19
20 END (log2);
21 }
22-#endif
23
24
25 static void
26@@ -4967,9 +4965,7 @@
27 log_test ();
28 log10_test ();
29 log1p_test ();
30-#if 0
31 log2_test ();
32-#endif
33 logb_test ();
34 modf_test ();
35 ilogb_test ();
diff --git a/meta/recipes-core/uclibc/uclibc-initial_0.9.33.bb b/meta/recipes-core/uclibc/uclibc-initial_0.9.33.bb
deleted file mode 100644
index 4620c96bb0..0000000000
--- a/meta/recipes-core/uclibc/uclibc-initial_0.9.33.bb
+++ /dev/null
@@ -1,36 +0,0 @@
1SECTION = "base"
2require uclibc.inc
3require uclibc-${PV}.inc
4
5DEPENDS = "linux-libc-headers ncurses-native virtual/${TARGET_PREFIX}gcc-initial"
6PROVIDES = "virtual/${TARGET_PREFIX}libc-initial"
7
8PACKAGES = ""
9PACKAGES_DYNAMIC = ""
10
11STAGINGCC = "gcc-cross-initial"
12STAGINGCC_class-nativesdk = "gcc-crosssdk-initial"
13
14do_install() {
15 # Install initial headers into the cross dir
16 make PREFIX=${D} DEVEL_PREFIX=${prefix}/ RUNTIME_PREFIX=/ \
17 install_headers install_startfiles
18
19 # add links to linux-libc-headers: final uclibc build need this.
20 for t in linux asm asm-generic; do
21 if [ -d ${D}${includedir}/$t ]; then
22 rm -rf ${D}${includedir}/$t
23 fi
24 ln -sf ${STAGING_DIR_TARGET}${includedir}/$t ${D}${includedir}/
25 done
26
27}
28do_compile() {
29 :
30}
31
32do_siteconfig () {
33 :
34}
35
36do_populate_sysroot[sstate-outputdirs] = "${STAGING_DIR_TCBOOTSTRAP}/"
diff --git a/meta/recipes-core/uclibc/uclibc_0.9.33.bb b/meta/recipes-core/uclibc/uclibc_0.9.33.bb
deleted file mode 100644
index 4071d2adad..0000000000
--- a/meta/recipes-core/uclibc/uclibc_0.9.33.bb
+++ /dev/null
@@ -1,22 +0,0 @@
1SRCREV="7810e4f8027b5c4c8ceec6fefec4eb779362ebb5"
2
3require uclibc.inc
4require uclibc-package.inc
5require uclibc-${PV}.inc
6
7STAGINGCC = "gcc-cross-initial"
8STAGINGCC_class-nativesdk = "gcc-crosssdk-initial"
9
10DEPENDS = "virtual/${TARGET_PREFIX}binutils \
11 virtual/${TARGET_PREFIX}gcc-initial \
12 virtual/${TARGET_PREFIX}libc-initial \
13 linux-libc-headers ncurses-native"
14
15PROVIDES += "virtual/libc virtual/${TARGET_PREFIX}libc-for-gcc"
16RDEPENDS_${PN}-dev = "linux-libc-headers-dev"
17RPROVIDES_${PN}-dev += "libc-dev virtual-libc-dev"
18# uclibc does not really have libsegfault but then using the one from glibc is also not
19# going to work. So we pretend that we have it to make bitbake not pull other recipes
20# to satisfy this dependency for the images/tasks
21
22RPROVIDES_${PN} += "libsegfault rtld(GNU_HASH)"