From: Harlan Stenn Date: Sat, 20 Nov 2010 04:26:17 +0000 (-0500) Subject: Upgrade libopts to 33.3.8 and autogen to 5.11.3 X-Git-Tag: NTP_4_2_7P84~10^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e52cf63ca08bb1a2ba9285ad839fe21fc41d972b;p=thirdparty%2Fntp.git Upgrade libopts to 33.3.8 and autogen to 5.11.3 bk: 4ce74de9aF2g0BlRdYgjKstAjtNgtA --- diff --git a/ChangeLog b/ChangeLog index 855e9d266..8809ead12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ * [Bug 1728] In ntp_openssl.m4, don't add -I/usr/include or -L/usr/lib to CPPFLAGS or LDFLAGS. * Remove log_msg() and debug_msg() from sntp in favor of msyslog(). +* Use a single copy of libopts/, in sntp/. +* Upgrade libopts to 33.3.8. --- (4.2.6p3-RC10) 2010/11/14 Released by Harlan Stenn diff --git a/Makefile.am b/Makefile.am index ddd30a649..9822e82ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,18 +1,19 @@ AUTOMAKE_OPTIONS = foreign 1.10 -ACLOCAL_AMFLAGS= -I m4 -I libopts/m4 +ACLOCAL_AMFLAGS = -I m4 -I sntp/libopts/m4 -NULL= +NULL = -SUBDIRS= -SUBDIRS+= \ +SUBDIRS = +SUBDIRS += \ scripts \ include \ ElectricFence \ $(NULL) if NEED_LIBOPTS -SUBDIRS+= libopts +SUBDIRS += \ + sntp/libopts endif -SUBDIRS+= \ +SUBDIRS += \ libntp \ libparse \ ntpd \ @@ -28,12 +29,11 @@ SUBDIRS+= \ util \ $(NULL) -DIST_SUBDIRS= \ +DIST_SUBDIRS = \ scripts \ include \ ElectricFence \ libntp \ - libopts \ libparse \ ntpd \ ntpdate \ @@ -95,9 +95,6 @@ DISTCLEANFILES = .gcc-warning ETAGS_ARGS = Makefile.am configure.ac -# HMS: make ports be the last directory... -# DIST_HOOK_DIRS = conf html scripts ports - # HMS: Keep .gcc-warning first, as that way it gets printed first. BUILT_SOURCES = \ .gcc-warning \ @@ -136,15 +133,15 @@ $(srcdir)/version: FRC.version case "$$x" in ''|$$y) ;; *) echo $$x > version ;; esac $(srcdir)/version.m4: $(srcdir)/packageinfo.sh - cd $(srcdir) && \ + TEMPDIR=`pwd` && export TEMPDIR && cd $(srcdir) && \ ./scripts/genver version.m4 $(srcdir)/include/version.def: $(srcdir)/packageinfo.sh - cd $(srcdir) && \ + TEMPDIR=`pwd` && export TEMPDIR && cd $(srcdir) && \ ./scripts/genver include/version.def $(srcdir)/include/version.texi: $(srcdir)/packageinfo.sh - cd $(srcdir) && \ + TEMPDIR=`pwd` && export TEMPDIR && cd $(srcdir) && \ ./scripts/genver include/version.texi $(srcdir)/.checkChangeLog: $(srcdir)/ChangeLog $(srcdir)/scripts/checkChangeLog @@ -156,7 +153,6 @@ libtool: $(LIBTOOL_DEPS) dist-hook: @find $(distdir) -type d -name SCCS -print | xargs rm -rf - @chmod u+w $(distdir)/ports/winnt .gcc-warning: @echo "Compiling with GCC now generates lots of new warnings." diff --git a/configure.ac b/configure.ac index e1d14c2c6..70ff57bb4 100644 --- a/configure.ac +++ b/configure.ac @@ -125,7 +125,7 @@ case "${enable_libopts_install+set}" in set) ;; *) enable_libopts_install=no ;; esac -LIBOPTS_CHECK(libopts) +LIBOPTS_CHECK(sntp/libopts) AC_FUNC_FORK diff --git a/deps-ver b/deps-ver index dd28e403a..9ad4b1451 100644 --- a/deps-ver +++ b/deps-ver @@ -1 +1 @@ -Fri Nov 13 17:21:31 UTC 2009 +Tue Nov 16 19:50:15 UTC 2010 diff --git a/sntp/libopts/COPYING.gplv3 b/sntp/libopts/COPYING.gplv3 index 2f9a4e932..d02ad3c8e 100644 --- a/sntp/libopts/COPYING.gplv3 +++ b/sntp/libopts/COPYING.gplv3 @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - copyright (c) 2009 by Bruce Korb - all rights reserved + Copyright (c) 2010 by Bruce Korb - all rights reserved Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/sntp/libopts/COPYING.lgplv3 b/sntp/libopts/COPYING.lgplv3 index 5b362d596..e2e0cec82 100644 --- a/sntp/libopts/COPYING.lgplv3 +++ b/sntp/libopts/COPYING.lgplv3 @@ -1,7 +1,7 @@ GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - copyright (c) 2009 by Bruce Korb - all rights reserved + Copyright (c) 2010 by Bruce Korb - all rights reserved Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. diff --git a/sntp/libopts/Makefile.am b/sntp/libopts/Makefile.am index adf3196b2..43dfb0abc 100644 --- a/sntp/libopts/Makefile.am +++ b/sntp/libopts/Makefile.am @@ -7,14 +7,14 @@ noinst_LTLIBRARIES = libopts.la endif libopts_la_SOURCES = libopts.c libopts_la_CPPFLAGS = -I$(top_srcdir) -libopts_la_LDFLAGS = -version-info 33:0:8 +libopts_la_LDFLAGS = -version-info 33:3:8 EXTRA_DIST = \ COPYING.gplv3 COPYING.lgplv3 COPYING.mbsd \ MakeDefs.inc README ag-char-map.h \ - autoopts/options.h autoopts/usage-txt.h autoopts.c \ - autoopts.h boolean.c compat/windows-config.h \ - compat/compat.h compat/pathfind.c compat/snprintf.c \ - compat/strdup.c compat/strchr.c configfile.c \ + autoopts/usage-txt.h autoopts/options.h autoopts.c \ + autoopts.h boolean.c compat/strchr.c \ + compat/windows-config.h compat/strdup.c compat/compat.h \ + compat/snprintf.c compat/pathfind.c configfile.c \ cook.c enumeration.c environment.c \ file.c genshell.c genshell.h \ load.c m4/libopts.m4 m4/liboptschk.m4 \ diff --git a/sntp/libopts/README b/sntp/libopts/README index 03c529d74..2a98071c6 100644 --- a/sntp/libopts/README +++ b/sntp/libopts/README @@ -85,7 +85,7 @@ will need to hand craft the rules for building the library. LICENSING: -This material is copyright (c) 1993-2009 by Bruce Korb. +This material is Copyright (c) 1993-2010 by Bruce Korb. You are licensed to use this under the terms of either the GNU Lesser General Public License (see: COPYING.lgpl), or, at your option, the modified Berkeley Software Distribution diff --git a/sntp/libopts/ag-char-map.h b/sntp/libopts/ag-char-map.h index 3659fe8e1..3ce10de6b 100644 --- a/sntp/libopts/ag-char-map.h +++ b/sntp/libopts/ag-char-map.h @@ -1,8 +1,19 @@ /* - * Character mapping generated 11/08/09 08:41:19 + * Character mapping generated 11/16/10 17:41:46 * * This file contains the character classifications * used by AutoGen and AutoOpts for identifying tokens. + * This file is part of AutoGen. + * AutoGen Copyright (c) 1992-2010 by Bruce Korb - all rights reserved + * AutoGen 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 3 of the License, or (at your option) any later + * version. + * AutoGen 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, see . */ #ifndef AG_CHAR_MAP_H_GUARD #define AG_CHAR_MAP_H_GUARD 1 @@ -62,8 +73,23 @@ // %table opt-char-cat // // %comment -// This file contains the character classifications -// used by AutoGen and AutoOpts for identifying tokens. +// This file contains the character classifications +// used by AutoGen and AutoOpts for identifying tokens. +// +// This file is part of AutoGen. +// AutoGen Copyright (c) 1992-2010 by Bruce Korb - all rights reserved +// +// AutoGen 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 3 of the License, or (at your option) any later +// version. +// +// AutoGen 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, see . // % // // lower-case "a-z" @@ -88,6 +114,9 @@ // suffix "-._" +alphanumeric // suffix-fmt "%/" +suffix // false-type "nNfF0\x00" +// file-name "/" +suffix +// end-token "\x00" +whitespace +// end-list-entry "," +end-token // #endif /* 0 -- mapping spec. source */ @@ -98,63 +127,66 @@ static inline int is_opt_char_cat_char(char ch, opt_char_cat_mask_t mask) { unsigned int ix = (unsigned char)ch; return ((ix < 0x7F) && ((opt_char_cat[ix] & mask) != 0)); } -#define IS_LOWER_CASE_CHAR(_c) is_opt_char_cat_char((_c), 0x00001) -#define IS_UPPER_CASE_CHAR(_c) is_opt_char_cat_char((_c), 0x00002) -#define IS_ALPHABETIC_CHAR(_c) is_opt_char_cat_char((_c), 0x00003) -#define IS_OCT_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x00004) -#define IS_DEC_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x0000C) -#define IS_HEX_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x0001C) -#define IS_ALPHANUMERIC_CHAR(_c) is_opt_char_cat_char((_c), 0x0000F) -#define IS_VAR_FIRST_CHAR(_c) is_opt_char_cat_char((_c), 0x00023) -#define IS_VARIABLE_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x0002F) -#define IS_OPTION_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x0006F) -#define IS_VALUE_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x000EF) -#define IS_HORIZ_WHITE_CHAR(_c) is_opt_char_cat_char((_c), 0x00100) -#define IS_COMPOUND_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x003EF) -#define IS_WHITESPACE_CHAR(_c) is_opt_char_cat_char((_c), 0x00500) -#define IS_UNQUOTABLE_CHAR(_c) is_opt_char_cat_char((_c), 0x00800) -#define IS_END_XML_TOKEN_CHAR(_c) is_opt_char_cat_char((_c), 0x01500) -#define IS_GRAPHIC_CHAR(_c) is_opt_char_cat_char((_c), 0x02000) -#define IS_PLUS_N_SPACE_CHAR(_c) is_opt_char_cat_char((_c), 0x04500) -#define IS_PUNCTUATION_CHAR(_c) is_opt_char_cat_char((_c), 0x08000) -#define IS_SUFFIX_CHAR(_c) is_opt_char_cat_char((_c), 0x1000F) -#define IS_SUFFIX_FMT_CHAR(_c) is_opt_char_cat_char((_c), 0x3000F) -#define IS_FALSE_TYPE_CHAR(_c) is_opt_char_cat_char((_c), 0x40000) +#define IS_LOWER_CASE_CHAR(_c) is_opt_char_cat_char((_c), 0x000001) +#define IS_UPPER_CASE_CHAR(_c) is_opt_char_cat_char((_c), 0x000002) +#define IS_ALPHABETIC_CHAR(_c) is_opt_char_cat_char((_c), 0x000003) +#define IS_OCT_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x000004) +#define IS_DEC_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x00000C) +#define IS_HEX_DIGIT_CHAR(_c) is_opt_char_cat_char((_c), 0x00001C) +#define IS_ALPHANUMERIC_CHAR(_c) is_opt_char_cat_char((_c), 0x00000F) +#define IS_VAR_FIRST_CHAR(_c) is_opt_char_cat_char((_c), 0x000023) +#define IS_VARIABLE_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x00002F) +#define IS_OPTION_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x00006F) +#define IS_VALUE_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x0000EF) +#define IS_HORIZ_WHITE_CHAR(_c) is_opt_char_cat_char((_c), 0x000100) +#define IS_COMPOUND_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x0003EF) +#define IS_WHITESPACE_CHAR(_c) is_opt_char_cat_char((_c), 0x000500) +#define IS_UNQUOTABLE_CHAR(_c) is_opt_char_cat_char((_c), 0x000800) +#define IS_END_XML_TOKEN_CHAR(_c) is_opt_char_cat_char((_c), 0x001500) +#define IS_GRAPHIC_CHAR(_c) is_opt_char_cat_char((_c), 0x002000) +#define IS_PLUS_N_SPACE_CHAR(_c) is_opt_char_cat_char((_c), 0x004500) +#define IS_PUNCTUATION_CHAR(_c) is_opt_char_cat_char((_c), 0x008000) +#define IS_SUFFIX_CHAR(_c) is_opt_char_cat_char((_c), 0x01000F) +#define IS_SUFFIX_FMT_CHAR(_c) is_opt_char_cat_char((_c), 0x03000F) +#define IS_FALSE_TYPE_CHAR(_c) is_opt_char_cat_char((_c), 0x040000) +#define IS_FILE_NAME_CHAR(_c) is_opt_char_cat_char((_c), 0x09000F) +#define IS_END_TOKEN_CHAR(_c) is_opt_char_cat_char((_c), 0x100500) +#define IS_END_LIST_ENTRY_CHAR(_c) is_opt_char_cat_char((_c), 0x300500) #ifdef AUTOOPTS_INTERNAL opt_char_cat_mask_t const opt_char_cat[128] = { - /*x00*/ 0x40000, /*x01*/ 0x00000, /*x02*/ 0x00000, /*x03*/ 0x00000, - /*x04*/ 0x00000, /*x05*/ 0x00000, /*x06*/ 0x00000, /*\a */ 0x00000, - /*\b */ 0x00400, /*\t */ 0x00100, /*\n */ 0x00400, /*\v */ 0x00400, - /*\f */ 0x00400, /*\r */ 0x00400, /*x0E*/ 0x00000, /*x0F*/ 0x00000, - /*x10*/ 0x00000, /*x11*/ 0x00000, /*x12*/ 0x00000, /*x13*/ 0x00000, - /*x14*/ 0x00000, /*x15*/ 0x00000, /*x16*/ 0x00000, /*x17*/ 0x00000, - /*x18*/ 0x00000, /*x19*/ 0x00000, /*x1A*/ 0x00000, /*x1B*/ 0x00000, - /*x1C*/ 0x00000, /*x1D*/ 0x00000, /*x1E*/ 0x00000, /*x1F*/ 0x00000, - /* */ 0x00100, /* ! */ 0x0A800, /* " */ 0x0A000, /* # */ 0x0A000, - /* $ */ 0x0A800, /* % */ 0x2A800, /* & */ 0x0A800, /* ' */ 0x0A000, - /* ( */ 0x0A000, /* ) */ 0x0A000, /* * */ 0x0A000, /* + */ 0x0E800, - /* , */ 0x0A000, /* - */ 0x1A840, /* . */ 0x1AA00, /* / */ 0x2B800, - /* 0 */ 0x42804, /* 1 */ 0x02804, /* 2 */ 0x02804, /* 3 */ 0x02804, - /* 4 */ 0x02804, /* 5 */ 0x02804, /* 6 */ 0x02804, /* 7 */ 0x02804, - /* 8 */ 0x02808, /* 9 */ 0x02808, /* : */ 0x0A880, /* ; */ 0x0A000, - /* < */ 0x0A000, /* = */ 0x0A000, /* > */ 0x0B000, /* ? */ 0x0A000, - /* @ */ 0x0A800, /* A */ 0x02812, /* B */ 0x02812, /* C */ 0x02812, - /* D */ 0x02812, /* E */ 0x02812, /* F */ 0x42812, /* G */ 0x02802, - /* H */ 0x02802, /* I */ 0x02802, /* J */ 0x02802, /* K */ 0x02802, - /* L */ 0x02802, /* M */ 0x02802, /* N */ 0x42802, /* O */ 0x02802, - /* P */ 0x02802, /* Q */ 0x02802, /* R */ 0x02802, /* S */ 0x02802, - /* T */ 0x02802, /* U */ 0x02802, /* V */ 0x02802, /* W */ 0x02802, - /* X */ 0x02802, /* Y */ 0x02802, /* Z */ 0x02802, /* [ */ 0x0A200, - /* \ */ 0x0A000, /* ] */ 0x0A200, /* ^ */ 0x0A840, /* _ */ 0x12820, - /* ` */ 0x0A000, /* a */ 0x02811, /* b */ 0x02811, /* c */ 0x02811, - /* d */ 0x02811, /* e */ 0x02811, /* f */ 0x42811, /* g */ 0x02801, - /* h */ 0x02801, /* i */ 0x02801, /* j */ 0x02801, /* k */ 0x02801, - /* l */ 0x02801, /* m */ 0x02801, /* n */ 0x42801, /* o */ 0x02801, - /* p */ 0x02801, /* q */ 0x02801, /* r */ 0x02801, /* s */ 0x02801, - /* t */ 0x02801, /* u */ 0x02801, /* v */ 0x02801, /* w */ 0x02801, - /* x */ 0x02801, /* y */ 0x02801, /* z */ 0x02801, /* { */ 0x0A000, - /* | */ 0x0A800, /* } */ 0x0A000, /* ~ */ 0x0A800, /*x7F*/ 0x00000 + /*x00*/ 0x140000, /*x01*/ 0x000000, /*x02*/ 0x000000, /*x03*/ 0x000000, + /*x04*/ 0x000000, /*x05*/ 0x000000, /*x06*/ 0x000000, /*\a */ 0x000000, + /*\b */ 0x000400, /*\t */ 0x000100, /*\n */ 0x000400, /*\v */ 0x000400, + /*\f */ 0x000400, /*\r */ 0x000400, /*x0E*/ 0x000000, /*x0F*/ 0x000000, + /*x10*/ 0x000000, /*x11*/ 0x000000, /*x12*/ 0x000000, /*x13*/ 0x000000, + /*x14*/ 0x000000, /*x15*/ 0x000000, /*x16*/ 0x000000, /*x17*/ 0x000000, + /*x18*/ 0x000000, /*x19*/ 0x000000, /*x1A*/ 0x000000, /*x1B*/ 0x000000, + /*x1C*/ 0x000000, /*x1D*/ 0x000000, /*x1E*/ 0x000000, /*x1F*/ 0x000000, + /* */ 0x000100, /* ! */ 0x00A800, /* " */ 0x00A000, /* # */ 0x00A000, + /* $ */ 0x00A800, /* % */ 0x02A800, /* & */ 0x00A800, /* ' */ 0x00A000, + /* ( */ 0x00A000, /* ) */ 0x00A000, /* * */ 0x00A000, /* + */ 0x00E800, + /* , */ 0x20A000, /* - */ 0x01A840, /* . */ 0x01AA00, /* / */ 0x0AB800, + /* 0 */ 0x042804, /* 1 */ 0x002804, /* 2 */ 0x002804, /* 3 */ 0x002804, + /* 4 */ 0x002804, /* 5 */ 0x002804, /* 6 */ 0x002804, /* 7 */ 0x002804, + /* 8 */ 0x002808, /* 9 */ 0x002808, /* : */ 0x00A880, /* ; */ 0x00A000, + /* < */ 0x00A000, /* = */ 0x00A000, /* > */ 0x00B000, /* ? */ 0x00A000, + /* @ */ 0x00A800, /* A */ 0x002812, /* B */ 0x002812, /* C */ 0x002812, + /* D */ 0x002812, /* E */ 0x002812, /* F */ 0x042812, /* G */ 0x002802, + /* H */ 0x002802, /* I */ 0x002802, /* J */ 0x002802, /* K */ 0x002802, + /* L */ 0x002802, /* M */ 0x002802, /* N */ 0x042802, /* O */ 0x002802, + /* P */ 0x002802, /* Q */ 0x002802, /* R */ 0x002802, /* S */ 0x002802, + /* T */ 0x002802, /* U */ 0x002802, /* V */ 0x002802, /* W */ 0x002802, + /* X */ 0x002802, /* Y */ 0x002802, /* Z */ 0x002802, /* [ */ 0x00A200, + /* \ */ 0x00A000, /* ] */ 0x00A200, /* ^ */ 0x00A840, /* _ */ 0x012820, + /* ` */ 0x00A000, /* a */ 0x002811, /* b */ 0x002811, /* c */ 0x002811, + /* d */ 0x002811, /* e */ 0x002811, /* f */ 0x042811, /* g */ 0x002801, + /* h */ 0x002801, /* i */ 0x002801, /* j */ 0x002801, /* k */ 0x002801, + /* l */ 0x002801, /* m */ 0x002801, /* n */ 0x042801, /* o */ 0x002801, + /* p */ 0x002801, /* q */ 0x002801, /* r */ 0x002801, /* s */ 0x002801, + /* t */ 0x002801, /* u */ 0x002801, /* v */ 0x002801, /* w */ 0x002801, + /* x */ 0x002801, /* y */ 0x002801, /* z */ 0x002801, /* { */ 0x00A000, + /* | */ 0x00A800, /* } */ 0x00A000, /* ~ */ 0x00A800, /*x7F*/ 0x000000 }; #endif /* AUTOOPTS_INTERNAL */ #endif /* AG_CHAR_MAP_H_GUARD */ diff --git a/sntp/libopts/autoopts.c b/sntp/libopts/autoopts.c index 21ad423f1..d3d6b41ee 100644 --- a/sntp/libopts/autoopts.c +++ b/sntp/libopts/autoopts.c @@ -1,7 +1,8 @@ -/* - * $Id: 56abb301f50605ec5bae137ded730e330d8d7735 $ - * Time-stamp: "2009-11-01 10:50:34 bkorb" +/** + * \file autoopts.c + * + * Time-stamp: "2010-07-17 10:41:35 bkorb" * * This file contains all of the routines that must be linked into * an executable to use the generated option processing. The optional @@ -10,7 +11,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -32,9 +33,8 @@ static char const zNil[] = ""; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static tSuccess -findOptDesc( tOptions* pOpts, tOptState* pOptState ); +findOptDesc(tOptions* pOpts, tOptState* pOptState); static tSuccess next_opt_arg_must(tOptions* pOpts, tOptState* pOptState); @@ -49,19 +49,19 @@ static tSuccess nextOption(tOptions* pOpts, tOptState* pOptState); static tSuccess -doPresets( tOptions* pOpts ); +doPresets(tOptions* pOpts); static int -checkConsistency( tOptions* pOpts ); +checkConsistency(tOptions* pOpts); /* = = = END-STATIC-FORWARD = = = */ LOCAL void * -ao_malloc( size_t sz ) +ao_malloc(size_t sz) { void * res = malloc(sz); if (res == NULL) { - fprintf( stderr, "malloc of %d bytes failed\n", (int)sz ); - exit( EXIT_FAILURE ); + fprintf(stderr, "malloc of %d bytes failed\n", (int)sz); + exit(EXIT_FAILURE); } return res; } @@ -69,12 +69,12 @@ ao_malloc( size_t sz ) #define malloc(_s) ao_malloc(_s) LOCAL void * -ao_realloc( void *p, size_t sz ) +ao_realloc(void *p, size_t sz) { - void * res = realloc(p, sz); + void * res = (p == NULL) ? malloc(sz) : realloc(p, sz); if (res == NULL) { - fprintf( stderr, "realloc of %d bytes at 0x%p failed\n", (int)sz, p ); - exit( EXIT_FAILURE ); + fprintf(stderr, "realloc of %d bytes at 0x%p failed\n", (int)sz, p); + exit(EXIT_FAILURE); } return res; } @@ -83,7 +83,7 @@ ao_realloc( void *p, size_t sz ) LOCAL void -ao_free( void *p ) +ao_free(void *p) { if (p != NULL) free(p); @@ -93,12 +93,12 @@ ao_free( void *p ) LOCAL char * -ao_strdup( char const *str ) +ao_strdup(char const *str) { char * res = strdup(str); if (res == NULL) { fprintf(stderr, "strdup of %d byte string failed\n", (int)strlen(str)); - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); } return res; } @@ -128,7 +128,7 @@ ao_strdup( char const *str ) * invokes the handler procedure, if any. */ LOCAL tSuccess -handleOption( tOptions* pOpts, tOptState* pOptState ) +handleOption(tOptions* pOpts, tOptState* pOptState) { /* * Save a copy of the option procedure pointer. @@ -176,8 +176,8 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) * THEN we have a usage problem. */ if (p->optActualIndex != pOD->optIndex) { - fprintf( stderr, (char*)zMultiEquiv, p->pz_Name, pOD->pz_Name, - (pOpts->pOptDesc + p->optActualIndex)->pz_Name); + fprintf(stderr, (char*)zMultiEquiv, p->pz_Name, pOD->pz_Name, + (pOpts->pOptDesc + p->optActualIndex)->pz_Name); return FAILURE; } } else { @@ -226,7 +226,7 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) char const * pzEqv = (pOD->optEquivIndex != NO_EQUIVALENT) ? zEquiv : zNil; - fputs( zErrOnly, stderr ); + fputs(zErrOnly, stderr); if (pOD->optMaxCt > 1) fprintf(stderr, zAtMost, pOD->optMaxCt, pOD->pz_Name, pzEqv); @@ -241,7 +241,7 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) * If provided a procedure to call, call it */ if (pOP != NULL) - (*pOP)( pOpts, pOD ); + (*pOP)(pOpts, pOD); return SUCCESS; } @@ -260,10 +260,10 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) * Find the long option descriptor for the current option */ LOCAL tSuccess -longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) +longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState) { ag_bool disable = AG_FALSE; - char* pzEq = strchr( pzOptName, '=' ); + char* pzEq = strchr(pzOptName, '='); tOptDesc* pOD = pOpts->pOptDesc; int idx = 0; int idxLim = pOpts->optCt; @@ -285,17 +285,20 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) pzOptName = opt_name_buf; pzEq++; - } else nameLen = strlen( pzOptName ); + } else nameLen = strlen(pzOptName); do { - if (SKIP_OPT(pOD)) { - if ( (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT)) - || (pOD->pz_Name == NULL)) - continue; - } - else assert(pOD->pz_Name != NULL); + /* + * If option disabled or a doc option, skip to next + */ + if (pOD->pz_Name == NULL) + continue; - if (strneqvcmp( pzOptName, pOD->pz_Name, nameLen ) == 0) { + if ( SKIP_OPT(pOD) + && (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT))) + continue; + + if (strneqvcmp(pzOptName, pOD->pz_Name, nameLen) == 0) { /* * IF we have a complete match * THEN it takes priority over any already located partial @@ -408,7 +411,7 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) * Find the short option descriptor for the current option */ LOCAL tSuccess -shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) +shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState) { tOptDesc* pRes = pOpts->pOptDesc; int ct = pOpts->optCt; @@ -461,8 +464,8 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) * THEN call the usage procedure. */ if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) { - fprintf( stderr, zIllOptChr, pOpts->pzProgPath, optValue ); - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + fprintf(stderr, zIllOptChr, pOpts->pzProgPath, optValue); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); } return FAILURE; @@ -475,7 +478,7 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) * Find the option descriptor for the current option */ static tSuccess -findOptDesc( tOptions* pOpts, tOptState* pOptState ) +findOptDesc(tOptions* pOpts, tOptState* pOptState) { /* * IF we are continuing a short option list (e.g. -xyz...) @@ -483,7 +486,7 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * OTHERWISE see if there is room to advance and then do so. */ if ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL)) - return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState ); + return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState); if (pOpts->curOptIdx >= pOpts->origArgCt) return PROBLEM; /* NORMAL COMPLETION */ @@ -551,12 +554,12 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * Therefore, if long options are not to be accepted, we punt. */ if ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) { - fprintf( stderr, zIllOptStr, pOpts->pzProgPath, - zIllegal, pOpts->pzCurOpt-2 ); + fprintf(stderr, zIllOptStr, pOpts->pzProgPath, + zIllegal, pOpts->pzCurOpt-2); return FAILURE; } - return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState ); + return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState); } /* @@ -565,9 +568,9 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * short (i.e. single character) option. */ if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0) - return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState ); + return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState); - return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState ); + return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState); } @@ -600,9 +603,8 @@ next_opt_arg_must(tOptions* pOpts, tOptState* pOptState) default: #ifdef DEBUG - fputs( "AutoOpts lib error: option type not selected\n", - stderr ); - exit( EXIT_FAILURE ); + fputs("AutoOpts lib error: option type not selected\n", stderr); + exit(EXIT_FAILURE); #endif case TOPT_DEFAULT: @@ -617,8 +619,7 @@ next_opt_arg_must(tOptions* pOpts, tOptState* pOptState) * Make sure we did not overflow the argument list. */ if (pOpts->curOptIdx > pOpts->origArgCt) { - fprintf( stderr, zMisArg, pOpts->pzProgPath, - pOptState->pOD->pz_Name ); + fprintf(stderr, zMisArg, pOpts->pzProgPath, pOptState->pOD->pz_Name); return FAILURE; } @@ -660,7 +661,7 @@ next_opt_arg_may(tOptions* pOpts, tOptState* pOptState) * with a `=' character) *AND* we are not in named argument mode */ if ( (pOptState->pzOptArg == NULL) - && (! NAMED_OPTS(pOpts))) { + && (! NAMED_OPTS(pOpts))) { char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ]; /* @@ -680,7 +681,7 @@ next_opt_arg_may(tOptions* pOpts, tOptState* pOptState) default: case TOPT_DEFAULT: fputs(zAO_Woops, stderr ); - exit( EX_SOFTWARE ); + exit(EX_SOFTWARE); } /* @@ -733,8 +734,8 @@ nextOption(tOptions* pOpts, tOptState* pOptState) { { tSuccess res; - res = findOptDesc( pOpts, pOptState ); - if (! SUCCESSFUL( res )) + res = findOptDesc(pOpts, pOptState); + if (! SUCCESSFUL(res)) return res; } @@ -796,7 +797,7 @@ nextOption(tOptions* pOpts, tOptState* pOptState) * doImmediateOpts - scan the command line for immediate action options */ LOCAL tSuccess -doImmediateOpts( tOptions* pOpts ) +doImmediateOpts(tOptions* pOpts) { pOpts->curOptIdx = 1; /* start by skipping program name */ pOpts->pzCurOpt = NULL; @@ -808,7 +809,7 @@ doImmediateOpts( tOptions* pOpts ) for (;;) { tOptState optState = OPTSTATE_INITIALIZER(PRESET); - switch (nextOption( pOpts, &optState )) { + switch (nextOption(pOpts, &optState)) { case FAILURE: goto optionsDone; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; @@ -820,18 +821,18 @@ doImmediateOpts( tOptions* pOpts ) if (! DO_IMMEDIATELY(optState.flags)) continue; - if (! SUCCESSFUL( handleOption( pOpts, &optState ))) + if (! SUCCESSFUL(handleOption(pOpts, &optState))) break; } optionsDone:; if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); return FAILURE; } LOCAL tSuccess -doRegularOpts( tOptions* pOpts ) +doRegularOpts(tOptions* pOpts) { /* * Now, process all the options from our current position onward. @@ -841,7 +842,7 @@ doRegularOpts( tOptions* pOpts ) for (;;) { tOptState optState = OPTSTATE_INITIALIZER(DEFINED); - switch (nextOption( pOpts, &optState )) { + switch (nextOption(pOpts, &optState)) { case FAILURE: goto optionsDone; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; @@ -857,11 +858,11 @@ doRegularOpts( tOptions* pOpts ) optState.pOD->optOccCt--; /* don't count last time */ } - if (! SUCCESSFUL( handleOption( pOpts, &optState ))) + if (! SUCCESSFUL(handleOption(pOpts, &optState))) break; } optionsDone:; if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); return FAILURE; } @@ -870,11 +871,11 @@ doRegularOpts( tOptions* pOpts ) * doPresets - check for preset values from a config file or the envrionment */ static tSuccess -doPresets( tOptions* pOpts ) +doPresets(tOptions* pOpts) { tOptDesc * pOD = NULL; - if (! SUCCESSFUL( doImmediateOpts( pOpts ))) + if (! SUCCESSFUL(doImmediateOpts(pOpts))) return FAILURE; /* @@ -898,22 +899,22 @@ doPresets( tOptions* pOpts ) * THEN do any environment presets and leave. */ if (pOpts->papzHomeList == NULL) { - doEnvPresets( pOpts, ENV_ALL ); + doEnvPresets(pOpts, ENV_ALL); } else { - doEnvPresets( pOpts, ENV_IMM ); + doEnvPresets(pOpts, ENV_IMM); /* * Check to see if environment variables have disabled presetting. */ if ((pOD != NULL) && ! DISABLED_OPT(pOD)) - internalFileLoad( pOpts ); + internalFileLoad(pOpts); /* * ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment * variable options. Only the loading of .rc files. */ - doEnvPresets( pOpts, ENV_NON_IMM ); + doEnvPresets(pOpts, ENV_NON_IMM); } pOpts->fOptSet &= ~OPTPROC_PRESETTING; @@ -928,7 +929,7 @@ doPresets( tOptions* pOpts ) * Make sure that the argument list passes our consistency tests. */ static int -checkConsistency( tOptions* pOpts ) +checkConsistency(tOptions* pOpts) { int errCt = 0; tOptDesc* pOD = pOpts->pOptDesc; @@ -953,7 +954,7 @@ checkConsistency( tOptions* pOpts ) if (UNUSED_OPT(p)) { const tOptDesc* pN = pOpts->pOptDesc + pMust[-1]; errCt++; - fprintf( stderr, zReqFmt, pOD->pz_Name, pN->pz_Name ); + fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name); } if (*pMust == NO_EQUIVALENT) @@ -965,7 +966,7 @@ checkConsistency( tOptions* pOpts ) if (SELECTED_OPT(p)) { const tOptDesc* pN = pOpts->pOptDesc + pCant[-1]; errCt++; - fprintf( stderr, zCantFmt, pOD->pz_Name, pN->pz_Name ); + fprintf(stderr, zCantFmt, pOD->pz_Name, pN->pz_Name); } if (*pCant == NO_EQUIVALENT) @@ -997,8 +998,8 @@ checkConsistency( tOptions* pOpts ) errCt++; if (pOD->optMinCt > 1) - fprintf( stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt ); - else fprintf( stderr, zNeedOne, pOD->pz_Name ); + fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt); + else fprintf(stderr, zNeedOne, pOD->pz_Name); } while (0); if (--oCt <= 0) @@ -1017,7 +1018,7 @@ checkConsistency( tOptions* pOpts ) */ if ((pOpts->fOptSet & OPTPROC_NO_ARGS) != 0) { if (pOpts->origArgCt > pOpts->curOptIdx) { - fprintf( stderr, zNoArgs, pOpts->pzProgName ); + fprintf(stderr, zNoArgs, pOpts->pzProgName); ++errCt; } } @@ -1027,7 +1028,7 @@ checkConsistency( tOptions* pOpts ) */ else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) { if (pOpts->origArgCt <= pOpts->curOptIdx) { - fprintf( stderr, zArgsMust, pOpts->pzProgName ); + fprintf(stderr, zArgsMust, pOpts->pzProgName); ++errCt; } } @@ -1095,8 +1096,8 @@ optionProcess( int argCt, char** argVect ) { - if (! SUCCESSFUL( validateOptionsStruct( pOpts, argVect[0] ))) - exit( EX_SOFTWARE ); + if (! SUCCESSFUL(validateOptionsStruct(pOpts, argVect[0]))) + exit(EX_SOFTWARE); /* * Establish the real program name, the program full path, @@ -1107,7 +1108,7 @@ optionProcess( pOpts->origArgVect = argVect; pOpts->fOptSet |= OPTPROC_INITDONE; - if (! SUCCESSFUL( doPresets( pOpts ))) + if (! SUCCESSFUL(doPresets(pOpts))) return 0; /* @@ -1125,7 +1126,7 @@ optionProcess( } if ((pOpts->fOptSet & OPTPROC_REORDER) != 0) - optionSort( pOpts ); + optionSort(pOpts); pOpts->curOptIdx = 1; pOpts->pzCurOpt = NULL; @@ -1140,7 +1141,7 @@ optionProcess( pOpts->pzCurOpt = NULL; } - if (! SUCCESSFUL( doRegularOpts( pOpts ))) + if (! SUCCESSFUL(doRegularOpts(pOpts))) return pOpts->origArgCt; /* @@ -1154,9 +1155,9 @@ optionProcess( && (pOpts->specOptIdx.save_opts != 0)) { tOptDesc* pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts; - if (SELECTED_OPT( pOD )) { - optionSaveFile( pOpts ); - exit( EXIT_SUCCESS ); + if (SELECTED_OPT(pOD)) { + optionSaveFile(pOpts); + exit(EXIT_SUCCESS); } } @@ -1165,8 +1166,8 @@ optionProcess( * THEN look for too few occurrences of required options */ if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) { - if (checkConsistency( pOpts ) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + if (checkConsistency(pOpts) != 0) + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); } return pOpts->curOptIdx; diff --git a/sntp/libopts/autoopts.h b/sntp/libopts/autoopts.h index 0a99df4fd..44675d68e 100644 --- a/sntp/libopts/autoopts.h +++ b/sntp/libopts/autoopts.h @@ -1,15 +1,15 @@ /* - * Time-stamp: "2008-11-01 20:08:06 bkorb" + * \file autoopts.h * - * autoopts.h $Id: d5e30331d37ca10ec88c592d24d8615dd6c1f0ee $ + * Time-stamp: "2010-07-17 10:39:18 bkorb" * * This file defines all the global structures and special values * used in the automated option processing library. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -110,10 +110,13 @@ typedef int tDirection; typedef int tSuccess; -#define SUCCEEDED( p ) ((p) == SUCCESS) -#define SUCCESSFUL( p ) SUCCEEDED( p ) -#define FAILED( p ) ((p) < SUCCESS) -#define HADGLITCH( p ) ((p) > SUCCESS) +#define SUCCEEDED(p) ((p) == SUCCESS) +#define SUCCESSFUL(p) SUCCEEDED(p) +#define FAILED(p) ((p) < SUCCESS) +#define HADGLITCH(p) ((p) > SUCCESS) + +#define ShellAsString(_s) #_s +#define DEFAULT_SHELL ShellAsString(CONFIG_SHELL) /* * When loading a line (or block) of text as an option, the value can @@ -183,9 +186,9 @@ typedef struct { { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED } #define TEXTTO_TABLE \ - _TT_( LONGUSAGE ) \ - _TT_( USAGE ) \ - _TT_( VERSION ) + _TT_(LONGUSAGE) \ + _TT_(USAGE) \ + _TT_(VERSION) #define _TT_(n) \ TT_ ## n , @@ -211,24 +214,24 @@ typedef struct { tCC* pzTime; } arg_types_t; -#define AGALOC( c, w ) ao_malloc((size_t)c) -#define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c) -#define AGFREE(_p) do{void*X=(void*)_p;ao_free(X);}while(0) -#define AGDUPSTR( p, s, w ) (p = ao_strdup(s)) +#define AGALOC(c, w) ao_malloc((size_t)c) +#define AGREALOC(p, c, w) ao_realloc((void*)p, (size_t)c) +#define AGFREE(_p) do{void*X=(void*)_p;ao_free(X);}while(0) +#define AGDUPSTR(p, s, w) (p = ao_strdup(s)) static void * -ao_malloc( size_t sz ); +ao_malloc(size_t sz); static void * -ao_realloc( void *p, size_t sz ); +ao_realloc(void *p, size_t sz); static void -ao_free( void *p ); +ao_free(void *p); static char * -ao_strdup( char const *str ); +ao_strdup(char const *str); -#define TAGMEM( m, t ) +#define TAGMEM(m, t) /* * DO option handling? @@ -335,8 +338,8 @@ ao_strdup( char const *str ); #endif #ifndef HAVE_STRCHR -extern char* strchr( char const *s, int c); -extern char* strrchr( char const *s, int c); +extern char* strchr(char const *s, int c); +extern char* strrchr(char const *s, int c); #endif /* diff --git a/sntp/libopts/autoopts/options.h b/sntp/libopts/autoopts/options.h index 2c1032109..03810572f 100644 --- a/sntp/libopts/autoopts/options.h +++ b/sntp/libopts/autoopts/options.h @@ -2,7 +2,7 @@ * * DO NOT EDIT THIS FILE (options.h) * - * It has been AutoGen-ed November 8, 2009 at 08:41:08 AM by AutoGen 5.9.10pre13 + * It has been AutoGen-ed November 16, 2010 at 05:41:49 PM by AutoGen 5.11.2pre7 * From the definitions funcs.def * and the template file options_h * @@ -57,30 +57,33 @@ * to an option descriptor must be obtained. There are two ways: * * 1. inside an option processing procedure, it is the second argument, - * conventionally "tOptDesc* pOD". + * conventionally "tOptDesc* pOD". * - * 2. Outside of an option procedure (or to reference a different option - * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )". + * 2. Outside of an option procedure (or to reference a different option + * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )". * * See the relevant generated header file to determine which and what * values for "opt_name" are available. */ - -#define OPTIONS_STRUCT_VERSION 135168 -#define OPTIONS_VERSION_STRING "33:0:8" +#define OPTIONS_STRUCT_VERSION 135171 +#define OPTIONS_VERSION_STRING "33:3:8" #define OPTIONS_MINIMUM_VERSION 102400 #define OPTIONS_MIN_VER_STRING "25:0:0" typedef enum { - OPARG_TYPE_NONE = 0, - OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ - OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ - OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ - OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ - OPARG_TYPE_NUMERIC = 5, /* opt arg has numeric value */ - OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */ - OPARG_TYPE_FILE = 7, /* option arg names a file */ - OPARG_TYPE_TIME = 8 /* opt arg is a time duration */ + OPARG_TYPE_NONE = 0, + OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ + OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ + OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ + OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ + OPARG_TYPE_NUMERIC = 5, /* opt arg is a long int */ + OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */ + OPARG_TYPE_FILE = 7, /* option arg names a file */ + OPARG_TYPE_TIME = 8, /* opt arg is a time duration */ + OPARG_TYPE_FLOAT = 9, /* opt arg is a floating point num */ + OPARG_TYPE_DOUBLE = 10, /* opt arg is a double prec. float */ + OPARG_TYPE_LONG_DOUBLE = 11, /* opt arg is a long double prec. */ + OPARG_TYPE_LONG_LONG = 12 /* opt arg is a long long int */ } teOptArgType; typedef struct optionValue { @@ -242,6 +245,7 @@ typedef enum { OPTPROC_REORDER_ID = 11, /* reorder operands after opts */ OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */ OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */ + OPTPROC_MISUSE_ID = 14, /* no usage on usage error */ OPTPROC_NXLAT_OPT_CFG_ID = 16, /* suppress for config only */ OPTPROC_NXLAT_OPT_ID = 17, /* suppress xlation always */ OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */ @@ -262,10 +266,11 @@ typedef enum { #define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID) #define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID) #define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID) +#define OPTPROC_MISUSE (1U << OPTPROC_MISUSE_ID) #define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID) #define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID) #define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID) -#define OPTPROC_STATE_MASK 0x000B3FFFU +#define OPTPROC_STATE_MASK 0x000B7FFFU #define OPTPROC_NO_XLAT_MASK ( \ OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \ @@ -355,6 +360,8 @@ typedef union { int argFd; } optArgBucket_t; +#define pzLastArg optArg.argString + /* * Descriptor structure for each option. * Only the fields marked "PUBLIC" are for public use. @@ -373,7 +380,6 @@ struct optDesc { tAoUI fOptState; /* PUBLIC */ tAoUI reserved; optArgBucket_t optArg; /* PUBLIC */ -# define pzLastArg optArg.argString void* optCookie; /* PUBLIC */ int const * const pOptMust; @@ -503,7 +509,7 @@ extern "C" { * The following routines may be coded into AutoOpts client code: */ -/* From: tokenize.c line 117 +/* From: tokenize.c line 166 * * ao_string_tokenize - tokenize an input string * @@ -547,7 +553,7 @@ extern "C" { extern token_list_t* ao_string_tokenize(char const*); -/* From: configfile.c line 85 +/* From: configfile.c line 71 * * configFileLoad - parse a configuration file * @@ -567,7 +573,7 @@ extern token_list_t* ao_string_tokenize(char const*); extern const tOptionValue* configFileLoad(char const*); -/* From: configfile.c line 897 +/* From: configfile.c line 934 * * optionFileLoad - Load the locatable config files, in order * @@ -597,7 +603,7 @@ extern const tOptionValue* configFileLoad(char const*); extern int optionFileLoad(tOptions*, char const*); -/* From: configfile.c line 217 +/* From: configfile.c line 203 * * optionFindNextValue - find a hierarcicaly valued option instance * @@ -616,7 +622,7 @@ extern int optionFileLoad(tOptions*, char const*); extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*); -/* From: configfile.c line 143 +/* From: configfile.c line 129 * * optionFindValue - find a hierarcicaly valued option instance * @@ -633,7 +639,7 @@ extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionVal extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char const*); -/* From: restore.c line 165 +/* From: restore.c line 166 * * optionFree - free allocated option processing memory * @@ -646,7 +652,7 @@ extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char co extern void optionFree(tOptions*); -/* From: configfile.c line 286 +/* From: configfile.c line 272 * * optionGetValue - get a specific value from a hierarcical list * @@ -664,7 +670,7 @@ extern void optionFree(tOptions*); extern const tOptionValue* optionGetValue(const tOptionValue*, char const*); -/* From: load.c line 498 +/* From: load.c line 482 * * optionLoadLine - process a string for an option name and value * @@ -688,7 +694,7 @@ extern const tOptionValue* optionGetValue(const tOptionValue*, char const*); extern void optionLoadLine(tOptions*, char const*); -/* From: configfile.c line 345 +/* From: configfile.c line 331 * * optionNextValue - get the next value from a hierarchical list * @@ -707,7 +713,7 @@ extern void optionLoadLine(tOptions*, char const*); extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*); -/* From: usage.c line 107 +/* From: usage.c line 204 * * optionOnlyUsage - Print usage text for just the options * @@ -722,7 +728,7 @@ extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionVal extern void optionOnlyUsage(tOptions*, int); -/* From: autoopts.c line 1058 +/* From: autoopts.c line 1059 * * optionProcess - this is the main option processing routine * @@ -752,7 +758,7 @@ extern void optionOnlyUsage(tOptions*, int); extern int optionProcess(tOptions*, int, char**); -/* From: restore.c line 122 +/* From: restore.c line 123 * * optionRestore - restore option state from memory copy * @@ -781,7 +787,7 @@ extern void optionRestore(tOptions*); * option, or by appending the @code{rcfile} attribute to the last * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it * will default to @code{.@i{programname}rc}. If you wish to specify another - * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro. + * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro. * * The recommend usage is as follows: * @example @@ -794,7 +800,7 @@ extern void optionRestore(tOptions*); extern void optionSaveFile(tOptions*); -/* From: restore.c line 70 +/* From: restore.c line 71 * * optionSaveState - saves the option state to memory * @@ -816,7 +822,7 @@ extern void optionSaveFile(tOptions*); extern void optionSaveState(tOptions*); -/* From: nested.c line 569 +/* From: nested.c line 551 * * optionUnloadNested - Deallocate the memory for a nested value * @@ -830,7 +836,7 @@ extern void optionSaveState(tOptions*); extern void optionUnloadNested(tOptionValue const *); -/* From: version.c line 37 +/* From: version.c line 36 * * optionVersion - return the compiled AutoOpts version number * @@ -842,7 +848,7 @@ extern void optionUnloadNested(tOptionValue const *); extern char const* optionVersion(void); -/* From: ../compat/pathfind.c line 32 +/* From: ../compat/pathfind.c line 29 * * pathfind - fild a file in a list of directories * @@ -886,7 +892,7 @@ extern char* pathfind(char const*, char const*, char const*); #endif /* HAVE_PATHFIND */ -/* From: streqvcmp.c line 208 +/* From: streqvcmp.c line 209 * * strequate - map a list of characters to the same value * @@ -901,7 +907,7 @@ extern char* pathfind(char const*, char const*, char const*); extern void strequate(char const*); -/* From: streqvcmp.c line 118 +/* From: streqvcmp.c line 119 * * streqvcmp - compare two strings with an equivalence mapping * @@ -920,7 +926,7 @@ extern void strequate(char const*); extern int streqvcmp(char const*, char const*); -/* From: streqvcmp.c line 155 +/* From: streqvcmp.c line 156 * * streqvmap - Set the character mappings for the streqv functions * @@ -936,7 +942,7 @@ extern int streqvcmp(char const*, char const*); * are incremented and the process repeated until @code{ct} entries have been * set. For example, * @example - * streqvmap( 'a', 'A', 26 ); + * streqvmap('a', 'A', 26); * @end example * @noindent * will alter the mapping so that all English lower case letters @@ -948,7 +954,7 @@ extern int streqvcmp(char const*, char const*); extern void streqvmap(char, char, int); -/* From: streqvcmp.c line 77 +/* From: streqvcmp.c line 78 * * strneqvcmp - compare two strings with an equivalence mapping * @@ -969,7 +975,7 @@ extern void streqvmap(char, char, int); extern int strneqvcmp(char const*, char const*, int); -/* From: streqvcmp.c line 234 +/* From: streqvcmp.c line 235 * * strtransform - convert a string into its mapped-to value * @@ -993,8 +999,6 @@ extern char* ao_string_cook(char*, int*); extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int); -extern void export_options_to_guile(tOptions*); - extern void genshelloptUsage(tOptions*, int); extern void optionBooleanVal(tOptions*, tOptDesc*); @@ -1003,7 +1007,7 @@ extern uintptr_t optionEnumerationVal(tOptions*, tOptDesc*, char const * const * extern void optionFileCheck(tOptions*, tOptDesc*, teOptFileType, tuFileMode); -extern char const* optionKeywordName(tOptDesc*, unsigned int); +extern char const * optionKeywordName(tOptDesc*, unsigned int); extern void optionLoadOpt(tOptions*, tOptDesc*); diff --git a/sntp/libopts/autoopts/usage-txt.h b/sntp/libopts/autoopts/usage-txt.h index 4abf1071f..ad5ef473b 100644 --- a/sntp/libopts/autoopts/usage-txt.h +++ b/sntp/libopts/autoopts/usage-txt.h @@ -2,12 +2,12 @@ * * DO NOT EDIT THIS FILE (usage-txt.h) * - * It has been AutoGen-ed November 8, 2009 at 08:41:07 AM by AutoGen 5.9.10pre13 + * It has been AutoGen-ed November 16, 2010 at 05:41:47 PM by AutoGen 5.11.2pre7 * From the definitions usage-txt.def * and the template file usage-txt.tpl * * This file handles all the bookkeeping required for tracking all the little - * tiny strings used by the AutoOpts library. There are 134 + * tiny strings used by the AutoOpts library. There are 137 * of them. This is not versioned because it is entirely internal to the * library and accessed by client code only in a very well-controlled way: * they may substitute translated strings using a procedure that steps through @@ -44,7 +44,7 @@ typedef struct { char* utpz_GnuTimeArg; char* utpz_GnuNumArg; char* utpz_GnuStrArg; - cch_t* apz_str[ 127 ]; + cch_t* apz_str[ 130 ]; } usage_text_t; /* @@ -75,122 +75,125 @@ extern usage_text_t option_usage_text; #define zBadVerArg (option_usage_text.apz_str[ 15]) #define zCantFmt (option_usage_text.apz_str[ 16]) #define zCantSave (option_usage_text.apz_str[ 17]) -#define zDefaultOpt (option_usage_text.apz_str[ 18]) -#define zDis (option_usage_text.apz_str[ 19]) -#define zDisabledErr (option_usage_text.apz_str[ 20]) -#define zDisabledOpt (option_usage_text.apz_str[ 21]) -#define zDisabledWhy (option_usage_text.apz_str[ 22]) -#define zEnab (option_usage_text.apz_str[ 23]) -#define zEquiv (option_usage_text.apz_str[ 24]) -#define zErrOnly (option_usage_text.apz_str[ 25]) -#define zExamineFmt (option_usage_text.apz_str[ 26]) -#define zFiveSpaces (option_usage_text.apz_str[ 27]) -#define zFlagOkay (option_usage_text.apz_str[ 28]) -#define zFmtFmt (option_usage_text.apz_str[ 29]) -#define zForkFail (option_usage_text.apz_str[ 30]) -#define zFSErrOptLoad (option_usage_text.apz_str[ 31]) -#define zFSErrReadFile (option_usage_text.apz_str[ 32]) -#define zFSOptError (option_usage_text.apz_str[ 33]) -#define zFSOptErrMayExist (option_usage_text.apz_str[ 34]) -#define zFSOptErrMustExist (option_usage_text.apz_str[ 35]) -#define zFSOptErrNoExist (option_usage_text.apz_str[ 36]) -#define zFSOptErrOpen (option_usage_text.apz_str[ 37]) -#define zFSOptErrFopen (option_usage_text.apz_str[ 38]) -#define zFileCannotExist (option_usage_text.apz_str[ 39]) -#define zFileMustExist (option_usage_text.apz_str[ 40]) -#define zGenshell (option_usage_text.apz_str[ 41]) +#define zCfgAO_Flags (option_usage_text.apz_str[ 18]) +#define zCfgProg (option_usage_text.apz_str[ 19]) +#define zDefaultOpt (option_usage_text.apz_str[ 20]) +#define zDis (option_usage_text.apz_str[ 21]) +#define zDisabledErr (option_usage_text.apz_str[ 22]) +#define zDisabledOpt (option_usage_text.apz_str[ 23]) +#define zDisabledWhy (option_usage_text.apz_str[ 24]) +#define zEnab (option_usage_text.apz_str[ 25]) +#define zEquiv (option_usage_text.apz_str[ 26]) +#define zErrOnly (option_usage_text.apz_str[ 27]) +#define zExamineFmt (option_usage_text.apz_str[ 28]) +#define zFiveSpaces (option_usage_text.apz_str[ 29]) +#define zFlagOkay (option_usage_text.apz_str[ 30]) +#define zFmtFmt (option_usage_text.apz_str[ 31]) +#define zForkFail (option_usage_text.apz_str[ 32]) +#define zFreopenFail (option_usage_text.apz_str[ 33]) +#define zFSErrOptLoad (option_usage_text.apz_str[ 34]) +#define zFSErrReadFile (option_usage_text.apz_str[ 35]) +#define zFSOptError (option_usage_text.apz_str[ 36]) +#define zFSOptErrMayExist (option_usage_text.apz_str[ 37]) +#define zFSOptErrMustExist (option_usage_text.apz_str[ 38]) +#define zFSOptErrNoExist (option_usage_text.apz_str[ 39]) +#define zFSOptErrOpen (option_usage_text.apz_str[ 40]) +#define zFSOptErrFopen (option_usage_text.apz_str[ 41]) +#define zFileCannotExist (option_usage_text.apz_str[ 42]) +#define zFileMustExist (option_usage_text.apz_str[ 43]) +#define zGenshell (option_usage_text.apz_str[ 44]) #define zGnuBoolArg (option_usage_text.utpz_GnuBoolArg) -#define zGnuBreak (option_usage_text.apz_str[ 42]) +#define zGnuBreak (option_usage_text.apz_str[ 45]) #define zGnuKeyArg (option_usage_text.utpz_GnuKeyArg) #define zGnuFileArg (option_usage_text.utpz_GnuFileArg) #define zGnuKeyLArg (option_usage_text.utpz_GnuKeyLArg) #define zGnuTimeArg (option_usage_text.utpz_GnuTimeArg) -#define zGnuNestArg (option_usage_text.apz_str[ 43]) +#define zGnuNestArg (option_usage_text.apz_str[ 46]) #define zGnuNumArg (option_usage_text.utpz_GnuNumArg) -#define zGnuOptArg (option_usage_text.apz_str[ 44]) -#define zGnuOptFmt (option_usage_text.apz_str[ 45]) +#define zGnuOptArg (option_usage_text.apz_str[ 47]) +#define zGnuOptFmt (option_usage_text.apz_str[ 48]) #define zGnuStrArg (option_usage_text.utpz_GnuStrArg) -#define zIllOptChr (option_usage_text.apz_str[ 46]) -#define zIllOptStr (option_usage_text.apz_str[ 47]) -#define zIllegal (option_usage_text.apz_str[ 48]) -#define zIntRange (option_usage_text.apz_str[ 49]) -#define zInvalOptDesc (option_usage_text.apz_str[ 50]) -#define zLowerBits (option_usage_text.apz_str[ 51]) -#define zMembers (option_usage_text.apz_str[ 52]) -#define zMisArg (option_usage_text.apz_str[ 53]) -#define zMultiEquiv (option_usage_text.apz_str[ 54]) -#define zMust (option_usage_text.apz_str[ 55]) -#define zNeedOne (option_usage_text.apz_str[ 56]) -#define zNoArg (option_usage_text.apz_str[ 57]) -#define zNoArgs (option_usage_text.apz_str[ 58]) -#define zNoCreat (option_usage_text.apz_str[ 59]) -#define zNoFlags (option_usage_text.apz_str[ 60]) -#define zNoKey (option_usage_text.apz_str[ 61]) -#define zNoLim (option_usage_text.apz_str[ 62]) -#define zNoPreset (option_usage_text.apz_str[ 63]) -#define zNoResetArg (option_usage_text.apz_str[ 64]) -#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 65]) -#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 66]) -#define zNoStat (option_usage_text.apz_str[ 67]) -#define zNoState (option_usage_text.apz_str[ 68]) -#define zNone (option_usage_text.apz_str[ 69]) -#define zNotDef (option_usage_text.apz_str[ 70]) -#define zNotCmdOpt (option_usage_text.apz_str[ 71]) -#define zNotEnough (option_usage_text.apz_str[ 72]) -#define zNotFile (option_usage_text.apz_str[ 73]) -#define zNotNumber (option_usage_text.apz_str[ 74]) -#define zNrmOptFmt (option_usage_text.apz_str[ 75]) -#define zNumberOpt (option_usage_text.apz_str[ 76]) -#define zOneSpace (option_usage_text.apz_str[ 77]) -#define zOnlyOne (option_usage_text.apz_str[ 78]) -#define zOptsOnly (option_usage_text.apz_str[ 79]) -#define zPathFmt (option_usage_text.apz_str[ 80]) -#define zPlsSendBugs (option_usage_text.apz_str[ 81]) -#define zPreset (option_usage_text.apz_str[ 82]) -#define zPresetFile (option_usage_text.apz_str[ 83]) -#define zPresetIntro (option_usage_text.apz_str[ 84]) -#define zProg (option_usage_text.apz_str[ 85]) -#define zProhib (option_usage_text.apz_str[ 86]) -#define zReorder (option_usage_text.apz_str[ 87]) -#define zRange (option_usage_text.apz_str[ 88]) -#define zRangeAbove (option_usage_text.apz_str[ 89]) -#define zRangeLie (option_usage_text.apz_str[ 90]) -#define zRangeBadLie (option_usage_text.apz_str[ 91]) -#define zRangeOnly (option_usage_text.apz_str[ 92]) -#define zRangeOr (option_usage_text.apz_str[ 93]) -#define zRangeErr (option_usage_text.apz_str[ 94]) -#define zRangeExact (option_usage_text.apz_str[ 95]) -#define zRangeScaled (option_usage_text.apz_str[ 96]) -#define zRangeUpto (option_usage_text.apz_str[ 97]) -#define zResetNotConfig (option_usage_text.apz_str[ 98]) -#define zReqFmt (option_usage_text.apz_str[ 99]) -#define zReqOptFmt (option_usage_text.apz_str[100]) -#define zReqThese (option_usage_text.apz_str[101]) -#define zReq_NoShrtTtl (option_usage_text.apz_str[102]) -#define zReq_ShrtTtl (option_usage_text.apz_str[103]) -#define zSepChars (option_usage_text.apz_str[104]) -#define zSetMemberSettings (option_usage_text.apz_str[105]) -#define zShrtGnuOptFmt (option_usage_text.apz_str[106]) -#define zSixSpaces (option_usage_text.apz_str[107]) -#define zStdBoolArg (option_usage_text.apz_str[108]) -#define zStdBreak (option_usage_text.apz_str[109]) -#define zStdFileArg (option_usage_text.apz_str[110]) -#define zStdKeyArg (option_usage_text.apz_str[111]) -#define zStdKeyLArg (option_usage_text.apz_str[112]) -#define zStdTimeArg (option_usage_text.apz_str[113]) -#define zStdNestArg (option_usage_text.apz_str[114]) -#define zStdNoArg (option_usage_text.apz_str[115]) -#define zStdNumArg (option_usage_text.apz_str[116]) -#define zStdOptArg (option_usage_text.apz_str[117]) -#define zStdReqArg (option_usage_text.apz_str[118]) -#define zStdStrArg (option_usage_text.apz_str[119]) -#define zTabHyp (option_usage_text.apz_str[120]) -#define zTabHypAnd (option_usage_text.apz_str[121]) -#define zTabout (option_usage_text.apz_str[122]) -#define zThreeSpaces (option_usage_text.apz_str[123]) -#define zTwoSpaces (option_usage_text.apz_str[124]) -#define zUpTo (option_usage_text.apz_str[125]) -#define zValidKeys (option_usage_text.apz_str[126]) +#define zIllOptChr (option_usage_text.apz_str[ 49]) +#define zIllOptStr (option_usage_text.apz_str[ 50]) +#define zIllegal (option_usage_text.apz_str[ 51]) +#define zIntRange (option_usage_text.apz_str[ 52]) +#define zInvalOptDesc (option_usage_text.apz_str[ 53]) +#define zLowerBits (option_usage_text.apz_str[ 54]) +#define zMembers (option_usage_text.apz_str[ 55]) +#define zMisArg (option_usage_text.apz_str[ 56]) +#define zMultiEquiv (option_usage_text.apz_str[ 57]) +#define zMust (option_usage_text.apz_str[ 58]) +#define zNeedOne (option_usage_text.apz_str[ 59]) +#define zNoArg (option_usage_text.apz_str[ 60]) +#define zNoArgs (option_usage_text.apz_str[ 61]) +#define zNoCreat (option_usage_text.apz_str[ 62]) +#define zNoFlags (option_usage_text.apz_str[ 63]) +#define zNoKey (option_usage_text.apz_str[ 64]) +#define zNoLim (option_usage_text.apz_str[ 65]) +#define zNoPreset (option_usage_text.apz_str[ 66]) +#define zNoResetArg (option_usage_text.apz_str[ 67]) +#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 68]) +#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 69]) +#define zNoStat (option_usage_text.apz_str[ 70]) +#define zNoState (option_usage_text.apz_str[ 71]) +#define zNone (option_usage_text.apz_str[ 72]) +#define zNotDef (option_usage_text.apz_str[ 73]) +#define zNotCmdOpt (option_usage_text.apz_str[ 74]) +#define zNotEnough (option_usage_text.apz_str[ 75]) +#define zNotFile (option_usage_text.apz_str[ 76]) +#define zNotNumber (option_usage_text.apz_str[ 77]) +#define zNrmOptFmt (option_usage_text.apz_str[ 78]) +#define zNumberOpt (option_usage_text.apz_str[ 79]) +#define zOneSpace (option_usage_text.apz_str[ 80]) +#define zOnlyOne (option_usage_text.apz_str[ 81]) +#define zOptsOnly (option_usage_text.apz_str[ 82]) +#define zOutputFail (option_usage_text.apz_str[ 83]) +#define zPathFmt (option_usage_text.apz_str[ 84]) +#define zPlsSendBugs (option_usage_text.apz_str[ 85]) +#define zPreset (option_usage_text.apz_str[ 86]) +#define zPresetFile (option_usage_text.apz_str[ 87]) +#define zPresetIntro (option_usage_text.apz_str[ 88]) +#define zProhib (option_usage_text.apz_str[ 89]) +#define zReorder (option_usage_text.apz_str[ 90]) +#define zRange (option_usage_text.apz_str[ 91]) +#define zRangeAbove (option_usage_text.apz_str[ 92]) +#define zRangeLie (option_usage_text.apz_str[ 93]) +#define zRangeBadLie (option_usage_text.apz_str[ 94]) +#define zRangeOnly (option_usage_text.apz_str[ 95]) +#define zRangeOr (option_usage_text.apz_str[ 96]) +#define zRangeErr (option_usage_text.apz_str[ 97]) +#define zRangeExact (option_usage_text.apz_str[ 98]) +#define zRangeScaled (option_usage_text.apz_str[ 99]) +#define zRangeUpto (option_usage_text.apz_str[100]) +#define zResetNotConfig (option_usage_text.apz_str[101]) +#define zReqFmt (option_usage_text.apz_str[102]) +#define zReqOptFmt (option_usage_text.apz_str[103]) +#define zReqThese (option_usage_text.apz_str[104]) +#define zReq_NoShrtTtl (option_usage_text.apz_str[105]) +#define zReq_ShrtTtl (option_usage_text.apz_str[106]) +#define zSepChars (option_usage_text.apz_str[107]) +#define zSetMemberSettings (option_usage_text.apz_str[108]) +#define zShrtGnuOptFmt (option_usage_text.apz_str[109]) +#define zSixSpaces (option_usage_text.apz_str[110]) +#define zStdBoolArg (option_usage_text.apz_str[111]) +#define zStdBreak (option_usage_text.apz_str[112]) +#define zStdFileArg (option_usage_text.apz_str[113]) +#define zStdKeyArg (option_usage_text.apz_str[114]) +#define zStdKeyLArg (option_usage_text.apz_str[115]) +#define zStdTimeArg (option_usage_text.apz_str[116]) +#define zStdNestArg (option_usage_text.apz_str[117]) +#define zStdNoArg (option_usage_text.apz_str[118]) +#define zStdNumArg (option_usage_text.apz_str[119]) +#define zStdOptArg (option_usage_text.apz_str[120]) +#define zStdReqArg (option_usage_text.apz_str[121]) +#define zStdStrArg (option_usage_text.apz_str[122]) +#define zTabHyp (option_usage_text.apz_str[123]) +#define zTabHypAnd (option_usage_text.apz_str[124]) +#define zTabout (option_usage_text.apz_str[125]) +#define zThreeSpaces (option_usage_text.apz_str[126]) +#define zTwoSpaces (option_usage_text.apz_str[127]) +#define zUpTo (option_usage_text.apz_str[128]) +#define zValidKeys (option_usage_text.apz_str[129]) /* * First, set up the strings. Some of these are writable. These are all in @@ -205,14 +208,14 @@ extern usage_text_t option_usage_text; static char eng_zGnuTimeArg[] = "=Tim"; static char eng_zGnuNumArg[] = "=num"; static char eng_zGnuStrArg[] = "=str"; -static char const usage_txt[4159] = +static char const usage_txt[4230] = "AutoOpts function called without option descriptor\n\0" "\tThis exceeds the compiled library version: \0" "Automated Options Processing Error!\n" "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0" "\tThis is less than the minimum library version: \0" "Automated Options version %s\n" - "\tcopyright (c) 1999-2009 by Bruce Korb - all rights reserved\n\0" + "\tcopyright (c) 1999-2010 by Bruce Korb - all rights reserved\n\0" "AutoOpts lib error: defaulted to option with optional arg\n\0" "(AutoOpts bug): Aliasing option is out of range.\0" "all\0" @@ -229,6 +232,8 @@ static char const usage_txt[4159] = "\t'n' - version and copyright notice\n\0" "ERROR: %s option conflicts with the %s option\n\0" "%s(optionSaveState): error: cannot allocate %d bytes\n\0" + "auto-options\0" + "program\0" "\t\t\t\t- default option for unnamed options\n\0" "\t\t\t\t- disabled as --%s\n\0" "%s: The ``%s'' option has been disabled\0" @@ -243,6 +248,7 @@ static char const usage_txt[4159] = "or by a single hyphen and the flag character.\n\0" "%%-%ds %%s\n\0" "fs error %d (%s) on fork - cannot obtain %s usage\n\0" + "fs error %d (%s) on freopen\n\0" "File error %d (%s) opening %s for loading options\n\0" "fs error %d (%s) reading file %s\n\0" "fs error %d (%s) on %s %s for option %s\n\0" @@ -297,6 +303,7 @@ static char const usage_txt[4159] = " \0" "one %s%s option allowed\n\0" "All arguments are named options.\n\0" + "Write failure to output file\0" " - reading file %s\0" "\n" "please send bug reports to: %s\n\0" @@ -305,7 +312,6 @@ static char const usage_txt[4159] = "# %s#\n\0" "\n" "The following option preset mechanisms are supported:\n\0" - "program\0" "prohibits these options:\n\0" "Operands and options may be intermixed. They will be reordered.\n\0" "%s%ld to %ld\0" @@ -359,7 +365,7 @@ static char const usage_txt[4159] = * Aren't you glad you don't maintain this by hand? */ usage_text_t option_usage_text = { - 134, + 137, eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuFileArg, eng_zGnuKeyLArg, eng_zGnuTimeArg, eng_zGnuNumArg, eng_zGnuStrArg, { @@ -367,34 +373,35 @@ static char const usage_txt[4159] = usage_txt + 247, usage_txt + 338, usage_txt + 397, usage_txt + 447, usage_txt + 451, usage_txt + 478, usage_txt + 527, usage_txt + 555, usage_txt + 592, usage_txt + 617, usage_txt + 643, usage_txt + 683, - usage_txt + 820, usage_txt + 868, usage_txt + 922, usage_txt + 964, - usage_txt + 988, usage_txt +1028, usage_txt +1043, usage_txt +1073, - usage_txt +1099, usage_txt +1112, usage_txt +1126, usage_txt +1173, - usage_txt +1179, usage_txt +1282, usage_txt +1294, usage_txt +1345, - usage_txt +1396, usage_txt +1430, usage_txt +1471, usage_txt +1494, - usage_txt +1520, usage_txt +1551, usage_txt +1565, usage_txt +1580, - usage_txt +1611, usage_txt +1638, usage_txt +1744, usage_txt +1750, - usage_txt +1756, usage_txt +1763, usage_txt +1774, usage_txt +1800, - usage_txt +1826, usage_txt +1834, usage_txt +1870, usage_txt +1921, - usage_txt +1977, usage_txt +2011, usage_txt +2049, usage_txt +2114, - usage_txt +2157, usage_txt +2192, usage_txt +2233, usage_txt +2273, - usage_txt +2300, usage_txt +2367, usage_txt +2415, usage_txt +2448, - usage_txt +2473, usage_txt +2521, usage_txt +2556, usage_txt +2594, - usage_txt +2621, usage_txt +2670, usage_txt +2675, usage_txt +2693, - usage_txt +2728, usage_txt +2772, usage_txt +2826, usage_txt +2872, - usage_txt +2880, usage_txt +2928, usage_txt +2930, usage_txt +2955, - usage_txt +2989, usage_txt +3008, usage_txt +3042, usage_txt +3078, - usage_txt +3116, usage_txt +3172, usage_txt +3180, usage_txt +3206, - usage_txt +3272, usage_txt +3285, usage_txt +3316, usage_txt +3353, - usage_txt +3399, usage_txt +3415, usage_txt +3421, usage_txt +3473, - usage_txt +3487, usage_txt +3533, usage_txt +3561, usage_txt +3606, - usage_txt +3648, usage_txt +3662, usage_txt +3687, usage_txt +3727, - usage_txt +3770, usage_txt +3774, usage_txt +3993, usage_txt +3996, - usage_txt +4003, usage_txt +4007, usage_txt +4015, usage_txt +4019, - usage_txt +4023, usage_txt +4027, usage_txt +4031, usage_txt +4035, - usage_txt +4039, usage_txt +4043, usage_txt +4047, usage_txt +4051, - usage_txt +4055, usage_txt +4062, usage_txt +4074, usage_txt +4082, - usage_txt +4086, usage_txt +4089, usage_txt +4122 + usage_txt + 820, usage_txt + 868, usage_txt + 922, usage_txt + 935, + usage_txt + 943, usage_txt + 985, usage_txt +1009, usage_txt +1049, + usage_txt +1064, usage_txt +1094, usage_txt +1120, usage_txt +1133, + usage_txt +1147, usage_txt +1194, usage_txt +1200, usage_txt +1303, + usage_txt +1315, usage_txt +1366, usage_txt +1395, usage_txt +1446, + usage_txt +1480, usage_txt +1521, usage_txt +1544, usage_txt +1570, + usage_txt +1601, usage_txt +1615, usage_txt +1630, usage_txt +1661, + usage_txt +1688, usage_txt +1794, usage_txt +1800, usage_txt +1806, + usage_txt +1813, usage_txt +1824, usage_txt +1850, usage_txt +1876, + usage_txt +1884, usage_txt +1920, usage_txt +1971, usage_txt +2027, + usage_txt +2061, usage_txt +2099, usage_txt +2164, usage_txt +2207, + usage_txt +2242, usage_txt +2283, usage_txt +2323, usage_txt +2350, + usage_txt +2417, usage_txt +2465, usage_txt +2498, usage_txt +2523, + usage_txt +2571, usage_txt +2606, usage_txt +2644, usage_txt +2671, + usage_txt +2720, usage_txt +2725, usage_txt +2743, usage_txt +2778, + usage_txt +2822, usage_txt +2876, usage_txt +2922, usage_txt +2930, + usage_txt +2978, usage_txt +2980, usage_txt +3005, usage_txt +3039, + usage_txt +3068, usage_txt +3087, usage_txt +3121, usage_txt +3157, + usage_txt +3195, usage_txt +3251, usage_txt +3277, usage_txt +3343, + usage_txt +3356, usage_txt +3387, usage_txt +3424, usage_txt +3470, + usage_txt +3486, usage_txt +3492, usage_txt +3544, usage_txt +3558, + usage_txt +3604, usage_txt +3632, usage_txt +3677, usage_txt +3719, + usage_txt +3733, usage_txt +3758, usage_txt +3798, usage_txt +3841, + usage_txt +3845, usage_txt +4064, usage_txt +4067, usage_txt +4074, + usage_txt +4078, usage_txt +4086, usage_txt +4090, usage_txt +4094, + usage_txt +4098, usage_txt +4102, usage_txt +4106, usage_txt +4110, + usage_txt +4114, usage_txt +4118, usage_txt +4122, usage_txt +4126, + usage_txt +4133, usage_txt +4145, usage_txt +4153, usage_txt +4157, + usage_txt +4160, usage_txt +4193 } }; diff --git a/sntp/libopts/boolean.c b/sntp/libopts/boolean.c index 71e341a09..335949f33 100644 --- a/sntp/libopts/boolean.c +++ b/sntp/libopts/boolean.c @@ -1,7 +1,8 @@ -/* - * $Id: 329b43154b88d78564d8f960a00a83ec7d8baee0 $ - * Time-stamp: "2008-08-03 13:06:02 bkorb" +/** + * \file boolean.c + * + * Time-stamp: "2010-07-10 11:02:10 bkorb" * * Automated Options Paged Usage module. * @@ -10,7 +11,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control diff --git a/sntp/libopts/compat/compat.h b/sntp/libopts/compat/compat.h index e2dd13497..7945129de 100644 --- a/sntp/libopts/compat/compat.h +++ b/sntp/libopts/compat/compat.h @@ -1,15 +1,14 @@ /* -*- Mode: C -*- */ -/* compat.h --- fake the preprocessor into handlng portability +/** + * \file compat.h --- fake the preprocessor into handlng portability * - * Time-stamp: "2009-10-18 11:14:14 bkorb" - * - * $Id: 27c1eb45f171295ab6176280aeca742cfdbe9fed $ + * Time-stamp: "2010-07-16 15:11:57 bkorb" * * compat.h is free software. * This file is part of AutoGen. * - * AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoGen Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoGen is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/sntp/libopts/compat/pathfind.c b/sntp/libopts/compat/pathfind.c index 9e813178a..2d5b27d91 100644 --- a/sntp/libopts/compat/pathfind.c +++ b/sntp/libopts/compat/pathfind.c @@ -4,10 +4,7 @@ /* * Author: Gary V Vaughan - * Time-stamp: "2006-09-23 19:46:16 bkorb" - * by: bkorb - * - * $Id: 8ce7ddfe2378f0b75c91c0ab348a6ad81634fb01 $ + * Time-stamp: "2010-07-17 09:50:32 bkorb" */ /* Code: */ diff --git a/sntp/libopts/compat/windows-config.h b/sntp/libopts/compat/windows-config.h index 967d277db..356eb1101 100644 --- a/sntp/libopts/compat/windows-config.h +++ b/sntp/libopts/compat/windows-config.h @@ -1,11 +1,10 @@ /* - * Time-stamp: "2009-07-22 18:53:59 bkorb" - * by: bkorb + * Time-stamp: "2010-02-24 08:39:04 bkorb" * * This file is part of AutoGen. * - * AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoGen Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoGen is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the diff --git a/sntp/libopts/configfile.c b/sntp/libopts/configfile.c index 07e1a6775..1fbe201a6 100644 --- a/sntp/libopts/configfile.c +++ b/sntp/libopts/configfile.c @@ -1,12 +1,13 @@ -/* - * $Id: f1650b45a91ec95af830ff76041cc4f0048e60f0 $ - * Time-stamp: "2009-01-18 10:21:58 bkorb" +/** + * \file configfile.c + * + * Time-stamp: "2010-11-07 14:43:09 bkorb" * * configuration/rc/ini file handling. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -25,60 +26,45 @@ * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ +static void +set_usage_flags(tOptions * opts, char const * flg_txt); + /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -filePreset( - tOptions* pOpts, - char const* pzFileName, - int direction ); +file_preset(tOptions * opts, char const * fname, int dir); static char* -handleComment( char* pzText ); +handle_comment(char* pzText); -static char* -handleConfig( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ); +static char * +handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); -static char* -handleDirective( - tOptions* pOpts, - char* pzText ); +static char * +handle_directive(tOptions * pOpts, char * pzText); -static char* -handleProgramSection( - tOptions* pOpts, - char* pzText ); +static char * +aoflags_directive(tOptions * pOpts, char * pzText); -static char* -handleStructure( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ); +static char * +program_directive(tOptions * pOpts, char * pzText); -static char* -parseKeyWordType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ); +static char * +handle_section(tOptions * pOpts, char * pzText); -static char* -parseSetMemType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ); +static char * +handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); static char* -parseValueType( - char* pzText, - tOptionValue* pType ); +parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType); static char* -skipUnknown( char* pzText ); +parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType); + +static char * +parse_value(char * pzText, tOptionValue * pType); + +static char * +skip_unkn(char* pzText); /* = = = END-STATIC-FORWARD = = = */ @@ -113,14 +99,14 @@ skipUnknown( char* pzText ); * @end itemize =*/ const tOptionValue* -configFileLoad( char const* pzFile ) +configFileLoad(char const* pzFile) { tmap_info_t cfgfile; tOptionValue* pRes = NULL; tOptionLoadMode save_mode = option_load_mode; char* pzText = - text_mmap( pzFile, PROT_READ, MAP_PRIVATE, &cfgfile ); + text_mmap(pzFile, PROT_READ, MAP_PRIVATE, &cfgfile); if (TEXT_MMAP_FAILED_ADDR(pzText)) return NULL; /* errno is set */ @@ -130,10 +116,10 @@ configFileLoad( char const* pzFile ) if (pRes == NULL) { int err = errno; - text_munmap( &cfgfile ); + text_munmap(&cfgfile); errno = err; } else - text_munmap( &cfgfile ); + text_munmap(&cfgfile); option_load_mode = save_mode; return pRes; @@ -165,8 +151,8 @@ configFileLoad( char const* pzFile ) * @end itemize =*/ const tOptionValue* -optionFindValue( const tOptDesc* pOptDesc, - char const* pzName, char const* pzVal ) +optionFindValue(const tOptDesc* pOptDesc, char const* pzName, + char const* pzVal) { const tOptionValue* pRes = NULL; @@ -196,7 +182,7 @@ optionFindValue( const tOptDesc* pOptDesc, while (--ct >= 0) { const tOptionValue* pOV = *(ppOV++); - const tOptionValue* pRV = optionGetValue( pOV, pzName ); + const tOptionValue* pRV = optionGetValue(pOV, pzName); if (pRV == NULL) continue; @@ -240,9 +226,9 @@ optionFindValue( const tOptDesc* pOptDesc, * @code{ENOENT} - no entry matched the given name. * @end itemize =*/ -const tOptionValue* -optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal, - char const* pzName, char const* pzVal ) +tOptionValue const * +optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal, + char const * pzName, char const * pzVal) { int foundOldVal = 0; tOptionValue* pRes = NULL; @@ -309,7 +295,7 @@ optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal, * @end itemize =*/ const tOptionValue* -optionGetValue( const tOptionValue* pOld, char const* pzValName ) +optionGetValue(const tOptionValue* pOld, char const* pzValName) { tArgList* pAL; tOptionValue* pRes = NULL; @@ -330,7 +316,7 @@ optionGetValue( const tOptionValue* pOld, char const* pzValName ) else do { tOptionValue* pOV = *(papOV++); - if (strcmp( pOV->pzName, pzValName ) == 0) { + if (strcmp(pOV->pzName, pzValName) == 0) { pRes = pOV; break; } @@ -405,27 +391,24 @@ optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV ) } -/* filePreset - * +/** * Load a file containing presetting information (a configuration file). */ static void -filePreset( - tOptions* pOpts, - char const* pzFileName, - int direction ) +file_preset(tOptions * opts, char const * fname, int dir) { tmap_info_t cfgfile; tOptState optst = OPTSTATE_INITIALIZER(PRESET); - char* pzFileText = - text_mmap( pzFileName, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile ); + tAoUL st_flags = optst.flags; + char * ftext = + text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile); - if (TEXT_MMAP_FAILED_ADDR(pzFileText)) + if (TEXT_MMAP_FAILED_ADDR(ftext)) return; - if (direction == DIRECTION_CALLED) { - optst.flags = OPTST_DEFINED; - direction = DIRECTION_PROCESS; + if (dir == DIRECTION_CALLED) { + st_flags = OPTST_DEFINED; + dir = DIRECTION_PROCESS; } /* @@ -434,33 +417,33 @@ filePreset( * If this is called via "optionFileLoad", then the bit is not set * and we consider stuff set herein to be "set" by the client program. */ - if ((pOpts->fOptSet & OPTPROC_PRESETTING) == 0) - optst.flags = OPTST_SET; + if ((opts->fOptSet & OPTPROC_PRESETTING) == 0) + st_flags = OPTST_SET; do { - while (IS_WHITESPACE_CHAR(*pzFileText)) pzFileText++; + optst.flags = st_flags; + while (IS_WHITESPACE_CHAR(*ftext)) ftext++; - if (IS_VAR_FIRST_CHAR(*pzFileText)) { - pzFileText = handleConfig(pOpts, &optst, pzFileText, direction); + if (IS_VAR_FIRST_CHAR(*ftext)) { + ftext = handle_cfg(opts, &optst, ftext, dir); - } else switch (*pzFileText) { + } else switch (*ftext) { case '<': - if (IS_VAR_FIRST_CHAR(pzFileText[1])) - pzFileText = - handleStructure(pOpts, &optst, pzFileText, direction); + if (IS_VAR_FIRST_CHAR(ftext[1])) + ftext = handle_struct(opts, &optst, ftext, dir); - else switch (pzFileText[1]) { + else switch (ftext[1]) { case '?': - pzFileText = handleDirective( pOpts, pzFileText ); + ftext = handle_directive(opts, ftext); break; case '!': - pzFileText = handleComment( pzFileText ); + ftext = handle_comment(ftext); break; case '/': - pzFileText = strchr( pzFileText+2, '>' ); - if (pzFileText++ != NULL) + ftext = strchr(ftext + 2, '>'); + if (ftext++ != NULL) break; default: @@ -469,55 +452,49 @@ filePreset( break; case '[': - pzFileText = handleProgramSection( pOpts, pzFileText ); + ftext = handle_section(opts, ftext); break; case '#': - pzFileText = strchr( pzFileText+1, '\n' ); + ftext = strchr(ftext + 1, '\n'); break; default: goto all_done; /* invalid format */ } - } while (pzFileText != NULL); + } while (ftext != NULL); - all_done: - text_munmap( &cfgfile ); +all_done: + text_munmap(&cfgfile); } -/* handleComment - * +/** * "pzText" points to a "". */ static char* -handleComment( char* pzText ) +handle_comment(char* pzText) { - char* pz = strstr( pzText, "-->" ); + char* pz = strstr(pzText, "-->"); if (pz != NULL) pz += 3; return pz; } -/* handleConfig - * +/** * "pzText" points to the start of some value name. * The end of the entry is the end of the line that is not preceded by * a backslash escape character. The string value is always processed * in "cooked" mode. */ -static char* -handleConfig( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ) +static char * +handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) { char* pzName = pzText++; - char* pzEnd = strchr( pzText, '\n' ); + char* pzEnd = strchr(pzText, '\n'); if (pzEnd == NULL) return pzText + strlen(pzText); @@ -527,7 +504,7 @@ handleConfig( if (pzText > pzEnd) { name_only: *pzEnd++ = NUL; - loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED ); + loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } @@ -583,100 +560,161 @@ handleConfig( * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED ); + loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } -/* handleDirective - * +/** * "pzText" points to a "' ); - if (pzText != NULL) - pzText++; - return pzText; + for (ix = 0; ix < dir_ct; ix++) { + size_t len = strlen(dir_names[ix]); + if ( (strncmp(pzText + 2, dir_names[ix], len) == 0) + && (! IS_VALUE_NAME_CHAR(pzText[len+2])) ) + return dir_disp[ix](pOpts, pzText + len + 2); + } + + /* + * We don't know what this is. Skip it. + */ + pzText = strchr(pzText+2, '>'); + if (pzText != NULL) + pzText++; + return pzText; +} + +/** + * handle AutoOpts mode flags + */ +static char * +aoflags_directive(tOptions * pOpts, char * pzText) +{ + char * pz = pzText; + + while (IS_WHITESPACE_CHAR(*++pz)) ; + pzText = strchr(pz, '>'); + if (pzText != NULL) { + + size_t len = pzText - pz; + char * ftxt = AGALOC(len + 1, "aoflags"); + + memcpy(ftxt, pz, len); + ftxt[len] = NUL; + set_usage_flags(pOpts, ftxt); + AGFREE(ftxt); + + pzText++; } - name_len = strlen( pOpts->pzProgName ); - strcpy( ztitle+2, zProg ); - title_len += 2; + return pzText; +} + +/** + * handle program segmentation of config file. + */ +static char * +program_directive(tOptions * pOpts, char * pzText) +{ + char * ttl; + size_t ttl_len = asprintf(&ttl, "pzProgName); + + (void) ttl_len; do { - pzText += title_len; + while (IS_WHITESPACE_CHAR(*++pzText)) ; - if (IS_WHITESPACE_CHAR(*pzText)) { - while (IS_WHITESPACE_CHAR(*++pzText)) ; - if ( (strneqvcmp( pzText, pOpts->pzProgName, (int)name_len) == 0) - && (pzText[name_len] == '>')) { - pzText += name_len + 1; - break; - } + if ( (strneqvcmp(pzText, pOpts->pzProgName, (int)name_len) == 0) + && (IS_END_XML_TOKEN_CHAR(pzText[name_len])) ) { + pzText += name_len; + break; } - pzText = strstr( pzText, ztitle ); + pzText = strstr(pzText, ttl); } while (pzText != NULL); + free(ttl); + if (pzText != NULL) + for (;;) { + if (*pzText == NUL) { + pzText = NULL; + break; + } + if (*(pzText++) == '>') + break; + } + return pzText; } -/* handleProgramSection - * +/** * "pzText" points to a '[' character. * The "traditional" [PROG_NAME] segmentation of the config file. * Do not ever mix with the "" variation. */ -static char* -handleProgramSection( - tOptions* pOpts, - char* pzText ) +static char * +handle_section(tOptions * pOpts, char * pzText) { - size_t len = strlen( pOpts->pzPROGNAME ); - if ( (strncmp( pzText+1, pOpts->pzPROGNAME, len ) == 0) + size_t len = strlen(pOpts->pzPROGNAME); + if ( (strncmp(pzText+1, pOpts->pzPROGNAME, len) == 0) && (pzText[len+1] == ']')) - return strchr( pzText + len + 2, '\n' ); + return strchr(pzText + len + 2, '\n'); if (len > 16) return NULL; { char z[24]; - sprintf( z, "[%s]", pOpts->pzPROGNAME ); - pzText = strstr( pzText, z ); + sprintf(z, "[%s]", pOpts->pzPROGNAME); + pzText = strstr(pzText, z); } if (pzText != NULL) - pzText = strchr( pzText, '\n' ); + pzText = strchr(pzText, '\n'); return pzText; } -/* handleStructure - * +/** * "pzText" points to a '<' character, followed by an alpha. * The end of the entry is either the "/>" following the name, or else a * "" string. */ -static char* -handleStructure( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ) +static char * +handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) { tOptionLoadMode mode = option_load_mode; tOptionValue valu; @@ -692,7 +730,7 @@ handleStructure( switch (*pzText) { case ' ': case '\t': - pzText = parseAttributes( pOpts, pzText, &mode, &valu ); + pzText = parseAttributes(pOpts, pzText, &mode, &valu); if (*pzText == '>') break; if (*pzText != '/') @@ -704,14 +742,14 @@ handleStructure( return NULL; *pzText = NUL; pzText += 2; - loadOptionLine( pOpts, pOS, pzName, direction, mode ); + loadOptionLine(pOpts, pOS, pzName, dir, mode); return pzText; case '>': break; default: - pzText = strchr( pzText, '>'); + pzText = strchr(pzText, '>'); if (pzText != NULL) pzText++; return pzText; @@ -733,9 +771,9 @@ handleStructure( if (len > sizeof(z)) pz = AGALOC(len, "scan name"); - sprintf( pz, "", pzName ); + sprintf(pz, "", pzName); *pzText = ' '; - pzText = strstr( pzText, pz ); + pzText = strstr(pzText, pz); if (pz != z) AGFREE(pz); if (pzText == NULL) @@ -786,20 +824,19 @@ handleStructure( * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine( pOpts, pOS, pzName, direction, mode ); + loadOptionLine(pOpts, pOS, pzName, dir, mode); return pzText; } -/* internalFileLoad - * +/** * Load a configuration file. This may be invoked either from * scanning the "homerc" list, or from a specific file request. * (see "optionFileLoad()", the implementation for --load-opts) */ LOCAL void -internalFileLoad( tOptions* pOpts ) +internalFileLoad(tOptions* pOpts) { uint32_t svfl; int idx; @@ -850,8 +887,8 @@ internalFileLoad( tOptions* pOpts ) idx += inc; - if (! optionMakePath( zFileName, (int)sizeof(zFileName), - pzPath, pOpts->pzProgPath )) + if (! optionMakePath(zFileName, (int)sizeof(zFileName), + pzPath, pOpts->pzProgPath)) continue; /* @@ -859,23 +896,23 @@ internalFileLoad( tOptions* pOpts ) * THEN append the Resource Configuration file name * ELSE we must have the complete file name */ - if (stat( zFileName, &StatBuf ) != 0) + if (stat(zFileName, &StatBuf) != 0) continue; /* bogus name - skip the home list entry */ - if (S_ISDIR( StatBuf.st_mode )) { - size_t len = strlen( zFileName ); + if (S_ISDIR(StatBuf.st_mode)) { + size_t len = strlen(zFileName); char* pz; - if (len + 1 + strlen( pOpts->pzRcName ) >= sizeof( zFileName )) + if (len + 1 + strlen(pOpts->pzRcName) >= sizeof(zFileName)) continue; pz = zFileName + len; if (pz[-1] != DIRCH) *(pz++) = DIRCH; - strcpy( pz, pOpts->pzRcName ); + strcpy(pz, pOpts->pzRcName); } - filePreset( pOpts, zFileName, inc ); + file_preset(pOpts, zFileName, inc); /* * IF we are now to skip config files AND we are presetting, @@ -928,13 +965,13 @@ internalFileLoad( tOptions* pOpts ) * always be returned. =*/ int -optionFileLoad( tOptions* pOpts, char const* pzProgram ) +optionFileLoad(tOptions* pOpts, char const* pzProgram) { - if (! SUCCESSFUL( validateOptionsStruct( pOpts, pzProgram ))) + if (! SUCCESSFUL(validateOptionsStruct(pOpts, pzProgram))) return -1; pOpts->pzProgName = pzProgram; - internalFileLoad( pOpts ); + internalFileLoad(pOpts); return 0; } @@ -951,7 +988,7 @@ optionFileLoad( tOptions* pOpts, char const* pzProgram ) * pOptDesc->optArg.argString. =*/ void -optionLoadOpt( tOptions* pOpts, tOptDesc* pOptDesc ) +optionLoadOpt(tOptions* pOpts, tOptDesc* pOptDesc) { struct stat sb; @@ -965,31 +1002,30 @@ optionLoadOpt( tOptions* pOpts, tOptDesc* pOptDesc ) || ((pOptDesc->fOptState & OPTST_RESET) != 0)) return; - if (stat( pOptDesc->optArg.argString, &sb ) != 0) { + if (stat(pOptDesc->optArg.argString, &sb) != 0) { if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) return; - fprintf( stderr, zFSErrOptLoad, errno, strerror( errno ), - pOptDesc->optArg.argString ); + fprintf(stderr, zFSErrOptLoad, errno, strerror(errno), + pOptDesc->optArg.argString); exit(EX_NOINPUT); /* NOT REACHED */ } - if (! S_ISREG( sb.st_mode )) { + if (! S_ISREG(sb.st_mode)) { if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) return; - fprintf( stderr, zNotFile, pOptDesc->optArg.argString ); + fprintf(stderr, zNotFile, pOptDesc->optArg.argString); exit(EX_NOINPUT); /* NOT REACHED */ } - filePreset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED); + file_preset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED); } -/* parseAttributes - * +/** * Parse the various attributes of an XML-styled config file entry */ LOCAL char* @@ -1017,15 +1053,15 @@ parseAttributes( switch (find_xat_attribute_id(pzText, len)) { case XAT_KWD_TYPE: - pzText = parseValueType( pzText+len, pType ); + pzText = parse_value(pzText+len, pType); break; case XAT_KWD_WORDS: - pzText = parseKeyWordType( pOpts, pzText+len, pType ); + pzText = parse_keyword(pOpts, pzText+len, pType); break; case XAT_KWD_MEMBERS: - pzText = parseSetMemType( pOpts, pzText+len, pType ); + pzText = parse_set_mem(pOpts, pzText+len, pType); break; case XAT_KWD_COOKED: @@ -1056,7 +1092,7 @@ parseAttributes( case XAT_KWD_INVALID: invalid_kwd: pType->valType = OPARG_TYPE_NONE; - return skipUnknown( pzText ); + return skip_unkn(pzText); } } while (pzText != NULL); @@ -1064,45 +1100,34 @@ parseAttributes( } -/* parseKeyWordType - * +/** * "pzText" points to the character after "words=". * What should follow is a name of a keyword (enumeration) list. */ static char* -parseKeyWordType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ) +parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType) { - return skipUnknown( pzText ); + return skip_unkn(pzText); } -/* parseSetMemType - * +/** * "pzText" points to the character after "members=" * What should follow is a name of a "set membership". * A collection of bit flags. */ static char* -parseSetMemType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ) +parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType) { - return skipUnknown( pzText ); + return skip_unkn(pzText); } -/* parseValueType - * +/** * "pzText" points to the character after "type=" */ -static char* -parseValueType( - char* pzText, - tOptionValue* pType ) +static char * +parse_value(char * pzText, tOptionValue * pType) { size_t len = 0; @@ -1115,7 +1140,7 @@ parseValueType( if ((len == 0) || (! IS_END_XML_TOKEN_CHAR(*pzText))) { woops: pType->valType = OPARG_TYPE_NONE; - return skipUnknown( pzText ); + return skip_unkn(pzText); } switch (find_value_type_id(pzText - len, len)) { @@ -1153,12 +1178,11 @@ parseValueType( } -/* skipUnknown - * +/** * Skip over some unknown attribute */ -static char* -skipUnknown( char* pzText ) +static char * +skip_unkn(char* pzText) { for (;; pzText++) { if (IS_END_XML_TOKEN_CHAR(*pzText)) return pzText; @@ -1167,8 +1191,7 @@ skipUnknown( char* pzText ) } -/* validateOptionsStruct - * +/** * Make sure the option descriptor is there and that we understand it. * This should be called from any user entry point where one needs to * worry about validity. (Some entry points are free to assume that @@ -1176,11 +1199,11 @@ skipUnknown( char* pzText ) * already been called.) */ LOCAL tSuccess -validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) +validateOptionsStruct(tOptions* pOpts, char const* pzProgram) { if (pOpts == NULL) { - fputs( zAO_Bad, stderr ); - exit( EX_CONFIG ); + fputs(zAO_Bad, stderr); + exit(EX_CONFIG); } /* @@ -1212,9 +1235,9 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) fprintf(stderr, zAO_Err, pzProgram, NUM_TO_VER(pOpts->structVersion)); if (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) - fputs( zAO_Big, stderr ); + fputs(zAO_Big, stderr); else - fputs( zAO_Sml, stderr ); + fputs(zAO_Sml, stderr); return FAILURE; } @@ -1224,7 +1247,7 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) * and the set of equivalent characters. */ if (pOpts->pzProgName == NULL) { - char const* pz = strrchr( pzProgram, DIRCH ); + char const* pz = strrchr(pzProgram, DIRCH); if (pz == NULL) pOpts->pzProgName = pzProgram; @@ -1235,7 +1258,7 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) /* * when comparing long names, these are equivalent */ - strequate( zSepChars ); + strequate(zSepChars); } return SUCCESS; diff --git a/sntp/libopts/cook.c b/sntp/libopts/cook.c index b2b1c5284..1c95de6da 100644 --- a/sntp/libopts/cook.c +++ b/sntp/libopts/cook.c @@ -1,13 +1,14 @@ -/* - * $Id: 3da9a5fc88c904673b3b95d0c9667b2bcbccfc80 $ - * Time-stamp: "2007-11-16 22:49:11 bkorb" +/** + * \file cook.c + * + * Time-stamp: "2010-07-10 11:01:32 bkorb" * * This file contains the routines that deal with processing quoted strings * into an internal format. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -27,7 +28,6 @@ */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ /* = = = END-STATIC-FORWARD = = = */ /*=export_func ao_string_cook_escape_char diff --git a/sntp/libopts/enumeration.c b/sntp/libopts/enumeration.c index 700b22d67..231f0e990 100644 --- a/sntp/libopts/enumeration.c +++ b/sntp/libopts/enumeration.c @@ -1,7 +1,8 @@ -/* - * $Id: 27595043d23170eb4bb8b9831fc54016944e00e8 $ - * Time-stamp: "2008-07-27 12:28:01 bkorb" +/** + * \file enumeration.c + * + * Time-stamp: "2010-08-22 15:36:14 bkorb" * * Automated Options Paged Usage module. * @@ -10,7 +11,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -32,29 +33,30 @@ tSCC* pz_enum_err_fmt; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -enumError( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - int name_ct ); +enum_err(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, int name_ct); static uintptr_t -findName( - tCC* pzName, - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ); +find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct); + +static void +set_memb_usage(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); + +static void +set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); + +static void +set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); /* = = = END-STATIC-FORWARD = = = */ static void -enumError( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - int name_ct ) +enum_err(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, int name_ct) { size_t max_len = 0; size_t ttl_len = 0; @@ -86,10 +88,10 @@ enumError( * of all the names. */ { - tCC * const * paz = paz_names; + char const * const * paz = paz_names; do { - size_t len = strlen( *(paz++) ) + 1; + size_t len = strlen(*(paz++)) + 1; if (len > max_len) max_len = len; ttl_len += len; @@ -103,7 +105,7 @@ enumError( */ if (max_len > 35) { do { - fprintf( option_usage_fp, " %s\n", *(paz_names++) ); + fprintf(option_usage_fp, " %s\n", *(paz_names++)); } while (--ct_down > 0); } @@ -111,12 +113,12 @@ enumError( * ELSE IF they all fit on one line, then do so. */ else if (ttl_len < 76) { - fputc( ' ', option_usage_fp ); + fputc(' ', option_usage_fp); do { - fputc( ' ', option_usage_fp ); - fputs( *(paz_names++), option_usage_fp ); + fputc(' ', option_usage_fp); + fputs(*(paz_names++), option_usage_fp); } while (--ct_down > 0); - fputc( '\n', option_usage_fp ); + fputc('\n', option_usage_fp); } /* @@ -126,9 +128,9 @@ enumError( int ent_no = 0; char zFmt[16]; /* format for all-but-last entries on a line */ - sprintf( zFmt, "%%-%ds", (int)max_len ); + sprintf(zFmt, "%%-%ds", (int)max_len); max_len = 78 / max_len; /* max_len is now max entries on a line */ - fputs( " ", option_usage_fp ); + fputs(" ", option_usage_fp); /* * Loop through all but the last entry @@ -139,7 +141,7 @@ enumError( /* * Last entry on a line. Start next line, too. */ - fprintf( option_usage_fp, "%s\n ", *(paz_names++) ); + fprintf(option_usage_fp, "%s\n ", *(paz_names++)); ent_no = 0; } @@ -152,11 +154,10 @@ enumError( if (pOpts > OPTPROC_EMIT_LIMIT) { fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden); - (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE ); + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); /* NOTREACHED */ } - if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) { fprintf(option_usage_fp, zLowerBits, name_ct); fputs(zSetMemberSettings, option_usage_fp); @@ -167,27 +168,23 @@ enumError( static uintptr_t -findName( - tCC* pzName, - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ) +find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct) { /* * Return the matching index as a pointer sized integer. * The result gets stashed in a char* pointer. */ - uintptr_t res = name_ct; - size_t len = strlen( (char*)pzName ); - uintptr_t idx; + uintptr_t res = name_ct; + size_t len = strlen((char*)pzName); + uintptr_t idx; if (IS_DEC_DIGIT_CHAR(*pzName)) { char * pz = (char *)(void *)pzName; unsigned long val = strtoul(pz, &pz, 0); if ((*pz == NUL) && (val < name_ct)) return (uintptr_t)val; - enumError(pOpts, pOD, paz_names, (int)name_ct); + enum_err(pOpts, pOD, paz_names, (int)name_ct); return name_ct; } @@ -196,7 +193,7 @@ findName( * Multiple partial matches means we have an ambiguous match. */ for (idx = 0; idx < name_ct; idx++) { - if (strncmp( (char*)paz_names[idx], (char*)pzName, len) == 0) { + if (strncmp((char*)paz_names[idx], (char*)pzName, len) == 0) { if (paz_names[idx][len] == NUL) return idx; /* full match */ @@ -209,7 +206,7 @@ findName( pz_enum_err_fmt = (res == name_ct) ? zNoKey : zAmbigKey; option_usage_fp = stderr; - enumError(pOpts, pOD, paz_names, (int)name_ct); + enum_err(pOpts, pOD, paz_names, (int)name_ct); return name_ct; } @@ -221,15 +218,13 @@ findName( * arg: tOptDesc*, pOD, enumeration option description * arg: unsigned int, enum_val, the enumeration value to map * - * ret_type: char const* + * ret_type: char const * * ret_desc: the enumeration name from const memory * * doc: This converts an enumeration value into the matching string. =*/ -char const* -optionKeywordName( - tOptDesc* pOD, - unsigned int enum_val ) +char const * +optionKeywordName(tOptDesc * pOD, unsigned int enum_val) { tOptDesc od; @@ -258,11 +253,8 @@ optionKeywordName( * if there is only one partial match. =*/ uintptr_t -optionEnumerationVal( - tOptions* pOpts, - tOptDesc* pOD, - tCC * const * paz_names, - unsigned int name_ct ) +optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct) { uintptr_t res = 0UL; @@ -275,7 +267,7 @@ optionEnumerationVal( /* * print the list of enumeration names. */ - enumError(pOpts, pOD, paz_names, (int)name_ct); + enum_err(pOpts, pOD, paz_names, (int)name_ct); break; case (uintptr_t)OPTPROC_EMIT_SHELL: @@ -285,9 +277,9 @@ optionEnumerationVal( * print the name string. */ if (ix >= name_ct) - printf( "INVALID-%d", ix ); + printf("INVALID-%d", ix); else - fputs( paz_names[ ix ], stdout ); + fputs(paz_names[ ix ], stdout); break; } @@ -307,7 +299,7 @@ optionEnumerationVal( } default: - res = findName(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct); + res = find_name(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct); if (pOD->fOptState & OPTST_ALLOC_ARG) { AGFREE(pOD->optArg.argString); @@ -319,6 +311,84 @@ optionEnumerationVal( return res; } +static void +set_memb_usage(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + /* + * print the list of enumeration names. + */ + enum_err(OPTPROC_EMIT_USAGE, pOD, paz_names, (int)name_ct ); +} + +static void +set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + /* + * print the name string. + */ + int ix = 0; + uintptr_t bits = (uintptr_t)pOD->optCookie; + size_t len = 0; + + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + + while (bits != 0) { + if (bits & 1) { + if (len++ > 0) fputs(" | ", stdout); + fputs(paz_names[ix], stdout); + } + if (++ix >= name_ct) break; + bits >>= 1; + } +} + +static void +set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + char* pz; + uintptr_t bits = (uintptr_t)pOD->optCookie; + int ix = 0; + size_t len = 5; + + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + + /* + * Replace the enumeration value with the name string. + * First, determine the needed length, then allocate and fill in. + */ + while (bits != 0) { + if (bits & 1) + len += strlen(paz_names[ix]) + 8; + if (++ix >= name_ct) break; + bits >>= 1; + } + + pOD->optArg.argString = pz = AGALOC(len, "enum name"); + + /* + * Start by clearing all the bits. We want to turn off any defaults + * because we will be restoring to current state, not adding to + * the default set of bits. + */ + strcpy(pz, "none"); + pz += 4; + bits = (uintptr_t)pOD->optCookie; + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + ix = 0; + + while (bits != 0) { + if (bits & 1) { + strcpy(pz, " + "); + strcpy(pz+3, paz_names[ix]); + pz += strlen(paz_names[ix]) + 3; + } + if (++ix >= name_ct) break; + bits >>= 1; + } +} /*=export_func optionSetMembers * what: Convert between bit flag values and strings @@ -337,11 +407,8 @@ optionEnumerationVal( * if there is only one partial match. =*/ void -optionSetMembers( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ) +optionSetMembers(tOptions * pOpts, tOptDesc * pOD, + char const* const * paz_names, unsigned int name_ct) { /* * IF the program option descriptor pointer is invalid, @@ -349,78 +416,16 @@ optionSetMembers( */ switch ((uintptr_t)pOpts) { case (uintptr_t)OPTPROC_EMIT_USAGE: - /* - * print the list of enumeration names. - */ - enumError(OPTPROC_EMIT_USAGE, pOD, paz_names, (int)name_ct ); + set_memb_usage(pOpts, pOD, paz_names, name_ct); return; case (uintptr_t)OPTPROC_EMIT_SHELL: - { - /* - * print the name string. - */ - int ix = 0; - uintptr_t bits = (uintptr_t)pOD->optCookie; - size_t len = 0; - - bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; - - while (bits != 0) { - if (bits & 1) { - if (len++ > 0) fputs( " | ", stdout ); - fputs(paz_names[ix], stdout); - } - if (++ix >= name_ct) break; - bits >>= 1; - } + set_memb_shell(pOpts, pOD, paz_names, name_ct); return; - } case (uintptr_t)OPTPROC_RETURN_VALNAME: - { - char* pz; - uintptr_t bits = (uintptr_t)pOD->optCookie; - int ix = 0; - size_t len = 5; - - bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; - - /* - * Replace the enumeration value with the name string. - * First, determine the needed length, then allocate and fill in. - */ - while (bits != 0) { - if (bits & 1) - len += strlen( paz_names[ix]) + 8; - if (++ix >= name_ct) break; - bits >>= 1; - } - - pOD->optArg.argString = pz = AGALOC(len, "enum name"); - - /* - * Start by clearing all the bits. We want to turn off any defaults - * because we will be restoring to current state, not adding to - * the default set of bits. - */ - strcpy( pz, "none" ); - pz += 4; - bits = (uintptr_t)pOD->optCookie; - bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; - ix = 0; - - while (bits != 0) { - if (bits & 1) { - strcpy( pz, " + " ); - strcpy( pz+3, paz_names[ix]); - pz += strlen( paz_names[ix]) + 3; - } - if (++ix >= name_ct) break; - bits >>= 1; - } + set_memb_names(pOpts, pOD, paz_names, name_ct); return; - } default: break; @@ -430,7 +435,7 @@ optionSetMembers( return; { - tCC* pzArg = pOD->optArg.argString; + char const* pzArg = pOD->optArg.argString; uintptr_t res; if ((pzArg == NULL) || (*pzArg == NUL)) { pOD->optCookie = (void*)0; @@ -442,44 +447,44 @@ optionSetMembers( tSCC zSpn[] = " ,|+\t\r\f\n"; int iv, len; - pzArg += strspn( pzArg, zSpn ); + pzArg += strspn(pzArg, zSpn); iv = (*pzArg == '!'); if (iv) - pzArg += strspn( pzArg+1, zSpn ) + 1; + pzArg += strspn(pzArg+1, zSpn) + 1; - len = strcspn( pzArg, zSpn ); + len = strcspn(pzArg, zSpn); if (len == 0) break; - if ((len == 3) && (strncmp(pzArg, zAll, (size_t)3) == 0)) { + if ((len == 3) && (strncmp(pzArg, zAll, 3) == 0)) { if (iv) res = 0; else res = ~0UL; } - else if ((len == 4) && (strncmp(pzArg, zNone, (size_t)4) == 0)) { + else if ((len == 4) && (strncmp(pzArg, zNone, 4) == 0)) { if (! iv) res = 0; } else do { char* pz; - uintptr_t bit = strtoul( pzArg, &pz, 0 ); + uintptr_t bit = strtoul(pzArg, &pz, 0); if (pz != pzArg + len) { char z[ AO_NAME_SIZE ]; - tCC* p; + char const* p; int shift_ct; if (*pz != NUL) { if (len >= AO_NAME_LIMIT) break; - strncpy( z, pzArg, (size_t)len ); + strncpy(z, pzArg, (size_t)len); z[len] = NUL; p = z; } else { p = pzArg; } - shift_ct = findName(p, pOpts, pOD, paz_names, name_ct); + shift_ct = find_name(p, pOpts, pOD, paz_names, name_ct); if (shift_ct >= name_ct) { pOD->optCookie = (void*)0; return; @@ -495,7 +500,7 @@ optionSetMembers( break; pzArg += len + 1; } - if (name_ct < (8 * sizeof( uintptr_t ))) { + if (name_ct < (8 * sizeof(uintptr_t))) { res &= (1UL << name_ct) - 1UL; } diff --git a/sntp/libopts/environment.c b/sntp/libopts/environment.c index a688158dd..7771e0c0a 100644 --- a/sntp/libopts/environment.c +++ b/sntp/libopts/environment.c @@ -1,7 +1,8 @@ -/* - * $Id: 8700c8e91e8094c455392c691d9b6a7d62222240 $ - * Time-stamp: "2009-07-20 20:12:24 bkorb" +/** + * \file environment.c + * + * Time-stamp: "2010-07-17 10:39:52 bkorb" * * This file contains all of the routines that must be linked into * an executable to use the generated option processing. The optional @@ -10,7 +11,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -30,7 +31,6 @@ */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void checkEnvOpt(tOptState * os, char * env_name, tOptions* pOpts, teEnvPresetType type); @@ -43,9 +43,9 @@ checkEnvOpt(tOptState * os, char * env_name, * doImmediateOpts and/or doRegularOpts. */ LOCAL void -doPrognameEnv( tOptions* pOpts, teEnvPresetType type ) +doPrognameEnv(tOptions* pOpts, teEnvPresetType type) { - char const* pczOptStr = getenv( pOpts->pzPROGNAME ); + char const* pczOptStr = getenv(pOpts->pzPROGNAME); token_list_t* pTL; int sv_argc; tAoUI sv_flag; @@ -61,7 +61,7 @@ doPrognameEnv( tOptions* pOpts, teEnvPresetType type ) * Tokenize the string. If there's nothing of interest, we'll bail * here immediately. */ - pTL = ao_string_tokenize( pczOptStr ); + pTL = ao_string_tokenize(pczOptStr); if (pTL == NULL) return; @@ -87,23 +87,23 @@ doPrognameEnv( tOptions* pOpts, teEnvPresetType type ) switch (type) { case ENV_IMM: - (void)doImmediateOpts( pOpts ); + (void)doImmediateOpts(pOpts); break; case ENV_ALL: - (void)doImmediateOpts( pOpts ); + (void)doImmediateOpts(pOpts); pOpts->curOptIdx = 1; pOpts->pzCurOpt = NULL; /* FALLTHROUGH */ case ENV_NON_IMM: - (void)doRegularOpts( pOpts ); + (void)doRegularOpts(pOpts); } /* * Free up the temporary arg vector and restore the original program args. */ - free( pTL ); + free(pTL); pOpts->origArgVect = sv_argv; pOpts->origArgCt = sv_argc; pOpts->fOptSet = sv_flag; @@ -113,7 +113,7 @@ static void checkEnvOpt(tOptState * os, char * env_name, tOptions* pOpts, teEnvPresetType type) { - os->pzOptArg = getenv( env_name ); + os->pzOptArg = getenv(env_name); if (os->pzOptArg == NULL) return; @@ -121,7 +121,7 @@ checkEnvOpt(tOptState * os, char * env_name, os->optType = TOPT_UNDEFINED; if ( (os->pOD->pz_DisablePfx != NULL) - && (streqvcmp( os->pzOptArg, os->pOD->pz_DisablePfx ) == 0)) { + && (streqvcmp(os->pzOptArg, os->pOD->pz_DisablePfx) == 0)) { os->flags |= OPTST_DISABLED; os->pzOptArg = NULL; } @@ -157,17 +157,17 @@ checkEnvOpt(tOptState * os, char * env_name, if (OPTST_GET_ARGTYPE(os->pOD->fOptState) == OPARG_TYPE_NONE) { os->pzOptArg = NULL; } else if ( (os->pOD->fOptState & OPTST_ARG_OPTIONAL) - && (*os->pzOptArg == NUL)) { + && (*os->pzOptArg == NUL)) { os->pzOptArg = NULL; } else if (*os->pzOptArg == NUL) { os->pzOptArg = zNil; } else { - AGDUPSTR( os->pzOptArg, os->pzOptArg, "option argument" ); + AGDUPSTR(os->pzOptArg, os->pzOptArg, "option argument"); os->flags |= OPTST_ALLOC_ARG; } } - handleOption( pOpts, os ); + handleOption(pOpts, os); } /* @@ -175,7 +175,7 @@ checkEnvOpt(tOptState * os, char * env_name, * This routine should process in all, immediate or normal modes.... */ LOCAL void -doEnvPresets( tOptions* pOpts, teEnvPresetType type ) +doEnvPresets(tOptions* pOpts, teEnvPresetType type) { int ct; tOptState st; @@ -190,13 +190,13 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type ) if ((pOpts->fOptSet & OPTPROC_ENVIRON) == 0) return; - doPrognameEnv( pOpts, type ); + doPrognameEnv(pOpts, type); ct = pOpts->presetOptCt; st.pOD = pOpts->pOptDesc; pzFlagName = zEnvName - + snprintf( zEnvName, sizeof( zEnvName ), "%s_", pOpts->pzPROGNAME ); + + snprintf(zEnvName, sizeof(zEnvName), "%s_", pOpts->pzPROGNAME); spaceLeft = AO_NAME_SIZE - (pzFlagName - zEnvName) - 1; for (;ct-- > 0; st.pOD++) { @@ -211,13 +211,13 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type ) * IF there is no such environment variable, * THEN skip this entry, too. */ - if (strlen( st.pOD->pz_NAME ) >= spaceLeft) + if (strlen(st.pOD->pz_NAME) >= spaceLeft) continue; /* * Set up the option state */ - strcpy( pzFlagName, st.pOD->pz_NAME ); + strcpy(pzFlagName, st.pOD->pz_NAME); checkEnvOpt(&st, zEnvName, pOpts, type); } @@ -227,8 +227,11 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type ) if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT) && (pOpts->specOptIdx.save_opts != 0)) { st.pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1; - strcpy( pzFlagName, st.pOD->pz_NAME ); - checkEnvOpt(&st, zEnvName, pOpts, type); + + if (st.pOD->pz_NAME != NULL) { + strcpy(pzFlagName, st.pOD->pz_NAME); + checkEnvOpt(&st, zEnvName, pOpts, type); + } } } diff --git a/sntp/libopts/file.c b/sntp/libopts/file.c index fccb042cf..447253567 100644 --- a/sntp/libopts/file.c +++ b/sntp/libopts/file.c @@ -1,11 +1,12 @@ -/* - * $Id: 1410aaa5f08a562e0cd6c28ffae5a49dc7a3164f $ - * Time-stamp: "2009-07-23 17:23:46 bkorb" +/** + * \file file.c + * + * Time-stamp: "2010-07-10 11:00:59 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control diff --git a/sntp/libopts/genshell.c b/sntp/libopts/genshell.c index bbf0685d1..af9db94ac 100644 --- a/sntp/libopts/genshell.c +++ b/sntp/libopts/genshell.c @@ -2,21 +2,19 @@ * * DO NOT EDIT THIS FILE (genshell.c) * - * It has been AutoGen-ed November 8, 2009 at 08:41:09 AM by AutoGen 5.9.10pre13 + * It has been AutoGen-ed November 16, 2010 at 05:41:46 PM by AutoGen 5.11.2pre7 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts @AO_CURRENT@:@AO_REVISION@:@AO_AGE@ templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This source file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * genshellopt author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 33:3:8 templates. + * + * AutoOpts is a copyrighted work. This source file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the genshellopt author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * * This source file is copyrighted and licensed under the following terms: * @@ -78,21 +76,21 @@ extern tUsageProc genshelloptUsage; /* * Script option description: */ -tSCC zScriptText[] = +static char const zScriptText[] = "Output Script File"; -tSCC zScript_NAME[] = "SCRIPT"; -tSCC zScript_Name[] = "script"; +static char const zScript_NAME[] = "SCRIPT"; +static char const zScript_Name[] = "script"; #define SCRIPT_FLAGS (OPTST_DISABLED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) /* * Shell option description: */ -tSCC zShellText[] = +static char const zShellText[] = "Shell name (follows \"#!\" magic)"; -tSCC zShell_NAME[] = "SHELL"; -tSCC zNotShell_Name[] = "no-shell"; -tSCC zNotShell_Pfx[] = "no"; +static char const zShell_NAME[] = "SHELL"; +static char const zNotShell_Name[] = "no-shell"; +static char const zNotShell_Pfx[] = "no"; #define zShell_Name (zNotShell_Name + 3) #define SHELL_FLAGS (OPTST_INITENABLED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) @@ -100,12 +98,12 @@ tSCC zNotShell_Pfx[] = "no"; /* * Help/More_Help/Version option descriptions: */ -tSCC zHelpText[] = "Display extended usage information and exit"; -tSCC zHelp_Name[] = "help"; +static char const zHelpText[] = "Display extended usage information and exit"; +static char const zHelp_Name[] = "help"; #ifdef HAVE_WORKING_FORK #define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) -tSCC zMore_Help_Name[] = "more-help"; -tSCC zMore_HelpText[] = "Extended usage information passed thru pager"; +static char const zMore_Help_Name[] = "more-help"; +static char const zMore_HelpText[] = "Extended usage information passed thru pager"; #else #define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) #define zMore_Help_Name NULL @@ -118,13 +116,16 @@ tSCC zMore_HelpText[] = "Extended usage information passed thru pager"; OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT #endif -tSCC zVersionText[] = "Output version information and exit"; -tSCC zVersion_Name[] = "version"; +static char const zVersionText[] = "Output version information and exit"; +static char const zVersion_Name[] = "version"; /* * Declare option callback procedures */ extern tOptProc - optionPagedUsage, optionPrintVersion; + optionBooleanVal, optionNestedVal, optionNumericVal, + optionPagedUsage, optionPrintVersion, optionResetOpt, + optionStackArg, optionTimeVal, optionUnstackArg, + optionVersionStderr; static tOptProc doUsageOpt; @@ -217,7 +218,7 @@ If the script file already exists and contains Automated Option Processing\n\ text, the second line of the file through the ending tag will be replaced\n\ by the newly generated text. The first `#!' line will be regenerated.\n"; tSCC zFullVersion[] = GENSHELLOPT_FULL_VERSION; -/* extracted from optcode.tpl near line 495 */ +/* extracted from /old-home/bkorb/ag/ag/autoopts/tpl/optcode.tpl near line 493 */ #if defined(ENABLE_NLS) # define OPTPROC_BASE OPTPROC_TRANSLATE @@ -271,9 +272,9 @@ doUsageOpt( tOptDesc* pOptDesc ) { (void)pOptions; - USAGE( EXIT_SUCCESS ); + USAGE(EXIT_SUCCESS); } -/* extracted from optcode.tpl near line 627 */ +/* extracted from /old-home/bkorb/ag/ag/autoopts/tpl/optcode.tpl near line 626 */ #if ENABLE_NLS #include @@ -282,11 +283,11 @@ doUsageOpt( #include #include -static char* AO_gettext( char const* pz ); +static char* AO_gettext(char const* pz); static void coerce_it(void** s); static char* -AO_gettext( char const* pz ) +AO_gettext(char const* pz) { char* pzRes; if (pz == NULL) @@ -294,10 +295,10 @@ AO_gettext( char const* pz ) pzRes = _(pz); if (pzRes == pz) return pzRes; - pzRes = strdup( pzRes ); + pzRes = strdup(pzRes); if (pzRes == NULL) { - fputs( _("No memory for duping translated strings\n"), stderr ); - exit( EXIT_FAILURE ); + fputs(_("No memory for duping translated strings\n"), stderr); + exit(EXIT_FAILURE); } return pzRes; } @@ -310,7 +311,7 @@ static void coerce_it(void** s) { *s = AO_gettext(*s); } * This invokes the translation code (e.g. gettext(3)). */ static void -translate_option_strings( void ) +translate_option_strings(void) { /* * Guard against re-translation. It won't work. The strings will have diff --git a/sntp/libopts/genshell.h b/sntp/libopts/genshell.h index 787ab6ec0..d547ea1a2 100644 --- a/sntp/libopts/genshell.h +++ b/sntp/libopts/genshell.h @@ -2,21 +2,19 @@ * * DO NOT EDIT THIS FILE (genshell.h) * - * It has been AutoGen-ed November 8, 2009 at 08:41:09 AM by AutoGen 5.9.10pre13 + * It has been AutoGen-ed November 16, 2010 at 05:41:46 PM by AutoGen 5.11.2pre7 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts @AO_CURRENT@:@AO_REVISION@:@AO_AGE@ templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This header file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * genshellopt author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 33:3:8 templates. + * + * AutoOpts is a copyrighted work. This header file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the genshellopt author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * * This source file is copyrighted and licensed under the following terms: * @@ -52,7 +50,7 @@ * tolerable version is at least as old as what was current when the header * template was released. */ -#define AO_TEMPLATE_VERSION 135168 +#define AO_TEMPLATE_VERSION 135171 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) # error option template version mismatches autoopts/options.h header @@ -77,7 +75,7 @@ typedef enum { /* * Interface defines for all options. Replace "n" with the UPPER_CASED * option name (as in the teOptIndex enumeration above). - * e.g. HAVE_OPT( SCRIPT ) + * e.g. HAVE_OPT(SCRIPT) */ #define DESC(n) (genshelloptOptions.pOptDesc[INDEX_OPT_## n]) #define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n))) @@ -91,7 +89,7 @@ typedef enum { #define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs) #define CLEAR_OPT(n) STMTS( \ DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \ - if ( (DESC(n).fOptState & OPTST_INITENABLED) == 0) \ + if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \ DESC(n).fOptState |= OPTST_DISABLED; \ DESC(n).optCookie = NULL ) @@ -107,14 +105,14 @@ typedef enum { /* * Interface defines not associated with particular options */ -#define ERRSKIP_OPTERR STMTS( genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP ) -#define ERRSTOP_OPTERR STMTS( genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP ) +#define ERRSKIP_OPTERR STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP) +#define ERRSTOP_OPTERR STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP) #define RESTART_OPT(n) STMTS( \ genshelloptOptions.curOptIdx = (n); \ - genshelloptOptions.pzCurOpt = NULL ) + genshelloptOptions.pzCurOpt = NULL) #define START_OPT RESTART_OPT(1) -#define USAGE(c) (*genshelloptOptions.pUsageProc)( &genshelloptOptions, c ) -/* extracted from opthead.tpl near line 409 */ +#define USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c) +/* extracted from /old-home/bkorb/ag/ag/autoopts/tpl/opthead.tpl near line 408 */ /* * * * * * * @@ -129,9 +127,9 @@ extern tOptions genshelloptOptions; #if defined(ENABLE_NLS) # ifndef _ # include - static inline char* aoGetsText( char const* pz ) { + static inline char* aoGetsText(char const* pz) { if (pz == NULL) return NULL; - return (char*)gettext( pz ); + return (char*)gettext(pz); } # define _(s) aoGetsText(s) # endif /* _() */ diff --git a/sntp/libopts/load.c b/sntp/libopts/load.c index ef84b0fe9..d7616cd57 100644 --- a/sntp/libopts/load.c +++ b/sntp/libopts/load.c @@ -1,7 +1,7 @@ -/* - * $Id: f0ececd5fec43bacb417d7b50294accc2121923f $ - * Time-stamp: "2008-12-06 10:16:05 bkorb" +/** + * \file load.c + * Time-stamp: "2010-07-17 10:38:19 bkorb" * * This file contains the routines that deal with processing text strings * for options, either from a NUL-terminated string passed in or from an @@ -9,7 +9,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -31,23 +31,16 @@ tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static ag_bool -insertProgramPath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ); +insertProgramPath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath); static ag_bool -insertEnvVal( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ); +insertEnvVal(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath); static char* -assembleArgValue( char* pzTxt, tOptionLoadMode mode ); +assembleArgValue(char* pzTxt, tOptionLoadMode mode); /* = = = END-STATIC-FORWARD = = = */ /*=export_func optionMakePath @@ -102,19 +95,16 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode ); * errors (cannot resolve the resulting path). =*/ ag_bool -optionMakePath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +optionMakePath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { - size_t name_len = strlen( pzName ); + size_t name_len = strlen(pzName); # ifndef PKGDATADIR # define PKGDATADIR "" # endif - tSCC pkgdatadir[] = PKGDATADIR; + static char const pkgdatadir[] = PKGDATADIR; ag_bool res = AG_TRUE; @@ -125,7 +115,7 @@ optionMakePath( * IF not an environment variable, just copy the data */ if (*pzName != '$') { - tCC* pzS = pzName; + char const* pzS = pzName; char* pzD = pzBuf; int ct = bufSize; @@ -147,7 +137,7 @@ optionMakePath( return AG_FALSE; case '$': - res = insertProgramPath( pzBuf, bufSize, pzName, pzProgPath ); + res = insertProgramPath(pzBuf, bufSize, pzName, pzProgPath); break; case '@': @@ -162,7 +152,7 @@ optionMakePath( break; default: - res = insertEnvVal( pzBuf, bufSize, pzName, pzProgPath ); + res = insertEnvVal(pzBuf, bufSize, pzName, pzProgPath); } if (! res) @@ -182,11 +172,11 @@ optionMakePath( { char z[ PATH_MAX+1 ]; - if (realpath( pzBuf, z ) == NULL) + if (realpath(pzBuf, z) == NULL) return AG_FALSE; if (strlen(z) < bufSize) - strcpy( pzBuf, z ); + strcpy(pzBuf, z); } #endif @@ -195,14 +185,11 @@ optionMakePath( static ag_bool -insertProgramPath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +insertProgramPath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { - tCC* pzPath; - tCC* pz; + char const* pzPath; + char const* pz; int skip = 2; switch (pzName[2]) { @@ -219,16 +206,16 @@ insertProgramPath( * If it is, we're done. Otherwise, we have to hunt * for the program using "pathfind". */ - if (strchr( pzProgPath, DIRCH ) != NULL) + if (strchr(pzProgPath, DIRCH) != NULL) pzPath = pzProgPath; else { - pzPath = pathfind( getenv( "PATH" ), (char*)pzProgPath, "rx" ); + pzPath = pathfind(getenv("PATH"), (char*)pzProgPath, "rx"); if (pzPath == NULL) return AG_FALSE; } - pz = strrchr( pzPath, DIRCH ); + pz = strrchr(pzPath, DIRCH); /* * IF we cannot find a directory name separator, @@ -246,8 +233,8 @@ insertProgramPath( if ((pz - pzPath)+1 + strlen(pzName) >= bufSize) return AG_FALSE; - memcpy( pzBuf, pzPath, (size_t)((pz - pzPath)+1) ); - strcpy( pzBuf + (pz - pzPath) + 1, pzName ); + memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1)); + strcpy(pzBuf + (pz - pzPath) + 1, pzName); /* * If the "pzPath" path was gotten from "pathfind()", then it was @@ -260,11 +247,8 @@ insertProgramPath( static ag_bool -insertEnvVal( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +insertEnvVal(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { char* pzDir = pzBuf; @@ -280,7 +264,7 @@ insertEnvVal( *pzDir = NUL; - pzDir = getenv( pzBuf ); + pzDir = getenv(pzBuf); /* * Environment value not found -- skip the home list entry @@ -288,16 +272,16 @@ insertEnvVal( if (pzDir == NULL) return AG_FALSE; - if (strlen( pzDir ) + 1 + strlen( pzName ) >= bufSize) + if (strlen(pzDir) + 1 + strlen(pzName) >= bufSize) return AG_FALSE; - sprintf( pzBuf, "%s%s", pzDir, pzName ); + sprintf(pzBuf, "%s%s", pzDir, pzName); return AG_TRUE; } LOCAL void -mungeString( char* pzTxt, tOptionLoadMode mode ) +mungeString(char* pzTxt, tOptionLoadMode mode) { char* pzE; @@ -311,7 +295,7 @@ mungeString( char* pzTxt, tOptionLoadMode mode ) while ((*(pzD++) = *(pzS++)) != NUL) ; pzE = pzD-1; } else - pzE = pzTxt + strlen( pzTxt ); + pzE = pzTxt + strlen(pzTxt); while ((pzE > pzTxt) && IS_WHITESPACE_CHAR(pzE[-1])) pzE--; *pzE = NUL; @@ -331,15 +315,15 @@ mungeString( char* pzTxt, tOptionLoadMode mode ) case '\'': break; } - (void)ao_string_cook( pzTxt, NULL ); + (void)ao_string_cook(pzTxt, NULL); } static char* -assembleArgValue( char* pzTxt, tOptionLoadMode mode ) +assembleArgValue(char* pzTxt, tOptionLoadMode mode) { - tSCC zBrk[] = " \t\n:="; - char* pzEnd = strpbrk( pzTxt, zBrk ); + static char const zBrk[] = " \t\n:="; + char* pzEnd = strpbrk(pzTxt, zBrk); int space_break; /* @@ -390,9 +374,9 @@ loadOptionLine( while (IS_WHITESPACE_CHAR(*pzLine)) pzLine++; { - char* pzArg = assembleArgValue( pzLine, load_mode ); + char* pzArg = assembleArgValue(pzLine, load_mode); - if (! SUCCESSFUL( longOptionFind( pOpts, pzLine, pOS ))) + if (! SUCCESSFUL(longOptionFind(pOpts, pzLine, pOS))) return; if (pOS->flags & OPTST_NO_INIT) return; @@ -473,7 +457,7 @@ loadOptionLine( if (*pOS->pzOptArg == NUL) pOS->pzOptArg = NULL; else { - AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" ); + AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument"); pOS->flags |= OPTST_ALLOC_ARG; } @@ -481,7 +465,7 @@ loadOptionLine( if (*pOS->pzOptArg == NUL) pOS->pzOptArg = zNil; else { - AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" ); + AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument"); pOS->flags |= OPTST_ALLOC_ARG; } } @@ -489,7 +473,7 @@ loadOptionLine( { tOptionLoadMode sv = option_load_mode; option_load_mode = load_mode; - handleOption( pOpts, pOS ); + handleOption(pOpts, pOS); option_load_mode = sv; } } @@ -521,15 +505,13 @@ loadOptionLine( * will cause a warning to print, but the function should return. =*/ void -optionLoadLine( - tOptions* pOpts, - tCC* pzLine ) +optionLoadLine(tOptions * pOpts, char const * pzLine) { tOptState st = OPTSTATE_INITIALIZER(SET); char* pz; - AGDUPSTR( pz, pzLine, "user option line" ); - loadOptionLine( pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED ); - AGFREE( pz ); + AGDUPSTR(pz, pzLine, "user option line"); + loadOptionLine(pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED); + AGFREE(pz); } /* * Local Variables: diff --git a/sntp/libopts/m4/libopts.m4 b/sntp/libopts/m4/libopts.m4 index ef7f2930a..04bcc69e2 100644 --- a/sntp/libopts/m4/libopts.m4 +++ b/sntp/libopts/m4/libopts.m4 @@ -2,7 +2,7 @@ dnl -*- buffer-read-only: t -*- vi: set ro: dnl dnl DO NOT EDIT THIS FILE (libopts.m4) dnl -dnl It has been AutoGen-ed November 8, 2009 at 08:41:10 AM by AutoGen 5.9.10pre13 +dnl It has been AutoGen-ed November 16, 2010 at 05:41:43 PM by AutoGen 5.11.2pre7 dnl From the definitions libopts.def dnl and the template file conftest.tpl dnl @@ -16,45 +16,28 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ # ================= # AC_CHECK_HEADERS # ================= - AC_CHECK_HEADERS(dlfcn.h errno.h fcntl.h libgen.h memory.h netinet/in.h \ - setjmp.h sys/mman.h sys/param.h sys/poll.h sys/procset.h sys/select.h \ - sys/socket.h sys/stropts.h sys/time.h sys/un.h sys/wait.h unistd.h \ - utime.h sysexits.h) + AC_CHECK_HEADERS([ \ + dlfcn.h errno.h fcntl.h libgen.h \ + memory.h netinet/in.h setjmp.h sys/mman.h \ + sys/param.h sys/poll.h sys/procset.h sys/select.h \ + sys/socket.h sys/stropts.h sys/time.h sys/un.h \ + sys/wait.h unistd.h utime.h sysexits.h ]) - # -------------------------------------------- - # Verify certain entries from AC_CHECK_HEADERS - # -------------------------------------------- - [for f in sys_types sys_mman sys_param sys_stat sys_wait \ - string errno stdlib memory setjmp - do eval as_ac_var=\${ac_cv_header_${f}_h+set} - test "${as_ac_var}" = set] || \ - AC_MSG_ERROR([You must have ${f}.h on your system]) - done + AC_CHECK_HEADERS([stdarg.h varargs.h], + [lo_have_arg_hdr=true;break], + [lo_have_arg_hdr=false]) - # ================================================ - # AC_CHECK_HEADERS: stdarg.h is present define HAVE_STDARG_H, otherwise - # if varargs.h is present define HAVE_VARARGS_H. - # ================================================ - AC_CHECK_HEADERS(stdarg.h varargs.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have stdarg.h or varargs.h on your system]) - fi + AC_CHECK_HEADERS([string.h strings.h], + [lo_have_str_hdr=true;break], + [lo_have_str_hdr=false]) - # ================================================ - # Similarly for the string.h and strings.h headers - # ================================================ - AC_CHECK_HEADERS(string.h strings.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have string.h or strings.h on your system]) - fi + AC_CHECK_HEADERS([limits.h sys/limits.h values.h], + [lo_have_lim_hdr=true;break], + [lo_have_lim_hdr=false]) - # ===================== - # ...and limits headers - # ===================== - AC_CHECK_HEADERS(limits.h sys/limits.h values.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have one of limits.h, sys/limits.h or values.h]) - fi + AC_CHECK_HEADERS([inttypes.h stdint.h], + [lo_have_typ_hdr=true;break], + [lo_have_typ_hdr=false]) # ---------------------------------------------------------------------- # check for various programs used during the build. @@ -67,6 +50,30 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ #endif ]) + # -------------------------------------------- + # Verify certain entries from AC_CHECK_HEADERS + # -------------------------------------------- + [for f in sys_types sys_mman sys_param sys_stat sys_wait \ + string errno stdlib memory setjmp + do eval as_ac_var=\${ac_cv_header_${f}_h+set} + test "${as_ac_var}" = set || { + ]AC_MSG_ERROR([You must have ${f}.h on your system])[ + } + done + + ${lo_have_arg_hdr} || \ + ]AC_MSG_ERROR([You must have stdarg.h or varargs.h on your system])[ + + ${lo_have_str_hdr} || \ + ]AC_MSG_ERROR([You must have string.h or strings.h on your system])[ + + ${lo_have_lim_hdr} || \ + ]AC_MSG_ERROR( + [You must have one of limits.h, sys/limits.h or values.h])[ + + ${lo_have_typ_hdr} || \ + ]AC_MSG_ERROR([You must have inttypes.h or stdint.h on your system]) + # ---------------------------------------------------------------------- # Checks for typedefs # ---------------------------------------------------------------------- @@ -80,11 +87,6 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ # include #endif ]) - - # ======================== - # ...and int types headers - # ======================== - AC_CHECK_HEADERS(stdint.h inttypes.h, break) AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, intptr_t, uintptr_t, uint_t, pid_t, size_t]) @@ -438,7 +440,7 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[ dnl @synopsis LIBOPTS_CHECK dnl -dnl Time-stamp: "2009-07-22 18:50:49 bkorb" +dnl Time-stamp: "2010-02-24 08:37:21 bkorb" dnl dnl If autoopts-config works, add the linking information to LIBS. dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all @@ -446,7 +448,7 @@ dnl the config tests that the library needs. Invoke the dnl "INVOKE_LIBOPTS_MACROS" macro iff we are building libopts. dnl dnl This file is part of AutoGen. -dnl AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved +dnl AutoGen Copyright (c) 1992-2010 by Bruce Korb - all rights reserved dnl dnl AutoGen is free software: you can redistribute it and/or modify it dnl under the terms of the GNU General Public License as published by the diff --git a/sntp/libopts/m4/liboptschk.m4 b/sntp/libopts/m4/liboptschk.m4 index 67443e879..896b05ea9 100644 --- a/sntp/libopts/m4/liboptschk.m4 +++ b/sntp/libopts/m4/liboptschk.m4 @@ -1,11 +1,11 @@ # liboptschk.m4 serial 1 (autogen - 5.7.3) -dnl copyright (c) 2005-2009 by Bruce Korb - all rights reserved +dnl Copyright (c) 2005-2010 by Bruce Korb - all rights reserved dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -dnl Time-stamp: "2009-07-22 18:53:27 bkorb" +dnl Time-stamp: "2010-02-24 08:38:55 bkorb" dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public diff --git a/sntp/libopts/makeshell.c b/sntp/libopts/makeshell.c index 5bbb05c5d..5bc8fc1ee 100644 --- a/sntp/libopts/makeshell.c +++ b/sntp/libopts/makeshell.c @@ -1,14 +1,15 @@ -/* - * $Id: 7226344c6486a4eda395f893881080b7d80a2003 $ - * Time-stamp: "2009-11-01 11:52:37 bkorb" +/** + * \file makeshell.c + * + * Time-stamp: "2010-09-05 05:58:57 bkorb" * * This module will interpret the options set in the tOptions * structure and create a Bourne shell script capable of parsing them. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -341,33 +342,32 @@ static char* pzLeader = NULL; static char* pzTrailer = NULL; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ); +textToVariable(tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD); static void -emitUsage( tOptions* pOpts ); +emitUsage(tOptions* pOpts); static void -emitSetup( tOptions* pOpts ); +emitSetup(tOptions* pOpts); static void -printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc ); +printOptionAction(tOptions* pOpts, tOptDesc* pOptDesc); static void -printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc ); +printOptionInaction(tOptions* pOpts, tOptDesc* pOptDesc); static void -emitFlag( tOptions* pOpts ); +emitFlag(tOptions* pOpts); static void -emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ); +emitMatchExpr(tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts); static void -emitLong( tOptions* pOpts ); +emitLong(tOptions* pOpts); static void -openOutput( char const* pzFile ); +openOutput(char const* pzFile); /* = = = END-STATIC-FORWARD = = = */ /*=export_func optionParseShell @@ -380,101 +380,105 @@ openOutput( char const* pzFile ); * Emit a shell script that will parse the command line options. =*/ void -optionParseShell( tOptions* pOpts ) +optionParseShell(tOptions* pOpts) { /* * Check for our SHELL option now. * IF the output file contains the "#!" magic marker, * it will override anything we do here. */ - if (HAVE_OPT( SHELL )) - pzShell = OPT_ARG( SHELL ); + if (HAVE_OPT(SHELL)) + pzShell = OPT_ARG(SHELL); - else if (! ENABLED_OPT( SHELL )) + else if (! ENABLED_OPT(SHELL)) pzShell = NULL; - else if ((pzShell = getenv( "SHELL" )), + else if ((pzShell = getenv("SHELL")), pzShell == NULL) - pzShell = "/bin/sh"; + pzShell = DEFAULT_SHELL; /* * Check for a specified output file */ - if (HAVE_OPT( SCRIPT )) - openOutput( OPT_ARG( SCRIPT )); + if (HAVE_OPT(SCRIPT)) + openOutput(OPT_ARG(SCRIPT)); - emitUsage( pOpts ); - emitSetup( pOpts ); + emitUsage(pOpts); + emitSetup(pOpts); /* * There are four modes of option processing. */ switch (pOpts->fOptSet & (OPTPROC_LONGOPT|OPTPROC_SHORTOPT)) { case OPTPROC_LONGOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zLongSelection, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zLongSelection, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; case 0: - fputs( zLoopOnly, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); + fputs(zLoopOnly, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); break; case OPTPROC_SHORTOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zFlagSelection, stdout ); - fputs( zFlagOptInit, stdout ); - emitFlag( pOpts ); - printf( zFlagOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zFlagSelection, stdout); + fputs(zFlagOptInit, stdout); + emitFlag(pOpts); + printf(zFlagOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; case OPTPROC_LONGOPT|OPTPROC_SHORTOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zLongSelection, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zLongSelection, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zFlagSelection, stdout ); - fputs( zFlagOptInit, stdout ); - emitFlag( pOpts ); - printf( zFlagOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zFlagSelection, stdout); + fputs(zFlagOptInit, stdout); + emitFlag(pOpts); + printf(zFlagOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; } - printf( zLoopEnd, pOpts->pzPROGNAME, zTrailerMarker ); + printf(zLoopEnd, pOpts->pzPROGNAME, zTrailerMarker); if ((pzTrailer != NULL) && (*pzTrailer != '\0')) - fputs( pzTrailer, stdout ); - else if (ENABLED_OPT( SHELL )) - printf( "\nenv | grep '^%s_'\n", pOpts->pzPROGNAME ); - - fflush( stdout ); - fchmod( STDOUT_FILENO, 0755 ); - fclose( stdout ); + fputs(pzTrailer, stdout); + else if (ENABLED_OPT(SHELL)) + printf("\nenv | grep '^%s_'\n", pOpts->pzPROGNAME); + + fflush(stdout); + fchmod(STDOUT_FILENO, 0755); + fclose(stdout); + if (ferror(stdout)) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } } static void -textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) +textToVariable(tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD) { # define _TT_(n) tSCC z ## n [] = #n; TEXTTO_TABLE @@ -484,42 +488,42 @@ textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) # undef _TT_ #if ! defined(HAVE_WORKING_FORK) - printf( "%1$s_%2$s_TEXT='no %2$s text'\n", - pOpts->pzPROGNAME, apzTTNames[ whichVar ]); + printf("%1$s_%2$s_TEXT='no %2$s text'\n", + pOpts->pzPROGNAME, apzTTNames[ whichVar ]); #else int nlHoldCt = 0; int pipeFd[2]; FILE* fp; - printf( "%s_%s_TEXT='", pOpts->pzPROGNAME, apzTTNames[ whichVar ]); - fflush( stdout ); + printf("%s_%s_TEXT='", pOpts->pzPROGNAME, apzTTNames[ whichVar ]); + fflush(stdout); - if (pipe( pipeFd ) != 0) { - fprintf( stderr, zBadPipe, errno, strerror( errno )); - exit( EXIT_FAILURE ); + if (pipe(pipeFd) != 0) { + fprintf(stderr, zBadPipe, errno, strerror(errno)); + exit(EXIT_FAILURE); } switch (fork()) { case -1: - fprintf( stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName); - exit( EXIT_FAILURE ); + fprintf(stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName); + exit(EXIT_FAILURE); break; case 0: - dup2( pipeFd[1], STDERR_FILENO ); - dup2( pipeFd[1], STDOUT_FILENO ); - close( pipeFd[0] ); + dup2(pipeFd[1], STDERR_FILENO); + dup2(pipeFd[1], STDOUT_FILENO); + close(pipeFd[0]); switch (whichVar) { case TT_LONGUSAGE: - (*(pOpts->pUsageProc))( pOpts, EXIT_SUCCESS ); + (*(pOpts->pUsageProc))(pOpts, EXIT_SUCCESS); /* NOTREACHED */ - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); case TT_USAGE: - (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE ); + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); /* NOTREACHED */ - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); case TT_VERSION: if (pOD->fOptState & OPTST_ALLOC_ARG) { @@ -527,20 +531,20 @@ textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) pOD->fOptState &= ~OPTST_ALLOC_ARG; } pOD->optArg.argString = "c"; - optionPrintVersion( pOpts, pOD ); + optionPrintVersion(pOpts, pOD); /* NOTREACHED */ default: - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); } default: - close( pipeFd[1] ); - fp = fdopen( pipeFd[0], "r" FOPEN_BINARY_FLAG ); + close(pipeFd[1]); + fp = fdopen(pipeFd[0], "r" FOPEN_BINARY_FLAG); } for (;;) { - int ch = fgetc( fp ); + int ch = fgetc(fp); switch (ch) { case '\n': @@ -549,10 +553,10 @@ textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) case '\'': while (nlHoldCt > 0) { - fputc( '\n', stdout ); + fputc('\n', stdout); nlHoldCt--; } - fputs( "'\\''", stdout ); + fputs("'\\''", stdout); break; case EOF: @@ -560,24 +564,24 @@ textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) default: while (nlHoldCt > 0) { - fputc( '\n', stdout ); + fputc('\n', stdout); nlHoldCt--; } - fputc( ch, stdout ); + fputc(ch, stdout); break; } } endCharLoop:; - fputs( "'\n\n", stdout ); - close( pipeFd[0] ); + fputs("'\n\n", stdout); + close(pipeFd[0]); #endif } static void -emitUsage( tOptions* pOpts ) +emitUsage(tOptions* pOpts) { - char zTimeBuf[ AO_NAME_SIZE ]; + char zTimeBuf[AO_NAME_SIZE]; /* * First, switch stdout to the output file name. @@ -586,26 +590,26 @@ emitUsage( tOptions* pOpts ) * executable name). Down case the upper cased name. */ if (pzLeader != NULL) - fputs( pzLeader, stdout ); + fputs(pzLeader, stdout); { tSCC zStdout[] = "stdout"; tCC* pzOutName; { - time_t curTime = time( NULL ); - struct tm* pTime = localtime( &curTime ); + time_t curTime = time(NULL); + struct tm* pTime = localtime(&curTime); strftime(zTimeBuf, AO_NAME_SIZE, "%A %B %e, %Y at %r %Z", pTime ); } - if (HAVE_OPT( SCRIPT )) - pzOutName = OPT_ARG( SCRIPT ); + if (HAVE_OPT(SCRIPT)) + pzOutName = OPT_ARG(SCRIPT); else pzOutName = zStdout; if ((pzLeader == NULL) && (pzShell != NULL)) - printf( "#! %s\n", pzShell ); + printf("#! %s\n", pzShell); - printf( zPreamble, zStartMarker, pzOutName, zTimeBuf ); + printf(zPreamble, zStartMarker, pzOutName, zTimeBuf); } /* @@ -615,16 +619,16 @@ emitUsage( tOptions* pOpts ) char* pzPN = zTimeBuf; tCC* pz = pOpts->pzPROGNAME; for (;;) { - if ((*pzPN++ = tolower( *pz++ )) == '\0') + if ((*pzPN++ = tolower(*pz++)) == '\0') break; } } - printf( zEndPreamble, pOpts->pzPROGNAME ); + printf(zEndPreamble, pOpts->pzPROGNAME); pOpts->pzProgPath = pOpts->pzProgName = zTimeBuf; - textToVariable( pOpts, TT_LONGUSAGE, NULL ); - textToVariable( pOpts, TT_USAGE, NULL ); + textToVariable(pOpts, TT_LONGUSAGE, NULL); + textToVariable(pOpts, TT_USAGE, NULL); { tOptDesc* pOptDesc = pOpts->pOptDesc; @@ -632,7 +636,7 @@ emitUsage( tOptions* pOpts ) for (;;) { if (pOptDesc->pOptProc == optionPrintVersion) { - textToVariable( pOpts, TT_VERSION, pOptDesc ); + textToVariable(pOpts, TT_VERSION, pOptDesc); break; } @@ -645,7 +649,7 @@ emitUsage( tOptions* pOpts ) static void -emitSetup( tOptions* pOpts ) +emitSetup(tOptions* pOpts) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->presetOptCt; @@ -680,14 +684,14 @@ emitSetup( tOptions* pOpts ) * Numeric and membership bit options are just printed as a number. */ case OPARG_TYPE_NUMERIC: - snprintf( zVal, sizeof( zVal ), "%d", - (int)pOptDesc->optArg.argInt ); + snprintf(zVal, sizeof(zVal), "%d", + (int)pOptDesc->optArg.argInt); pzDefault = zVal; break; case OPARG_TYPE_MEMBERSHIP: - snprintf( zVal, sizeof( zVal ), "%lu", - (unsigned long)pOptDesc->optArg.argIntptr ); + snprintf(zVal, sizeof(zVal), "%lu", + (unsigned long)pOptDesc->optArg.argIntptr); pzDefault = zVal; break; @@ -705,87 +709,87 @@ emitSetup( tOptions* pOpts ) pzDefault = pOptDesc->optArg.argString; } - printf( pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault ); + printf(pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault); } } static void -printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc ) +printOptionAction(tOptions* pOpts, tOptDesc* pOptDesc) { if (pOptDesc->pOptProc == optionPrintVersion) - printf( zTextExit, pOpts->pzPROGNAME, "VERSION" ); + printf(zTextExit, pOpts->pzPROGNAME, "VERSION"); else if (pOptDesc->pOptProc == optionPagedUsage) - printf( zPagedUsageExit, pOpts->pzPROGNAME ); + printf(zPagedUsageExit, pOpts->pzPROGNAME); else if (pOptDesc->pOptProc == optionLoadOpt) { - printf( zCmdFmt, "echo 'Warning: Cannot load options files' >&2" ); - printf( zCmdFmt, "OPT_ARG_NEEDED=YES" ); + printf(zCmdFmt, "echo 'Warning: Cannot load options files' >&2"); + printf(zCmdFmt, "OPT_ARG_NEEDED=YES"); } else if (pOptDesc->pz_NAME == NULL) { if (pOptDesc->pOptProc == NULL) { - printf( zCmdFmt, "echo 'Warning: Cannot save options files' " - ">&2" ); - printf( zCmdFmt, "OPT_ARG_NEEDED=OK" ); + printf(zCmdFmt, "echo 'Warning: Cannot save options files' " + ">&2"); + printf(zCmdFmt, "OPT_ARG_NEEDED=OK"); } else - printf( zTextExit, pOpts->pzPROGNAME, "LONGUSAGE" ); + printf(zTextExit, pOpts->pzPROGNAME, "LONGUSAGE"); } else { if (pOptDesc->optMaxCt == 1) - printf( zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); else { if ((unsigned)pOptDesc->optMaxCt < NOLIMIT) - printf( zCountTest, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->optMaxCt ); + printf(zCountTest, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->optMaxCt); - printf( zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } /* * Fix up the args. */ if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) { - printf( zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) { - printf( zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } else { - fputs( zMustArg, stdout ); + fputs(zMustArg, stdout); } } - fputs( zOptionEndSelect, stdout ); + fputs(zOptionEndSelect, stdout); } static void -printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc ) +printOptionInaction(tOptions* pOpts, tOptDesc* pOptDesc) { if (pOptDesc->pOptProc == optionLoadOpt) { - printf( zCmdFmt, "echo 'Warning: Cannot suppress the loading of " - "options files' >&2" ); + printf(zCmdFmt, "echo 'Warning: Cannot suppress the loading of " + "options files' >&2"); } else if (pOptDesc->optMaxCt == 1) - printf( zNoSingleArg, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx ); + printf(zNoSingleArg, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); else - printf( zNoMultiArg, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx ); + printf(zNoMultiArg, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); - printf( zCmdFmt, "OPT_ARG_NEEDED=NO" ); - fputs( zOptionEndSelect, stdout ); + printf(zCmdFmt, "OPT_ARG_NEEDED=NO"); + fputs(zOptionEndSelect, stdout); } static void -emitFlag( tOptions* pOpts ) +emitFlag(tOptions* pOpts) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->optCt; - fputs( zOptionCase, stdout ); + fputs(zOptionCase, stdout); for (;optionCt > 0; pOptDesc++, --optionCt) { @@ -793,11 +797,11 @@ emitFlag( tOptions* pOpts ) continue; if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) { - printf( zOptionFlag, pOptDesc->optValue ); - printOptionAction( pOpts, pOptDesc ); + printf(zOptionFlag, pOptDesc->optValue); + printOptionAction(pOpts, pOptDesc); } } - printf( zOptionUnknown, "flag", pOpts->pzPROGNAME ); + printf(zOptionUnknown, "flag", pOpts->pzPROGNAME); } @@ -805,7 +809,7 @@ emitFlag( tOptions* pOpts ) * Emit the match text for a long option */ static void -emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) +emitMatchExpr(tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts) { tOptDesc* pOD = pOpts->pOptDesc; int oCt = pOpts->optCt; @@ -831,8 +835,8 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) * They must not be the same. They cannot be, because it would * not compile correctly if they were. */ - while ( toupper( pOD->pz_Name[matchCt] ) - == toupper( pzMatchName[matchCt] )) + while ( toupper(pOD->pz_Name[matchCt]) + == toupper(pzMatchName[matchCt])) matchCt++; if (matchCt > min) @@ -843,8 +847,8 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) */ if (pOD->pz_DisableName != NULL) { matchCt = 0; - while ( toupper( pOD->pz_DisableName[matchCt] ) - == toupper( pzMatchName[matchCt] )) + while ( toupper(pOD->pz_DisableName[matchCt]) + == toupper(pzMatchName[matchCt])) matchCt++; if (matchCt > min) min = matchCt; @@ -860,7 +864,7 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) */ if ( (pzMatchName[min ] == NUL) || (pzMatchName[min+1] == NUL) ) - printf( zOptionFullName, pzMatchName ); + printf(zOptionFullName, pzMatchName); else { int matchCt = 0; @@ -869,11 +873,11 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) for (;;) { *pz = NUL; - printf( zOptionPartName, zName ); + printf(zOptionPartName, zName); *pz++ = pzMatchName[matchCt++]; if (pzMatchName[matchCt] == NUL) { *pz = NUL; - printf( zOptionFullName, zName ); + printf(zOptionFullName, zName); break; } } @@ -885,12 +889,12 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) * Emit GNU-standard long option handling code */ static void -emitLong( tOptions* pOpts ) +emitLong(tOptions* pOpts) { tOptDesc* pOD = pOpts->pOptDesc; int ct = pOpts->optCt; - fputs( zOptionCase, stdout ); + fputs(zOptionCase, stdout); /* * do each option, ... @@ -902,24 +906,24 @@ emitLong( tOptions* pOpts ) if (SKIP_OPT(pOD)) continue; - emitMatchExpr( pOD->pz_Name, pOD, pOpts ); - printOptionAction( pOpts, pOD ); + emitMatchExpr(pOD->pz_Name, pOD, pOpts); + printOptionAction(pOpts, pOD); /* * Now, do the same thing for the disablement version of the option. */ if (pOD->pz_DisableName != NULL) { - emitMatchExpr( pOD->pz_DisableName, pOD, pOpts ); - printOptionInaction( pOpts, pOD ); + emitMatchExpr(pOD->pz_DisableName, pOD, pOpts); + printOptionInaction(pOpts, pOD); } } while (pOD++, --ct > 0); - printf( zOptionUnknown, "option", pOpts->pzPROGNAME ); + printf(zOptionUnknown, "option", pOpts->pzPROGNAME); } static void -openOutput( char const* pzFile ) +openOutput(char const* pzFile) { FILE* fp; char* pzData = NULL; @@ -934,19 +938,19 @@ openOutput( char const* pzFile ) * THEN assume we are creating a new file. * Skip the loading of the old data. */ - if (stat( pzFile, &stbf ) != 0) + if (stat(pzFile, &stbf) != 0) break; /* * The file must be a regular file */ - if (! S_ISREG( stbf.st_mode )) { - fprintf( stderr, zNotFile, pzFile ); - exit( EXIT_FAILURE ); + if (! S_ISREG(stbf.st_mode)) { + fprintf(stderr, zNotFile, pzFile); + exit(EXIT_FAILURE); } pzData = AGALOC(stbf.st_size + 1, "file data"); - fp = fopen( pzFile, "r" FOPEN_BINARY_FLAG ); + fp = fopen(pzFile, "r" FOPEN_BINARY_FLAG); sizeLeft = (unsigned)stbf.st_size; pzScan = pzData; @@ -955,7 +959,7 @@ openOutput( char const* pzFile ) * Read in all the data as fast as our OS will let us. */ for (;;) { - int inct = fread( (void*)pzScan, (size_t)1, sizeLeft, fp); + int inct = fread((void*)pzScan, (size_t)1, sizeLeft, fp); if (inct == 0) break; @@ -970,29 +974,32 @@ openOutput( char const* pzFile ) * NUL-terminate the leader and look for the trailer */ *pzScan = '\0'; - fclose( fp ); - pzScan = strstr( pzData, zStartMarker ); + fclose(fp); + pzScan = strstr(pzData, zStartMarker); if (pzScan == NULL) { pzTrailer = pzData; break; } *(pzScan++) = NUL; - pzScan = strstr( pzScan, zTrailerMarker ); + pzScan = strstr(pzScan, zTrailerMarker); if (pzScan == NULL) { pzTrailer = pzData; break; } /* - * Check to see if the data contains - * our marker. If it does, then we will skip over it + * Check to see if the data contains our marker. + * If it does, then we will skip over it */ - pzTrailer = pzScan + sizeof( zTrailerMarker ) - 1; + pzTrailer = pzScan + sizeof(zTrailerMarker) - 1; pzLeader = pzData; } while (AG_FALSE); - freopen( pzFile, "w" FOPEN_BINARY_FLAG, stdout ); + if (freopen(pzFile, "w" FOPEN_BINARY_FLAG, stdout) != stdout) { + fprintf(stderr, zFreopenFail, errno, strerror(errno)); + exit(EXIT_FAILURE); + } } @@ -1011,19 +1018,21 @@ openOutput( char const* pzFile ) * and create shell script variables containing the two types of text. =*/ void -genshelloptUsage( tOptions* pOpts, int exitCode ) +genshelloptUsage(tOptions* pOpts, int exitCode) { #if ! defined(HAVE_WORKING_FORK) - optionUsage( pOpts, exitCode ); + optionUsage(pOpts, exitCode); #else /* * IF not EXIT_SUCCESS, * THEN emit the short form of usage. */ if (exitCode != EXIT_SUCCESS) - optionUsage( pOpts, exitCode ); - fflush( stderr ); - fflush( stdout ); + optionUsage(pOpts, exitCode); + fflush(stderr); + fflush(stdout); + if (ferror(stdout) || ferror(stderr)) + exit(EXIT_FAILURE); option_usage_fp = stdout; @@ -1032,20 +1041,20 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) */ switch (fork()) { case -1: - optionUsage( pOpts, EXIT_FAILURE ); + optionUsage(pOpts, EXIT_FAILURE); /* NOTREACHED */ - _exit( EXIT_FAILURE ); + _exit(EXIT_FAILURE); case 0: pagerState = PAGER_STATE_CHILD; - optionUsage( pOpts, EXIT_SUCCESS ); + optionUsage(pOpts, EXIT_SUCCESS); /* NOTREACHED */ - _exit( EXIT_FAILURE ); + _exit(EXIT_FAILURE); default: { int sts; - wait( &sts ); + wait(&sts); } } @@ -1055,10 +1064,10 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) */ { char* pz; - AGDUPSTR( pz, pShellParseOptions->pzPROGNAME, "program name" ); + AGDUPSTR(pz, pShellParseOptions->pzPROGNAME, "program name"); pShellParseOptions->pzProgName = pz; while (*pz != NUL) { - *pz = tolower( *pz ); + *pz = tolower(*pz); pz++; } } @@ -1066,8 +1075,8 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) /* * Separate the makeshell usage from the client usage */ - fprintf( option_usage_fp, zGenshell, pShellParseOptions->pzProgName ); - fflush( option_usage_fp ); + fprintf(option_usage_fp, zGenshell, pShellParseOptions->pzProgName); + fflush(option_usage_fp); /* * Now, print the client usage. @@ -1077,16 +1086,22 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) pagerState = PAGER_STATE_CHILD; /*FALLTHROUGH*/ case -1: - optionUsage( pShellParseOptions, EXIT_FAILURE ); + optionUsage(pShellParseOptions, EXIT_FAILURE); default: { int sts; - wait( &sts ); + wait(&sts); + } } + + fflush(stdout); + if (ferror(stdout)) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); } - exit( EXIT_SUCCESS ); + exit(EXIT_SUCCESS); #endif } diff --git a/sntp/libopts/nested.c b/sntp/libopts/nested.c index 3c016b747..b965c67ec 100644 --- a/sntp/libopts/nested.c +++ b/sntp/libopts/nested.c @@ -1,13 +1,14 @@ -/* - * $Id: 43877d3ade0b626b4bec87f2f340a8358c118333 $ - * Time-stamp: "2008-07-28 19:18:28 bkorb" +/** + * \file nested.c + * + * Time-stamp: "2010-08-22 11:17:56 bkorb" * * Automated Options Nested Values module. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -41,49 +42,44 @@ static xml_xlate_t const xml_xlate[] = { }; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -removeLineContinue( char* pzSrc ); +remove_continuation(char* pzSrc); static char const* -scanQuotedString( char const* pzTxt ); +scan_q_str(char const* pzTxt); static tOptionValue* -addStringValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_string(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addBoolValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_bool(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addNumberValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_number(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addNestedValue( void** pp, char const* pzName, size_t nameLen, - char* pzValue, size_t dataLen ); +add_nested(void** pp, char const* pzName, size_t nameLen, + char* pzValue, size_t dataLen); -static char const* -scanNameEntry(char const* pzName, tOptionValue* pRes); +static char const * +scan_name(char const* pzName, tOptionValue* pRes); static char const* -scanXmlEntry( char const* pzName, tOptionValue* pRes ); - -static void -unloadNestedArglist( tArgList* pAL ); +scan_xml(char const* pzName, tOptionValue* pRes); static void -sortNestedList( tArgList* pAL ); +sort_list(tArgList* pAL); /* = = = END-STATIC-FORWARD = = = */ -/* removeLineContinue - * +/** * Backslashes are used for line continuations. We keep the newline * characters, but trim out the backslash: */ static void -removeLineContinue( char* pzSrc ) +remove_continuation(char* pzSrc) { char* pzD; @@ -117,13 +113,11 @@ removeLineContinue( char* pzSrc ) } } - -/* scanQuotedString - * +/** * Find the end of a quoted string, skipping escaped quote characters. */ static char const* -scanQuotedString( char const* pzTxt ) +scan_q_str(char const* pzTxt) { char q = *(pzTxt++); /* remember the type of quote */ @@ -156,18 +150,17 @@ scanQuotedString( char const* pzTxt ) } -/* addStringValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addStringValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_string(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + dataLen + sizeof(*pNV); - pNV = AGALOC( sz, "option name/str value pair" ); + pNV = AGALOC(sz, "option name/str value pair"); if (pNV == NULL) return NULL; @@ -198,25 +191,23 @@ addStringValue( void** pp, char const* pzName, size_t nameLen, pNV->pzName = pNV->v.strVal + dataLen + 1; } - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addBoolValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addBoolValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_bool(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "option name/bool value pair" ); + pNV = AGALOC(sz, "option name/bool value pair"); if (pNV == NULL) return NULL; while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) { @@ -232,25 +223,23 @@ addBoolValue( void** pp, char const* pzName, size_t nameLen, pNV->valType = OPARG_TYPE_BOOLEAN; pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addNumberValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addNumberValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_number(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "option name/bool value pair" ); + pNV = AGALOC(sz, "option name/bool value pair"); if (pNV == NULL) return NULL; while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) { @@ -263,52 +252,48 @@ addNumberValue( void** pp, char const* pzName, size_t nameLen, pNV->valType = OPARG_TYPE_NUMERIC; pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addNestedValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addNestedValue( void** pp, char const* pzName, size_t nameLen, - char* pzValue, size_t dataLen ) +add_nested(void** pp, char const* pzName, size_t nameLen, + char* pzValue, size_t dataLen) { tOptionValue* pNV; if (dataLen == 0) { size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "empty nested value pair" ); + pNV = AGALOC(sz, "empty nested value pair"); if (pNV == NULL) return NULL; pNV->v.nestVal = NULL; pNV->valType = OPARG_TYPE_HIERARCHY; pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; } else { - pNV = optionLoadNested( pzValue, pzName, nameLen ); + pNV = optionLoadNested(pzValue, pzName, nameLen); } if (pNV != NULL) - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* scanNameEntry - * +/** * We have an entry that starts with a name. Find the end of it, cook it * (if called for) and create the name/value association. */ -static char const* -scanNameEntry(char const* pzName, tOptionValue* pRes) +static char const * +scan_name(char const* pzName, tOptionValue* pRes) { tOptionValue* pNV; char const * pzScan = pzName+1; /* we know first char is a name char */ @@ -324,11 +309,12 @@ scanNameEntry(char const* pzName, tOptionValue* pRes) if (pzScan[-1] == ':') { pzScan--; nameLen--; } while (IS_HORIZ_WHITE_CHAR(*pzScan)) pzScan++; -re_switch: + re_switch: + switch (*pzScan) { case '=': case ':': - while (IS_HORIZ_WHITE_CHAR( (int)*++pzScan )) ; + while (IS_HORIZ_WHITE_CHAR((int)*++pzScan)) ; if ((*pzScan == '=') || (*pzScan == ':')) goto default_char; goto re_switch; @@ -339,18 +325,18 @@ re_switch: /* FALLTHROUGH */ case NUL: - addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); break; case '"': case '\'': pzVal = pzScan; - pzScan = scanQuotedString( pzScan ); + pzScan = scan_q_str(pzScan); dataLen = pzScan - pzVal; - pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, - dataLen ); + pNV = add_string(&(pRes->v.nestVal), pzName, nameLen, pzVal, + dataLen); if ((pNV != NULL) && (option_load_mode == OPTION_LOAD_COOKED)) - ao_string_cook( pNV->v.strVal, NULL ); + ao_string_cook(pNV->v.strVal, NULL); break; default: @@ -379,10 +365,10 @@ re_switch: case ',': dataLen = (pzScan - pzVal) - 1; string_done: - pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen, - pzVal, dataLen ); + pNV = add_string(&(pRes->v.nestVal), pzName, nameLen, + pzVal, dataLen); if (pNV != NULL) - removeLineContinue( pNV->v.strVal ); + remove_continuation(pNV->v.strVal); goto leave_scan_name; } } @@ -392,15 +378,13 @@ re_switch: return pzScan; } - -/* scanXmlEntry - * +/** * We've found a '<' character. We ignore this if it is a comment or a * directive. If it is something else, then whatever it is we are looking * at is bogus. Returning NULL stops processing. */ static char const* -scanXmlEntry( char const* pzName, tOptionValue* pRes ) +scan_xml(char const* pzName, tOptionValue* pRes) { size_t nameLen = 1, valLen = 0; char const* pzScan = ++pzName; @@ -416,13 +400,13 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) break; case '!': - pzName = strstr( pzName, "-->" ); + pzName = strstr(pzName, "-->"); if (pzName != NULL) pzName += 3; break; case '?': - pzName = strchr( pzName, '>' ); + pzName = strchr(pzName, '>'); if (pzName != NULL) pzName++; break; @@ -431,7 +415,7 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) } pzScan++; - while (IS_VALUE_NAME_CHAR( (int)*pzScan )) { pzScan++; nameLen++; } + while (IS_VALUE_NAME_CHAR((int)*pzScan)) { pzScan++; nameLen++; } if (nameLen > 64) return NULL; valu.valType = OPARG_TYPE_STRING; @@ -457,7 +441,7 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) option_load_mode = save_mode; return NULL; } - addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); option_load_mode = save_mode; return pzScan+1; @@ -487,7 +471,7 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) *(pzD++) = '>'; *pzD = NUL; - pzScan = strstr( pzScan, z ); + pzScan = strstr(pzScan, z); if (pzScan == NULL) { option_load_mode = save_mode; return NULL; @@ -499,34 +483,34 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) switch (valu.valType) { case OPARG_TYPE_NONE: - addStringValue( &(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); break; case OPARG_TYPE_STRING: - pNewVal = addStringValue( + pNewVal = add_string( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); if (option_load_mode == OPTION_LOAD_KEEP) break; - mungeString( pNewVal->v.strVal, option_load_mode ); + mungeString(pNewVal->v.strVal, option_load_mode); break; case OPARG_TYPE_BOOLEAN: - addBoolValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen ); + add_bool(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); break; case OPARG_TYPE_NUMERIC: - addNumberValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen ); + add_number(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); break; case OPARG_TYPE_HIERARCHY: { - char* pz = AGALOC( valLen+1, "hierarchical scan" ); + char* pz = AGALOC(valLen+1, "hierarchical scan"); if (pz == NULL) break; - memcpy( pz, pzVal, valLen ); + memcpy(pz, pzVal, valLen); pz[valLen] = NUL; - addNestedValue( &(pRes->v.nestVal), pzName, nameLen, pz, valLen ); + add_nested(&(pRes->v.nestVal), pzName, nameLen, pz, valLen); AGFREE(pz); break; } @@ -542,15 +526,14 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) } -/* unloadNestedArglist - * +/** * Deallocate a list of option arguments. This must have been gotten from * a hierarchical option argument, not a stacked list of strings. It is * an internal call, so it is not validated. The caller is responsible for * knowing what they are doing. */ -static void -unloadNestedArglist( tArgList* pAL ) +LOCAL void +unload_arg_list(tArgList* pAL) { int ct = pAL->useCt; tCC** ppNV = pAL->apzArgs; @@ -558,14 +541,13 @@ unloadNestedArglist( tArgList* pAL ) while (ct-- > 0) { tOptionValue* pNV = (tOptionValue*)(void*)*(ppNV++); if (pNV->valType == OPARG_TYPE_HIERARCHY) - unloadNestedArglist( pNV->v.nestVal ); - AGFREE( pNV ); + unload_arg_list(pNV->v.nestVal); + AGFREE(pNV); } - AGFREE( (void*)pAL ); + AGFREE((void*)pAL); } - /*=export_func optionUnloadNested * * what: Deallocate the memory for a nested value @@ -577,7 +559,7 @@ unloadNestedArglist( tArgList* pAL ) * @pxref{libopts-configFileLoad}). =*/ void -optionUnloadNested( tOptionValue const * pOV ) +optionUnloadNested(tOptionValue const * pOV) { if (pOV == NULL) return; if (pOV->valType != OPARG_TYPE_HIERARCHY) { @@ -585,20 +567,18 @@ optionUnloadNested( tOptionValue const * pOV ) return; } - unloadNestedArglist( pOV->v.nestVal ); + unload_arg_list(pOV->v.nestVal); - AGFREE( (void*)pOV ); + AGFREE((void*)pOV); } - -/* sortNestedList - * +/** * This is a _stable_ sort. The entries are sorted alphabetically, * but within entries of the same name the ordering is unchanged. * Typically, we also hope the input is sorted. */ static void -sortNestedList( tArgList* pAL ) +sort_list(tArgList* pAL) { int ix; int lm = pAL->useCt; @@ -616,7 +596,7 @@ sortNestedList( tArgList* pAL ) * move the old pointer. Stop before trying to extract the * "-1" entry. */ - while (strcmp( pOldNV->pzName, pNewNV->pzName ) > 0) { + while (strcmp(pOldNV->pzName, pNewNV->pzName) > 0) { pAL->apzArgs[iy+1] = (void*)pOldNV; pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[--iy]); if (iy < 0) @@ -631,7 +611,6 @@ sortNestedList( tArgList* pAL ) } } - /* optionLoadNested * private: * @@ -652,7 +631,6 @@ LOCAL tOptionValue* optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen) { tOptionValue* pRes; - tArgList* pAL; /* * Make sure we have some data and we have space to put what we find. @@ -666,56 +644,60 @@ optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen) errno = ENOENT; return NULL; } - pRes = AGALOC( sizeof(*pRes) + nameLen + 1, "nested args" ); + pRes = AGALOC(sizeof(*pRes) + nameLen + 1, "nested args"); if (pRes == NULL) { errno = ENOMEM; return NULL; } pRes->valType = OPARG_TYPE_HIERARCHY; pRes->pzName = (char*)(pRes + 1); - memcpy( pRes->pzName, pzName, nameLen ); - pRes->pzName[ nameLen ] = NUL; + memcpy(pRes->pzName, pzName, nameLen); + pRes->pzName[nameLen] = NUL; - pAL = AGALOC( sizeof(*pAL), "nested arg list" ); - if (pAL == NULL) { - AGFREE( pRes ); - return NULL; + { + tArgList * pAL = AGALOC(sizeof(*pAL), "nested arg list"); + if (pAL == NULL) { + AGFREE(pRes); + return NULL; + } + + pRes->v.nestVal = pAL; + pAL->useCt = 0; + pAL->allocCt = MIN_ARG_ALLOC_CT; } - pRes->v.nestVal = pAL; - pAL->useCt = 0; - pAL->allocCt = MIN_ARG_ALLOC_CT; /* * Scan until we hit a NUL. */ do { - while (IS_WHITESPACE_CHAR( (int)*pzTxt )) pzTxt++; - if (IS_VAR_FIRST_CHAR( (int)*pzTxt )) { - pzTxt = scanNameEntry( pzTxt, pRes ); + while (IS_WHITESPACE_CHAR((int)*pzTxt)) pzTxt++; + if (IS_VAR_FIRST_CHAR((int)*pzTxt)) { + pzTxt = scan_name(pzTxt, pRes); } else switch (*pzTxt) { case NUL: goto scan_done; - case '<': pzTxt = scanXmlEntry( pzTxt, pRes ); + case '<': pzTxt = scan_xml(pzTxt, pRes); if (pzTxt == NULL) goto woops; if (*pzTxt == ',') pzTxt++; break; - case '#': pzTxt = strchr( pzTxt, '\n' ); break; + case '#': pzTxt = strchr(pzTxt, '\n'); break; default: goto woops; } } while (pzTxt != NULL); scan_done:; - pAL = pRes->v.nestVal; - if (pAL->useCt != 0) { - sortNestedList( pAL ); - return pRes; + { + tArgList * al = pRes->v.nestVal; + if (al->useCt != 0) + sort_list(al); } + return pRes; + woops: - AGFREE( pRes->v.nestVal ); - AGFREE( pRes ); + AGFREE(pRes->v.nestVal); + AGFREE(pRes); return NULL; } - /*=export_func optionNestedVal * private: * @@ -754,11 +736,10 @@ optionNestedVal(tOptions* pOpts, tOptDesc* pOD) pOD->optArg.argString, pOD->pz_Name, strlen(pOD->pz_Name)); if (pOV != NULL) - addArgListEntry( &(pOD->optCookie), (void*)pOV ); + addArgListEntry(&(pOD->optCookie), (void*)pOV); } } - /* * get_special_char */ @@ -811,7 +792,6 @@ get_special_char(char const ** ppz, int * ct) return '&'; } - /* * emit_special_char */ diff --git a/sntp/libopts/numeric.c b/sntp/libopts/numeric.c index 1596f4782..f2d5ddc46 100644 --- a/sntp/libopts/numeric.c +++ b/sntp/libopts/numeric.c @@ -1,11 +1,12 @@ -/* - * $Id: 52d772d69bed7f2911d88ff17b9a44308d6ca0b1 $ - * Time-stamp: "2009-07-23 17:25:39 bkorb" +/** + * \file numeric.c + * + * Time-stamp: "2010-07-10 10:57:10 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control diff --git a/sntp/libopts/parse-duration.c b/sntp/libopts/parse-duration.c index 6487ba05e..35891d03c 100644 --- a/sntp/libopts/parse-duration.c +++ b/sntp/libopts/parse-duration.c @@ -1,5 +1,5 @@ /* Parse a time duration and return a seconds count - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2010 Free Software Foundation, Inc. Written by Bruce Korb , 2008. This program is free software: you can redistribute it and/or modify @@ -579,4 +579,4 @@ parse_duration (char const * pz) * c-file-style: "gnu" * indent-tabs-mode: nil * End: - * end of parse-duration.c */ + * end of autoopts/parse-duration.c */ diff --git a/sntp/libopts/parse-duration.h b/sntp/libopts/parse-duration.h index 7ecc7dbe0..9dfbbbd72 100644 --- a/sntp/libopts/parse-duration.h +++ b/sntp/libopts/parse-duration.h @@ -1,5 +1,5 @@ /* Parse a time duration and return a seconds count - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2010 Free Software Foundation, Inc. Written by Bruce Korb , 2008. This program is free software: you can redistribute it and/or modify @@ -80,3 +80,11 @@ extern time_t parse_duration(char const * in_pz); #endif /* GNULIB_PARSE_DURATION_H */ + +/* + * Local Variables: + * mode: C + * c-file-style: "gnu" + * indent-tabs-mode: nil + * End: + * end of autoopts/parse-duration.h */ diff --git a/sntp/libopts/pgusage.c b/sntp/libopts/pgusage.c index 8ce9a9650..6fa7bee45 100644 --- a/sntp/libopts/pgusage.c +++ b/sntp/libopts/pgusage.c @@ -1,7 +1,8 @@ -/* - * $Id: da09fc943da953195b243b7697fdbf5127f5b6c2 $ - * Time-stamp: "2009-11-01 11:52:51 bkorb" +/** + * \file pgusage.c + * + * Time-stamp: "2010-07-17 10:42:53 bkorb" * * Automated Options Paged Usage module. * @@ -10,7 +11,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -44,13 +45,13 @@ tePagerState pagerState = PAGER_STATE_INITIAL; * This is disabled on platforms without a working fork() function. =*/ void -optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) +optionPagedUsage(tOptions* pOptions, tOptDesc* pOD) { #if ! defined(HAVE_WORKING_FORK) if ((pOD->fOptState & OPTST_RESET) != 0) return; - (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS ); + (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS); #else static pid_t my_pid; char zPageUsage[ 1024 ]; @@ -70,38 +71,38 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) #ifdef HAVE_SNPRINTF snprintf(zPageUsage, sizeof(zPageUsage), "/tmp/use.%lu", (tAoUL)my_pid); #else - sprintf( zPageUsage, "/tmp/use.%lu", (tAoUL)my_pid ); + sprintf(zPageUsage, "/tmp/use.%lu", (tAoUL)my_pid); #endif - unlink( zPageUsage ); + unlink(zPageUsage); /* * Set usage output to this temporary file */ - option_usage_fp = fopen( zPageUsage, "w" FOPEN_BINARY_FLAG ); + option_usage_fp = fopen(zPageUsage, "w" FOPEN_BINARY_FLAG); if (option_usage_fp == NULL) - _exit( EXIT_FAILURE ); + _exit(EXIT_FAILURE); pagerState = PAGER_STATE_READY; /* * Set up so this routine gets called during the exit logic */ - atexit( (void(*)(void))optionPagedUsage ); + atexit((void(*)(void))optionPagedUsage); /* * The usage procedure will now put the usage information into * the temporary file we created above. */ - (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS ); + (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS); /* NOTREACHED */ - _exit( EXIT_FAILURE ); + _exit(EXIT_FAILURE); } case PAGER_STATE_READY: { tSCC zPage[] = "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu"; - tCC* pzPager = (tCC*)getenv( "PAGER" ); + tCC* pzPager = (tCC*)getenv("PAGER"); /* * Use the "more(1)" program if "PAGER" has not been defined @@ -115,12 +116,12 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) #ifdef HAVE_SNPRINTF snprintf(zPageUsage, sizeof(zPageUsage), zPage, pzPager, (tAoUL)my_pid); #else - sprintf( zPageUsage, zPage, pzPager, (tAoUL)my_pid ); + sprintf(zPageUsage, zPage, pzPager, (tAoUL)my_pid); #endif - fclose( stderr ); - dup2( STDOUT_FILENO, STDERR_FILENO ); + fclose(stderr); + dup2(STDOUT_FILENO, STDERR_FILENO); - (void)system( zPageUsage ); + (void)system(zPageUsage); } case PAGER_STATE_CHILD: diff --git a/sntp/libopts/proto.h b/sntp/libopts/proto.h index 91cde020f..bc4a49f03 100644 --- a/sntp/libopts/proto.h +++ b/sntp/libopts/proto.h @@ -1,7 +1,7 @@ /* -*- buffer-read-only: t -*- vi: set ro: * * Prototypes for autoopts - * Generated Sun Nov 8 08:41:10 PST 2009 + * Generated Tue Nov 16 17:41:54 PST 2010 */ #ifndef AUTOOPTS_PROTO_H_GUARD #define AUTOOPTS_PROTO_H_GUARD 1 @@ -16,37 +16,37 @@ * Extracted from autoopts.c */ LOCAL void * -ao_malloc( size_t sz ); +ao_malloc(size_t sz); LOCAL void * -ao_realloc( void *p, size_t sz ); +ao_realloc(void *p, size_t sz); LOCAL void -ao_free( void *p ); +ao_free(void *p); LOCAL char * -ao_strdup( char const *str ); +ao_strdup(char const *str); LOCAL tSuccess -handleOption( tOptions* pOpts, tOptState* pOptState ); +handleOption(tOptions* pOpts, tOptState* pOptState); LOCAL tSuccess -longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ); +longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState); LOCAL tSuccess -shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ); +shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState); LOCAL tSuccess -doImmediateOpts( tOptions* pOpts ); +doImmediateOpts(tOptions* pOpts); LOCAL tSuccess -doRegularOpts( tOptions* pOpts ); +doRegularOpts(tOptions* pOpts); /* * Extracted from configfile.c */ LOCAL void -internalFileLoad( tOptions* pOpts ); +internalFileLoad(tOptions* pOpts); LOCAL char* parseAttributes( @@ -56,22 +56,22 @@ parseAttributes( tOptionValue* pType ); LOCAL tSuccess -validateOptionsStruct( tOptions* pOpts, char const* pzProgram ); +validateOptionsStruct(tOptions* pOpts, char const* pzProgram); /* * Extracted from environment.c */ LOCAL void -doPrognameEnv( tOptions* pOpts, teEnvPresetType type ); +doPrognameEnv(tOptions* pOpts, teEnvPresetType type); LOCAL void -doEnvPresets( tOptions* pOpts, teEnvPresetType type ); +doEnvPresets(tOptions* pOpts, teEnvPresetType type); /* * Extracted from load.c */ LOCAL void -mungeString( char* pzTxt, tOptionLoadMode mode ); +mungeString(char* pzTxt, tOptionLoadMode mode); LOCAL void loadOptionLine( @@ -84,6 +84,9 @@ loadOptionLine( /* * Extracted from nested.c */ +LOCAL void +unload_arg_list(tArgList* pAL); + LOCAL tOptionValue* optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen); @@ -97,13 +100,13 @@ emit_special_char(FILE * fp, int ch); * Extracted from sort.c */ LOCAL void -optionSort( tOptions* pOpts ); +optionSort(tOptions* pOpts); /* * Extracted from stack.c */ LOCAL void -addArgListEntry( void** ppAL, void* entry ); +addArgListEntry(void** ppAL, void* entry); #ifdef REDEF_LOCAL # undef LOCAL diff --git a/sntp/libopts/putshell.c b/sntp/libopts/putshell.c index 8cdd7a528..8f2927571 100644 --- a/sntp/libopts/putshell.c +++ b/sntp/libopts/putshell.c @@ -1,7 +1,8 @@ -/* - * $Id: 5d14243d5d32d234f05bc8a20b1a6464716b30aa $ - * Time-stamp: "2008-07-27 12:14:38 bkorb" +/** + * \file putshell.c + * + * Time-stamp: "2010-09-05 06:10:56 bkorb" * * This module will interpret the options set in the tOptions * structure and print them to standard out in a fashion that @@ -9,7 +10,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -27,11 +28,25 @@ * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ +static char const zOptValFmt[] = "%s_%s="; +static char const zOptEnd[] = "\nexport %s_%s\n"; +static char const zOptNumFmt[] = "%1$s_%2$s=%3$d # 0x%3$X\nexport %1$s_%2$s\n"; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -putQuotedStr( tCC* pzStr ); +print_quot_str(tCC* pzStr); + +static void +print_enumeration(tOptions * pOpts, tOptDesc * pOD); + +static void +print_membership(tOptions * pOpts, tOptDesc * pOD); + +static void +print_stacked_arg(tOptions * pOpts, tOptDesc * pOD); + +static void +print_reordering(tOptions * pOpts); /* = = = END-STATIC-FORWARD = = = */ /* @@ -39,13 +54,13 @@ putQuotedStr( tCC* pzStr ); * been emitted and the closing quote will be upon return. */ static void -putQuotedStr( tCC* pzStr ) +print_quot_str(tCC* pzStr) { /* * Handle empty strings to make the rest of the logic simpler. */ if ((pzStr == NULL) || (*pzStr == NUL)) { - fputs( "''", stdout ); + fputs("''", stdout); return; } @@ -54,7 +69,7 @@ putQuotedStr( tCC* pzStr ) * bail if that is all we need to do. */ while (*pzStr == '\'') { - fputs( "\\'", stdout ); + fputs("\\'", stdout); pzStr++; } if (*pzStr == NUL) @@ -63,38 +78,144 @@ putQuotedStr( tCC* pzStr ) /* * Start the single quote string */ - fputc( '\'', stdout ); + fputc('\'', stdout); for (;;) { - tCC* pz = strchr( pzStr, '\'' ); + tCC* pz = strchr(pzStr, '\''); if (pz == NULL) break; /* * Emit the string up to the single quote (apostrophe) we just found. */ - (void)fwrite( pzStr, (size_t)(pz - pzStr), (size_t)1, stdout ); - fputc( '\'', stdout ); + (void)fwrite(pzStr, (size_t)(pz - pzStr), (size_t)1, stdout); + fputc('\'', stdout); pzStr = pz; /* * Emit an escaped apostrophe for every one we find. * If that ends the string, do not re-open the single quotes. */ - while (*++pzStr == '\'') fputs( "\\'", stdout ); + while (*++pzStr == '\'') fputs("\\'", stdout); if (*pzStr == NUL) return; - fputc( '\'', stdout ); + fputc('\'', stdout); } /* * If we broke out of the loop, we must still emit the remaining text * and then close the single quote string. */ - fputs( pzStr, stdout ); - fputc( '\'', stdout ); + fputs(pzStr, stdout); + fputc('\'', stdout); +} + +static void +print_enumeration(tOptions * pOpts, tOptDesc * pOD) +{ + uintptr_t e_val = pOD->optArg.argEnum; + printf(zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME); + + /* + * Convert value to string, print that and restore numeric value. + */ + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + printf("'%s'", pOD->optArg.argString); + if (pOD->fOptState & OPTST_ALLOC_ARG) + AGFREE(pOD->optArg.argString); + pOD->optArg.argEnum = e_val; + + printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME); +} + +static void +print_membership(tOptions * pOpts, tOptDesc * pOD) +{ + char const * pz; + uintptr_t val = 1; + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (int)(uintptr_t)(pOD->optCookie)); + pOD->optCookie = (void*)(uintptr_t)~0UL; + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + + /* + * We are building the typeset list. The list returned starts with + * 'none + ' for use by option saving stuff. We must ignore that. + */ + pz = pOD->optArg.argString + 7; + while (*pz != NUL) { + printf("typeset -x -i %s_", pOD->pz_NAME); + while (IS_PLUS_N_SPACE_CHAR(*pz)) pz++; + + for (;;) { + int ch = *(pz++); + if (IS_LOWER_CASE_CHAR(ch)) fputc(toupper(ch), stdout); + else if (IS_UPPER_CASE_CHAR(ch)) fputc(ch, stdout); + else if (IS_PLUS_N_SPACE_CHAR(ch)) goto name_done; + else if (ch == NUL) { pz--; goto name_done; } + else fputc('_', stdout); + } name_done:; + printf("=%1$lu # 0x%1$lX\n", (unsigned long)val); + val <<= 1; + } + + AGFREE(pOD->optArg.argString); + pOD->optArg.argString = NULL; + pOD->fOptState &= ~OPTST_ALLOC_ARG; +} + +static void +print_stacked_arg(tOptions * pOpts, tOptDesc * pOD) +{ + tSCC zOptCookieCt[] = "%1$s_%2$s_CT=%3$d\nexport %1$s_%2$s_CT\n"; + + tArgList* pAL = (tArgList*)pOD->optCookie; + tCC** ppz = pAL->apzArgs; + int ct = pAL->useCt; + + printf(zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct); + + while (--ct >= 0) { + tSCC numarg_z[] = "%s_%s_%d="; + tSCC end_z[] = "\nexport %s_%s_%d\n"; + + printf(numarg_z, pOpts->pzPROGNAME, pOD->pz_NAME, + pAL->useCt - ct); + print_quot_str(*(ppz++)); + printf(end_z, pOpts->pzPROGNAME, pOD->pz_NAME, + pAL->useCt - ct); + } } +static void +print_reordering(tOptions * pOpts) +{ + int optIx; + + fputs("set --", stdout); + + for (optIx = pOpts->curOptIdx; optIx < pOpts->origArgCt; optIx++) { + + char* pzArg = pOpts->origArgVect[ optIx ]; + + if (strchr(pzArg, '\'') == NULL) + printf(" '%s'", pzArg); + + else { + fputs(" '", stdout); + for (;;) { + char ch = *(pzArg++); + switch (ch) { + case '\'': fputs("'\\''", stdout); break; + case NUL: goto arg_done; + default: fputc(ch, stdout); break; + } + } arg_done:; + fputc('\'', stdout); + } + } + fputs("\nOPTION_CT=0\n", stdout); +} /*=export_func optionPutShell * what: write a portable shell script to parse options @@ -104,18 +225,15 @@ putQuotedStr( tCC* pzStr ) * the options described in the option definitions. =*/ void -optionPutShell( tOptions* pOpts ) +optionPutShell(tOptions* pOpts) { int optIx = 0; tSCC zOptCtFmt[] = "OPTION_CT=%d\nexport OPTION_CT\n"; - tSCC zOptNumFmt[] = "%1$s_%2$s=%3$d # 0x%3$X\nexport %1$s_%2$s\n"; tSCC zOptDisabl[] = "%1$s_%2$s=%3$s\nexport %1$s_%2$s\n"; - tSCC zOptValFmt[] = "%s_%s="; - tSCC zOptEnd[] = "\nexport %s_%s\n"; tSCC zFullOptFmt[]= "%1$s_%2$s='%3$s'\nexport %1$s_%2$s\n"; tSCC zEquivMode[] = "%1$s_%2$s_MODE='%3$s'\nexport %1$s_%2$s_MODE\n"; - printf( zOptCtFmt, pOpts->curOptIdx-1 ); + printf(zOptCtFmt, pOpts->curOptIdx-1); do { tOptDesc* pOD = pOpts->pOptDesc + optIx; @@ -143,7 +261,7 @@ optionPutShell( tOptions* pOpts ) p->optArg = pOD->optArg; p->fOptState &= OPTST_PERSISTENT_MASK; p->fOptState |= pOD->fOptState & ~OPTST_PERSISTENT_MASK; - printf( zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME ); + printf(zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME); pOD = p; } @@ -153,37 +271,7 @@ optionPutShell( tOptions* pOpts ) * of bitmask value and we need to emit the bit values. */ if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) { - char const * pz; - uintptr_t val = 1; - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (int)(uintptr_t)(pOD->optCookie) ); - pOD->optCookie = (void*)(uintptr_t)~0UL; - (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); - - /* - * We are building the typeset list. The list returned starts with - * 'none + ' for use by option saving stuff. We must ignore that. - */ - pz = pOD->optArg.argString + 7; - while (*pz != NUL) { - printf( "typeset -x -i %s_", pOD->pz_NAME ); - while (IS_PLUS_N_SPACE_CHAR(*pz)) pz++; - - for (;;) { - int ch = *(pz++); - if (IS_LOWER_CASE_CHAR(ch)) fputc(toupper(ch), stdout); - else if (IS_UPPER_CASE_CHAR(ch)) fputc(ch, stdout); - else if (IS_PLUS_N_SPACE_CHAR(ch)) goto name_done; - else if (ch == NUL) { pz--; goto name_done; } - else fputc( '_', stdout ); - } name_done:; - printf( "=%1$lu # 0x%1$lX\n", (unsigned long)val ); - val <<= 1; - } - - AGFREE(pOD->optArg.argString); - pOD->optArg.argString = NULL; - pOD->fOptState &= ~OPTST_ALLOC_ARG; + print_membership(pOpts, pOD); continue; } @@ -193,122 +281,86 @@ optionPutShell( tOptions* pOpts ) * The idea is that if someone defines an option to initialize * enabled, we should tell our shell script that it is enabled. */ - if (UNUSED_OPT( pOD ) && DISABLED_OPT( pOD )) + if (UNUSED_OPT(pOD) && DISABLED_OPT(pOD)) { continue; + } /* * Handle stacked arguments */ if ( (pOD->fOptState & OPTST_STACKED) && (pOD->optCookie != NULL) ) { - tSCC zOptCookieCt[] = "%1$s_%2$s_CT=%3$d\nexport %1$s_%2$s_CT\n"; - - tArgList* pAL = (tArgList*)pOD->optCookie; - tCC** ppz = pAL->apzArgs; - int ct = pAL->useCt; - - printf( zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct ); - - while (--ct >= 0) { - tSCC numarg_z[] = "%s_%s_%d="; - tSCC end_z[] = "\nexport %s_%s_%d\n"; - - printf( numarg_z, pOpts->pzPROGNAME, pOD->pz_NAME, - pAL->useCt - ct ); - putQuotedStr( *(ppz++) ); - printf( end_z, pOpts->pzPROGNAME, pOD->pz_NAME, - pAL->useCt - ct ); - } + print_stacked_arg(pOpts, pOD); + continue; } /* * If the argument has been disabled, * Then set its value to the disablement string */ - else if ((pOD->fOptState & OPTST_DISABLED) != 0) - printf( zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME, - (pOD->pz_DisablePfx != NULL) - ? pOD->pz_DisablePfx : "false" ); + if ((pOD->fOptState & OPTST_DISABLED) != 0) { + printf(zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME, + (pOD->pz_DisablePfx != NULL) + ? pOD->pz_DisablePfx : "false"); + continue; + } /* * If the argument type is numeric, the last arg pointer * is really the VALUE of the string that was pointed to. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (int)pOD->optArg.argInt ); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) { + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (int)pOD->optArg.argInt); + continue; + } /* * If the argument type is an enumeration, then it is much * like a text value, except we call the callback function * to emit the value corresponding to the "optArg" number. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) { - uintptr_t e_val = pOD->optArg.argEnum; - printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME ); - - /* - * Convert value to string, print that and restore numeric value. - */ - (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); - printf("'%s'", pOD->optArg.argString); - if (pOD->fOptState & OPTST_ALLOC_ARG) - AGFREE(pOD->optArg.argString); - pOD->optArg.argEnum = e_val; - - printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) { + print_enumeration(pOpts, pOD); + continue; } /* * If the argument type is numeric, the last arg pointer * is really the VALUE of the string that was pointed to. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN) - printf( zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (pOD->optArg.argBool == 0) ? "false" : "true" ); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN) { + printf(zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (pOD->optArg.argBool == 0) ? "false" : "true"); + continue; + } /* * IF the option has an empty value, * THEN we set the argument to the occurrence count. */ - else if ( (pOD->optArg.argString == NULL) - || (pOD->optArg.argString[0] == NUL) ) + if ( (pOD->optArg.argString == NULL) + || (pOD->optArg.argString[0] == NUL) ) { - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - pOD->optOccCt ); + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + pOD->optOccCt); + continue; + } /* * This option has a text value */ - else { - printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME ); - putQuotedStr( pOD->optArg.argString ); - printf( zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME ); - } + printf(zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME); + print_quot_str(pOD->optArg.argString); + printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME); + } while (++optIx < pOpts->presetOptCt ); if ( ((pOpts->fOptSet & OPTPROC_REORDER) != 0) - && (pOpts->curOptIdx < pOpts->origArgCt)) { - fputs( "set --", stdout ); - for (optIx = pOpts->curOptIdx; optIx < pOpts->origArgCt; optIx++) { - char* pzArg = pOpts->origArgVect[ optIx ]; - if (strchr( pzArg, '\'' ) == NULL) - printf( " '%s'", pzArg ); - else { - fputs( " '", stdout ); - for (;;) { - char ch = *(pzArg++); - switch (ch) { - case '\'': fputs( "'\\''", stdout ); break; - case NUL: goto arg_done; - default: fputc( ch, stdout ); break; - } - } arg_done:; - fputc( '\'', stdout ); - } - } - fputs( "\nOPTION_CT=0\n", stdout ); - } + && (pOpts->curOptIdx < pOpts->origArgCt)) + print_reordering(pOpts); + + fflush(stdout); } /* diff --git a/sntp/libopts/reset.c b/sntp/libopts/reset.c index 47a2ec0cf..efc48db35 100644 --- a/sntp/libopts/reset.c +++ b/sntp/libopts/reset.c @@ -1,11 +1,12 @@ -/* - * $Id: 808e536555f06924b450ab6b5a72c03b67c5b99a $ - * Time-stamp: "2009-11-01 11:45:57 bkorb" +/** + * \file reset.c + * + * Time-stamp: "2010-07-10 10:56:34 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control diff --git a/sntp/libopts/restore.c b/sntp/libopts/restore.c index 40a9bc0d1..f8d4c1dce 100644 --- a/sntp/libopts/restore.c +++ b/sntp/libopts/restore.c @@ -1,7 +1,8 @@ /* - * restore.c $Id: 6f5237ba2586755d8ca354f325fc00e7fa1395ec $ - * Time-stamp: "2007-07-04 11:34:40 bkorb" + * \file restore.c + * + * Time-stamp: "2010-08-22 11:04:00 bkorb" * * This module's routines will save the current option state to memory * and restore it. If saved prior to the initial optionProcess call, @@ -9,7 +10,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -96,8 +97,8 @@ optionSaveState(tOptions* pOpts) tOptions* p = (tOptions*)pOpts->pSavedState; if (p == NULL) { - size_t sz = sizeof( *pOpts ) + (pOpts->optCt * sizeof( tOptDesc )); - p = AGALOC( sz, "saved option state" ); + size_t sz = sizeof(*pOpts) + (pOpts->optCt * sizeof(tOptDesc)); + p = AGALOC(sz, "saved option state"); if (p == NULL) { tCC* pzName = pOpts->pzProgName; if (pzName == NULL) { @@ -105,15 +106,15 @@ optionSaveState(tOptions* pOpts) if (pzName == NULL) pzName = zNil; } - fprintf( stderr, zCantSave, pzName, sz ); - exit( EXIT_FAILURE ); + fprintf(stderr, zCantSave, pzName, sz); + exit(EXIT_FAILURE); } pOpts->pSavedState = p; } - memcpy( p, pOpts, sizeof( *p )); - memcpy( p + 1, pOpts->pOptDesc, p->optCt * sizeof( tOptDesc )); + memcpy(p, pOpts, sizeof(*p)); + memcpy(p + 1, pOpts->pOptDesc, p->optCt * sizeof(tOptDesc)); fixupSavedOptionArgs(pOpts); } @@ -135,7 +136,7 @@ optionSaveState(tOptions* pOpts) * printed to @code{stderr} and exit is called. =*/ void -optionRestore( tOptions* pOpts ) +optionRestore(tOptions* pOpts) { tOptions* p = (tOptions*)pOpts->pSavedState; @@ -146,15 +147,15 @@ optionRestore( tOptions* pOpts ) if (pzName == NULL) pzName = zNil; } - fprintf( stderr, zNoState, pzName ); - exit( EXIT_FAILURE ); + fprintf(stderr, zNoState, pzName); + exit(EXIT_FAILURE); } pOpts->pSavedState = NULL; optionFree(pOpts); - memcpy( pOpts, p, sizeof( *p )); - memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc )); + memcpy(pOpts, p, sizeof(*p)); + memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc)); pOpts->pSavedState = p; fixupSavedOptionArgs(pOpts); @@ -174,7 +175,7 @@ optionRestore( tOptions* pOpts ) * this routine is always successful. =*/ void -optionFree( tOptions* pOpts ) +optionFree(tOptions* pOpts) { free_saved_state: { @@ -202,7 +203,7 @@ optionFree( tOptions* pOpts ) case OPARG_TYPE_HIERARCHY: if (p->optCookie != NULL) - unloadNestedArglist(p->optCookie); + unload_arg_list(p->optCookie); break; } @@ -211,9 +212,9 @@ optionFree( tOptions* pOpts ) } if (pOpts->pSavedState != NULL) { tOptions * p = (tOptions*)pOpts->pSavedState; - memcpy( pOpts, p, sizeof( *p )); - memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc )); - AGFREE( pOpts->pSavedState ); + memcpy(pOpts, p, sizeof(*p)); + memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc)); + AGFREE(pOpts->pSavedState); pOpts->pSavedState = NULL; goto free_saved_state; } diff --git a/sntp/libopts/save.c b/sntp/libopts/save.c index 5ea2c5632..42abefe99 100644 --- a/sntp/libopts/save.c +++ b/sntp/libopts/save.c @@ -1,7 +1,8 @@ /* - * save.c $Id: 5a69234fab4c2d8d7eaf4aed4dbb3052ce6be5b6 $ - * Time-stamp: "2009-07-20 20:40:28 bkorb" + * \file save.c + * + * Time-stamp: "2010-07-17 10:27:48 bkorb" * * This module's routines will take the currently set options and * store them into an ".rc" file for re-interpretation the next @@ -9,7 +10,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -32,12 +33,11 @@ static char const zWarn[] = "%s WARNING: cannot save options - "; static char const close_xml[] = "\n"; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static tCC* -findDirName( tOptions* pOpts, int* p_free ); +findDirName(tOptions* pOpts, int* p_free); static tCC* -findFileName( tOptions* pOpts, int* p_free_name ); +findFileName(tOptions* pOpts, int* p_free_name); static void printEntry( @@ -58,7 +58,7 @@ static void printHierarchy(FILE * fp, tOptDesc * p); static FILE * -openSaveFile( tOptions* pOpts ); +openSaveFile(tOptions* pOpts); static void printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD); @@ -77,7 +77,7 @@ printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts); /* = = = END-STATIC-FORWARD = = = */ static tCC* -findDirName( tOptions* pOpts, int* p_free ) +findDirName(tOptions* pOpts, int* p_free) { tCC* pzDir; @@ -109,7 +109,7 @@ findDirName( tOptions* pOpts, int* p_free ) return pzDir; { - tCC* pzEndDir = strchr( ++pzDir, DIRCH ); + tCC* pzEndDir = strchr(++pzDir, DIRCH); char* pzFileName; char* pzEnv; @@ -117,21 +117,21 @@ findDirName( tOptions* pOpts, int* p_free ) char z[ AO_NAME_SIZE ]; if ((pzEndDir - pzDir) > AO_NAME_LIMIT ) return NULL; - strncpy( z, pzDir, (size_t)(pzEndDir - pzDir) ); + strncpy(z, pzDir, (size_t)(pzEndDir - pzDir)); z[ (pzEndDir - pzDir) ] = NUL; - pzEnv = getenv( z ); + pzEnv = getenv(z); } else { /* * Make sure we can get the env value (after stripping off * any trailing directory or file names) */ - pzEnv = getenv( pzDir ); + pzEnv = getenv(pzDir); } if (pzEnv == NULL) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNotDef, pzDir ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNotDef, pzDir); return NULL; } @@ -139,8 +139,8 @@ findDirName( tOptions* pOpts, int* p_free ) return pzEnv; { - size_t sz = strlen( pzEnv ) + strlen( pzEndDir ) + 2; - pzFileName = (char*)AGALOC( sz, "dir name" ); + size_t sz = strlen(pzEnv) + strlen(pzEndDir) + 2; + pzFileName = (char*)AGALOC(sz, "dir name"); } if (pzFileName == NULL) @@ -151,20 +151,20 @@ findDirName( tOptions* pOpts, int* p_free ) * Glue together the full name into the allocated memory. * FIXME: We lose track of this memory. */ - sprintf( pzFileName, "%s/%s", pzEnv, pzEndDir ); + sprintf(pzFileName, "%s/%s", pzEnv, pzEndDir); return pzFileName; } } static tCC* -findFileName( tOptions* pOpts, int* p_free_name ) +findFileName(tOptions* pOpts, int* p_free_name) { tCC* pzDir; struct stat stBuf; int free_dir_name = 0; - pzDir = findDirName( pOpts, &free_dir_name ); + pzDir = findDirName(pOpts, &free_dir_name); if (pzDir == NULL) return NULL; @@ -172,7 +172,7 @@ findFileName( tOptions* pOpts, int* p_free_name ) * See if we can find the specified directory. We use a once-only loop * structure so we can bail out early. */ - if (stat( pzDir, &stBuf ) != 0) do { + if (stat(pzDir, &stBuf) != 0) do { /* * IF we could not, check to see if we got a full @@ -185,17 +185,17 @@ findFileName( tOptions* pOpts, int* p_free_name ) * Strip off the last component, stat the remaining string and * that string must name a directory */ - char* pzDirCh = strrchr( pzDir, DIRCH ); + char* pzDirCh = strrchr(pzDir, DIRCH); if (pzDirCh == NULL) { stBuf.st_mode = S_IFREG; continue; /* bail out of error condition */ } - strncpy( z, pzDir, (size_t)(pzDirCh - pzDir)); + strncpy(z, pzDir, (size_t)(pzDirCh - pzDir)); z[ pzDirCh - pzDir ] = NUL; - if ( (stat( z, &stBuf ) == 0) - && S_ISDIR( stBuf.st_mode )) { + if ( (stat(z, &stBuf) == 0) + && S_ISDIR(stBuf.st_mode)) { /* * We found the directory. Restore the file name and @@ -209,10 +209,10 @@ findFileName( tOptions* pOpts, int* p_free_name ) /* * We got a bogus name. */ - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoStat, errno, strerror( errno ), pzDir ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoStat, errno, strerror(errno), pzDir); if (free_dir_name) - AGFREE( (void*)pzDir ); + AGFREE((void*)pzDir); return NULL; } while (0); @@ -220,18 +220,18 @@ findFileName( tOptions* pOpts, int* p_free_name ) * IF what we found was a directory, * THEN tack on the config file name */ - if (S_ISDIR( stBuf.st_mode )) { - size_t sz = strlen( pzDir ) + strlen( pOpts->pzRcName ) + 2; + if (S_ISDIR(stBuf.st_mode)) { + size_t sz = strlen(pzDir) + strlen(pOpts->pzRcName) + 2; { - char* pzPath = (char*)AGALOC( sz, "file name" ); + char* pzPath = (char*)AGALOC(sz, "file name"); #ifdef HAVE_SNPRINTF - snprintf( pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName ); + snprintf(pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName); #else - sprintf( pzPath, "%s/%s", pzDir, pOpts->pzRcName ); + sprintf(pzPath, "%s/%s", pzDir, pOpts->pzRcName); #endif if (free_dir_name) - AGFREE( (void*)pzDir ); + AGFREE((void*)pzDir); pzDir = pzPath; free_dir_name = 1; } @@ -240,12 +240,12 @@ findFileName( tOptions* pOpts, int* p_free_name ) * IF we cannot stat the object for any reason other than * it does not exist, then we bail out */ - if (stat( pzDir, &stBuf ) != 0) { + if (stat(pzDir, &stBuf) != 0) { if (errno != ENOENT) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoStat, errno, strerror( errno ), - pzDir ); - AGFREE( (void*)pzDir ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoStat, errno, strerror(errno), + pzDir); + AGFREE((void*)pzDir); return NULL; } @@ -260,18 +260,18 @@ findFileName( tOptions* pOpts, int* p_free_name ) * Make sure that whatever we ultimately found, that it either is * or will soon be a file. */ - if (! S_ISREG( stBuf.st_mode )) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNotFile, pzDir ); + if (! S_ISREG(stBuf.st_mode)) { + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNotFile, pzDir); if (free_dir_name) - AGFREE( (void*)pzDir ); + AGFREE((void*)pzDir); return NULL; } /* * Get rid of the old file */ - unlink( pzDir ); + unlink(pzDir); *p_free_name = free_dir_name; return pzDir; } @@ -303,18 +303,18 @@ printEntry( * THEN the char pointer is really the number */ if (OPTST_GET_ARGTYPE(p->fOptState) == OPARG_TYPE_NUMERIC) - fprintf( fp, " %d\n", (int)(t_word)pzLA ); + fprintf(fp, " %d\n", (int)(t_word)pzLA); /* * OTHERWISE, FOR each line of the value text, ... */ else if (pzLA == NULL) - fputc( '\n', fp ); + fputc('\n', fp); else { - fputc( ' ', fp ); fputc( ' ', fp ); + fputc(' ', fp); fputc(' ', fp); for (;;) { - tCC* pzNl = strchr( pzLA, '\n' ); + tCC* pzNl = strchr(pzLA, '\n'); /* * IF this is the last line @@ -326,16 +326,16 @@ printEntry( /* * Print the continuation and the text from the current line */ - (void)fwrite( pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp ); + (void)fwrite(pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp); pzLA = pzNl+1; /* advance the Last Arg pointer */ - fputs( "\\\n", fp ); + fputs("\\\n", fp); } /* * Terminate the entry */ - fputs( pzLA, fp ); - fputc( '\n', fp ); + fputs(pzLA, fp); + fputc('\n', fp); } } @@ -383,7 +383,7 @@ print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp) /* * set membership strings get allocated */ - AGFREE( (void*)pOD->optArg.argString ); + AGFREE((void*)pOD->optArg.argString); } } @@ -519,47 +519,47 @@ printHierarchy(FILE * fp, tOptDesc * p) static FILE * -openSaveFile( tOptions* pOpts ) +openSaveFile(tOptions* pOpts) { FILE* fp; { int free_name = 0; - tCC* pzFName = findFileName( pOpts, &free_name ); + tCC* pzFName = findFileName(pOpts, &free_name); if (pzFName == NULL) return NULL; - fp = fopen( pzFName, "w" FOPEN_BINARY_FLAG ); + fp = fopen(pzFName, "w" FOPEN_BINARY_FLAG); if (fp == NULL) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoCreat, errno, strerror( errno ), pzFName ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoCreat, errno, strerror(errno), pzFName); if (free_name) AGFREE((void*) pzFName ); return fp; } if (free_name) - AGFREE( (void*)pzFName ); + AGFREE((void*)pzFName); } { char const* pz = pOpts->pzUsageTitle; - fputs( "# ", fp ); - do { fputc( *pz, fp ); } while (*(pz++) != '\n'); + fputs("# ", fp); + do { fputc(*pz, fp); } while (*(pz++) != '\n'); } { - time_t timeVal = time( NULL ); - char* pzTime = ctime( &timeVal ); + time_t timeVal = time(NULL); + char* pzTime = ctime(&timeVal); - fprintf( fp, zPresetFile, pzTime ); + fprintf(fp, zPresetFile, pzTime); #ifdef HAVE_ALLOCATED_CTIME /* * The return values for ctime(), localtime(), and gmtime() * normally point to static data that is overwritten by each call. * The test to detect allocated ctime, so we leak the memory. */ - AGFREE( (void*)pzTime ); + AGFREE((void*)pzTime); #endif } @@ -575,7 +575,7 @@ printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD) * string, so we get that there, not with "p". */ char const * pznm = - (DISABLED_OPT( p )) ? pOD->pz_DisableName : pOD->pz_Name; + (DISABLED_OPT(p)) ? pOD->pz_DisableName : pOD->pz_Name; /* * If the option was disabled and the disablement name is NULL, * then the disablement was caused by aliasing. @@ -602,9 +602,9 @@ printStringArg(FILE * fp, tOptDesc * pOD) pOD->fOptState &= ~OPTST_DISABLED; while (uct-- > 0) - printEntry( fp, pOD, *(ppz++) ); + printEntry(fp, pOD, *(ppz++)); } else { - printEntry( fp, pOD, pOD->optArg.argString ); + printEntry(fp, pOD, pOD->optArg.argString); } } @@ -618,7 +618,7 @@ printEnumArg(FILE * fp, tOptDesc * pOD) * bit flag values back into a string suitable for printing. */ (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); - printEntry( fp, pOD, (void*)(pOD->optArg.argString)); + printEntry(fp, pOD, (void*)(pOD->optArg.argString)); pOD->optArg.argEnum = val; } @@ -633,13 +633,13 @@ printSetMemberArg(FILE * fp, tOptDesc * pOD) * bit flag values back into a string suitable for printing. */ (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); - printEntry( fp, pOD, (void*)(pOD->optArg.argString)); + printEntry(fp, pOD, (void*)(pOD->optArg.argString)); if (pOD->optArg.argString != NULL) { /* * set membership strings get allocated */ - AGFREE( (void*)pOD->optArg.argString ); + AGFREE((void*)pOD->optArg.argString); pOD->fOptState &= ~OPTST_ALLOC_ARG; } @@ -681,7 +681,7 @@ printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts) * option, or by appending the @code{rcfile} attribute to the last * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it * will default to @code{.@i{programname}rc}. If you wish to specify another - * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro. + * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro. * * The recommend usage is as follows: * @example @@ -698,7 +698,7 @@ printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts) * will be printed to @code{stderr} and the routine will return. =*/ void -optionSaveFile( tOptions* pOpts ) +optionSaveFile(tOptions* pOpts) { tOptDesc* pOD; int ct; @@ -724,7 +724,7 @@ optionSaveFile( tOptions* pOpts ) * Equivalenced options get picked up when the equivalenced-to * option is processed. */ - if (UNUSED_OPT( pOD )) + if (UNUSED_OPT(pOD)) continue; if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0) @@ -748,7 +748,7 @@ optionSaveFile( tOptions* pOpts ) break; case OPARG_TYPE_NUMERIC: - printEntry( fp, p, (void*)(p->optArg.argInt)); + printEntry(fp, p, (void*)(p->optArg.argInt)); break; case OPARG_TYPE_STRING: @@ -764,7 +764,7 @@ optionSaveFile( tOptions* pOpts ) break; case OPARG_TYPE_BOOLEAN: - printEntry( fp, p, p->optArg.argBool ? "true" : "false" ); + printEntry(fp, p, p->optArg.argBool ? "true" : "false"); break; case OPARG_TYPE_HIERARCHY: @@ -778,9 +778,9 @@ optionSaveFile( tOptions* pOpts ) default: break; /* cannot handle - skip it */ } - } while ( (pOD++), (--ct > 0)); + } while (pOD++, (--ct > 0)); - fclose( fp ); + fclose(fp); } /* * Local Variables: diff --git a/sntp/libopts/sort.c b/sntp/libopts/sort.c index 4d81a6186..c1c64015f 100644 --- a/sntp/libopts/sort.c +++ b/sntp/libopts/sort.c @@ -1,13 +1,14 @@ /* - * sort.c $Id: aac1bf81481f4bb149a72129fbd11fe54db7fa35 $ - * Time-stamp: "2007-07-04 11:34:52 bkorb" + * \file sort.c + * + * Time-stamp: "2010-07-17 10:34:15 bkorb" * * This module implements argument sorting. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -27,18 +28,17 @@ */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static tSuccess -mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); static tSuccess -mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); static tSuccess -checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); /* = = = END-STATIC-FORWARD = = = */ /* @@ -47,8 +47,8 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, * does not start with a hyphen and "must" will consume it, hyphen or not. */ static tSuccess -mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { /* * An option argument is required. Long options can either have @@ -85,8 +85,8 @@ mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, } static tSuccess -mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { /* * An option argument is optional. @@ -128,11 +128,11 @@ mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, * does or may take an argument, the do the argument processing and leave. */ static tSuccess -checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { while (*pzArg != NUL) { - if (FAILED( shortOptionFind( pOpts, (tAoUC)*pzArg, pOS ))) + if (FAILED(shortOptionFind(pOpts, (tAoUC)*pzArg, pOS))) return FAILURE; /* @@ -177,7 +177,7 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, * then this routine will to the trick. */ LOCAL void -optionSort( tOptions* pOpts ) +optionSort(tOptions* pOpts) { char** ppzOpts; char** ppzOpds; @@ -189,20 +189,20 @@ optionSort( tOptions* pOpts ) /* * Disable for POSIX conformance, or if there are no operands. */ - if ( (getenv( "POSIXLY_CORRECT" ) != NULL) + if ( (getenv("POSIXLY_CORRECT") != NULL) || NAMED_OPTS(pOpts)) return; /* * Make sure we can allocate two full-sized arg vectors. */ - ppzOpts = malloc( pOpts->origArgCt * sizeof( char* )); + ppzOpts = malloc(pOpts->origArgCt * sizeof(char*)); if (ppzOpts == NULL) goto exit_no_mem; - ppzOpds = malloc( pOpts->origArgCt * sizeof( char* )); + ppzOpds = malloc(pOpts->origArgCt * sizeof(char*)); if (ppzOpds == NULL) { - free( ppzOpts ); + free(ppzOpts); goto exit_no_mem; } @@ -251,7 +251,7 @@ optionSort( tOptions* pOpts ) pOpts->origArgVect[ (pOpts->curOptIdx)++ ]; goto restOperands; } - res = longOptionFind( pOpts, pzArg+2, &os ); + res = longOptionFind(pOpts, pzArg+2, &os); break; default: @@ -261,13 +261,13 @@ optionSort( tOptions* pOpts ) * short (i.e. single character) option. */ if ((pOpts->fOptSet & OPTPROC_SHORTOPT) == 0) { - res = longOptionFind( pOpts, pzArg+1, &os ); + res = longOptionFind(pOpts, pzArg+1, &os); } else { - res = shortOptionFind( pOpts, (tAoUC)pzArg[1], &os ); + res = shortOptionFind(pOpts, (tAoUC)pzArg[1], &os); } break; } - if (FAILED( res )) { + if (FAILED(res)) { errno = EINVAL; goto freeTemps; } @@ -286,20 +286,20 @@ optionSort( tOptions* pOpts ) * of the argument string. */ if ( (os.optType == TOPT_SHORT) - && FAILED( checkShortOpts( pOpts, pzArg+2, &os, - ppzOpts, &optsIdx )) ) { + && FAILED(checkShortOpts(pOpts, pzArg+2, &os, ppzOpts, + &optsIdx)) ) { errno = EINVAL; goto freeTemps; } } else if (os.pOD->fOptState & OPTST_ARG_OPTIONAL) { - switch (mayHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) { + switch (mayHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) { case FAILURE: errno = EIO; goto freeTemps; case PROBLEM: errno = 0; goto joinLists; } } else { - switch (mustHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) { + switch (mustHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) { case PROBLEM: case FAILURE: errno = EIO; goto freeTemps; } @@ -312,14 +312,14 @@ optionSort( tOptions* pOpts ) joinLists: if (optsIdx > 0) - memcpy( pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof( char* )); + memcpy(pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof(char*)); if (opdsIdx > 0) - memcpy( pOpts->origArgVect + 1 + optsIdx, - ppzOpds, opdsIdx * sizeof( char* )); + memcpy(pOpts->origArgVect + 1 + optsIdx, ppzOpds, + opdsIdx * sizeof(char*)); freeTemps: - free( ppzOpts ); - free( ppzOpds ); + free(ppzOpts); + free(ppzOpds); return; exit_no_mem: diff --git a/sntp/libopts/stack.c b/sntp/libopts/stack.c index 8eb7856da..525adc670 100644 --- a/sntp/libopts/stack.c +++ b/sntp/libopts/stack.c @@ -1,15 +1,15 @@ -/* - * stack.c - * $Id: 9d4a7c1c6ae364a6134dc5ff01f58f08b52f1a16 $ - * Time-stamp: "2008-07-30 16:56:32 bkorb" +/** + * \file stack.c + * + * Time-stamp: "2010-07-17 10:42:27 bkorb" * * This is a special option processing routine that will save the * argument to an option in a FIFO queue. * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -61,7 +61,7 @@ optionUnstackArg( */ if (pAL == NULL) { pOptDesc->fOptState &= OPTST_PERSISTENT_MASK; - if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0) + if ((pOptDesc->fOptState & OPTST_INITENABLED) == 0) pOptDesc->fOptState |= OPTST_DISABLED; return; } @@ -71,7 +71,7 @@ optionUnstackArg( regex_t re; int i, ct, dIdx; - if (regcomp( &re, pOptDesc->optArg.argString, REG_NOSUB ) != 0) + if (regcomp(&re, pOptDesc->optArg.argString, REG_NOSUB) != 0) return; /* @@ -82,12 +82,12 @@ optionUnstackArg( */ for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) { tCC* pzSrc = pAL->apzArgs[ i ]; - char* pzEq = strchr( pzSrc, '=' ); + char* pzEq = strchr(pzSrc, '='); if (pzEq != NULL) *pzEq = NUL; - res = regexec( &re, pzSrc, (size_t)0, NULL, 0 ); + res = regexec(&re, pzSrc, (size_t)0, NULL, 0); switch (res) { case 0: /* @@ -114,7 +114,7 @@ optionUnstackArg( } } - regfree( &re ); + regfree(&re); } #else /* not WITH_LIBREGEX */ { @@ -128,12 +128,12 @@ optionUnstackArg( */ for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) { tCC* pzSrc = pAL->apzArgs[ i ]; - char* pzEq = strchr( pzSrc, '=' ); + char* pzEq = strchr(pzSrc, '='); if (pzEq != NULL) *pzEq = NUL; - if (strcmp( pzSrc, pOptDesc->optArg.argString ) == 0) { + if (strcmp(pzSrc, pOptDesc->optArg.argString) == 0) { /* * Remove this entry by reducing the in-use count * and *not* putting the string pointer back into @@ -162,9 +162,9 @@ optionUnstackArg( */ if (pAL->useCt == 0) { pOptDesc->fOptState &= OPTST_PERSISTENT_MASK; - if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0) + if ((pOptDesc->fOptState & OPTST_INITENABLED) == 0) pOptDesc->fOptState |= OPTST_DISABLED; - AGFREE( (void*)pAL ); + AGFREE((void*)pAL); pOptDesc->optCookie = NULL; } } @@ -176,7 +176,7 @@ optionUnstackArg( * as an opaque address. */ LOCAL void -addArgListEntry( void** ppAL, void* entry ) +addArgListEntry(void** ppAL, void* entry) { tArgList* pAL = *(void**)ppAL; @@ -185,7 +185,7 @@ addArgListEntry( void** ppAL, void* entry ) * THEN allocate one now */ if (pAL == NULL) { - pAL = (tArgList*)AGALOC( sizeof( *pAL ), "new option arg stack" ); + pAL = (tArgList*)AGALOC(sizeof(*pAL), "new option arg stack"); if (pAL == NULL) return; pAL->useCt = 0; @@ -198,7 +198,7 @@ addArgListEntry( void** ppAL, void* entry ) * THEN make it bigger */ else if (pAL->useCt >= pAL->allocCt) { - size_t sz = sizeof( *pAL ); + size_t sz = sizeof(*pAL); pAL->allocCt += INCR_ARG_ALLOC_CT; /* @@ -206,7 +206,7 @@ addArgListEntry( void** ppAL, void* entry ) * pointers. We subtract it off to find our augment size. */ sz += sizeof(char*) * (pAL->allocCt - MIN_ARG_ALLOC_CT); - pAL = (tArgList*)AGREALOC( (void*)pAL, sz, "expanded opt arg stack" ); + pAL = (tArgList*)AGREALOC((void*)pAL, sz, "expanded opt arg stack"); if (pAL == NULL) return; *ppAL = (void*)pAL; @@ -252,7 +252,7 @@ optionStackArg( return; AGDUPSTR(pz, pOD->optArg.argString, "stack arg"); - addArgListEntry( &(pOD->optCookie), (void*)pz ); + addArgListEntry(&(pOD->optCookie), (void*)pz); } } /* diff --git a/sntp/libopts/streqvcmp.c b/sntp/libopts/streqvcmp.c index 744212357..5719bdaad 100644 --- a/sntp/libopts/streqvcmp.c +++ b/sntp/libopts/streqvcmp.c @@ -1,7 +1,8 @@ -/* - * $Id: cb437d22b0c48960c9e1c23501fba6e3291fecd8 $ - * Time-stamp: "2008-12-26 10:15:46 bkorb" +/** + * \file streqvcmp.c + * + * Time-stamp: "2010-07-17 10:16:24 bkorb" * * String Equivalence Comparison * @@ -12,7 +13,7 @@ * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -97,7 +98,7 @@ static unsigned char charmap[] = { * err: none checked. Caller responsible for seg faults. =*/ int -strneqvcmp( tCC* s1, tCC* s2, int ct ) +strneqvcmp(tCC* s1, tCC* s2, int ct) { for (; ct > 0; --ct) { unsigned char u1 = (unsigned char) *s1++; @@ -136,7 +137,7 @@ strneqvcmp( tCC* s1, tCC* s2, int ct ) * err: none checked. Caller responsible for seg faults. =*/ int -streqvcmp( tCC* s1, tCC* s2 ) +streqvcmp(tCC* s1, tCC* s2) { for (;;) { unsigned char u1 = (unsigned char) *s1++; @@ -169,7 +170,7 @@ streqvcmp( tCC* s1, tCC* s2 ) * are incremented and the process repeated until @code{ct} entries have been * set. For example, * @example - * streqvmap( 'a', 'A', 26 ); + * streqvmap('a', 'A', 26); * @end example * @noindent * will alter the mapping so that all English lower case letters @@ -181,10 +182,10 @@ streqvcmp( tCC* s1, tCC* s2 ) * err: none. =*/ void -streqvmap( char From, char To, int ct ) +streqvmap(char From, char To, int ct) { if (ct == 0) { - ct = sizeof( charmap ) - 1; + ct = sizeof(charmap) - 1; do { charmap[ ct ] = ct; } while (--ct >= 0); @@ -198,7 +199,7 @@ streqvmap( char From, char To, int ct ) charmap[ chFrom ] = (unsigned)chTo; chFrom++; chTo++; - if ((chFrom >= sizeof( charmap )) || (chTo >= sizeof( charmap ))) + if ((chFrom >= sizeof(charmap)) || (chTo >= sizeof(charmap))) break; } while (--ct > 0); } @@ -221,7 +222,7 @@ streqvmap( char From, char To, int ct ) * err: none. =*/ void -strequate( char const* s ) +strequate(char const* s) { if ((s != NULL) && (*s != NUL)) { unsigned char equiv = (unsigned)*s; @@ -250,7 +251,7 @@ strequate( char const* s ) * err: none. =*/ void -strtransform( char* d, char const* s ) +strtransform(char* d, char const* s) { do { *(d++) = (char)charmap[ (unsigned)*s ]; diff --git a/sntp/libopts/text_mmap.c b/sntp/libopts/text_mmap.c index c5a99e360..57aa227fb 100644 --- a/sntp/libopts/text_mmap.c +++ b/sntp/libopts/text_mmap.c @@ -1,11 +1,11 @@ -/* - * $Id: 14e1f51d1a5a31d8395fdf1e93a07bace1c59e87 $ +/** + * \file text_mmap.c * - * Time-stamp: "2007-07-04 11:35:49 bkorb" + * Time-stamp: "2010-07-17 10:15:32 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -90,16 +90,16 @@ * #include * tmap_info_t mi; * int no_nul; - * void* data = text_mmap( "file", PROT_WRITE, MAP_PRIVATE, &mi ); + * void* data = text_mmap("file", PROT_WRITE, MAP_PRIVATE, &mi); * if (data == MAP_FAILED) return; * no_nul = (mi.txt_size == mi.txt_full_size); * << use the data >> - * text_munmap( &mi ); + * text_munmap(&mi); =*/ void* -text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) +text_mmap(char const* pzFile, int prot, int flags, tmap_info_t* pMI) { - memset( pMI, 0, sizeof(*pMI) ); + memset(pMI, 0, sizeof(*pMI)); #ifdef HAVE_MMAP pMI->txt_zero_fd = -1; #endif @@ -110,12 +110,12 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) */ { struct stat sb; - if (stat( pzFile, &sb ) != 0) { + if (stat(pzFile, &sb) != 0) { pMI->txt_errno = errno; return MAP_FAILED_PTR; } - if (! S_ISREG( sb.st_mode )) { + if (! S_ISREG(sb.st_mode)) { pMI->txt_errno = errno = EINVAL; return MAP_FAILED_PTR; } @@ -146,7 +146,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE)) o_flag |= O_EXCL; - pMI->txt_fd = open( pzFile, o_flag ); + pMI->txt_fd = open(pzFile, o_flag); } if (pMI->txt_fd == AO_INVALID_FD) { @@ -207,7 +207,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) pMI->txt_errno = errno; #elif defined(HAVE_DEV_ZERO) - pMI->txt_zero_fd = open( "/dev/zero", O_RDONLY ); + pMI->txt_zero_fd = open("/dev/zero", O_RDONLY); if (pMI->txt_zero_fd == AO_INVALID_FD) { pMI->txt_errno = errno; @@ -222,7 +222,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) return pMI->txt_data; pMI->txt_errno = errno; - close( pMI->txt_zero_fd ); + close(pMI->txt_zero_fd); pMI->txt_zero_fd = -1; } #endif @@ -231,8 +231,8 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) } { - void* p = AGALOC( pMI->txt_size+1, "file text" ); - memcpy( p, pMI->txt_data, pMI->txt_size ); + void* p = AGALOC(pMI->txt_size+1, "file text"); + memcpy(p, pMI->txt_data, pMI->txt_size); ((char*)p)[pMI->txt_size] = NUL; munmap(pMI->txt_data, pMI->txt_size ); pMI->txt_data = p; @@ -242,7 +242,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) #else /* * * * * * no HAVE_MMAP * * * * * */ - pMI->txt_data = AGALOC( pMI->txt_size+1, "file text" ); + pMI->txt_data = AGALOC(pMI->txt_size+1, "file text"); if (pMI->txt_data == NULL) { pMI->txt_errno = ENOMEM; goto fail_return; @@ -253,12 +253,12 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) char* pz = pMI->txt_data; while (sz > 0) { - ssize_t rdct = read( pMI->txt_fd, pz, sz ); + ssize_t rdct = read(pMI->txt_fd, pz, sz); if (rdct <= 0) { pMI->txt_errno = errno; - fprintf( stderr, zFSErrReadFile, - errno, strerror( errno ), pzFile ); - free( pMI->txt_data ); + fprintf(stderr, zFSErrReadFile, + errno, strerror(errno), pzFile); + free(pMI->txt_data); goto fail_return; } @@ -281,7 +281,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) fail_return: if (pMI->txt_fd >= 0) { - close( pMI->txt_fd ); + close(pMI->txt_fd); pMI->txt_fd = -1; } errno = pMI->txt_errno; @@ -310,7 +310,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) * err: Any error code issued by munmap(2) or close(2) is possible. =*/ int -text_munmap( tmap_info_t* pMI ) +text_munmap(tmap_info_t* pMI) { #ifdef HAVE_MMAP int res = 0; @@ -326,26 +326,26 @@ text_munmap( tmap_info_t* pMI ) if (lseek(pMI->txt_fd, (size_t)0, SEEK_SET) != 0) goto error_return; - res = (write( pMI->txt_fd, pMI->txt_data, pMI->txt_size ) < 0) + res = (write(pMI->txt_fd, pMI->txt_data, pMI->txt_size) < 0) ? errno : 0; } - AGFREE( pMI->txt_data ); + AGFREE(pMI->txt_data); errno = res; } else { - res = munmap( pMI->txt_data, pMI->txt_full_size ); + res = munmap(pMI->txt_data, pMI->txt_full_size); } if (res != 0) goto error_return; - res = close( pMI->txt_fd ); + res = close(pMI->txt_fd); if (res != 0) goto error_return; pMI->txt_fd = -1; errno = 0; if (pMI->txt_zero_fd != -1) { - res = close( pMI->txt_zero_fd ); + res = close(pMI->txt_zero_fd); pMI->txt_zero_fd = -1; } @@ -361,14 +361,14 @@ text_munmap( tmap_info_t* pMI ) * THEN rewrite the data. */ if ( FILE_WRITABLE(pMI->txt_prot, pMI->txt_flags) - && (lseek( pMI->txt_fd, 0, SEEK_SET ) >= 0) ) { - write( pMI->txt_fd, pMI->txt_data, pMI->txt_size ); + && (lseek(pMI->txt_fd, 0, SEEK_SET) >= 0) ) { + write(pMI->txt_fd, pMI->txt_data, pMI->txt_size); } - close( pMI->txt_fd ); + close(pMI->txt_fd); pMI->txt_fd = -1; pMI->txt_errno = errno; - free( pMI->txt_data ); + free(pMI->txt_data); return pMI->txt_errno; #endif /* HAVE_MMAP */ diff --git a/sntp/libopts/time.c b/sntp/libopts/time.c index 1f2f7bbcd..ea32e4d38 100644 --- a/sntp/libopts/time.c +++ b/sntp/libopts/time.c @@ -1,11 +1,12 @@ -/* - * $Id: 63d3312044fd7854ad0995faea41c96f5185cb93 $ - * Time-stamp: "2008-11-16 14:51:48 bkorb" +/** + * \file time.c + * + * Time-stamp: "2010-07-17 10:36:19 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -73,7 +74,7 @@ optionTimeVal(tOptions* pOpts, tOptDesc* pOD ) return; bad_time: - fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString ); + fprintf(stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString); if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); @@ -85,4 +86,4 @@ bad_time: * c-file-style: "stroustrup" * indent-tabs-mode: nil * End: - * end of autoopts/numeric.c */ + * end of autoopts/time.c */ diff --git a/sntp/libopts/tokenize.c b/sntp/libopts/tokenize.c index 74295674a..d93f7a1d7 100644 --- a/sntp/libopts/tokenize.c +++ b/sntp/libopts/tokenize.c @@ -1,10 +1,10 @@ /* * This file defines the string_tokenize interface - * Time-stamp: "2007-11-12 20:40:36 bkorb" + * Time-stamp: "2010-07-17 10:40:26 bkorb" * * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -30,16 +30,18 @@ #define ch_t unsigned char /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -copy_cooked( ch_t** ppDest, char const ** ppSrc ); +copy_cooked(ch_t** ppDest, char const ** ppSrc); static void -copy_raw( ch_t** ppDest, char const ** ppSrc ); +copy_raw(ch_t** ppDest, char const ** ppSrc); + +static token_list_t * +alloc_token_list(char const * str); /* = = = END-STATIC-FORWARD = = = */ static void -copy_cooked( ch_t** ppDest, char const ** ppSrc ) +copy_cooked(ch_t** ppDest, char const ** ppSrc) { ch_t* pDest = (ch_t*)*ppDest; const ch_t* pSrc = (const ch_t*)(*ppSrc + 1); @@ -50,7 +52,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc ) case NUL: *ppSrc = NULL; return; case '"': goto done; case '\\': - pSrc += ao_string_cook_escape_char( (char*)pSrc, (char*)&ch, 0x7F ); + pSrc += ao_string_cook_escape_char((char*)pSrc, (char*)&ch, 0x7F); if (ch == 0x7F) break; /* FALLTHROUGH */ @@ -67,7 +69,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc ) static void -copy_raw( ch_t** ppDest, char const ** ppSrc ) +copy_raw(ch_t** ppDest, char const ** ppSrc) { ch_t* pDest = *ppDest; cc_t* pSrc = (cc_t*) (*ppSrc + 1); @@ -113,6 +115,53 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) *ppSrc = (char const *) pSrc; /* char following closing quote */ } +static token_list_t * +alloc_token_list(char const * str) +{ + token_list_t * res; + + int max_token_ct = 2; /* allow for trailing NULL pointer & NUL on string */ + + if (str == NULL) goto enoent_res; + + /* + * Trim leading white space. Use "ENOENT" and a NULL return to indicate + * an empty string was passed. + */ + while (IS_WHITESPACE_CHAR(*str)) str++; + if (*str == NUL) goto enoent_res; + + /* + * Take an approximate count of tokens. If no quoted strings are used, + * it will be accurate. If quoted strings are used, it will be a little + * high and we'll squander the space for a few extra pointers. + */ + { + cc_t* pz = (cc_t*)str; + + do { + max_token_ct++; + while (! IS_WHITESPACE_CHAR(*++pz)) + if (*pz == NUL) goto found_nul; + while (IS_WHITESPACE_CHAR(*pz)) pz++; + } while (*pz != NUL); + + found_nul: + res = malloc(sizeof(*res) + (pz - (cc_t*)str) + + (max_token_ct * sizeof(ch_t*))); + } + + if (res == NULL) + errno = ENOMEM; + else res->tkn_list[0] = (ch_t*)(res->tkn_list + (max_token_ct - 1)); + + return res; + + enoent_res: + + errno = ENOENT; + return NULL; +} /*=export_func ao_string_tokenize * @@ -161,10 +210,10 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) * @example * #include * int ix; - * token_list_t* ptl = ao_string_tokenize( some_string ) + * token_list_t* ptl = ao_string_tokenize(some_string) * for (ix = 0; ix < ptl->tkn_ct; ix++) - * do_something_with_tkn( ptl->tkn_list[ix] ); - * free( ptl ); + * do_something_with_tkn(ptl->tkn_list[ix]); + * free(ptl); * @end example * Note that everything is freed with the one call to @code{free(3C)}. * @@ -180,106 +229,69 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) * @end itemize =*/ token_list_t* -ao_string_tokenize( char const* str ) +ao_string_tokenize(char const* str) { - int max_token_ct = 1; /* allow for trailing NUL on string */ - token_list_t* res; - - if (str == NULL) goto bogus_str; + token_list_t* res = alloc_token_list(str); + ch_t* pzDest; /* - * Trim leading white space. Use "ENOENT" and a NULL return to indicate - * an empty string was passed. - */ - while (IS_WHITESPACE_CHAR(*str)) str++; - if (*str == NUL) { - bogus_str: - errno = ENOENT; - return NULL; - } - - /* - * Take an approximate count of tokens. If no quoted strings are used, - * it will be accurate. If quoted strings are used, it will be a little - * high and we'll squander the space for a few extra pointers. + * Now copy each token into the output buffer. */ - { - cc_t* pz = (cc_t*)str; - - do { - max_token_ct++; - while (! IS_WHITESPACE_CHAR(*++pz)) - if (*pz == NUL) goto found_nul; - while (IS_WHITESPACE_CHAR(*pz)) pz++; - } while (*pz != NUL); + if (res == NULL) + return res; - found_nul: - ; - } + pzDest = (ch_t*)(res->tkn_list[0]); + res->tkn_ct = 0; - res = malloc( sizeof(*res) + strlen(str) + (max_token_ct * sizeof(ch_t*)) ); - if (res == NULL) { - errno = ENOMEM; - return res; - } + do { + res->tkn_list[ res->tkn_ct++ ] = pzDest; + for (;;) { + int ch = (ch_t)*str; + if (IS_WHITESPACE_CHAR(ch)) { + found_white_space: + while (IS_WHITESPACE_CHAR(*++str)) ; + break; + } - /* - * Now copy each token into the output buffer. - */ - { - ch_t* pzDest = (ch_t*)(res->tkn_list + (max_token_ct + 1)); - res->tkn_ct = 0; - - do { - res->tkn_list[ res->tkn_ct++ ] = pzDest; - for (;;) { - int ch = (ch_t)*str; - if (IS_WHITESPACE_CHAR(ch)) { - found_white_space: - while (IS_WHITESPACE_CHAR(*++str)) ; - break; + switch (ch) { + case '"': + copy_cooked(&pzDest, &str); + if (str == NULL) { + free(res); + errno = EINVAL; + return NULL; } + if (IS_WHITESPACE_CHAR(*str)) + goto found_white_space; + break; - switch (ch) { - case '"': - copy_cooked( &pzDest, &str ); - if (str == NULL) { - free(res); - errno = EINVAL; - return NULL; - } - if (IS_WHITESPACE_CHAR(*str)) - goto found_white_space; - break; - - case '\'': - copy_raw( &pzDest, &str ); - if (str == NULL) { - free(res); - errno = EINVAL; - return NULL; - } - if (IS_WHITESPACE_CHAR(*str)) - goto found_white_space; - break; - - case NUL: - goto copy_done; - - default: - str++; - *(pzDest++) = ch; + case '\'': + copy_raw(&pzDest, &str); + if (str == NULL) { + free(res); + errno = EINVAL; + return NULL; } - } copy_done:; + if (IS_WHITESPACE_CHAR(*str)) + goto found_white_space; + break; - /* - * NUL terminate the last token and see if we have any more tokens. - */ - *(pzDest++) = NUL; - } while (*str != NUL); + case NUL: + goto copy_done; - res->tkn_list[ res->tkn_ct ] = NULL; - } + default: + str++; + *(pzDest++) = ch; + } + } copy_done:; + + /* + * NUL terminate the last token and see if we have any more tokens. + */ + *(pzDest++) = NUL; + } while (*str != NUL); + + res->tkn_list[ res->tkn_ct ] = NULL; return res; } @@ -289,7 +301,7 @@ ao_string_tokenize( char const* str ) #include int -main( int argc, char** argv ) +main(int argc, char** argv) { if (argc == 1) { printf("USAGE: %s arg [ ... ]\n", *argv); @@ -297,15 +309,15 @@ main( int argc, char** argv ) } while (--argc > 0) { char* arg = *(++argv); - token_list_t* p = ao_string_tokenize( arg ); + token_list_t* p = ao_string_tokenize(arg); if (p == NULL) { - printf( "Parsing string ``%s'' failed:\n\terrno %d (%s)\n", - arg, errno, strerror( errno )); + printf("Parsing string ``%s'' failed:\n\terrno %d (%s)\n", + arg, errno, strerror(errno)); } else { int ix = 0; - printf( "Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct ); + printf("Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct); do { - printf( " %3d: ``%s''\n", ix+1, p->tkn_list[ix] ); + printf(" %3d: ``%s''\n", ix+1, p->tkn_list[ix]); } while (++ix < p->tkn_ct); free(p); } diff --git a/sntp/libopts/usage.c b/sntp/libopts/usage.c index 9a1cf63f6..b0977560c 100644 --- a/sntp/libopts/usage.c +++ b/sntp/libopts/usage.c @@ -1,7 +1,8 @@ /* - * usage.c $Id: f611ee45aa9aa8dc102b8acf6b4bc568c60fa99f $ - * Time-stamp: "2009-10-02 23:18:50 bkorb" + * \file usage.c + * + * Time-stamp: "2010-11-05 11:41:54 bkorb" * * This module implements the default usage procedure for * Automated Options. It may be overridden, of course. @@ -15,7 +16,7 @@ /* * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -38,77 +39,167 @@ static arg_types_t argTypes; -FILE* option_usage_fp = NULL; +FILE * option_usage_fp = NULL; static char zOptFmtLine[ 16 ]; static ag_bool displayEnum; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ -static ag_bool -checkGNUUsage( tOptions* pOpts ); +static void +set_usage_flags(tOptions * opts, char const * flg_txt); + +static inline ag_bool +do_gnu_usage(tOptions * pOpts); + +static inline ag_bool +skip_misuse_usage(tOptions * pOpts); static void -printExtendedUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ); +print_usage_details(tOptions * opts, int exit_code); static void -printInitList( - tCC* const* papz, - ag_bool* pInitIntro, - tCC* pzRc, - tCC* pzPN ); +prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printOptPreamble( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ); +prt_ini_list( + char const * const * papz, + ag_bool * pInitIntro, + char const * pzRc, + char const * pzPN ); static void -printOneUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ); +prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printOptionUsage( - tOptions * pOpts, - int ex_code, - tCC * pOptTitle ); +prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printProgramDetails( tOptions* pOptions ); +prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle); + +static void +prt_prog_detail(tOptions* pOptions); static int -setGnuOptFmts( tOptions* pOpts, tCC** ppT ); +setGnuOptFmts(tOptions* pOpts, tCC** ppT); static int -setStdOptFmts( tOptions* pOpts, tCC** ppT ); +setStdOptFmts(tOptions* pOpts, tCC** ppT); /* = = = END-STATIC-FORWARD = = = */ - /* - * Figure out if we should try to format usage text sort-of like - * the way many GNU programs do. + * NB: no entry may be a prefix of another entry */ -static ag_bool -checkGNUUsage( tOptions* pOpts ) +#define AOFLAG_TABLE \ + _aof_(gnu, OPTPROC_GNUUSAGE ) \ + _aof_(autoopts, ~OPTPROC_GNUUSAGE) \ + _aof_(no_misuse_usage, OPTPROC_MISUSE ) \ + _aof_(misuse_usage, ~OPTPROC_MISUSE ) + +static void +set_usage_flags(tOptions * opts, char const * flg_txt) { - char* pz = getenv( "AUTOOPTS_USAGE" ); - if (pz == NULL) - ; + typedef struct { + size_t fnm_len; + uint32_t fnm_mask; + char const * fnm_name; + } ao_flag_names_t; + +# define _aof_(_n, _f) AOUF_ ## _n ## _ID, + typedef enum { AOFLAG_TABLE AOUF_COUNT } ao_flag_id_t; +# undef _aof_ + +# define _aof_(_n, _f) AOUF_ ## _n = (1 << AOUF_ ## _n ## _ID), + typedef enum { AOFLAG_TABLE } ao_flags_t; +# undef _aof_ + +# define _aof_(_n, _f) { sizeof(#_n)-1, _f, #_n }, + static ao_flag_names_t const fn_table[AOUF_COUNT] = { + AOFLAG_TABLE + }; +# undef _aof_ + + ao_flags_t flg = 0; + + if (flg_txt == NULL) { + flg_txt = getenv("AUTOOPTS_USAGE"); + if (flg_txt == NULL) + return; + } - else if (streqvcmp( pz, "gnu" ) == 0) - pOpts->fOptSet |= OPTPROC_GNUUSAGE; + while (IS_WHITESPACE_CHAR(*flg_txt)) flg_txt++; + if (*flg_txt == NUL) + return; + + for (;;) { + int ix = 0; + ao_flag_names_t const * fnt = fn_table; + + for (;;) { + if (strneqvcmp(flg_txt, fnt->fnm_name, fnt->fnm_len) == 0) + break; + if (++ix >= AOUF_COUNT) + return; + fnt++; + } - else if (streqvcmp( pz, "autoopts" ) == 0) - pOpts->fOptSet &= ~OPTPROC_GNUUSAGE; + /* + * Make sure we have a full match. Look for whitespace, + * a comma, or a NUL byte. + */ + if (! IS_END_LIST_ENTRY_CHAR(flg_txt[fnt->fnm_len])) + return; + + flg |= 1 << ix; + flg_txt += fnt->fnm_len; + while (IS_WHITESPACE_CHAR(*flg_txt)) flg_txt++; + + if (*flg_txt == NUL) + break; + + if (*flg_txt == ',') { + /* + * skip the comma and following white space + */ + while (IS_WHITESPACE_CHAR(*++flg_txt)) ; + if (*flg_txt == NUL) + break; + } + } + + { + ao_flag_names_t const * fnm = fn_table; + + while (flg != 0) { + if ((flg & 1) != 0) { + if ((fnm->fnm_mask & OPTPROC_LONGOPT) != 0) + opts->fOptSet &= fnm->fnm_mask; + else opts->fOptSet |= fnm->fnm_mask; + } + flg >>= 1; + fnm++; + } + } +} +/* + * Figure out if we should try to format usage text sort-of like + * the way many GNU programs do. + */ +static inline ag_bool +do_gnu_usage(tOptions * pOpts) +{ return (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? AG_TRUE : AG_FALSE; } +/* + * Figure out if we should try to format usage text sort-of like + * the way many GNU programs do. + */ +static inline ag_bool +skip_misuse_usage(tOptions * pOpts) +{ + return (pOpts->fOptSet & OPTPROC_MISUSE) ? AG_TRUE : AG_FALSE; +} + /*=export_func optionOnlyUsage * @@ -122,23 +213,103 @@ checkGNUUsage( tOptions* pOpts ) * information not available to AutoOpts. =*/ void -optionOnlyUsage( - tOptions* pOpts, - int ex_code ) +optionOnlyUsage(tOptions * pOpts, int ex_code) { - tCC* pOptTitle = NULL; + char const * pOptTitle = NULL; + + set_usage_flags(pOpts, NULL); + if ((ex_code != EXIT_SUCCESS) && + skip_misuse_usage(pOpts)) + return; /* * Determine which header and which option formatting strings to use */ - if (checkGNUUsage(pOpts)) { - (void)setGnuOptFmts( pOpts, &pOptTitle ); + if (do_gnu_usage(pOpts)) { + (void)setGnuOptFmts(pOpts, &pOptTitle); } else { - (void)setStdOptFmts( pOpts, &pOptTitle ); + (void)setStdOptFmts(pOpts, &pOptTitle); + } + + prt_opt_usage(pOpts, ex_code, pOptTitle); + + fflush(option_usage_fp); + if (ferror(option_usage_fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } +} + +static void +print_usage_details(tOptions * opts, int exit_code) +{ + { + char const * pOptTitle = NULL; + + /* + * Determine which header and which option formatting strings to use + */ + if (do_gnu_usage(opts)) { + int flen = setGnuOptFmts(opts, &pOptTitle); + sprintf(zOptFmtLine, zFmtFmt, flen); + fputc('\n', option_usage_fp); + } + else { + int flen = setStdOptFmts(opts, &pOptTitle); + sprintf(zOptFmtLine, zFmtFmt, flen); + + /* + * When we exit with EXIT_SUCCESS and the first option is a doc + * option, we do *NOT* want to emit the column headers. + * Otherwise, we do. + */ + if ( (exit_code != EXIT_SUCCESS) + || ((opts->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) ) + + fputs(pOptTitle, option_usage_fp); + } + + prt_opt_usage(opts, exit_code, pOptTitle); + } + + /* + * Describe the mechanics of denoting the options + */ + switch (opts->fOptSet & OPTPROC_L_N_S) { + case OPTPROC_L_N_S: fputs(zFlagOkay, option_usage_fp); break; + case OPTPROC_SHORTOPT: break; + case OPTPROC_LONGOPT: fputs(zNoFlags, option_usage_fp); break; + case 0: fputs(zOptsOnly, option_usage_fp); break; } - printOptionUsage( pOpts, ex_code, pOptTitle ); + if ((opts->fOptSet & OPTPROC_NUM_OPT) != 0) { + fputs(zNumberOpt, option_usage_fp); + } + + if ((opts->fOptSet & OPTPROC_REORDER) != 0) { + fputs(zReorder, option_usage_fp); + } + + if (opts->pzExplain != NULL) + fputs(opts->pzExplain, option_usage_fp); + + /* + * IF the user is asking for help (thus exiting with SUCCESS), + * THEN see what additional information we can provide. + */ + if (exit_code == EXIT_SUCCESS) + prt_prog_detail(opts); + + if (opts->pzBugAddr != NULL) + fprintf(option_usage_fp, zPlsSendBugs, opts->pzBugAddr); + + fflush(option_usage_fp); + + if (ferror(option_usage_fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } } @@ -159,11 +330,9 @@ optionOnlyUsage( * and the actual exit code will be "EXIT_SUCCESS". =*/ void -optionUsage( - tOptions* pOptions, - int usage_exit_code ) +optionUsage(tOptions * pOptions, int usage_exit_code) { - int actual_exit_code = + int exit_code = (usage_exit_code == EX_USAGE) ? EXIT_SUCCESS : usage_exit_code; displayEnum = AG_FALSE; @@ -179,7 +348,7 @@ optionUsage( { char const * pz; - if (actual_exit_code == EXIT_SUCCESS) { + if (exit_code == EXIT_SUCCESS) { pz = (pOptions->structVersion >= 30 * 4096) ? pOptions->pzFullUsage : NULL; @@ -195,74 +364,19 @@ optionUsage( if (pz != NULL) { fputs(pz, option_usage_fp); - exit(actual_exit_code); - } - } - - fprintf( option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName ); - - { - tCC* pOptTitle = NULL; - - /* - * Determine which header and which option formatting strings to use - */ - if (checkGNUUsage(pOptions)) { - int flen = setGnuOptFmts( pOptions, &pOptTitle ); - sprintf( zOptFmtLine, zFmtFmt, flen ); - fputc( '\n', option_usage_fp ); - } - else { - int flen = setStdOptFmts( pOptions, &pOptTitle ); - sprintf( zOptFmtLine, zFmtFmt, flen ); - - /* - * When we exit with EXIT_SUCCESS and the first option is a doc - * option, we do *NOT* want to emit the column headers. - * Otherwise, we do. - */ - if ( (usage_exit_code != EXIT_SUCCESS) - || ((pOptions->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) ) - - fputs( pOptTitle, option_usage_fp ); + exit(exit_code); } - - printOptionUsage( pOptions, usage_exit_code, pOptTitle ); } - /* - * Describe the mechanics of denoting the options - */ - switch (pOptions->fOptSet & OPTPROC_L_N_S) { - case OPTPROC_L_N_S: fputs( zFlagOkay, option_usage_fp ); break; - case OPTPROC_SHORTOPT: break; - case OPTPROC_LONGOPT: fputs( zNoFlags, option_usage_fp ); break; - case 0: fputs( zOptsOnly, option_usage_fp ); break; - } - - if ((pOptions->fOptSet & OPTPROC_NUM_OPT) != 0) { - fputs( zNumberOpt, option_usage_fp ); - } + fprintf(option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName); + set_usage_flags(pOptions, NULL); - if ((pOptions->fOptSet & OPTPROC_REORDER) != 0) { - fputs( zReorder, option_usage_fp ); - } + if ((exit_code == EXIT_SUCCESS) || + (! skip_misuse_usage(pOptions))) - if (pOptions->pzExplain != NULL) - fputs( pOptions->pzExplain, option_usage_fp ); + print_usage_details(pOptions, usage_exit_code); - /* - * IF the user is asking for help (thus exiting with SUCCESS), - * THEN see what additional information we can provide. - */ - if (usage_exit_code == EXIT_SUCCESS) - printProgramDetails( pOptions ); - - if (pOptions->pzBugAddr != NULL) - fprintf( option_usage_fp, zPlsSendBugs, pOptions->pzBugAddr ); - fflush( option_usage_fp ); - - exit( actual_exit_code ); + exit(exit_code); } @@ -271,10 +385,7 @@ optionUsage( * PER OPTION TYPE USAGE INFORMATION */ static void -printExtendedUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ) +prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) { /* * IF there are option conflicts or dependencies, @@ -283,7 +394,7 @@ printExtendedUsage( if ( (pOD->pOptMust != NULL) || (pOD->pOptCant != NULL) ) { - fputs( zTabHyp, option_usage_fp ); + fputs(zTabHyp, option_usage_fp); /* * DEPENDENCIES: @@ -291,16 +402,16 @@ printExtendedUsage( if (pOD->pOptMust != NULL) { const int* pOptNo = pOD->pOptMust; - fputs( zReqThese, option_usage_fp ); + fputs(zReqThese, option_usage_fp); for (;;) { - fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[ - *pOptNo ].pz_Name ); + fprintf(option_usage_fp, zTabout, + pOptions->pOptDesc[*pOptNo].pz_Name); if (*++pOptNo == NO_EQUIVALENT) break; } if (pOD->pOptCant != NULL) - fputs( zTabHypAnd, option_usage_fp ); + fputs(zTabHypAnd, option_usage_fp); } /* @@ -309,10 +420,10 @@ printExtendedUsage( if (pOD->pOptCant != NULL) { const int* pOptNo = pOD->pOptCant; - fputs( zProhib, option_usage_fp ); + fputs(zProhib, option_usage_fp); for (;;) { - fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[ - *pOptNo ].pz_Name ); + fprintf(option_usage_fp, zTabout, + pOptions->pOptDesc[*pOptNo].pz_Name); if (*++pOptNo == NO_EQUIVALENT) break; } @@ -324,7 +435,7 @@ printExtendedUsage( * THEN print the disablement info */ if (pOD->pz_DisableName != NULL ) - fprintf( option_usage_fp, zDis, pOD->pz_DisableName ); + fprintf(option_usage_fp, zDis, pOD->pz_DisableName); /* * Check for argument types that have callbacks with magical properties @@ -351,7 +462,7 @@ printExtendedUsage( * THEN print that out */ if (pOD->fOptState & OPTST_INITENABLED) - fputs( zEnab, option_usage_fp ); + fputs(zEnab, option_usage_fp); /* * IF the option is in an equivalence class @@ -360,8 +471,8 @@ printExtendedUsage( */ if ( (pOD->optEquivIndex != NO_EQUIVALENT) && (pOD->optEquivIndex != pOD->optActualIndex ) ) { - fprintf( option_usage_fp, zAlt, - pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name ); + fprintf(option_usage_fp, zAlt, + pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name); return; } @@ -378,25 +489,25 @@ printExtendedUsage( && (pOD->optIndex < pOptions->presetOptCt) ) - fputs( zNoPreset, option_usage_fp ); + fputs(zNoPreset, option_usage_fp); /* * Print the appearance requirements. */ if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) - fputs( zMembers, option_usage_fp ); + fputs(zMembers, option_usage_fp); else switch (pOD->optMinCt) { case 1: case 0: switch (pOD->optMaxCt) { - case 0: fputs( zPreset, option_usage_fp ); break; - case NOLIMIT: fputs( zNoLim, option_usage_fp ); break; + case 0: fputs(zPreset, option_usage_fp); break; + case NOLIMIT: fputs(zNoLim, option_usage_fp); break; case 1: break; /* * IF the max is more than one but limited, print "UP TO" message */ - default: fprintf( option_usage_fp, zUpTo, pOD->optMaxCt ); break; + default: fprintf(option_usage_fp, zUpTo, pOD->optMaxCt); break; } break; @@ -404,12 +515,12 @@ printExtendedUsage( /* * More than one is required. Print the range. */ - fprintf( option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt ); + fprintf(option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt); } - if ( NAMED_OPTS( pOptions ) + if ( NAMED_OPTS(pOptions) && (pOptions->specOptIdx.default_opt == pOD->optIndex)) - fputs( zDefaultOpt, option_usage_fp ); + fputs(zDefaultOpt, option_usage_fp); } @@ -421,18 +532,18 @@ printExtendedUsage( * squishy, but important to tell users how to find these files. */ static void -printInitList( - tCC* const* papz, - ag_bool* pInitIntro, - tCC* pzRc, - tCC* pzPN ) +prt_ini_list( + char const * const * papz, + ag_bool * pInitIntro, + char const * pzRc, + char const * pzPN ) { char zPath[ AG_PATH_MAX+1 ]; if (papz == NULL) return; - fputs( zPresetIntro, option_usage_fp ); + fputs(zPresetIntro, option_usage_fp); *pInitIntro = AG_FALSE; for (;;) { @@ -441,14 +552,14 @@ printInitList( if (pzPath == NULL) break; - if (optionMakePath(zPath, (int)sizeof( zPath ), pzPath, pzPN)) + if (optionMakePath(zPath, (int)sizeof(zPath), pzPath, pzPN)) pzPath = zPath; /* * Print the name of the "homerc" file. If the "rcfile" name is * not empty, we may or may not print that, too... */ - fprintf( option_usage_fp, zPathFmt, pzPath ); + fprintf(option_usage_fp, zPathFmt, pzPath); if (*pzRc != NUL) { struct stat sb; @@ -456,23 +567,20 @@ printInitList( * IF the "homerc" file is a directory, * then append the "rcfile" name. */ - if ( (stat( pzPath, &sb ) == 0) - && S_ISDIR( sb.st_mode ) ) { - fputc( DIRCH, option_usage_fp ); - fputs( pzRc, option_usage_fp ); + if ( (stat(pzPath, &sb) == 0) + && S_ISDIR(sb.st_mode)) { + fputc(DIRCH, option_usage_fp); + fputs(pzRc, option_usage_fp); } } - fputc( '\n', option_usage_fp ); + fputc('\n', option_usage_fp); } } static void -printOptPreamble( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ) +prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) { /* * Flag prefix: IF no flags at all, then omit it. If not printable @@ -481,19 +589,19 @@ printOptPreamble( * opts are to be printed too. */ if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0) - fputs( pAT->pzSpc, option_usage_fp ); + fputs(pAT->pzSpc, option_usage_fp); else if (! IS_GRAPHIC_CHAR(pOD->optValue)) { if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) - fputc( ' ', option_usage_fp ); - fputs( pAT->pzNoF, option_usage_fp ); + fputc(' ', option_usage_fp); + fputs(pAT->pzNoF, option_usage_fp); } else { - fprintf( option_usage_fp, " -%c", pOD->optValue ); + fprintf(option_usage_fp, " -%c", pOD->optValue); if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) - fputs( ", ", option_usage_fp ); + fputs(", ", option_usage_fp); } } @@ -501,16 +609,14 @@ printOptPreamble( * Print the usage information for a single option. */ static void -printOneUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ) +prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) { - printOptPreamble(pOptions, pOD, pAT); + prt_preamble(pOptions, pOD, pAT); { - char z[ 80 ]; - tCC* pzArgType; + char z[ 80 ]; + char const * pzArgType; + /* * Determine the argument type string first on its usage, then, * when the option argument is required, base the type string on the @@ -522,7 +628,7 @@ printOneUsage( } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break; case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break; - case OPARG_TYPE_FILE : pzArgType = pAT->pzFile; break; + case OPARG_TYPE_FILE: pzArgType = pAT->pzFile; break; case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break; case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break; case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break; @@ -532,10 +638,10 @@ printOneUsage( default: goto bogus_desc; } - snprintf( z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name, - (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt ); + snprintf(z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name, + (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt); - fprintf( option_usage_fp, zOptFmtLine, z, pOD->pzText ); + fprintf(option_usage_fp, zOptFmtLine, z, pOD->pzText); switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_ENUMERATION: @@ -546,8 +652,8 @@ printOneUsage( return; bogus_desc: - fprintf( stderr, zInvalOptDesc, pOD->pz_Name ); - exit( EX_SOFTWARE ); + fprintf(stderr, zInvalOptDesc, pOD->pz_Name); + exit(EX_SOFTWARE); } @@ -555,10 +661,7 @@ printOneUsage( * Print out the usage information for just the options. */ static void -printOptionUsage( - tOptions * pOpts, - int ex_code, - tCC * pOptTitle ) +prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) { int ct = pOpts->optCt; int optNo = 0; @@ -580,7 +683,7 @@ printOptionUsage( char const * why_pz = (pOD->pzText == NULL) ? zDisabledWhy : pOD->pzText; - printOptPreamble(pOpts, pOD, &argTypes); + prt_preamble(pOpts, pOD, &argTypes); fprintf(option_usage_fp, zDisabledOpt, pOD->pz_Name, why_pz); } @@ -608,20 +711,20 @@ printOptionUsage( && (ex_code == EXIT_SUCCESS) && (docCt > 0) && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) ) - fprintf( option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle ); + fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle); - printOneUsage(pOpts, pOD, &argTypes); + prt_one_usage(pOpts, pOD, &argTypes); /* * IF we were invoked because of the --help option, * THEN print all the extra info */ if (ex_code == EXIT_SUCCESS) - printExtendedUsage( pOpts, pOD, &argTypes ); + prt_extd_usage(pOpts, pOD, &argTypes); } while (pOD++, optNo++, (--ct > 0)); - fputc( '\n', option_usage_fp ); + fputc('\n', option_usage_fp); } @@ -630,24 +733,24 @@ printOptionUsage( * PROGRAM DETAILS */ static void -printProgramDetails( tOptions* pOptions ) +prt_prog_detail(tOptions* pOptions) { ag_bool initIntro = AG_TRUE; /* * Display all the places we look for config files */ - printInitList( pOptions->papzHomeList, &initIntro, - pOptions->pzRcName, pOptions->pzProgPath ); + prt_ini_list(pOptions->papzHomeList, &initIntro, + pOptions->pzRcName, pOptions->pzProgPath); /* * Let the user know about environment variable settings */ if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) { if (initIntro) - fputs( zPresetIntro, option_usage_fp ); + fputs(zPresetIntro, option_usage_fp); - fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME ); + fprintf(option_usage_fp, zExamineFmt, pOptions->pzPROGNAME); } /* @@ -660,8 +763,8 @@ printProgramDetails( tOptions* pOptions ) int optNo = 0; tOptDesc* pOD = pOptions->pOptDesc; - fputc( '\n', option_usage_fp ); - fflush( option_usage_fp ); + fputc('\n', option_usage_fp); + fflush(option_usage_fp); do { switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_ENUMERATION: @@ -675,7 +778,7 @@ printProgramDetails( tOptions* pOptions ) * If there is a detail string, now is the time for that. */ if (pOptions->pzDetail != NULL) - fputs( pOptions->pzDetail, option_usage_fp ); + fputs(pOptions->pzDetail, option_usage_fp); } @@ -694,7 +797,7 @@ printProgramDetails( tOptions* pOptions ) * Set up the formatting for GNU-style output */ static int -setGnuOptFmts( tOptions* pOpts, tCC** ppT ) +setGnuOptFmts(tOptions* pOpts, tCC** ppT) { int flen = 22; *ppT = zNoRq_ShrtTtl; @@ -734,7 +837,7 @@ setGnuOptFmts( tOptions* pOpts, tCC** ppT ) * Standard (AutoOpts normal) option line formatting */ static int -setStdOptFmts( tOptions* pOpts, tCC** ppT ) +setStdOptFmts(tOptions* pOpts, tCC** ppT) { int flen = 0; diff --git a/sntp/libopts/value-type.c b/sntp/libopts/value-type.c index 27c010be0..ff98c0a1e 100644 --- a/sntp/libopts/value-type.c +++ b/sntp/libopts/value-type.c @@ -1,4 +1,4 @@ -/* ANSI-C code produced by gperf version 3.0.2 */ +/* ANSI-C code produced by gperf version 3.0.4 */ #if 0 /* gperf build options: */ @@ -91,6 +91,9 @@ static const value_type_map_t value_type_table[] = }; #ifdef __GNUC__ +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif #endif static inline const value_type_map_t * find_value_type_name (register const char *str, register unsigned int len) diff --git a/sntp/libopts/value-type.h b/sntp/libopts/value-type.h index 17719e1b4..955bceeea 100644 --- a/sntp/libopts/value-type.h +++ b/sntp/libopts/value-type.h @@ -1,5 +1,5 @@ /* - * Generated header for gperf generated source Sun Nov 8 08:41:19 PST 2009 + * Generated header for gperf generated source Tue Nov 16 17:41:46 PST 2010 * This file enumerates the list of names and declares the * procedure for mapping string names to the enum value. */ diff --git a/sntp/libopts/version.c b/sntp/libopts/version.c index 07e0e183c..a6dfb3abb 100644 --- a/sntp/libopts/version.c +++ b/sntp/libopts/version.c @@ -1,6 +1,6 @@ -/* $Id: e21e2bf9958c54e440efbdc7c1026e46ac589f66 $ - * Time-stamp: "2008-07-27 10:11:30 bkorb" +/* + * Time-stamp: "2010-09-05 05:53:20 bkorb" * * This module implements the default usage procedure for * Automated Options. It may be overridden, of course. @@ -9,7 +9,7 @@ /* * This file is part of AutoOpts, a companion to AutoGen. * AutoOpts is free software. - * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved + * AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved * * AutoOpts is available under any one of two licenses. The license * in use must be one of these two and the choice is under the control @@ -29,9 +29,8 @@ */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by mk-fwd */ static void -printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ); +printVersion(tOptions* pOpts, tOptDesc* pOD, FILE* fp); /* = = = END-STATIC-FORWARD = = = */ /*=export_func optionVersion @@ -44,17 +43,17 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ); * The returned string cannot be modified. =*/ char const* -optionVersion( void ) +optionVersion(void) { static char const zVersion[] = - STR( AO_CURRENT.AO_REVISION ); + STR(AO_CURRENT.AO_REVISION); return zVersion; } static void -printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) +printVersion(tOptions* pOpts, tOptDesc* pOD, FILE* fp) { char swCh; @@ -68,8 +67,8 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) else swCh = tolower(pOD->optArg.argString[0]); if (pOpts->pzFullVersion != NULL) { - fputs( pOpts->pzFullVersion, fp ); - fputc( '\n', fp ); + fputs(pOpts->pzFullVersion, fp); + fputc('\n', fp); } else { char const *pz = pOpts->pzUsageTitle; @@ -83,37 +82,42 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) case 'c': if (pOpts->pzCopyright != NULL) { - fputs( pOpts->pzCopyright, fp ); - fputc( '\n', fp ); + fputs(pOpts->pzCopyright, fp); + fputc('\n', fp); } - fprintf( fp, zAO_Ver, optionVersion() ); + fprintf(fp, zAO_Ver, optionVersion()); if (pOpts->pzBugAddr != NULL) - fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr ); + fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr); break; case 'n': if (pOpts->pzCopyright != NULL) { - fputs( pOpts->pzCopyright, fp ); - fputc( '\n', fp ); - fputc( '\n', fp ); + fputs(pOpts->pzCopyright, fp); + fputc('\n', fp); + fputc('\n', fp); } if (pOpts->pzCopyNotice != NULL) { - fputs( pOpts->pzCopyNotice, fp ); - fputc( '\n', fp ); + fputs(pOpts->pzCopyNotice, fp); + fputc('\n', fp); } - fprintf( fp, zAO_Ver, optionVersion() ); + fprintf(fp, zAO_Ver, optionVersion()); if (pOpts->pzBugAddr != NULL) - fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr ); + fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr); break; default: - fprintf( stderr, zBadVerArg, swCh ); - exit( EXIT_FAILURE ); + fprintf(stderr, zBadVerArg, swCh); + exit(EXIT_FAILURE); } - exit( EXIT_SUCCESS ); + fflush(fp); + if (ferror(fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); } /*=export_func optionPrintVersion @@ -127,9 +131,9 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) * This routine will print the version to stdout. =*/ void -optionPrintVersion( tOptions* pOpts, tOptDesc* pOD ) +optionPrintVersion(tOptions* pOpts, tOptDesc* pOD) { - printVersion( pOpts, pOD, stdout ); + printVersion(pOpts, pOD, stdout); } /*=export_func optionVersionStderr @@ -143,9 +147,9 @@ optionPrintVersion( tOptions* pOpts, tOptDesc* pOD ) * This routine will print the version to stderr. =*/ void -optionVersionStderr( tOptions* pOpts, tOptDesc* pOD ) +optionVersionStderr(tOptions* pOpts, tOptDesc* pOD) { - printVersion( pOpts, pOD, stderr ); + printVersion(pOpts, pOD, stderr); } /* diff --git a/sntp/libopts/xat-attribute.c b/sntp/libopts/xat-attribute.c index 85b735fb6..db4753124 100644 --- a/sntp/libopts/xat-attribute.c +++ b/sntp/libopts/xat-attribute.c @@ -1,4 +1,4 @@ -/* ANSI-C code produced by gperf version 3.0.2 */ +/* ANSI-C code produced by gperf version 3.0.4 */ #if 0 /* gperf build options: */ @@ -82,6 +82,9 @@ static const xat_attribute_map_t xat_attribute_table[] = }; #ifdef __GNUC__ +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif #endif static inline const xat_attribute_map_t * find_xat_attribute_name (register const char *str, register unsigned int len) diff --git a/sntp/libopts/xat-attribute.h b/sntp/libopts/xat-attribute.h index 517d8fd39..ea3e9a623 100644 --- a/sntp/libopts/xat-attribute.h +++ b/sntp/libopts/xat-attribute.h @@ -1,5 +1,5 @@ /* - * Generated header for gperf generated source Sun Nov 8 08:41:19 PST 2009 + * Generated header for gperf generated source Tue Nov 16 17:41:46 PST 2010 * This file enumerates the list of names and declares the * procedure for mapping string names to the enum value. */