diff options
Diffstat (limited to 'support')
52 files changed, 0 insertions, 11778 deletions
diff --git a/support/.cvsignore b/support/.cvsignore deleted file mode 100644 index 9b6973f4..00000000 --- a/support/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -Makefile.in -Makefile -.deps -*.la -*.lo -.libs -gnomesupport-h -gnomesupport.h diff --git a/support/ChangeLog b/support/ChangeLog deleted file mode 100644 index 720f3aef..00000000 --- a/support/ChangeLog +++ /dev/null @@ -1,323 +0,0 @@ -1998-12-02 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (EXTRA_DIST): Add back `gnomesupport.awk' and - `README-gnome'. - -1998-11-06 Raja R Harinath <harinath@cs.umn.edu> - - * popt.c (gnomesupport-fake.h): Include. - * poptint.h (ENABLE_NLS): Define POPT_() and _() i18n markers - based on this. - -1998-11-04 Raja R Harinath <harinath@cs.umn.edu> - - * gnomesupport-fake.h: Include gnomesupport.h unconditionally. - * Makefile.am: Build libgnomesupport.la unconditionally. - (popt_sources): List `popt' sources. - (libgnomesupport_la_SOURCES): Include $popt_sources. - (include_HEADERS): Install `popt.h'. - (noinst_HEADERS): Don't install poptint.h and findme.h. - * popt.c: New file. From the POPT package. Replacement for - argp/getopt. - * poptparse.c: Likewise. - * popthelp.c: Likewise. - * poptconfig.c: Likewise. - * findme.c: Likewise. - * findme.h: Likewise. - * popt.h: Likewise. - * poptint.h: Likewise. - -1998-09-02 Raja R Harinath <harinath@cs.umn.edu> - - * canonicalize.c (realpath): Remove `weak_alias'. - (canonicalize_file_name): Comment out. - - * gnomesupport.awk: Remove `canonicalize_file_name', and correct - the comment for `realpath'. - -1998-09-02 Martin Baulig <martin@home-of-linux.org> - - * gnomesupport.awk (canonicalize_file_name, realpath): Emit - declarations if required. - - * canonicalize.c (canonicalize_file_name, realpath): New file. - Imported from GLibC 2.0.7. - - * libc-symbols.h: New file. Imported from GLibC 2.0.7. - -1998-08-24 Martin Baulig <martin@home-of-linux.org> - - * gnomesupport.awk: Emit declarations for `setreuid', `setregid' - and `getpagesize' if required (GCC_NEED_DECLARATIONS). - -1998-08-18 Martin Baulig <martin@home-of-linux.org> - - * Makefile.am: Added explicit dependency `error.c: gnomesupport.h'. - - * gnomesupport-fake.h: Include `sys/types.h' to get `size_t' under - FreeBSD. - - * gnomesupport-fake.h: Include `gnomesupport.h' only if we really - `NEED_GNOMESUPPORT_H'. - -1998-08-16 Martin Baulig <martin@home-of-linux.org> - - * Makefile.am (EXTRA_DIST): Added all source and header files that - are in CVS to make sure everything is included in the distribution - no matter which files are used on the build system. - -1998-08-15 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (libgnomesupport_la_SOURCES): List `gnomesupport.h' - here in the hope that it'll ensure that it is built. - -1998-08-05 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (noinst_HEADERS): Add `gnomesupport-fake.h'. - -1998-08-02 Raja R Harinath <harinath@cs.umn.edu> - - * error.c (program_name): Clean up #ifdef logic some more. - (HAVE_STRERROR_R): Step on implementation namespace only if _LIBC. - -1998-07-30 Martin Baulig <martin@home-of-linux.org> - - * error.c: Making weak alias `__error' and `__error_at_line' - only if `_LIBC' is defined and not if we only - HAVE_PROGRAM_INVOCATION_NAME. - - * gnomesupport-fake.h: Include gnome-argp.h to get - `program_invocation_name'. - -1998-07-29 Raja R Harinath <harinath@cs.umn.edu> - - * gnomesupport-fake.h: New file. Fake in HAVE_* for functions - that are provided by `gnomesupport' rather than `libc'. - * error.c: Include gnomesupport-fake.h. - (program_name): Define to `program_invocation_name' if - HAVE_PROGRAM_INVOCATION_NAME. - -1998-07-29 Martin Baulig <martin@home-of-linux.org> - - * error.c, error.h: New files. Imported from glibc. - - * Makefile.am (supportinclude_HEADERS): Added `error.h'. - -1998-07-17 Martin Baulig <martin@home-of-linux.org> - - * strtol.c, strtoul.c (<ansidecl.h>): Removed. Using - `const' instead of `CONST'. - -1998-07-15 Raja R Harinath <harinath@cs.umn.edu> - - * gnomesupport.awk (gethostname): Emit declaration. - -1998-07-15 Martin Baulig <baulig@Stud.Informatik.uni-trier.de> - - * gnomesupport.awk (memmove strtod strtol strtoul): Emit - declarations. - - * memmove.c: New file. Imported from GNU libiberty. - - * strtod.c, strtol.c, strtoul.c: New files. Imported from - GNU libiberty. - -1998-07-14 Raja R Harinath <harinath@cs.umn.edu> - - * mkstemp.c (<stdint.h>): Systems that don't have `mkstemp' - probably don't have <stdint.h> either. Will fix it with a proper - autoconf test later. - -1998-07-13 Raja R Harinath <harinath@cs.umn.edu> - - * argp.h (ARGP_EI): Define to `extern __inline__', rather that - `extern inline'. Since this code is inside an __OPTIMIZE__ check, - I assume this is GCC, and __inline__ will work. - - * mkstemp.c: New file. - * gnomesupport.awk: Conditionally emit prototype for `mkstemp'. - -Tue Jul 7 00:02:51 1998 Tom Tromey <tromey@cygnus.com> - - * argp-help.c: Don't include <malloc.h>. - -1998-06-11 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (gnomesupport.h): Build with `gnomesupport.awk'. - (CROSS_COMPILING): Remove. - (EXTRA_DIST): Add `gnomesupport.awk'. - - * gnomesupport.awk: New file, to replace `gnomesupport-h.c'. - * gnomesupport-h.c: Removed. Doesn't work well in cross-compiles. - -1998-06-08 Martin Baulig <martin@home-of-linux.org> - - * Makefile.am (gnomesupport-h): When cross-compiling, this - is build using `$(build_CC)' because it needs to run on the - build system. Look at gnome-libs/configure.in to see how to - get `build_CC'. - -Thu May 21 21:21:12 1998 Tom Tromey <tromey@cygnus.com> - - * gnome-argp.h: Unconditionally declare program_invocation_name - and program_invocation_short_name; some systems define these but - don't declare them. - -1998-05-20 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (INCLUDES): Define _GNU_SOURCE. - -1998-05-19 Raja R Harinath <harinath@cs.umn.edu> - - * gnomesupport-h.c (strerror): Emit declaration. - * strerror.c: New file. Imported from GNU libiberty. - -1998-05-19 Martin Baulig <martin@home-of-linux.org> - - * vsnprintf.c (vsnprintf): Changed declaration of this - function on systems defining __STDC__ to avoid clash - with prototype in system header file. - - * vsnprintf.c (snprintf): Moved toward the end of the - file, so that the compiler sees correct declaration for - vsnprintf(). - -1998-05-12 Kjartan Maraas <kmaraas@fib.hl.no> - - * argp-help.c (argp_doc): Backed out previous "fix". :-) - As pointed out it was dead wrong. - -1998-05-09 Kjartan Maraas <kmaraas@fib.hl.no> - - * argp-help.c (argp_doc): Removed a compiler warning. - -1998-04-14 Raja R Harinath <harinath@cs.umn.edu> - - * gnomesupport-h.c (main): Make gnomesupport.h include stddef.h - unconditionally. - -1998-04-13 Raja R Harinath <harinath@cs.umn.edu> - - * scandir.c (<sys/types.h>): Include. - * gnomesupport-h.c (!HAVE_SCANDIR): Do all the `dirent' wrangling - only if `scandir' is needed. Also, include <sys/types.h> in all - cases. - -1998-04-13 Seth Alves <alves@twitch.cp.domain.net> - - * gnomesupport-h.c (HAVE_DIRENT_H): FreeBSD needs <sys/types.h> - before <dirent.h>. - -1998-04-12 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (supportincludedir): Is now $(pkglibdir)/include. - `gnomesupport.h' is a generated file dependent on the configure - process. So, this seems a good place. The rest of the headers - are also here just because I'm too lazy to maintain two separate - include directories to search in for `libgnomesupport' stuff ;-) - (supportinclude_DATA): New var. Has `gnomesupport.h'. - (BUILT_SOURCES): Generate `gnomesupport.h'. - - * gnomesupport-h.c: New file. Used to generate `gnomesupport.h', - which contains prototypes for many of the functions in - `libgnomesupport'. This method is used to ensure that prototypes - appear only for those functions that are provided by - `libgnomesupport'. - - * scandir.c (alphasort): New utility function. - -1998-04-08 Raja R Harinath <harinath@cs.umn.edu> - - * scandir.c: Import from GNU libc. - Remove assumptions that this file is compiled inside GLIBC. - Here are the ChangeLog entries when I imported it originally into - `gwp': - - 1998-02-08 Raja R Harinath <harinath@cs.umn.edu> - * scandir.c (scandir): Revert change of `1998-02-07'. - Don't use d_reclen, but fix the expression used to - figure out the length. - - 1998-02-07 Raja R Harinath <harinath@cs.umn.edu> - * scandir.c (scandir): Use `d_reclen' field to get length - of record. - - 1998-02-06 Raja R Harinath <harinath@cs.umn.edu> - * scandir.c: New file. Replacement function copied from - glibc, edited to not step on implementation namespace. - -1998-03-28 Raja R Harinath <harinath@cs.umn.edu> - - * vasprintf.c (int_vasprintf): Imported from GNU libit-0.4. - Applied a change that appears in `libiberty'. - -Fri Mar 13 21:30:34 1998 Tom Tromey <tromey@cygnus.com> - - * argp.texi: Imported from glibc. - * Makefile.am (EXTRA_DIST): Added argp.texi. - -1998-03-12 Raja R Harinath <harinath@cs.umn.edu> - - * Makefile.am (noinst_HEADERS): Don't install argp-fmtstream.h and - argp-namefrob.h. They are used only to compile `argp' and not for - general usage. - -1998-03-11 Raja R Harinath <harinath@cs.umn.edu> - - * getopt.h: Don't mention getopt() for C++. (Local fix). - - * vsnprintf.c: Actually fill it in. It is from - <URL:http://theos.com/~deraadt/snprintf.c>, with one small fix to - actually make it compile. - -1998-03-09 Raja R Harinath <harinath@cs.umn.edu> - - * easy-vsnprintf.c: New file. Provides (v)snprintf as simple - wrappers to `__vsnprintf'. - * vsnprintf.c: New file. Empty for now. - -Sun Mar 8 17:13:33 1998 Tom Tromey <tromey@cygnus.com> - - * Makefile.am: Rewrote. Library now named libgnomesupport, now - installed if Gnome support code is built. - -Sat Mar 7 00:03:26 1998 Tom Tromey <tromey@cygnus.com> - - * gnome-argp.h (__mempcpy): New define. - - * strnlen.c: New file from glibc; needed by strndup.c. - -Fri Mar 6 20:10:55 1998 Tom Tromey <tromey@cygnus.com> - - * argp-fmtstream.h (__attribute__): Define unless using gcc. - * argp.h (__attribute__): Define unless using gcc. - - * argp-help.c, argp-parse.c, argp.h: Imported new versions from - glibc, while preserving local changes. - -Wed Mar 4 00:58:27 1998 Tom Tromey <tromey@cygnus.com> - - * Makefile.am (libsupport_a_SOURCES): Added gnome-argp.c. - * gnome-argp.c: New file. - - * argp-parse.c: Include gnome-argp.h. - * argp-help.c: Include gnome-argp.h. - - * README-gnome, gnome-argp.h: New files. - - * argp-ba.c, argp-eexst.c, argp-fmtstream.c, argp-fmtstream.h, - argp-fs-xinl.c, argp-help.c, argp-namefrob.h, argp-parse.c, - argp-pv.c, argp-pvh.c, argp-test.c, argp-xinl.c, argp.h, - strndup.c: New files, imported from glibc. Please use "cvs - import" if you import new versions. - - * Makefile.am (noinst_HEADERS): Added argp-fmtstream.h, - argp-namefrob.h, argp.h, gnome-argp.h. - (EXTRA_DIST): New macro. - -1998-02-18 Raja R Harinath <harinath@cs.umn.edu> - - * strcasecmp.c: New file, copied from `glibc'. Used to provide - replacement `strcasecmp' file. - - diff --git a/support/Makefile.am b/support/Makefile.am deleted file mode 100644 index fae50a87..00000000 --- a/support/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -supportincludedir = $(pkglibdir)/include - -INCLUDES = -D_GNU_SOURCE - -lib_LTLIBRARIES = libgnomesupport.la - -supportinclude_HEADERS = gnome-argp.h getopt.h long-options.h argp.h error.h - -# it is in _DATA since we don't want `gnomesupport.h' to be part of -# the distributed `.tar.gz' file -supportinclude_DATA = gnomesupport.h - -# These are internal headers: they are used only when compiling and -# should not be installed -noinst_HEADERS = argp-fmtstream.h argp-namefrob.h gnomesupport-fake.h \ - findme.h poptint.h - -# Hmm... should we move `error.h' here. -include_HEADERS = popt-gnome.h - -popt_sources = findme.c poptconfig.c poptparse.c popt.c popthelp.c -other_sources = long-options.c gnome-argp.c - -libgnomesupport_la_SOURCES = gnomesupport.h $(popt_sources) $(other_sources) -libgnomesupport_la_LIBADD = @LTLIBOBJS@ -libgnomesupport_la_LDFLAGS = -version-info 0:0:0 - -BUILT_SOURCES = gnomesupport.h - -error.c: gnomesupport.h - -gnomesupport.h: gnomesupport.awk $(top_builddir)/config.h - $(AWK) -f $(srcdir)/gnomesupport.awk < $(top_builddir)/config.h > gsh-t - mv gsh-t gnomesupport.h - -EXTRA_DIST = gnomesupport.awk README-gnome easy-vsnprintf.c diff --git a/support/README-gnome b/support/README-gnome deleted file mode 100644 index b2f3101a..00000000 --- a/support/README-gnome +++ /dev/null @@ -1,92 +0,0 @@ -Note to Gnome hackers: - -Some files in this directory are taken verbatim from glibc. -Do not modify them. If you find a bug, report it as you would any -glibc bug. - -When updating the glibc files in the master Gnome repository, be sure -to use "cvs import". That will ensure that any local changes are -merged in. - -Yes, there are some minor local changes. Hopefully these will be -sorted out with the glibc maintainer before long. - -- Tom Tromey <tromey@cygnus.com> - Wed, Mar 4 1998 - -Notes on CVS import: - -This directory has files from two "vendors". There are, thus, two -vendor branches - - 1.1.1 GNU - 1.1.2 SNPRINTF_de_Raadt - -The files that have "vendor" versions are: - - argp-ba.c GNU - argp-eexst.c GNU - argp-fmtstream.c GNU - argp-fmtstream.h GNU - argp-fs-xinl.c GNU - argp-help.c GNU - argp-namefrob.h GNU - argp-parse.c GNU - argp-pv.c GNU - argp-pvh.c GNU - argp-test.c GNU - argp-xinl.c GNU - argp.h GNU - getopt.c GNU - getopt.h GNU - getopt1.c GNU - strcasecmp.c GNU - strndup.c GNU - strnlen.c GNU - strtok_r.c GNU - vasprintf.c GNU - vsnprintf.c SNPRINTF_de_Raadt - -To find out the list of changes made against a "vendor" revision, you -can say - - cvs diff -r <vendor-branch-tag> - -When any of these files are changed by the vendor, they can be -reimported. At the time of importing, please make sure you use the -correct branch revision and vendor tag. - -So, if you are importing changes to any of the `GNU' files, please use - - cvs import -b 1.1.1 gnome-common/support GNU <new-release-tag> - -If you are importing changes to "SNPRINTF_de_Raadt" files, please use - - cvs import -b 1.1.2 gnome-common/support SNPRINTF_de_Raadt <new-rel-tag> - ^^^^^^^ ^^^^^^^^^^^^^^^^^^^ - | | - Branch revision Vendor Tag - -In other words the "Branch revision" and "Vendor Tag" must agree. - -- Raja R Harinath <harinath@cs.umn.edu> - 1998-03-11 - -Good places to get "support" functions: - -`libgnomesupport' is essentially a `glibc' emulation library, and hence -`glibc' itself is a good source. However, some of the functions cannot -be easily ripped out and put here (esp. any of the stdio-derived -functions). Other places are: - -* libiberty from your friendly Cygnus source distribution, e.g., - binutils, gdb. The only caveat is that these cannot be used drop-in: - you have to remove references to other files in the Cygnus tree &c. - -* libit, which appeared briefly on ftp://alpha.gnu.org - -* Jim Meyering's collection from his `fileutils'/`sh-utils'/`textutils' - packages - -- Raja R Harinath - 1998-03-28 diff --git a/support/argp-ba.c b/support/argp-ba.c deleted file mode 100644 index 5d58cc6c..00000000 --- a/support/argp-ba.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Default definition for ARGP_PROGRAM_BUG_ADDRESS. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* If set by the user program, it should point to string that is the - bug-reporting address for the program. It will be printed by argp_help if - the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help - messages), embedded in a sentence that says something like `Report bugs to - ADDR.'. */ -const char *argp_program_bug_address = 0; diff --git a/support/argp-eexst.c b/support/argp-eexst.c deleted file mode 100644 index 9040058e..00000000 --- a/support/argp-eexst.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Default definition for ARGP_ERR_EXIT_STATUS - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <sysexits.h> - -#include "argp.h" - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - <sysexits.h>. */ -error_t argp_err_exit_status = EX_USAGE; diff --git a/support/argp-fmtstream.c b/support/argp-fmtstream.c deleted file mode 100644 index 0c9b3118..00000000 --- a/support/argp-fmtstream.c +++ /dev/null @@ -1,382 +0,0 @@ -/* Word-wrapping and line-truncating streams - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <stdarg.h> -#include <ctype.h> - -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - -#ifndef ARGP_FMTSTREAM_USE_LINEWRAP - -#ifndef isblank -#define isblank(ch) ((ch)==' ' || (ch)=='\t') -#endif - -#define INIT_BUF_SIZE 200 -#define PRINTF_SIZE_GUESS 150 - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -argp_fmtstream_t -__argp_make_fmtstream (FILE *stream, - size_t lmargin, size_t rmargin, ssize_t wmargin) -{ - argp_fmtstream_t fs = malloc (sizeof (struct argp_fmtstream)); - if (fs) - { - fs->stream = stream; - - fs->lmargin = lmargin; - fs->rmargin = rmargin; - fs->wmargin = wmargin; - fs->point_col = 0; - fs->point_offs = 0; - - fs->buf = malloc (INIT_BUF_SIZE); - if (! fs->buf) - { - free (fs); - fs = 0; - } - else - { - fs->p = fs->buf; - fs->end = fs->buf + INIT_BUF_SIZE; - } - } - - return fs; -} -#ifdef weak_alias -weak_alias (__argp_make_fmtstream, argp_make_fmtstream) -#endif - -/* Flush FS to its stream, and free it (but don't close the stream). */ -void -__argp_fmtstream_free (argp_fmtstream_t fs) -{ - __argp_fmtstream_update (fs); - if (fs->p > fs->buf) - fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream); - free (fs->buf); - free (fs); -} -#ifdef weak_alias -weak_alias (__argp_fmtstream_free, argp_fmtstream_free) -#endif - -/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the - end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ -void -__argp_fmtstream_update (argp_fmtstream_t fs) -{ - char *buf, *nl; - size_t len; - - /* Scan the buffer for newlines. */ - buf = fs->buf + fs->point_offs; - while (buf < fs->p) - { - size_t r; - - if (fs->point_col == 0 && fs->lmargin != 0) - { - /* We are starting a new line. Print spaces to the left margin. */ - const size_t pad = fs->lmargin; - if (fs->p + pad < fs->end) - { - /* We can fit in them in the buffer by moving the - buffer text up and filling in the beginning. */ - memmove (buf + pad, buf, fs->p - buf); - fs->p += pad; /* Compensate for bigger buffer. */ - memset (buf, ' ', pad); /* Fill in the spaces. */ - buf += pad; /* Don't bother searching them. */ - } - else - { - /* No buffer space for spaces. Must flush. */ - size_t i; - for (i = 0; i < pad; i++) - putc (' ', fs->stream); - } - fs->point_col = pad; - } - - len = fs->p - buf; - nl = memchr (buf, '\n', len); - - if (fs->point_col < 0) - fs->point_col = 0; - - if (!nl) - { - /* The buffer ends in a partial line. */ - - if (fs->point_col + len < fs->rmargin) - { - /* The remaining buffer text is a partial line and fits - within the maximum line width. Advance point for the - characters to be written and stop scanning. */ - fs->point_col += len; - break; - } - else - /* Set the end-of-line pointer for the code below to - the end of the buffer. */ - nl = fs->p; - } - else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) - { - /* The buffer contains a full line that fits within the maximum - line width. Reset point and scan the next line. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - - /* This line is too long. */ - r = fs->rmargin - 1; - - if (fs->wmargin < 0) - { - /* Truncate the line by overwriting the excess with the - newline and anything after it in the buffer. */ - if (nl < fs->p) - { - memmove (buf + (r - fs->point_col), nl, fs->p - nl); - fs->p -= buf + (r - fs->point_col) - nl; - /* Reset point for the next line and start scanning it. */ - fs->point_col = 0; - buf += r + 1; /* Skip full line plus \n. */ - } - else - { - /* The buffer ends with a partial line that is beyond the - maximum line width. Advance point for the characters - written, and discard those past the max from the buffer. */ - fs->point_col += len; - fs->p -= fs->point_col - r; - break; - } - } - else - { - /* Do word wrap. Go to the column just past the maximum line - width and scan back for the beginning of the word there. - Then insert a line break. */ - - char *p, *nextline; - int i; - - p = buf + (r + 1 - fs->point_col); - while (p >= buf && !isblank (*p)) - --p; - nextline = p + 1; /* This will begin the next line. */ - - if (nextline > buf) - { - /* Swallow separating blanks. */ - if (p > buf) - do - --p; - while (p > buf && isblank (*p)); - nl = p + 1; /* The newline will replace the first blank. */ - } - else - { - /* A single word that is greater than the maximum line width. - Oh well. Put it on an overlong line by itself. */ - p = buf + (r + 1 - fs->point_col); - /* Find the end of the long word. */ - do - ++p; - while (p < nl && !isblank (*p)); - if (p == nl) - { - /* It already ends a line. No fussing required. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - /* We will move the newline to replace the first blank. */ - nl = p; - /* Swallow separating blanks. */ - do - ++p; - while (isblank (*p)); - /* The next line will start here. */ - nextline = p; - } - - /* Note: There are a bunch of tests below for - NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall - at the end of the buffer, and NEXTLINE is in fact empty (and so - we need not be careful to maintain its contents). */ - - if (nextline == buf + len + 1 - ? fs->end - nl < fs->wmargin + 1 - : nextline - (nl + 1) < fs->wmargin) - /* The margin needs more blanks than we removed. */ - if (fs->end - fs->p > fs->wmargin + 1) - /* Make some space for them. */ - { - size_t mv = fs->p - nextline; - memmove (nl + 1 + fs->wmargin, nextline, mv); - nextline = nl + 1 + fs->wmargin; - len = nextline + mv - buf; - *nl++ = '\n'; - } - else - /* Output the first line so we can use the space. */ - { - if (nl > fs->buf) - fwrite (fs->buf, 1, nl - fs->buf, fs->stream); - putc ('\n', fs->stream); - len += buf - fs->buf; - nl = buf = fs->buf; - } - else - /* We can fit the newline and blanks in before - the next word. */ - *nl++ = '\n'; - - if (nextline - nl >= fs->wmargin - || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) - /* Add blanks up to the wrap margin column. */ - for (i = 0; i < fs->wmargin; ++i) - *nl++ = ' '; - else - for (i = 0; i < fs->wmargin; ++i) - putc (' ', fs->stream); - - /* Copy the tail of the original buffer into the current buffer - position. */ - if (nl < nextline) - memmove (nl, nextline, buf + len - nextline); - len -= nextline - buf; - - /* Continue the scan on the remaining lines in the buffer. */ - buf = nl; - - /* Restore bufp to include all the remaining text. */ - fs->p = nl + len; - - /* Reset the counter of what has been output this line. If wmargin - is 0, we want to avoid the lmargin getting added, so we set - point_col to a magic value of -1 in that case. */ - fs->point_col = fs->wmargin ? fs->wmargin : -1; - } - } - - /* Remember that we've scanned as far as the end of the buffer. */ - fs->point_offs = fs->p - fs->buf; -} - -/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by - growing the buffer, or by flushing it. True is returned iff we succeed. */ -int -__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) -{ - if ((size_t) (fs->end - fs->p) < amount) - { - ssize_t wrote; - - /* Flush FS's buffer. */ - __argp_fmtstream_update (fs); - - wrote = fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream); - if (wrote == fs->p - fs->buf) - { - fs->p = fs->buf; - fs->point_offs = 0; - } - else - { - fs->p -= wrote; - fs->point_offs -= wrote; - memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); - return 0; - } - - if ((size_t) (fs->end - fs->buf) < amount) - /* Gotta grow the buffer. */ - { - size_t new_size = fs->end - fs->buf + amount; - char *new_buf = realloc (fs->buf, new_size); - - if (! new_buf) - { - __set_errno (ENOMEM); - return 0; - } - - fs->buf = new_buf; - fs->end = new_buf + new_size; - fs->p = fs->buf; - } - } - - return 1; -} - -ssize_t -__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...) -{ - int out; - size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */ - - do - { - va_list args; - - if (! __argp_fmtstream_ensure (fs, size_guess)) - return -1; - size_guess += size_guess; - - va_start (args, fmt); - out = __vsnprintf (fs->p, fs->end - fs->p, fmt, args); - va_end (args); - } - while (out == -1); - - fs->p += out; - - return out; -} -#ifdef weak_alias -weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf) -#endif - -#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */ diff --git a/support/argp-fmtstream.h b/support/argp-fmtstream.h deleted file mode 100644 index 46184c16..00000000 --- a/support/argp-fmtstream.h +++ /dev/null @@ -1,302 +0,0 @@ -/* Word-wrapping and line-truncating streams. - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. If the system does have it, it is just a wrapper for - that. This header file is only used internally while compiling argp, and - shouldn't be installed. */ - -#ifndef _ARGP_FMTSTREAM_H -#define _ARGP_FMTSTREAM_H - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -/* For Gnome only: don't assume gcc. */ -#ifndef __GNUC__ -#define __attribute__(X) -#endif - -#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \ - || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)) -/* line_wrap_stream is available, so use that. */ -#define ARGP_FMTSTREAM_USE_LINEWRAP -#endif - -#ifdef ARGP_FMTSTREAM_USE_LINEWRAP -/* Just be a simple wrapper for line_wrap_stream; the semantics are - *slightly* different, as line_wrap_stream doesn't actually make a new - object, it just modifies the given stream (reversibly) to do - line-wrapping. Since we control who uses this code, it doesn't matter. */ - -#include <linewrap.h> - -typedef FILE *argp_fmtstream_t; - -#define argp_make_fmtstream line_wrap_stream -#define __argp_make_fmtstream line_wrap_stream -#define argp_fmtstream_free line_unwrap_stream -#define __argp_fmtstream_free line_unwrap_stream - -#define __argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define __argp_fmtstream_puts(fs,str) fputs(str,fs) -#define argp_fmtstream_puts(fs,str) fputs(str,fs) -#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define __argp_fmtstream_printf fprintf -#define argp_fmtstream_printf fprintf - -#define __argp_fmtstream_lmargin line_wrap_lmargin -#define argp_fmtstream_lmargin line_wrap_lmargin -#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define __argp_fmtstream_rmargin line_wrap_rmargin -#define argp_fmtstream_rmargin line_wrap_rmargin -#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define __argp_fmtstream_wmargin line_wrap_wmargin -#define argp_fmtstream_wmargin line_wrap_wmargin -#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define __argp_fmtstream_point line_wrap_point -#define argp_fmtstream_point line_wrap_point - -#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ -/* Guess we have to define our own version. */ - -#ifndef __const -#define __const const -#endif - -struct argp_fmtstream -{ - FILE *stream; /* The stream we're outputting to. */ - - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ - - /* Point in buffer to which we've processed for wrapping, but not output. */ - size_t point_offs; - /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ - ssize_t point_col; - - char *buf; /* Output buffer. */ - char *p; /* Current end of text in BUF. */ - char *end; /* Absolute end of BUF. */ -}; - -typedef struct argp_fmtstream *argp_fmtstream_t; - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); -extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); - -/* Flush __FS to its stream, and free it (but don't close the stream). */ -extern void __argp_fmtstream_free (argp_fmtstream_t __fs); -extern void argp_fmtstream_free (argp_fmtstream_t __fs); - -extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); -extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); - -extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); -extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); - -extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); -extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); - -extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); -extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); - -/* Access macros for various bits of state. */ -#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin) -#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin) -#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin) -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* Set __FS's left margin to LMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); -extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); -extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); - -/* Set __FS's wrap margin to __WMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); -extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); - -/* Return the column number of the current output point in __FS. */ -extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); -extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs); - -/* Internal routines. */ -extern void _argp_fmtstream_update (argp_fmtstream_t __fs); -extern void __argp_fmtstream_update (argp_fmtstream_t __fs); -extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); -extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); - -#ifdef __OPTIMIZE__ -/* Inline versions of above routines. */ - -#if !_LIBC -#define __argp_fmtstream_putc argp_fmtstream_putc -#define __argp_fmtstream_puts argp_fmtstream_puts -#define __argp_fmtstream_write argp_fmtstream_write -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#define __argp_fmtstream_point argp_fmtstream_point -#define __argp_fmtstream_update _argp_fmtstream_update -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#endif - -#ifndef ARGP_FS_EI -#define ARGP_FS_EI extern inline -#endif - -ARGP_FS_EI size_t -__argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len) -{ - if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) - { - memcpy (__fs->p, __str, __len); - __fs->p += __len; - return __len; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str) -{ - size_t __len = strlen (__str); - if (__len) - { - size_t __wrote = __argp_fmtstream_write (__fs, __str, __len); - return __wrote == __len ? 0 : -1; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch) -{ - if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1)) - return *__fs->p++ = __ch; - else - return EOF; -} - -/* Set __FS's left margin to __LMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->lmargin; - __fs->lmargin = __lmargin; - return __old; -} - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->rmargin; - __fs->rmargin = __rmargin; - return __old; -} - -/* Set FS's wrap margin to __WMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->wmargin; - __fs->wmargin = __wmargin; - return __old; -} - -/* Return the column number of the current output point in __FS. */ -ARGP_FS_EI size_t -__argp_fmtstream_point (argp_fmtstream_t __fs) -{ - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - return __fs->point_col >= 0 ? __fs->point_col : 0; -} - -#if !_LIBC -#undef __argp_fmtstream_putc -#undef __argp_fmtstream_puts -#undef __argp_fmtstream_write -#undef __argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#undef __argp_fmtstream_update -#undef __argp_fmtstream_ensure -#endif - -#endif /* __OPTIMIZE__ */ - -#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */ - -#endif /* argp-fmtstream.h */ diff --git a/support/argp-fs-xinl.c b/support/argp-fs-xinl.c deleted file mode 100644 index 94d5f589..00000000 --- a/support/argp-fs-xinl.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Real definitions for extern inline functions in argp-fmtstream.h - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#define ARGP_FS_EI -#undef __OPTIMIZE__ -#define __OPTIMIZE__ -#include "argp-fmtstream.h" - -/* Add weak aliases. */ -#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias) - -weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc) -weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts) -weak_alias (__argp_fmtstream_write, argp_fmtstream_write) -weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin) -weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin) -weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin) -weak_alias (__argp_fmtstream_point, argp_fmtstream_point) - -#endif diff --git a/support/argp-help.c b/support/argp-help.c deleted file mode 100644 index 6c7f5712..00000000 --- a/support/argp-help.c +++ /dev/null @@ -1,1732 +0,0 @@ -/* Hierarchial argument parsing help output - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <stdarg.h> -#include <ctype.h> - -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ -#ifdef HAVE_LIBINTL_H -# include <libintl.h> -#else -# define dgettext(domain, msgid) (msgid) -# define gettext(msgid) (msgid) -#endif -#endif - -#include "argp.h" -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - -/* This is for Gnome only. */ -#include "gnome-argp.h" - - -/* User-selectable (using an environment variable) formatting parameters. - - These may be specified in an environment variable called `ARGP_HELP_FMT', - with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2 - Where VALn must be a positive integer. The list of variables is in the - UPARAM_NAMES vector, below. */ - -/* Default parameters. */ -#define DUP_ARGS 0 /* True if option argument can be duplicated. */ -#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ -#define SHORT_OPT_COL 2 /* column in which short options start */ -#define LONG_OPT_COL 6 /* column in which long options start */ -#define DOC_OPT_COL 2 /* column in which doc options start */ -#define OPT_DOC_COL 29 /* column in which option text starts */ -#define HEADER_COL 1 /* column in which group headers are printed */ -#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ -#define RMARGIN 79 /* right margin used for wrapping */ - -/* User-selectable (using an environment variable) formatting parameters. - They must all be of type `int' for the parsing code to work. */ -struct uparams -{ - /* If true, arguments for an option are shown with both short and long - options, even when a given option has both, e.g. `-x ARG, --longx=ARG'. - If false, then if an option has both, the argument is only shown with - the long one, e.g., `-x, --longx=ARG', and a message indicating that - this really means both is printed below the options. */ - int dup_args; - - /* This is true if when DUP_ARGS is false, and some duplicate arguments have - been suppressed, an explanatory message should be printed. */ - int dup_args_note; - - /* Various output columns. */ - int short_opt_col; - int long_opt_col; - int doc_opt_col; - int opt_doc_col; - int header_col; - int usage_indent; - int rmargin; - - int valid; /* True when the values in here are valid. */ -}; - -/* This is a global variable, as user options are only ever read once. */ -static struct uparams uparams = { - DUP_ARGS, DUP_ARGS_NOTE, - SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL, - USAGE_INDENT, RMARGIN, - 0 -}; - -/* A particular uparam, and what the user name is. */ -struct uparam_name -{ - const char *name; /* User name. */ - int is_bool; /* Whether it's `boolean'. */ - size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ -}; - -/* The name-field mappings we know about. */ -static const struct uparam_name uparam_names[] = -{ - { "dup-args", 1, offsetof (struct uparams, dup_args) }, - { "dup-args-note", 1, offsetof (struct uparams, dup_args_note) }, - { "short-opt-col", 0, offsetof (struct uparams, short_opt_col) }, - { "long-opt-col", 0, offsetof (struct uparams, long_opt_col) }, - { "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) }, - { "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) }, - { "header-col", 0, offsetof (struct uparams, header_col) }, - { "usage-indent", 0, offsetof (struct uparams, usage_indent) }, - { "rmargin", 0, offsetof (struct uparams, rmargin) }, - { 0 } -}; - -/* Read user options from the environment, and fill in UPARAMS appropiately. */ -static void -fill_in_uparams (const struct argp_state *state) -{ - const char *var = getenv ("ARGP_HELP_FMT"); - -#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0); - - if (var) - /* Parse var. */ - while (*var) - { - SKIPWS (var); - - if (isalpha (*var)) - { - size_t var_len; - const struct uparam_name *un; - int unspec = 0, val = 0; - const char *arg = var; - - while (isalnum (*arg) || *arg == '-' || *arg == '_') - arg++; - var_len = arg - var; - - SKIPWS (arg); - - if (*arg == '\0' || *arg == ',') - unspec = 1; - else if (*arg == '=') - { - arg++; - SKIPWS (arg); - } - - if (unspec) - if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') - { - val = 0; - var += 3; - var_len -= 3; - } - else - val = 1; - else if (isdigit (*arg)) - { - val = atoi (arg); - while (isdigit (*arg)) - arg++; - SKIPWS (arg); - } - - for (un = uparam_names; un->name; un++) - if (strlen (un->name) == var_len - && strncmp (var, un->name, var_len) == 0) - { - if (unspec && !un->is_bool) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ -%.*s: ARGP_HELP_FMT parameter requires a value"), - (int) var_len, var); - else - *(int *)((char *)&uparams + un->uparams_offs) = val; - break; - } - if (! un->name) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ -%.*s: Unknown ARGP_HELP_FMT parameter"), - (int) var_len, var); - - var = arg; - if (*var == ',') - var++; - } - else if (*var) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "Garbage in ARGP_HELP_FMT: %s"), var); - break; - } - } -} - -/* Returns true if OPT hasn't been marked invisible. Visibility only affects - whether OPT is displayed or used in sorting, not option shadowing. */ -#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN)) - -/* Returns true if OPT is an alias for an earlier option. */ -#define oalias(opt) ((opt)->flags & OPTION_ALIAS) - -/* Returns true if OPT is an documentation-only entry. */ -#define odoc(opt) ((opt)->flags & OPTION_DOC) - -/* Returns true if OPT is the end-of-list marker for a list of options. */ -#define oend(opt) __option_is_end (opt) - -/* Returns true if OPT has a short option. */ -#define oshort(opt) __option_is_short (opt) - -/* - The help format for a particular option is like: - - -xARG, -yARG, --long1=ARG, --long2=ARG Documentation... - - Where ARG will be omitted if there's no argument, for this option, or - will be surrounded by "[" and "]" appropiately if the argument is - optional. The documentation string is word-wrapped appropiately, and if - the list of options is long enough, it will be started on a separate line. - If there are no short options for a given option, the first long option is - indented slighly in a way that's supposed to make most long options appear - to be in a separate column. - - For example, the following output (from ps): - - -p PID, --pid=PID List the process PID - --pgrp=PGRP List processes in the process group PGRP - -P, -x, --no-parent Include processes without parents - -Q, --all-fields Don't elide unusable fields (normally if there's - some reason ps can't print a field for any - process, it's removed from the output entirely) - -r, --reverse, --gratuitously-long-reverse-option - Reverse the order of any sort - --session[=SID] Add the processes from the session SID (which - defaults to the sid of the current process) - - Here are some more options: - -f ZOT, --foonly=ZOT Glork a foonly - -z, --zaza Snit a zar - - -?, --help Give this help list - --usage Give a short usage message - -V, --version Print program version - - The struct argp_option array for the above could look like: - - { - {"pid", 'p', "PID", 0, "List the process PID"}, - {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, - {0, 'x', 0, OPTION_ALIAS}, - {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" - " if there's some reason ps can't" - " print a field for any process, it's" - " removed from the output entirely)" }, - {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, - {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, - {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL, - "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, - - {0,0,0,0, "Here are some more options:"}, - {"foonly", 'f', "ZOT", 0, "Glork a foonly"}, - {"zaza", 'z', 0, 0, "Snit a zar"}, - - {0} - } - - Note that the last three options are automatically supplied by argp_parse, - unless you tell it not to with ARGP_NO_HELP. - -*/ - -/* Returns true if CH occurs between BEG and END. */ -static int -find_char (char ch, char *beg, char *end) -{ - while (beg < end) - if (*beg == ch) - return 1; - else - beg++; - return 0; -} - -struct hol_cluster; /* fwd decl */ - -struct hol_entry -{ - /* First option. */ - const struct argp_option *opt; - /* Number of options (including aliases). */ - unsigned num; - - /* A pointers into the HOL's short_options field, to the first short option - letter for this entry. The order of the characters following this point - corresponds to the order of options pointed to by OPT, and there are at - most NUM. A short option recorded in a option following OPT is only - valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's - probably been shadowed by some other entry). */ - char *short_options; - - /* Entries are sorted by their group first, in the order: - 1, 2, ..., n, 0, -m, ..., -2, -1 - and then alphabetically within each group. The default is 0. */ - int group; - - /* The cluster of options this entry belongs to, or 0 if none. */ - struct hol_cluster *cluster; - - /* The argp from which this option came. */ - const struct argp *argp; -}; - -/* A cluster of entries to reflect the argp tree structure. */ -struct hol_cluster -{ - /* A descriptive header printed before options in this cluster. */ - const char *header; - - /* Used to order clusters within the same group with the same parent, - according to the order in which they occured in the parent argp's child - list. */ - int index; - - /* How to sort this cluster with respect to options and other clusters at the - same depth (clusters always follow options in the same group). */ - int group; - - /* The cluster to which this cluster belongs, or 0 if it's at the base - level. */ - struct hol_cluster *parent; - - /* The argp from which this cluster is (eventually) derived. */ - const struct argp *argp; - - /* The distance this cluster is from the root. */ - int depth; - - /* Clusters in a given hol are kept in a linked list, to make freeing them - possible. */ - struct hol_cluster *next; -}; - -/* A list of options for help. */ -struct hol -{ - /* An array of hol_entry's. */ - struct hol_entry *entries; - /* The number of entries in this hol. If this field is zero, the others - are undefined. */ - unsigned num_entries; - - /* A string containing all short options in this HOL. Each entry contains - pointers into this string, so the order can't be messed with blindly. */ - char *short_options; - - /* Clusters of entries in this hol. */ - struct hol_cluster *clusters; -}; - -/* Create a struct hol from the options in ARGP. CLUSTER is the - hol_cluster in which these entries occur, or 0, if at the root. */ -static struct hol * -make_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - char *so; - const struct argp_option *o; - const struct argp_option *opts = argp->options; - struct hol_entry *entry; - unsigned num_short_options = 0; - struct hol *hol = malloc (sizeof (struct hol)); - - assert (hol); - - hol->num_entries = 0; - hol->clusters = 0; - - if (opts) - { - int cur_group = 0; - - /* The first option must not be an alias. */ - assert (! oalias (opts)); - - /* Calculate the space needed. */ - for (o = opts; ! oend (o); o++) - { - if (! oalias (o)) - hol->num_entries++; - if (oshort (o)) - num_short_options++; /* This is an upper bound. */ - } - - hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries); - hol->short_options = malloc (num_short_options + 1); - - assert (hol->entries && hol->short_options); - - /* Fill in the entries. */ - so = hol->short_options; - for (o = opts, entry = hol->entries; ! oend (o); entry++) - { - entry->opt = o; - entry->num = 0; - entry->short_options = so; - entry->group = cur_group = - o->group - ? o->group - : ((!o->name && !o->key) - ? cur_group + 1 - : cur_group); - entry->cluster = cluster; - entry->argp = argp; - - do - { - entry->num++; - if (oshort (o) && ! find_char (o->key, hol->short_options, so)) - /* O has a valid short option which hasn't already been used.*/ - *so++ = o->key; - o++; - } - while (! oend (o) && oalias (o)); - } - *so = '\0'; /* null terminated so we can find the length */ - } - - return hol; -} - -/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the - associated argp child list entry), INDEX, and PARENT, and return a pointer - to it. ARGP is the argp that this cluster results from. */ -static struct hol_cluster * -hol_add_cluster (struct hol *hol, int group, const char *header, int index, - struct hol_cluster *parent, const struct argp *argp) -{ - struct hol_cluster *cl = malloc (sizeof (struct hol_cluster)); - if (cl) - { - cl->group = group; - cl->header = header; - - cl->index = index; - cl->parent = parent; - cl->argp = argp; - cl->depth = parent ? parent->depth + 1 : 0; - - cl->next = hol->clusters; - hol->clusters = cl; - } - return cl; -} - -/* Free HOL and any resources it uses. */ -static void -hol_free (struct hol *hol) -{ - struct hol_cluster *cl = hol->clusters; - - while (cl) - { - struct hol_cluster *next = cl->next; - free (cl); - cl = next; - } - - if (hol->num_entries > 0) - { - free (hol->entries); - free (hol->short_options); - } - - free (hol); -} - -static inline int -hol_entry_short_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - char *so = entry->short_options; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (oshort (opt) && *so == opt->key) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - so++; - } - - return val; -} - -static inline int -hol_entry_long_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (opt->name) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - } - - return val; -} - -/* Iterator that returns true for the first short option. */ -static inline int -until_short (const struct argp_option *opt, const struct argp_option *real, - const char *domain, void *cookie) -{ - return oshort (opt) ? opt->key : 0; -} - -/* Returns the first valid short option in ENTRY, or 0 if there is none. */ -static char -hol_entry_first_short (const struct hol_entry *entry) -{ - return hol_entry_short_iterate (entry, until_short, - entry->argp->argp_domain, 0); -} - -/* Returns the first valid long option in ENTRY, or 0 if there is none. */ -static const char * -hol_entry_first_long (const struct hol_entry *entry) -{ - const struct argp_option *opt; - unsigned num; - for (opt = entry->opt, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - return opt->name; - return 0; -} - -/* Returns the entry in HOL with the long option name NAME, or 0 if there is - none. */ -static struct hol_entry * -hol_find_entry (struct hol *hol, const char *name) -{ - struct hol_entry *entry = hol->entries; - unsigned num_entries = hol->num_entries; - - while (num_entries-- > 0) - { - const struct argp_option *opt = entry->opt; - unsigned num_opts = entry->num; - - while (num_opts-- > 0) - if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) - return entry; - else - opt++; - - entry++; - } - - return 0; -} - -/* If an entry with the long option NAME occurs in HOL, set it's special - sort position to GROUP. */ -static void -hol_set_group (struct hol *hol, const char *name, int group) -{ - struct hol_entry *entry = hol_find_entry (hol, name); - if (entry) - entry->group = group; -} - -/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1. - EQ is what to return if GROUP1 and GROUP2 are the same. */ -static int -group_cmp (int group1, int group2, int eq) -{ - if (group1 == group2) - return eq; - else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0)) - return group1 - group2; - else - return group2 - group1; -} - -/* Compare clusters CL1 & CL2 by the order that they should appear in - output. */ -static int -hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2) -{ - /* If one cluster is deeper than the other, use its ancestor at the same - level, so that finding the common ancestor is straightforward. */ - while (cl1->depth < cl2->depth) - cl1 = cl1->parent; - while (cl2->depth < cl1->depth) - cl2 = cl2->parent; - - /* Now reduce both clusters to their ancestors at the point where both have - a common parent; these can be directly compared. */ - while (cl1->parent != cl2->parent) - cl1 = cl1->parent, cl2 = cl2->parent; - - return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index); -} - -/* Return the ancestor of CL that's just below the root (i.e., has a parent - of 0). */ -static struct hol_cluster * -hol_cluster_base (struct hol_cluster *cl) -{ - while (cl->parent) - cl = cl->parent; - return cl; -} - -/* Return true if CL1 is a child of CL2. */ -static int -hol_cluster_is_child (const struct hol_cluster *cl1, - const struct hol_cluster *cl2) -{ - while (cl1 && cl1 != cl2) - cl1 = cl1->parent; - return cl1 == cl2; -} - -/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail - that should be used for comparisons, and returns true iff it should be - treated as a non-option. */ -static int -canon_doc_option (const char **name) -{ - int non_opt; - /* Skip initial whitespace. */ - while (isspace (**name)) - (*name)++; - /* Decide whether this looks like an option (leading `-') or not. */ - non_opt = (**name != '-'); - /* Skip until part of name used for sorting. */ - while (**name && !isalnum (**name)) - (*name)++; - return non_opt; -} - -/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help - listing. */ -static int -hol_entry_cmp (const struct hol_entry *entry1, - const struct hol_entry *entry2) -{ - /* The group numbers by which the entries should be ordered; if either is - in a cluster, then this is just the group within the cluster. */ - int group1 = entry1->group, group2 = entry2->group; - - if (entry1->cluster != entry2->cluster) - /* The entries are not within the same cluster, so we can't compare them - directly, we have to use the appropiate clustering level too. */ - if (! entry1->cluster) - /* ENTRY1 is at the `base level', not in a cluster, so we have to - compare it's group number with that of the base cluster in which - ENTRY2 resides. Note that if they're in the same group, the - clustered option always comes laster. */ - return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); - else if (! entry2->cluster) - /* Likewise, but ENTRY2's not in a cluster. */ - return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); - else - /* Both entries are in clusters, we can just compare the clusters. */ - return hol_cluster_cmp (entry1->cluster, entry2->cluster); - else if (group1 == group2) - /* The entries are both in the same cluster and group, so compare them - alphabetically. */ - { - int short1 = hol_entry_first_short (entry1); - int short2 = hol_entry_first_short (entry2); - int doc1 = odoc (entry1->opt); - int doc2 = odoc (entry2->opt); - const char *long1 = hol_entry_first_long (entry1); - const char *long2 = hol_entry_first_long (entry2); - - if (doc1) - doc1 = canon_doc_option (&long1); - if (doc2) - doc2 = canon_doc_option (&long2); - - if (doc1 != doc2) - /* `documentation' options always follow normal options (or - documentation options that *look* like normal options). */ - return doc1 - doc2; - else if (!short1 && !short2 && long1 && long2) - /* Only long options. */ - return __strcasecmp (long1, long2); - else - /* Compare short/short, long/short, short/long, using the first - character of long options. Entries without *any* valid - options (such as options with OPTION_HIDDEN set) will be put - first, but as they're not displayed, it doesn't matter where - they are. */ - { - char first1 = short1 ? short1 : long1 ? *long1 : 0; - char first2 = short2 ? short2 : long2 ? *long2 : 0; - int lower_cmp = tolower (first1) - tolower (first2); - /* Compare ignoring case, except when the options are both the - same letter, in which case lower-case always comes first. */ - return lower_cmp ? lower_cmp : first2 - first1; - } - } - else - /* Within the same cluster, but not the same group, so just compare - groups. */ - return group_cmp (group1, group2, 0); -} - -/* Version of hol_entry_cmp with correct signature for qsort. */ -static int -hol_entry_qcmp (const void *entry1_v, const void *entry2_v) -{ - return hol_entry_cmp (entry1_v, entry2_v); -} - -/* Sort HOL by group and alphabetically by option name (with short options - taking precedence over long). Since the sorting is for display purposes - only, the shadowing of options isn't effected. */ -static void -hol_sort (struct hol *hol) -{ - if (hol->num_entries > 0) - qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), - hol_entry_qcmp); -} - -/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow - any in MORE with the same name. */ -static void -hol_append (struct hol *hol, struct hol *more) -{ - struct hol_cluster **cl_end = &hol->clusters; - - /* Steal MORE's cluster list, and add it to the end of HOL's. */ - while (*cl_end) - cl_end = &(*cl_end)->next; - *cl_end = more->clusters; - more->clusters = 0; - - /* Merge entries. */ - if (more->num_entries > 0) - if (hol->num_entries == 0) - { - hol->num_entries = more->num_entries; - hol->entries = more->entries; - hol->short_options = more->short_options; - more->num_entries = 0; /* Mark MORE's fields as invalid. */ - } - else - /* Append the entries in MORE to those in HOL, taking care to only add - non-shadowed SHORT_OPTIONS values. */ - { - unsigned left; - char *so, *more_so; - struct hol_entry *e; - unsigned num_entries = hol->num_entries + more->num_entries; - struct hol_entry *entries = - malloc (num_entries * sizeof (struct hol_entry)); - unsigned hol_so_len = strlen (hol->short_options); - char *short_options = - malloc (hol_so_len + strlen (more->short_options) + 1); - - __mempcpy (__mempcpy (entries, hol->entries, - hol->num_entries * sizeof (struct hol_entry)), - more->entries, - more->num_entries * sizeof (struct hol_entry)); - - __mempcpy (short_options, hol->short_options, hol_so_len); - - /* Fix up the short options pointers from HOL. */ - for (e = entries, left = hol->num_entries; left > 0; e++, left--) - e->short_options += (short_options - hol->short_options); - - /* Now add the short options from MORE, fixing up its entries too. */ - so = short_options + hol_so_len; - more_so = more->short_options; - for (left = more->num_entries; left > 0; e++, left--) - { - int opts_left; - const struct argp_option *opt; - - e->short_options = so; - - for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) - { - int ch = *more_so; - if (oshort (opt) && ch == opt->key) - /* The next short option in MORE_SO, CH, is from OPT. */ - { - if (! find_char (ch, short_options, - short_options + hol_so_len)) - /* The short option CH isn't shadowed by HOL's options, - so add it to the sum. */ - *so++ = ch; - more_so++; - } - } - } - - *so = '\0'; - - free (hol->entries); - free (hol->short_options); - - hol->entries = entries; - hol->num_entries = num_entries; - hol->short_options = short_options; - } - - hol_free (more); -} - -/* Inserts enough spaces to make sure STREAM is at column COL. */ -static void -indent_to (argp_fmtstream_t stream, unsigned col) -{ - int needed = col - __argp_fmtstream_point (stream); - while (needed-- > 0) - __argp_fmtstream_putc (stream, ' '); -} - -/* Output to STREAM either a space, or a newline if there isn't room for at - least ENSURE characters before the right margin. */ -static void -space (argp_fmtstream_t stream, size_t ensure) -{ - if (__argp_fmtstream_point (stream) + ensure - >= __argp_fmtstream_rmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - else - __argp_fmtstream_putc (stream, ' '); -} - -/* If the option REAL has an argument, we print it in using the printf - format REQ_FMT or OPT_FMT depending on whether it's a required or - optional argument. */ -static void -arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, - const char *domain, argp_fmtstream_t stream) -{ - if (real->arg) - if (real->flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, opt_fmt, dgettext (domain, real->arg)); - else - __argp_fmtstream_printf (stream, req_fmt, dgettext (domain, real->arg)); -} - -/* Helper functions for hol_entry_help. */ - -/* State used during the execution of hol_help. */ -struct hol_help_state -{ - /* PREV_ENTRY should contain the previous entry printed, or 0. */ - struct hol_entry *prev_entry; - - /* If an entry is in a different group from the previous one, and SEP_GROUPS - is true, then a blank line will be printed before any output. */ - int sep_groups; - - /* True if a duplicate option argument was suppressed (only ever set if - UPARAMS.dup_args is false). */ - int suppressed_dup_arg; -}; - -/* Some state used while printing a help entry (used to communicate with - helper functions). See the doc for hol_entry_help for more info, as most - of the fields are copied from its arguments. */ -struct pentry_state -{ - const struct hol_entry *entry; - argp_fmtstream_t stream; - struct hol_help_state *hhstate; - - /* True if nothing's been printed so far. */ - int first; - - /* If non-zero, the state that was used to print this help. */ - const struct argp_state *state; -}; - -/* If a user doc filter should be applied to DOC, do so. */ -static const char * -filter_doc (const char *doc, int key, const struct argp *argp, - const struct argp_state *state) -{ - if (argp->help_filter) - /* We must apply a user filter to this output. */ - { - void *input = __argp_input (argp, state); - return (*argp->help_filter) (key, doc, input); - } - else - /* No filter. */ - return doc; -} - -/* Prints STR as a header line, with the margin lines set appropiately, and - notes the fact that groups should be separated with a blank line. ARGP is - the argp that should dictate any user doc filtering to take place. Note - that the previous wrap margin isn't restored, but the left margin is reset - to 0. */ -static void -print_header (const char *str, const struct argp *argp, - struct pentry_state *pest) -{ - const char *tstr = dgettext (argp->argp_domain, str); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); - - if (fstr) - { - if (*fstr) - { - if (pest->hhstate->prev_entry) - /* Precede with a blank line. */ - __argp_fmtstream_putc (pest->stream, '\n'); - indent_to (pest->stream, uparams.header_col); - __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); - __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); - __argp_fmtstream_puts (pest->stream, fstr); - __argp_fmtstream_set_lmargin (pest->stream, 0); - __argp_fmtstream_putc (pest->stream, '\n'); - } - - pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */ - } - - if (fstr != tstr) - free ((char *) fstr); -} - -/* Inserts a comma if this isn't the first item on the line, and then makes - sure we're at least to column COL. If this *is* the first item on a line, - prints any pending whitespace/headers that should precede this line. Also - clears FIRST. */ -static void -comma (unsigned col, struct pentry_state *pest) -{ - if (pest->first) - { - const struct hol_entry *pe = pest->hhstate->prev_entry; - const struct hol_cluster *cl = pest->entry->cluster; - - if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group) - __argp_fmtstream_putc (pest->stream, '\n'); - - if (cl && cl->header && *cl->header - && (!pe - || (pe->cluster != cl - && !hol_cluster_is_child (pe->cluster, cl)))) - /* If we're changing clusters, then this must be the start of the - ENTRY's cluster unless that is an ancestor of the previous one - (in which case we had just popped into a sub-cluster for a bit). - If so, then print the cluster's header line. */ - { - int old_wm = __argp_fmtstream_wmargin (pest->stream); - print_header (cl->header, cl->argp, pest); - __argp_fmtstream_set_wmargin (pest->stream, old_wm); - } - - pest->first = 0; - } - else - __argp_fmtstream_puts (pest->stream, ", "); - - indent_to (pest->stream, col); -} - -/* Print help for ENTRY to STREAM. */ -static void -hol_entry_help (struct hol_entry *entry, const struct argp_state *state, - argp_fmtstream_t stream, struct hol_help_state *hhstate) -{ - unsigned num; - const struct argp_option *real = entry->opt, *opt; - char *so = entry->short_options; - int have_long_opt = 0; /* We have any long options. */ - /* Saved margins. */ - int old_lm = __argp_fmtstream_set_lmargin (stream, 0); - int old_wm = __argp_fmtstream_wmargin (stream); - /* PEST is a state block holding some of our variables that we'd like to - share with helper functions. */ - struct pentry_state pest; - - pest.entry = entry; - pest.stream = stream; - pest.hhstate = hhstate; - pest.first = 1; - pest.state = state; - - - if (! odoc (real)) - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - have_long_opt = 1; - break; - } - - /* First emit short options. */ - __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */ - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (oshort (opt) && opt->key == *so) - /* OPT has a valid (non shadowed) short option. */ - { - if (ovisible (opt)) - { - comma (uparams.short_opt_col, &pest); - __argp_fmtstream_putc (stream, '-'); - __argp_fmtstream_putc (stream, *so); - if (!have_long_opt || uparams.dup_args) - arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - so++; - } - - /* Now, long options. */ - if (odoc (real)) - /* A `documentation' option. */ - { - __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.doc_opt_col, &pest); - /* Calling gettext here isn't quite right, since sorting will - have been done on the original; but documentation options - should be pretty rare anyway... */ - __argp_fmtstream_puts (stream, - dgettext (state->root_argp->argp_domain, - opt->name)); - } - } - else - /* A real long option. */ - { - int first_long_opt = 1; - - __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.long_opt_col, &pest); - __argp_fmtstream_printf (stream, "--%s", opt->name); - if (first_long_opt || uparams.dup_args) - arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, - stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - } - - /* Next, documentation strings. */ - __argp_fmtstream_set_lmargin (stream, 0); - - if (pest.first) - /* Didn't print any switches, what's up? */ - if (!oshort (real) && !real->name) - /* This is a group header, print it nicely. */ - print_header (real->doc, entry->argp, &pest); - else - /* Just a totally shadowed option or null header; print nothing. */ - goto cleanup; /* Just return, after cleaning up. */ - else - { - const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain, - real->doc) : 0; - const char *fstr = filter_doc (tstr, real->key, entry->argp, state); - if (fstr && *fstr) - { - unsigned int col = __argp_fmtstream_point (stream); - - __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); - __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); - - if (col > (unsigned int) (uparams.opt_doc_col + 3)) - __argp_fmtstream_putc (stream, '\n'); - else if (col >= (unsigned int) uparams.opt_doc_col) - __argp_fmtstream_puts (stream, " "); - else - indent_to (stream, uparams.opt_doc_col); - - __argp_fmtstream_puts (stream, fstr); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - - /* Reset the left margin. */ - __argp_fmtstream_set_lmargin (stream, 0); - __argp_fmtstream_putc (stream, '\n'); - } - - hhstate->prev_entry = entry; - -cleanup: - __argp_fmtstream_set_lmargin (stream, old_lm); - __argp_fmtstream_set_wmargin (stream, old_wm); -} - -/* Output a long help message about the options in HOL to STREAM. */ -static void -hol_help (struct hol *hol, const struct argp_state *state, - argp_fmtstream_t stream) -{ - unsigned num; - struct hol_entry *entry; - struct hol_help_state hhstate = { 0, 0, 0 }; - - for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--) - hol_entry_help (entry, state, stream, &hhstate); - - if (hhstate.suppressed_dup_arg && uparams.dup_args_note) - { - const char *tstr = dgettext (state->root_argp->argp_domain, "\ -Mandatory or optional arguments to long options are also mandatory or \ -optional for any corresponding short options."); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, - state ? state->root_argp : 0, state); - if (fstr && *fstr) - { - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, fstr); - __argp_fmtstream_putc (stream, '\n'); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - } -} - -/* Helper functions for hol_usage. */ - -/* If OPT is a short option without an arg, append its key to the string - pointer pointer to by COOKIE, and advance the pointer. */ -static int -add_argless_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - char **snao_end = cookie; - if (!(opt->arg || real->arg) - && !((opt->flags | real->flags) & OPTION_NO_USAGE)) - *(*snao_end)++ = opt->key; - return 0; -} - -/* If OPT is a short option with an arg, output a usage entry for it to the - stream pointed at by COOKIE. */ -static int -usage_argful_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (arg && !(flags & OPTION_NO_USAGE)) - { - arg = dgettext (domain, arg); - - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); - else - { - /* Manually do line wrapping so that it (probably) won't - get wrapped at the embedded space. */ - space (stream, 6 + strlen (arg)); - __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); - } - } - - return 0; -} - -/* Output a usage entry for the long option opt to the stream pointed at by - COOKIE. */ -static int -usage_long_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (! (flags & OPTION_NO_USAGE)) - if (arg) - { - arg = dgettext (domain, arg); - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); - else - __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); - } - else - __argp_fmtstream_printf (stream, " [--%s]", opt->name); - - return 0; -} - -/* Print a short usage description for the arguments in HOL to STREAM. */ -static void -hol_usage (struct hol *hol, argp_fmtstream_t stream) -{ - if (hol->num_entries > 0) - { - unsigned nentries; - struct hol_entry *entry; - char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1); - char *snao_end = short_no_arg_opts; - - /* First we put a list of short options without arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, add_argless_short_opt, - entry->argp->argp_domain, &snao_end); - if (snao_end > short_no_arg_opts) - { - *snao_end++ = 0; - __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); - } - - /* Now a list of short options *with* arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, usage_argful_short_opt, - entry->argp->argp_domain, stream); - - /* Finally, a list of long options (whew!). */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_long_iterate (entry, usage_long_opt, - entry->argp->argp_domain, stream); - } -} - -/* Make a HOL containing all levels of options in ARGP. CLUSTER is the - cluster in which ARGP's entries should be clustered, or 0. */ -static struct hol * -argp_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - const struct argp_child *child = argp->children; - struct hol *hol = make_hol (argp, cluster); - if (child) - while (child->argp) - { - struct hol_cluster *child_cluster = - ((child->group || child->header) - /* Put CHILD->argp within its own cluster. */ - ? hol_add_cluster (hol, child->group, child->header, - child - argp->children, cluster, argp) - /* Just merge it into the parent's cluster. */ - : cluster); - hol_append (hol, argp_hol (child->argp, child_cluster)) ; - child++; - } - return hol; -} - -/* Calculate how many different levels with alternative args strings exist in - ARGP. */ -static size_t -argp_args_levels (const struct argp *argp) -{ - size_t levels = 0; - const struct argp_child *child = argp->children; - - if (argp->args_doc && strchr (argp->args_doc, '\n')) - levels++; - - if (child) - while (child->argp) - levels += argp_args_levels ((child++)->argp); - - return levels; -} - -/* Print all the non-option args documented in ARGP to STREAM. Any output is - preceded by a space. LEVELS is a pointer to a byte vector the length - returned by argp_args_levels; it should be initialized to zero, and - updated by this routine for the next call if ADVANCE is true. True is - returned as long as there are more patterns to output. */ -static int -argp_args_usage (const struct argp *argp, const struct argp_state *state, - char **levels, int advance, argp_fmtstream_t stream) -{ - char *our_level = *levels; - int multiple = 0; - const struct argp_child *child = argp->children; - const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0; - const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); - - if (fdoc) - { - const char *cp = fdoc; - nl = strchr (cp, '\n'); - if (nl) - /* This is a `multi-level' args doc; advance to the correct position - as determined by our state in LEVELS, and update LEVELS. */ - { - int i; - multiple = 1; - for (i = 0; i < *our_level; i++) - cp = nl + 1, nl = strchr (cp, '\n'); - (*levels)++; - } - if (! nl) - nl = cp + strlen (cp); - - /* Manually do line wrapping so that it (probably) won't get wrapped at - any embedded spaces. */ - space (stream, 1 + nl - cp); - - __argp_fmtstream_write (stream, cp, nl - cp); - } - if (fdoc && fdoc != tdoc) - free ((char *)fdoc); /* Free user's modified doc string. */ - - if (child) - while (child->argp) - advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream); - - if (advance && multiple) - /* Need to increment our level. */ - if (*nl) - /* There's more we can do here. */ - { - (*our_level)++; - advance = 0; /* Our parent shouldn't advance also. */ - } - else if (*our_level > 0) - /* We had multiple levels, but used them up; reset to zero. */ - *our_level = 0; - - return !advance; -} - -/* Print the documentation for ARGP to STREAM; if POST is false, then - everything preceeding a `\v' character in the documentation strings (or - the whole string, for those with none) is printed, otherwise, everything - following the `\v' character (nothing for strings without). Each separate - bit of documentation is separated a blank line, and if PRE_BLANK is true, - then the first is as well. If FIRST_ONLY is true, only the first - occurance is output. Returns true if anything was output. */ -static int -argp_doc (const struct argp *argp, const struct argp_state *state, - int post, int pre_blank, int first_only, - argp_fmtstream_t stream) -{ - const char *text; - const char *inp_text; - void *input = 0; - int anything = 0; - size_t inp_text_limit = 0; - const char *doc = dgettext (argp->argp_domain, argp->doc); - const struct argp_child *child = argp->children; - - if (doc) - { - char *vt = strchr (doc, '\v'); - inp_text = post ? (vt ? vt + 1 : 0) : doc; - inp_text_limit = (!post && vt) ? (vt - doc) : 0; - } - else - inp_text = 0; - - if (argp->help_filter) - /* We have to filter the doc strings. */ - { - if (inp_text_limit) - /* Copy INP_TEXT so that it's nul-terminated. */ - inp_text = strndup (inp_text, inp_text_limit); - input = __argp_input (argp, state); - text = - (*argp->help_filter) (post - ? ARGP_KEY_HELP_POST_DOC - : ARGP_KEY_HELP_PRE_DOC, - inp_text, input); - } - else - text = (const char *) inp_text; - - if (text) - { - if (pre_blank) - __argp_fmtstream_putc (stream, '\n'); - - if (text == inp_text && inp_text_limit) - __argp_fmtstream_write (stream, inp_text, inp_text_limit); - else - __argp_fmtstream_puts (stream, text); - - if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - - anything = 1; - } - - if (text && text != inp_text) - free ((char *) text); /* Free TEXT returned from the help filter. */ - if (inp_text && inp_text_limit && argp->help_filter) - free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ - - if (post && argp->help_filter) - /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */ - { - text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input); - if (text) - { - if (anything || pre_blank) - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, text); - free ((char *) text); - if (__argp_fmtstream_point (stream) - > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - anything = 1; - } - } - - if (child) - while (child->argp && !(first_only && anything)) - anything |= - argp_doc ((child++)->argp, state, - post, anything || pre_blank, first_only, - stream); - - return anything; -} - -/* Output a usage message for ARGP to STREAM. If called from - argp_state_help, STATE is the relevent parsing state. FLAGS are from the - set ARGP_HELP_*. NAME is what to use wherever a `program name' is - needed. */ -static void -_help (const struct argp *argp, const struct argp_state *state, FILE *stream, - unsigned flags, char *name) -{ - int anything = 0; /* Whether we've output anything. */ - struct hol *hol = 0; - argp_fmtstream_t fs; - - if (! stream) - return; - - if (! uparams.valid) - fill_in_uparams (state); - - fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0); - if (! fs) - return; - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG)) - { - hol = argp_hol (argp, 0); - - /* If present, these options always come last. */ - hol_set_group (hol, "help", -1); - hol_set_group (hol, "version", -1); - - hol_sort (hol); - } - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE)) - /* Print a short `Usage:' message. */ - { - int first_pattern = 1, more_patterns; - size_t num_pattern_levels = argp_args_levels (argp); - char *pattern_levels = alloca (num_pattern_levels); - - memset (pattern_levels, 0, num_pattern_levels); - - do - { - int old_lm; - int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); - char *levels = pattern_levels; - - if (first_pattern) - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, "Usage:"), - name); - else - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, " or: "), - name); - - /* We set the lmargin as well as the wmargin, because hol_usage - manually wraps options with newline to avoid annoying breaks. */ - old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); - - if (flags & ARGP_HELP_SHORT_USAGE) - /* Just show where the options go. */ - { - if (hol->num_entries > 0) - __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, - " [OPTION...]")); - } - else - /* Actually print the options. */ - { - hol_usage (hol, fs); - flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ - } - - more_patterns = argp_args_usage (argp, state, &levels, 1, fs); - - __argp_fmtstream_set_wmargin (fs, old_wm); - __argp_fmtstream_set_lmargin (fs, old_lm); - - __argp_fmtstream_putc (fs, '\n'); - anything = 1; - - first_pattern = 0; - } - while (more_patterns); - } - - if (flags & ARGP_HELP_PRE_DOC) - anything |= argp_doc (argp, state, 0, 0, 1, fs); - - if (flags & ARGP_HELP_SEE) - { - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\ -Try `%s --help' or `%s --usage' for more information.\n"), - name, name); - anything = 1; - } - - if (flags & ARGP_HELP_LONG) - /* Print a long, detailed help message. */ - { - /* Print info about all the options. */ - if (hol->num_entries > 0) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - hol_help (hol, state, fs); - anything = 1; - } - } - - if (flags & ARGP_HELP_POST_DOC) - /* Print any documentation strings at the end. */ - anything |= argp_doc (argp, state, 1, anything, 0, fs); - - if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, - "Report bugs to %s.\n"), - argp_program_bug_address); - anything = 1; - } - - if (hol) - hol_free (hol); - - __argp_fmtstream_free (fs); -} - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */ -void __argp_help (const struct argp *argp, FILE *stream, - unsigned flags, char *name) -{ - _help (argp, 0, stream, flags, name); -} -#ifdef weak_alias -weak_alias (__argp_help, argp_help) -#endif - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -void -__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags) -{ - if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) - { - if (state && (state->flags & ARGP_LONG_ONLY)) - flags |= ARGP_HELP_LONG_ONLY; - - _help (state ? state->root_argp : 0, state, stream, flags, - state ? state->name : program_invocation_short_name); - - if (!state || ! (state->flags & ARGP_NO_EXIT)) - { - if (flags & ARGP_HELP_EXIT_ERR) - exit (argp_err_exit_status); - if (flags & ARGP_HELP_EXIT_OK) - exit (0); - } - } -} -#ifdef weak_alias -weak_alias (__argp_state_help, argp_state_help) -#endif - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -void -__argp_error (const struct argp_state *state, const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { - va_list ap; - - fputs (state ? state->name : program_invocation_short_name, stream); - putc (':', stream); - putc (' ', stream); - - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); - - putc ('\n', stream); - - __argp_state_help (state, stream, ARGP_HELP_STD_ERR); - } - } -} -#ifdef weak_alias -weak_alias (__argp_error, argp_error) -#endif - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -void -__argp_failure (const struct argp_state *state, int status, int errnum, - const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { - fputs (state ? state->name : program_invocation_short_name, stream); - - if (fmt) - { - va_list ap; - - putc (':', stream); - putc (' ', stream); - - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); - } - - if (errnum) - { - putc (':', stream); - putc (' ', stream); - fputs (strerror (errnum), stream); - } - - putc ('\n', stream); - - if (status && (!state || !(state->flags & ARGP_NO_EXIT))) - exit (status); - } - } -} -#ifdef weak_alias -weak_alias (__argp_failure, argp_failure) -#endif diff --git a/support/argp-namefrob.h b/support/argp-namefrob.h deleted file mode 100644 index 983ae9fc..00000000 --- a/support/argp-namefrob.h +++ /dev/null @@ -1,92 +0,0 @@ -/* Name frobnication for compiling argp outside of glibc - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#if !_LIBC -/* This code is written for inclusion in gnu-libc, and uses names in the - namespace reserved for libc. If we're not compiling in libc, define those - names to be the normal ones instead. */ - -/* argp-parse functions */ -#undef __argp_parse -#define __argp_parse argp_parse -#undef __option_is_end -#define __option_is_end _option_is_end -#undef __option_is_short -#define __option_is_short _option_is_short -#undef __argp_input -#define __argp_input _argp_input - -/* argp-help functions */ -#undef __argp_help -#define __argp_help argp_help -#undef __argp_error -#define __argp_error argp_error -#undef __argp_failure -#define __argp_failure argp_failure -#undef __argp_state_help -#define __argp_state_help argp_state_help -#undef __argp_usage -#define __argp_usage argp_usage - -/* argp-fmtstream functions */ -#undef __argp_make_fmtstream -#define __argp_make_fmtstream argp_make_fmtstream -#undef __argp_fmtstream_free -#define __argp_fmtstream_free argp_fmtstream_free -#undef __argp_fmtstream_putc -#define __argp_fmtstream_putc argp_fmtstream_putc -#undef __argp_fmtstream_puts -#define __argp_fmtstream_puts argp_fmtstream_puts -#undef __argp_fmtstream_write -#define __argp_fmtstream_write argp_fmtstream_write -#undef __argp_fmtstream_printf -#define __argp_fmtstream_printf argp_fmtstream_printf -#undef __argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#define __argp_fmtstream_point argp_fmtstream_point -#undef __argp_fmtstream_update -#define __argp_fmtstream_update _argp_fmtstream_update -#undef __argp_fmtstream_ensure -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#undef __argp_fmtstream_lmargin -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#undef __argp_fmtstream_rmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#undef __argp_fmtstream_wmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* normal libc functions we call */ -#undef __sleep -#define __sleep sleep -#undef __strcasecmp -#define __strcasecmp strcasecmp -#undef __vsnprintf -#define __vsnprintf vsnprintf - -#endif /* !_LIBC */ - -#ifndef __set_errno -#define __set_errno(e) (errno = (e)) -#endif diff --git a/support/argp-parse.c b/support/argp-parse.c deleted file mode 100644 index 545e0406..00000000 --- a/support/argp-parse.c +++ /dev/null @@ -1,962 +0,0 @@ -/* Hierarchial argument parsing, layered over getopt - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <limits.h> -#include <getopt.h> - -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ -#ifdef HAVE_LIBINTL_H -# include <libintl.h> -#else -# define dgettext(domain, msgid) (msgid) -# define gettext(msgid) (msgid) -#endif -#define N_(msgid) (msgid) -#define _(msgid) msgid -#endif - -#if _LIBC - 0 -#include <bits/libc-lock.h> -#else -#ifdef HAVE_CTHREADS_H -#include <cthreads.h> -#endif -#endif /* _LIBC */ - -#include "argp.h" -#include "argp-namefrob.h" - -/* This is for Gnome only. */ -#include "gnome-argp.h" - -/* Getopt return values. */ -#define KEY_END (-1) /* The end of the options. */ -#define KEY_ARG 1 /* A non-option argument. */ -#define KEY_ERR '?' /* An error parsing the options. */ - -/* The meta-argument used to prevent any further arguments being interpreted - as options. */ -#define QUOTE "--" - -/* The number of bits we steal in a long-option value for our own use. */ -#define GROUP_BITS CHAR_BIT - -/* The number of bits available for the user value. */ -#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS) -#define USER_MASK ((1 << USER_BITS) - 1) - -/* EZ alias for ARGP_ERR_UNKNOWN. */ -#define EBADKEY ARGP_ERR_UNKNOWN - -/* Default options. */ - -/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep - for one second intervals, decrementing _ARGP_HANG until it's zero. Thus - you can force the program to continue by attaching a debugger and setting - it to 0 yourself. */ -volatile int _argp_hang = 0; - -#define OPT_PROGNAME -2 -#define OPT_USAGE -3 -#define OPT_HANG -4 - -static const struct argp_option argp_default_options[] = -{ - {"help", '?', 0, 0, N_("Give this help list"), -1}, - {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message")}, - {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name")}, - {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("Hang for SECS seconds (default 3600)")}, - {0, 0} -}; - -static error_t -argp_default_parser (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case '?': - __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP); - break; - case OPT_USAGE: - __argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); - break; - - case OPT_PROGNAME: /* Set the program name. */ - program_invocation_name = arg; - - /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka - __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined - to be that, so we have to be a bit careful here.] */ - arg = strrchr (arg, '/'); - if (arg) - program_invocation_short_name = arg + 1; - else - program_invocation_short_name = program_invocation_name; - - /* Update what we use for messages. */ - state->name = program_invocation_short_name; - - if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) - == ARGP_PARSE_ARGV0) - /* Update what getopt uses too. */ - state->argv[0] = program_invocation_name; - - break; - - case OPT_HANG: - _argp_hang = atoi (arg ? arg : "3600"); - while (_argp_hang-- > 0) - __sleep (1); - break; - - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_default_argp = - {argp_default_options, &argp_default_parser}; - - -static const struct argp_option argp_version_options[] = -{ - {"version", 'V', 0, 0, N_("Print program version"), -1}, - {0, 0} -}; - -static error_t -argp_version_parser (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case 'V': - if (argp_program_version_hook) - (*argp_program_version_hook) (state->out_stream, state); - else if (argp_program_version) - fprintf (state->out_stream, "%s\n", argp_program_version); - else - __argp_error (state, dgettext (state->root_argp->argp_domain, - "(PROGRAM ERROR) No version known!?")); - if (! (state->flags & ARGP_NO_EXIT)) - exit (0); - break; - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_version_argp = - {argp_version_options, &argp_version_parser}; - -/* Returns the offset into the getopt long options array LONG_OPTIONS of a - long option with called NAME, or -1 if none is found. Passing NULL as - NAME will return the number of options. */ -static int -find_long_option (struct option *long_options, const char *name) -{ - struct option *l = long_options; - while (l->name != NULL) - if (name != NULL && strcmp (l->name, name) == 0) - return l - long_options; - else - l++; - if (name == NULL) - return l - long_options; - else - return -1; -} - -/* If we can, we regulate access to getopt, which is non-reentrant, with a - mutex. Since the case we're trying to guard against is two different - threads interfering, and it's possible that someone might want to call - argp_parse recursively (they're careful), we use a recursive lock if - possible. */ - -#if _LIBC - 0 - -__libc_lock_define_initialized_recursive (static, getopt_lock) -#define LOCK_GETOPT __libc_lock_lock_recursive (getopt_lock) -#define UNLOCK_GETOPT __libc_lock_unlock_recursive (getopt_lock) - -#else /* !_LIBC */ -#ifdef HAVE_CTHREADS_H - -static struct mutex getopt_lock = MUTEX_INITIALIZER; -#define LOCK_GETOPT mutex_lock (&getopt_lock) -#define UNLOCK_GETOPT mutex_unlock (&getopt_lock) - -#else /* !HAVE_CTHREADS_H */ - -#define LOCK_GETOPT (void)0 -#define UNLOCK_GETOPT (void)0 - -#endif /* HAVE_CTHREADS_H */ -#endif /* _LIBC */ - -/* This hack to allow programs that know what's going on to call argp - recursively. If someday argp is changed not to use the non-reentrant - getopt interface, we can get rid of this shit. XXX */ -void -_argp_unlock_xxx (void) -{ - UNLOCK_GETOPT; -} - -/* The state of a `group' during parsing. Each group corresponds to a - particular argp structure from the tree of such descending from the top - level argp passed to argp_parse. */ -struct group -{ - /* This group's parsing function. */ - argp_parser_t parser; - - /* Which argp this group is from. */ - const struct argp *argp; - - /* Points to the point in SHORT_OPTS corresponding to the end of the short - options for this group. We use it to determine from which group a - particular short options is from. */ - char *short_end; - - /* The number of non-option args sucessfully handled by this parser. */ - unsigned args_processed; - - /* This group's parser's parent's group. */ - struct group *parent; - unsigned parent_index; /* And the our position in the parent. */ - - /* These fields are swapped into and out of the state structure when - calling this group's parser. */ - void *input, **child_inputs; - void *hook; -}; - -/* Call GROUP's parser with KEY and ARG, swapping any group-specific info - from STATE before calling, and back into state afterwards. If GROUP has - no parser, EBADKEY is returned. */ -static error_t -group_parse (struct group *group, struct argp_state *state, int key, char *arg) -{ - if (group->parser) - { - error_t err; - state->hook = group->hook; - state->input = group->input; - state->child_inputs = group->child_inputs; - state->arg_num = group->args_processed; - err = (*group->parser)(key, arg, state); - group->hook = state->hook; - return err; - } - else - return EBADKEY; -} - -struct parser -{ - const struct argp *argp; - - /* SHORT_OPTS is the getopt short options string for the union of all the - groups of options. */ - char *short_opts; - /* LONG_OPTS is the array of getop long option structures for the union of - all the groups of options. */ - struct option *long_opts; - - /* States of the various parsing groups. */ - struct group *groups; - /* The end of the GROUPS array. */ - struct group *egroup; - /* An vector containing storage for the CHILD_INPUTS field in all groups. */ - void **child_inputs; - - /* True if we think using getopt is still useful; if false, then - remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is - cleared whenever getopt returns KEY_END, but may be set again if the user - moves the next argument pointer backwards. */ - int try_getopt; - - /* State block supplied to parsing routines. */ - struct argp_state state; - - /* Memory used by this parser. */ - void *storage; -}; - -/* The next usable entries in the various parser tables being filled in by - convert_options. */ -struct parser_convert_state -{ - struct parser *parser; - char *short_end; - struct option *long_end; - void **child_inputs_end; -}; - -/* Converts all options in ARGP (which is put in GROUP) and ancestors - into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and - CVT->LONG_END are the points at which new options are added. Returns the - next unused group entry. CVT holds state used during the conversion. */ -static struct group * -convert_options (const struct argp *argp, - struct group *parent, unsigned parent_index, - struct group *group, struct parser_convert_state *cvt) -{ - /* REAL is the most recent non-alias value of OPT. */ - const struct argp_option *real = argp->options; - const struct argp_child *children = argp->children; - - if (real || argp->parser) - { - const struct argp_option *opt; - - if (real) - for (opt = real; !__option_is_end (opt); opt++) - { - if (! (opt->flags & OPTION_ALIAS)) - /* OPT isn't an alias, so we can use values from it. */ - real = opt; - - if (! (real->flags & OPTION_DOC)) - /* A real option (not just documentation). */ - { - if (__option_is_short (opt)) - /* OPT can be used as a short option. */ - { - *cvt->short_end++ = opt->key; - if (real->arg) - { - *cvt->short_end++ = ':'; - if (real->flags & OPTION_ARG_OPTIONAL) - *cvt->short_end++ = ':'; - } - *cvt->short_end = '\0'; /* keep 0 terminated */ - } - - if (opt->name - && find_long_option (cvt->parser->long_opts, opt->name) < 0) - /* OPT can be used as a long option. */ - { - cvt->long_end->name = opt->name; - cvt->long_end->has_arg = - (real->arg - ? (real->flags & OPTION_ARG_OPTIONAL - ? optional_argument - : required_argument) - : no_argument); - cvt->long_end->flag = 0; - /* we add a disambiguating code to all the user's - values (which is removed before we actually call - the function to parse the value); this means that - the user loses use of the high 8 bits in all his - values (the sign of the lower bits is preserved - however)... */ - cvt->long_end->val = - ((opt->key | real->key) & USER_MASK) - + (((group - cvt->parser->groups) + 1) << USER_BITS); - - /* Keep the LONG_OPTS list terminated. */ - (++cvt->long_end)->name = NULL; - } - } - } - - group->parser = argp->parser; - group->argp = argp; - group->short_end = cvt->short_end; - group->args_processed = 0; - group->parent = parent; - group->parent_index = parent_index; - group->input = 0; - group->hook = 0; - group->child_inputs = 0; - - if (children) - /* Assign GROUP's CHILD_INPUTS field some space from - CVT->child_inputs_end.*/ - { - unsigned num_children = 0; - while (children[num_children].argp) - num_children++; - group->child_inputs = cvt->child_inputs_end; - cvt->child_inputs_end += num_children; - } - - parent = group++; - } - else - parent = 0; - - if (children) - { - unsigned index = 0; - while (children->argp) - group = - convert_options (children++->argp, parent, index++, group, cvt); - } - - return group; -} - -/* Find the merged set of getopt options, with keys appropiately prefixed. */ -static void -parser_convert (struct parser *parser, const struct argp *argp, int flags) -{ - struct parser_convert_state cvt; - - cvt.parser = parser; - cvt.short_end = parser->short_opts; - cvt.long_end = parser->long_opts; - cvt.child_inputs_end = parser->child_inputs; - - if (flags & ARGP_IN_ORDER) - *cvt.short_end++ = '-'; - else if (flags & ARGP_NO_ARGS) - *cvt.short_end++ = '+'; - *cvt.short_end = '\0'; - - cvt.long_end->name = NULL; - - parser->argp = argp; - - if (argp) - parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt); - else - parser->egroup = parser->groups; /* No parsers at all! */ -} - -/* Lengths of various parser fields which we will allocated. */ -struct parser_sizes -{ - size_t short_len; /* Getopt short options string. */ - size_t long_len; /* Getopt long options vector. */ - size_t num_groups; /* Group structures we allocate. */ - size_t num_child_inputs; /* Child input slots. */ -}; - -/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of - argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by - the maximum lengths of the resulting merged getopt short options string and - long-options array, respectively. */ -static void -calc_sizes (const struct argp *argp, struct parser_sizes *szs) -{ - const struct argp_child *child = argp->children; - const struct argp_option *opt = argp->options; - - if (opt || argp->parser) - { - szs->num_groups++; - if (opt) - { - int num_opts = 0; - while (!__option_is_end (opt++)) - num_opts++; - szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */ - szs->long_len += num_opts; - } - } - - if (child) - while (child->argp) - { - calc_sizes ((child++)->argp, szs); - szs->num_child_inputs++; - } -} - -/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */ -static error_t -parser_init (struct parser *parser, const struct argp *argp, - int argc, char **argv, int flags, void *input) -{ - error_t err = 0; - struct group *group; - struct parser_sizes szs; - - szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1; - szs.long_len = 0; - szs.num_groups = 0; - szs.num_child_inputs = 0; - - if (argp) - calc_sizes (argp, &szs); - - /* Lengths of the various bits of storage used by PARSER. */ -#define GLEN (szs.num_groups + 1) * sizeof (struct group) -#define CLEN (szs.num_child_inputs * sizeof (void *)) -#define LLEN ((szs.long_len + 1) * sizeof (struct option)) -#define SLEN (szs.short_len + 1) - - parser->storage = malloc (GLEN + CLEN + LLEN + SLEN); - if (! parser->storage) - return ENOMEM; - - parser->groups = parser->storage; - parser->child_inputs = (void **)((char *)parser->storage + GLEN); - parser->long_opts = (struct option *)((char *)parser->storage + GLEN + CLEN); - parser->short_opts = (char *)parser->storage + GLEN + CLEN + LLEN; - - memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *)); - parser_convert (parser, argp, flags); - - memset (&parser->state, 0, sizeof (struct argp_state)); - parser->state.root_argp = parser->argp; - parser->state.argc = argc; - parser->state.argv = argv; - parser->state.flags = flags; - parser->state.err_stream = stderr; - parser->state.out_stream = stdout; - parser->state.next = 0; /* Tell getopt to initialize. */ - parser->state.pstate = parser; - - parser->try_getopt = 1; - - /* Call each parser for the first time, giving it a chance to propagate - values to child parsers. */ - if (parser->groups < parser->egroup) - parser->groups->input = input; - for (group = parser->groups; - group < parser->egroup && (!err || err == EBADKEY); - group++) - { - if (group->parent) - /* If a child parser, get the initial input value from the parent. */ - group->input = group->parent->child_inputs[group->parent_index]; - - if (!group->parser - && group->argp->children && group->argp->children->argp) - /* For the special case where no parsing function is supplied for an - argp, propagate its input to its first child, if any (this just - makes very simple wrapper argps more convenient). */ - group->child_inputs[0] = group->input; - - err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0); - } - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - if (err) - return err; - - /* Getopt is (currently) non-reentrant. */ - LOCK_GETOPT; - - if (parser->state.flags & ARGP_NO_ERRS) - { - opterr = 0; - if (parser->state.flags & ARGP_PARSE_ARGV0) - /* getopt always skips ARGV[0], so we have to fake it out. As long - as OPTERR is 0, then it shouldn't actually try to access it. */ - parser->state.argv--, parser->state.argc++; - } - else - opterr = 1; /* Print error messages. */ - - if (parser->state.argv == argv && argv[0]) - /* There's an argv[0]; use it for messages. */ - { - char *short_name = strrchr (argv[0], '/'); - parser->state.name = short_name ? short_name + 1 : argv[0]; - } - else - parser->state.name = program_invocation_short_name; - - return 0; -} - -/* Free any storage consumed by PARSER (but not PARSER itself). */ -static error_t -parser_finalize (struct parser *parser, - error_t err, int arg_ebadkey, int *end_index) -{ - struct group *group; - - UNLOCK_GETOPT; - - if (err == EBADKEY && arg_ebadkey) - /* Suppress errors generated by unparsed arguments. */ - err = 0; - - if (! err) - if (parser->state.next == parser->state.argc) - /* We successfully parsed all arguments! Call all the parsers again, - just a few more times... */ - { - for (group = parser->groups; - group < parser->egroup && (!err || err==EBADKEY); - group++) - if (group->args_processed == 0) - err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); - for (group = parser->groups; - group < parser->egroup && (!err || err==EBADKEY); - group++) - err = group_parse (group, &parser->state, ARGP_KEY_END, 0); - - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - /* Tell the user that all arguments are parsed. */ - if (end_index) - *end_index = parser->state.next; - } - else if (end_index) - /* Return any remaining arguments to the user. */ - *end_index = parser->state.next; - else - /* No way to return the remaining arguments, they must be bogus. */ - { - if (!(parser->state.flags & ARGP_NO_ERRS) && parser->state.err_stream) - fprintf (parser->state.err_stream, - dgettext (parser->argp->argp_domain, - "%s: Too many arguments\n"), parser->state.name); - err = EBADKEY; - } - - /* Okay, we're all done, with either an error or success; call the parsers - to indicate which one. */ - - if (err) - { - /* Maybe print an error message. */ - if (err == EBADKEY) - /* An appropriate message describing what the error was should have - been printed earlier. */ - __argp_state_help (&parser->state, parser->state.err_stream, - ARGP_HELP_STD_ERR); - - /* Since we didn't exit, give each parser an error indication. */ - for (group = parser->groups; group < parser->egroup; group++) - group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); - } - else - /* Notify parsers of success, and propagate back values from parsers. */ - { - /* We pass over the groups in reverse order so that child groups are - given a chance to do there processing before passing back a value to - the parent. */ - for (group = parser->egroup - 1 - ; group >= parser->groups && (!err || err == EBADKEY) - ; group--) - err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - } - - /* Call parsers once more, to do any final cleanup. Errors are ignored. */ - for (group = parser->egroup - 1; group >= parser->groups; group--) - group_parse (group, &parser->state, ARGP_KEY_FINI, 0); - - if (err == EBADKEY) - err = EINVAL; - - free (parser->storage); - - return err; -} - -/* Call the user parsers to parse the non-option argument VAL, at the current - position, returning any error. The state NEXT pointer is assumed to have - been adjusted (by getopt) to point after this argument; this function will - adjust it correctly to reflect however many args actually end up being - consumed. */ -static error_t -parser_parse_arg (struct parser *parser, char *val) -{ - /* Save the starting value of NEXT, first adjusting it so that the arg - we're parsing is again the front of the arg vector. */ - int index = --parser->state.next; - error_t err = EBADKEY; - struct group *group; - int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ - - /* Try to parse the argument in each parser. */ - for (group = parser->groups - ; group < parser->egroup && err == EBADKEY - ; group++) - { - parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ - key = ARGP_KEY_ARG; - err = group_parse (group, &parser->state, key, val); - - if (err == EBADKEY) - /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ - { - parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ - key = ARGP_KEY_ARGS; - err = group_parse (group, &parser->state, key, 0); - } - } - - if (! err) - { - if (key == ARGP_KEY_ARGS) - /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't - changed by the user, *all* arguments should be considered - consumed. */ - parser->state.next = parser->state.argc; - - if (parser->state.next > index) - /* Remember that we successfully processed a non-option - argument -- but only if the user hasn't gotten tricky and set - the clock back. */ - (--group)->args_processed += (parser->state.next - index); - else - /* The user wants to reparse some args, give getopt another try. */ - parser->try_getopt = 1; - } - - return err; -} - -/* Call the user parsers to parse the option OPT, with argument VAL, at the - current position, returning any error. */ -static error_t -parser_parse_opt (struct parser *parser, int opt, char *val) -{ - /* The group key encoded in the high bits; 0 for short opts or - group_number + 1 for long opts. */ - int group_key = opt >> USER_BITS; - error_t err = EBADKEY; - - if (group_key == 0) - /* A short option. By comparing OPT's position in SHORT_OPTS to the - various starting positions in each group's SHORT_END field, we can - determine which group OPT came from. */ - { - struct group *group; - char *short_index = strchr (parser->short_opts, opt); - - if (short_index) - for (group = parser->groups; group < parser->egroup; group++) - if (group->short_end > short_index) - { - err = group_parse (group, &parser->state, opt, optarg); - break; - } - } - else - /* A long option. We use shifts instead of masking for extracting - the user value in order to preserve the sign. */ - err = - group_parse (&parser->groups[group_key - 1], &parser->state, - (opt << GROUP_BITS) >> GROUP_BITS, optarg); - - if (err == EBADKEY) - /* At least currently, an option not recognized is an error in the - parser, because we pre-compute which parser is supposed to deal - with each option. */ - { - static const char bad_key_err[] = - _("(PROGRAM ERROR) Option should have been recognized!?"); - if (group_key == 0) - __argp_error (&parser->state, "-%c: %s", opt, - dgettext (parser->argp->argp_domain, bad_key_err)); - else - { - struct option *long_opt = parser->long_opts; - while (long_opt->val != opt && long_opt->name) - long_opt++; - __argp_error (&parser->state, "--%s: %s", - long_opt->name ? long_opt->name : "???", - dgettext (parser->argp->argp_domain, bad_key_err)); - } - } - - return err; -} - -/* Parse the next argument in PARSER (as indicated by PARSER->state.next). - Any error from the parsers is returned, and *ARGP_EBADKEY indicates - whether a value of EBADKEY is due to an unrecognized argument (which is - generally not fatal). */ -static error_t -parser_parse_next (struct parser *parser, int *arg_ebadkey) -{ - int opt; - error_t err = 0; - - if (parser->state.quoted && parser->state.next < parser->state.quoted) - /* The next argument pointer has been moved to before the quoted - region, so pretend we never saw the quoting `--', and give getopt - another chance. If the user hasn't removed it, getopt will just - process it again. */ - parser->state.quoted = 0; - - if (parser->try_getopt && !parser->state.quoted) - /* Give getopt a chance to parse this. */ - { - optind = parser->state.next; /* Put it back in OPTIND for getopt. */ - optopt = KEY_END; /* Distinguish KEY_ERR from a real option. */ - if (parser->state.flags & ARGP_LONG_ONLY) - opt = getopt_long_only (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0); - else - opt = getopt_long (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0); - parser->state.next = optind; /* And see what getopt did. */ - - if (opt == KEY_END) - /* Getopt says there are no more options, so stop using - getopt; we'll continue if necessary on our own. */ - { - parser->try_getopt = 0; - if (parser->state.next > 1 - && strcmp (parser->state.argv[parser->state.next - 1], QUOTE) - == 0) - /* Not only is this the end of the options, but it's a - `quoted' region, which may have args that *look* like - options, so we definitely shouldn't try to use getopt past - here, whatever happens. */ - parser->state.quoted = parser->state.next; - } - else if (opt == KEY_ERR && optopt != KEY_END) - /* KEY_ERR can have the same value as a valid user short - option, but in the case of a real error, getopt sets OPTOPT - to the offending character, which can never be KEY_END. */ - { - *arg_ebadkey = 0; - return EBADKEY; - } - } - else - opt = KEY_END; - - if (opt == KEY_END) - /* We're past what getopt considers the options. */ - if (parser->state.next >= parser->state.argc - || (parser->state.flags & ARGP_NO_ARGS)) - /* Indicate that we're done. */ - { - *arg_ebadkey = 1; - return EBADKEY; - } - else - /* A non-option arg; simulate what getopt might have done. */ - { - opt = KEY_ARG; - optarg = parser->state.argv[parser->state.next++]; - } - - if (opt == KEY_ARG) - /* A non-option argument; try each parser in turn. */ - err = parser_parse_arg (parser, optarg); - else - err = parser_parse_opt (parser, opt, optarg); - - if (err == EBADKEY) - *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG); - - return err; -} - -/* Parse the options strings in ARGC & ARGV according to the argp in ARGP. - FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, EINVAL is returned; if some parser routine - returned a non-zero value, it is returned; otherwise 0 is returned. */ -error_t -__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, - int *end_index, void *input) -{ - error_t err; - struct parser parser; - - /* If true, then err == EBADKEY is a result of a non-option argument failing - to be parsed (which in some cases isn't actually an error). */ - int arg_ebadkey = 0; - - if (! (flags & ARGP_NO_HELP)) - /* Add our own options. */ - { - struct argp_child *child = alloca (4 * sizeof (struct argp_child)); - struct argp *top_argp = alloca (sizeof (struct argp)); - - /* TOP_ARGP has no options, it just serves to group the user & default - argps. */ - memset (top_argp, 0, sizeof (*top_argp)); - top_argp->children = child; - - memset (child, 0, 4 * sizeof (struct argp_child)); - - if (argp) - (child++)->argp = argp; - (child++)->argp = &argp_default_argp; - if (argp_program_version || argp_program_version_hook) - (child++)->argp = &argp_version_argp; - child->argp = 0; - - argp = top_argp; - } - - /* Construct a parser for these arguments. */ - err = parser_init (&parser, argp, argc, argv, flags, input); - - if (! err) - /* Parse! */ - { - while (! err) - err = parser_parse_next (&parser, &arg_ebadkey); - err = parser_finalize (&parser, err, arg_ebadkey, end_index); - } - - return err; -} -#ifdef weak_alias -weak_alias (__argp_parse, argp_parse) -#endif - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -void * -__argp_input (const struct argp *argp, const struct argp_state *state) -{ - if (state) - { - struct group *group; - struct parser *parser = state->pstate; - - for (group = parser->groups; group < parser->egroup; group++) - if (group->argp == argp) - return group->input; - } - - return 0; -} -#ifdef weak_alias -weak_alias (__argp_input, _argp_input) -#endif diff --git a/support/argp-pv.c b/support/argp-pv.c deleted file mode 100644 index 27d714b3..00000000 --- a/support/argp-pv.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which will - print this this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -const char *argp_program_version = 0; diff --git a/support/argp-pvh.c b/support/argp-pvh.c deleted file mode 100644 index ed60aa99..00000000 --- a/support/argp-pvh.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION_HOOK. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "argp.h" - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which calls - this function with a stream to print the version to and a pointer to the - current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = 0; diff --git a/support/argp-test.c b/support/argp-test.c deleted file mode 100644 index 702ae9aa..00000000 --- a/support/argp-test.c +++ /dev/null @@ -1,209 +0,0 @@ -/* Test program for argp argument parser - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <time.h> -#include <string.h> -#include <argp.h> - -const char *argp_program_version = "argp-test 1.0"; - -struct argp_option sub_options[] = -{ - {"subopt1", 's', 0, 0, "Nested option 1"}, - {"subopt2", 'S', 0, 0, "Nested option 2"}, - - { 0, 0, 0, 0, "Some more nested options:", 10}, - {"subopt3", 'p', 0, 0, "Nested option 3"}, - - {"subopt4", 'q', 0, 0, "Nested option 4", 1}, - - {0} -}; - -static const char sub_args_doc[] = "STRING...\n-"; -static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser."; - -static error_t -sub_parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case ARGP_KEY_NO_ARGS: - printf ("NO SUB ARGS\n"); - break; - case ARGP_KEY_ARG: - printf ("SUB ARG: %s\n", arg); - break; - - case 's' : case 'S': case 'p': case 'q': - printf ("SUB KEY %c\n", key); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static char * -sub_help_filter (int key, const char *text, void *input) -{ - if (key == ARGP_KEY_HELP_EXTRA) - return strdup ("This is some extra text from the sub parser (note that it \ -is preceded by a blank line)."); - else - return (char *)text; -} - -static struct argp sub_argp = { - sub_options, sub_parse_opt, sub_args_doc, sub_doc, 0, sub_help_filter -}; - -/* Structure used to communicate with the parsing functions. */ -struct params -{ - unsigned foonly; /* Value parsed for foonly. */ - unsigned foonly_default; /* Default value for it. */ -}; - -#define OPT_PGRP 1 -#define OPT_SESS 2 - -struct argp_option options[] = -{ - {"pid", 'p', "PID", 0, "List the process PID"}, - {"pgrp", OPT_PGRP,"PGRP",0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, - {0, 'x', 0, OPTION_ALIAS}, - {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" - " if there's some reason ps can't" - " print a field for any process, it's" - " removed from the output entirely)" }, - {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, - {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, - {"session", OPT_SESS,"SID", OPTION_ARG_OPTIONAL, - "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, - - {0,0,0,0, "Here are some more options:"}, - {"foonly", 'f', "ZOT", OPTION_ARG_OPTIONAL, "Glork a foonly"}, - {"zaza", 'z', 0, 0, "Snit a zar"}, - - {0} -}; - -static const char args_doc[] = "STRING"; -static const char doc[] = "Test program for argp." - "\vThis doc string comes after the options." - "\nHey! Some manual formatting!" - "\nThe current time is: %s"; - -static void -popt (int key, char *arg) -{ - char buf[10]; - if (isprint (key)) - sprintf (buf, "%c", key); - else - sprintf (buf, "%d", key); - if (arg) - printf ("KEY %s: %s\n", buf, arg); - else - printf ("KEY %s\n", buf); -} - -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - struct params *params = state->input; - - switch (key) - { - case ARGP_KEY_NO_ARGS: - printf ("NO ARGS\n"); - break; - - case ARGP_KEY_ARG: - if (state->arg_num > 0) - return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */ - printf ("ARG: %s\n", arg); - break; - - case 'f': - if (arg) - params->foonly = atoi (arg); - else - params->foonly = params->foonly_default; - popt (key, arg); - break; - - case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q': - case 'r': case OPT_SESS: case 'z': - popt (key, arg); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static char * -help_filter (int key, const char *text, void *input) -{ - char *new_text; - struct params *params = input; - - if (key == ARGP_KEY_HELP_POST_DOC && text) - { - time_t now = time (0); - asprintf (&new_text, text, ctime (&now)); - } - else if (key == 'f') - /* Show the default for the --foonly option. */ - asprintf (&new_text, "%s (ZOT defaults to %x)", - text, params->foonly_default); - else - new_text = (char *)text; - - return new_text; -} - -static struct argp_child argp_children[] = { { &sub_argp }, { 0 } }; -static struct argp argp = { - options, parse_opt, args_doc, doc, argp_children, help_filter -}; - -int -main (int argc, char **argv) -{ - struct params params; - params.foonly = 0; - params.foonly_default = random (); - argp_parse (&argp, argc, argv, 0, 0, ¶ms); - printf ("After parsing: foonly = %x\n", params.foonly); - return 0; -} diff --git a/support/argp-xinl.c b/support/argp-xinl.c deleted file mode 100644 index 35a8f832..00000000 --- a/support/argp-xinl.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Real definitions for extern inline functions in argp.h - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#define ARGP_EI -#undef __OPTIMIZE__ -#define __OPTIMIZE__ -#include "argp.h" - -/* Add weak aliases. */ -#if _LIBC - 0 && defined (weak_alias) - -weak_alias (__argp_usage, argp_usage) -weak_alias (__option_is_short, _option_is_short) -weak_alias (__option_is_end, _option_is_end) - -#endif diff --git a/support/argp.h b/support/argp.h deleted file mode 100644 index b27a02d9..00000000 --- a/support/argp.h +++ /dev/null @@ -1,571 +0,0 @@ -/* Hierarchial argument parsing, layered over getopt. - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _ARGP_H -#define _ARGP_H - -#include <stdio.h> -#include <ctype.h> -#include <getopt.h> - -#define __need_error_t -#include <errno.h> - -#ifndef __const -# define __const const -#endif - -#ifndef __error_t_defined -typedef int error_t; -# define __error_t_defined -#endif - -#ifndef __P -# if (defined __STDC__ && __STDC__) || defined __cplusplus -# define __P(args) args -# else -# define __P(args) () -# endif -#endif - -/* For Gnome only: don't assume gcc. */ -#ifndef __GNUC__ -#define __attribute__(X) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* A description of a particular option. A pointer to an array of - these is passed in the OPTIONS field of an argp structure. Each option - entry can correspond to one long option and/or one short option; more - names for the same option can be added by following an entry in an option - array with options having the OPTION_ALIAS flag set. */ -struct argp_option -{ - /* The long option name. For more than one name for the same option, you - can use following options with the OPTION_ALIAS flag set. */ - __const char *name; - - /* What key is returned for this option. If > 0 and printable, then it's - also accepted as a short option. */ - int key; - - /* If non-NULL, this is the name of the argument associated with this - option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */ - __const char *arg; - - /* OPTION_ flags. */ - int flags; - - /* The doc string for this option. If both NAME and KEY are 0, This string - will be printed outdented from the normal option column, making it - useful as a group header (it will be the first thing printed in its - group); in this usage, it's conventional to end the string with a `:'. */ - __const char *doc; - - /* The group this option is in. In a long help message, options are sorted - alphabetically within each group, and the groups presented in the order - 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with - if this field 0 will inherit the group number of the previous entry, or - zero if it's the first one, unless its a group header (NAME and KEY both - 0), in which case, the previous entry + 1 is the default. Automagic - options such as --help are put into group -1. */ - int group; -}; - -/* The argument associated with this option is optional. */ -#define OPTION_ARG_OPTIONAL 0x1 - -/* This option isn't displayed in any help messages. */ -#define OPTION_HIDDEN 0x2 - -/* This option is an alias for the closest previous non-alias option. This - means that it will be displayed in the same help entry, and will inherit - fields other than NAME and KEY from the aliased option. */ -#define OPTION_ALIAS 0x4 - -/* This option isn't actually an option (and so should be ignored by the - actual option parser), but rather an arbitrary piece of documentation that - should be displayed in much the same manner as the options. If this flag - is set, then the option NAME field is displayed unmodified (e.g., no `--' - prefix is added) at the left-margin (where a *short* option would normally - be displayed), and the documentation string in the normal place. For - purposes of sorting, any leading whitespace and puncuation is ignored, - except that if the first non-whitespace character is not `-', this entry - is displayed after all options (and OPTION_DOC entries with a leading `-') - in the same group. */ -#define OPTION_DOC 0x8 - -/* This option shouldn't be included in `long' usage messages (but is still - included in help messages). This is mainly intended for options that are - completely documented in an argp's ARGS_DOC field, in which case including - the option in the generic usage list would be redundant. For instance, - if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to - distinguish these two cases, -x should probably be marked - OPTION_NO_USAGE. */ -#define OPTION_NO_USAGE 0x10 - -struct argp; /* fwd declare this type */ -struct argp_state; /* " */ -struct argp_child; /* " */ - -/* The type of a pointer to an argp parsing function. */ -typedef error_t (*argp_parser_t)(int key, char *arg, struct argp_state *state); - -/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such - returns will simply be ignored. For user keys, this error will be turned - into EINVAL (if the call to argp_parse is such that errors are propagated - back to the user instead of exiting); returning EINVAL itself would result - in an immediate stop to parsing in *all* cases. */ -#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ - -/* Special values for the KEY argument to an argument parsing function. - ARGP_ERR_UNKNOWN should be returned if they aren't understood. - - The sequence of keys to a parsing function is either (where each - uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key): - - INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all - or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed - or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized - - The third case is where every parser returned ARGP_KEY_UNKNOWN for an - argument, in which case parsing stops at that argument (returning the - unparsed arguments to the caller of argp_parse if requested, or stopping - with an error message if not). - - If an error occurs (either detected by argp, or because the parsing - function returned an error value), then the parser is called with - ARGP_KEY_ERROR, and no further calls are made. */ - -/* This is not an option at all, but rather a command line argument. If a - parser receiving this key returns success, the fact is recorded, and the - ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the - argument, a parser function decrements the NEXT field of the state it's - passed, the option won't be considered processed; this is to allow you to - actually modify the argument (perhaps into an option), and have it - processed again. */ -#define ARGP_KEY_ARG 0 -/* There are remaining arguments not parsed by any parser, which may be found - starting at (STATE->argv + STATE->next). If success is returned, but - STATE->next left untouched, it's assumed that all arguments were consume, - otherwise, the parser should adjust STATE->next to reflect any arguments - consumed. */ -#define ARGP_KEY_ARGS 0x1000006 -/* There are no more command line arguments at all. */ -#define ARGP_KEY_END 0x1000001 -/* Because it's common to want to do some special processing if there aren't - any non-option args, user parsers are called with this key if they didn't - successfully process any non-option arguments. Called just before - ARGP_KEY_END (where more general validity checks on previously parsed - arguments can take place). */ -#define ARGP_KEY_NO_ARGS 0x1000002 -/* Passed in before any parsing is done. Afterwards, the values of each - element of the CHILD_INPUT field, if any, in the state structure is - copied to each child's state to be the initial value of the INPUT field. */ -#define ARGP_KEY_INIT 0x1000003 -/* Use after all other keys, including SUCCESS & END. */ -#define ARGP_KEY_FINI 0x1000007 -/* Passed in when parsing has successfully been completed (even if there are - still arguments remaining). */ -#define ARGP_KEY_SUCCESS 0x1000004 -/* Passed in if an error occurs. */ -#define ARGP_KEY_ERROR 0x1000005 - -/* An argp structure contains a set of options declarations, a function to - deal with parsing one, documentation string, a possible vector of child - argp's, and perhaps a function to filter help output. When actually - parsing options, getopt is called with the union of all the argp - structures chained together through their CHILD pointers, with conflicts - being resolved in favor of the first occurance in the chain. */ -struct argp -{ - /* An array of argp_option structures, terminated by an entry with both - NAME and KEY having a value of 0. */ - __const struct argp_option *options; - - /* What to do with an option from this structure. KEY is the key - associated with the option, and ARG is any associated argument (NULL if - none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be - returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then - parsing is stopped immediately, and that value is returned from - argp_parse(). For special (non-user-supplied) values of KEY, see the - ARGP_KEY_ definitions below. */ - argp_parser_t parser; - - /* A string describing what other arguments are wanted by this program. It - is only used by argp_usage to print the `Usage:' message. If it - contains newlines, the strings separated by them are considered - alternative usage patterns, and printed on separate lines (lines after - the first are prefix by ` or: ' instead of `Usage:'). */ - __const char *args_doc; - - /* If non-NULL, a string containing extra text to be printed before and - after the options in a long help message (separated by a vertical tab - `\v' character). */ - __const char *doc; - - /* A vector of argp_children structures, terminated by a member with a 0 - argp field, pointing to child argps should be parsed with this one. Any - conflicts are resolved in favor of this argp, or early argps in the - CHILDREN list. This field is useful if you use libraries that supply - their own argp structure, which you want to use in conjunction with your - own. */ - __const struct argp_child *children; - - /* If non-zero, this should be a function to filter the output of help - messages. KEY is either a key from an option, in which case TEXT is - that option's help text, or a special key from the ARGP_KEY_HELP_ - defines, below, describing which other help text TEXT is. The function - should return either TEXT, if it should be used as-is, a replacement - string, which should be malloced, and will be freed by argp, or NULL, - meaning `print nothing'. The value for TEXT is *after* any translation - has been done, so if any of the replacement text also needs translation, - that should be done by the filter function. INPUT is either the input - supplied to argp_parse, or NULL, if argp_help was called directly. */ - char *(*help_filter)(int __key, __const char *__text, void *__input); - - /* If non-zero the strings used in the argp library are translated using - the domain described by this string. Otherwise the currently installed - default domain is used. */ - const char *argp_domain; -}; - -/* Possible KEY arguments to a help filter function. */ -#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ -#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ -#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ -#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; - TEXT is NULL for this key. */ -/* Explanatory note emitted when duplicate option arguments have been - suppressed. */ -#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 -#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ - -/* When an argp has a non-zero CHILDREN field, it should point to a vector of - argp_child structures, each of which describes a subsidiary argp. */ -struct argp_child -{ - /* The child parser. */ - __const struct argp *argp; - - /* Flags for this child. */ - int flags; - - /* If non-zero, an optional header to be printed in help output before the - child options. As a side-effect, a non-zero value forces the child - options to be grouped together; to achieve this effect without actually - printing a header string, use a value of "". */ - __const char *header; - - /* Where to group the child options relative to the other (`consolidated') - options in the parent argp; the values are the same as the GROUP field - in argp_option structs, but all child-groupings follow parent options at - a particular group level. If both this field and HEADER are zero, then - they aren't grouped at all, but rather merged with the parent options - (merging the child's grouping levels with the parents). */ - int group; -}; - -/* Parsing state. This is provided to parsing functions called by argp, - which may examine and, as noted, modify fields. */ -struct argp_state -{ - /* The top level ARGP being parsed. */ - __const struct argp *root_argp; - - /* The argument vector being parsed. May be modified. */ - int argc; - char **argv; - - /* The index in ARGV of the next arg that to be parsed. May be modified. */ - int next; - - /* The flags supplied to argp_parse. May be modified. */ - unsigned flags; - - /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the - number of the current arg, starting at zero, and incremented after each - such call returns. At all other times, this is the number of such - arguments that have been processed. */ - unsigned arg_num; - - /* If non-zero, the index in ARGV of the first argument following a special - `--' argument (which prevents anything following being interpreted as an - option). Only set once argument parsing has proceeded past this point. */ - int quoted; - - /* An arbitrary pointer passed in from the user. */ - void *input; - /* Values to pass to child parsers. This vector will be the same length as - the number of children for the current parser. */ - void **child_inputs; - - /* For the parser's use. Initialized to 0. */ - void *hook; - - /* The name used when printing messages. This is initialized to ARGV[0], - or PROGRAM_INVOCATION_NAME if that is unavailable. */ - char *name; - - /* Streams used when argp prints something. */ - FILE *err_stream; /* For errors; initialized to stderr. */ - FILE *out_stream; /* For information; initialized to stdout. */ - - void *pstate; /* Private, for use by argp. */ -}; - -/* Flags for argp_parse (note that the defaults are those that are - convenient for program command line parsing): */ - -/* Don't ignore the first element of ARGV. Normally (and always unless - ARGP_NO_ERRS is set) the first element of the argument vector is - skipped for option parsing purposes, as it corresponds to the program name - in a command line. */ -#define ARGP_PARSE_ARGV0 0x01 - -/* Don't print error messages for unknown options to stderr; unless this flag - is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program - name in the error messages. This flag implies ARGP_NO_EXIT (on the - assumption that silent exiting upon errors is bad behaviour). */ -#define ARGP_NO_ERRS 0x02 - -/* Don't parse any non-option args. Normally non-option args are parsed by - calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg - as the value. Since it's impossible to know which parse function wants to - handle it, each one is called in turn, until one returns 0 or an error - other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the - argp_parse returns prematurely (but with a return value of 0). If all - args have been parsed without error, all parsing functions are called one - last time with a key of ARGP_KEY_END. This flag needn't normally be set, - as the normal behavior is to stop parsing as soon as some argument can't - be handled. */ -#define ARGP_NO_ARGS 0x04 - -/* Parse options and arguments in the same order they occur on the command - line -- normally they're rearranged so that all options come first. */ -#define ARGP_IN_ORDER 0x08 - -/* Don't provide the standard long option --help, which causes usage and - option help information to be output to stdout, and exit (0) called. */ -#define ARGP_NO_HELP 0x10 - -/* Don't exit on errors (they may still result in error messages). */ -#define ARGP_NO_EXIT 0x20 - -/* Use the gnu getopt `long-only' rules for parsing arguments. */ -#define ARGP_LONG_ONLY 0x40 - -/* Turns off any message-printing/exiting options. */ -#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) - -/* Parse the options strings in ARGC & ARGV according to the options in ARGP. - FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser - routine returned a non-zero value, it is returned; otherwise 0 is - returned. This function may also call exit unless the ARGP_NO_HELP flag - is set. INPUT is a pointer to a value to be passed in to the parser. */ -extern error_t argp_parse __P ((__const struct argp *__argp, - int __argc, char **__argv, unsigned __flags, - int *__arg_index, void *__input)); -extern error_t __argp_parse __P ((__const struct argp *__argp, - int __argc, char **__argv, unsigned __flags, - int *__arg_index, void *__input)); - -/* Global variables. */ - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - will print this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -extern __const char *argp_program_version; - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - calls this function with a stream to print the version to and a pointer to - the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -extern void (*argp_program_version_hook) __P ((FILE *__stream, - struct argp_state *__state)); - -/* If defined or set by the user program, it should point to string that is - the bug-reporting address for the program. It will be printed by - argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various - standard help messages), embedded in a sentence that says something like - `Report bugs to ADDR.'. */ -extern __const char *argp_program_bug_address; - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - <sysexits.h>. */ -extern error_t argp_err_exit_status; - -/* Flags for argp_help. */ -#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ -#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ -#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ -#define ARGP_HELP_LONG 0x08 /* a long help message. */ -#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ -#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ -#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) -#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ -#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to - reflect ARGP_LONG_ONLY mode. */ - -/* These ARGP_HELP flags are only understood by argp_state_help. */ -#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ -#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ - -/* The standard thing to do after a program command line parsing error, if an - error message has already been printed. */ -#define ARGP_HELP_STD_ERR \ - (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do after a program command line parsing error, if no - more specific error message has been printed. */ -#define ARGP_HELP_STD_USAGE \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do in response to a --help option. */ -#define ARGP_HELP_STD_HELP \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ - | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR) - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. */ -extern void argp_help __P ((__const struct argp *__argp, FILE *__stream, - unsigned __flags, char *__name)); -extern void __argp_help __P ((__const struct argp *__argp, FILE *__stream, - unsigned __flags, char *__name)); - -/* The following routines are intended to be called from within an argp - parsing routine (thus taking an argp_state structure as the first - argument). They may or may not print an error message and exit, depending - on the flags in STATE -- in any case, the caller should be prepared for - them *not* to exit, and should return an appropiate error after calling - them. [argp_usage & argp_error should probably be called argp_state_..., - but they're used often enough that they should be short] */ - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -extern void argp_state_help __P ((__const struct argp_state *__state, - FILE *__stream, unsigned __flags)); -extern void __argp_state_help __P ((__const struct argp_state *__state, - FILE *__stream, unsigned __flags)); - -/* Possibly output the standard usage message for ARGP to stderr and exit. */ -extern void argp_usage __P ((__const struct argp_state *__state)); -extern void __argp_usage __P ((__const struct argp_state *__state)); - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -extern void argp_error __P ((__const struct argp_state *__state, - __const char *__fmt, ...)) - __attribute__ ((__format__ (__printf__, 2, 3))); -extern void __argp_error __P ((__const struct argp_state *__state, - __const char *__fmt, ...)) - __attribute__ ((__format__ (__printf__, 2, 3))); - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -extern void argp_failure __P ((__const struct argp_state *__state, - int __status, int __errnum, - __const char *__fmt, ...)) - __attribute__ ((__format__ (__printf__, 4, 5))); -extern void __argp_failure __P ((__const struct argp_state *__state, - int __status, int __errnum, - __const char *__fmt, ...)) - __attribute__ ((__format__ (__printf__, 4, 5))); - -/* Returns true if the option OPT is a valid short option. */ -extern int _option_is_short __P ((__const struct argp_option *__opt)); -extern int __option_is_short __P ((__const struct argp_option *__opt)); - -/* Returns true if the option OPT is in fact the last (unused) entry in an - options array. */ -extern int _option_is_end __P ((__const struct argp_option *__opt)); -extern int __option_is_end __P ((__const struct argp_option *__opt)); - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -extern void *_argp_input __P ((__const struct argp *argp, - __const struct argp_state *state)); -extern void *__argp_input __P ((__const struct argp *argp, - __const struct argp_state *state)); - -#ifdef __OPTIMIZE__ - -# if !_LIBC -# define __argp_usage argp_usage -# define __argp_state_help argp_state_help -# define __option_is_short _option_is_short -# define __option_is_end _option_is_end -# endif - -/* FIXME: Assume we are using GCC. This is inside an __OPTIMIZE__ test. */ -# ifndef ARGP_EI -# define ARGP_EI extern __inline__ -# endif - -ARGP_EI void -__argp_usage (__const struct argp_state *__state) -{ - __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); -} - -ARGP_EI int -__option_is_short (__const struct argp_option *__opt) -{ - if (__opt->flags & OPTION_DOC) - return 0; - else - { - int __key = __opt->key; - return __key > 0 && isprint (__key); - } -} - -ARGP_EI int -__option_is_end (__const struct argp_option *__opt) -{ - return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; -} - -# if !_LIBC -# undef __argp_usage -# undef __argp_state_help -# undef __option_is_short -# undef __option_is_end -# endif -#endif /* __OPTIMIZE__ */ - -#ifdef __cplusplus -} -#endif - -#endif /* argp.h */ diff --git a/support/argp.texi b/support/argp.texi deleted file mode 100644 index 8c41f078..00000000 --- a/support/argp.texi +++ /dev/null @@ -1,1157 +0,0 @@ -@ignore - Documentation for the argp argument parser - - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader <miles@gnu.ai.mit.edu>. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ -@end ignore - -@node Argp, Suboptions, Getopt, Parsing Program Arguments -@need 5000 -@section Parsing Program Options with Argp -@cindex argp (program argument parser) -@cindex argument parsing with argp -@cindex option parsing with argp - -@dfn{Argp} is an interface for parsing unix-style argument vectors -(@pxref{Program Arguments}). - -Unlike the more common @code{getopt} interface, it provides many related -convenience features in addition to parsing options, such as -automatically producing output in response to @samp{--help} and -@samp{--version} options (as defined by the GNU coding standards). -Doing these things in argp results in a more consistent look for -programs that use it, and makes less likely that implementors will -neglect to implement them or keep them up-to-date. - -Argp also provides the ability to merge several independently defined -option parsers into one, mediating conflicts between them, and making -the result appear seamless. A library can export an argp option parser, -which programs can easily use in conjunction with their own option -parser. This results in less work for user programs (indeed, some may -use only argument parsers exported by libraries, and have no options of -their own), and more consistent option-parsing for the abstractions -implemented by the library. - -@pindex argp.h -The header file @file{<argp.h>} should be included to use argp. - -@subsection The @code{argp_parse} Function - -The main interface to argp is the @code{argp_parse} function; often, a -call to @code{argp_parse} is the only argument-parsing code needed in -@code{main} (@pxref{Program Arguments}). - -@comment argp.h -@comment GNU -@deftypefun {error_t} argp_parse (const struct argp *@var{argp}, @w{int @var{argc}, char **@var{argv}}, @w{unsigned @var{flags}}, @w{int *@var{arg_index}}, @w{void *@var{input}}) -The @code{argp_parse} function parses the arguments in in @var{argv}, of -length @var{argc}, using the argp parser @var{argp} (@pxref{Argp -Parsers}); a value of zero is the same as a @code{struct argp} -containing all zeros. @var{flags} is a set of flag bits that modify the -parsing behavior (@pxref{Argp Flags}). @var{input} is passed through to -the argp parser @var{argp}, and has meaning defined by it; a typical -usage is to pass a pointer to a structure which can be used for -specifying parameters to the parser and passing back results from it. - -Unless the @code{ARGP_NO_EXIT} or @code{ARGP_NO_HELP} flags are included -in @var{flags}, calling @code{argp_parse} may result in the program -exiting---for instance when an unknown option is encountered. -@xref{Program Termination}. - -The return value is zero for successful parsing, or a unix error code -(@pxref{Error Codes}) if an error was detected. Different argp parsers -may return arbitrary error codes, but standard ones are @code{ENOMEM} if -a memory allocation error occurred, or @code{EINVAL} if an unknown option -or option argument was encountered. -@end deftypefun - -@menu -* Globals: Argp Global Variables. Global argp parameters. -* Parsers: Argp Parsers. Defining parsers for use with @code{argp_parse}. -* Flags: Argp Flags. Flags that modify the behavior of @code{argp_parse}. -* Help: Argp Help. Printing help messages when not parsing. -* Examples: Argp Examples. Simple examples of programs using argp. -* Customization: Argp User Customization. - Users may control the @samp{--help} output format. -@end menu - -@node Argp Global Variables, Argp Parsers, , Argp -@subsection Argp Global Variables - -These variables make it very easy for every user program to implement -the @samp{--version} option and provide a bug-reporting address in the -@samp{--help} output (which is implemented by argp regardless). - -@comment argp.h -@comment GNU -@deftypevar {const char *} argp_program_version -If defined or set by the user program to a non-zero value, then a -@samp{--version} option is added when parsing with @code{argp_parse} -(unless the @code{ARGP_NO_HELP} flag is used), which will print this -string followed by a newline and exit (unless the @code{ARGP_NO_EXIT} -flag is used). -@end deftypevar - -@comment argp.h -@comment GNU -@deftypevar {const char *} argp_program_bug_address -If defined or set by the user program to a non-zero value, -@code{argp_program_bug_address} should point to string that is the -bug-reporting address for the program. It will be printed at the end of -the standard output for the @samp{--help} option, embedded in a sentence -that says something like @samp{Report bugs to @var{address}.}. -@end deftypevar - -@need 1500 -@comment argp.h -@comment GNU -@defvar argp_program_version_hook -If defined or set by the user program to a non-zero value, then a -@samp{--version} option is added when parsing with @code{argp_parse} -(unless the @code{ARGP_NO_HELP} flag is used), which calls this function -to print the version, and then exits with a status of 0 (unless the -@code{ARGP_NO_EXIT} flag is used). It should point to a function with -the following type signature: - -@smallexample -void @var{print-version} (FILE *@var{stream}, struct argp_state *@var{state}) -@end smallexample - -@noindent -@xref{Argp Parsing State}, for an explanation of @var{state}. - -This variable takes precedent over @code{argp_program_version}, and is -useful if a program has version information that cannot be easily -specified as a simple string. -@end defvar - -@comment argp.h -@comment GNU -@deftypevar error_t argp_err_exit_status -The exit status that argp will use when exiting due to a parsing error. -If not defined or set by the user program, this defaults to -@code{EX_USAGE} from @file{<sysexits.h>}. -@end deftypevar - -@node Argp Parsers, Argp Flags, Argp Global Variables, Argp -@subsection Specifying Argp Parsers - -The first argument to the @code{argp_parse} function is a pointer to a -@code{struct argp}, which known as an @dfn{argp parser}: - -@comment argp.h -@comment GNU -@deftp {Data Type} {struct argp} -This structure specifies how to parse a given set of options and -arguments, perhaps in conjunction with other argp parsers. It has the -following fields: - -@table @code -@item const struct argp_option *options -A pointer to a vector of @code{argp_option} structures specifying which -options this argp parser understands; it may be zero if there are no -options at all. @xref{Argp Option Vectors}. - -@item argp_parser_t parser -A pointer to a function that defines actions for this parser; it is -called for each option parsed, and at other well-defined points in the -parsing process. A value of zero is the same as a pointer to a -function that always returns @code{ARGP_ERR_UNKNOWN}. -@xref{Argp Parser Functions}. - -@item const char *args_doc -If non-zero, a string describing what non-option arguments are wanted by -this parser; it is only used to print the @samp{Usage:} message. If it -contains newlines, the strings separated by them are considered -alternative usage patterns, and printed on separate lines (lines after -the first are prefix by @samp{ or: } instead of @samp{Usage:}). - -@item const char *doc -If non-zero, a string containing extra text to be printed before and -after the options in a long help message, with the two sections -separated by a vertical tab (@code{'\v'}, @code{'\013'}) character. By -convention, the documentation before the options is just a short string -saying what the program does, and that afterwards is longer, describing -the behavior in more detail. - -@item const struct argp_child *children -A pointer to a vector of @code{argp_children} structures specifying -additional argp parsers that should be combined with this one. -@xref{Argp Children}. - -@item char *(*help_filter)(int @var{key}, const char *@var{text}, void *@var{input}) -If non-zero, a pointer to a function to filter the output of help -messages. @xref{Argp Help Filtering}. -@end table -@end deftp - -The @code{options}, @code{parser}, @code{args_doc}, and @code{doc} -fields are usually all that are needed. If an argp parser is defined as -an initialized C variable, only the used fields need be specified in in -the initializer---the rest will default to zero due to the way C -structure initialization works (this fact is exploited for most argp -structures, grouping the most-used fields near the beginning, so that -unused fields can simply be left unspecified). - -@menu -* Options: Argp Option Vectors. Specifying options in an argp parser. -* Argp Parser Functions:: Defining actions for an argp parser. -* Children: Argp Children. Combining multiple argp parsers. -* Help Filtering: Argp Help Filtering. Customizing help output for an argp parser. -@end menu - -@node Argp Option Vectors, Argp Parser Functions, Argp Parsers, Argp Parsers -@subsection Specifying Options in an Argp Parser - -The @code{options} field in a @code{struct argp} points to a vector of -@code{struct argp_option} structures, each of which specifies an option -that argp parser supports (actually, sometimes multiple entries may used -for a single option if it has many names). It should be terminated by -an entry with zero in all fields (note that when using an initialized C -array for options, writing @code{@{ 0 @}} is enough to achieve this). - -@comment argp.h -@comment GNU -@deftp {Data Type} {struct argp_option} -This structure specifies a single option that an argp parser -understands, and how to parse and document it. It has the following fields: - -@table @code -@item const char *name -The long name for this option, corresponding to the long option -@samp{--@var{name}}; this field can be zero if this option only has a -short name. To specify multiple names for an option, additional entries -may follow this one, with the @code{OPTION_ALIAS} flag set (@pxref{Argp -Option Flags}). - -@item int key -The integer key that is provided to the argp parser's parsing function -when this option is being parsed. Also, if @var{key} has a value that -is a printable @sc{ascii} character (i.e., @code{isascii (@var{key})} is -true), it @emph{also} specifies a short option @samp{-@var{char}}, where -@var{char} is the @sc{ascii} character with the code @var{key}. - -@item const char *arg -If non-zero, this is the name of an argument associated with this -option, which must be provided (e.g., with the -@samp{--@var{name}=@var{value}} or @samp{-@var{char} @var{value}} -syntaxes) unless the @code{OPTION_ARG_OPTIONAL} flag (@pxref{Argp Option -Flags}) is set, in which case it @emph{may} be provided. - -@item int flags -Flags associated with this option (some of which are referred to above). -@xref{Argp Option Flags}. - -@item const char *doc -A documentation string for this option, for printing in help messages. - -If both the @code{name} and @code{key} fields are zero, this string -will be printed out-dented from the normal option column, making it -useful as a group header (it will be the first thing printed in its -group); in this usage, it's conventional to end the string with a -@samp{:} character. - -@item int group -The group this option is in. - -In a long help message, options are sorted alphabetically within each -group, and the groups presented in the order 0, 1, 2, @dots{}, @var{n}, -@minus{}@var{m}, @dots{}, @minus{}2, @minus{}1. Every entry in an -options array with this -field 0 will inherit the group number of the previous entry, or zero if -it's the first one, unless its a group header (@code{name} and -@code{key} fields both zero), in which case, the previous entry + 1 is -the default. Automagic options such as @samp{--help} are put into group -@minus{}1. - -Note that because of C structure initialization rules, this field -often need not be specified, because 0 is the right value. -@end table -@end deftp - -@menu -* Flags: Argp Option Flags. Flags for options. -@end menu - -@node Argp Option Flags, , , Argp Option Vectors -@subsubsection Flags for Argp Options - -The following flags may be or'd together in the @code{flags} field of a -@code{struct argp_option}, and control various aspects of how that -option is parsed or displayed in help messages: - -@vtable @code -@comment argp.h -@comment GNU -@item OPTION_ARG_OPTIONAL -The argument associated with this option is optional. - -@comment argp.h -@comment GNU -@item OPTION_HIDDEN -This option isn't displayed in any help messages. - -@comment argp.h -@comment GNU -@item OPTION_ALIAS -This option is an alias for the closest previous non-alias option. This -means that it will be displayed in the same help entry, and will inherit -fields other than @code{name} and @code{key} from the aliased option. - -@comment argp.h -@comment GNU -@item OPTION_DOC -This option isn't actually an option (and so should be ignored by the -actual option parser), but rather an arbitrary piece of documentation -that should be displayed in much the same manner as the options (known -as a @dfn{documentation option}). - -If this flag is set, then the option @code{name} field is displayed -unmodified (e.g., no @samp{--} prefix is added) at the left-margin -(where a @emph{short} option would normally be displayed), and the -documentation string in the normal place. For purposes of sorting, any -leading whitespace and punctuation is ignored, except that if the first -non-whitespace character is not @samp{-}, this entry is displayed after -all options (and @code{OPTION_DOC} entries with a leading @samp{-}) in -the same group. - -@comment argp.h -@comment GNU -@item OPTION_NO_USAGE -This option shouldn't be included in `long' usage messages (but is still -included in help messages). This is mainly intended for options that -are completely documented in an argp's @code{args_doc} field -(@pxref{Argp Parsers}), in which case including the option -in the generic usage list would be redundant. - -For instance, if @code{args_doc} is @code{"FOO BAR\n-x BLAH"}, and the -@samp{-x} option's purpose is to distinguish these two cases, @samp{-x} -should probably be marked @code{OPTION_NO_USAGE}. -@end vtable - -@node Argp Parser Functions, Argp Children, Argp Option Vectors, Argp Parsers -@subsection Argp Parser Functions - -The function pointed to by the @code{parser} field in a @code{struct -argp} (@pxref{Argp Parsers}) defines what actions take place in response -to each option or argument that is parsed, and is also used as a hook, -to allow a parser to do something at certain other points during -parsing. - -@need 2000 -Argp parser functions have the following type signature: - -@cindex argp parser functions -@smallexample -error_t @var{parser} (int @var{key}, char *@var{arg}, struct argp_state *@var{state}) -@end smallexample - -@noindent -where the arguments are as follows: - -@table @var -@item key -For each option that is parsed, @var{parser} is called with a value of -@var{key} from that option's @code{key} field in the option vector -(@pxref{Argp Option Vectors}). @var{parser} is also called at other -times with special reserved keys, such as @code{ARGP_KEY_ARG} for -non-option arguments. @xref{Argp Special Keys}. - -@item arg -If @var{key} is an option, @var{arg} is the value given for it, or zero -if no value was specified. Only options that have a non-zero @code{arg} -field can ever have a value, and those must @emph{always} have a value, -unless the @code{OPTION_ARG_OPTIONAL} flag was specified (if the input -being parsed specifies a value for an option that doesn't allow one, an -error results before @var{parser} ever gets called). - -If @var{key} is @code{ARGP_KEY_ARG}, @var{arg} is a non-option argument; -other special keys always have a zero @var{arg}. - -@item state -@var{state} points to a @code{struct argp_state}, containing useful -information about the current parsing state for use by @var{parser}. -@xref{Argp Parsing State}. -@end table - -When @var{parser} is called, it should perform whatever action is -appropriate for @var{key}, and return either @code{0} for success, -@code{ARGP_ERR_UNKNOWN}, if the value of @var{key} is not handled by -this parser function, or a unix error code if a real error occurred -(@pxref{Error Codes}). - -@comment argp.h -@comment GNU -@deftypevr Macro int ARGP_ERR_UNKNOWN -Argp parser functions should return @code{ARGP_ERR_UNKNOWN} for any -@var{key} value they do not recognize, or for non-option arguments -(@code{@var{key} == ARGP_KEY_ARG}) that they do not which to handle. -@end deftypevr - -@need 3000 -A typical parser function uses a switch statement on @var{key}: - -@smallexample -error_t -parse_opt (int key, char *arg, struct argp_state *state) -@{ - switch (key) - @{ - case @var{option_key}: - @var{action} - break; - @dots{} - default: - return ARGP_ERR_UNKNOWN; - @} - return 0; -@} -@end smallexample - -@menu -* Keys: Argp Special Keys. Special values for the @var{key} argument. -* State: Argp Parsing State. What the @var{state} argument refers to. -* Functions: Argp Helper Functions. Functions to help during argp parsing. -@end menu - -@node Argp Special Keys, Argp Parsing State, , Argp Parser Functions -@subsubsection Special Keys for Argp Parser Functions - -In addition to key values corresponding to user options, the @var{key} -argument to argp parser functions may have a number of other special -values (@var{arg} and @var{state} refer to parser function arguments; -@pxref{Argp Parser Functions}): - -@vtable @code -@comment argp.h -@comment GNU -@item ARGP_KEY_ARG -This is not an option at all, but rather a command line argument, whose -value is pointed to by @var{arg}. - -When there are multiple parser functions (due to argp parsers being -combined), it's impossible to know which one wants to handle an -argument, so each is called in turn, until one returns 0 or an error -other than @code{ARGP_ERR_UNKNOWN}; if an argument is handled by no one, -@code{argp_parse} immediately returns success, without parsing any more -arguments. - -Once a parser function returns success for this key, that fact is -recorded, and the @code{ARGP_KEY_NO_ARGS} case won't be used. -@emph{However}, if while processing the argument, a parser function -decrements the @code{next} field of its @var{state} argument, the option -won't be considered processed; this is to allow you to actually modify -the argument (perhaps into an option), and have it processed again. - -@comment argp.h -@comment GNU -@item ARGP_KEY_ARGS -If a parser function returns @code{ARGP_ERR_UNKNOWN} for -@code{ARGP_KEY_ARG}, it is immediately called again with the key -@code{ARGP_KEY_ARGS}, which has a similar meaning, but is slightly more -convenient for consuming all remaining arguments. @var{arg} is 0, and -the tail of the argument vector may be found at @code{@var{state}->argv -+ @var{state}->next}. If success is returned for this key, and -@code{@var{state}->next} is unchanged, then all remaining arguments are -considered to have been consumed, otherwise, the amount by which -@code{@var{state}->next} has been adjust indicates how many were used. -For instance, here's an example that uses both, for different args: - -@smallexample -... -case ARGP_KEY_ARG: - if (@var{state}->arg_num == 0) - /* First argument */ - first_arg = @var{arg}; - else - return ARGP_KEY_UNKNOWN; /* Let the next case parse it. */ - break; -case ARGP_KEY_ARGS: - remaining_args = @var{state}->argv + @var{state}->next; - num_remaining_args = @var{state}->argc - @var{state}->next; - break; -@end smallexample - -@comment argp.h -@comment GNU -@item ARGP_KEY_END -There are no more command line arguments at all. - -@comment argp.h -@comment GNU -@item ARGP_KEY_NO_ARGS -Because it's common to want to do some special processing if there -aren't any non-option args, parser functions are called with this key if -they didn't successfully process any non-option arguments. Called just -before @code{ARGP_KEY_END} (where more general validity checks on -previously parsed arguments can take place). - -@comment argp.h -@comment GNU -@item ARGP_KEY_INIT -Passed in before any parsing is done. Afterwards, the values of each -element of the @code{child_input} field of @var{state}, if any, are -copied to each child's state to be the initial value of the @code{input} -when @emph{their} parsers are called. - -@comment argp.h -@comment GNU -@item ARGP_KEY_SUCCESS -Passed in when parsing has successfully been completed (even if there are -still arguments remaining). - -@comment argp.h -@comment GNU -@item ARGP_KEY_ERROR -Passed in if an error has occurred, and parsing terminated (in which case -a call with a key of @code{ARGP_KEY_SUCCESS} is never made). - -@comment argp.h -@comment GNU -@item ARGP_KEY_FINI -The final key ever seen by any parser (even after -@code{ARGP_KEY_SUCCESS} and @code{ARGP_KEY_ERROR}). Any resources -allocated by @code{ARGP_KEY_INIT} may be freed here (although sometimes -certain resources allocated there are to be returned to the caller after -a successful parse; in that case, those particular resources can be -freed in the @code{ARGP_KEY_ERROR} case). -@end vtable - -In all cases, @code{ARGP_KEY_INIT} is the first key seen by parser -functions, and @code{ARGP_KEY_FINI} the last (unless an error was -returned by the parser for @code{ARGP_KEY_INIT}). Other keys can occur -in one the following orders (@var{opt} refers to an arbitrary option -key): - -@table @asis -@item @var{opt}@dots{} @code{ARGP_KEY_NO_ARGS} @code{ARGP_KEY_END} @code{ARGP_KEY_SUCCESS} -The arguments being parsed contained no non-option arguments at all. - -@item ( @var{opt} | @code{ARGP_KEY_ARG} )@dots{} @code{ARGP_KEY_END} @code{ARGP_KEY_SUCCESS} -All non-option arguments were successfully handled by a parser function -(there may be multiple parser functions if multiple argp parsers were -combined). - -@item ( @var{opt} | @code{ARGP_KEY_ARG} )@dots{} @code{ARGP_KEY_SUCCESS} -Some non-option argument was unrecognized. - -This occurs when every parser function returns @code{ARGP_KEY_UNKNOWN} -for an argument, in which case parsing stops at that argument. If a -non-zero value for @var{arg_index} was passed to @code{argp_parse}, the -index of this argument is returned in it, otherwise an error occurs. -@end table - -If an error occurs (either detected by argp, or because a parser -function returned an error value), then each parser is called with -@code{ARGP_KEY_ERROR}, and no further calls are made except the final -call with @code{ARGP_KEY_FINI}. - -@node Argp Helper Functions, , Argp Parsing State, Argp Parser Functions -@subsubsection Functions For Use in Argp Parsers - -Argp provides a number of functions for the user of argp parser -functions (@pxref{Argp Parser Functions}), mostly for producing error -messages. These take as their first argument the @var{state} argument -to the parser function (@pxref{Argp Parsing State}). - -@cindex usage messages, in argp -@comment argp.h -@comment GNU -@deftypefun void argp_usage (const struct argp_state *@var{state}) -Output the standard usage message for the argp parser referred to by -@var{state} to @code{@var{state}->err_stream} and terminate the program -with @code{exit (argp_err_exit_status)} (@pxref{Argp Global Variables}). -@end deftypefun - -@cindex syntax error messages, in argp -@comment argp.h -@comment GNU -@deftypefun void argp_error (const struct argp_state *@var{state}, @w{const char *@var{fmt}, @dots{}}) -Print the printf format string @var{fmt} and following args, preceded by -the program name and @samp{:}, and followed by a @w{@samp{Try @dots{} ---help}} message, and terminate the program with an exit status of -@code{argp_err_exit_status} (@pxref{Argp Global Variables}). -@end deftypefun - -@cindex error messages, in argp -@comment argp.h -@comment GNU -@deftypefun void argp_failure (const struct argp_state *@var{state}, @w{int @var{status}, int @var{errnum},} @w{const char *@var{fmt}, @dots{}}) -Similarly to the standard gnu error-reporting function @code{error}, -print the printf format string @var{fmt} and following args, preceded by -the program name and @samp{:}, and followed by the standard unix error -text for @var{errnum} if it is non-zero; then if @var{status} is -non-zero, terminate the program with that as its exit status. - -The difference between this function and @code{argp_error} is that -@code{argp_error} is for @emph{parsing errors}, whereas -@code{argp_failure} is for other problems that occur during parsing but -don't reflect a syntactic problem with the input---such as illegal -values for options, bad phase of the moon, etc. -@end deftypefun - -@comment argp.h -@comment GNU -@deftypefun void argp_state_help (const struct argp_state *@var{state}, @w{FILE *@var{stream}}, @w{unsigned @var{flags}}) -Output a help message for the argp parser referred to by @var{state} to -@var{stream}. The @var{flags} argument determines what sort of help -message is produced. @xref{Argp Help Flags}. -@end deftypefun - -Error output is sent to @code{@var{state}->err_stream}, and the program -name printed is @code{@var{state}->name}. - -The output or program termination behavior of these functions may be -suppressed if the @code{ARGP_NO_EXIT} or @code{ARGP_NO_ERRS} flags, -respectively, were passed to @code{argp_parse}. @xref{Argp Flags}. - -This behavior is useful if an argp parser is exported for use by other -programs (e.g., by a library), and may be used in a context where it is -not desirable to terminate the program in response to parsing errors. -In argp parsers intended for such general use, calls to any of these -functions should be followed by code return of an appropriate error code -for the case where the program @emph{doesn't} terminate; for example: - -@smallexample -if (@var{bad argument syntax}) - @{ - argp_usage (@var{state}); - return EINVAL; - @} -@end smallexample - -@noindent -If it's known that a parser function will only be used when -@code{ARGP_NO_EXIT} is not set, the return may be omitted. - -@node Argp Parsing State, Argp Helper Functions, Argp Special Keys, Argp Parser Functions -@subsubsection Argp Parsing State - -The third argument to argp parser functions (@pxref{Argp Parser -Functions}) is a pointer to a @code{struct argp_state}, which contains -information about the state of the option parsing. - -@comment argp.h -@comment GNU -@deftp {Data Type} {struct argp_state} -This structure has the following fields, which may be modified as noted: - -@table @code -@item const struct argp *const root_argp -The top level argp parser being parsed. Note that this is often -@emph{not} the same @code{struct argp} passed into @code{argp_parse} by -the invoking program (@pxref{Argp}), but instead an internal argp parser -that contains options implemented by @code{argp_parse} itself (such as -@samp{--help}). - -@item int argc -@itemx char **argv -The argument vector being parsed. May be modified. - -@item int next -The index in @code{argv} of the next argument to be parsed. May be modified. - -One way to consume all remaining arguments in the input is to set -@code{@var{state}->next = @var{state}->argc} (perhaps after recording -the value of the @code{next} field to find the consumed arguments). -Also, you can cause the current option to be re-parsed by decrementing -this field, and then modifying -@code{@var{state}->argv[@var{state}->next]} to be the option that should -be reexamined. - -@item unsigned flags -The flags supplied to @code{argp_parse}. May be modified, although some -flags may only take effect when @code{argp_parse} is first invoked. -@xref{Argp Flags}. - -@item unsigned arg_num -While calling a parsing function with the @var{key} argument -@code{ARGP_KEY_ARG}, this is the number of the current arg, starting at -0, and incremented after each such call returns. At all other times, -this is the number of such arguments that have been processed. - -@item int quoted -If non-zero, the index in @code{argv} of the first argument following a -special @samp{--} argument (which prevents anything following being -interpreted as an option). Only set once argument parsing has proceeded -past this point. - -@item void *input -An arbitrary pointer passed in from the caller of @code{argp_parse}, in -the @var{input} argument. - -@item void **child_inputs -Values to pass to child parsers. This vector will be the same length as -the number of children in the current parser, and each child parser will -be given the value of @code{@var{state}->child_inputs[@var{i}]} as -@emph{its} @code{@var{state}->input} field, where @var{i} is the index -of the child in the this parser's @code{children} field. @xref{Argp -Children}. - -@item void *hook -For the parser function's use. Initialized to 0, but otherwise ignored -by argp. - -@item char *name -The name used when printing messages. This is initialized to -@code{argv[0]}, or @code{program_invocation_name} if that is -unavailable. - -@item FILE *err_stream -@itemx FILE *out_stream -Stdio streams used when argp prints something; error messages are -printed to @code{err_stream}, and all other output (such as -@samp{--help} output) to @code{out_stream}. These are initialized to -@code{stderr} and @code{stdout} respectively (@pxref{Standard Streams}). - -@item void *pstate -Private, for use by the argp implementation. -@end table -@end deftp - -@node Argp Children, Argp Help Filtering, Argp Parser Functions, Argp Parsers -@subsection Combining Multiple Argp Parsers - -The @code{children} field in a @code{struct argp} allows other argp -parsers to be combined with the referencing one to parse a single set of -arguments. It should point to a vector of @code{struct argp_child}, -terminated by an entry having a value of zero in the @code{argp} field. - -Where conflicts between combined parsers arise (for instance, if two -specify an option with the same name), they are resolved in favor of -the parent argp parsers, or earlier argp parsers in the list of children. - -@comment argp.h -@comment GNU -@deftp {Data Type} {struct argp_child} -An entry in the list of subsidiary argp parsers pointed to by the -@code{children} field in a @code{struct argp}. The fields are as follows: - -@table @code -@item const struct argp *argp -The child argp parser, or zero to end the list. - -@item int flags -Flags for this child. - -@item const char *header -If non-zero, an optional header to be printed in help output before the -child options. As a side-effect, a non-zero value forces the child -options to be grouped together; to achieve this effect without actually -printing a header string, use a value of @code{""}. As with header -strings specified in an option entry, the value conventionally has -@samp{:} as the last character. @xref{Argp Option Vectors}. - -@item int group -Where to group the child options relative to the other (`consolidated') -options in the parent argp parser. The values are the same as the -@code{group} field in @code{struct argp_option} (@pxref{Argp Option -Vectors}), but all child-groupings follow parent options at a particular -group level. If both this field and @code{header} are zero, then the -child's options aren't grouped together at all, but rather merged with -the parent options (merging the child's grouping levels with the -parents). -@end table -@end deftp - -@node Argp Flags, Argp Help, Argp Parsers, Argp -@subsection Flags for @code{argp_parse} - -The default behavior of @code{argp_parse} is designed to be convenient -for the most common case of parsing program command line argument. To -modify these defaults, the following flags may be or'd together in the -@var{flags} argument to @code{argp_parse}: - -@vtable @code -@comment argp.h -@comment GNU -@item ARGP_PARSE_ARGV0 -Don't ignore the first element of the @var{argv} argument to -@code{argp_parse}. Normally (and always unless @code{ARGP_NO_ERRS} is -set) the first element of the argument vector is skipped for option -parsing purposes, as it corresponds to the program name in a command -line. - -@comment argp.h -@comment GNU -@item ARGP_NO_ERRS -Don't print error messages for unknown options to @code{stderr}; unless -this flag is set, @code{ARGP_PARSE_ARGV0} is ignored, as @code{argv[0]} -is used as the program name in the error messages. This flag implies -@code{ARGP_NO_EXIT} (on the assumption that silent exiting upon errors -is bad behaviour). - -@comment argp.h -@comment GNU -@item ARGP_NO_ARGS -Don't parse any non-option args. Normally non-option args are parsed by -calling the parse functions with a key of @code{ARGP_KEY_ARG}, and the -actual arg as the value. This flag needn't normally be set, as the -normal behavior is to stop parsing as soon as some argument isn't -accepted by a parsing function. @xref{Argp Parser Functions}. - -@comment argp.h -@comment GNU -@item ARGP_IN_ORDER -Parse options and arguments in the same order they occur on the command -line---normally they're rearranged so that all options come first - -@comment argp.h -@comment GNU -@item ARGP_NO_HELP -Don't provide the standard long option @samp{--help}, which ordinarily -causes usage and option help information to be output to @code{stdout}, -and @code{exit (0)} called. - -@comment argp.h -@comment GNU -@item ARGP_NO_EXIT -Don't exit on errors (they may still result in error messages). - -@comment argp.h -@comment GNU -@item ARGP_LONG_ONLY -Use the gnu getopt `long-only' rules for parsing arguments. This -allows long-options to be recognized with only a single @samp{-} (for -instances, @samp{-help}), but results in a generally somewhat less -useful interface, that conflicts with the way most GNU programs work. -For this reason, its use is discouraged. - -@comment argp.h -@comment GNU -@item ARGP_SILENT -Turns off any message-printing/exiting options, specifically -@code{ARGP_NO_EXIT}, @code{ARGP_NO_ERRS}, and @code{ARGP_NO_HELP}. -@end vtable - -@node Argp Help Filtering, , Argp Children, Argp Parsers -@need 2000 -@subsection Customizing Argp Help Output - -The @code{help_filter} field in a a @code{struct argp} is a pointer to a -function to filter the text of help messages before displaying them. -They have a function signature like: - -@smallexample -char *@var{help-filter} (int @var{key}, const char *@var{text}, void *@var{input}) -@end smallexample - -@noindent -where @var{key} is either a key from an option, in which case @var{text} -is that option's help text (@pxref{Argp Option Vectors}), or one of the -special keys with names beginning with @samp{ARGP_KEY_HELP_}, describing -which other help text @var{text} is (@pxref{Argp Help Filter Keys}). - -The function should return either @var{text}, if it should be used -as-is, a replacement string, which should be allocated using -@code{malloc}, and will be freed by argp, or zero, meaning `print -nothing'. The value of @var{text} supplied is @emph{after} any -translation has been done, so if any of the replacement text also needs -translation, that should be done by the filter function. @var{input} is -either the input supplied to @code{argp_parse}, or zero, if -@code{argp_help} was called directly by the user. - -@menu -* Keys: Argp Help Filter Keys. Special @var{key} values for help filter functions. -@end menu - -@node Argp Help Filter Keys, , , Argp Help Filtering -@subsubsection Special Keys for Argp Help Filter Functions - -The following special values may be passed to an argp help filter -function as the first argument, in addition to key values for user -options, and specify which help text the @var{text} argument contains: - -@vtable @code -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_PRE_DOC -Help text preceding options. - -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_POST_DOC -Help text following options. - -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_HEADER -Option header string. - -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_EXTRA -After all other documentation; @var{text} is zero for this key. - -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_DUP_ARGS_NOTE -The explanatory note emitted when duplicate option arguments have been -suppressed. - -@comment argp.h -@comment GNU -@item ARGP_KEY_HELP_ARGS_DOC -The argument doc string (the @code{args_doc} field from the argp parser; -@pxref{Argp Parsers}). -@end vtable - -@node Argp Help, Argp Examples, Argp Flags, Argp -@subsection The @code{argp_help} Function - -Normally programs using argp need not worry too much about printing -argument-usage-type help messages, because the standard @samp{--help} -option is handled automatically by argp, and the typical error cases can -be handled using @code{argp_usage} and @code{argp_error} (@pxref{Argp -Helper Functions}). - -However, if it's desirable to print a standard help message in some -context other than parsing the program options, argp offers the -@code{argp_help} interface. - -@comment argp.h -@comment GNU -@deftypefun void argp_help (const struct argp *@var{argp}, @w{FILE *@var{stream}}, @w{unsigned @var{flags}}, @w{char *@var{name}}) -Output a help message for the argp parser @var{argp} to @var{stream}. -What sort of messages is printed is determined by @var{flags}. - -Any options such as @samp{--help} that are implemented automatically by -argp itself will @emph{not} be present in the help output; for this -reason, it is better to use @code{argp_state_help} if calling from -within an argp parser function. @xref{Argp Helper Functions}. -@end deftypefun - -@menu -* Flags: Argp Help Flags. Specifying what sort of help message to print. -@end menu - -@node Argp Help Flags, , , Argp Help -@subsection Flags for the @code{argp_help} Function - -When calling @code{argp_help} (@pxref{Argp Help}), or -@code{argp_state_help} (@pxref{Argp Helper Functions}), exactly what is -output is determined by the @var{flags} argument, which should consist -of any of the following flags, or'd together: - -@vtable @code -@item ARGP_HELP_USAGE -A unix @samp{Usage:} message that explicitly lists all options. - -@item ARGP_HELP_SHORT_USAGE -A unix @samp{Usage:} message that displays only an appropriate -placeholder to indicate where the options go; useful for showing -the non-option argument syntax. - -@item ARGP_HELP_SEE -A @samp{Try @dots{} for more help} message; @samp{@dots{}} contains the -program name and @samp{--help}. - -@item ARGP_HELP_LONG -A verbose option help message that gives each option understood along -with its documentation string. - -@item ARGP_HELP_PRE_DOC -The part of the argp parser doc string that precedes the verbose option help. - -@item ARGP_HELP_POST_DOC -The part of the argp parser doc string that follows the verbose option help. - -@item ARGP_HELP_DOC -@code{(ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)} - -@item ARGP_HELP_BUG_ADDR -A message saying where to report bugs for this program, if the -@code{argp_program_bug_address} variable contains one. - -@item ARGP_HELP_LONG_ONLY -Modify any output appropriately to reflect @code{ARGP_LONG_ONLY} mode. -@end vtable - -The following flags are only understood when used with -@code{argp_state_help}, and control whether the function returns after -printing its output, or terminates the program: - -@vtable @code -@item ARGP_HELP_EXIT_ERR -Terminate the program with @code{exit (argp_err_exit_status)}. - -@item ARGP_HELP_EXIT_OK -Terminate the program with @code{exit (0)}. -@end vtable - -The following flags are combinations of the basic ones for printing -standard messages: - -@vtable @code -@item ARGP_HELP_STD_ERR -Assuming an error message for a parsing error has already printed, -prints a note on how to get help, and terminates the program with an -error. - -@item ARGP_HELP_STD_USAGE -Prints a standard usage message and terminates the program with an -error. This is used when no more specific error message is appropriate. - -@item ARGP_HELP_STD_HELP -Prints the standard response for a @samp{--help} option, and terminates -the program successfully. -@end vtable - -@node Argp Examples, Argp User Customization, Argp Help, Argp -@subsection Argp Examples - -These example programs demonstrate the basic usage of argp. - -@menu -* 1: Argp Example 1. A minimal program using argp. -* 2: Argp Example 2. A program using only default options. -* 3: Argp Example 3. A simple program with user options. -* 4: Argp Example 4. Combining multiple argp parsers. -@end menu - -@node Argp Example 1, Argp Example 2, , Argp Examples -@subsubsection A Minimal Program Using Argp - -This is (probably) the smallest possible program that uses argp. -It won't do much except give an error messages and exit when there are any -arguments, and print a (rather pointless) message for @samp{--help}. - -@smallexample -@end smallexample - -@node Argp Example 2, Argp Example 3, Argp Example 1, Argp Examples -@subsubsection A Program Using Argp with Only Default Options - -This program doesn't use any options or arguments, but uses argp to be -compliant with the GNU standard command line format. - -In addition to making sure no arguments are given, and implementing a -@samp{--help} option, this example will have a @samp{--version} option, -and will put the given documentation string and bug address in the -@samp{--help} output, as per GNU standards. - -The variable @code{argp} contains the argument parser specification; -adding fields to this structure is the way most parameters are passed to -@code{argp_parse} (the first three fields are usually used, but not in -this small program). There are also two global variables that argp -knows about defined here, @code{argp_program_version} and -@code{argp_program_bug_address} (they are global variables because they -will almost always be constant for a given program, even if it uses -different argument parsers for various tasks). - -@smallexample -@end smallexample - -@node Argp Example 3, Argp Example 4, Argp Example 2, Argp Examples -@subsubsection A Program Using Argp with User Options - -This program uses the same features as example 2, and adds user options -and arguments. - -We now use the first four fields in @code{argp} (@pxref{Argp Parsers}), -and specifies @code{parse_opt} as the parser function (@pxref{Argp -Parser Functions}). - -Note that in this example, @code{main} uses a structure to communicate -with the @code{parse_opt} function, a pointer to which it passes in the -@code{input} argument to @code{argp_parse} (@pxref{Argp}), and is -retrieved by @code{parse_opt} through the @code{input} field in its -@code{state} argument (@pxref{Argp Parsing State}). Of course, it's -also possible to use global variables instead, but using a structure -like this is somewhat more flexible and clean. - -@smallexample -@end smallexample - -@node Argp Example 4, , Argp Example 3, Argp Examples -@subsubsection A Program Using Multiple Combined Argp Parsers - -This program uses the same features as example 3, but has more options, -and somewhat more structure in the @samp{--help} output. It also shows -how you can `steal' the remainder of the input arguments past a certain -point, for programs that accept a list of items, and the special -@var{key} value @code{ARGP_KEY_NO_ARGS}, which is only given if no -non-option arguments were supplied to the program (@pxref{Argp Special -Keys}). - -For structuring the help output, two features are used: @emph{headers}, -which are entries in the options vector (@pxref{Argp Option Vectors}) -with the first four fields being zero, and a two part documentation -string (in the variable @code{doc}), which allows documentation both -before and after the options (@pxref{Argp Parsers}); the -two parts of @code{doc} are separated by a vertical-tab character -(@code{'\v'}, or @code{'\013'}). By convention, the documentation -before the options is just a short string saying what the program does, -and that afterwards is longer, describing the behavior in more detail. -All documentation strings are automatically filled for output, although -newlines may be included to force a line break at a particular point. -All documentation strings are also passed to the @code{gettext} -function, for possible translation into the current locale. - -@smallexample -@end smallexample - -@node Argp User Customization, , Argp Examples, Argp -@subsection Argp User Customization - -@cindex ARGP_HELP_FMT environment variable -The way formatting of argp @samp{--help} output may be controlled to -some extent by a program's users, by setting the @code{ARGP_HELP_FMT} -environment variable to a comma-separated list (whitespace is ignored) -of the following tokens: - -@table @samp -@item dup-args -@itemx no-dup-args -Turn @dfn{duplicate-argument-mode} on or off. In duplicate argument -mode, if an option which accepts an argument has multiple names, the -argument is shown for each name; otherwise, it is only shown for the -first long option, and a note is emitted later so the user knows that it -applies to the other names as well. The default is @samp{no-dup-args}, -which is less consistent, but prettier. - -@item dup-args-note -@item no-dup-args-note -Enable or disable the note informing the user of suppressed option -argument duplication. The default is @samp{dup-args-note}. - -@item short-opt-col=@var{n} -Show the first short option in column @var{n} (default 2). - -@item long-opt-col=@var{n} -Show the first long option in column @var{n} (default 6). - -@item doc-opt-col=@var{n} -Show `documentation options' (@pxref{Argp Option Flags}) in column -@var{n} (default 2). - -@item opt-doc-col=@var{n} -Show the documentation for options starting in column @var{n} (default 29). - -@item header-col=@var{n} -Indent group headers (which document groups of options) to column -@var{n} (default 1). - -@item usage-indent=@var{n} -Indent continuation lines in @samp{Usage:} messages to column @var{n} -(default 12). - -@item rmargin=@var{n} -Word wrap help output at or before column @var{n} (default 79). -@end table diff --git a/support/canonicalize.c b/support/canonicalize.c deleted file mode 100644 index 80cd7cff..00000000 --- a/support/canonicalize.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Return the canonical absolute name of a given file. - Copyright (C) 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <limits.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <errno.h> - -#include <argp-namefrob.h> - -/* Return the canonical absolute name of file NAME. A canonical name - does not contain any `.', `..' components nor any repeated path - separators ('/') or symlinks. All path components must exist. If - RESOLVED is null, the result is malloc'd; otherwise, if the - canonical name is PATH_MAX chars or more, returns null with `errno' - set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, - returns the name in RESOLVED. If the name cannot be resolved and - RESOLVED is non-NULL, it contains the path of the first component - that cannot be resolved. If the path can be resolved, RESOLVED - holds the same value as the value returned. */ - -static char * -canonicalize (const char *name, char *resolved) -{ - char *rpath, *dest, *extra_buf = NULL; - const char *start, *end, *rpath_limit; - long int path_max; - int num_links = 0; - -#ifdef PATH_MAX - path_max = PATH_MAX; -#else - path_max = pathconf (name, _PC_PATH_MAX); - if (path_max <= 0) - path_max = 1024; -#endif - - rpath = resolved ? __alloca (path_max) : malloc (path_max); - rpath_limit = rpath + path_max; - - if (name[0] != '/') - { - if (!getcwd (rpath, path_max)) - goto error; - dest = strchr (rpath, '\0'); - } - else - { - rpath[0] = '/'; - dest = rpath + 1; - } - - for (start = end = name; *start; start = end) - { - struct stat st; - int n; - - /* skip sequence of multiple path-separators: */ - while (*start == '/') ++start; - - /* find end of path component: */ - for (end = start; *end && *end != '/'; ++end); - - if (end - start == 0) - break; - else if (strncmp (start, ".", end - start) == 0) - /* nothing */; - else if (strncmp (start, "..", end - start) == 0) { - /* back up to previous component, ignore if at root already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } else - { - size_t new_size; - - if (dest[-1] != '/') - *dest++ = '/'; - - if (dest + (end - start) >= rpath_limit) - { - if (resolved) - { - __set_errno (ENAMETOOLONG); - goto error; - } - new_size = rpath_limit - rpath; - if (end - start + 1 > path_max) - new_size += end - start + 1; - else - new_size += path_max; - rpath = realloc (rpath, new_size); - rpath_limit = rpath + new_size; - if (!rpath) - return NULL; - } - - memcpy (dest, start, end - start); - dest += end - start; - *dest = '\0'; - - if (__lstat (rpath, &st) < 0) - goto error; - - if (S_ISLNK (st.st_mode)) - { - char *buf = __alloca (path_max); - - if (++num_links > MAXSYMLINKS) - { - __set_errno (ELOOP); - goto error; - } - - n = readlink (rpath, buf, path_max); - if (n < 0) - goto error; - buf[n] = '\0'; - - if (!extra_buf) - extra_buf = __alloca (path_max); - - if ((long int) (n + strlen (end)) >= path_max) - { - __set_errno (ENAMETOOLONG); - goto error; - } - - /* careful here, end may be a pointer into extra_buf... */ - strcat (buf, end); - strcpy (extra_buf, buf); - name = end = extra_buf; - - if (buf[0] == '/') - dest = rpath + 1; /* it's an absolute symlink */ - else - /* back up to previous component, ignore if at root already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } - else - num_links = 0; - } - } - if (dest > rpath + 1 && dest[-1] == '/') - --dest; - *dest = '\0'; - - return resolved ? strcpy (resolved, rpath) : rpath; - -error: - if (resolved) - strcpy (resolved, rpath); - else - free (rpath); - return NULL; -} - -char * -realpath (const char *name, char *resolved) -{ - if (resolved == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - return canonicalize (name, resolved); -} - -#if 0 -char * -canonicalize_file_name (const char *name) -{ - return canonicalize (name, NULL); -} -#endif diff --git a/support/easy-vsnprintf.c b/support/easy-vsnprintf.c deleted file mode 100644 index b50df741..00000000 --- a/support/easy-vsnprintf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* (v)snprintf in terms of __(v)snprintf - * - * Useful with Solaris 2.5 libc, which appears to have the `__*' versions - * of (v)snprintf. - * - * This file is in the public domain - * (in case it matters) - */ - -#include <stdarg.h> -#include <stdlib.h> - -extern int __vsnprintf (char *, size_t, const char *, va_list); - -int -vsnprintf (char *string, size_t maxlen, const char *format, va_list args) -{ - return __vsnprintf (string, maxlen, format, args); -} - -int -snprintf (char *string, size_t maxlen, const char *format, ...) -{ - va_list args; - int retval; - va_start(args, format); - retval = vsnprintf (string, maxlen, format, args); - va_end(args); - return retval; -} diff --git a/support/error.c b/support/error.c deleted file mode 100644 index b0264bc6..00000000 --- a/support/error.c +++ /dev/null @@ -1,254 +0,0 @@ -/* Error handler for noninteractive utilities - Copyright (C) 1990,91,92,93,94,95,96,97,98 Free Software Foundation, Inc. - - This file is part of the GNU C Library. Its master source is NOT part of - the C library, however. The master source lives in /gd/gnu/lib. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gnomesupport-fake.h> - -#include <stdio.h> - -#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC -# if __STDC__ -# include <stdarg.h> -# define VA_START(args, lastarg) va_start(args, lastarg) -# else -# include <varargs.h> -# define VA_START(args, lastarg) va_start(args) -# endif -#else -# define va_alist a1, a2, a3, a4, a5, a6, a7, a8 -# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; -#endif - -#if STDC_HEADERS || _LIBC -# include <stdlib.h> -# include <string.h> -#else -void exit (); -#endif - -#include "error.h" - -#ifndef _ -# define _(String) String -#endif - -/* If NULL, error will flush stdout, then print on stderr the program - name, a colon and a space. Otherwise, error will call this - function without parameters instead. */ -void (*error_print_progname) ( -#if __STDC__ - 0 - void -#endif - ); - -/* This variable is incremented each time `error' is called. */ -unsigned int error_message_count; - -#if HAVE_PROGRAM_INVOCATION_NAME || _LIBC -/* In the GNU C library, there is a predefined variable for this. */ - -# define program_name program_invocation_name -# include <errno.h> - -#else - -/* The calling program should define program_name and set it to the - name of the executing program. */ -extern char *program_name; - -#endif - -#ifdef _LIBC -/* In GNU libc we want do not want to use the common name `error' directly. - Instead make it a weak alias. */ -# define error __error -# define error_at_line __error_at_line - -# define strerror_r __strerror_r - -#else /* not _LIBC */ - -# if ! HAVE_STRERROR_R -# if HAVE_STRERROR -# ifndef strerror /* On some systems, strerror is a macro */ -char *strerror (); -# endif -# else -static char * -private_strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum > 0 && errnum <= sys_nerr) - return _(sys_errlist[errnum]); - return _("Unknown system error"); -} -# define strerror private_strerror -# endif /* HAVE_STRERROR */ -# endif /* ! HAVE_STRERROR_R */ -#endif /* not _LIBC */ - -/* Print the program name and error message MESSAGE, which is a printf-style - format string with optional args. - If ERRNUM is nonzero, print its corresponding system error message. - Exit with status STATUS if it is nonzero. */ -/* VARARGS */ - -void -#if defined VA_START && __STDC__ -error (int status, int errnum, const char *message, ...) -#else -error (status, errnum, message, va_alist) - int status; - int errnum; - char *message; - va_dcl -#endif -{ -#ifdef VA_START - va_list args; -#endif - - if (error_print_progname) - (*error_print_progname) (); - else - { - fflush (stdout); - fprintf (stderr, "%s: ", program_name); - } - -#ifdef VA_START - VA_START (args, message); -# if HAVE_VPRINTF || _LIBC - vfprintf (stderr, message, args); -# else - _doprnt (message, args, stderr); -# endif - va_end (args); -#else - fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); -#endif - - ++error_message_count; - if (errnum) - { -#if defined HAVE_STRERROR_R || defined _LIBC - char errbuf[1024]; - fprintf (stderr, ": %s", strerror_r (errnum, errbuf, sizeof errbuf)); -#else - fprintf (stderr, ": %s", strerror (errnum)); -#endif - } - putc ('\n', stderr); - fflush (stderr); - if (status) - exit (status); -} - -/* Sometimes we want to have at most one error per line. This - variable controls whether this mode is selected or not. */ -int error_one_per_line; - -void -#if defined VA_START && __STDC__ -error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, ...) -#else -error_at_line (status, errnum, file_name, line_number, message, va_alist) - int status; - int errnum; - const char *file_name; - unsigned int line_number; - char *message; - va_dcl -#endif -{ -#ifdef VA_START - va_list args; -#endif - - if (error_one_per_line) - { - static const char *old_file_name; - static unsigned int old_line_number; - - if (old_line_number == line_number && - (file_name == old_file_name || !strcmp (old_file_name, file_name))) - /* Simply return and print nothing. */ - return; - - old_file_name = file_name; - old_line_number = line_number; - } - - if (error_print_progname) - (*error_print_progname) (); - else - { - fflush (stdout); - fprintf (stderr, "%s:", program_name); - } - - if (file_name != NULL) - fprintf (stderr, "%s:%d: ", file_name, line_number); - -#ifdef VA_START - VA_START (args, message); -# if HAVE_VPRINTF || _LIBC - vfprintf (stderr, message, args); -# else - _doprnt (message, args, stderr); -# endif - va_end (args); -#else - fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); -#endif - - ++error_message_count; - if (errnum) - { -#if defined HAVE_STRERROR_R || defined _LIBC - char errbuf[1024]; - fprintf (stderr, ": %s", strerror_r (errnum, errbuf, sizeof errbuf)); -#else - fprintf (stderr, ": %s", strerror (errnum)); -#endif - } - putc ('\n', stderr); - fflush (stderr); - if (status) - exit (status); -} - -#ifdef _LIBC -/* Make the weak alias. */ -# undef error -# undef error_at_line -weak_alias (__error, error) -weak_alias (__error_at_line, error_at_line) -#endif diff --git a/support/error.h b/support/error.h deleted file mode 100644 index 0d3bcb7a..00000000 --- a/support/error.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Declaration for error-reporting function - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. - - This file is part of the GNU C Library. Its master source is NOT part of - the C library, however. The master source lives in /gd/gnu/lib. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _ERROR_H -#define _ERROR_H 1 - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined (__STDC__) && __STDC__ - -/* Print a message with `fprintf (stderr, FORMAT, ...)'; - if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). - If STATUS is nonzero, terminate the program with `exit (STATUS)'. */ - -extern void error (int status, int errnum, const char *format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); - -extern void error_at_line (int status, int errnum, const char *fname, - unsigned int lineno, const char *format, ...) - __attribute__ ((__format__ (__printf__, 5, 6))); - -/* If NULL, error will flush stdout, then print on stderr the program - name, a colon and a space. Otherwise, error will call this - function without parameters instead. */ -extern void (*error_print_progname) (void); - -#else -void error (); -void error_at_line (); -extern void (*error_print_progname) (); -#endif - -/* This variable is incremented each time `error' is called. */ -extern unsigned int error_message_count; - -/* Sometimes we want to have at most one error per line. This - variable controls whether this mode is selected or not. */ -extern int error_one_per_line; - -#ifdef __cplusplus -} -#endif - -#endif /* error.h */ diff --git a/support/findme.c b/support/findme.c deleted file mode 100644 index 1cda62c5..00000000 --- a/support/findme.c +++ /dev/null @@ -1,60 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#ifdef __NeXT -/* access macros are not declared in non posix mode in unistd.h - - don't try to use posix on NeXTstep 3.3 ! */ -#include <libc.h> -#endif - -#if HAVE_ALLOCA_H -# include <alloca.h> -#endif - -#include "findme.h" - -char * findProgramPath(char * argv0) { - char * path = getenv("PATH"); - char * pathbuf; - char * start, * chptr; - char * buf; - - /* If there is a / in the argv[0], it has to be an absolute - path */ - if (strchr(argv0, '/')) - return strdup(argv0); - - if (!path) return NULL; - - start = pathbuf = alloca(strlen(path) + 1); - buf = malloc(strlen(path) + strlen(argv0) + 2); - strcpy(pathbuf, path); - - chptr = NULL; - do { - if ((chptr = strchr(start, ':'))) - *chptr = '\0'; - sprintf(buf, "%s/%s", start, argv0); - - if (!access(buf, X_OK)) - return buf; - - if (chptr) - start = chptr + 1; - else - start = NULL; - } while (start && *start); - - free(buf); - - return NULL; -} diff --git a/support/findme.h b/support/findme.h deleted file mode 100644 index fdd01d52..00000000 --- a/support/findme.h +++ /dev/null @@ -1,10 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifndef H_FINDME -#define H_FINDME - -char * findProgramPath(char * argv0); - -#endif diff --git a/support/getopt.c b/support/getopt.c deleted file mode 100644 index 31999258..00000000 --- a/support/getopt.c +++ /dev/null @@ -1,1041 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97 - Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. - Ditto for AIX 3.2 and <stdlib.h>. */ -#ifndef _NO_PROTO -#define _NO_PROTO -#endif - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#if !defined (__STDC__) || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include <stdio.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 -#include <gnu-versions.h> -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -#define ELIDE_CODE -#endif -#endif - -#ifndef ELIDE_CODE - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -#include <stdlib.h> -#include <unistd.h> -#endif /* GNU C library. */ - -#ifdef VMS -#include <unixlib.h> -#if HAVE_STRING_H - 0 -#include <string.h> -#endif -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ -#ifdef HAVE_LIBINTL_H -# include <libintl.h> -# define _(msgid) gettext (msgid) -#else -# define _(msgid) (msgid) -#endif -#endif - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg = NULL; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* 1003.2 says this must be 1 before any call. */ -int optind = 1; - -/* Formerly, initialization of getopt depended on optind==0, which - causes problems with re-calling getopt as programs generally don't - know that. */ - -int __getopt_initialized = 0; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int optopt = '?'; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return -1 with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -/* Value of POSIXLY_CORRECT environment variable. */ -static char *posixly_correct; - -#ifdef __GNU_LIBRARY__ -/* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -#include <string.h> -#define my_index strchr -#else - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -char *getenv (); - -static char * -my_index (str, chr) - const char *str; - int chr; -{ - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; -} - -/* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ -#ifdef __GNUC__ -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ -#if !defined (__STDC__) || !__STDC__ -/* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); -#endif /* not __STDC__ */ -#endif /* __GNUC__ */ - -#endif /* not __GNU_LIBRARY__ */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -#ifdef _LIBC -/* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ - -/* Defined in getopt_init.c */ -extern char *__getopt_nonoption_flags; - -static int nonoption_flags_max_len; -static int nonoption_flags_len; - -static int original_argc; -static char *const *original_argv; - -/* Make sure the environment variable bash 2.0 puts in the environment - is valid for the getopt call we must make sure that the ARGV passed - to getopt is that one passed to the process. */ -static void -__attribute__ ((unused)) -store_args_and_env (int argc, char *const *argv) -{ - /* XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ - original_argc = argc; - original_argv = argv; -} -# ifdef text_set_element -text_set_element (__libc_subinit, store_args_and_env); -# endif /* text_set_element */ - -# define SWAP_FLAGS(ch1, ch2) \ - if (nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } -#else /* !_LIBC */ -# define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -#if defined (__STDC__) && __STDC__ -static void exchange (char **); -#endif - -static void -exchange (argv) - char **argv; -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - -#ifdef _LIBC - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); - if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - nonoption_flags_max_len), - '\0', top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } -#endif - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -/* Initialize the internal data when the first call is made. */ - -#if defined (__STDC__) && __STDC__ -static const char *_getopt_initialize (int, char *const *, const char *); -#endif -static const char * -_getopt_initialize (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - first_nonopt = last_nonopt = optind; - - nextchar = NULL; - - posixly_correct = getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - -#ifdef _LIBC - if (posixly_correct == NULL - && argc == original_argc && argv == original_argv) - { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '\0') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '\0', nonoption_flags_max_len - len); - } - } - nonoption_flags_len = nonoption_flags_max_len; - } - else - nonoption_flags_len = 0; -#endif - - return optstring; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns -1. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; -{ - optarg = NULL; - - if (optind == 0 || !__getopt_initialized) - { - if (optind == 0) - optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring); - __getopt_initialized = 1; - } - - /* Test whether ARGV[optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ -#ifdef _LIBC -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ - || (optind < nonoption_flags_len \ - && __getopt_nonoption_flags[optind] == '1')) -#else -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') -#endif - - if (nextchar == NULL || *nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ - if (last_nonopt > optind) - last_nonopt = optind; - if (first_nonopt > optind) - first_nonopt = optind; - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc && NONOPTION_P) - optind++; - last_nonopt = optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (opterr) - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], pfound->name); - - nextchar += strlen (nextchar); - - optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') - { - if (opterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - optopt = c; - return '?'; - } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - - /* optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (opterr) - fprintf (stderr, _("\ -%s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } - } - return c; - } -} - -int -getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); -} - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/support/getopt.h b/support/getopt.h deleted file mode 100644 index 9b25f902..00000000 --- a/support/getopt.h +++ /dev/null @@ -1,135 +0,0 @@ -/* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _GETOPT_H -#define _GETOPT_H 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -extern int opterr; - -/* Set to an option character which was unrecognized. */ - -extern int optopt; - -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ -#if defined (__STDC__) && __STDC__ - const char *name; -#else - char *name; -#endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct option'. */ - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -#if defined (__STDC__) && __STDC__ -#ifdef __GNU_LIBRARY__ -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int getopt (int argc, char *const *argv, const char *shortopts); -#else /* not __GNU_LIBRARY__ */ -#ifndef __cplusplus -/* C++ is more pedantic, and demands a full prototype, not this. - Hope that stdlib.h has a prototype for `getopt'. */ -extern int getopt (); -#endif /* __cplusplus */ -#endif /* __GNU_LIBRARY__ */ -extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); -extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind); - -/* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind, - int long_only); -#else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); -#endif /* __STDC__ */ - -#ifdef __cplusplus -} -#endif - -#endif /* getopt.h */ diff --git a/support/getopt1.c b/support/getopt1.c deleted file mode 100644 index 4aa8de6f..00000000 --- a/support/getopt1.c +++ /dev/null @@ -1,187 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "getopt.h" - -#if !defined (__STDC__) || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include <stdio.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 -#include <gnu-versions.h> -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -#define ELIDE_CODE -#endif -#endif - -#ifndef ELIDE_CODE - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include <stdlib.h> -#endif - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -#include <stdio.h> - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/support/gnome-argp.c b/support/gnome-argp.c deleted file mode 100644 index 8f908628..00000000 --- a/support/gnome-argp.c +++ /dev/null @@ -1,12 +0,0 @@ -/* Gnome-specific code to help with argp integration. - Written by Tom Tromey <tromey@cygnus.com>. */ - -#include <config.h> - -#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME -char *program_invocation_short_name; -#endif - -#ifndef HAVE_PROGRAM_INVOCATION_NAME -char *program_invocation_name; -#endif diff --git a/support/gnome-argp.h b/support/gnome-argp.h deleted file mode 100644 index fc18a87f..00000000 --- a/support/gnome-argp.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Gnome-specific code to help with argp integration. - Written by Tom Tromey <tromey@cygnus.com>. */ - -#ifndef __GNOME_ARGP_H__ -#define __GNOME_ARGP_H__ - -#ifndef HAVE_STRNDUP -/* Like strdup, but only copy N chars. */ -extern char *strndup (const char *s, size_t n); -#endif - -/* Some systems, like Red Hat 4.0, define these but don't declare - them. Hopefully it is safe to always declare them here. */ -extern char *program_invocation_short_name; -extern char *program_invocation_name; - -#define __mempcpy(To,From,Len) ((char *)memcpy ((To), (From), (Len)) + (Len)) - -#endif /* __GNOME_ARGP_H__ */ diff --git a/support/gnomesupport-fake.h b/support/gnomesupport-fake.h deleted file mode 100644 index a6423d09..00000000 --- a/support/gnomesupport-fake.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GNOMESUPPORT_FAKE_H_ -#define GNOMESUPPORT_FAKE_H_ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stddef.h> -/* ??? This is required to get `size_t' on some systems. */ -#include <sys/types.h> - -#include <gnomesupport.h> - -#include <gnome-argp.h> - -/* Override some of config.h. - Gnomesupport provides the replacements for these, so you actually - HAVE_ them. */ - -#ifndef HAVE_STRERROR -# define HAVE_STRERROR 1 -#endif - -#ifndef HAVE_PROGRAM_INVOCATION_NAME -# define HAVE_PROGRAM_INVOCATION_NAME 1 -#endif - -#endif /* GNOMESUPPORT_FAKE_H_ */ diff --git a/support/gnomesupport.awk b/support/gnomesupport.awk deleted file mode 100644 index e529be52..00000000 --- a/support/gnomesupport.awk +++ /dev/null @@ -1,209 +0,0 @@ -# This program is used to generate gnomesupport.h - -# Print prologue -BEGIN { - print "/* gnomesupport.h */"; - print "/* This is a generated file. Please modify `gnomesupport.awk' */"; - print ""; - print "#ifndef GNOMESUPPORT_H"; - print "#define GNOMESUPPORT_H"; - print ""; - print "#ifdef __cplusplus"; - print "extern \"C\" {"; - print "#endif /* __cplusplus */"; - print ""; - print "#include <stddef.h> /* for size_t */"; -} - -# For each `#define HAVE_FOO 1', set def["HAVE_FOO"] = 1 -/^\#define[ \t]/ { def[$2] = 1; } - -END { - if (!def["HAVE_VASPRINTF"] || !def["HAVE_VSNPRINTF"]) { - print ""; - print "#include <stdarg.h>"; - } - - if (!def["HAVE_SCANDIR"]) { - print ""; - print "#include <sys/types.h>"; - - if (def["HAVE_DIRENT_H"]) { - print "#include <dirent.h>"; - print "#define NAMLEN(dirent) strlen((dirent)->d_name)"; - } else { - print "#define dirent direct"; - print "#define NAMLEN(dirent) (dirent)->d_namlen"; - - if (def["HAVE_SYS_NDIR_H"]) - print "#include <sys/ndir.h>"; - if (def["HAVE_SYS_DIR_H"]) - print "#include <sys/dir.h>"; - if (def["HAVE_NDIR_H"]) - print "#include <ndir.h>"; - } - } - - if (def["NEED_DECLARATION_GETHOSTNAME"]) { - print ""; - print "/* Get name of current host. */"; - print "int gethostname(char */*name*/, int /*namelen*/);"; - } - - if (def["NEED_DECLARATION_SETREUID"]) { - print ""; - print "/* Set real and effective user ID. */"; - print "int setreuid(uid_t /*ruid*/, uid_t /*euid*/);"; - } - - if (def["NEED_DECLARATION_SETREGID"]) { - print ""; - print "/* Set real and effective group ID. */"; - print "int setregid(gid_t /*rgid*/, gid_t /*egid*/);"; - } - - if (def["NEED_DECLARATION_GETPAGESIZE"]) { - print ""; - print "/* Get system page size. */"; - print "size_t getpagesize(void);"; - } - - if (!def["HAVE_MEMMOVE"]) { - print ""; - print "/* Copies len bytes from src to dest. */"; - print "void * memmove (void */*dest*/, const void */*src*/, size_t /*len*/);"; - } - - if (!def["HAVE_MKSTEMP"]) { - print ""; - print "/* Generate a unique temporary file name from TEMPLATE."; - print " The last six characters of TEMPLATE must be "XXXXXX";"; - print " they are replaced with a string that makes the filename"; - print " unique. Returns a file descriptor open on the file for"; - print " reading and writing. */"; - print "int mkstemp (char */*template*/);"; - } - - if (!def["HAVE_SCANDIR"]) { - print ""; - print "/* Scan the directory DIR, calling SELECTOR on each directory"; - print " entry. Entries for which SELECTOR returns nonzero are"; - print " individually malloc'd, sorted using qsort with CMP, and"; - print " collected in a malloc'd array in *NAMELIST. Returns the"; - print " number of entries selected, or -1 on error. */"; - print "int scandir (const char */*dir*/, struct dirent ***/*namelist*/,"; - print " int (*/*selector*/) (struct dirent *),"; - print " int (*/*cmp*/) (const void *, const void *));"; - print ""; - print "/* Function to compare two `struct dirent's alphabetically. */"; - print "int alphasort (const void */*a*/, const void */*b*/);"; - } - - if (!def["HAVE_STRERROR"]) { - print ""; - print "/* Return a string describing the meaning of the `errno' code"; - print " in ERRNUM. */"; - print "extern char *strerror (int /*errnum*/);"; - } - - if (!def["HAVE_STRCASECMP"]) { - print ""; - print "/* Compare S1 and S2, ignoring case. */"; - print "int strcasecmp (const char */*s1*/, const char */*s2*/);"; - } - - if (!def["HAVE_STRNDUP"]) { - print ""; - print "/* Return a malloc'd copy of at most N bytes of STRING. The"; - print " resultant string is terminated even if no null terminator"; - print " appears before STRING[N]. */"; - print "char * strndup (const char */*s*/, size_t /*n*/);"; - } - - if (!def["HAVE_STRNLEN"]) { - print ""; - print "/* Find the length of STRING, but scan at most MAXLEN"; - print " characters. If no '\\0' terminator is found in that many"; - print " characters, return MAXLEN. */"; - print "size_t strnlen (const char */*string*/, size_t /*maxlen*/);"; - } - - if (!def["HAVE_STRTOK_R"]) { - print ""; - print "/* Divide S into tokens separated by characters in DELIM."; - print " Information passed between calls are stored in SAVE_PTR. */"; - print "char * strtok_r (char */*s*/, const char */*delim*/,"; - print " char **/*save_ptr*/);"; - } - - if (!def["HAVE_STRTOD"]) { - print ""; - print "/* Convert the initial portion of the string pointed to by"; - print " nptr to double representation and return the converted value."; - print " If endptr is not NULL, a pointer to the character after the"; - print " last character used in the conversion is stored in the"; - print " location referenced by endptr. */"; - print "double strtod (const char */*nptr*/, char **/*endptr*/);"; - } - - if (!def["HAVE_STRTOL"]) { - print ""; - print "/* Convert the initial portion of the string pointed to by"; - print " nptr to a long integer value according to the given base."; - print " If endptr is not NULL, a pointer to the character after the"; - print " last character used in the conversion is stored in the"; - print " location referenced by endptr. */"; - print "long int strtol (const char */*nptr*/, char **/*endptr*/, int /*base*/);"; - } - - if (!def["HAVE_STRTOUL"]) { - print ""; - print "/* Convert the initial portion of the string pointed to by"; - print " nptr to an unsigned long integer value according to the given base."; - print " If endptr is not NULL, a pointer to the character after the"; - print " last character used in the conversion is stored in the"; - print " location referenced by endptr. */"; - print "unsigned long int strtoul (const char */*nptr*/, char **/*endptr*/,"; - print " int /*base*/);"; - } - - if (!def["HAVE_VASPRINTF"]) { - print ""; - print "/* Write formatted output to a string dynamically allocated with"; - print " `malloc'. Store the address of the string in *PTR. */"; - print "int vasprintf (char **/*ptr*/, const char */*format*/,"; - print " va_list /*args*/);"; - print "int asprintf (char **/*ptr*/, const char */*format*/, ...);"; - } - - if (!def["HAVE_VSNPRINTF"]) { - print ""; - print "/* Maximum chars of output to write is MAXLEN. */"; - print "int vsnprintf (char */*str*/, size_t /*maxlen*/,"; - print " char */*fmt*/, va_list /*ap*/);"; - print "int snprintf (char */*str*/, size_t /*maxlen*/,"; - print " char */*fmt*/, ...);"; - } - - if (!def["HAVE_REALPATH"]) { - print ""; - print "/* Return the canonical absolute name of file NAME. A canonical name"; - print " does not contain any `.', `..' components nor any repeated path"; - print " separators ('/') or symlinks. All path components must exist."; - print " If the canonical name is PATH_MAX chars or more, returns null with"; - print " `errno' set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX"; - print " chars, returns the name in RESOLVED. If the name cannot be resolved"; - print " and RESOLVED is non-NULL, it contains the path of the first component"; - print " that cannot be resolved. If the path can be resolved, RESOLVED"; - print " holds the same value as the value returned. */"; - print ""; - print "char *realpath (char */*path*/, char /*resolved_path*/[]);"; - } - - print ""; - print "#ifdef __cplusplus"; - print "}"; - print "#endif /* __cplusplus */"; - print ""; - print "#endif /* GNOMESUPPORT_H */"; -} diff --git a/support/long-options.c b/support/long-options.c deleted file mode 100644 index cd2c68d6..00000000 --- a/support/long-options.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Utility to accept --help and --version options as unobtrusively as possible. - Copyright (C) 1993, 1994 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Written by Jim Meyering. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <getopt.h> -#include "long-options.h" - -static struct option const long_options[] = -{ - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} -}; - -/* Process long options --help and --version, but only if argc == 2. - Be careful not to gobble up `--'. */ - -void -parse_long_options (argc, argv, command_name, package, version, usage) - int argc; - char **argv; - const char *command_name; - const char *package; - const char *version; - void (*usage)(); -{ - int c; - int saved_opterr; - - saved_opterr = opterr; - - /* Don't print an error message for unrecognized options. */ - opterr = 0; - - if (argc == 2 - && (c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF) - { - switch (c) - { - case 'h': - (*usage) (0); - - case 'v': - printf ("%s (%s) %s\n", command_name, package, version); - exit (0); - - default: - /* Don't process any other long-named options. */ - break; - } - } - - /* Restore previous value. */ - opterr = saved_opterr; - - /* Reset this to zero so that getopt internals get initialized from - the probably-new parameters when/if getopt is called later. */ - optind = 0; -} diff --git a/support/long-options.h b/support/long-options.h deleted file mode 100644 index 4cb06937..00000000 --- a/support/long-options.h +++ /dev/null @@ -1,31 +0,0 @@ -/* long-options.h -- declaration for --help- and --version-handling function. - Copyright (C) 1993, 1994 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Written by Jim Meyering. */ - -#undef PARAMS -#if defined (__STDC__) && __STDC__ -# define PARAMS(Args) Args -#else -# define PARAMS(Args) () -#endif - -void - parse_long_options PARAMS ((int _argc, char **_argv, - const char *_command_name, - const char *_package, - const char *_version, void (*_usage) (int))); diff --git a/support/memmove.c b/support/memmove.c deleted file mode 100644 index 96e257ed..00000000 --- a/support/memmove.c +++ /dev/null @@ -1,18 +0,0 @@ -/* Wrapper to implement ANSI C's memmove using BSD's bcopy. */ -/* This function is in the public domain. --Per Bothner. */ - -#ifdef __STDC__ -#include <stddef.h> -#else -#define size_t unsigned long -#endif - -void * -memmove (s1, s2, n) - void *s1; - const void *s2; - size_t n; -{ - bcopy (s2, s1, n); - return s1; -} diff --git a/support/mkstemp.c b/support/mkstemp.c deleted file mode 100644 index 09c5a55e..00000000 --- a/support/mkstemp.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/time.h> - -#ifdef _LIBC -#include <stdint.h> -#define gettimeofday __gettimeofday -#define set_errno(e) __set_errno(e) -typedef uint64_t big_type; -#else -#define set_errno(e) errno = (e) -/* FIXME: maybe check for long long. */ -typedef long big_type; -#endif - -/* Generate a unique temporary file name from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the filename unique. - Returns a file descriptor open on the file for reading and writing. */ -int -mkstemp (template) - char *template; -{ - static const char letters[] - = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - static big_type value; - struct timeval tv; - char *XXXXXX; - size_t len; - int count; - - len = strlen (template); - if (len < 6 || strcmp (&template[len - 6], "XXXXXX")) - { - set_errno (EINVAL); - return -1; - } - - /* This is where the Xs start. */ - XXXXXX = &template[len - 6]; - - /* Get some more or less random data. */ - gettimeofday (&tv, NULL); - value += ((big_type) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); - - for (count = 0; count < TMP_MAX; ++count) - { - big_type v = value; - int fd; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - - fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600); - if (fd >= 0) - /* The file does not exist. */ - return fd; - - /* This is a random value. It is only necessary that the next - TMP_MAX values generated by adding 7777 to VALUE are different - with (module 2^32). */ - value += 7777; - } - - /* We return the null string if we can't find a unique file name. */ - template[0] = '\0'; - return -1; -} diff --git a/support/popt-gnome.h b/support/popt-gnome.h deleted file mode 100644 index 069cab11..00000000 --- a/support/popt-gnome.h +++ /dev/null @@ -1,115 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifndef H_POPT -#define H_POPT - -#include <stdio.h> /* for FILE * */ - -#define POPT_OPTION_DEPTH 10 - -#define POPT_ARG_NONE 0 -#define POPT_ARG_STRING 1 -#define POPT_ARG_INT 2 -#define POPT_ARG_LONG 3 -#define POPT_ARG_INCLUDE_TABLE 4 /* arg points to table */ -#define POPT_ARG_CALLBACK 5 /* table-wide callback... must be - set first in table; arg points - to callback, descrip points to - callback data to pass */ -#define POPT_ARG_INTL_DOMAIN 6 /* set the translation domain - for this table and any - included tables; arg points - to the domain string */ -#define POPT_ARG_VAL 7 /* arg should take value val */ -#define POPT_ARG_MASK 0x0000FFFF -#define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */ -#define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */ -#define POPT_CBFLAG_PRE 0x80000000 /* call the callback before parse */ -#define POPT_CBFLAG_POST 0x40000000 /* call the callback after parse */ -#define POPT_CBFLAG_INC_DATA 0x20000000 /* use data from the include line, - not the subtable */ - -#define POPT_ERROR_NOARG -10 -#define POPT_ERROR_BADOPT -11 -#define POPT_ERROR_OPTSTOODEEP -13 -#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ -#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ -#define POPT_ERROR_BADNUMBER -17 -#define POPT_ERROR_OVERFLOW -18 - -/* poptBadOption() flags */ -#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */ - -/* poptGetContext() flags */ -#define POPT_CONTEXT_NO_EXEC (1 << 0) /* ignore exec expansions */ -#define POPT_CONTEXT_KEEP_FIRST (1 << 1) /* pay attention to argv[0] */ -#define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /* options can't follow args */ - -struct poptOption { - const char * longName; /* may be NULL */ - char shortName; /* may be '\0' */ - int argInfo; - void * arg; /* depends on argInfo */ - int val; /* 0 means don't return, just update flag */ - char * descrip; /* description for autohelp -- may be NULL */ - char * argDescrip; /* argument description for autohelp */ -}; - -struct poptAlias { - char * longName; /* may be NULL */ - char shortName; /* may be '\0' */ - int argc; - char ** argv; /* must be free()able */ -}; - -extern struct poptOption poptHelpOptions[]; -#define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \ - 0, "Help options", NULL }, - -typedef struct poptContext_s * poptContext; -#ifndef __cplusplus -typedef struct poptOption * poptOption; -#endif - -enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, - POPT_CALLBACK_REASON_POST, - POPT_CALLBACK_REASON_OPTION }; -typedef void (*poptCallbackType)(poptContext con, - enum poptCallbackReason reason, - const struct poptOption * opt, - const char * arg, void * data); - -poptContext poptGetContext(char * name, int argc, char ** argv, - const struct poptOption * options, int flags); -void poptResetContext(poptContext con); - -/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ -int poptGetNextOpt(poptContext con); -/* returns NULL if no argument is available */ -char * poptGetOptArg(poptContext con); -/* returns NULL if no more options are available */ -char * poptGetArg(poptContext con); -char * poptPeekArg(poptContext con); -char ** poptGetArgs(poptContext con); -/* returns the option which caused the most recent error */ -char * poptBadOption(poptContext con, int flags); -void poptFreeContext(poptContext con); -int poptStuffArgs(poptContext con, char ** argv); -int poptAddAlias(poptContext con, struct poptAlias alias, int flags); -int poptReadConfigFile(poptContext con, char * fn); -/* like above, but reads /etc/popt and $HOME/.popt along with environment - vars */ -int poptReadDefaultConfig(poptContext con, int useEnv); -/* argv should be freed -- this allows ', ", and \ quoting, but ' is treated - the same as " and both may include \ quotes */ -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); -const char * poptStrerror(const int error); -void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); -void poptPrintHelp(poptContext con, FILE * f, int flags); -void poptPrintUsage(poptContext con, FILE * f, int flags); -void poptSetOtherOptionHelp(poptContext con, const char * text); -const char * poptGetInvocationName(poptContext con); - -#endif diff --git a/support/popt.c b/support/popt.c deleted file mode 100644 index f1469244..00000000 --- a/support/popt.c +++ /dev/null @@ -1,579 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <errno.h> -#include <ctype.h> -#include <fcntl.h> -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#if HAVE_ALLOCA_H -# include <alloca.h> -#endif - -#include "findme.h" -#include "popt-gnome.h" -#include "poptint.h" - -#ifndef HAVE_STRERROR -static char * strerror(int errno) { - extern int sys_nerr; - extern char * sys_errlist[]; - - if ((0 <= errno) && (errno < sys_nerr)) - return sys_errlist[errno]; - else - return POPT_("unknown errno"); -} -#endif - -void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { - if (con->execPath) free(con->execPath); - con->execPath = strdup(path); - con->execAbsolute = allowAbsolute; -} - -static void invokeCallbacks(poptContext con, const struct poptOption * table, - int post) { - const struct poptOption * opt = table; - poptCallbackType cb; - - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { - invokeCallbacks(con, opt->arg, post); - } else if (((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) && - ((!post && (opt->argInfo & POPT_CBFLAG_PRE)) || - ( post && (opt->argInfo & POPT_CBFLAG_POST)))) { - cb = opt->arg; - cb(con, post ? POPT_CALLBACK_REASON_POST : POPT_CALLBACK_REASON_PRE, - NULL, NULL, opt->descrip); - } - opt++; - } -} - -poptContext poptGetContext(char * name, int argc, char ** argv, - const struct poptOption * options, int flags) { - poptContext con = malloc(sizeof(*con)); - - memset(con, 0, sizeof(*con)); - - con->os = con->optionStack; - con->os->argc = argc; - con->os->argv = argv; - - if (!(flags & POPT_CONTEXT_KEEP_FIRST)) - con->os->next = 1; /* skip argv[0] */ - - con->leftovers = malloc(sizeof(char *) * (argc + 1)); - con->options = options; - con->finalArgv = malloc(sizeof(*con->finalArgv) * (argc * 2)); - con->finalArgvAlloced = argc * 2; - con->flags = flags; - con->execAbsolute = 1; - - if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER")) - con->flags |= POPT_CONTEXT_POSIXMEHARDER; - - if (name) - con->appName = strcpy(malloc(strlen(name) + 1), name); - - invokeCallbacks(con, con->options, 0); - - return con; -} - -void poptResetContext(poptContext con) { - con->os = con->optionStack; - con->os->currAlias = NULL; - con->os->nextCharArg = NULL; - con->os->nextArg = NULL; - con->os->next = 1; /* skip argv[0] */ - - con->numLeftovers = 0; - con->nextLeftover = 0; - con->restLeftover = 0; - con->doExec = NULL; - con->finalArgvCount = 0; -} - -/* Only one of longName, shortName may be set at a time */ -static int handleExec(poptContext con, char * longName, char shortName) { - int i; - - i = con->numExecs - 1; - if (longName) { - while (i >= 0 && (!con->execs[i].longName || - strcmp(con->execs[i].longName, longName))) i--; - } else { - while (i >= 0 && - con->execs[i].shortName != shortName) i--; - } - - if (i < 0) return 0; - - if (con->flags & POPT_CONTEXT_NO_EXEC) - return 1; - - if (!con->doExec) { - con->doExec = con->execs + i; - return 1; - } - - /* We already have an exec to do; remember this option for next - time 'round */ - if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) { - con->finalArgvAlloced += 10; - con->finalArgv = realloc(con->finalArgv, - sizeof(*con->finalArgv) * con->finalArgvAlloced); - } - - i = con->finalArgvCount++; - con->finalArgv[i] = malloc((longName ? strlen(longName) : 0) + 3); - if (longName) - sprintf(con->finalArgv[i], "--%s", longName); - else - sprintf(con->finalArgv[i], "-%c", shortName); - - return 1; -} - -/* Only one of longName, shortName may be set at a time */ -static int handleAlias(poptContext con, char * longName, char shortName, - char * nextCharArg) { - int i; - - if (con->os->currAlias && con->os->currAlias->longName && longName && - !strcmp(con->os->currAlias->longName, longName)) - return 0; - if (con->os->currAlias && shortName && - shortName == con->os->currAlias->shortName) - return 0; - - i = con->numAliases - 1; - if (longName) { - while (i >= 0 && (!con->aliases[i].longName || - strcmp(con->aliases[i].longName, longName))) i--; - } else { - while (i >= 0 && - con->aliases[i].shortName != shortName) i--; - } - - if (i < 0) return 0; - - if ((con->os - con->optionStack + 1) - == POPT_OPTION_DEPTH) - return POPT_ERROR_OPTSTOODEEP; - - if (nextCharArg && *nextCharArg) - con->os->nextCharArg = nextCharArg; - - con->os++; - con->os->next = 0; - con->os->stuffed = 0; - con->os->nextArg = con->os->nextCharArg = NULL; - con->os->currAlias = con->aliases + i; - con->os->argc = con->os->currAlias->argc; - con->os->argv = con->os->currAlias->argv; - - return 1; -} - -static void execCommand(poptContext con) { - char ** argv; - int pos = 0; - char * script = con->doExec->script; - - argv = malloc(sizeof(*argv) * - (6 + con->numLeftovers + con->finalArgvCount)); - - if (!con->execAbsolute && strchr(script, '/')) return; - - if (!strchr(script, '/') && con->execPath) { - argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2); - sprintf(argv[pos], "%s/%s", con->execPath, script); - } else { - argv[pos] = script; - } - pos++; - - argv[pos] = findProgramPath(con->os->argv[0]); - if (argv[pos]) pos++; - argv[pos++] = ";"; - - memcpy(argv + pos, con->finalArgv, sizeof(*argv) * con->finalArgvCount); - pos += con->finalArgvCount; - - if (con->numLeftovers) { - argv[pos++] = "--"; - memcpy(argv + pos, con->leftovers, sizeof(*argv) * con->numLeftovers); - pos += con->numLeftovers; - } - - argv[pos++] = NULL; - -#ifdef __hpux - setresuid(getuid(), getuid(),-1); -#else - setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ -#endif - - execvp(argv[0], argv); -} - -static const struct poptOption * findOption(const struct poptOption * table, - const char * longName, - const char shortName, - poptCallbackType * callback, - void ** callbackData, - int singleDash) { - const struct poptOption * opt = table; - const struct poptOption * opt2; - const struct poptOption * cb = NULL; - - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { - opt2 = findOption(opt->arg, longName, shortName, callback, - callbackData, singleDash); - if (opt2) { - if (*callback && !*callbackData) - *callbackData = opt->descrip; - return opt2; - } - } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) { - cb = opt; - } else if (longName && opt->longName && - (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) && - !strcmp(longName, opt->longName)) { - break; - } else if (shortName && shortName == opt->shortName) { - break; - } - opt++; - } - - if (!opt->longName && !opt->shortName) return NULL; - *callbackData = NULL; - *callback = NULL; - if (cb) { - *callback = cb->arg; - if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) - *callbackData = cb->descrip; - } - - return opt; -} - -/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ -int poptGetNextOpt(poptContext con) { - char * optString, * chptr, * localOptString; - char * longArg = NULL; - char * origOptString; - long aLong; - char * end; - const struct poptOption * opt = NULL; - int done = 0; - int i; - poptCallbackType cb; - void * cbData; - int singleDash; - - while (!done) { - while (!con->os->nextCharArg && con->os->next == con->os->argc - && con->os > con->optionStack) - con->os--; - if (!con->os->nextCharArg && con->os->next == con->os->argc) { - invokeCallbacks(con, con->options, 1); - if (con->doExec) execCommand(con); - return -1; - } - - if (!con->os->nextCharArg) { - - origOptString = con->os->argv[con->os->next++]; - - if (con->restLeftover || *origOptString != '-') { - con->leftovers[con->numLeftovers++] = origOptString; - if (con->flags & POPT_CONTEXT_POSIXMEHARDER) - con->restLeftover = 1; - continue; - } - - /* Make a copy we can hack at */ - localOptString = optString = - strcpy(alloca(strlen(origOptString) + 1), - origOptString); - - if (!optString[0]) - return POPT_ERROR_BADOPT; - - if (optString[1] == '-' && !optString[2]) { - con->restLeftover = 1; - continue; - } else { - optString++; - if (*optString == '-') - singleDash = 0, optString++; - else - singleDash = 1; - - if (handleAlias(con, optString, '\0', NULL)) - continue; - if (handleExec(con, optString, '\0')) - continue; - - chptr = optString; - while (*chptr && *chptr != '=') chptr++; - if (*chptr == '=') { - longArg = origOptString + (chptr - localOptString) + 1; - *chptr = '\0'; - } - - opt = findOption(con->options, optString, '\0', &cb, &cbData, - singleDash); - if (!opt && !singleDash) return POPT_ERROR_BADOPT; - } - - if (!opt) - con->os->nextCharArg = origOptString + 1; - } - - if (con->os->nextCharArg) { - origOptString = con->os->nextCharArg; - - con->os->nextCharArg = NULL; - - if (handleAlias(con, NULL, *origOptString, - origOptString + 1)) { - origOptString++; - continue; - } - if (handleExec(con, NULL, *origOptString)) - continue; - - opt = findOption(con->options, NULL, *origOptString, &cb, - &cbData, 0); - if (!opt) return POPT_ERROR_BADOPT; - - origOptString++; - if (*origOptString) - con->os->nextCharArg = origOptString; - } - - if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { - *((int *)opt->arg) = 1; - } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) { - if (opt->arg) *((int *) opt->arg) = opt->val; - } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { - if (longArg) { - con->os->nextArg = longArg; - } else if (con->os->nextCharArg) { - con->os->nextArg = con->os->nextCharArg; - con->os->nextCharArg = NULL; - } else { - while (con->os->next == con->os->argc && - con->os > con->optionStack) - con->os--; - if (con->os->next == con->os->argc) - return POPT_ERROR_NOARG; - - con->os->nextArg = con->os->argv[con->os->next++]; - } - - if (opt->arg) { - switch (opt->argInfo & POPT_ARG_MASK) { - case POPT_ARG_STRING: - *((char **) opt->arg) = con->os->nextArg; - break; - - case POPT_ARG_INT: - case POPT_ARG_LONG: - aLong = strtol(con->os->nextArg, &end, 0); - if (*end) - return POPT_ERROR_BADNUMBER; - - if (aLong == LONG_MIN || aLong == LONG_MAX) - return POPT_ERROR_OVERFLOW; - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { - *((long *) opt->arg) = aLong; - } else { - if (aLong > INT_MAX || aLong < INT_MIN) - return POPT_ERROR_OVERFLOW; - *((int *) opt->arg) =aLong; - } - break; - - default: - fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"), - opt->argInfo & POPT_ARG_MASK); - exit(1); - } - } - } - - if (cb) - cb(con, POPT_CALLBACK_REASON_OPTION, opt, con->os->nextArg, cbData); - else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)) - done = 1; - - if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) { - con->finalArgvAlloced += 10; - con->finalArgv = realloc(con->finalArgv, - sizeof(*con->finalArgv) * con->finalArgvAlloced); - } - - i = con->finalArgvCount++; - con->finalArgv[i] = - malloc((opt->longName ? strlen(opt->longName) : 0) + 3); - if (opt->longName) - sprintf(con->finalArgv[i], "--%s", opt->longName); - else - sprintf(con->finalArgv[i], "-%c", opt->shortName); - - if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE - && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL) - con->finalArgv[con->finalArgvCount++] = strdup(con->os->nextArg); - } - - return opt->val; -} - -char * poptGetOptArg(poptContext con) { - char * ret = con->os->nextArg; - con->os->nextArg = NULL; - return ret; -} - -char * poptGetArg(poptContext con) { - if (con->numLeftovers == con->nextLeftover) return NULL; - return (con->leftovers[con->nextLeftover++]); -} - -char * poptPeekArg(poptContext con) { - if (con->numLeftovers == con->nextLeftover) return NULL; - return (con->leftovers[con->nextLeftover]); -} - -char ** poptGetArgs(poptContext con) { - if (con->numLeftovers == con->nextLeftover) return NULL; - - /* some apps like [like RPM ;-) ] need this NULL terminated */ - con->leftovers[con->numLeftovers] = NULL; - - return (con->leftovers + con->nextLeftover); -} - -void poptFreeContext(poptContext con) { - int i; - - for (i = 0; i < con->numAliases; i++) { - if (con->aliases[i].longName) free(con->aliases[i].longName); - free(con->aliases[i].argv); - } - - for (i = 0; i < con->numExecs; i++) { - if (con->execs[i].longName) free(con->execs[i].longName); - free(con->execs[i].script); - } - - for (i = 0; i < con->finalArgvCount; i++) - free(con->finalArgv[i]); - - free(con->leftovers); - free(con->finalArgv); - if (con->appName) free(con->appName); - if (con->aliases) free(con->aliases); - if (con->otherHelp) free(con->otherHelp); - free(con); -} - -int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) { - int aliasNum = con->numAliases++; - struct poptAlias * alias; - - /* SunOS won't realloc(NULL, ...) */ - if (!con->aliases) - con->aliases = malloc(sizeof(newAlias) * con->numAliases); - else - con->aliases = realloc(con->aliases, - sizeof(newAlias) * con->numAliases); - alias = con->aliases + aliasNum; - - *alias = newAlias; - if (alias->longName) - alias->longName = strcpy(malloc(strlen(alias->longName) + 1), - alias->longName); - else - alias->longName = NULL; - - return 0; -} - -char * poptBadOption(poptContext con, int flags) { - struct optionStackEntry * os; - - if (flags & POPT_BADOPTION_NOALIAS) - os = con->optionStack; - else - os = con->os; - - return os->argv[os->next - 1]; -} - -#define POPT_ERROR_NOARG -10 -#define POPT_ERROR_BADOPT -11 -#define POPT_ERROR_OPTSTOODEEP -13 -#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ -#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ - -const char * poptStrerror(const int error) { - switch (error) { - case POPT_ERROR_NOARG: - return POPT_("missing argument"); - case POPT_ERROR_BADOPT: - return POPT_("unknown option"); - case POPT_ERROR_OPTSTOODEEP: - return POPT_("aliases nested too deeply"); - case POPT_ERROR_BADQUOTE: - return POPT_("error in paramter quoting"); - case POPT_ERROR_BADNUMBER: - return POPT_("invalid numeric value"); - case POPT_ERROR_OVERFLOW: - return POPT_("number too large or too small"); - case POPT_ERROR_ERRNO: - return strerror(errno); - default: - return POPT_("unknown error"); - } -} - -int poptStuffArgs(poptContext con, char ** argv) { - int i; - - if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) - return POPT_ERROR_OPTSTOODEEP; - - for (i = 0; argv[i]; i++); - - con->os++; - con->os->next = 0; - con->os->nextArg = con->os->nextCharArg = NULL; - con->os->currAlias = NULL; - con->os->argc = i; - con->os->argv = argv; - con->os->stuffed = 1; - - return 0; -} - -const char * poptGetInvocationName(poptContext con) { - return con->os->argv[0]; -} diff --git a/support/poptconfig.c b/support/poptconfig.c deleted file mode 100644 index dabf6f55..00000000 --- a/support/poptconfig.c +++ /dev/null @@ -1,151 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#if HAVE_ALLOCA_H -# include <alloca.h> -#endif - -#include "popt-gnome.h" -#include "poptint.h" - -static void configLine(poptContext con, char * line) { - int nameLength = strlen(con->appName); - char * opt; - struct poptAlias alias; - char * entryType; - char * longName = NULL; - char shortName = '\0'; - - if (strncmp(line, con->appName, nameLength)) return; - line += nameLength; - if (!*line || !isspace(*line)) return; - while (*line && isspace(*line)) line++; - entryType = line; - - while (!*line || !isspace(*line)) line++; - *line++ = '\0'; - while (*line && isspace(*line)) line++; - if (!*line) return; - opt = line; - - while (!*line || !isspace(*line)) line++; - *line++ = '\0'; - while (*line && isspace(*line)) line++; - if (!*line) return; - - if (opt[0] == '-' && opt[1] == '-') - longName = opt + 2; - else if (opt[0] == '-' && !opt[2]) - shortName = opt[1]; - - if (!strcmp(entryType, "alias")) { - if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; - alias.longName = longName, alias.shortName = shortName; - poptAddAlias(con, alias, 0); - } else if (!strcmp(entryType, "exec")) { - con->execs = realloc(con->execs, - sizeof(*con->execs) * (con->numExecs + 1)); - if (longName) - con->execs[con->numExecs].longName = strdup(longName); - else - con->execs[con->numExecs].longName = NULL; - - con->execs[con->numExecs].shortName = shortName; - con->execs[con->numExecs].script = strdup(line); - - con->numExecs++; - } -} - -int poptReadConfigFile(poptContext con, char * fn) { - char * file, * chptr, * end; - char * buf, * dst; - int fd, rc; - int fileLength; - - fd = open(fn, O_RDONLY); - if (fd < 0) { - if (errno == ENOENT) - return 0; - else - return POPT_ERROR_ERRNO; - } - - fileLength = lseek(fd, 0, SEEK_END); - lseek(fd, 0, 0); - - file = alloca(fileLength + 1); - if ((fd = read(fd, file, fileLength)) != fileLength) { - rc = errno; - close(fd); - errno = rc; - return POPT_ERROR_ERRNO; - } - close(fd); - - dst = buf = alloca(fileLength + 1); - - chptr = file; - end = (file + fileLength); - while (chptr < end) { - switch (*chptr) { - case '\n': - *dst = '\0'; - dst = buf; - while (*dst && isspace(*dst)) dst++; - if (*dst && *dst != '#') { - configLine(con, dst); - } - chptr++; - break; - case '\\': - *dst++ = *chptr++; - if (chptr < end) { - if (*chptr == '\n') - dst--, chptr++; - /* \ at the end of a line does not insert a \n */ - else - *dst++ = *chptr++; - } - break; - default: - *dst++ = *chptr++; - } - } - - return 0; -} - -int poptReadDefaultConfig(poptContext con, int useEnv) { - char * fn, * home; - int rc; - - if (!con->appName) return 0; - - rc = poptReadConfigFile(con, "/etc/popt"); - if (rc) return rc; - if (getuid() != geteuid()) return 0; - - if ((home = getenv("HOME"))) { - fn = alloca(strlen(home) + 20); - strcpy(fn, home); - strcat(fn, "/.popt"); - rc = poptReadConfigFile(con, fn); - if (rc) return rc; - } - - return 0; -} - diff --git a/support/popthelp.c b/support/popthelp.c deleted file mode 100644 index 618f8a21..00000000 --- a/support/popthelp.c +++ /dev/null @@ -1,306 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ - -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif - -#include "popt-gnome.h" -#include "poptint.h" - -static void displayArgs(poptContext con, enum poptCallbackReason foo, - struct poptOption * key, - const char * arg, void * data) { - if (key->shortName== '?') - poptPrintHelp(con, stdout, 0); - else - poptPrintUsage(con, stdout, 0); - exit(0); -} - -struct poptOption poptHelpOptions[] = { - { NULL, '\0', POPT_ARG_CALLBACK, &displayArgs, '\0', NULL }, - { "help", '?', 0, NULL, '?', N_("Show this help message") }, - { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message") }, - { NULL, '\0', 0, NULL, 0 } -} ; - - -static const char * -getTableTranslationDomain(const struct poptOption *table) -{ - const struct poptOption *opt; - - for(opt = table; - opt->longName || opt->shortName || opt->arg; - opt++) { - if(opt->argInfo == POPT_ARG_INTL_DOMAIN) - return opt->arg; - } - - return NULL; -} - -static const char * getArgDescrip(const struct poptOption * opt, - const char *translation_domain) { - if (!(opt->argInfo & POPT_ARG_MASK)) return NULL; - - if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2)) - if (opt->argDescrip) return POPT_(opt->argDescrip); - - if (opt->argDescrip) return D_(translation_domain, opt->argDescrip); - return POPT_("ARG"); -} - -static void singleOptionHelp(FILE * f, int maxLeftCol, - const struct poptOption * opt, - const char *translation_domain) { - int indentLength = maxLeftCol + 5; - int lineLength = 79 - indentLength; - const char * help = D_(translation_domain, opt->descrip); - int helpLength; - const char * ch; - char format[10]; - char * left = alloca(maxLeftCol + 1); - const char * argDescrip = getArgDescrip(opt, translation_domain); - - *left = '\0'; - if (opt->longName && opt->shortName) - sprintf(left, "-%c, --%s", opt->shortName, opt->longName); - else if (opt->shortName) - sprintf(left, "-%c", opt->shortName); - else if (opt->longName) - sprintf(left, "--%s", opt->longName); - if (!*left) return ; - if (argDescrip) { - strcat(left, "="); - strcat(left, argDescrip); - } - - if (help) - fprintf(f," %-*s ", maxLeftCol, left); - else { - fprintf(f," %s\n", left); - return; - } - - helpLength = strlen(help); - while (helpLength > lineLength) { - ch = help + lineLength - 1; - while (ch > help && !isspace(*ch)) ch--; - if (ch == help) break; /* give up */ - while (ch > (help + 1) && isspace(*ch)) ch--; - ch++; - - sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength); - fprintf(f, format, help, " "); - help = ch; - while (isspace(*help) && *help) help++; - helpLength = strlen(help); - } - - if (helpLength) fprintf(f, "%s\n", help); -} - -static int maxArgWidth(const struct poptOption * opt, - const char * translation_domain) { - int max = 0; - int this; - const char * s; - - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { - this = maxArgWidth(opt->arg, translation_domain); - if (this > max) max = this; - } else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { - this = opt->shortName ? 2 : 0; - if (opt->longName) { - if (this) this += 2; - this += strlen(opt->longName) + 2; - } - - s = getArgDescrip(opt, translation_domain); - if (s) - this += strlen(s) + 1; - if (this > max) max = this; - } - - opt++; - } - - return max; -} - -static void singleTableHelp(FILE * f, const struct poptOption * table, - int left, - const char *translation_domain) { - const struct poptOption * opt; - const char *sub_transdom; - - opt = table; - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->longName || opt->shortName) && - !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) - singleOptionHelp(f, left, opt, translation_domain); - opt++; - } - - opt = table; - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { - sub_transdom = getTableTranslationDomain(opt->arg); - if(!sub_transdom) - sub_transdom = translation_domain; - - if (opt->descrip) - fprintf(f, "\n%s\n", D_(sub_transdom, opt->descrip)); - - singleTableHelp(f, opt->arg, left, sub_transdom); - } - opt++; - } -} - -static int showHelpIntro(poptContext con, FILE * f) { - int len = 6; - char * fn; - - fprintf(f, POPT_("Usage:")); - if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) { - fn = con->optionStack->argv[0]; - if (strchr(fn, '/')) fn = strchr(fn, '/') + 1; - fprintf(f, " %s", fn); - len += strlen(fn) + 1; - } - - return len; -} - -void poptPrintHelp(poptContext con, FILE * f, int flags) { - int leftColWidth; - - showHelpIntro(con, f); - if (con->otherHelp) - fprintf(f, " %s\n", con->otherHelp); - else - fprintf(f, " %s\n", POPT_("[OPTION...]")); - - leftColWidth = maxArgWidth(con->options, NULL); - singleTableHelp(f, con->options, leftColWidth, NULL); -} - -static int singleOptionUsage(FILE * f, int cursor, - const struct poptOption * opt, - const char *translation_domain) { - int len = 3; - char shortStr[2]; - const char * item = shortStr; - const char * argDescrip = getArgDescrip(opt, translation_domain); - - if (opt->shortName) { - if (!(opt->argInfo & POPT_ARG_MASK)) - return cursor; /* we did these already */ - len++; - *shortStr = opt->shortName; - shortStr[1] = '\0'; - } else if (opt->longName) { - len += 1 + strlen(opt->longName); - item = opt->longName; - } - - if (len == 3) return cursor; - - if (argDescrip) - len += strlen(argDescrip) + 1; - - if ((cursor + len) > 79) { - fprintf(f, "\n "); - cursor = 7; - } - - fprintf(f, " [-%s%s%s%s]", opt->shortName ? "" : "-", item, - argDescrip ? (opt->shortName ? " " : "=") : "", - argDescrip ? argDescrip : ""); - - return cursor + len + 1; -} - -int singleTableUsage(FILE * f, int cursor, const struct poptOption * table, - const char *translation_domain) { - const struct poptOption * opt; - - opt = table; - while (opt->longName || opt->shortName || opt->arg) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) - translation_domain = (const char *)opt->arg; - else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) - cursor = singleTableUsage(f, cursor, opt->arg, - translation_domain); - else if ((opt->longName || opt->shortName) && - !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) - cursor = singleOptionUsage(f, cursor, opt, translation_domain); - - opt++; - } - - return cursor; -} - -static int showShortOptions(const struct poptOption * opt, FILE * f, - char * str) { - char s[300]; /* this is larger then the ascii set, so - it should do just fine */ - - if (!str) { - str = s; - memset(str, 0, sizeof(str)); - } - - while (opt->longName || opt->shortName || opt->arg) { - if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK)) - str[strlen(str)] = opt->shortName; - else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) - showShortOptions(opt->arg, f, str); - - opt++; - } - - if (s != str || !*s) - return 0; - - fprintf(f, " [-%s]", s); - return strlen(s) + 4; -} - -void poptPrintUsage(poptContext con, FILE * f, int flags) { - int cursor; - - cursor = showHelpIntro(con, f); - cursor += showShortOptions(con->options, f, NULL); - singleTableUsage(f, cursor, con->options, NULL); - - if (con->otherHelp) { - cursor += strlen(con->otherHelp) + 1; - if (cursor > 79) fprintf(f, "\n "); - fprintf(f, " %s", con->otherHelp); - } - - fprintf(f, "\n"); -} - -void poptSetOtherOptionHelp(poptContext con, const char * text) { - if (con->otherHelp) free(con->otherHelp); - con->otherHelp = strdup(text); -} diff --git a/support/poptint.h b/support/poptint.h deleted file mode 100644 index 8fc6a84c..00000000 --- a/support/poptint.h +++ /dev/null @@ -1,66 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifndef H_POPTINT -#define H_POPTINT - -struct optionStackEntry { - int argc; - char ** argv; - int next; - char * nextArg; - char * nextCharArg; - struct poptAlias * currAlias; - int stuffed; -}; - -struct execEntry { - char * longName; - char shortName; - char * script; -}; - -struct poptContext_s { - struct optionStackEntry optionStack[POPT_OPTION_DEPTH], * os; - char ** leftovers; - int numLeftovers; - int nextLeftover; - const struct poptOption * options; - int restLeftover; - char * appName; - struct poptAlias * aliases; - int numAliases; - int flags; - struct execEntry * execs; - int numExecs; - char ** finalArgv; - int finalArgvCount; - int finalArgvAlloced; - struct execEntry * doExec; - char * execPath; - int execAbsolute; - char * otherHelp; -}; - -#ifdef HAVE_LIBINTL_H -#include <libintl.h> -#endif - -#ifdef HAVE_GETTEXT -#define _(foo) gettext(foo) -#else -#define _(foo) (foo) -#endif - -#ifdef HAVE_DGETTEXT -#define D_(dom, str) dgettext(dom, str) -#define POPT_(foo) D_("popt", foo) -#else -#define POPT_(foo) (foo) -#define D_(dom, str) (str) -#endif - -#define N_(foo) (foo) - -#endif diff --git a/support/poptparse.c b/support/poptparse.c deleted file mode 100644 index 35eaa436..00000000 --- a/support/poptparse.c +++ /dev/null @@ -1,97 +0,0 @@ -/* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING - file accompanying popt source distributions, available from - ftp://ftp.redhat.com/pub/code/popt */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif - -#include "popt-gnome.h" - -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { - char * buf; - char * bufStart = buf; - char * src, * dst; - char quote = '\0'; - int argvAlloced = 5; - char ** argv = malloc(sizeof(*argv) * argvAlloced); - char ** argv2; - int argc = 0; - int i; - - buf = strcpy(alloca(strlen(s) + 1), s); - src = s; - dst = buf; - argv[argc] = buf; - - memset(buf, '\0', strlen(s) + 1); - - while (*src) { - if (quote == *src) { - quote = '\0'; - } else if (quote) { - if (*src == '\\') { - src++; - if (!*src) { - free(argv); - return POPT_ERROR_BADQUOTE; - } - if (*src != quote) *buf++ = '\\'; - } - *buf++ = *src; - } else if (isspace(*src)) { - if (*argv[argc]) { - buf++, argc++; - if (argc == argvAlloced) { - argvAlloced += 5; - argv = realloc(argv, sizeof(*argv) * argvAlloced); - } - argv[argc] = buf; - } - } else switch (*src) { - case '"': - case '\'': - quote = *src; - break; - case '\\': - src++; - if (!*src) { - free(argv); - return POPT_ERROR_BADQUOTE; - } - /* fallthrough */ - default: - *buf++ = *src; - } - - src++; - } - - if (strlen(argv[argc])) { - argc++, buf++; - } - - dst = malloc(argc * sizeof(*argv) + (buf - bufStart)); - argv2 = (void *) dst; - dst += argc * sizeof(*argv); - memcpy(argv2, argv, argc * sizeof(*argv)); - memcpy(dst, bufStart, buf - bufStart); - - for (i = 0; i < argc; i++) { - argv2[i] = dst + (argv[i] - bufStart); - } - - free(argv); - - *argvPtr = argv2; - *argcPtr = argc; - - return 0; -} diff --git a/support/scandir.c b/support/scandir.c deleted file mode 100644 index 1b45e376..00000000 --- a/support/scandir.c +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> - -#if HAVE_DIRENT_H -# include <dirent.h> -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -# define dirent direct -# define NAMLEN(dirent) (dirent)->d_namlen -# if HAVE_SYS_NDIR_H -# include <sys/ndir.h> -# endif -# if HAVE_SYS_DIR_H -# include <sys/dir.h> -# endif -# if HAVE_NDIR_H -# include <ndir.h> -# endif -#endif - -#undef PARAMS -#if defined (__GNUC__) || __STDC__ -# define PARAMS(args) args -#else -# define PARAMS(args) () -#endif - -#define set_errno(e) (errno = (e)) - -int -scandir (dir, namelist, select, cmp) - const char *dir; - struct dirent ***namelist; - int (*select) PARAMS ((struct dirent *)); - int (*cmp) PARAMS ((const void *, const void *)); -{ - DIR *dp = opendir (dir); - struct dirent **v = NULL; - size_t vsize = 0, i; - struct dirent *d; - int save; - - if (dp == NULL) - return -1; - - save = errno; - set_errno (0); - - i = 0; - while ((d = readdir (dp)) != NULL) - if (select == NULL || (*select) (d)) - { - size_t dsize; - - /* Ignore errors from select or readdir */ - set_errno (0); - - if (i == vsize) - { - struct dirent **new; - if (vsize == 0) - vsize = 10; - else - vsize *= 2; - new = (struct dirent **) realloc (v, vsize * sizeof (*v)); - if (new == NULL) - { - lose: - set_errno (ENOMEM); - break; - } - v = new; - } - - dsize = &d->d_name[1 + NAMLEN (d)] - (char *) d; - v[i] = (struct dirent *) malloc (dsize); - if (v[i] == NULL) - goto lose; - - memcpy (v[i++], d, dsize); - } - - if (errno != 0) - { - save = errno; - (void) closedir (dp); - while (i > 0) - free (v[--i]); - free (v); - set_errno (save); - return -1; - } - - (void) closedir (dp); - set_errno (save); - - /* Sort the list if we have a comparison function to sort with. */ - if (cmp != NULL) - qsort (v, i, sizeof (*v), cmp); - *namelist = v; - return i; -} - -int -alphasort (const void *a, const void *b) -{ - return strcmp ((*(const struct dirent **) a)->d_name, - (*(const struct dirent **) b)->d_name); -} diff --git a/support/strcasecmp.c b/support/strcasecmp.c deleted file mode 100644 index 4640372e..00000000 --- a/support/strcasecmp.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <ctype.h> -#include <string.h> - -#ifndef weak_alias -# define __strcasecmp strcasecmp -# define TOLOWER(Ch) tolower (Ch) -#else -# ifdef USE_IN_EXTENDED_LOCALE_MODEL -# define __strcasecmp __strcasecmp_l -# define TOLOWER(Ch) __tolower_l ((Ch), loc) -# else -# define TOLOWER(Ch) tolower (Ch) -# endif -#endif - -#ifdef USE_IN_EXTENDED_LOCALE_MODEL -# define LOCALE_PARAM , loc -# define LOCALE_PARAM_DECL __locale_t loc; -#else -# define LOCALE_PARAM -# define LOCALE_PARAM_DECL -#endif - -/* Compare S1 and S2, ignoring case, returning less than, equal to or - greater than zero if S1 is lexicographically less than, - equal to or greater than S2. */ -int -__strcasecmp (s1, s2 LOCALE_PARAM) - const char *s1; - const char *s2; - LOCALE_PARAM_DECL -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = TOLOWER (*p1++); - c2 = TOLOWER (*p2++); - if (c1 == '\0') - break; - } - while (c1 == c2); - - return c1 - c2; -} -#ifndef __strcasecmp -weak_alias (__strcasecmp, strcasecmp) -#endif diff --git a/support/strerror.c b/support/strerror.c deleted file mode 100644 index f8fff572..00000000 --- a/support/strerror.c +++ /dev/null @@ -1,837 +0,0 @@ -/* Extended support for using errno values. - Written by Fred Fish. fnf@cygnus.com - This file is in the public domain. --Per Bothner. */ - -#include "config.h" - -#ifndef PARAMS -#if defined (__GNUC__) || __STDC__ || defined __cplusplus -# define PARAMS(args) args -#else -# define PARAMS(args) () -#endif -#endif - - -#ifdef HAVE_SYS_ERRLIST -/* Note that errno.h (not sure what OS) or stdio.h (BSD 4.4, at least) - might declare sys_errlist in a way that the compiler might consider - incompatible with our later declaration, perhaps by using const - attributes. So we hide the declaration in errno.h (if any) using a - macro. */ -#define sys_errlist sys_errlist__ -#endif - -#include <stdio.h> -#include <errno.h> - -#ifdef HAVE_SYS_ERRLIST -#undef sys_errlist -#endif - -/* Routines imported from standard C runtime libraries. */ - -#ifdef __STDC__ -#include <stddef.h> -extern void *malloc (size_t size); /* 4.10.3.3 */ -extern void *memset (void *s, int c, size_t n); /* 4.11.6.1 */ -#else /* !__STDC__ */ -extern char *malloc (); /* Standard memory allocater */ -extern char *memset (); -#endif /* __STDC__ */ - -#ifndef MAX -# define MAX(a,b) ((a) > (b) ? (a) : (b)) -#endif - -static void init_error_tables PARAMS ((void)); - -/* Translation table for errno values. See intro(2) in most UNIX systems - Programmers Reference Manuals. - - Note that this table is generally only accessed when it is used at runtime - to initialize errno name and message tables that are indexed by errno - value. - - Not all of these errnos will exist on all systems. This table is the only - thing that should have to be updated as new error numbers are introduced. - It's sort of ugly, but at least its portable. */ - -struct error_info -{ - int value; /* The numeric value from <errno.h> */ - const char *name; /* The equivalent symbolic value */ -#ifndef HAVE_SYS_ERRLIST - const char *msg; /* Short message about this value */ -#endif -}; - -#ifndef HAVE_SYS_ERRLIST -# define ENTRY(value, name, msg) {value, name, msg} -#else -# define ENTRY(value, name, msg) {value, name} -#endif - -static const struct error_info error_table[] = -{ -#if defined (EPERM) - ENTRY(EPERM, "EPERM", "Not owner"), -#endif -#if defined (ENOENT) - ENTRY(ENOENT, "ENOENT", "No such file or directory"), -#endif -#if defined (ESRCH) - ENTRY(ESRCH, "ESRCH", "No such process"), -#endif -#if defined (EINTR) - ENTRY(EINTR, "EINTR", "Interrupted system call"), -#endif -#if defined (EIO) - ENTRY(EIO, "EIO", "I/O error"), -#endif -#if defined (ENXIO) - ENTRY(ENXIO, "ENXIO", "No such device or address"), -#endif -#if defined (E2BIG) - ENTRY(E2BIG, "E2BIG", "Arg list too long"), -#endif -#if defined (ENOEXEC) - ENTRY(ENOEXEC, "ENOEXEC", "Exec format error"), -#endif -#if defined (EBADF) - ENTRY(EBADF, "EBADF", "Bad file number"), -#endif -#if defined (ECHILD) - ENTRY(ECHILD, "ECHILD", "No child processes"), -#endif -#if defined (EWOULDBLOCK) /* Put before EAGAIN, sometimes aliased */ - ENTRY(EWOULDBLOCK, "EWOULDBLOCK", "Operation would block"), -#endif -#if defined (EAGAIN) - ENTRY(EAGAIN, "EAGAIN", "No more processes"), -#endif -#if defined (ENOMEM) - ENTRY(ENOMEM, "ENOMEM", "Not enough space"), -#endif -#if defined (EACCES) - ENTRY(EACCES, "EACCES", "Permission denied"), -#endif -#if defined (EFAULT) - ENTRY(EFAULT, "EFAULT", "Bad address"), -#endif -#if defined (ENOTBLK) - ENTRY(ENOTBLK, "ENOTBLK", "Block device required"), -#endif -#if defined (EBUSY) - ENTRY(EBUSY, "EBUSY", "Device busy"), -#endif -#if defined (EEXIST) - ENTRY(EEXIST, "EEXIST", "File exists"), -#endif -#if defined (EXDEV) - ENTRY(EXDEV, "EXDEV", "Cross-device link"), -#endif -#if defined (ENODEV) - ENTRY(ENODEV, "ENODEV", "No such device"), -#endif -#if defined (ENOTDIR) - ENTRY(ENOTDIR, "ENOTDIR", "Not a directory"), -#endif -#if defined (EISDIR) - ENTRY(EISDIR, "EISDIR", "Is a directory"), -#endif -#if defined (EINVAL) - ENTRY(EINVAL, "EINVAL", "Invalid argument"), -#endif -#if defined (ENFILE) - ENTRY(ENFILE, "ENFILE", "File table overflow"), -#endif -#if defined (EMFILE) - ENTRY(EMFILE, "EMFILE", "Too many open files"), -#endif -#if defined (ENOTTY) - ENTRY(ENOTTY, "ENOTTY", "Not a typewriter"), -#endif -#if defined (ETXTBSY) - ENTRY(ETXTBSY, "ETXTBSY", "Text file busy"), -#endif -#if defined (EFBIG) - ENTRY(EFBIG, "EFBIG", "File too large"), -#endif -#if defined (ENOSPC) - ENTRY(ENOSPC, "ENOSPC", "No space left on device"), -#endif -#if defined (ESPIPE) - ENTRY(ESPIPE, "ESPIPE", "Illegal seek"), -#endif -#if defined (EROFS) - ENTRY(EROFS, "EROFS", "Read-only file system"), -#endif -#if defined (EMLINK) - ENTRY(EMLINK, "EMLINK", "Too many links"), -#endif -#if defined (EPIPE) - ENTRY(EPIPE, "EPIPE", "Broken pipe"), -#endif -#if defined (EDOM) - ENTRY(EDOM, "EDOM", "Math argument out of domain of func"), -#endif -#if defined (ERANGE) - ENTRY(ERANGE, "ERANGE", "Math result not representable"), -#endif -#if defined (ENOMSG) - ENTRY(ENOMSG, "ENOMSG", "No message of desired type"), -#endif -#if defined (EIDRM) - ENTRY(EIDRM, "EIDRM", "Identifier removed"), -#endif -#if defined (ECHRNG) - ENTRY(ECHRNG, "ECHRNG", "Channel number out of range"), -#endif -#if defined (EL2NSYNC) - ENTRY(EL2NSYNC, "EL2NSYNC", "Level 2 not synchronized"), -#endif -#if defined (EL3HLT) - ENTRY(EL3HLT, "EL3HLT", "Level 3 halted"), -#endif -#if defined (EL3RST) - ENTRY(EL3RST, "EL3RST", "Level 3 reset"), -#endif -#if defined (ELNRNG) - ENTRY(ELNRNG, "ELNRNG", "Link number out of range"), -#endif -#if defined (EUNATCH) - ENTRY(EUNATCH, "EUNATCH", "Protocol driver not attached"), -#endif -#if defined (ENOCSI) - ENTRY(ENOCSI, "ENOCSI", "No CSI structure available"), -#endif -#if defined (EL2HLT) - ENTRY(EL2HLT, "EL2HLT", "Level 2 halted"), -#endif -#if defined (EDEADLK) - ENTRY(EDEADLK, "EDEADLK", "Deadlock condition"), -#endif -#if defined (ENOLCK) - ENTRY(ENOLCK, "ENOLCK", "No record locks available"), -#endif -#if defined (EBADE) - ENTRY(EBADE, "EBADE", "Invalid exchange"), -#endif -#if defined (EBADR) - ENTRY(EBADR, "EBADR", "Invalid request descriptor"), -#endif -#if defined (EXFULL) - ENTRY(EXFULL, "EXFULL", "Exchange full"), -#endif -#if defined (ENOANO) - ENTRY(ENOANO, "ENOANO", "No anode"), -#endif -#if defined (EBADRQC) - ENTRY(EBADRQC, "EBADRQC", "Invalid request code"), -#endif -#if defined (EBADSLT) - ENTRY(EBADSLT, "EBADSLT", "Invalid slot"), -#endif -#if defined (EDEADLOCK) - ENTRY(EDEADLOCK, "EDEADLOCK", "File locking deadlock error"), -#endif -#if defined (EBFONT) - ENTRY(EBFONT, "EBFONT", "Bad font file format"), -#endif -#if defined (ENOSTR) - ENTRY(ENOSTR, "ENOSTR", "Device not a stream"), -#endif -#if defined (ENODATA) - ENTRY(ENODATA, "ENODATA", "No data available"), -#endif -#if defined (ETIME) - ENTRY(ETIME, "ETIME", "Timer expired"), -#endif -#if defined (ENOSR) - ENTRY(ENOSR, "ENOSR", "Out of streams resources"), -#endif -#if defined (ENONET) - ENTRY(ENONET, "ENONET", "Machine is not on the network"), -#endif -#if defined (ENOPKG) - ENTRY(ENOPKG, "ENOPKG", "Package not installed"), -#endif -#if defined (EREMOTE) - ENTRY(EREMOTE, "EREMOTE", "Object is remote"), -#endif -#if defined (ENOLINK) - ENTRY(ENOLINK, "ENOLINK", "Link has been severed"), -#endif -#if defined (EADV) - ENTRY(EADV, "EADV", "Advertise error"), -#endif -#if defined (ESRMNT) - ENTRY(ESRMNT, "ESRMNT", "Srmount error"), -#endif -#if defined (ECOMM) - ENTRY(ECOMM, "ECOMM", "Communication error on send"), -#endif -#if defined (EPROTO) - ENTRY(EPROTO, "EPROTO", "Protocol error"), -#endif -#if defined (EMULTIHOP) - ENTRY(EMULTIHOP, "EMULTIHOP", "Multihop attempted"), -#endif -#if defined (EDOTDOT) - ENTRY(EDOTDOT, "EDOTDOT", "RFS specific error"), -#endif -#if defined (EBADMSG) - ENTRY(EBADMSG, "EBADMSG", "Not a data message"), -#endif -#if defined (ENAMETOOLONG) - ENTRY(ENAMETOOLONG, "ENAMETOOLONG", "File name too long"), -#endif -#if defined (EOVERFLOW) - ENTRY(EOVERFLOW, "EOVERFLOW", "Value too large for defined data type"), -#endif -#if defined (ENOTUNIQ) - ENTRY(ENOTUNIQ, "ENOTUNIQ", "Name not unique on network"), -#endif -#if defined (EBADFD) - ENTRY(EBADFD, "EBADFD", "File descriptor in bad state"), -#endif -#if defined (EREMCHG) - ENTRY(EREMCHG, "EREMCHG", "Remote address changed"), -#endif -#if defined (ELIBACC) - ENTRY(ELIBACC, "ELIBACC", "Can not access a needed shared library"), -#endif -#if defined (ELIBBAD) - ENTRY(ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library"), -#endif -#if defined (ELIBSCN) - ENTRY(ELIBSCN, "ELIBSCN", ".lib section in a.out corrupted"), -#endif -#if defined (ELIBMAX) - ENTRY(ELIBMAX, "ELIBMAX", "Attempting to link in too many shared libraries"), -#endif -#if defined (ELIBEXEC) - ENTRY(ELIBEXEC, "ELIBEXEC", "Cannot exec a shared library directly"), -#endif -#if defined (EILSEQ) - ENTRY(EILSEQ, "EILSEQ", "Illegal byte sequence"), -#endif -#if defined (ENOSYS) - ENTRY(ENOSYS, "ENOSYS", "Operation not applicable"), -#endif -#if defined (ELOOP) - ENTRY(ELOOP, "ELOOP", "Too many symbolic links encountered"), -#endif -#if defined (ERESTART) - ENTRY(ERESTART, "ERESTART", "Interrupted system call should be restarted"), -#endif -#if defined (ESTRPIPE) - ENTRY(ESTRPIPE, "ESTRPIPE", "Streams pipe error"), -#endif -#if defined (ENOTEMPTY) - ENTRY(ENOTEMPTY, "ENOTEMPTY", "Directory not empty"), -#endif -#if defined (EUSERS) - ENTRY(EUSERS, "EUSERS", "Too many users"), -#endif -#if defined (ENOTSOCK) - ENTRY(ENOTSOCK, "ENOTSOCK", "Socket operation on non-socket"), -#endif -#if defined (EDESTADDRREQ) - ENTRY(EDESTADDRREQ, "EDESTADDRREQ", "Destination address required"), -#endif -#if defined (EMSGSIZE) - ENTRY(EMSGSIZE, "EMSGSIZE", "Message too long"), -#endif -#if defined (EPROTOTYPE) - ENTRY(EPROTOTYPE, "EPROTOTYPE", "Protocol wrong type for socket"), -#endif -#if defined (ENOPROTOOPT) - ENTRY(ENOPROTOOPT, "ENOPROTOOPT", "Protocol not available"), -#endif -#if defined (EPROTONOSUPPORT) - ENTRY(EPROTONOSUPPORT, "EPROTONOSUPPORT", "Protocol not supported"), -#endif -#if defined (ESOCKTNOSUPPORT) - ENTRY(ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT", "Socket type not supported"), -#endif -#if defined (EOPNOTSUPP) - ENTRY(EOPNOTSUPP, "EOPNOTSUPP", "Operation not supported on transport endpoint"), -#endif -#if defined (EPFNOSUPPORT) - ENTRY(EPFNOSUPPORT, "EPFNOSUPPORT", "Protocol family not supported"), -#endif -#if defined (EAFNOSUPPORT) - ENTRY(EAFNOSUPPORT, "EAFNOSUPPORT", "Address family not supported by protocol"), -#endif -#if defined (EADDRINUSE) - ENTRY(EADDRINUSE, "EADDRINUSE", "Address already in use"), -#endif -#if defined (EADDRNOTAVAIL) - ENTRY(EADDRNOTAVAIL, "EADDRNOTAVAIL","Cannot assign requested address"), -#endif -#if defined (ENETDOWN) - ENTRY(ENETDOWN, "ENETDOWN", "Network is down"), -#endif -#if defined (ENETUNREACH) - ENTRY(ENETUNREACH, "ENETUNREACH", "Network is unreachable"), -#endif -#if defined (ENETRESET) - ENTRY(ENETRESET, "ENETRESET", "Network dropped connection because of reset"), -#endif -#if defined (ECONNABORTED) - ENTRY(ECONNABORTED, "ECONNABORTED", "Software caused connection abort"), -#endif -#if defined (ECONNRESET) - ENTRY(ECONNRESET, "ECONNRESET", "Connection reset by peer"), -#endif -#if defined (ENOBUFS) - ENTRY(ENOBUFS, "ENOBUFS", "No buffer space available"), -#endif -#if defined (EISCONN) - ENTRY(EISCONN, "EISCONN", "Transport endpoint is already connected"), -#endif -#if defined (ENOTCONN) - ENTRY(ENOTCONN, "ENOTCONN", "Transport endpoint is not connected"), -#endif -#if defined (ESHUTDOWN) - ENTRY(ESHUTDOWN, "ESHUTDOWN", "Cannot send after transport endpoint shutdown"), -#endif -#if defined (ETOOMANYREFS) - ENTRY(ETOOMANYREFS, "ETOOMANYREFS", "Too many references: cannot splice"), -#endif -#if defined (ETIMEDOUT) - ENTRY(ETIMEDOUT, "ETIMEDOUT", "Connection timed out"), -#endif -#if defined (ECONNREFUSED) - ENTRY(ECONNREFUSED, "ECONNREFUSED", "Connection refused"), -#endif -#if defined (EHOSTDOWN) - ENTRY(EHOSTDOWN, "EHOSTDOWN", "Host is down"), -#endif -#if defined (EHOSTUNREACH) - ENTRY(EHOSTUNREACH, "EHOSTUNREACH", "No route to host"), -#endif -#if defined (EALREADY) - ENTRY(EALREADY, "EALREADY", "Operation already in progress"), -#endif -#if defined (EINPROGRESS) - ENTRY(EINPROGRESS, "EINPROGRESS", "Operation now in progress"), -#endif -#if defined (ESTALE) - ENTRY(ESTALE, "ESTALE", "Stale NFS file handle"), -#endif -#if defined (EUCLEAN) - ENTRY(EUCLEAN, "EUCLEAN", "Structure needs cleaning"), -#endif -#if defined (ENOTNAM) - ENTRY(ENOTNAM, "ENOTNAM", "Not a XENIX named type file"), -#endif -#if defined (ENAVAIL) - ENTRY(ENAVAIL, "ENAVAIL", "No XENIX semaphores available"), -#endif -#if defined (EISNAM) - ENTRY(EISNAM, "EISNAM", "Is a named type file"), -#endif -#if defined (EREMOTEIO) - ENTRY(EREMOTEIO, "EREMOTEIO", "Remote I/O error"), -#endif - ENTRY(0, NULL, NULL) -}; - -#ifdef EVMSERR -/* This is not in the table, because the numeric value of EVMSERR (32767) - lies outside the range of sys_errlist[]. */ -static struct { int value; const char *name, *msg; } - evmserr = { EVMSERR, "EVMSERR", "VMS-specific error" }; -#endif - -/* Translation table allocated and initialized at runtime. Indexed by the - errno value to find the equivalent symbolic value. */ - -static const char **error_names; -static int num_error_names = 0; - -/* Translation table allocated and initialized at runtime, if it does not - already exist in the host environment. Indexed by the errno value to find - the descriptive string. - - We don't export it for use in other modules because even though it has the - same name, it differs from other implementations in that it is dynamically - initialized rather than statically initialized. */ - -#ifndef HAVE_SYS_ERRLIST - -static int sys_nerr; -static const char **sys_errlist; - -#else - -extern int sys_nerr; -extern char *sys_errlist[]; - -#endif - - -/* - -NAME - - init_error_tables -- initialize the name and message tables - -SYNOPSIS - - static void init_error_tables (); - -DESCRIPTION - - Using the error_table, which is initialized at compile time, generate - the error_names and the sys_errlist (if needed) tables, which are - indexed at runtime by a specific errno value. - -BUGS - - The initialization of the tables may fail under low memory conditions, - in which case we don't do anything particularly useful, but we don't - bomb either. Who knows, it might succeed at a later point if we free - some memory in the meantime. In any case, the other routines know - how to deal with lack of a table after trying to initialize it. This - may or may not be considered to be a bug, that we don't specifically - warn about this particular failure mode. - -*/ - -static void -init_error_tables () -{ - const struct error_info *eip; - int nbytes; - - /* If we haven't already scanned the error_table once to find the maximum - errno value, then go find it now. */ - - if (num_error_names == 0) - { - for (eip = error_table; eip -> name != NULL; eip++) - { - if (eip -> value >= num_error_names) - { - num_error_names = eip -> value + 1; - } - } - } - - /* Now attempt to allocate the error_names table, zero it out, and then - initialize it from the statically initialized error_table. */ - - if (error_names == NULL) - { - nbytes = num_error_names * sizeof (char *); - if ((error_names = (const char **) malloc (nbytes)) != NULL) - { - memset (error_names, 0, nbytes); - for (eip = error_table; eip -> name != NULL; eip++) - { - error_names[eip -> value] = eip -> name; - } - } - } - -#ifndef HAVE_SYS_ERRLIST - - /* Now attempt to allocate the sys_errlist table, zero it out, and then - initialize it from the statically initialized error_table. */ - - if (sys_errlist == NULL) - { - nbytes = num_error_names * sizeof (char *); - if ((sys_errlist = (const char **) malloc (nbytes)) != NULL) - { - memset (sys_errlist, 0, nbytes); - sys_nerr = num_error_names; - for (eip = error_table; eip -> name != NULL; eip++) - { - sys_errlist[eip -> value] = eip -> msg; - } - } - } - -#endif - -} - -/* - -NAME - - errno_max -- return the max errno value - -SYNOPSIS - - int errno_max (); - -DESCRIPTION - - Returns the maximum errno value for which a corresponding symbolic - name or message is available. Note that in the case where - we use the sys_errlist supplied by the system, it is possible for - there to be more symbolic names than messages, or vice versa. - In fact, the manual page for perror(3C) explicitly warns that one - should check the size of the table (sys_nerr) before indexing it, - since new error codes may be added to the system before they are - added to the table. Thus sys_nerr might be smaller than value - implied by the largest errno value defined in <errno.h>. - - We return the maximum value that can be used to obtain a meaningful - symbolic name or message. - -*/ - -int -errno_max () -{ - int maxsize; - - if (error_names == NULL) - { - init_error_tables (); - } - maxsize = MAX (sys_nerr, num_error_names); - return (maxsize - 1); -} - -#ifndef HAVE_STRERROR - -/* - -NAME - - strerror -- map an error number to an error message string - -SYNOPSIS - - char *strerror (int errnoval) - -DESCRIPTION - - Maps an errno number to an error message string, the contents of - which are implementation defined. On systems which have the external - variables sys_nerr and sys_errlist, these strings will be the same - as the ones used by perror(). - - If the supplied error number is within the valid range of indices - for the sys_errlist, but no message is available for the particular - error number, then returns the string "Error NUM", where NUM is the - error number. - - If the supplied error number is not a valid index into sys_errlist, - returns NULL. - - The returned string is only guaranteed to be valid only until the - next call to strerror. - -*/ - -char * -strerror (errnoval) - int errnoval; -{ - char *msg; - static char buf[32]; - -#ifndef HAVE_SYS_ERRLIST - - if (error_names == NULL) - { - init_error_tables (); - } - -#endif - - if ((errnoval < 0) || (errnoval >= sys_nerr)) - { -#ifdef EVMSERR - if (errnoval == evmserr.value) - msg = evmserr.msg; - else -#endif - /* Out of range, just return NULL */ - msg = NULL; - } - else if ((sys_errlist == NULL) || (sys_errlist[errnoval] == NULL)) - { - /* In range, but no sys_errlist or no entry at this index. */ - sprintf (buf, "Error %d", errnoval); - msg = buf; - } - else - { - /* In range, and a valid message. Just return the message. */ - msg = (char *) sys_errlist[errnoval]; - } - - return (msg); -} - -#endif /* ! HAVE_STRERROR */ - - -/* - -NAME - - strerrno -- map an error number to a symbolic name string - -SYNOPSIS - - const char *strerrno (int errnoval) - -DESCRIPTION - - Given an error number returned from a system call (typically - returned in errno), returns a pointer to a string containing the - symbolic name of that error number, as found in <errno.h>. - - If the supplied error number is within the valid range of indices - for symbolic names, but no name is available for the particular - error number, then returns the string "Error NUM", where NUM is - the error number. - - If the supplied error number is not within the range of valid - indices, then returns NULL. - -BUGS - - The contents of the location pointed to are only guaranteed to be - valid until the next call to strerrno. - -*/ - -const char * -strerrno (errnoval) - int errnoval; -{ - const char *name; - static char buf[32]; - - if (error_names == NULL) - { - init_error_tables (); - } - - if ((errnoval < 0) || (errnoval >= num_error_names)) - { -#ifdef EVMSERR - if (errnoval == evmserr.value) - name = evmserr.name; - else -#endif - /* Out of range, just return NULL */ - name = NULL; - } - else if ((error_names == NULL) || (error_names[errnoval] == NULL)) - { - /* In range, but no error_names or no entry at this index. */ - sprintf (buf, "Error %d", errnoval); - name = (const char *) buf; - } - else - { - /* In range, and a valid name. Just return the name. */ - name = error_names[errnoval]; - } - - return (name); -} - -/* - -NAME - - strtoerrno -- map a symbolic errno name to a numeric value - -SYNOPSIS - - int strtoerrno (char *name) - -DESCRIPTION - - Given the symbolic name of a error number, map it to an errno value. - If no translation is found, returns 0. - -*/ - -int -strtoerrno (name) - const char *name; -{ - int errnoval = 0; - - if (name != NULL) - { - if (error_names == NULL) - { - init_error_tables (); - } - for (errnoval = 0; errnoval < num_error_names; errnoval++) - { - if ((error_names[errnoval] != NULL) && - (strcmp (name, error_names[errnoval]) == 0)) - { - break; - } - } - if (errnoval == num_error_names) - { -#ifdef EVMSERR - if (strcmp (name, evmserr.name) == 0) - errnoval = evmserr.value; - else -#endif - errnoval = 0; - } - } - return (errnoval); -} - - -/* A simple little main that does nothing but print all the errno translations - if MAIN is defined and this file is compiled and linked. */ - -#ifdef MAIN - -#include <stdio.h> - -int -main () -{ - int errn; - int errnmax; - const char *name; - char *msg; - char *strerror (); - - errnmax = errno_max (); - printf ("%d entries in names table.\n", num_error_names); - printf ("%d entries in messages table.\n", sys_nerr); - printf ("%d is max useful index.\n", errnmax); - - /* Keep printing values until we get to the end of *both* tables, not - *either* table. Note that knowing the maximum useful index does *not* - relieve us of the responsibility of testing the return pointer for - NULL. */ - - for (errn = 0; errn <= errnmax; errn++) - { - name = strerrno (errn); - name = (name == NULL) ? "<NULL>" : name; - msg = strerror (errn); - msg = (msg == NULL) ? "<NULL>" : msg; - printf ("%-4d%-18s%s\n", errn, name, msg); - } - - return 0; -} - -#endif diff --git a/support/strndup.c b/support/strndup.c deleted file mode 100644 index cd971e1c..00000000 --- a/support/strndup.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <stdio.h> -#include <sys/types.h> - -#if defined _LIBC || defined STDC_HEADERS -# include <stdlib.h> -# include <string.h> -#else -char *malloc (); -#endif - -#ifndef weak_alias -# define __strndup strndup -#endif - -char * -__strndup (s, n) - const char *s; - size_t n; -{ - size_t len = strnlen (s, n); - char *new = malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return memcpy (new, s, len); -} -#ifdef weak_alias -weak_alias (__strndup, strndup) -#endif diff --git a/support/strnlen.c b/support/strnlen.c deleted file mode 100644 index ab95d170..00000000 --- a/support/strnlen.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Find the length of STRING, but scan at most MAXLEN characters. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include <string.h> - -/* Find the length of STRING, but scan at most MAXLEN characters. - If no '\0' terminator is found in that many characters, return MAXLEN. */ - -size_t -strnlen (const char *string, size_t maxlen) -{ - const char *end = memchr (string, '\0', maxlen); - return end ? end - string : maxlen; -} diff --git a/support/strtod.c b/support/strtod.c deleted file mode 100644 index c86c73de..00000000 --- a/support/strtod.c +++ /dev/null @@ -1,122 +0,0 @@ -/* Implementation of strtod for systems with atof. - Copyright (C) 1991, 1995 Free Software Foundation, Inc. - -This file is part of the libiberty library. This library is free -software; you can redistribute it and/or modify it under the -terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) -any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -As a special exception, if you link this library with files -compiled with a GNU compiler to produce an executable, this does not cause -the resulting executable to be covered by the GNU General Public License. -This exception does not however invalidate any other reasons why -the executable file might be covered by the GNU General Public License. */ - -#include <ctype.h> - -extern double atof (); - -/* Disclaimer: this is currently just used by CHILL in GDB and therefore - has not been tested well. It may have been tested for nothing except - that it compiles. */ - -double -strtod (str, ptr) - char *str; - char **ptr; -{ - char *p; - - if (ptr == (char **)0) - return atof (str); - - p = str; - - while (isspace (*p)) - ++p; - - if (*p == '+' || *p == '-') - ++p; - - /* INF or INFINITY. */ - if ((p[0] == 'i' || p[0] == 'I') - && (p[1] == 'n' || p[1] == 'N') - && (p[2] == 'f' || p[2] == 'F')) - { - if ((p[3] == 'i' || p[3] == 'I') - && (p[4] == 'n' || p[4] == 'N') - && (p[5] == 'i' || p[5] == 'I') - && (p[6] == 't' || p[6] == 'T') - && (p[7] == 'y' || p[7] == 'Y')) - { - *ptr = p + 7; - return atof (str); - } - else - { - *ptr = p + 3; - return atof (str); - } - } - - /* NAN or NAN(foo). */ - if ((p[0] == 'n' || p[0] == 'N') - && (p[1] == 'a' || p[1] == 'A') - && (p[2] == 'n' || p[2] == 'N')) - { - p += 3; - if (*p == '(') - { - ++p; - while (*p != '\0' && *p != ')') - ++p; - if (*p == ')') - ++p; - } - *ptr = p; - return atof (str); - } - - /* digits, with 0 or 1 periods in it. */ - if (isdigit (*p) || *p == '.') - { - int got_dot = 0; - while (isdigit (*p) || (!got_dot && *p == '.')) - { - if (*p == '.') - got_dot = 1; - ++p; - } - - /* Exponent. */ - if (*p == 'e' || *p == 'E') - { - int i; - i = 1; - if (p[i] == '+' || p[i] == '-') - ++i; - if (isdigit (p[i])) - { - while (isdigit (p[i])) - ++i; - *ptr = p + i; - return atof (str); - } - } - *ptr = p; - return atof (str); - } - /* Didn't find any digits. Doesn't look like a number. */ - *ptr = str; - return 0.0; -} diff --git a/support/strtok_r.c b/support/strtok_r.c deleted file mode 100644 index 44430dae..00000000 --- a/support/strtok_r.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Reentrant string tokenizer. Generic version. - Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include <string.h> - -#undef strtok_r - -/* Parse S into tokens separated by characters in DELIM. - If S is NULL, the saved pointer in SAVE_PTR is used as - the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = strtok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" -*/ -char * -strtok_r (s, delim, save_ptr) - char *s; - const char *delim; - char **save_ptr; -{ - char *token; - - if (s == NULL) - s = *save_ptr; - - /* Scan leading delimiters. */ - s += strspn (s, delim); - if (*s == '\0') - return NULL; - - /* Find the end of the token. */ - token = s; - s = strpbrk (token, delim); - if (s == NULL) - /* This token finishes the string. */ - *save_ptr = strchr (token, '\0'); - else - { - /* Terminate the token and make *SAVE_PTR point past it. */ - *s = '\0'; - *save_ptr = s + 1; - } - return token; -} diff --git a/support/strtol.c b/support/strtol.c deleted file mode 100644 index 75b74939..00000000 --- a/support/strtol.c +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <limits.h> -#include <ctype.h> -#include <errno.h> -#if 0 -#include <stdlib.h> -#endif - -/* FIXME: It'd be nice to configure around these, but the include files are too - painful. These macros should at least be more portable than hardwired hex - constants. */ - -#ifndef ULONG_MAX -#define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ -#endif - -#ifndef LONG_MAX -#define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF */ -#endif - -#ifndef LONG_MIN -#define LONG_MIN ((long)(~LONG_MAX)) /* 0x80000000 */ -#endif - -/* - * Convert a string to a long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -long -strtol(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s = nptr; - register unsigned long acc; - register int c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for longs is - * [-2147483648..2147483647] and the input base is 10, - * cutoff will be set to 214748364 and cutlim to either - * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated - * a value > 214748364, or equal but the next digit is > 7 (or 8), - * the number is too big, and we will return a range error. - * - * Set any if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; - cutlim = cutoff % (unsigned long)base; - cutoff /= (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = neg ? LONG_MIN : LONG_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *) (any ? s - 1 : nptr); - return (acc); -} diff --git a/support/strtoul.c b/support/strtoul.c deleted file mode 100644 index 54207fa9..00000000 --- a/support/strtoul.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <limits.h> -#include <ctype.h> -#include <errno.h> -#if 0 -#include <stdlib.h> -#endif - -#ifndef ULONG_MAX -#define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ -#endif - -/* - * Convert a string to an unsigned long integer. - * - * Ignores `locale' stuff. Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -unsigned long -strtoul(nptr, endptr, base) - const char *nptr; - char **endptr; - register int base; -{ - register const char *s = nptr; - register unsigned long acc; - register int c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; - cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = ULONG_MAX; - errno = ERANGE; - } else if (neg) - acc = -acc; - if (endptr != 0) - *endptr = (char *) (any ? s - 1 : nptr); - return (acc); -} diff --git a/support/vasprintf.c b/support/vasprintf.c deleted file mode 100644 index 64e06b88..00000000 --- a/support/vasprintf.c +++ /dev/null @@ -1,197 +0,0 @@ -/* Like vsprintf but provides a pointer to malloc'd storage, which must - be freed by the caller. - Copyright (C) 1994 Free Software Foundation, Inc. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stdio.h> -#include <string.h> - -#if __STDC__ -# include <stdarg.h> -#else -# include <varargs.h> -#endif - -#ifdef TEST -int global_total_width; -#endif - -unsigned long strtoul (); -char *malloc (); - -static int -int_vasprintf (result, format, args) - char **result; - const char *format; - va_list *args; -{ - const char *p = format; - /* Add one to make sure that it is never zero, which might cause malloc - to return NULL. */ - int total_width = strlen (format) + 1; - va_list ap; - - memcpy (&ap, args, sizeof (va_list)); - - while (*p != '\0') - { - if (*p++ == '%') - { - while (strchr ("-+ #0", *p)) - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - total_width += strtoul (p, &p, 10); - if (*p == '.') - { - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - total_width += strtoul (p, &p, 10); - } - while (strchr ("hlL", *p)) - ++p; - /* Should be big enough for any format specifier except %s - and floats. */ - total_width += 30; - switch (*p) - { - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'c': - (void) va_arg (ap, int); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - (void) va_arg (ap, double); - /* Since an ieee double can have an exponent of 307, we'll - make the buffer wide enough to cover the gross case. */ - total_width += 307; - break; - case 's': - total_width += strlen (va_arg (ap, char *)); - break; - case 'p': - case 'n': - (void) va_arg (ap, char *); - break; - } - } - } -#ifdef TEST - global_total_width = total_width; -#endif - *result = malloc (total_width); - if (*result != NULL) - return vsprintf (*result, format, *args); - else - return 0; -} - -int -vasprintf (result, format, args) - char **result; - const char *format; - va_list args; -{ - return int_vasprintf (result, format, &args); -} - -int -asprintf -#if __STDC__ - (char **result, const char *format, ...) -#else - (result, va_alist) - char **result; - va_dcl -#endif -{ - va_list args; - int done; - -#if __STDC__ - va_start (args, format); -#else - char *format; - va_start (args); - format = va_arg (args, char *); -#endif - done = vasprintf (result, format, args); - va_end (args); - - return done; -} - -#ifdef TEST -void -checkit -#if __STDC__ - (const char* format, ...) -#else - (va_alist) - va_dcl -#endif -{ - va_list args; - char *result; - -#if __STDC__ - va_start (args, format); -#else - char *format; - va_start (args); - format = va_arg (args, char *); -#endif - vasprintf (&result, format, args); - if (strlen (result) < global_total_width) - printf ("PASS: "); - else - printf ("FAIL: "); - printf ("%d %s\n", global_total_width, result); -} - -int -main () -{ - checkit ("%d", 0x12345678); - checkit ("%200d", 5); - checkit ("%.300d", 6); - checkit ("%100.150d", 7); - checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\ -777777777777777777333333333333366666666666622222222222777777777777733333"); - checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"); -} -#endif /* TEST */ diff --git a/support/vsnprintf.c b/support/vsnprintf.c deleted file mode 100644 index a2dfb4ed..00000000 --- a/support/vsnprintf.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Revision 12: http://theos.com/~deraadt/snprintf.c - * - * Copyright (c) 1997 Theo de Raadt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <signal.h> -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#include <stdlib.h> -#else -#include <varargs.h> -#endif -#include <setjmp.h> - -#ifndef roundup -#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) -#endif - -static int pgsize; -static char *curobj; -static int caught; -static sigjmp_buf bail; - -#define EXTRABYTES 2 /* XXX: why 2? you don't want to know */ - -static char * -msetup(str, n) - char *str; - size_t n; -{ - char *e; - - if (n == 0) - return NULL; - if (pgsize == 0) - pgsize = getpagesize(); - curobj = (char *)malloc(n + EXTRABYTES + pgsize * 2); - if (curobj == NULL) - return NULL; - e = curobj + n + EXTRABYTES; - e = (char *)roundup((unsigned long)e, pgsize); - if (mprotect(e, pgsize, PROT_NONE) == -1) { - free(curobj); - curobj = NULL; - return NULL; - } - e = e - n - EXTRABYTES; - *e = '\0'; - return (e); -} - -static void -mcatch() -{ - siglongjmp(bail, 1); -} - -static void -mcleanup(str, n, p) - char *str; - size_t n; - char *p; -{ - strncpy(str, p, n-1); - str[n-1] = '\0'; - if (mprotect((caddr_t)(p + n + EXTRABYTES), pgsize, - PROT_READ|PROT_WRITE|PROT_EXEC) == -1) - mprotect((caddr_t)(p + n + EXTRABYTES), pgsize, - PROT_READ|PROT_WRITE); - free(curobj); -} - -int -#if __STDC__ -vsnprintf(char *str, size_t n, char const *fmt, va_list ap) -#else -vsnprintf(str, n, fmt, ap) - char *str; - size_t n; - char *fmt; - char *ap; -#endif -{ - struct sigaction osa, nsa; - char *p; - int ret = n + 1; /* if we bail, indicated we overflowed */ - - memset(&nsa, 0, sizeof nsa); - nsa.sa_handler = mcatch; - sigemptyset(&nsa.sa_mask); - - p = msetup(str, n); - if (p == NULL) { - *str = '\0'; - return 0; - } - if (sigsetjmp(bail, 1) == 0) { - if (sigaction(SIGSEGV, &nsa, &osa) == -1) { - mcleanup(str, n, p); - return (0); - } - ret = vsprintf(p, fmt, ap); - } - mcleanup(str, n, p); - (void) sigaction(SIGSEGV, &osa, NULL); - return (ret); -} - -int -#if __STDC__ -snprintf(char *str, size_t n, char const *fmt, ...) -#else -snprintf(str, n, fmt, va_alist) - char *str; - size_t n; - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - - return (vsnprintf(str, n, fmt, ap)); - va_end(ap); -} - - - |