updated libopts

This commit is contained in:
Nikos Mavrogiannopoulos
2013-04-28 15:01:17 +03:00
parent fed7861b89
commit 66d9e9404d
59 changed files with 7427 additions and 4770 deletions

View File

@@ -21,6 +21,9 @@
/* Define to the number of bits in type 'wint_t'. */
#undef BITSIZEOF_WINT_T
/* nls support in libopts */
#undef ENABLE_NLS
/* Define this to 1 if F_DUPFD behavior does not match POSIX */
#undef FCNTL_DUPFD_BUGGY
@@ -245,6 +248,9 @@
/* Define to 1 if you have the <libgen.h> header file. */
#undef HAVE_LIBGEN_H
/* Define to 1 if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H
/* Define if you have the libseccomp library. */
#undef HAVE_LIBSECCOMP

View File

@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
Copyright (C) 1992-2013 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.
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
copyright (c) by Bruce Korb - all rights reserved
Copyright (C) by Bruce Korb - all rights reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> copyright (c) by Bruce Korb - all rights reserved
<program> Copyright (C) by Bruce Korb - all rights reserved
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

View File

@@ -1,7 +1,7 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
Copyright (C) 1992-2013 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.

View File

@@ -1,26 +1,29 @@
## LIBOPTS Makefile
MAINTAINERCLEANFILES = Makefile.in
noinst_LIBRARIES = libopts.a
libopts_a_SOURCES = libopts.c
libopts_a_CPPFLAGS = -I$(top_srcdir)
EXTRA_DIST = \
ag-char-map.h alias.c ao-strs.c \
ao-strs.h autoopts/options.h autoopts/project.h \
autoopts/usage-txt.h autoopts.c autoopts.h \
boolean.c check.c compat/strchr.c \
compat/pathfind.c compat/strdup.c compat/windows-config.h \
compat/snprintf.c compat/compat.h configfile.c \
compat/snprintf.c compat/compat.h compat/windows-config.h \
compat/pathfind.c compat/strdup.c configfile.c \
cook.c COPYING.gplv3 COPYING.lgplv3 \
COPYING.mbsd enum.c env.c \
file.c find.c genshell.c \
genshell.h load.c m4/liboptschk.m4 \
m4/libopts.m4 MakeDefs.inc makeshell.c \
nested.c numeric.c parse-duration.c \
genshell.h gettext.h init.c \
load.c m4/libopts.m4 m4/liboptschk.m4 \
MakeDefs.inc makeshell.c nested.c \
numeric.c option-value-type.c option-value-type.h \
option-xat-attribute.c option-xat-attribute.h parse-duration.c \
parse-duration.h pgusage.c proto.h \
putshell.c README reset.c \
restore.c save.c sort.c \
stack.c streqvcmp.c text_mmap.c \
time.c tokenize.c usage.c \
value-type.c value-type.h version.c \
xat-attribute.c xat-attribute.h
version.c

View File

@@ -115,7 +115,7 @@ These macros work as follows:
LICENSING:
This material is Copyright (c) 1992-2012 by Bruce Korb. You are
This material is Copyright (C) 1992-2013 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 License (see: COPYING.mbsd). Both of

View File

@@ -1,25 +1,30 @@
/*
* 28 bits for 44 character classifications
* generated by char-mapper on 05/06/12 at 16:20:58
* 29 bits for 46 character classifications
* generated by char-mapper on 03/31/13 at 10:41:23
*
* This file contains the character classifications
* used by AutoGen and AutoOpts for identifying tokens.
* The table is static scope, so %guard is empty.
*
* This file is part of AutoGen.
* Copyright (c) 1992-2012 Bruce Korb - all rights reserved
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (C) 1992-2013 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.
* 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
* of the user of the license.
*
* 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.
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following sha256 sums:
*
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef AG_CHAR_MAP_H_GUARD
#define AG_CHAR_MAP_H_GUARD 1
@@ -62,6 +67,7 @@
// underscore "_"
// plus "+"
// dollar "$"
// option-marker "-"
//
// horiz-white "\t "
// alt-white "\v\f\r\b"
@@ -100,342 +106,372 @@
// set-separator "|+" +end-list-entry
// signed-number +inversion +dec-digit
// make-script +dollar +newline
// load-line-skip +horiz-white +option-marker
//
#endif /* 0 -- mapping spec. source */
typedef uint32_t ag_char_map_mask_t;
#define IS_NEWLINE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000001)
#define SPN_NEWLINE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 0)
#define BRK_NEWLINE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 0)
#define SPN_NEWLINE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 0)
#define BRK_NEWLINE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 0)
#define IS_NUL_BYTE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000002)
#define SPN_NUL_BYTE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 1)
#define BRK_NUL_BYTE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 1)
#define SPN_NUL_BYTE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 1)
#define BRK_NUL_BYTE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 1)
#define IS_DIR_SEP_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000004)
#define SPN_DIR_SEP_CHARS(_s) spn_ag_char_map_chars((char *)_s, 2)
#define BRK_DIR_SEP_CHARS(_s) brk_ag_char_map_chars((char *)_s, 2)
#define SPN_DIR_SEP_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 2)
#define BRK_DIR_SEP_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 2)
#define IS_PERCENT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000008)
#define SPN_PERCENT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 3)
#define BRK_PERCENT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 3)
#define SPN_PERCENT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 3)
#define BRK_PERCENT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 3)
#define IS_COMMA_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000010)
#define SPN_COMMA_CHARS(_s) spn_ag_char_map_chars((char *)_s, 4)
#define BRK_COMMA_CHARS(_s) brk_ag_char_map_chars((char *)_s, 4)
#define SPN_COMMA_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 4)
#define BRK_COMMA_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 4)
#define IS_COLON_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000020)
#define SPN_COLON_CHARS(_s) spn_ag_char_map_chars((char *)_s, 5)
#define BRK_COLON_CHARS(_s) brk_ag_char_map_chars((char *)_s, 5)
#define SPN_COLON_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 5)
#define BRK_COLON_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 5)
#define IS_UNDERSCORE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000040)
#define SPN_UNDERSCORE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 6)
#define BRK_UNDERSCORE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 6)
#define SPN_UNDERSCORE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 6)
#define BRK_UNDERSCORE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 6)
#define IS_PLUS_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000080)
#define SPN_PLUS_CHARS(_s) spn_ag_char_map_chars((char *)_s, 7)
#define BRK_PLUS_CHARS(_s) brk_ag_char_map_chars((char *)_s, 7)
#define SPN_PLUS_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 7)
#define BRK_PLUS_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 7)
#define IS_DOLLAR_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000100)
#define SPN_DOLLAR_CHARS(_s) spn_ag_char_map_chars((char *)_s, 8)
#define BRK_DOLLAR_CHARS(_s) brk_ag_char_map_chars((char *)_s, 8)
#define SPN_DOLLAR_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 8)
#define BRK_DOLLAR_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 8)
#define IS_HORIZ_WHITE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000200)
#define SPN_HORIZ_WHITE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 9)
#define BRK_HORIZ_WHITE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 9)
#define SPN_HORIZ_WHITE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 9)
#define BRK_HORIZ_WHITE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 9)
#define IS_ALT_WHITE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000400)
#define SPN_ALT_WHITE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 10)
#define BRK_ALT_WHITE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 10)
#define SPN_ALT_WHITE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 10)
#define BRK_ALT_WHITE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 10)
#define IS_WHITESPACE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000601)
#define SPN_WHITESPACE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 11)
#define BRK_WHITESPACE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 11)
#define SPN_WHITESPACE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 11)
#define BRK_WHITESPACE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 11)
#define IS_NON_NL_WHITE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000600)
#define SPN_NON_NL_WHITE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 12)
#define BRK_NON_NL_WHITE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 12)
#define SPN_NON_NL_WHITE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 12)
#define BRK_NON_NL_WHITE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 12)
#define IS_QUOTE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000800)
#define SPN_QUOTE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 13)
#define BRK_QUOTE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 13)
#define SPN_QUOTE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 13)
#define BRK_QUOTE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 13)
#define IS_PARENTHESES_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0001000)
#define SPN_PARENTHESES_CHARS(_s) spn_ag_char_map_chars((char *)_s, 14)
#define BRK_PARENTHESES_CHARS(_s) brk_ag_char_map_chars((char *)_s, 14)
#define SPN_PARENTHESES_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 14)
#define BRK_PARENTHESES_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 14)
#define IS_GRAPHIC_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0002000)
#define SPN_GRAPHIC_CHARS(_s) spn_ag_char_map_chars((char *)_s, 15)
#define BRK_GRAPHIC_CHARS(_s) brk_ag_char_map_chars((char *)_s, 15)
#define SPN_GRAPHIC_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 15)
#define BRK_GRAPHIC_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 15)
#define IS_INVERSION_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0004000)
#define SPN_INVERSION_CHARS(_s) spn_ag_char_map_chars((char *)_s, 16)
#define BRK_INVERSION_CHARS(_s) brk_ag_char_map_chars((char *)_s, 16)
#define SPN_INVERSION_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 16)
#define BRK_INVERSION_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 16)
#define IS_OCT_DIGIT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0008000)
#define SPN_OCT_DIGIT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 17)
#define BRK_OCT_DIGIT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 17)
#define SPN_OCT_DIGIT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 17)
#define BRK_OCT_DIGIT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 17)
#define IS_DEC_DIGIT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0018000)
#define SPN_DEC_DIGIT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 18)
#define BRK_DEC_DIGIT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 18)
#define SPN_DEC_DIGIT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 18)
#define BRK_DEC_DIGIT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 18)
#define IS_HEX_DIGIT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0038000)
#define SPN_HEX_DIGIT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 19)
#define BRK_HEX_DIGIT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 19)
#define SPN_HEX_DIGIT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 19)
#define BRK_HEX_DIGIT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 19)
#define IS_LOWER_CASE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0040000)
#define SPN_LOWER_CASE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 20)
#define BRK_LOWER_CASE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 20)
#define SPN_LOWER_CASE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 20)
#define BRK_LOWER_CASE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 20)
#define IS_UPPER_CASE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0080000)
#define SPN_UPPER_CASE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 21)
#define BRK_UPPER_CASE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 21)
#define SPN_UPPER_CASE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 21)
#define BRK_UPPER_CASE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 21)
#define IS_ALPHABETIC_CHAR( _c) is_ag_char_map_char((char)( _c), 0x00C0000)
#define SPN_ALPHABETIC_CHARS(_s) spn_ag_char_map_chars((char *)_s, 22)
#define BRK_ALPHABETIC_CHARS(_s) brk_ag_char_map_chars((char *)_s, 22)
#define SPN_ALPHABETIC_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 22)
#define BRK_ALPHABETIC_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 22)
#define IS_ALPHANUMERIC_CHAR( _c) is_ag_char_map_char((char)( _c), 0x00D8000)
#define SPN_ALPHANUMERIC_CHARS(_s) spn_ag_char_map_chars((char *)_s, 23)
#define BRK_ALPHANUMERIC_CHARS(_s) brk_ag_char_map_chars((char *)_s, 23)
#define SPN_ALPHANUMERIC_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 23)
#define BRK_ALPHANUMERIC_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 23)
#define IS_VAR_FIRST_CHAR( _c) is_ag_char_map_char((char)( _c), 0x00C0040)
#define SPN_VAR_FIRST_CHARS(_s) spn_ag_char_map_chars((char *)_s, 24)
#define BRK_VAR_FIRST_CHARS(_s) brk_ag_char_map_chars((char *)_s, 24)
#define SPN_VAR_FIRST_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 24)
#define BRK_VAR_FIRST_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 24)
#define IS_VARIABLE_NAME_CHAR( _c) is_ag_char_map_char((char)( _c), 0x00D8040)
#define SPN_VARIABLE_NAME_CHARS(_s) spn_ag_char_map_chars((char *)_s, 25)
#define BRK_VARIABLE_NAME_CHARS(_s) brk_ag_char_map_chars((char *)_s, 25)
#define SPN_VARIABLE_NAME_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 25)
#define BRK_VARIABLE_NAME_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 25)
#define IS_OPTION_NAME_CHAR( _c) is_ag_char_map_char((char)( _c), 0x01D8040)
#define SPN_OPTION_NAME_CHARS(_s) spn_ag_char_map_chars((char *)_s, 26)
#define BRK_OPTION_NAME_CHARS(_s) brk_ag_char_map_chars((char *)_s, 26)
#define SPN_OPTION_NAME_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 26)
#define BRK_OPTION_NAME_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 26)
#define IS_VALUE_NAME_CHAR( _c) is_ag_char_map_char((char)( _c), 0x01D8060)
#define SPN_VALUE_NAME_CHARS(_s) spn_ag_char_map_chars((char *)_s, 27)
#define BRK_VALUE_NAME_CHARS(_s) brk_ag_char_map_chars((char *)_s, 27)
#define SPN_VALUE_NAME_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 27)
#define BRK_VALUE_NAME_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 27)
#define IS_NAME_SEP_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0200000)
#define SPN_NAME_SEP_CHARS(_s) spn_ag_char_map_chars((char *)_s, 28)
#define BRK_NAME_SEP_CHARS(_s) brk_ag_char_map_chars((char *)_s, 28)
#define SPN_NAME_SEP_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 28)
#define BRK_NAME_SEP_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 28)
#define IS_COMPOUND_NAME_CHAR( _c) is_ag_char_map_char((char)( _c), 0x03D8260)
#define SPN_COMPOUND_NAME_CHARS(_s) spn_ag_char_map_chars((char *)_s, 29)
#define BRK_COMPOUND_NAME_CHARS(_s) brk_ag_char_map_chars((char *)_s, 29)
#define SPN_COMPOUND_NAME_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 29)
#define BRK_COMPOUND_NAME_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 29)
#define IS_SCHEME_NOTE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0001800)
#define SPN_SCHEME_NOTE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 30)
#define BRK_SCHEME_NOTE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 30)
#define SPN_SCHEME_NOTE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 30)
#define BRK_SCHEME_NOTE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 30)
#define IS_UNQUOTABLE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0400000)
#define SPN_UNQUOTABLE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 31)
#define BRK_UNQUOTABLE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 31)
#define SPN_UNQUOTABLE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 31)
#define BRK_UNQUOTABLE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 31)
#define IS_END_XML_TOKEN_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0800601)
#define SPN_END_XML_TOKEN_CHARS(_s) spn_ag_char_map_chars((char *)_s, 32)
#define BRK_END_XML_TOKEN_CHARS(_s) brk_ag_char_map_chars((char *)_s, 32)
#define SPN_END_XML_TOKEN_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 32)
#define BRK_END_XML_TOKEN_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 32)
#define IS_PLUS_N_SPACE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000681)
#define SPN_PLUS_N_SPACE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 33)
#define BRK_PLUS_N_SPACE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 33)
#define SPN_PLUS_N_SPACE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 33)
#define BRK_PLUS_N_SPACE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 33)
#define IS_PUNCTUATION_CHAR( _c) is_ag_char_map_char((char)( _c), 0x1000000)
#define SPN_PUNCTUATION_CHARS(_s) spn_ag_char_map_chars((char *)_s, 34)
#define BRK_PUNCTUATION_CHARS(_s) brk_ag_char_map_chars((char *)_s, 34)
#define SPN_PUNCTUATION_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 34)
#define BRK_PUNCTUATION_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 34)
#define IS_SUFFIX_CHAR( _c) is_ag_char_map_char((char)( _c), 0x20D8000)
#define SPN_SUFFIX_CHARS(_s) spn_ag_char_map_chars((char *)_s, 35)
#define BRK_SUFFIX_CHARS(_s) brk_ag_char_map_chars((char *)_s, 35)
#define SPN_SUFFIX_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 35)
#define BRK_SUFFIX_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 35)
#define IS_SUFFIX_FMT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x20D800C)
#define SPN_SUFFIX_FMT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 36)
#define BRK_SUFFIX_FMT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 36)
#define SPN_SUFFIX_FMT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 36)
#define BRK_SUFFIX_FMT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 36)
#define IS_FALSE_TYPE_CHAR( _c) is_ag_char_map_char((char)( _c), 0x4000002)
#define SPN_FALSE_TYPE_CHARS(_s) spn_ag_char_map_chars((char *)_s, 37)
#define BRK_FALSE_TYPE_CHARS(_s) brk_ag_char_map_chars((char *)_s, 37)
#define SPN_FALSE_TYPE_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 37)
#define BRK_FALSE_TYPE_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 37)
#define IS_FILE_NAME_CHAR( _c) is_ag_char_map_char((char)( _c), 0x20D8004)
#define SPN_FILE_NAME_CHARS(_s) spn_ag_char_map_chars((char *)_s, 38)
#define BRK_FILE_NAME_CHARS(_s) brk_ag_char_map_chars((char *)_s, 38)
#define SPN_FILE_NAME_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 38)
#define BRK_FILE_NAME_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 38)
#define IS_END_TOKEN_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000603)
#define SPN_END_TOKEN_CHARS(_s) spn_ag_char_map_chars((char *)_s, 39)
#define BRK_END_TOKEN_CHARS(_s) brk_ag_char_map_chars((char *)_s, 39)
#define SPN_END_TOKEN_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 39)
#define BRK_END_TOKEN_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 39)
#define IS_END_LIST_ENTRY_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000613)
#define SPN_END_LIST_ENTRY_CHARS(_s) spn_ag_char_map_chars((char *)_s, 40)
#define BRK_END_LIST_ENTRY_CHARS(_s) brk_ag_char_map_chars((char *)_s, 40)
#define SPN_END_LIST_ENTRY_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 40)
#define BRK_END_LIST_ENTRY_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 40)
#define IS_SET_SEPARATOR_CHAR( _c) is_ag_char_map_char((char)( _c), 0x8000613)
#define SPN_SET_SEPARATOR_CHARS(_s) spn_ag_char_map_chars((char *)_s, 41)
#define BRK_SET_SEPARATOR_CHARS(_s) brk_ag_char_map_chars((char *)_s, 41)
#define SPN_SET_SEPARATOR_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 41)
#define BRK_SET_SEPARATOR_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 41)
#define IS_SIGNED_NUMBER_CHAR( _c) is_ag_char_map_char((char)( _c), 0x001C000)
#define SPN_SIGNED_NUMBER_CHARS(_s) spn_ag_char_map_chars((char *)_s, 42)
#define BRK_SIGNED_NUMBER_CHARS(_s) brk_ag_char_map_chars((char *)_s, 42)
#define SPN_SIGNED_NUMBER_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 42)
#define BRK_SIGNED_NUMBER_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 42)
#define IS_MAKE_SCRIPT_CHAR( _c) is_ag_char_map_char((char)( _c), 0x0000101)
#define SPN_MAKE_SCRIPT_CHARS(_s) spn_ag_char_map_chars((char *)_s, 43)
#define BRK_MAKE_SCRIPT_CHARS(_s) brk_ag_char_map_chars((char *)_s, 43)
#define SPN_MAKE_SCRIPT_BACK(s,e) spn_ag_char_map_back((char *)s, (char *)e, 43)
#define BRK_MAKE_SCRIPT_BACK(s,e) brk_ag_char_map_back((char *)s, (char *)e, 43)
#define IS_NEWLINE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000001)
#define SPN_NEWLINE_CHARS(_s) spn_ag_char_map_chars(_s, 0)
#define BRK_NEWLINE_CHARS(_s) brk_ag_char_map_chars(_s, 0)
#define SPN_NEWLINE_BACK(s,e) spn_ag_char_map_back(s, e, 0)
#define BRK_NEWLINE_BACK(s,e) brk_ag_char_map_back(s, e, 0)
#define IS_NUL_BYTE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000002)
#define SPN_NUL_BYTE_CHARS(_s) spn_ag_char_map_chars(_s, 1)
#define BRK_NUL_BYTE_CHARS(_s) brk_ag_char_map_chars(_s, 1)
#define SPN_NUL_BYTE_BACK(s,e) spn_ag_char_map_back(s, e, 1)
#define BRK_NUL_BYTE_BACK(s,e) brk_ag_char_map_back(s, e, 1)
#define IS_DIR_SEP_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000004)
#define SPN_DIR_SEP_CHARS(_s) spn_ag_char_map_chars(_s, 2)
#define BRK_DIR_SEP_CHARS(_s) brk_ag_char_map_chars(_s, 2)
#define SPN_DIR_SEP_BACK(s,e) spn_ag_char_map_back(s, e, 2)
#define BRK_DIR_SEP_BACK(s,e) brk_ag_char_map_back(s, e, 2)
#define IS_PERCENT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000008)
#define SPN_PERCENT_CHARS(_s) spn_ag_char_map_chars(_s, 3)
#define BRK_PERCENT_CHARS(_s) brk_ag_char_map_chars(_s, 3)
#define SPN_PERCENT_BACK(s,e) spn_ag_char_map_back(s, e, 3)
#define BRK_PERCENT_BACK(s,e) brk_ag_char_map_back(s, e, 3)
#define IS_COMMA_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000010)
#define SPN_COMMA_CHARS(_s) spn_ag_char_map_chars(_s, 4)
#define BRK_COMMA_CHARS(_s) brk_ag_char_map_chars(_s, 4)
#define SPN_COMMA_BACK(s,e) spn_ag_char_map_back(s, e, 4)
#define BRK_COMMA_BACK(s,e) brk_ag_char_map_back(s, e, 4)
#define IS_COLON_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000020)
#define SPN_COLON_CHARS(_s) spn_ag_char_map_chars(_s, 5)
#define BRK_COLON_CHARS(_s) brk_ag_char_map_chars(_s, 5)
#define SPN_COLON_BACK(s,e) spn_ag_char_map_back(s, e, 5)
#define BRK_COLON_BACK(s,e) brk_ag_char_map_back(s, e, 5)
#define IS_UNDERSCORE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000040)
#define SPN_UNDERSCORE_CHARS(_s) spn_ag_char_map_chars(_s, 6)
#define BRK_UNDERSCORE_CHARS(_s) brk_ag_char_map_chars(_s, 6)
#define SPN_UNDERSCORE_BACK(s,e) spn_ag_char_map_back(s, e, 6)
#define BRK_UNDERSCORE_BACK(s,e) brk_ag_char_map_back(s, e, 6)
#define IS_PLUS_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000080)
#define SPN_PLUS_CHARS(_s) spn_ag_char_map_chars(_s, 7)
#define BRK_PLUS_CHARS(_s) brk_ag_char_map_chars(_s, 7)
#define SPN_PLUS_BACK(s,e) spn_ag_char_map_back(s, e, 7)
#define BRK_PLUS_BACK(s,e) brk_ag_char_map_back(s, e, 7)
#define IS_DOLLAR_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000100)
#define SPN_DOLLAR_CHARS(_s) spn_ag_char_map_chars(_s, 8)
#define BRK_DOLLAR_CHARS(_s) brk_ag_char_map_chars(_s, 8)
#define SPN_DOLLAR_BACK(s,e) spn_ag_char_map_back(s, e, 8)
#define BRK_DOLLAR_BACK(s,e) brk_ag_char_map_back(s, e, 8)
#define IS_OPTION_MARKER_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000200)
#define SPN_OPTION_MARKER_CHARS(_s) spn_ag_char_map_chars(_s, 9)
#define BRK_OPTION_MARKER_CHARS(_s) brk_ag_char_map_chars(_s, 9)
#define SPN_OPTION_MARKER_BACK(s,e) spn_ag_char_map_back(s, e, 9)
#define BRK_OPTION_MARKER_BACK(s,e) brk_ag_char_map_back(s, e, 9)
#define IS_HORIZ_WHITE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000400)
#define SPN_HORIZ_WHITE_CHARS(_s) spn_ag_char_map_chars(_s, 10)
#define BRK_HORIZ_WHITE_CHARS(_s) brk_ag_char_map_chars(_s, 10)
#define SPN_HORIZ_WHITE_BACK(s,e) spn_ag_char_map_back(s, e, 10)
#define BRK_HORIZ_WHITE_BACK(s,e) brk_ag_char_map_back(s, e, 10)
#define IS_ALT_WHITE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000800)
#define SPN_ALT_WHITE_CHARS(_s) spn_ag_char_map_chars(_s, 11)
#define BRK_ALT_WHITE_CHARS(_s) brk_ag_char_map_chars(_s, 11)
#define SPN_ALT_WHITE_BACK(s,e) spn_ag_char_map_back(s, e, 11)
#define BRK_ALT_WHITE_BACK(s,e) brk_ag_char_map_back(s, e, 11)
#define IS_WHITESPACE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000C01)
#define SPN_WHITESPACE_CHARS(_s) spn_ag_char_map_chars(_s, 12)
#define BRK_WHITESPACE_CHARS(_s) brk_ag_char_map_chars(_s, 12)
#define SPN_WHITESPACE_BACK(s,e) spn_ag_char_map_back(s, e, 12)
#define BRK_WHITESPACE_BACK(s,e) brk_ag_char_map_back(s, e, 12)
#define IS_NON_NL_WHITE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000C00)
#define SPN_NON_NL_WHITE_CHARS(_s) spn_ag_char_map_chars(_s, 13)
#define BRK_NON_NL_WHITE_CHARS(_s) brk_ag_char_map_chars(_s, 13)
#define SPN_NON_NL_WHITE_BACK(s,e) spn_ag_char_map_back(s, e, 13)
#define BRK_NON_NL_WHITE_BACK(s,e) brk_ag_char_map_back(s, e, 13)
#define IS_QUOTE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00001000)
#define SPN_QUOTE_CHARS(_s) spn_ag_char_map_chars(_s, 14)
#define BRK_QUOTE_CHARS(_s) brk_ag_char_map_chars(_s, 14)
#define SPN_QUOTE_BACK(s,e) spn_ag_char_map_back(s, e, 14)
#define BRK_QUOTE_BACK(s,e) brk_ag_char_map_back(s, e, 14)
#define IS_PARENTHESES_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00002000)
#define SPN_PARENTHESES_CHARS(_s) spn_ag_char_map_chars(_s, 15)
#define BRK_PARENTHESES_CHARS(_s) brk_ag_char_map_chars(_s, 15)
#define SPN_PARENTHESES_BACK(s,e) spn_ag_char_map_back(s, e, 15)
#define BRK_PARENTHESES_BACK(s,e) brk_ag_char_map_back(s, e, 15)
#define IS_GRAPHIC_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00004000)
#define SPN_GRAPHIC_CHARS(_s) spn_ag_char_map_chars(_s, 16)
#define BRK_GRAPHIC_CHARS(_s) brk_ag_char_map_chars(_s, 16)
#define SPN_GRAPHIC_BACK(s,e) spn_ag_char_map_back(s, e, 16)
#define BRK_GRAPHIC_BACK(s,e) brk_ag_char_map_back(s, e, 16)
#define IS_INVERSION_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00008000)
#define SPN_INVERSION_CHARS(_s) spn_ag_char_map_chars(_s, 17)
#define BRK_INVERSION_CHARS(_s) brk_ag_char_map_chars(_s, 17)
#define SPN_INVERSION_BACK(s,e) spn_ag_char_map_back(s, e, 17)
#define BRK_INVERSION_BACK(s,e) brk_ag_char_map_back(s, e, 17)
#define IS_OCT_DIGIT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00010000)
#define SPN_OCT_DIGIT_CHARS(_s) spn_ag_char_map_chars(_s, 18)
#define BRK_OCT_DIGIT_CHARS(_s) brk_ag_char_map_chars(_s, 18)
#define SPN_OCT_DIGIT_BACK(s,e) spn_ag_char_map_back(s, e, 18)
#define BRK_OCT_DIGIT_BACK(s,e) brk_ag_char_map_back(s, e, 18)
#define IS_DEC_DIGIT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00030000)
#define SPN_DEC_DIGIT_CHARS(_s) spn_ag_char_map_chars(_s, 19)
#define BRK_DEC_DIGIT_CHARS(_s) brk_ag_char_map_chars(_s, 19)
#define SPN_DEC_DIGIT_BACK(s,e) spn_ag_char_map_back(s, e, 19)
#define BRK_DEC_DIGIT_BACK(s,e) brk_ag_char_map_back(s, e, 19)
#define IS_HEX_DIGIT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00070000)
#define SPN_HEX_DIGIT_CHARS(_s) spn_ag_char_map_chars(_s, 20)
#define BRK_HEX_DIGIT_CHARS(_s) brk_ag_char_map_chars(_s, 20)
#define SPN_HEX_DIGIT_BACK(s,e) spn_ag_char_map_back(s, e, 20)
#define BRK_HEX_DIGIT_BACK(s,e) brk_ag_char_map_back(s, e, 20)
#define IS_LOWER_CASE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00080000)
#define SPN_LOWER_CASE_CHARS(_s) spn_ag_char_map_chars(_s, 21)
#define BRK_LOWER_CASE_CHARS(_s) brk_ag_char_map_chars(_s, 21)
#define SPN_LOWER_CASE_BACK(s,e) spn_ag_char_map_back(s, e, 21)
#define BRK_LOWER_CASE_BACK(s,e) brk_ag_char_map_back(s, e, 21)
#define IS_UPPER_CASE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00100000)
#define SPN_UPPER_CASE_CHARS(_s) spn_ag_char_map_chars(_s, 22)
#define BRK_UPPER_CASE_CHARS(_s) brk_ag_char_map_chars(_s, 22)
#define SPN_UPPER_CASE_BACK(s,e) spn_ag_char_map_back(s, e, 22)
#define BRK_UPPER_CASE_BACK(s,e) brk_ag_char_map_back(s, e, 22)
#define IS_ALPHABETIC_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00180000)
#define SPN_ALPHABETIC_CHARS(_s) spn_ag_char_map_chars(_s, 23)
#define BRK_ALPHABETIC_CHARS(_s) brk_ag_char_map_chars(_s, 23)
#define SPN_ALPHABETIC_BACK(s,e) spn_ag_char_map_back(s, e, 23)
#define BRK_ALPHABETIC_BACK(s,e) brk_ag_char_map_back(s, e, 23)
#define IS_ALPHANUMERIC_CHAR( _c) is_ag_char_map_char((char)(_c), 0x001B0000)
#define SPN_ALPHANUMERIC_CHARS(_s) spn_ag_char_map_chars(_s, 24)
#define BRK_ALPHANUMERIC_CHARS(_s) brk_ag_char_map_chars(_s, 24)
#define SPN_ALPHANUMERIC_BACK(s,e) spn_ag_char_map_back(s, e, 24)
#define BRK_ALPHANUMERIC_BACK(s,e) brk_ag_char_map_back(s, e, 24)
#define IS_VAR_FIRST_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00180040)
#define SPN_VAR_FIRST_CHARS(_s) spn_ag_char_map_chars(_s, 25)
#define BRK_VAR_FIRST_CHARS(_s) brk_ag_char_map_chars(_s, 25)
#define SPN_VAR_FIRST_BACK(s,e) spn_ag_char_map_back(s, e, 25)
#define BRK_VAR_FIRST_BACK(s,e) brk_ag_char_map_back(s, e, 25)
#define IS_VARIABLE_NAME_CHAR( _c) is_ag_char_map_char((char)(_c), 0x001B0040)
#define SPN_VARIABLE_NAME_CHARS(_s) spn_ag_char_map_chars(_s, 26)
#define BRK_VARIABLE_NAME_CHARS(_s) brk_ag_char_map_chars(_s, 26)
#define SPN_VARIABLE_NAME_BACK(s,e) spn_ag_char_map_back(s, e, 26)
#define BRK_VARIABLE_NAME_BACK(s,e) brk_ag_char_map_back(s, e, 26)
#define IS_OPTION_NAME_CHAR( _c) is_ag_char_map_char((char)(_c), 0x003B0040)
#define SPN_OPTION_NAME_CHARS(_s) spn_ag_char_map_chars(_s, 27)
#define BRK_OPTION_NAME_CHARS(_s) brk_ag_char_map_chars(_s, 27)
#define SPN_OPTION_NAME_BACK(s,e) spn_ag_char_map_back(s, e, 27)
#define BRK_OPTION_NAME_BACK(s,e) brk_ag_char_map_back(s, e, 27)
#define IS_VALUE_NAME_CHAR( _c) is_ag_char_map_char((char)(_c), 0x003B0060)
#define SPN_VALUE_NAME_CHARS(_s) spn_ag_char_map_chars(_s, 28)
#define BRK_VALUE_NAME_CHARS(_s) brk_ag_char_map_chars(_s, 28)
#define SPN_VALUE_NAME_BACK(s,e) spn_ag_char_map_back(s, e, 28)
#define BRK_VALUE_NAME_BACK(s,e) brk_ag_char_map_back(s, e, 28)
#define IS_NAME_SEP_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00400000)
#define SPN_NAME_SEP_CHARS(_s) spn_ag_char_map_chars(_s, 29)
#define BRK_NAME_SEP_CHARS(_s) brk_ag_char_map_chars(_s, 29)
#define SPN_NAME_SEP_BACK(s,e) spn_ag_char_map_back(s, e, 29)
#define BRK_NAME_SEP_BACK(s,e) brk_ag_char_map_back(s, e, 29)
#define IS_COMPOUND_NAME_CHAR( _c) is_ag_char_map_char((char)(_c), 0x007B0460)
#define SPN_COMPOUND_NAME_CHARS(_s) spn_ag_char_map_chars(_s, 30)
#define BRK_COMPOUND_NAME_CHARS(_s) brk_ag_char_map_chars(_s, 30)
#define SPN_COMPOUND_NAME_BACK(s,e) spn_ag_char_map_back(s, e, 30)
#define BRK_COMPOUND_NAME_BACK(s,e) brk_ag_char_map_back(s, e, 30)
#define IS_SCHEME_NOTE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00003000)
#define SPN_SCHEME_NOTE_CHARS(_s) spn_ag_char_map_chars(_s, 31)
#define BRK_SCHEME_NOTE_CHARS(_s) brk_ag_char_map_chars(_s, 31)
#define SPN_SCHEME_NOTE_BACK(s,e) spn_ag_char_map_back(s, e, 31)
#define BRK_SCHEME_NOTE_BACK(s,e) brk_ag_char_map_back(s, e, 31)
#define IS_UNQUOTABLE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00800000)
#define SPN_UNQUOTABLE_CHARS(_s) spn_ag_char_map_chars(_s, 32)
#define BRK_UNQUOTABLE_CHARS(_s) brk_ag_char_map_chars(_s, 32)
#define SPN_UNQUOTABLE_BACK(s,e) spn_ag_char_map_back(s, e, 32)
#define BRK_UNQUOTABLE_BACK(s,e) brk_ag_char_map_back(s, e, 32)
#define IS_END_XML_TOKEN_CHAR( _c) is_ag_char_map_char((char)(_c), 0x01000C01)
#define SPN_END_XML_TOKEN_CHARS(_s) spn_ag_char_map_chars(_s, 33)
#define BRK_END_XML_TOKEN_CHARS(_s) brk_ag_char_map_chars(_s, 33)
#define SPN_END_XML_TOKEN_BACK(s,e) spn_ag_char_map_back(s, e, 33)
#define BRK_END_XML_TOKEN_BACK(s,e) brk_ag_char_map_back(s, e, 33)
#define IS_PLUS_N_SPACE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000C81)
#define SPN_PLUS_N_SPACE_CHARS(_s) spn_ag_char_map_chars(_s, 34)
#define BRK_PLUS_N_SPACE_CHARS(_s) brk_ag_char_map_chars(_s, 34)
#define SPN_PLUS_N_SPACE_BACK(s,e) spn_ag_char_map_back(s, e, 34)
#define BRK_PLUS_N_SPACE_BACK(s,e) brk_ag_char_map_back(s, e, 34)
#define IS_PUNCTUATION_CHAR( _c) is_ag_char_map_char((char)(_c), 0x02000000)
#define SPN_PUNCTUATION_CHARS(_s) spn_ag_char_map_chars(_s, 35)
#define BRK_PUNCTUATION_CHARS(_s) brk_ag_char_map_chars(_s, 35)
#define SPN_PUNCTUATION_BACK(s,e) spn_ag_char_map_back(s, e, 35)
#define BRK_PUNCTUATION_BACK(s,e) brk_ag_char_map_back(s, e, 35)
#define IS_SUFFIX_CHAR( _c) is_ag_char_map_char((char)(_c), 0x041B0000)
#define SPN_SUFFIX_CHARS(_s) spn_ag_char_map_chars(_s, 36)
#define BRK_SUFFIX_CHARS(_s) brk_ag_char_map_chars(_s, 36)
#define SPN_SUFFIX_BACK(s,e) spn_ag_char_map_back(s, e, 36)
#define BRK_SUFFIX_BACK(s,e) brk_ag_char_map_back(s, e, 36)
#define IS_SUFFIX_FMT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x041B000C)
#define SPN_SUFFIX_FMT_CHARS(_s) spn_ag_char_map_chars(_s, 37)
#define BRK_SUFFIX_FMT_CHARS(_s) brk_ag_char_map_chars(_s, 37)
#define SPN_SUFFIX_FMT_BACK(s,e) spn_ag_char_map_back(s, e, 37)
#define BRK_SUFFIX_FMT_BACK(s,e) brk_ag_char_map_back(s, e, 37)
#define IS_FALSE_TYPE_CHAR( _c) is_ag_char_map_char((char)(_c), 0x08000002)
#define SPN_FALSE_TYPE_CHARS(_s) spn_ag_char_map_chars(_s, 38)
#define BRK_FALSE_TYPE_CHARS(_s) brk_ag_char_map_chars(_s, 38)
#define SPN_FALSE_TYPE_BACK(s,e) spn_ag_char_map_back(s, e, 38)
#define BRK_FALSE_TYPE_BACK(s,e) brk_ag_char_map_back(s, e, 38)
#define IS_FILE_NAME_CHAR( _c) is_ag_char_map_char((char)(_c), 0x041B0004)
#define SPN_FILE_NAME_CHARS(_s) spn_ag_char_map_chars(_s, 39)
#define BRK_FILE_NAME_CHARS(_s) brk_ag_char_map_chars(_s, 39)
#define SPN_FILE_NAME_BACK(s,e) spn_ag_char_map_back(s, e, 39)
#define BRK_FILE_NAME_BACK(s,e) brk_ag_char_map_back(s, e, 39)
#define IS_END_TOKEN_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000C03)
#define SPN_END_TOKEN_CHARS(_s) spn_ag_char_map_chars(_s, 40)
#define BRK_END_TOKEN_CHARS(_s) brk_ag_char_map_chars(_s, 40)
#define SPN_END_TOKEN_BACK(s,e) spn_ag_char_map_back(s, e, 40)
#define BRK_END_TOKEN_BACK(s,e) brk_ag_char_map_back(s, e, 40)
#define IS_END_LIST_ENTRY_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000C13)
#define SPN_END_LIST_ENTRY_CHARS(_s) spn_ag_char_map_chars(_s, 41)
#define BRK_END_LIST_ENTRY_CHARS(_s) brk_ag_char_map_chars(_s, 41)
#define SPN_END_LIST_ENTRY_BACK(s,e) spn_ag_char_map_back(s, e, 41)
#define BRK_END_LIST_ENTRY_BACK(s,e) brk_ag_char_map_back(s, e, 41)
#define IS_SET_SEPARATOR_CHAR( _c) is_ag_char_map_char((char)(_c), 0x10000C13)
#define SPN_SET_SEPARATOR_CHARS(_s) spn_ag_char_map_chars(_s, 42)
#define BRK_SET_SEPARATOR_CHARS(_s) brk_ag_char_map_chars(_s, 42)
#define SPN_SET_SEPARATOR_BACK(s,e) spn_ag_char_map_back(s, e, 42)
#define BRK_SET_SEPARATOR_BACK(s,e) brk_ag_char_map_back(s, e, 42)
#define IS_SIGNED_NUMBER_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00038000)
#define SPN_SIGNED_NUMBER_CHARS(_s) spn_ag_char_map_chars(_s, 43)
#define BRK_SIGNED_NUMBER_CHARS(_s) brk_ag_char_map_chars(_s, 43)
#define SPN_SIGNED_NUMBER_BACK(s,e) spn_ag_char_map_back(s, e, 43)
#define BRK_SIGNED_NUMBER_BACK(s,e) brk_ag_char_map_back(s, e, 43)
#define IS_MAKE_SCRIPT_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000101)
#define SPN_MAKE_SCRIPT_CHARS(_s) spn_ag_char_map_chars(_s, 44)
#define BRK_MAKE_SCRIPT_CHARS(_s) brk_ag_char_map_chars(_s, 44)
#define SPN_MAKE_SCRIPT_BACK(s,e) spn_ag_char_map_back(s, e, 44)
#define BRK_MAKE_SCRIPT_BACK(s,e) brk_ag_char_map_back(s, e, 44)
#define IS_LOAD_LINE_SKIP_CHAR( _c) is_ag_char_map_char((char)(_c), 0x00000600)
#define SPN_LOAD_LINE_SKIP_CHARS(_s) spn_ag_char_map_chars(_s, 45)
#define BRK_LOAD_LINE_SKIP_CHARS(_s) brk_ag_char_map_chars(_s, 45)
#define SPN_LOAD_LINE_SKIP_BACK(s,e) spn_ag_char_map_back(s, e, 45)
#define BRK_LOAD_LINE_SKIP_BACK(s,e) brk_ag_char_map_back(s, e, 45)
static ag_char_map_mask_t const ag_char_map_table[128] = {
/*NUL*/ 0x0000002, /*x01*/ 0x0000000, /*x02*/ 0x0000000, /*x03*/ 0x0000000,
/*x04*/ 0x0000000, /*x05*/ 0x0000000, /*x06*/ 0x0000000, /*BEL*/ 0x0000000,
/* BS*/ 0x0000400, /* HT*/ 0x0000200, /* NL*/ 0x0000001, /* VT*/ 0x0000400,
/* FF*/ 0x0000400, /* CR*/ 0x0000400, /*x0E*/ 0x0000000, /*x0F*/ 0x0000000,
/*x10*/ 0x0000000, /*x11*/ 0x0000000, /*x12*/ 0x0000000, /*x13*/ 0x0000000,
/*x14*/ 0x0000000, /*x15*/ 0x0000000, /*x16*/ 0x0000000, /*x17*/ 0x0000000,
/*x18*/ 0x0000000, /*x19*/ 0x0000000, /*x1A*/ 0x0000000, /*ESC*/ 0x0000000,
/*x1C*/ 0x0000000, /*x1D*/ 0x0000000, /*x1E*/ 0x0000000, /*x1F*/ 0x0000000,
/* */ 0x0000200, /* ! */ 0x1402000, /* " */ 0x1002800, /* # */ 0x1002000,
/* $ */ 0x1402100, /* % */ 0x1402008, /* & */ 0x1402000, /* ' */ 0x1002800,
/* ( */ 0x1003000, /* ) */ 0x1003000, /* * */ 0x1002000, /* + */ 0x9402080,
/* , */ 0x1002010, /* - */ 0x3506000, /* . */ 0x3602000, /* / */ 0x1C02004,
/* 0 */ 0x440A000, /* 1 */ 0x040A000, /* 2 */ 0x040A000, /* 3 */ 0x040A000,
/* 4 */ 0x040A000, /* 5 */ 0x040A000, /* 6 */ 0x040A000, /* 7 */ 0x040A000,
/* 8 */ 0x0412000, /* 9 */ 0x0412000, /* : */ 0x1402020, /* ; */ 0x1002000,
/* < */ 0x1002000, /* = */ 0x1002000, /* > */ 0x1802000, /* ? */ 0x1002000,
/* @ */ 0x1402000, /* A */ 0x04A2000, /* B */ 0x04A2000, /* C */ 0x04A2000,
/* D */ 0x04A2000, /* E */ 0x04A2000, /* F */ 0x44A2000, /* G */ 0x0482000,
/* H */ 0x0482000, /* I */ 0x0482000, /* J */ 0x0482000, /* K */ 0x0482000,
/* L */ 0x0482000, /* M */ 0x0482000, /* N */ 0x4482000, /* O */ 0x0482000,
/* P */ 0x0482000, /* Q */ 0x0482000, /* R */ 0x0482000, /* S */ 0x0482000,
/* T */ 0x0482000, /* U */ 0x0482000, /* V */ 0x0482000, /* W */ 0x0482000,
/* X */ 0x0482000, /* Y */ 0x0482000, /* Z */ 0x0482000, /* [ */ 0x1202000,
/* \ */ 0x1002004, /* ] */ 0x1202000, /* ^ */ 0x1502000, /* _ */ 0x2402040,
/* ` */ 0x1002000, /* a */ 0x0462000, /* b */ 0x0462000, /* c */ 0x0462000,
/* d */ 0x0462000, /* e */ 0x0462000, /* f */ 0x4462000, /* g */ 0x0442000,
/* h */ 0x0442000, /* i */ 0x0442000, /* j */ 0x0442000, /* k */ 0x0442000,
/* l */ 0x0442000, /* m */ 0x0442000, /* n */ 0x4442000, /* o */ 0x0442000,
/* p */ 0x0442000, /* q */ 0x0442000, /* r */ 0x0442000, /* s */ 0x0442000,
/* t */ 0x0442000, /* u */ 0x0442000, /* v */ 0x0442000, /* w */ 0x0442000,
/* x */ 0x0442000, /* y */ 0x0442000, /* z */ 0x0442000, /* { */ 0x1002000,
/* | */ 0x9402000, /* } */ 0x1002000, /* ~ */ 0x1406000, /*x7F*/ 0x0000000
/*NUL*/ 0x00000002, /*x01*/ 0x00000000, /*x02*/ 0x00000000, /*x03*/ 0x00000000,
/*x04*/ 0x00000000, /*x05*/ 0x00000000, /*x06*/ 0x00000000, /*BEL*/ 0x00000000,
/* BS*/ 0x00000800, /* HT*/ 0x00000400, /* NL*/ 0x00000001, /* VT*/ 0x00000800,
/* FF*/ 0x00000800, /* CR*/ 0x00000800, /*x0E*/ 0x00000000, /*x0F*/ 0x00000000,
/*x10*/ 0x00000000, /*x11*/ 0x00000000, /*x12*/ 0x00000000, /*x13*/ 0x00000000,
/*x14*/ 0x00000000, /*x15*/ 0x00000000, /*x16*/ 0x00000000, /*x17*/ 0x00000000,
/*x18*/ 0x00000000, /*x19*/ 0x00000000, /*x1A*/ 0x00000000, /*ESC*/ 0x00000000,
/*x1C*/ 0x00000000, /*x1D*/ 0x00000000, /*x1E*/ 0x00000000, /*x1F*/ 0x00000000,
/* */ 0x00000400, /* ! */ 0x02804000, /* " */ 0x02005000, /* # */ 0x02004000,
/* $ */ 0x02804100, /* % */ 0x02804008, /* & */ 0x02804000, /* ' */ 0x02005000,
/* ( */ 0x02006000, /* ) */ 0x02006000, /* * */ 0x02004000, /* + */ 0x12804080,
/* , */ 0x02004010, /* - */ 0x06A0C200, /* . */ 0x06C04000, /* / */ 0x03804004,
/* 0 */ 0x08814000, /* 1 */ 0x00814000, /* 2 */ 0x00814000, /* 3 */ 0x00814000,
/* 4 */ 0x00814000, /* 5 */ 0x00814000, /* 6 */ 0x00814000, /* 7 */ 0x00814000,
/* 8 */ 0x00824000, /* 9 */ 0x00824000, /* : */ 0x02804020, /* ; */ 0x02004000,
/* < */ 0x02004000, /* = */ 0x02004000, /* > */ 0x03004000, /* ? */ 0x02004000,
/* @ */ 0x02804000, /* A */ 0x00944000, /* B */ 0x00944000, /* C */ 0x00944000,
/* D */ 0x00944000, /* E */ 0x00944000, /* F */ 0x08944000, /* G */ 0x00904000,
/* H */ 0x00904000, /* I */ 0x00904000, /* J */ 0x00904000, /* K */ 0x00904000,
/* L */ 0x00904000, /* M */ 0x00904000, /* N */ 0x08904000, /* O */ 0x00904000,
/* P */ 0x00904000, /* Q */ 0x00904000, /* R */ 0x00904000, /* S */ 0x00904000,
/* T */ 0x00904000, /* U */ 0x00904000, /* V */ 0x00904000, /* W */ 0x00904000,
/* X */ 0x00904000, /* Y */ 0x00904000, /* Z */ 0x00904000, /* [ */ 0x02404000,
/* \ */ 0x02004004, /* ] */ 0x02404000, /* ^ */ 0x02A04000, /* _ */ 0x04804040,
/* ` */ 0x02004000, /* a */ 0x008C4000, /* b */ 0x008C4000, /* c */ 0x008C4000,
/* d */ 0x008C4000, /* e */ 0x008C4000, /* f */ 0x088C4000, /* g */ 0x00884000,
/* h */ 0x00884000, /* i */ 0x00884000, /* j */ 0x00884000, /* k */ 0x00884000,
/* l */ 0x00884000, /* m */ 0x00884000, /* n */ 0x08884000, /* o */ 0x00884000,
/* p */ 0x00884000, /* q */ 0x00884000, /* r */ 0x00884000, /* s */ 0x00884000,
/* t */ 0x00884000, /* u */ 0x00884000, /* v */ 0x00884000, /* w */ 0x00884000,
/* x */ 0x00884000, /* y */ 0x00884000, /* z */ 0x00884000, /* { */ 0x02004000,
/* | */ 0x12804000, /* } */ 0x02004000, /* ~ */ 0x0280C000, /*x7F*/ 0x00000000
};
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static unsigned char const * ag_char_map_spanners[44];
#ifndef _
# define _(_s) _s
#endif
static unsigned char const * ag_char_map_spanners[46];
/**
* Character category masks. Some categories may have multiple bits,
* if their definition incorporates other character categories.
* This mask array is only used by calc_ag_char_map_spanners().
*/
static ag_char_map_mask_t const ag_char_map_masks[44] = {
0x0000001, /* NEWLINE */
0x0000002, /* NUL_BYTE */
0x0000004, /* DIR_SEP */
0x0000008, /* PERCENT */
0x0000010, /* COMMA */
0x0000020, /* COLON */
0x0000040, /* UNDERSCORE */
0x0000080, /* PLUS */
0x0000100, /* DOLLAR */
0x0000200, /* HORIZ_WHITE */
0x0000400, /* ALT_WHITE */
0x0000601, /* WHITESPACE */
0x0000600, /* NON_NL_WHITE */
0x0000800, /* QUOTE */
0x0001000, /* PARENTHESES */
0x0002000, /* GRAPHIC */
0x0004000, /* INVERSION */
0x0008000, /* OCT_DIGIT */
0x0018000, /* DEC_DIGIT */
0x0038000, /* HEX_DIGIT */
0x0040000, /* LOWER_CASE */
0x0080000, /* UPPER_CASE */
0x00C0000, /* ALPHABETIC */
0x00D8000, /* ALPHANUMERIC */
0x00C0040, /* VAR_FIRST */
0x00D8040, /* VARIABLE_NAME */
0x01D8040, /* OPTION_NAME */
0x01D8060, /* VALUE_NAME */
0x0200000, /* NAME_SEP */
0x03D8260, /* COMPOUND_NAME */
0x0001800, /* SCHEME_NOTE */
0x0400000, /* UNQUOTABLE */
0x0800601, /* END_XML_TOKEN */
0x0000681, /* PLUS_N_SPACE */
0x1000000, /* PUNCTUATION */
0x20D8000, /* SUFFIX */
0x20D800C, /* SUFFIX_FMT */
0x4000002, /* FALSE_TYPE */
0x20D8004, /* FILE_NAME */
0x0000603, /* END_TOKEN */
0x0000613, /* END_LIST_ENTRY */
0x8000613, /* SET_SEPARATOR */
0x001C000, /* SIGNED_NUMBER */
0x0000101, /* MAKE_SCRIPT */
static ag_char_map_mask_t const ag_char_map_masks[46] = {
0x00000001, /* NEWLINE */
0x00000002, /* NUL_BYTE */
0x00000004, /* DIR_SEP */
0x00000008, /* PERCENT */
0x00000010, /* COMMA */
0x00000020, /* COLON */
0x00000040, /* UNDERSCORE */
0x00000080, /* PLUS */
0x00000100, /* DOLLAR */
0x00000200, /* OPTION_MARKER */
0x00000400, /* HORIZ_WHITE */
0x00000800, /* ALT_WHITE */
0x00000C01, /* WHITESPACE */
0x00000C00, /* NON_NL_WHITE */
0x00001000, /* QUOTE */
0x00002000, /* PARENTHESES */
0x00004000, /* GRAPHIC */
0x00008000, /* INVERSION */
0x00010000, /* OCT_DIGIT */
0x00030000, /* DEC_DIGIT */
0x00070000, /* HEX_DIGIT */
0x00080000, /* LOWER_CASE */
0x00100000, /* UPPER_CASE */
0x00180000, /* ALPHABETIC */
0x001B0000, /* ALPHANUMERIC */
0x00180040, /* VAR_FIRST */
0x001B0040, /* VARIABLE_NAME */
0x003B0040, /* OPTION_NAME */
0x003B0060, /* VALUE_NAME */
0x00400000, /* NAME_SEP */
0x007B0460, /* COMPOUND_NAME */
0x00003000, /* SCHEME_NOTE */
0x00800000, /* UNQUOTABLE */
0x01000C01, /* END_XML_TOKEN */
0x00000C81, /* PLUS_N_SPACE */
0x02000000, /* PUNCTUATION */
0x041B0000, /* SUFFIX */
0x041B000C, /* SUFFIX_FMT */
0x08000002, /* FALSE_TYPE */
0x041B0004, /* FILE_NAME */
0x00000C03, /* END_TOKEN */
0x00000C13, /* END_LIST_ENTRY */
0x10000C13, /* SET_SEPARATOR */
0x00038000, /* SIGNED_NUMBER */
0x00000101, /* MAKE_SCRIPT */
0x00000600, /* LOAD_LINE_SKIP */
};
#define lock_ag_char_map_spanners()
#define unlock_ag_char_map_spanners()
#undef LOCK_SPANNER_TABLES
static unsigned char const *
calc_ag_char_map_spanners(unsigned int mask_ix)
{
lock_ag_char_map_spanners();
if (ag_char_map_spanners[mask_ix] == NULL) {
#ifdef LOCK_SPANNER_TABLES
if (ag_char_map_spanners[mask_ix] != NULL)
return ag_char_map_spanners[mask_ix];
pthread_mutex_lock(&ag_char_map_mutex);
if (ag_char_map_spanners[mask_ix] == NULL)
#endif
{
int ix = 1;
ag_char_map_mask_t mask = ag_char_map_masks[mask_ix];
unsigned char * res = malloc(256 /* 1 << NBBY */);
if (res == NULL) {
fputs(_("no memory for char-mapper span map\n"), stderr);
exit(EXIT_FAILURE);
}
memset(res, 0, 256);
for (; ix < 128; ix++)
if (ag_char_map_table[ix] & mask)
res[ix] = 1;
ag_char_map_spanners[mask_ix] = res;
}
unlock_ag_char_map_spanners();
#ifdef LOCK_SPANNER_TABLES
pthread_mutex_unlock(&ag_char_map_mutex);
#endif
return ag_char_map_spanners[mask_ix];
}
#define ag_char_map_masks POISONED_ag_char_map_masks
@@ -448,44 +484,44 @@ is_ag_char_map_char(char ch, ag_char_map_mask_t mask)
}
static inline char *
spn_ag_char_map_chars(char * p, unsigned int mask_ix)
spn_ag_char_map_chars(char const * p, unsigned int mask_ix)
{
unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix);
while (v[(unsigned)*p]) p++;
return p;
return (char *)(uintptr_t)p;
}
static inline char *
brk_ag_char_map_chars(char * p, unsigned int mask_ix)
brk_ag_char_map_chars(char const * p, unsigned int mask_ix)
{
unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix);
while ((*p != '\0') && (! v[(unsigned)*p])) p++;
return p;
return (char *)(uintptr_t)p;
}
static inline char *
spn_ag_char_map_back(char * s, char * e, unsigned int mask_ix)
spn_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
{
unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix);
if (s >= e) e = s + strlen(s);
while ((e > s) && v[(unsigned)e[-1]]) e--;
return e;
return (char *)(uintptr_t)e;
}
static inline char *
brk_ag_char_map_back(char * s, char * e, unsigned int mask_ix)
brk_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
{
unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix);
if (s == e) e += strlen(e);
while ((e > s) && (! v[(unsigned)e[-1]])) e--;
return e;
return (char *)(uintptr_t)e;
}
#endif /* AG_CHAR_MAP_H_GUARD */

View File

@@ -2,15 +2,17 @@
/**
* \file alias.c
*
* Time-stamp: "2012-02-12 09:41:42 bkorb"
*
* Automated Options Paged Usage module.
* Handle options that are aliases for another option.
*
* @addtogroup autoopts
* @{
*/
/*
* This routine will forward an option alias to the correct option code.
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,20 +24,39 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
LOCAL tSuccess
too_many_occurrences(tOptions * opts, tOptDesc * od)
{
if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
char const * eqv = (od->optEquivIndex != NO_EQUIVALENT) ? zequiv : zNil;
fprintf(stderr, ztoo_often_fmt, opts->pzProgName);
if (od->optMaxCt > 1)
fprintf(stderr, zat_most, od->optMaxCt, od->pz_Name, eqv);
else
fprintf(stderr, zonly_one, od->pz_Name, eqv);
(*opts->pUsageProc)(opts, EXIT_FAILURE);
/* NOTREACHED */
}
return FAILURE;
}
/*=export_func optionAlias
* private:
*
* what: relay an option to its alias
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + unsigned int + alias + the aliased-to option index +
* arg: + tOptions * + opts + program options descriptor +
* arg: + tOptDesc * + old_od + the descriptor for this arg +
* arg: + unsigned int + alias + the aliased-to option index +
* ret-type: int
*
* doc:
@@ -43,63 +64,50 @@
* Returns "-1" if the aliased-to option has appeared too many times.
=*/
int
optionAlias(tOptions * pOpts, tOptDesc * pOldOD, unsigned int alias)
optionAlias(tOptions * opts, tOptDesc * old_od, unsigned int alias)
{
tOptDesc * pOD;
tOptDesc * new_od;
if (pOpts == OPTPROC_EMIT_USAGE)
if (opts <= OPTPROC_EMIT_LIMIT)
return 0;
pOD = pOpts->pOptDesc + alias;
if ((unsigned)pOpts->optCt <= alias) {
fwrite(zAliasRange, strlen (zAliasRange), 1, stderr);
new_od = opts->pOptDesc + alias;
if ((unsigned)opts->optCt <= alias) {
fputs(zbad_alias_id, stderr);
exit(EXIT_FAILURE);
}
/*
* Copy over the option instance flags
*/
pOD->fOptState &= OPTST_PERSISTENT_MASK;
pOD->fOptState |= (pOldOD->fOptState & ~OPTST_PERSISTENT_MASK);
pOD->optArg.argString = pOldOD->optArg.argString;
new_od->fOptState &= OPTST_PERSISTENT_MASK;
new_od->fOptState |= (old_od->fOptState & ~OPTST_PERSISTENT_MASK);
new_od->optArg.argString = old_od->optArg.argString;
/*
* Keep track of count only for DEFINED (command line) options.
* IF we have too many, build up an error message and bail.
*/
if ( (pOD->fOptState & OPTST_DEFINED)
&& (++pOD->optOccCt > pOD->optMaxCt) ) {
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
char const * pzEqv =
(pOD->optEquivIndex != NO_EQUIVALENT) ? zEquiv : zNil;
fputs(zErrOnly, stderr);
if (pOD->optMaxCt > 1)
fprintf(stderr, zAtMost, pOD->optMaxCt, pOD->pz_Name, pzEqv);
else
fprintf(stderr, zOnlyOne, pOD->pz_Name, pzEqv);
}
return -1;
}
if ( (new_od->fOptState & OPTST_DEFINED)
&& (++new_od->optOccCt > new_od->optMaxCt) )
return too_many_occurrences(opts, new_od);
/*
* Clear the state bits and counters
*/
pOldOD->fOptState &= OPTST_PERSISTENT_MASK;
pOldOD->optOccCt = 0;
old_od->fOptState &= OPTST_PERSISTENT_MASK;
old_od->optOccCt = 0;
/*
* If there is a procedure to call, call it
*/
if (pOD->pOptProc != NULL)
(*pOD->pOptProc)(pOpts, pOD);
if (new_od->pOptProc != NULL)
(*new_od->pOptProc)(opts, new_od);
return 0;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,16 +1,16 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
*
* DO NOT EDIT THIS FILE (ao-strs.c)
*
* It has been AutoGen-ed May 6, 2012 at 04:20:58 PM by AutoGen 5.16pre36
*
* It has been AutoGen-ed March 31, 2013 at 10:41:23 AM by AutoGen 5.17.3
* From the definitions ao-strs.def
* and the template file strings
*
* Copyright (C) 2011-2012 Bruce Korb, all rights reserved.
* Copyright (C) 2011-2013 Bruce Korb, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* Modified (3 clause) Berkeley Software Distribution License
* <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
* <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* strings IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,94 +38,181 @@
*/
#include "ao-strs.h"
char const ao_strs_strtable[6266] =
/* 0 */ " \t\n"
char const ao_strs_strtable[6637] =
/* 0 */ "-_^\0"
/* 4 */ " %s%s\n\0"
/* 12 */ "auto-options\0"
/* 25 */ "program\0"
/* 33 */ "%%-%ds %%s\n\0"
/* 45 */ "\n"
"%s\n\n\0"
/* 51 */ "=file\0"
/* 57 */ "=Mbr\0"
/* 62 */ "=Cplx\0"
/* 68 */ "[=arg]\0"
/* 75 */ "--%2$s%1$s\0"
/* 86 */ "=Tim\0"
/* 91 */ "none\0"
/* 96 */ "# preset/initialization file\n"
"# %s#\n\0"
/* 134 */ " %3s %-14s %s\0"
/* 148 */ "%s\0"
/* 151 */ "T/F\0"
/* 155 */ "\n"
"%s\n\n"
"%s\0"
/* 163 */ "Fil\0"
/* 167 */ "KWd\0"
/* 171 */ "Mbr\0"
/* 175 */ "Cpx\0"
/* 179 */ "no \0"
/* 183 */ "Num\0"
/* 187 */ "opt\0"
/* 191 */ "YES\0"
/* 195 */ "Str\0"
/* 199 */ "Tim\0"
/* 203 */ "\t\t\t\t- \0"
/* 210 */ "\t\t\t\t \0"
/* 217 */ "\t\t\t\t-- and \0"
/* 229 */ "\t\t\t\t%s\n\0"
/* 237 */ " \0"
/* 244 */ " \0"
/* 250 */ " \0"
/* 254 */ " \0"
/* 257 */ "all\0"
/* 261 */ " \t\n"
":=\0"
/* 6 */ "INVALID-%d\0"
/* 17 */ "*INVALID*\0"
/* 27 */ "none\0"
/* 32 */ " + \0"
/* 36 */ " | \0"
/* 40 */ "%s\n\0"
/* 44 */ "PAGER\0"
/* 50 */ "/tmp/use.%lu\0"
/* 63 */ "more\0"
/* 68 */ " --* )\n\0"
/* 79 */ "%s\n"
" \0"
/* 85 */ " \0"
/* 88 */ " -* )\n\0"
/* 98 */ " ;;\n\n\0"
/* 111 */ "stdout\0"
/* 118 */ "%A %B %e, %Y at %r %Z\0"
/* 140 */ "#! %s\n\0"
/* 147 */ "%s_%s=\0"
/* 154 */ "\n"
"export %s_%s\n\0"
/* 169 */ "''\0"
/* 172 */ "\\'\0"
/* 175 */ "'%s'\0"
/* 180 */ "%s_%s_%d=\0"
/* 190 */ "\n"
/* 267 */ "%s_%s_%d=\0"
/* 277 */ "''\0"
/* 280 */ " ;;\n\n\0"
/* 293 */ "'\n\n\0"
/* 297 */ "</%s>\n\0"
/* 304 */ " %s\n\0"
/* 310 */ "%%-%ds\0"
/* 317 */ "\n"
"export %s_%s_%d\n\0"
/* 208 */ "set --\0"
/* 215 */ " '%s'\0"
/* 221 */ "'\\''\0"
/* 226 */ "\n"
"OPTION_CT=0\n\0"
/* 240 */ "=%1$lu # 0x%1$lX\n\0"
/* 258 */ "true\0"
/* 263 */ "false\0"
/* 269 */ "VERSION\0"
/* 277 */ "OPT_ARG_NEEDED=OK\0"
/* 295 */ "OPT_ARG_NEEDED=NO\0"
/* 313 */ "OPT_ARG_NEEDED=YES\0"
/* 332 */ "LONGUSAGE\0"
/* 342 */ "flag\0"
/* 347 */ "%s_%s_TEXT='\0"
/* 360 */ "'\n\n\0"
/* 364 */ "option\0"
/* 371 */ "\n"
/* 335 */ "false\0"
/* 341 */ " -* )\n\0"
/* 351 */ "flag\0"
/* 356 */ "INVALID-%d\0"
/* 367 */ "*INVALID*\0"
/* 377 */ "\\n\\\n\0"
/* 382 */ " --* )\n\0"
/* 393 */ "--\0"
/* 396 */ "LONGUSAGE\0"
/* 406 */ " %s\n\0"
/* 422 */ "\\%03o\0"
/* 428 */ "more\0"
/* 433 */ "<%s type=nested>\n\0"
/* 451 */ "%s\n\0"
/* 455 */ "%s\n"
" \0"
/* 461 */ "OPT_ARG_NEEDED=NO\0"
/* 479 */ "<%s/>\n\0"
/* 486 */ "OPT_ARG_NEEDED=OK\0"
/* 504 */ "\t\0"
/* 506 */ "<%s>\0"
/* 511 */ "option\0"
/* 518 */ "\n"
"export %s_%s\n\0"
/* 533 */ "%s_%s=\0"
/* 540 */ " | \0"
/* 544 */ "PAGER\0"
/* 550 */ " + \0"
/* 554 */ " puts(_(%s));\n\0"
/* 570 */ "\\'\0"
/* 573 */ "'%s'\0"
/* 578 */ " -- %s\0"
/* 585 */ "%s_%s_TEXT='\0"
/* 598 */ "#! %s\n\0"
/* 605 */ "\n"
"env | grep '^%s_'\n\0"
/* 391 */ " -- %s\0"
/* 398 */ "--\0"
/* 401 */ "\t\t\t\t- \0"
/* 408 */ "\t\t\t\t \0"
/* 415 */ "\t\0"
/* 417 */ " * )\n"
" OPT_PROCESS=false\n"
" ;;\n"
" esac\n\0"
/* 474 */ " %s\n\0"
/* 480 */ "%%-%ds\0"
/* 487 */ "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu\0"
/* 530 */ "# # # # # # # # # # -- do not modify this marker --\n"
"#\n"
"# DO NOT EDIT THIS SECTION\n\0"
/* 613 */ "%s OF %s\n"
"#\n"
"# From here to the next `-- do not modify this marker --',\n"
"# the text has been generated %s\n\0"
/* 719 */ "# From the %s option definitions\n"
/* 625 */ "=%1$lu # 0x%1$lX\n\0"
/* 643 */ "stdout\0"
/* 650 */ "%A %B %e, %Y at %r %Z\0"
/* 672 */ "/tmp/use.%lu\0"
/* 685 */ "true\0"
/* 690 */ "<%s type=%s>\0"
/* 703 */ "VERSION\0"
/* 711 */ "#x%02X;\0"
/* 719 */ "OPT_ARG_NEEDED=YES\0"
/* 738 */ "'\\''\0"
/* 743 */ " '%s'\0"
/* 749 */ "\n"
"OPTION_CT=0\n\0"
/* 763 */ "set --\0"
/* 770 */ " ;;\n\n\0"
/* 787 */ " '%c' )\n\0"
/* 803 */ " '%s' )\n\0"
/* 819 */ " '%s' | \\\n\0"
/* 837 */ "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu\0"
/* 880 */ "<%1$s type=boolean>%2$s</%1$s>\n\0"
/* 912 */ "# From the %s option definitions\n"
"#\n\0"
/* 756 */ "\n"
"if test -z \"${%1$s_%2$s}\"\n"
"then\n"
" %1$s_%2$s_CT=0\n"
"else\n"
" %1$s_%2$s_CT=1\n"
" %1$s_%2$s_1=${%1$s_%2$s}\n"
"fi\n"
"export %1$s_%2$s_CT\0"
/* 877 */ "\n"
"%1$s_%2$s=${%1$s_%2$s-'%3$s'}\n"
"%1$s_%2$s_set=false\n"
"export %1$s_%2$s\0"
/* 945 */ "\n"
"%1$s_%2$s=${%1$s_%2$s}\n"
"%1$s_%2$s_set=false\n"
/* 949 */ "echo 'Warning: Cannot load options files' >&2\0"
/* 996 */ "echo 'Warning: Cannot save options files' >&2\0"
/* 1043 */ "echo 'Warning: Cannot suppress the loading of options files' >&2\0"
/* 1109 */ "<%1$s type=integer>0x%2$lX</%1$s>\n\0"
/* 1144 */ "%1$s_%2$s_TEXT='no %2$s text'\n\0"
/* 1175 */ "%1$s_%2$s_MODE='%3$s'\n"
"export %1$s_%2$s_MODE\n\0"
/* 1220 */ "%1$s_%2$s='%3$s'\n"
"export %1$s_%2$s\n\0"
/* 1007 */ "\n"
/* 1255 */ "%1$s_%2$s_CT=%3$d\n"
"export %1$s_%2$s_CT\n\0"
/* 1294 */ "OPTION_CT=%d\n"
"export OPTION_CT\n\0"
/* 1325 */ "%1$s_%2$s=%3$s\n"
"export %1$s_%2$s\n\0"
/* 1358 */ "%1$s_%2$s=%3$d # 0x%3$X\n"
"export %1$s_%2$s\n\0"
/* 1400 */ " case \"${OPT_CODE}\" in\n\0"
/* 1431 */ " if [ $%1$s_%2$s_CT -gt %3$u ] ; then\n"
" echo 'Error: more than %3$d %2$s options'\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n"
" fi >&2\n\0"
/* 1622 */ "test ${%1$s_%2$s_CT-0} -ge %3$u || {\n"
" echo %1$s_%2$s has not been set\n"
" exit 1\n"
"} 1>&2\n\0"
/* 1714 */ "test -n \"$%1$s_%2$s\" || {\n"
" echo %1$s_%2$s has not been set\n"
" exit 1\n"
"} 1>&2\n\0"
/* 1795 */ " echo \"$%s_%s_TEXT\"\n"
" exit 0\n\0"
/* 1846 */ "\n"
"# # # # # # # # # #\n"
"#\n"
"# END OF AUTOMATED OPTION PROCESSING\n"
"#\n"
"# # # # # # # # # # -- do not modify this marker --\n\0"
/* 1962 */ " if [ -n \"${OPT_ARG_VAL}\" ]\n"
" then\n"
" eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n"
" export %1$s_${OPT_NAME}${OPT_ELEMENT}\n"
" fi\n"
"done\n"
"OPTION_COUNT=`expr $ARG_COUNT - $#`\n"
"OPERAND_COUNT=$#\n"
"unset OPT_PROCESS || :\n"
"unset OPT_ELEMENT || :\n"
"unset OPT_ARG || :\n"
"unset OPT_ARG_NEEDED || :\n"
"unset OPT_NAME || :\n"
"unset OPT_CODE || :\n"
"unset OPT_ARG_VAL || :\n\0"
/* 2341 */ " OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n"
" shift\n"
" OPT_ARG=$1\n"
" case \"${OPT_CODE}\" in *=* )\n"
" OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n"
" OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\0"
/* 2592 */ " OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n"
" OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\0"
/* 2709 */ "\n"
"ARG_COUNT=$#\n"
"OPT_PROCESS=true\n"
"OPT_ARG=$1\n"
"while ${OPT_PROCESS} && [ $# -gt 0 ]\n"
@@ -137,89 +224,7 @@ char const ao_strs_strtable[6266] =
" OPT_PROCESS=false\n"
" shift\n"
" ;;\n\0"
/* 1201 */ "\n"
"OPT_ARG=$1\n"
"while [ $# -gt 0 ]\n"
"do\n"
" OPT_ELEMENT=''\n"
" OPT_ARG_VAL=''\n"
" OPT_ARG=${1}\n\0"
/* 1291 */ " if [ -n \"${OPT_ARG_VAL}\" ]\n"
" then\n"
" eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n"
" export %1$s_${OPT_NAME}${OPT_ELEMENT}\n"
" fi\n"
"done\n"
"unset OPT_PROCESS || :\n"
"unset OPT_ELEMENT || :\n"
"unset OPT_ARG || :\n"
"unset OPT_ARG_NEEDED || :\n"
"unset OPT_NAME || :\n"
"unset OPT_CODE || :\n"
"unset OPT_ARG_VAL || :\n"
"%2$s\0"
/* 1621 */ "\n"
"# # # # # # # # # #\n"
"#\n"
"# END OF AUTOMATED OPTION PROCESSING\n"
"#\n"
"# # # # # # # # # # -- do not modify this marker --\n\0"
/* 1737 */ " case \"${OPT_CODE}\" in\n\0"
/* 1768 */ " '%s' | \\\n\0"
/* 1786 */ " '%s' )\n\0"
/* 1802 */ " '%c' )\n\0"
/* 1818 */ " ;;\n\n\0"
/* 1835 */ " * )\n"
" echo Unknown %s: \"${OPT_CODE}\" >&2\n"
" echo \"$%s_USAGE_TEXT\"\n"
" exit 1\n"
" ;;\n"
" esac\n\n\0"
/* 1977 */ " echo \"$%s_%s_TEXT\"\n"
" exit 0\n\0"
/* 2028 */ " echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n"
" exit 0\n\0"
/* 2102 */ " %s\n\0"
/* 2118 */ " if [ $%1$s_%2$s_CT -ge %3$d ] ; then\n"
" echo Error: more than %3$d %2$s options >&2\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1 ; fi\n\0"
/* 2297 */ " %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n"
" OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n"
" OPT_NAME='%2$s'\n\0"
/* 2421 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo Error: duplicate %2$s option >&2\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1 ; fi\n"
" %1$s_%2$s_set=true\n"
" OPT_NAME='%2$s'\n\0"
/* 2668 */ " %1$s_%2$s_CT=0\n"
" OPT_ELEMENT=''\n"
" %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0"
/* 2809 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo 'Error: duplicate %2$s option' >&2\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1 ; fi\n"
" %1$s_%2$s_set=true\n"
" %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0"
/* 3116 */ " eval %1$s_%2$s${OPT_ELEMENT}=true\n"
" export %1$s_%2$s${OPT_ELEMENT}\n"
" OPT_ARG_NEEDED=OK\n\0"
/* 3236 */ " OPT_ARG_NEEDED=YES\n\0"
/* 3268 */ " eval %1$s_%2$s${OPT_ELEMENT}=true\n"
" export %1$s_%2$s${OPT_ELEMENT}\n"
" OPT_ARG_NEEDED=NO\n\0"
/* 3388 */ " OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n"
" shift\n"
" OPT_ARG=$1\n"
" case \"${OPT_CODE}\" in *=* )\n"
" OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n"
" OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\0"
/* 3639 */ " case \"${OPT_ARG_NEEDED}\" in\n"
/* 2916 */ " case \"${OPT_ARG_NEEDED}\" in\n"
" NO )\n"
" OPT_ARG_VAL=''\n"
" ;;\n"
@@ -228,10 +233,10 @@ char const ao_strs_strtable[6266] =
" then\n"
" if [ $# -eq 0 ]\n"
" then\n"
" echo No argument provided for ${OPT_NAME} option >&2\n"
" echo No argument provided for ${OPT_NAME} option\n"
" echo \"$%s_USAGE_TEXT\"\n"
" exit 1\n"
" fi\n"
" fi >&2\n"
" OPT_ARG_VAL=${OPT_ARG}\n"
" shift\n"
" OPT_ARG=$1\n"
@@ -247,9 +252,46 @@ char const ao_strs_strtable[6266] =
" fi\n"
" ;;\n"
" esac\n\0"
/* 4418 */ " OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n"
" OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\0"
/* 4535 */ " case \"${OPT_ARG_NEEDED}\" in\n"
/* 3695 */ " %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n"
" OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n"
" OPT_NAME='%2$s'\n\0"
/* 3819 */ "\n"
"if test -z \"${%1$s_%2$s}\"\n"
"then\n"
" %1$s_%2$s_CT=0\n"
" export %1$s_%2$s_CT\n"
"else\n"
" %1$s_%2$s_CT=1\n"
" %1$s_%2$s_1=${%1$s_%2$s}\n"
" export %1$s_%2$s_CT %1$s_%2$s_1\n"
"fi\n\0"
/* 3977 */ " * )\n"
" OPT_PROCESS=false\n"
" ;;\n"
" esac\n\0"
/* 4034 */ " %1$s_%2$s_CT=0\n"
" OPT_ELEMENT=''\n"
" %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0"
/* 4175 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo 'Error: duplicate %2$s option'\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n"
" fi >&2\n"
" %1$s_%2$s_set=true\n"
" %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0"
/* 4492 */ "\n"
"ARG_COUNT=$#\n"
"OPT_ARG=$1\n"
"while [ $# -gt 0 ]\n"
"do\n"
" OPT_ELEMENT=''\n"
" OPT_ARG_VAL=''\n"
" OPT_ARG=${1}\n\0"
/* 4595 */ " case \"${OPT_ARG_NEEDED}\" in\n"
" NO )\n"
" if [ -n \"${OPT_ARG}\" ]\n"
" then\n"
@@ -266,10 +308,10 @@ char const ao_strs_strtable[6266] =
" else\n"
" if [ $# -eq 0 ]\n"
" then\n"
" echo No argument provided for ${OPT_NAME} option >&2\n"
" echo No argument provided for ${OPT_NAME} option\n"
" echo \"$%s_USAGE_TEXT\"\n"
" exit 1\n"
" fi\n"
" fi >&2\n"
" shift\n"
" OPT_ARG_VAL=$1\n"
" fi\n"
@@ -294,30 +336,37 @@ char const ao_strs_strtable[6266] =
" fi\n"
" ;;\n"
" esac\n\0"
/* 5689 */ "%1$s_%2$s=%3$d # 0x%3$X\n"
/* 5749 */ " echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n"
" exit 0\n\0"
/* 5823 */ "%s OF %s\n"
"#\n"
"# From here to the next `-- do not modify this marker --',\n"
"# the text has been generated %s\n\0"
/* 5929 */ " eval %1$s_%2$s${OPT_ELEMENT}=true\n"
" export %1$s_%2$s${OPT_ELEMENT}\n\0"
/* 6019 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo 'Error: duplicate %2$s option'\n"
" echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n"
" fi >&2\n"
" %1$s_%2$s_set=true\n"
" OPT_NAME='%2$s'\n\0"
/* 6278 */ "\n"
"%1$s_%2$s=${%1$s_%2$s-'%3$s'}\n"
"%1$s_%2$s_set=false\n"
"export %1$s_%2$s\n\0"
/* 5731 */ "%1$s_%2$s_CT=%3$d\n"
"export %1$s_%2$s_CT\n\0"
/* 5770 */ "OPTION_CT=%d\n"
"export OPTION_CT\n\0"
/* 5801 */ "%1$s_%2$s=%3$s\n"
/* 6347 */ "\n"
"%1$s_%2$s=${%1$s_%2$s}\n"
"%1$s_%2$s_set=false\n"
"export %1$s_%2$s\n\0"
/* 5834 */ "%1$s_%2$s='%3$s'\n"
"export %1$s_%2$s\n\0"
/* 5869 */ "%1$s_%2$s_MODE='%3$s'\n"
"export %1$s_%2$s_MODE\n\0"
/* 5914 */ "echo 'Warning: Cannot load options files' >&2\0"
/* 5961 */ "echo 'Warning: Cannot save options files' >&2\0"
/* 6008 */ "echo 'Warning: Cannot suppress the loading of options files' >&2\0"
/* 6074 */ "%1$s_%2$s_TEXT='no %2$s text'\n\0"
/* 6105 */ "%s WARNING: cannot save options - \0"
/* 6141 */ "<%s/>\n\0"
/* 6148 */ "<%s>\0"
/* 6153 */ "</%s>\n\0"
/* 6160 */ "<%s type=%s>\0"
/* 6173 */ "<%s type=nested>\n\0"
/* 6191 */ "#x%02X;\0"
/* 6199 */ "<%1$s type=boolean>%2$s</%1$s>\n\0"
/* 6231 */ "<%1$s type=integer>0x%2$lX</%1$s>\n";
/* 6409 */ "# # # # # # # # # # -- do not modify this marker --\n"
"#\n"
"# DO NOT EDIT THIS SECTION\n\0"
/* 6492 */ " * )\n"
" echo Unknown %s: \"${OPT_CODE}\" >&2\n"
" echo \"$%s_USAGE_TEXT\" >&2\n"
" exit 1\n"
" ;;\n"
" esac\n";
/* end of ao-strs.c */

View File

@@ -1,16 +1,16 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
*
* DO NOT EDIT THIS FILE (ao-strs.h)
*
* It has been AutoGen-ed May 6, 2012 at 04:20:58 PM by AutoGen 5.16pre36
*
* It has been AutoGen-ed March 31, 2013 at 10:41:23 AM by AutoGen 5.17.3
* From the definitions ao-strs.def
* and the template file strings
*
* Copyright (C) 2011-2012 Bruce Korb, all rights reserved.
* Copyright (C) 2011-2013 Bruce Korb, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* Modified (3 clause) Berkeley Software Distribution License
* <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
* <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* strings IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,213 +39,288 @@
#ifndef STRINGS_AO_STRS_H_GUARD
#define STRINGS_AO_STRS_H_GUARD 1
/*
* 102 strings in ao_strs_strtable string table
* 140 strings in ao_strs_strtable string table
*/
#define ARG_BREAK_STR (ao_strs_strtable+0)
#define ARG_BREAK_STR_LEN 5
#define INVALID_FMT (ao_strs_strtable+6)
#define INVALID_FMT_LEN 10
#define INVALID_STR (ao_strs_strtable+17)
#define INVALID_STR_LEN 9
#define NONE_STR (ao_strs_strtable+27)
#define NONE_STR_LEN 4
#define PLUS_STR (ao_strs_strtable+32)
#define PLUS_STR_LEN 3
#define OR_STR (ao_strs_strtable+36)
#define OR_STR_LEN 3
#define NLSTR_FMT (ao_strs_strtable+40)
#define NLSTR_FMT_LEN 3
#define PAGER_NAME (ao_strs_strtable+44)
#define PAGER_NAME_LEN 5
#define TMP_USAGE_FMT (ao_strs_strtable+50)
#define TMP_USAGE_FMT_LEN 12
#define MORE_STR (ao_strs_strtable+63)
#define MORE_STR_LEN 4
#define LONG_OPT_MARK (ao_strs_strtable+68)
#define LONG_OPT_MARK_LEN 10
#define NLSTR_SPACE_FMT (ao_strs_strtable+79)
#define NLSTR_SPACE_FMT_LEN 5
#define TWO_SPACES_STR (ao_strs_strtable+85)
#define TWO_SPACES_STR_LEN 2
#define FLAG_OPT_MARK (ao_strs_strtable+88)
#define FLAG_OPT_MARK_LEN 9
#define END_OPT_SEL_STR (ao_strs_strtable+98)
#define END_OPT_SEL_STR_LEN 12
#define STDOUT (ao_strs_strtable+111)
#define STDOUT_LEN 6
#define TIME_FMT (ao_strs_strtable+118)
#define TIME_FMT_LEN 21
#define SHELL_MAGIC (ao_strs_strtable+140)
#define SHELL_MAGIC_LEN 6
#define OPT_VAL_FMT (ao_strs_strtable+147)
#define OPT_VAL_FMT_LEN 6
#define OPT_END_FMT (ao_strs_strtable+154)
#define OPT_END_FMT_LEN 14
#define EMPTY_ARG (ao_strs_strtable+169)
#define EMPTY_ARG_LEN 2
#define QUOT_APOS (ao_strs_strtable+172)
#define QUOT_APOS_LEN 2
#define QUOT_ARG_FMT (ao_strs_strtable+175)
#define QUOT_ARG_FMT_LEN 4
#define ARG_BY_NUM_FMT (ao_strs_strtable+180)
#define ARG_BY_NUM_FMT_LEN 9
#define EXPORT_ARG_FMT (ao_strs_strtable+190)
#define EXPORT_ARG_FMT_LEN 17
#define set_dash (ao_strs_strtable+208)
#define set_dash_LEN 6
#define arg_fmt (ao_strs_strtable+215)
#define arg_fmt_LEN 5
#define apostrophy (ao_strs_strtable+221)
#define apostrophy_LEN 4
#define init_optct (ao_strs_strtable+226)
#define init_optct_LEN 13
#define SHOW_VAL_FMT (ao_strs_strtable+240)
#define SHOW_VAL_FMT_LEN 17
#define TRUE_STR (ao_strs_strtable+258)
#define TRUE_STR_LEN 4
#define FALSE_STR (ao_strs_strtable+263)
#define FALSE_STR_LEN 5
#define VER_STR (ao_strs_strtable+269)
#define VER_STR_LEN 7
#define OK_NEED_OPT_ARG (ao_strs_strtable+277)
#define OK_NEED_OPT_ARG_LEN 17
#define NO_ARG_NEEDED (ao_strs_strtable+295)
#define NO_ARG_NEEDED_LEN 17
#define YES_NEED_OPT_ARG (ao_strs_strtable+313)
#define YES_NEED_OPT_ARG_LEN 18
#define LONG_USE_STR (ao_strs_strtable+332)
#define LONG_USE_STR_LEN 9
#define FLAG_STR (ao_strs_strtable+342)
#define FLAG_STR_LEN 4
#define SET_TEXT_FMT (ao_strs_strtable+347)
#define SET_TEXT_FMT_LEN 12
#define END_SET_TEXT (ao_strs_strtable+360)
#define END_SET_TEXT_LEN 3
#define OPTION_STR (ao_strs_strtable+364)
#define OPTION_STR_LEN 6
#define SHOW_PROG_ENV (ao_strs_strtable+371)
#define SHOW_PROG_ENV_LEN 19
#define SET_OFF_FMT (ao_strs_strtable+391)
#define SET_OFF_FMT_LEN 6
#define LONG_OPT_MARKER (ao_strs_strtable+398)
#define LONG_OPT_MARKER_LEN 2
#define BULLET_STR (ao_strs_strtable+401)
#define BULLET_STR_LEN 6
#define DEEP_INDENT_STR (ao_strs_strtable+408)
#define DEEP_INDENT_STR_LEN 6
#define ONE_TAB_STR (ao_strs_strtable+415)
#define ONE_TAB_STR_LEN 1
#define NOT_FOUND_STR (ao_strs_strtable+417)
#define NOT_FOUND_STR_LEN 56
#define ENUM_ERR_SEP_LINE_FMT (ao_strs_strtable+474)
#define ENUM_ERR_SEP_LINE_FMT_LEN 5
#define ENUM_ERR_STR_WIDTH_FMT (ao_strs_strtable+480)
#define ENUM_ERR_STR_WIDTH_FMT_LEN 6
#define PAGE_USAGE_FMT (ao_strs_strtable+487)
#define PAGE_USAGE_FMT_LEN 42
#define START_MARK (ao_strs_strtable+530)
#define START_MARK_LEN 82
#define PREAMBLE_FMT (ao_strs_strtable+613)
#define PREAMBLE_FMT_LEN 105
#define END_PRE_FMT (ao_strs_strtable+719)
#define END_PRE_FMT_LEN 36
#define MULTI_DEF_FMT (ao_strs_strtable+756)
#define MULTI_DEF_FMT_LEN 120
#define SGL_DEF_FMT (ao_strs_strtable+877)
#define SGL_DEF_FMT_LEN 67
#define SGL_NO_DEF_FMT (ao_strs_strtable+945)
#define SGL_NO_DEF_FMT_LEN 61
#define LOOP_STR (ao_strs_strtable+1007)
#define LOOP_STR_LEN 193
#define ONLY_OPTS_LOOP (ao_strs_strtable+1201)
#define ONLY_OPTS_LOOP_LEN 89
#define zLoopEnd (ao_strs_strtable+1291)
#define zLoopEnd_LEN 329
#define END_MARK (ao_strs_strtable+1621)
#define END_MARK_LEN 115
#define zOptionCase (ao_strs_strtable+1737)
#define zOptionCase_LEN 30
#define zOptionPartName (ao_strs_strtable+1768)
#define zOptionPartName_LEN 17
#define zOptionFullName (ao_strs_strtable+1786)
#define zOptionFullName_LEN 15
#define zOptionFlag (ao_strs_strtable+1802)
#define zOptionFlag_LEN 15
#define zOptionEndSelect (ao_strs_strtable+1818)
#define zOptionEndSelect_LEN 16
#define UNK_OPT_FMT (ao_strs_strtable+1835)
#define UNK_OPT_FMT_LEN 141
#define zTextExit (ao_strs_strtable+1977)
#define zTextExit_LEN 50
#define zPagedUsageExit (ao_strs_strtable+2028)
#define zPagedUsageExit_LEN 73
#define zCmdFmt (ao_strs_strtable+2102)
#define zCmdFmt_LEN 15
#define zCountTest (ao_strs_strtable+2118)
#define zCountTest_LEN 178
#define MULTI_ARG_FMT (ao_strs_strtable+2297)
#define MULTI_ARG_FMT_LEN 123
#define SGL_ARG_FMT (ao_strs_strtable+2421)
#define SGL_ARG_FMT_LEN 246
#define NO_MULTI_ARG_FMT (ao_strs_strtable+2668)
#define NO_MULTI_ARG_FMT_LEN 140
#define NO_SGL_ARG_FMT (ao_strs_strtable+2809)
#define NO_SGL_ARG_FMT_LEN 306
#define zMayArg (ao_strs_strtable+3116)
#define zMayArg_LEN 119
#define zMustArg (ao_strs_strtable+3236)
#define zMustArg_LEN 31
#define zCantArg (ao_strs_strtable+3268)
#define zCantArg_LEN 119
#define INIT_LOPT_STR (ao_strs_strtable+3388)
#define INIT_LOPT_STR_LEN 250
#define LOPT_ARG_FMT (ao_strs_strtable+3639)
#define LOPT_ARG_FMT_LEN 778
#define INIT_OPT_STR (ao_strs_strtable+4418)
#define INIT_OPT_STR_LEN 116
#define OPT_ARG_FMT (ao_strs_strtable+4535)
#define OPT_ARG_FMT_LEN 1153
#define zOptNumFmt (ao_strs_strtable+5689)
#define zOptNumFmt_LEN 41
#define zOptCookieCt (ao_strs_strtable+5731)
#define zOptCookieCt_LEN 38
#define zOptCtFmt (ao_strs_strtable+5770)
#define zOptCtFmt_LEN 30
#define zOptDisabl (ao_strs_strtable+5801)
#define zOptDisabl_LEN 32
#define zFullOptFmt (ao_strs_strtable+5834)
#define zFullOptFmt_LEN 34
#define zEquivMode (ao_strs_strtable+5869)
#define zEquivMode_LEN 44
#define NO_LOAD_WARN (ao_strs_strtable+5914)
#define NO_LOAD_WARN_LEN 46
#define NO_SAVE_OPTS (ao_strs_strtable+5961)
#define NO_SAVE_OPTS_LEN 46
#define NO_SUPPRESS_LOAD (ao_strs_strtable+6008)
#define NO_SUPPRESS_LOAD_LEN 65
#define SET_NO_TEXT_FMT (ao_strs_strtable+6074)
#define SET_NO_TEXT_FMT_LEN 30
#define SAVE_WARN (ao_strs_strtable+6105)
#define SAVE_WARN_LEN 35
#define OPEN_CLOSE_FMT (ao_strs_strtable+6141)
#define OPEN_CLOSE_FMT_LEN 6
#define OPEN_XML_FMT (ao_strs_strtable+6148)
#define OPEN_XML_FMT_LEN 4
#define END_XML_FMT (ao_strs_strtable+6153)
#define END_XML_FMT_LEN 6
#define TYPE_ATR_FMT (ao_strs_strtable+6160)
#define TYPE_ATR_FMT_LEN 12
#define NULL_ATR_FMT (ao_strs_strtable+6141)
#define NULL_ATR_FMT_LEN 6
#define NESTED_OPT_FMT (ao_strs_strtable+6173)
#define NESTED_OPT_FMT_LEN 17
#define XML_HEX_BYTE_FMT (ao_strs_strtable+6191)
#define XML_HEX_BYTE_FMT_LEN 7
#define BOOL_ATR_FMT (ao_strs_strtable+6199)
#define BOOL_ATR_FMT_LEN 31
#define NUMB_ATR_FMT (ao_strs_strtable+6231)
#define NUMB_ATR_FMT_LEN 34
extern char const ao_strs_strtable[6266];
#define ARG_BREAK_STR (ao_strs_strtable+261)
#define ARG_BREAK_STR_LEN 5
#define ARG_BY_NUM_FMT (ao_strs_strtable+267)
#define ARG_BY_NUM_FMT_LEN 9
#define BOOL_ATR_FMT (ao_strs_strtable+880)
#define BOOL_ATR_FMT_LEN 31
#define CHK_MAX_COUNT (ao_strs_strtable+1431)
#define CHK_MAX_COUNT_LEN 190
#define CHK_MIN_COUNT (ao_strs_strtable+1622)
#define CHK_MIN_COUNT_LEN 91
#define CHK_ONE_REQUIRED (ao_strs_strtable+1714)
#define CHK_ONE_REQUIRED_LEN 80
#define ECHO_N_EXIT (ao_strs_strtable+1795)
#define ECHO_N_EXIT_LEN 50
#define EMPTY_ARG (ao_strs_strtable+277)
#define EMPTY_ARG_LEN 2
#define END_MARK (ao_strs_strtable+1846)
#define END_MARK_LEN 115
#define END_OPT_SEL_STR (ao_strs_strtable+280)
#define END_OPT_SEL_STR_LEN 12
#define END_PRE_FMT (ao_strs_strtable+912)
#define END_PRE_FMT_LEN 36
#define END_SET_TEXT (ao_strs_strtable+293)
#define END_SET_TEXT_LEN 3
#define END_XML_FMT (ao_strs_strtable+297)
#define END_XML_FMT_LEN 6
#define ENUM_ERR_LINE (ao_strs_strtable+304)
#define ENUM_ERR_LINE_LEN 5
#define ENUM_ERR_WIDTH (ao_strs_strtable+310)
#define ENUM_ERR_WIDTH_LEN 6
#define EXPORT_ARG_FMT (ao_strs_strtable+317)
#define EXPORT_ARG_FMT_LEN 17
#define FALSE_STR (ao_strs_strtable+335)
#define FALSE_STR_LEN 5
#define FINISH_LOOP (ao_strs_strtable+1962)
#define FINISH_LOOP_LEN 378
#define FLAG_OPT_MARK (ao_strs_strtable+341)
#define FLAG_OPT_MARK_LEN 9
#define FLAG_STR (ao_strs_strtable+351)
#define FLAG_STR_LEN 4
#define INIT_LOPT_STR (ao_strs_strtable+2341)
#define INIT_LOPT_STR_LEN 250
#define INIT_OPT_STR (ao_strs_strtable+2592)
#define INIT_OPT_STR_LEN 116
#define INVALID_FMT (ao_strs_strtable+356)
#define INVALID_FMT_LEN 10
#define INVALID_STR (ao_strs_strtable+367)
#define INVALID_STR_LEN 9
#define LINE_SPLICE (ao_strs_strtable+377)
#define LINE_SPLICE_LEN 4
#define LONG_OPT_MARK (ao_strs_strtable+382)
#define LONG_OPT_MARKER (ao_strs_strtable+393)
#define LONG_OPT_MARKER_LEN 2
#define LONG_OPT_MARK_LEN 10
#define LONG_USE_STR (ao_strs_strtable+396)
#define LONG_USE_STR_LEN 9
#define LOOP_STR (ao_strs_strtable+2709)
#define LOOP_STR_LEN 206
#define LOPT_ARG_FMT (ao_strs_strtable+2916)
#define LOPT_ARG_FMT_LEN 778
#define LVL3_CMD (ao_strs_strtable+406)
#define LVL3_CMD_LEN 15
#define MK_STR_OCT_FMT (ao_strs_strtable+422)
#define MK_STR_OCT_FMT_LEN 5
#define MORE_STR (ao_strs_strtable+428)
#define MORE_STR_LEN 4
#define MULTI_ARG_FMT (ao_strs_strtable+3695)
#define MULTI_ARG_FMT_LEN 123
#define MULTI_DEF_FMT (ao_strs_strtable+3819)
#define MULTI_DEF_FMT_LEN 157
#define NESTED_OPT_FMT (ao_strs_strtable+433)
#define NESTED_OPT_FMT_LEN 17
#define NLSTR_FMT (ao_strs_strtable+451)
#define NLSTR_FMT_LEN 3
#define NLSTR_SPACE_FMT (ao_strs_strtable+455)
#define NLSTR_SPACE_FMT_LEN 5
#define NONE_STR (ao_strs_strtable+91)
#define NONE_STR_LEN 4
#define NOT_FOUND_STR (ao_strs_strtable+3977)
#define NOT_FOUND_STR_LEN 56
#define NO_ARG_NEEDED (ao_strs_strtable+461)
#define NO_ARG_NEEDED_LEN 17
#define NO_LOAD_WARN (ao_strs_strtable+949)
#define NO_LOAD_WARN_LEN 46
#define NO_MULTI_ARG_FMT (ao_strs_strtable+4034)
#define NO_MULTI_ARG_FMT_LEN 140
#define NO_SAVE_OPTS (ao_strs_strtable+996)
#define NO_SAVE_OPTS_LEN 46
#define NO_SGL_ARG_FMT (ao_strs_strtable+4175)
#define NO_SGL_ARG_FMT_LEN 316
#define NO_SUPPRESS_LOAD (ao_strs_strtable+1043)
#define NO_SUPPRESS_LOAD_LEN 65
#define NULL_ATR_FMT (ao_strs_strtable+479)
#define NULL_ATR_FMT_LEN 6
#define NUMB_ATR_FMT (ao_strs_strtable+1109)
#define NUMB_ATR_FMT_LEN 34
#define OK_NEED_OPT_ARG (ao_strs_strtable+486)
#define OK_NEED_OPT_ARG_LEN 17
#define ONE_TAB_STR (ao_strs_strtable+504)
#define ONE_TAB_STR_LEN 1
#define ONLY_OPTS_LOOP (ao_strs_strtable+4492)
#define ONLY_OPTS_LOOP_LEN 102
#define OPEN_CLOSE_FMT (ao_strs_strtable+479)
#define OPEN_CLOSE_FMT_LEN 6
#define OPEN_XML_FMT (ao_strs_strtable+506)
#define OPEN_XML_FMT_LEN 4
#define OPTION_STR (ao_strs_strtable+511)
#define OPTION_STR_LEN 6
#define OPT_ARG_FMT (ao_strs_strtable+4595)
#define OPT_ARG_FMT_LEN 1153
#define OPT_END_FMT (ao_strs_strtable+518)
#define OPT_END_FMT_LEN 14
#define OPT_VAL_FMT (ao_strs_strtable+533)
#define OPT_VAL_FMT_LEN 6
#define OR_STR (ao_strs_strtable+540)
#define OR_STR_LEN 3
#define PAGER_NAME (ao_strs_strtable+544)
#define PAGER_NAME_LEN 5
#define PAGE_USAGE_FMT (ao_strs_strtable+837)
#define PAGE_USAGE_FMT (ao_strs_strtable+837)
#define PAGE_USAGE_FMT_LEN 42
#define PAGE_USAGE_FMT_LEN 42
#define PAGE_USAGE_TEXT (ao_strs_strtable+5749)
#define PAGE_USAGE_TEXT_LEN 73
#define PLUS_STR (ao_strs_strtable+550)
#define PLUS_STR_LEN 3
#define PREAMBLE_FMT (ao_strs_strtable+5823)
#define PREAMBLE_FMT_LEN 105
#define PUTS_FMT (ao_strs_strtable+554)
#define PUTS_FMT_LEN 15
#define QUOT_APOS (ao_strs_strtable+570)
#define QUOT_APOS_LEN 2
#define QUOT_ARG_FMT (ao_strs_strtable+573)
#define QUOT_ARG_FMT_LEN 4
#define SET_MULTI_ARG (ao_strs_strtable+5929)
#define SET_MULTI_ARG_LEN 89
#define SET_NO_TEXT_FMT (ao_strs_strtable+1144)
#define SET_NO_TEXT_FMT_LEN 30
#define SET_OFF_FMT (ao_strs_strtable+578)
#define SET_OFF_FMT_LEN 6
#define SET_TEXT_FMT (ao_strs_strtable+585)
#define SET_TEXT_FMT_LEN 12
#define SGL_ARG_FMT (ao_strs_strtable+6019)
#define SGL_ARG_FMT_LEN 258
#define SGL_DEF_FMT (ao_strs_strtable+6278)
#define SGL_DEF_FMT_LEN 68
#define SGL_NO_DEF_FMT (ao_strs_strtable+6347)
#define SGL_NO_DEF_FMT_LEN 61
#define SHELL_MAGIC (ao_strs_strtable+598)
#define SHELL_MAGIC_LEN 6
#define SHOW_PROG_ENV (ao_strs_strtable+605)
#define SHOW_PROG_ENV_LEN 19
#define SHOW_VAL_FMT (ao_strs_strtable+625)
#define SHOW_VAL_FMT_LEN 17
#define START_MARK (ao_strs_strtable+6409)
#define START_MARK_LEN 82
#define STDOUT (ao_strs_strtable+643)
#define STDOUT_LEN 6
#define TIME_FMT (ao_strs_strtable+650)
#define TIME_FMT_LEN 21
#define TMP_USAGE_FMT (ao_strs_strtable+672)
#define TMP_USAGE_FMT_LEN 12
#define TRUE_STR (ao_strs_strtable+685)
#define TRUE_STR_LEN 4
#define TWO_SPACES_STR (ao_strs_strtable+254)
#define TWO_SPACES_STR_LEN 2
#define TYPE_ATR_FMT (ao_strs_strtable+690)
#define TYPE_ATR_FMT_LEN 12
#define UNK_OPT_FMT (ao_strs_strtable+6492)
#define UNK_OPT_FMT_LEN 144
#define VER_STR (ao_strs_strtable+703)
#define VER_STR_LEN 7
#define XML_HEX_BYTE_FMT (ao_strs_strtable+711)
#define XML_HEX_BYTE_FMT_LEN 7
#define YES_NEED_OPT_ARG (ao_strs_strtable+719)
#define YES_NEED_OPT_ARG_LEN 18
#define apostrophe (ao_strs_strtable+738)
#define apostrophe_LEN 4
#define arg_fmt (ao_strs_strtable+743)
#define arg_fmt_LEN 5
#define init_optct (ao_strs_strtable+749)
#define init_optct_LEN 13
#define set_dash (ao_strs_strtable+763)
#define set_dash_LEN 6
#define zAll (ao_strs_strtable+257)
#define zAll_LEN 3
#define zCfgAO_Flags (ao_strs_strtable+12)
#define zCfgAO_Flags_LEN 12
#define zCfgProg (ao_strs_strtable+25)
#define zCfgProg_LEN 7
#define zEquivMode (ao_strs_strtable+1175)
#define zEquivMode_LEN 44
#define zFiveSpaces (ao_strs_strtable+244)
#define zFiveSpaces_LEN 5
#define zFmtFmt (ao_strs_strtable+33)
#define zFmtFmt_LEN 11
#define zFullOptFmt (ao_strs_strtable+1220)
#define zFullOptFmt_LEN 34
#define zGnuBreak (ao_strs_strtable+45)
#define zGnuBreak_LEN 5
#define zGnuFileArg (ao_strs_strtable+51)
#define zGnuFileArg_LEN 5
#define zGnuKeyLArg (ao_strs_strtable+57)
#define zGnuKeyLArg_LEN 4
#define zGnuNestArg (ao_strs_strtable+62)
#define zGnuNestArg_LEN 5
#define zGnuOptArg (ao_strs_strtable+68)
#define zGnuOptArg_LEN 6
#define zGnuOptFmt (ao_strs_strtable+75)
#define zGnuOptFmt_LEN 10
#define zGnuTimeArg (ao_strs_strtable+86)
#define zGnuTimeArg_LEN 4
#define zNone (ao_strs_strtable+91)
#define zNone_LEN 4
#define zOptCookieCt (ao_strs_strtable+1255)
#define zOptCookieCt_LEN 38
#define zOptCtFmt (ao_strs_strtable+1294)
#define zOptCtFmt_LEN 30
#define zOptDisabl (ao_strs_strtable+1325)
#define zOptDisabl_LEN 32
#define zOptNumFmt (ao_strs_strtable+1358)
#define zOptNumFmt_LEN 41
#define zOptionCase (ao_strs_strtable+1400)
#define zOptionCase_LEN 30
#define zOptionEndSelect (ao_strs_strtable+770)
#define zOptionEndSelect_LEN 16
#define zOptionFlag (ao_strs_strtable+787)
#define zOptionFlag_LEN 15
#define zOptionFullName (ao_strs_strtable+803)
#define zOptionFullName_LEN 15
#define zOptionPartName (ao_strs_strtable+819)
#define zOptionPartName_LEN 17
#define zPresetFile (ao_strs_strtable+96)
#define zPresetFile_LEN 37
#define zReqOptFmt (ao_strs_strtable+134)
#define zReqOptFmt_LEN 13
#define zSepChars (ao_strs_strtable+0)
#define zSepChars_LEN 3
#define zShrtGnuOptFmt (ao_strs_strtable+148)
#define zShrtGnuOptFmt_LEN 2
#define zSixSpaces (ao_strs_strtable+237)
#define zSixSpaces_LEN 6
#define zStdBoolArg (ao_strs_strtable+151)
#define zStdBoolArg_LEN 3
#define zStdBreak (ao_strs_strtable+155)
#define zStdBreak_LEN 7
#define zStdFileArg (ao_strs_strtable+163)
#define zStdFileArg_LEN 3
#define zStdKeyArg (ao_strs_strtable+167)
#define zStdKeyArg_LEN 3
#define zStdKeyLArg (ao_strs_strtable+171)
#define zStdKeyLArg_LEN 3
#define zStdNestArg (ao_strs_strtable+175)
#define zStdNestArg_LEN 3
#define zStdNoArg (ao_strs_strtable+179)
#define zStdNoArg_LEN 3
#define zStdNumArg (ao_strs_strtable+183)
#define zStdNumArg_LEN 3
#define zStdOptArg (ao_strs_strtable+187)
#define zStdOptArg_LEN 3
#define zStdReqArg (ao_strs_strtable+191)
#define zStdReqArg_LEN 3
#define zStdStrArg (ao_strs_strtable+195)
#define zStdStrArg_LEN 3
#define zStdTimeArg (ao_strs_strtable+199)
#define zStdTimeArg_LEN 3
#define zTabHyp (ao_strs_strtable+203)
#define zTabHypAnd (ao_strs_strtable+217)
#define zTabHypAnd_LEN 11
#define zTabHyp_LEN 6
#define zTabSpace (ao_strs_strtable+210)
#define zTabSpace_LEN 6
#define zTabout (ao_strs_strtable+229)
#define zTabout_LEN 7
#define zThreeSpaces (ao_strs_strtable+250)
#define zThreeSpaces_LEN 3
#define zTwoSpaces (ao_strs_strtable+254)
#define zTwoSpaces_LEN 2
#define zambig_file (ao_strs_strtable+4)
#define zambig_file_LEN 7
extern char const ao_strs_strtable[6637];
#endif /* STRINGS_AO_STRS_H_GUARD */

View File

@@ -2,16 +2,18 @@
/**
* \file autoopts.c
*
* Time-stamp: "2012-03-04 19:44:56 bkorb"
*
* This file contains all of the routines that must be linked into
* an executable to use the generated option processing. The optional
* routines are in separately compiled modules so that they will not
* necessarily be linked in.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -23,11 +25,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef PKGDATADIR
@@ -45,104 +47,98 @@ static tePagerState pagerState = PAGER_STATE_INITIAL;
FILE * option_usage_fp = NULL;
/* = = = START-STATIC-FORWARD = = = */
static tSuccess
next_opt_arg_must(tOptions * pOpts, tOptState* pOptState);
static tSuccess
next_opt_arg_may(tOptions * pOpts, tOptState * pOptState);
static tSuccess
next_opt_arg_none(tOptions * pOpts, tOptState* pOptState);
static tSuccess
next_opt(tOptions * pOpts, tOptState * pOptState);
static tSuccess
doPresets(tOptions * pOpts);
/* = = = END-STATIC-FORWARD = = = */
/**
* The number of tab characters to skip when printing continuation lines.
*/
static unsigned int tab_skip_ct = 0;
LOCAL void *
ao_malloc(size_t sz)
{
void * res = malloc(sz);
if (res == NULL) {
fprintf(stderr, zAO_Alloc, (int)sz);
fprintf(stderr, zalloc_fail, (int)sz);
exit(EXIT_FAILURE);
}
return res;
}
#undef malloc
#define malloc(_s) ao_malloc(_s)
#define malloc(_s) ao_malloc(_s)
LOCAL void *
ao_realloc(void *p, size_t sz)
{
void * res = (p == NULL) ? malloc(sz) : realloc(p, sz);
if (res == NULL) {
fprintf(stderr, zAO_Realloc, (int)sz, p);
fprintf(stderr, zrealloc_fail, (int)sz, p);
exit(EXIT_FAILURE);
}
return res;
}
#undef realloc
#define realloc(_p,_s) ao_realloc(_p,_s)
#define realloc(_p,_s) ao_realloc(_p,_s)
LOCAL char *
ao_strdup(char const *str)
{
char * res = strdup(str);
if (res == NULL) {
fprintf(stderr, zAO_Strdup, (int)strlen(str));
fprintf(stderr, zalloc_fail, (int)strlen(str));
exit(EXIT_FAILURE);
}
return res;
}
#undef strdup
#define strdup(_p) ao_strdup(_p)
#define strdup(_p) ao_strdup(_p)
#ifndef HAVE_PATHFIND
# define pathfind(_p, _n, _m) option_pathfind(_p, _n, _m)
# include "compat/pathfind.c"
#endif
#ifndef HAVE_SNPRINTF
# define vsnprintf option_vsnprintf
# define snprintf option_snprintf
# include "compat/snprintf.c"
#endif
#ifndef HAVE_STRDUP
# define strdup(_s) option_strdup(_s)
# include "compat/strdup.c"
#endif
#ifndef HAVE_STRCHR
# define strrchr(_s, _c) option_strrchr(_s, _c)
# define strchr(_s, _c) option_strchr(_s, _c)
# include "compat/strchr.c"
#endif
/*
* handle_opt
/**
* handle an option.
*
* This routine handles equivalencing, sets the option state flags and
* invokes the handler procedure, if any.
*/
LOCAL tSuccess
handle_opt(tOptions * pOpts, tOptState* pOptState)
handle_opt(tOptions * opts, tOptState * o_st)
{
/*
* Save a copy of the option procedure pointer.
* If this is an equivalence class option, we still want this proc.
*/
tOptDesc* pOD = pOptState->pOD;
tOptProc* pOP = pOD->pOptProc;
if (pOD->fOptState & OPTST_ALLOC_ARG)
AGFREE(pOD->optArg.argString);
tOptDesc * od = o_st->pOD;
tOptProc * opt_proc = od->pOptProc;
if (od->fOptState & OPTST_ALLOC_ARG)
AGFREE(od->optArg.argString);
pOD->optArg.argString = pOptState->pzOptArg;
od->optArg.argString = o_st->pzOptArg;
/*
* IF we are presetting options, then we will ignore any un-presettable
* options. They are the ones either marked as such.
*/
if ( ((pOpts->fOptSet & OPTPROC_PRESETTING) != 0)
&& ((pOD->fOptState & OPTST_NO_INIT) != 0)
if ( ((opts->fOptSet & OPTPROC_PRESETTING) != 0)
&& ((od->fOptState & OPTST_NO_INIT) != 0)
)
return PROBLEM;
@@ -150,19 +146,19 @@ handle_opt(tOptions * pOpts, tOptState* pOptState)
* IF this is an equivalence class option,
* THEN
* Save the option value that got us to this option
* entry. (It may not be pOD->optChar[0], if this is an
* entry. (It may not be od->optChar[0], if this is an
* equivalence entry.)
* set the pointer to the equivalence class base
*/
if (pOD->optEquivIndex != NO_EQUIVALENT) {
tOptDesc* p = pOpts->pOptDesc + pOD->optEquivIndex;
if (od->optEquivIndex != NO_EQUIVALENT) {
tOptDesc * eqv_od = opts->pOptDesc + od->optEquivIndex;
/*
* IF the current option state has not been defined (set on the
* command line), THEN we will allow continued resetting of
* the value. Once "defined", then it must not change.
*/
if ((pOD->fOptState & OPTST_DEFINED) != 0) {
if ((od->fOptState & OPTST_DEFINED) != 0) {
/*
* The equivalenced-to option has been found on the command
* line before. Make sure new occurrences are the same type.
@@ -171,9 +167,9 @@ handle_opt(tOptions * pOpts, tOptState* pOptState)
* it was not the same equivalenced-to option,
* 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);
if (eqv_od->optActualIndex != od->optIndex) {
fprintf(stderr, zmultiway_bug, eqv_od->pz_Name, od->pz_Name,
(opts->pOptDesc + eqv_od->optActualIndex)->pz_Name);
return FAILURE;
}
} else {
@@ -183,310 +179,75 @@ handle_opt(tOptions * pOpts, tOptState* pOptState)
* never have been selected before, or else it was selected by
* some sort of "presetting" mechanism.
*/
p->optActualIndex = NO_EQUIVALENT;
eqv_od->optActualIndex = NO_EQUIVALENT;
}
if (p->optActualIndex != pOD->optIndex) {
if (eqv_od->optActualIndex != od->optIndex) {
/*
* First time through, copy over the state
* and add in the equivalence flag
*/
p->optActualValue = pOD->optValue;
p->optActualIndex = pOD->optIndex;
pOptState->flags |= OPTST_EQUIVALENCE;
eqv_od->optActualValue = od->optValue;
eqv_od->optActualIndex = od->optIndex;
o_st->flags |= OPTST_EQUIVALENCE;
}
/*
* Copy the most recent option argument. set membership state
* is kept in ``p->optCookie''. Do not overwrite.
* is kept in 'eqv_od->optCookie'. Do not overwrite.
*/
p->optArg.argString = pOD->optArg.argString;
pOD = p;
eqv_od->optArg.argString = od->optArg.argString;
od = eqv_od;
} else {
pOD->optActualValue = pOD->optValue;
pOD->optActualIndex = pOD->optIndex;
od->optActualValue = od->optValue;
od->optActualIndex = od->optIndex;
}
pOD->fOptState &= OPTST_PERSISTENT_MASK;
pOD->fOptState |= (pOptState->flags & ~OPTST_PERSISTENT_MASK);
od->fOptState &= OPTST_PERSISTENT_MASK;
od->fOptState |= (o_st->flags & ~OPTST_PERSISTENT_MASK);
/*
* Keep track of count only for DEFINED (command line) options.
* IF we have too many, build up an error message and bail.
*/
if ( (pOD->fOptState & OPTST_DEFINED)
&& (++pOD->optOccCt > pOD->optMaxCt) ) {
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
char const * pzEqv =
(pOD->optEquivIndex != NO_EQUIVALENT) ? zEquiv : zNil;
fputs(zErrOnly, stderr);
if (pOD->optMaxCt > 1)
fprintf(stderr, zAtMost, pOD->optMaxCt, pOD->pz_Name, pzEqv);
else
fprintf(stderr, zOnlyOne, pOD->pz_Name, pzEqv);
}
return FAILURE;
}
if ( (od->fOptState & OPTST_DEFINED)
&& (++od->optOccCt > od->optMaxCt) )
return too_many_occurrences(opts, od);
/*
* If provided a procedure to call, call it
*/
if (pOP != NULL)
(*pOP)(pOpts, pOD);
if (opt_proc != NULL)
(*opt_proc)(opts, od);
return SUCCESS;
}
static tSuccess
next_opt_arg_must(tOptions * pOpts, tOptState* pOptState)
{
/*
* An option argument is required. Long options can either have
* a separate command line argument, or an argument attached by
* the '=' character. Figure out which.
*/
switch (pOptState->optType) {
case TOPT_SHORT:
/*
* See if an arg string follows the flag character
*/
if (*++(pOpts->pzCurOpt) == NUL)
pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx++ ];
pOptState->pzOptArg = pOpts->pzCurOpt;
break;
case TOPT_LONG:
/*
* See if an arg string has already been assigned (glued on
* with an `=' character)
*/
if (pOptState->pzOptArg == NULL)
pOptState->pzOptArg = pOpts->origArgVect[ pOpts->curOptIdx++ ];
break;
default:
#ifdef DEBUG
fputs("AutoOpts lib error: option type not selected\n", stderr);
exit(EXIT_FAILURE);
#endif
case TOPT_DEFAULT:
/*
* The option was selected by default. The current token is
* the option argument.
*/
break;
}
/*
* Make sure we did not overflow the argument list.
*/
if (pOpts->curOptIdx > pOpts->origArgCt) {
fprintf(stderr, zMisArg, pOpts->pzProgPath, pOptState->pOD->pz_Name);
return FAILURE;
}
pOpts->pzCurOpt = NULL; /* next time advance to next arg */
return SUCCESS;
}
/**
* Process an optional option argument. For short options, it looks at the
* character after the option character, or it consumes the next full argument.
* For long options, it looks for an '=' character attachment to the long
* option name before deciding to take the next command line argument.
*
* @param pOpts the option descriptor
* @param pOptState a structure for managing the current processing state
* @returns SUCCESS or does not return
*/
static tSuccess
next_opt_arg_may(tOptions * pOpts, tOptState * pOptState)
{
/*
* An option argument is optional.
*/
switch (pOptState->optType) {
case TOPT_SHORT:
if (*++pOpts->pzCurOpt != NUL)
pOptState->pzOptArg = pOpts->pzCurOpt;
else {
char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
/*
* BECAUSE it is optional, we must make sure
* we did not find another flag and that there
* is such an argument.
*/
if ((pzLA == NULL) || (*pzLA == '-'))
pOptState->pzOptArg = NULL;
else {
pOpts->curOptIdx++; /* argument found */
pOptState->pzOptArg = pzLA;
}
}
break;
case TOPT_LONG:
/*
* Look for an argument if we don't already have one (glued on
* with a `=' character) *AND* we are not in named argument mode
*/
if ( (pOptState->pzOptArg == NULL)
&& (! NAMED_OPTS(pOpts))) {
char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
/*
* BECAUSE it is optional, we must make sure
* we did not find another flag and that there
* is such an argument.
*/
if ((pzLA == NULL) || (*pzLA == '-'))
pOptState->pzOptArg = NULL;
else {
pOpts->curOptIdx++; /* argument found */
pOptState->pzOptArg = pzLA;
}
}
break;
default:
case TOPT_DEFAULT:
fputs(zAO_Woops, stderr );
exit(EX_SOFTWARE);
}
/*
* After an option with an optional argument, we will
* *always* start with the next option because if there
* were any characters following the option name/flag,
* they would be interpreted as the argument.
*/
pOpts->pzCurOpt = NULL;
return SUCCESS;
}
static tSuccess
next_opt_arg_none(tOptions * pOpts, tOptState* pOptState)
{
/*
* No option argument. Make sure next time around we find
* the correct option flag character for short options
*/
if (pOptState->optType == TOPT_SHORT)
(pOpts->pzCurOpt)++;
/*
* It is a long option. Make sure there was no ``=xxx'' argument
*/
else if (pOptState->pzOptArg != NULL) {
fprintf(stderr, zNoArg, pOpts->pzProgPath, pOptState->pOD->pz_Name);
return FAILURE;
}
/*
* It is a long option. Advance to next command line argument.
*/
else
pOpts->pzCurOpt = NULL;
return SUCCESS;
}
/**
* Find the option descriptor and option argument (if any) for the
* next command line argument. DO NOT modify the descriptor. Put
* all the state in the state argument so that the option can be skipped
* without consequence (side effect).
*
* @param pOpts the program option descriptor
* @param pOptState the state of the next found option
* @param opts the program option descriptor
* @param o_st the state of the next found option
*/
static tSuccess
next_opt(tOptions * pOpts, tOptState * pOptState)
LOCAL tSuccess
next_opt(tOptions * opts, tOptState * o_st)
{
{
tSuccess res = find_opt(pOpts, pOptState);
tSuccess res = find_opt(opts, o_st);
if (! SUCCESSFUL(res))
return res;
}
if ( ((pOptState->flags & OPTST_DEFINED) != 0)
&& ((pOptState->pOD->fOptState & OPTST_NO_COMMAND) != 0)) {
fprintf(stderr, zNotCmdOpt, pOptState->pOD->pz_Name);
if ( ((o_st->flags & OPTST_DEFINED) != 0)
&& ((o_st->pOD->fOptState & OPTST_NO_COMMAND) != 0)) {
fprintf(stderr, zNotCmdOpt, o_st->pOD->pz_Name);
return FAILURE;
}
return get_opt_arg(pOpts, pOptState);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* DO PRESETS
*
* The next several routines do the immediate action pass on the command
* line options, then the environment variables, then the config files in
* reverse order. Once done with that, the order is reversed and all
* the config files and environment variables are processed again, this
* time only processing the non-immediate action options. doPresets()
* will then return for optionProcess() to do the final pass on the command
* line arguments.
*/
/**
* scan the command line for immediate action options.
* This is only called the first time through.
* While this procedure is active, the OPTPROC_IMMEDIATE is true.
*
* @param pOpts program options descriptor
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
immediate_opts(tOptions * pOpts)
{
tSuccess res;
pOpts->fOptSet |= OPTPROC_IMMEDIATE;
pOpts->curOptIdx = 1; /* start by skipping program name */
pOpts->pzCurOpt = NULL;
/*
* Examine all the options from the start. We process any options that
* are marked for immediate processing.
*/
for (;;) {
tOptState opt_st = OPTSTATE_INITIALIZER(PRESET);
res = next_opt(pOpts, &opt_st);
switch (res) {
case FAILURE: goto failed_option;
case PROBLEM: res = SUCCESS; goto leave;
case SUCCESS: break;
}
/*
* IF this is an immediate-attribute option, then do it.
*/
if (! DO_IMMEDIATELY(opt_st.flags))
continue;
if (! SUCCESSFUL(handle_opt(pOpts, &opt_st)))
break;
} failed_option:;
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
leave:
pOpts->fOptSet &= ~OPTPROC_IMMEDIATE;
return res;
return get_opt_arg(opts, o_st);
}
/**
@@ -495,17 +256,17 @@ leave:
* require it.) Thus, do not rewind option indexes because some programs
* choose to re-invoke after a non-option.
*
* @param pOpts program options descriptor
* @param[in,out] opts program options descriptor
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
regular_opts(tOptions * pOpts)
regular_opts(tOptions * opts)
{
/* assert: pOpts->fOptSet & OPTPROC_IMMEDIATE == 0 */
/* assert: opts->fOptSet & OPTPROC_IMMEDIATE == 0 */
for (;;) {
tOptState opt_st = OPTSTATE_INITIALIZER(DEFINED);
switch (next_opt(pOpts, &opt_st)) {
switch (next_opt(opts, &opt_st)) {
case FAILURE: goto failed_option;
case PROBLEM: return SUCCESS; /* no more args */
case SUCCESS: break;
@@ -521,71 +282,16 @@ regular_opts(tOptions * pOpts)
opt_st.pOD->optOccCt--; /* don't count this repetition */
}
if (! SUCCESSFUL(handle_opt(pOpts, &opt_st)))
if (! SUCCESSFUL(handle_opt(opts, &opt_st)))
break;
} failed_option:;
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*opts->pUsageProc)(opts, EXIT_FAILURE);
return FAILURE;
}
/**
* check for preset values from a config files or envrionment variables
*/
static tSuccess
doPresets(tOptions * pOpts)
{
tOptDesc * pOD = NULL;
if (! SUCCESSFUL(immediate_opts(pOpts)))
return FAILURE;
/*
* IF this option set has a --save-opts option, then it also
* has a --load-opts option. See if a command line option has disabled
* option presetting.
*/
if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
&& (pOpts->specOptIdx.save_opts != 0)) {
pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1;
if (DISABLED_OPT(pOD))
return SUCCESS;
}
/*
* Until we return from this procedure, disable non-presettable opts
*/
pOpts->fOptSet |= OPTPROC_PRESETTING;
/*
* IF there are no config files,
* THEN do any environment presets and leave.
*/
if (pOpts->papzHomeList == NULL) {
env_presets(pOpts, ENV_ALL);
}
else {
env_presets(pOpts, ENV_IMM);
/*
* Check to see if environment variables have disabled presetting.
*/
if ((pOD != NULL) && ! DISABLED_OPT(pOD))
intern_file_load(pOpts);
/*
* ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment
* variable options. Only the loading of .rc files.
*/
env_presets(pOpts, ENV_NON_IMM);
}
pOpts->fOptSet &= ~OPTPROC_PRESETTING;
return SUCCESS;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* THESE ROUTINES ARE CALLABLE FROM THE GENERATED OPTION PROCESSING CODE
@@ -608,9 +314,9 @@ doPresets(tOptions * pOpts)
*
* what: this is the main option processing routine
*
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + int + argc + program arg count +
* arg: + char** + argv + program arg vector +
* arg: + tOptions* + opts + program options descriptor +
* arg: + int + a_ct + program arg count +
* arg: + char** + a_v + program arg vector +
*
* ret_type: int
* ret_desc: the count of the arguments processed
@@ -639,57 +345,29 @@ doPresets(tOptions * pOpts)
* ERRSKIP_OPTERR or ERRSTOP_OPTERR macros were invoked.
=*/
int
optionProcess(tOptions * pOpts, int argCt, char ** argVect)
optionProcess(tOptions * opts, int a_ct, char ** a_v)
{
if (! SUCCESSFUL(validate_struct(pOpts, argVect[0])))
exit(EX_SOFTWARE);
if (! SUCCESSFUL(validate_struct(opts, a_v[0])))
ao_bug(zbad_data_msg);
/*
* Establish the real program name, the program full path,
* and do all the presetting the first time thru only.
*/
if ((pOpts->fOptSet & OPTPROC_INITDONE) == 0) {
pOpts->origArgCt = (unsigned int)argCt;
pOpts->origArgVect = argVect;
pOpts->fOptSet |= OPTPROC_INITDONE;
if (HAS_pzPkgDataDir(pOpts))
program_pkgdatadir = pOpts->pzPkgDataDir;
if (! SUCCESSFUL(doPresets(pOpts)))
return 0;
/*
* IF option name conversion was suppressed but it is not suppressed
* for the command line, then it's time to translate option names.
* Usage text will not get retranslated.
*/
if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0)
&& (pOpts->pTransProc != NULL)
&& ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK)
== OPTPROC_NXLAT_OPT_CFG) ) {
pOpts->fOptSet &= ~OPTPROC_NXLAT_OPT_CFG;
(*pOpts->pTransProc)();
}
if ((pOpts->fOptSet & OPTPROC_REORDER) != 0)
optionSort(pOpts);
pOpts->curOptIdx = 1;
pOpts->pzCurOpt = NULL;
}
if (! ao_initialize(opts, a_ct, a_v))
return 0;
/*
* IF we are (re)starting,
* THEN reset option location
*/
else if (pOpts->curOptIdx <= 0) {
pOpts->curOptIdx = 1;
pOpts->pzCurOpt = NULL;
if (opts->curOptIdx <= 0) {
opts->curOptIdx = 1;
opts->pzCurOpt = NULL;
}
if (! SUCCESSFUL(regular_opts(pOpts)))
return pOpts->origArgCt;
if (! SUCCESSFUL(regular_opts(opts)))
return (int)opts->origArgCt;
/*
* IF there were no errors
@@ -698,29 +376,34 @@ optionProcess(tOptions * pOpts, int argCt, char ** argVect)
* THEN do that now before testing for conflicts.
* (conflicts are ignored in preset options)
*/
if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
&& (pOpts->specOptIdx.save_opts != 0)) {
tOptDesc* pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts;
switch (opts->specOptIdx.save_opts) {
case 0:
case NO_EQUIVALENT:
break;
default:
{
tOptDesc * od = opts->pOptDesc + opts->specOptIdx.save_opts;
if (SELECTED_OPT(pOD)) {
optionSaveFile(pOpts);
if (SELECTED_OPT(od)) {
optionSaveFile(opts);
exit(EXIT_SUCCESS);
}
}
}
/*
* IF we are checking for errors,
* THEN look for too few occurrences of required options
*/
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
if (! is_consistent(pOpts))
(*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
}
if (((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
&& (! is_consistent(opts)))
(*opts->pUsageProc)(opts, EXIT_FAILURE);
return pOpts->curOptIdx;
return (int)opts->curOptIdx;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,14 +2,16 @@
/*
* \file autoopts.h
*
* Time-stamp: "2012-03-04 19:05:01 bkorb"
*
* This file defines all the global structures and special values
* used in the automated option processing library.
*
* @group autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -21,11 +23,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef AUTOGEN_AUTOOPTS_H
@@ -50,13 +52,35 @@
#undef EXPORT
#define EXPORT
#ifndef NUL
#define NUL '\0'
#endif
#define BEL '\a'
#define BS '\b'
#define HT '\t'
#define LF '\n'
#define VT '\v'
#define FF '\f'
#define CR '\r'
#if defined(_WIN32) && !defined(__CYGWIN__)
# define DIRCH '\\'
#else
# define DIRCH '/'
#endif
#define AO_EXIT_REQ_USAGE 64
#ifndef EX_USAGE
/**
* Command line usage problem
*/
# define EX_USAGE 64
#endif
#ifndef EX_DATAERR
/**
* The input data was incorrect in some way.
*/
# define EX_DATAERR 64
#endif
#ifndef EX_NOINPUT
/**
* option state was requested from a file that cannot be loaded.
@@ -69,8 +93,30 @@
*/
# define EX_SOFTWARE 70
#endif
#ifndef EX_OSERR
/**
* Command line usage problem
*/
# define EX_OSERR 71
#endif
#define NL '\n'
#ifndef C
/**
* Coercive cast. Compel an address to be interpreted as the type
* of the first argument. No complaints, just do it.
*/
#define C(_t,_p) ((_t)(void *)(_p))
#endif
/* The __attribute__((__warn_unused_result__)) feature
is available in gcc versions 3.4 and newer,
while the typeof feature has been available since 2.7 at least. */
# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
# define ignore_val(x) ((void) (x))
# else
# define ignore_val(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
# endif
/*
* Convert the number to a list usable in a printf call
@@ -89,37 +135,39 @@ typedef int tDirection;
#define PROCESSING(d) ((d)>0)
#define PRESETTING(d) ((d)<0)
#define CALLED(d) ((d)==0)
/*
/**
* When loading a line (or block) of text as an option, the value can
* be processed in any of several modes:
*
* @table @samp
* @item keep
* Every part of the value between the delimiters is saved.
*
* @item uncooked
* Even if the value begins with quote characters, do not do quote processing.
*
* @item cooked
* If the value looks like a quoted string, then process it.
* Double quoted strings are processed the way strings are in "C" programs,
* except they are treated as regular characters if the following character
* is not a well-established escape sequence.
* Single quoted strings (quoted with apostrophies) are handled the way
* strings are handled in shell scripts, *except* that backslash escapes
* are honored before backslash escapes and apostrophies.
* @end table
* be processed in any of several modes.
*/
typedef enum {
/**
* If the value looks like a quoted string, then process it. Double
* quoted strings are processed the way strings are in "C" programs,
* except they are treated as regular characters if the following
* character is not a well-established escape sequence. Single quoted
* strings (quoted with apostrophies) are handled the way strings are
* handled in shell scripts, *except* that backslash escapes are
* honored before backslash escapes and apostrophies.
*/
OPTION_LOAD_COOKED,
/**
* Even if the value begins with quote characters, do not do quote
* processing. Strip leading and trailing white space.
*/
OPTION_LOAD_UNCOOKED,
/**
* Keep every part of the value between the delimiters.
*/
OPTION_LOAD_KEEP
} tOptionLoadMode;
static tOptionLoadMode option_load_mode;
/*
/**
* The pager state is used by optionPagedUsage() procedure.
* When it runs, it sets itself up to be called again on exit.
* If, however, a routine needs a child process to do some work
@@ -128,8 +176,16 @@ static tOptionLoadMode option_load_mode;
* to run the pager program before its time.
*/
typedef enum {
PAGER_STATE_INITIAL,
PAGER_STATE_INITIAL, //@< initial option paging state
/**
* temp file created and optionPagedUsage is scheduled to run at exit
*/
PAGER_STATE_READY,
/**
* This is a child process used in creating shell script usage.
*/
PAGER_STATE_CHILD
} tePagerState;
@@ -147,10 +203,10 @@ typedef enum {
} teOptType;
typedef struct {
tOptDesc* pOD;
tCC* pzOptArg;
tAoUL flags;
teOptType optType;
tOptDesc * pOD;
char const * pzOptArg;
opt_state_mask_t flags;
teOptType optType;
} tOptState;
#define OPTSTATE_INITIALIZER(st) \
{ NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
@@ -166,6 +222,10 @@ typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
#undef _TT_
/**
* option argument types. Used to create usage information for
* particular options.
*/
typedef struct {
char const * pzStr;
char const * pzReq;
@@ -200,7 +260,7 @@ ao_realloc(void *p, size_t sz);
static char *
ao_strdup(char const *str);
/*
/**
* DO option handling?
*
* Options are examined at two times: at immediate handling time and at
@@ -230,7 +290,8 @@ ao_strdup(char const *str);
|| ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
== (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
/* B) handling at "regular" time because it was not immediate
/**
* B) handling at "regular" time because it was not immediate
*
* 1. OPTST_DISABLED is not set:
* IMM must *NOT* be set
@@ -251,7 +312,8 @@ ao_strdup(char const *str);
|| (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
OPTST_DISABLED) )
/* C) handling at "regular" time because it is to be handled twice.
/**
* C) handling at "regular" time because it is to be handled twice.
* The immediate bit was already tested and found to be set:
*
* 3. OPTST_DISABLED is not set:
@@ -309,7 +371,7 @@ extern char* strchr(char const *s, int c);
extern char* strrchr(char const *s, int c);
#endif
/*
/**
* Define and initialize all the user visible strings.
* We do not do translations. If translations are to be done, then
* the client will provide a callback for that purpose.
@@ -317,16 +379,22 @@ extern char* strrchr(char const *s, int c);
#undef DO_TRANSLATIONS
#include "autoopts/usage-txt.h"
/*
/**
* File pointer for usage output
*/
FILE * option_usage_fp;
/**
* If provided in the option structure
*/
static char const * program_pkgdatadir;
/**
* privately exported functions
*/
extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
#endif /* AUTOGEN_AUTOOPTS_H */
/*
/**
* @}
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,28 @@
/**
* \file project.h
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (C) 1992-2013 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
* of the user of the license.
*
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following sha256 sums:
*
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef AUTOGEN_PROJECT_H
#define AUTOGEN_PROJECT_H
@@ -48,3 +72,4 @@ typedef int tSuccess;
#endif
#endif /* AUTOGEN_PROJECT_H */
/* end of project.h */

File diff suppressed because it is too large Load Diff

View File

@@ -2,16 +2,18 @@
/**
* \file boolean.c
*
* Time-stamp: "2012-03-31 13:46:19 bkorb"
*
* Automated Options Paged Usage module.
* Handle options with true/false values for arguments.
*
* @addtogroup autoopts
* @{
*/
/*
* This routine will run run-on options through a pager so the
* user may examine, print or edit them at their leisure.
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -23,11 +25,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*=export_func optionBooleanVal
@@ -50,6 +52,9 @@ optionBooleanVal(tOptions * pOpts, tOptDesc * pOD )
(void)pOpts;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((pOD->fOptState & OPTST_RESET) != 0)
return;
@@ -85,7 +90,8 @@ optionBooleanVal(tOptions * pOpts, tOptDesc * pOD )
}
pOD->optArg.argBool = res;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,16 +1,15 @@
/**
* @file check.c
*
* @brief consistency checks.
*
* Time-stamp: "2012-03-31 13:46:35 bkorb"
*
* This file contains the routines that deal with processing quoted strings
* into an internal format.
* @brief option consistency checks.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,40 +21,42 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/**
* Check for conflicts based on "must" and "cannot" attributes.
*/
static bool
has_conflict(tOptions * pOpts, tOptDesc * pOD)
has_conflict(tOptions * pOpts, tOptDesc * od)
{
if (pOD->pOptMust != NULL) {
int const * pMust = pOD->pOptMust;
if (od->pOptMust != NULL) {
int const * must = od->pOptMust;
while (*pMust != NO_EQUIVALENT) {
tOptDesc * p = pOpts->pOptDesc + *(pMust++);
while (*must != NO_EQUIVALENT) {
tOptDesc * p = pOpts->pOptDesc + *(must++);
if (UNUSED_OPT(p)) {
const tOptDesc * pN = pOpts->pOptDesc + pMust[-1];
fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name);
const tOptDesc * ood = pOpts->pOptDesc + must[-1];
fprintf(stderr, zneed_fmt, pOpts->pzProgName,
od->pz_Name, ood->pz_Name);
return true;
}
}
}
if (pOD->pOptCant != NULL) {
int const * pCant = pOD->pOptCant;
if (od->pOptCant != NULL) {
int const * cant = od->pOptCant;
while (*pCant != NO_EQUIVALENT) {
tOptDesc * p = pOpts->pOptDesc + *(pCant++);
while (*cant != NO_EQUIVALENT) {
tOptDesc * p = pOpts->pOptDesc + *(cant++);
if (SELECTED_OPT(p)) {
const tOptDesc* pN = pOpts->pOptDesc + pCant[-1];
fprintf(stderr, zCantFmt, pOD->pz_Name, pN->pz_Name);
const tOptDesc * ood = pOpts->pOptDesc + cant[-1];
fprintf(stderr, zconflict_fmt, pOpts->pzProgName,
od->pz_Name, ood->pz_Name);
return true;
}
}
@@ -88,8 +89,9 @@ occurs_enough(tOptions * pOpts, tOptDesc * pOD)
return true;
if (pOD->optMinCt > 1)
fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt);
else fprintf(stderr, zNeedOne, pOD->pz_Name);
fprintf(stderr, zneed_more, pOpts->pzProgName, pOD->pz_Name,
pOD->optMinCt);
else fprintf(stderr, zneed_one, pOpts->pzProgName, pOD->pz_Name);
return false;
}
@@ -156,7 +158,7 @@ is_consistent(tOptions * pOpts)
*/
else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) {
if (pOpts->origArgCt <= pOpts->curOptIdx) {
fprintf(stderr, zArgsMust, pOpts->pzProgName);
fprintf(stderr, zargs_must, pOpts->pzProgName);
return false;
}
}
@@ -164,3 +166,12 @@ is_consistent(tOptions * pOpts)
return true;
}
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"
* indent-tabs-mode: nil
* End:
* end of autoopts/check.c */

View File

@@ -1,50 +1,30 @@
/* -*- Mode: C -*- */
/**
* \file compat.h --- fake the preprocessor into handlng portability
*
* Time-stamp: "2012-02-28 19:40:44 bkorb"
/* -*- Mode: C -*-
*
* compat.h is free software.
* This file is part of AutoGen.
* This file is part of AutoGen and AutoOpts.
*
* AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoGen Copyright (C) 1992-2013 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.
* 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
* of the user of the license.
*
* 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.
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* As a special exception, Bruce Korb gives permission for additional
* uses of the text contained in the release of compat.h.
* These files have the following sha256 sums:
*
* The exception is that, if you link the compat.h library with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the compat.h library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by Bruce Korb under
* the name compat.h. If you copy code from other sources under the
* General Public License into a copy of compat.h, as the General Public
* License permits, the exception does not apply to the code that you add
* in this way. To avoid misleading anyone as to the status of such
* modified files, you must delete this exception notice from them.
*
* If you write modifications of your own for compat.h, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/**
* \file compat.h
* fake the preprocessor into handlng stuff portability
*/
#ifndef COMPAT_H_GUARD
#define COMPAT_H_GUARD 1
@@ -62,7 +42,9 @@
#ifndef HAVE_STRSIGNAL
char * strsignal( int signo );
# ifndef HAVE_RAW_DECL_STRSIGNAL
char * strsignal(int signo);
# endif
#endif
#define _GNU_SOURCE 1 /* for strsignal in GNU's libc */

View File

@@ -2,20 +2,22 @@
/* pathfind.c --- find a FILE MODE along PATH */
/*
* Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk>
* Time-stamp: "2012-03-31 13:44:42 bkorb"
*/
/* Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk> */
/* Code: */
static char *
pathfind( char const * path,
char const * fileName,
char const * mode );
#include "compat.h"
#ifndef HAVE_PATHFIND
#if defined(__windows__) && !defined(__CYGWIN__)
char*
pathfind( char const* path,
char const* fileName,
char const* mode )
static char *
pathfind( char const * path,
char const * fileName,
char const * mode )
{
return NULL;
}
@@ -80,10 +82,10 @@ static char* extract_colon_unit( char* dir, char const *string, int *p_index );
*
* err: returns NULL if the file is not found.
=*/
char*
pathfind( char const* path,
char const* fileName,
char const* mode )
static char *
pathfind( char const * path,
char const * fileName,
char const * mode )
{
int p_index = 0;
int mode_bits = 0;
@@ -171,7 +173,7 @@ make_absolute( char const *string, char const *dot_path )
if (dot_path && dot_path[0]) {
result = malloc( 2 + strlen( dot_path ) + strlen( string ) );
strcpy( result, dot_path );
result_len = strlen( result );
result_len = (int)strlen(result);
if (result[result_len - 1] != '/') {
result[result_len++] = '/';
result[result_len] = '\0';
@@ -286,7 +288,7 @@ canonicalize_pathname( char *path )
static char*
extract_colon_unit( char* pzDir, char const *string, int *p_index )
{
char* pzDest = pzDir;
char * pzDest = pzDir;
int ix = *p_index;
if (string == NULL)
@@ -296,7 +298,7 @@ extract_colon_unit( char* pzDir, char const *string, int *p_index )
return NULL;
{
char const* pzSrc = string + ix;
char const * pzSrc = string + ix;
while (*pzSrc == ':') pzSrc++;
@@ -305,6 +307,7 @@ extract_colon_unit( char* pzDir, char const *string, int *p_index )
switch (ch) {
case ':':
pzDest[-1] = NUL;
/* FALLTHROUGH */
case NUL:
goto copy_done;
}
@@ -313,7 +316,7 @@ extract_colon_unit( char* pzDir, char const *string, int *p_index )
break;
} copy_done:;
ix = pzSrc - string;
ix = (int)(pzSrc - string);
}
if (*pzDir == NUL)

View File

@@ -1,6 +1,7 @@
#ifndef HAVE_VPRINTF
#include "choke-me: no vprintf and no snprintf"
choke me.
#endif
#if defined(HAVE_STDARG_H)
@@ -21,6 +22,7 @@
#else
# include "must-have-stdarg-or-varargs"
choke me.
#endif
static int

View File

@@ -24,8 +24,14 @@
SVID 3, POSIX, BSD 4.3, ISO 9899
*/
char*
strchr( char const *s, int c)
static char *
strchr(char const *s, int c);
static char *
strrchr(char const *s, int c);
static char *
strchr(char const *s, int c)
{
do {
if ((unsigned)*s == (unsigned)c)
@@ -36,8 +42,8 @@ strchr( char const *s, int c)
return NULL;
}
char*
strrchr( char const *s, int c)
static char *
strrchr(char const *s, int c)
{
char const *e = s + strlen(s);

View File

@@ -2,6 +2,9 @@
* Platforms without strdup ?!?!?!
*/
static char *
strdup( char const *s );
static char *
strdup( char const *s )
{

View File

@@ -1,24 +1,33 @@
/*
* Time-stamp: "2010-02-24 08:39:04 bkorb"
/**
* \file windows-config.h
*
* This file is part of AutoGen.
* This file contains all of the routines that must be linked into
* an executable to use the generated option processing. The optional
* routines are in separately compiled modules so that they will not
* necessarily be linked in.
*
* AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (C) 1992-2013 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.
* 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
* of the user of the license.
*
* 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.
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following sha256 sums:
*
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifndef WINDOWS_CONFIG_HACKERY
#define WINDOWS_CONFIG_HACKERY 1
@@ -32,64 +41,25 @@
#endif
/*
* Miscellaneous functions that Microsoft maps
* to other names
*
* #define inline __inline
* #define vsnprintf _vsnprintf
* Miscellaneous functions that Microsoft maps to other names
*/
#define snprintf _snprintf
/*
* #define stricmp _stricmp
* #define strcasecmp _stricmp
* #define isascii __isascii
* #define finite _finite
* #define random rand
* #define srandom srand
*/
#define SIZEOF_INT 4
#define SIZEOF_CHARP 4
#define SIZEOF_LONG 4
#define SIZEOF_SHORT 2
typedef unsigned long uintptr_t;
/*
* # define HAVE_NET_IF_H
* # define QSORT_USES_VOID_P
* # define HAVE_SETVBUF
* # define HAVE_VSPRINTF
* # define HAVE_SNPRINTF
* # define HAVE_VSNPRINTF
* # define HAVE_PROTOTYPES /* from ntpq.mak * /
* # define HAVE_MEMMOVE
* # define HAVE_TERMIOS_H
* # define HAVE_ERRNO_H
* # define HAVE_STDARG_H
* # define HAVE_NO_NICE
* # define HAVE_MKTIME
* # define TIME_WITH_SYS_TIME
* # define HAVE_IO_COMPLETION_PORT
* # define ISC_PLATFORM_NEEDNTOP
* # define ISC_PLATFORM_NEEDPTON
* # define NEED_S_CHAR_TYPEDEF
* # define USE_PROTOTYPES /* for ntp_types.h * /
*
* #define ULONG_CONST(a) a ## UL
*/
#define HAVE_LIMITS_H 1
#define HAVE_STRDUP 1
#define HAVE_STRCHR 1
#define HAVE_FCNTL_H 1
/*
* VS.NET's version of wspiapi.h has a bug in it
* where it assigns a value to a variable inside
* an if statement. It should be comparing them.
* We prevent inclusion since we are not using this
* code so we don't have to see the warning messages
* VS.NET's version of wspiapi.h has a bug in it where it assigns a value
* to a variable inside an if statement. It should be comparing them.
* We prevent inclusion since we are not using this code so we don't have
* to see the warning messages
*/
#ifndef _WSPIAPI_H_
#define _WSPIAPI_H_
@@ -116,7 +86,7 @@ typedef unsigned long uintptr_t;
#define strdup _strdup
#define stat _stat /* struct stat from <sys/stat.h> */
#define unlink _unlink
#define fchmod( _x, _y );
#define fchmod( _x, _y )
#define ssize_t SSIZE_T
#include <io.h>
@@ -142,4 +112,33 @@ typedef unsigned long uintptr_t;
# define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR)
#endif
/* C99 exact size integer support. */
#if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#elif defined(HAVE_STDINT_H)
# include <stdint.h>
# define MISSING_INTTYPES_H 1
#elif ! defined(ADDED_EXACT_SIZE_INTEGERS)
# define ADDED_EXACT_SIZE_INTEGERS 1
# define MISSING_INTTYPES_H 1
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef unsigned long uintptr_t;
typedef long intptr_t;
#endif
#endif /* WINDOWS_CONFIG_HACKERY */
/* windows-config.h ends here */

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,16 @@
/**
* \file cook.c
*
* Time-stamp: "2012-02-28 19:40:47 bkorb"
*
* This file contains the routines that deal with processing quoted strings
* into an internal format.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -20,11 +22,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
@@ -59,9 +61,9 @@ contiguous_quote(char ** pps, char * pq, int * lnct_p);
* err: @code{NULL} is returned if the string is mal-formed.
=*/
unsigned int
ao_string_cook_escape_char(char const* pzIn, char* pRes, uint_t nl)
ao_string_cook_escape_char(char const * pzIn, char * pRes, uint_t nl)
{
unsigned int res = 1;
unsigned int res = 1;
switch (*pRes = *pzIn++) {
case NUL: /* NUL - end of input string */
@@ -86,13 +88,17 @@ ao_string_cook_escape_char(char const* pzIn, char* pRes, uint_t nl)
case 'x':
case 'X': /* HEX Escape */
if (IS_HEX_DIGIT_CHAR(*pzIn)) {
char z[4], *pz = z;
char z[4];
unsigned int ct = 0;
do *(pz++) = *(pzIn++);
while (IS_HEX_DIGIT_CHAR(*pzIn) && (pz < z + 2));
*pz = NUL;
*pRes = (unsigned char)strtoul(z, NULL, 16);
res += pz - z;
do {
z[ct] = pzIn[ct];
if (++ct >= 2)
break;
} while (IS_HEX_DIGIT_CHAR(pzIn[ct]));
z[ct] = NUL;
*pRes = (char)strtoul(z, NULL, 16);
return ct + 1;
}
break;
@@ -101,24 +107,29 @@ ao_string_cook_escape_char(char const* pzIn, char* pRes, uint_t nl)
{
/*
* IF the character copied was an octal digit,
* THEN set the output character to an octal value
* THEN set the output character to an octal value.
* The 3 octal digit result might exceed 0xFF, so check it.
*/
char z[4], *pz = z + 1;
char z[4];
unsigned long val;
z[0] = *pRes;
unsigned int ct = 0;
while (IS_OCT_DIGIT_CHAR(*pzIn) && (pz < z + 3))
*(pz++) = *(pzIn++);
*pz = NUL;
z[ct++] = *--pzIn;
while (IS_OCT_DIGIT_CHAR(pzIn[ct])) {
z[ct] = pzIn[ct];
if (++ct >= 3)
break;
}
z[ct] = NUL;
val = strtoul(z, NULL, 8);
if (val > 0xFF)
val = 0xFF;
*pRes = (unsigned char)val;
res = pz - z;
break;
*pRes = (char)val;
return ct;
}
default: ;
default: /* quoted character is result character */;
}
return res;
@@ -282,7 +293,8 @@ ao_string_cook(char * pzScan, int * lnct_p)
* THEN we do the full escape character processing
*/
else if (q != '\'') {
int ct = ao_string_cook_escape_char(pzS, pzD-1, (uint_t)NL);
unsigned int ct;
ct = ao_string_cook_escape_char(pzS, pzD-1, (uint_t)NL);
if (ct == 0)
return NULL;
@@ -302,7 +314,9 @@ ao_string_cook(char * pzScan, int * lnct_p)
} /* switch (*(pzD++) = *(pzS++)) */
} /* for (;;) */
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,16 +2,19 @@
/**
* \file enumeration.c
*
* Time-stamp: "2012-03-31 13:22:33 bkorb"
*
* Automated Options Paged Usage module.
* Handle options with enumeration names and bit mask bit names
* for their arguments.
*
* @addtogroup autoopts
* @{
*/
/*
* This routine will run run-on options through a pager so the
* user may examine, print or edit them at their leisure.
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -23,11 +26,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
static char const * pz_enum_err_fmt;
@@ -38,13 +41,9 @@ enum_err(tOptions * pOpts, tOptDesc * pOD,
char const * const * paz_names, int name_ct);
static uintptr_t
find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD,
find_name(char const * name, 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);
@@ -105,7 +104,7 @@ enum_err(tOptions * pOpts, tOptDesc * pOD,
*/
if (max_len > 35) {
do {
fprintf(option_usage_fp, ENUM_ERR_SEP_LINE_FMT, *(paz_names++));
fprintf(option_usage_fp, ENUM_ERR_LINE, *(paz_names++));
} while (--ct_down > 0);
}
@@ -128,7 +127,7 @@ enum_err(tOptions * pOpts, tOptDesc * pOD,
unsigned int ent_no = 0;
char zFmt[16]; /* format for all-but-last entries on a line */
sprintf(zFmt, ENUM_ERR_STR_WIDTH_FMT, (int)max_len);
sprintf(zFmt, ENUM_ERR_WIDTH, (int)max_len);
max_len = 78 / max_len; /* max_len is now max entries on a line */
fputs(TWO_SPACES_STR, option_usage_fp);
@@ -170,14 +169,14 @@ enum_err(tOptions * pOpts, tOptDesc * pOD,
* Convert a name or number into a binary number.
* "~0" and "-1" will be converted to the largest value in the enumeration.
*
* @param pzName the keyword name (number) to convert
* @param name the keyword name (number) to convert
* @param pOpts the program's option descriptor
* @param pOD the option descriptor for this option
* @param paz_names the list of keywords for this option
* @param name_ct the count of keywords
*/
static uintptr_t
find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD,
find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
char const * const * paz_names, unsigned int name_ct)
{
/*
@@ -185,23 +184,23 @@ find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD,
* The result gets stashed in a char* pointer.
*/
uintptr_t res = name_ct;
size_t len = strlen((char*)pzName);
size_t len = strlen((char*)name);
uintptr_t idx;
if (IS_DEC_DIGIT_CHAR(*pzName)) {
char * pz = (char *)(void *)pzName;
if (IS_DEC_DIGIT_CHAR(*name)) {
char * pz = (char *)(void *)name;
unsigned long val = strtoul(pz, &pz, 0);
if ((*pz == NUL) && (val < name_ct))
return (uintptr_t)val;
pz_enum_err_fmt = zTooLarge;
pz_enum_err_fmt = znum_too_large;
option_usage_fp = stderr;
enum_err(pOpts, pOD, paz_names, (int)name_ct);
return name_ct;
}
if (IS_INVERSION_CHAR(*pzName) && (pzName[2] == NUL)) {
if ( ((pzName[0] == '~') && (pzName[1] == '0'))
|| ((pzName[0] == '-') && (pzName[1] == '1')))
if (IS_INVERSION_CHAR(*name) && (name[2] == NUL)) {
if ( ((name[0] == '~') && (name[1] == '0'))
|| ((name[0] == '-') && (name[1] == '1')))
return (uintptr_t)(name_ct - 1);
goto oops;
}
@@ -211,23 +210,23 @@ find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD,
* 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*)name, len) == 0) {
if (paz_names[idx][len] == NUL)
return idx; /* full match */
if (res == name_ct)
res = idx; /* save partial match */
else
res = ~0; /* may yet find full match */
res = (uintptr_t)~0; /* may yet find full match */
}
}
if (res < name_ct)
return res; /* partial match */
oops:
oops:
pz_enum_err_fmt = (res == name_ct) ? zNoKey : zAmbigKey;
pz_enum_err_fmt = (res == name_ct) ? zNoKey : zambiguous_key;
option_usage_fp = stderr;
enum_err(pOpts, pOD, paz_names, (int)name_ct);
return name_ct;
@@ -249,8 +248,8 @@ oops:
char const *
optionKeywordName(tOptDesc * pOD, unsigned int enum_val)
{
tOptDesc od = {
.optArg.argEnum = enum_val };
tOptDesc od = { 0 };
od.optArg.argEnum = enum_val;
(*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od );
return od.optArg.argString;
@@ -295,7 +294,7 @@ optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
case (uintptr_t)OPTPROC_EMIT_SHELL:
{
unsigned int ix = pOD->optArg.argEnum;
unsigned int ix = (unsigned int)pOD->optArg.argEnum;
/*
* print the name string.
*/
@@ -309,7 +308,7 @@ optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
case (uintptr_t)OPTPROC_RETURN_VALNAME:
{
unsigned int ix = pOD->optArg.argEnum;
unsigned int ix = (unsigned int)pOD->optArg.argEnum;
/*
* Replace the enumeration value with the name string.
*/
@@ -321,6 +320,9 @@ optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
}
default:
if ((pOD->fOptState & OPTST_RESET) != 0)
break;
res = find_name(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct);
if (pOD->fOptState & OPTST_ALLOC_ARG) {
@@ -333,17 +335,6 @@ optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
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.
*/
(void)pOpts;
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)
@@ -443,7 +434,7 @@ optionSetMembers(tOptions * pOpts, tOptDesc * pOD,
*/
switch ((uintptr_t)pOpts) {
case (uintptr_t)OPTPROC_EMIT_USAGE:
set_memb_usage(pOpts, pOD, paz_names, name_ct);
enum_err(OPTPROC_EMIT_USAGE, pOD, paz_names, name_ct);
return;
case (uintptr_t)OPTPROC_EMIT_SHELL:
@@ -478,7 +469,7 @@ optionSetMembers(tOptions * pOpts, tOptDesc * pOD,
if (iv)
pzArg = SPN_WHITESPACE_CHARS(pzArg+1);
len = BRK_SET_SEPARATOR_CHARS(pzArg) - pzArg;
len = (int)(BRK_SET_SEPARATOR_CHARS(pzArg) - pzArg);
if (len == 0)
break;
@@ -510,7 +501,8 @@ optionSetMembers(tOptions * pOpts, tOptDesc * pOD,
p = pzArg;
}
shift_ct = find_name(p, pOpts, pOD, paz_names, name_ct);
shift_ct = (unsigned int)
find_name(p, pOpts, pOD, paz_names, name_ct);
if (shift_ct >= name_ct) {
pOD->optCookie = (void*)0;
return;
@@ -534,10 +526,11 @@ optionSetMembers(tOptions * pOpts, tOptDesc * pOD,
}
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"
* indent-tabs-mode: nil
* End:
* end of autoopts/enumeration.c */
* end of autoopts/enum.c */

View File

@@ -2,16 +2,18 @@
/**
* \file environment.c
*
* Time-stamp: "2012-04-01 05:59:15 bkorb"
*
* This file contains all of the routines that must be linked into
* an executable to use the generated option processing. The optional
* routines are in separately compiled modules so that they will not
* necessarily be linked in.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -23,11 +25,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
@@ -45,30 +47,30 @@ do_env_opt(tOptState * os, char * env_name,
LOCAL void
doPrognameEnv(tOptions * pOpts, teEnvPresetType type)
{
char const * pczOptStr = getenv(pOpts->pzPROGNAME);
token_list_t* pTL;
int sv_argc;
tAoUI sv_flag;
char ** sv_argv;
char const * env_opts = getenv(pOpts->pzPROGNAME);
token_list_t* pTL;
int sv_argc;
proc_state_mask_t sv_flag;
char ** sv_argv;
/*
* No such beast? Then bail now.
*/
if (pczOptStr == NULL)
if (env_opts == NULL)
return;
/*
* Tokenize the string. If there's nothing of interest, we'll bail
* here immediately.
*/
pTL = ao_string_tokenize(pczOptStr);
pTL = ao_string_tokenize(env_opts);
if (pTL == NULL)
return;
/*
* Substitute our $PROGNAME argument list for the real one
*/
sv_argc = pOpts->origArgCt;
sv_argc = (int)pOpts->origArgCt;
sv_argv = pOpts->origArgVect;
sv_flag = pOpts->fOptSet;
@@ -82,7 +84,7 @@ doPrognameEnv(tOptions * pOpts, teEnvPresetType type)
uintptr_t v = (uintptr_t)(pTL->tkn_list);
pOpts->origArgVect = (void *)(v - sizeof(char *));
}
pOpts->origArgCt = pTL->tkn_ct + 1;
pOpts->origArgCt = (unsigned int)pTL->tkn_ct + 1;
pOpts->fOptSet &= ~OPTPROC_ERRSTOP;
pOpts->curOptIdx = 1;
@@ -108,7 +110,7 @@ doPrognameEnv(tOptions * pOpts, teEnvPresetType type)
*/
free(pTL);
pOpts->origArgVect = sv_argv;
pOpts->origArgCt = sv_argc;
pOpts->origArgCt = (unsigned int)sv_argc;
pOpts->fOptSet = sv_flag;
}
@@ -127,6 +129,8 @@ do_env_opt(tOptState * os, char * env_name,
&& (streqvcmp(os->pzOptArg, os->pOD->pz_DisablePfx) == 0)) {
os->flags |= OPTST_DISABLED;
os->pzOptArg = NULL;
handle_opt(pOpts, os);
return;
}
switch (type) {
@@ -206,7 +210,7 @@ env_presets(tOptions * pOpts, teEnvPresetType type)
pzFlagName = zEnvName
+ snprintf(zEnvName, sizeof(zEnvName), "%s_", pOpts->pzPROGNAME);
spaceLeft = AO_NAME_SIZE - (pzFlagName - zEnvName) - 1;
spaceLeft = AO_NAME_SIZE - (unsigned long)(pzFlagName - zEnvName) - 1;
for (;ct-- > 0; st.pOD++) {
size_t nln;
@@ -244,7 +248,7 @@ env_presets(tOptions * pOpts, teEnvPresetType type)
return;
nln = strlen(st.pOD->pz_NAME) + 1;
if (nln > spaceLeft)
return;
@@ -253,7 +257,8 @@ env_presets(tOptions * pOpts, teEnvPresetType type)
}
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,11 +2,15 @@
/**
* \file file.c
*
* Time-stamp: "2011-08-06 08:49:35 bkorb"
* Handle options that have file names for arguments.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -18,11 +22,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/**
@@ -46,9 +50,7 @@ check_existence(teOptFileType ftype, tOptions * pOpts, tOptDesc * pOD)
if ((stat(fname, &sb) == 0) || (errno != ENOENT)) {
if (errno == 0)
errno = EINVAL;
fprintf(stderr, zFSOptError, errno, strerror(errno),
zFSOptErrNoExist, fname, pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
fserr_exit(pOpts->pzProgName, "stat", fname);
/* NOTREACHED */
}
/* FALLTHROUGH */
@@ -66,30 +68,25 @@ check_existence(teOptFileType ftype, tOptions * pOpts, tOptDesc * pOD)
*/
break;
l = p - fname;
l = (size_t)(p - fname);
p = AGALOC(l + 1, "fname");
memcpy(p, fname, l);
p[l] = NUL;
if ((stat(p, &sb) != 0) || (errno = EINVAL, ! S_ISDIR(sb.st_mode))) {
fprintf(stderr, zFSOptError, errno, strerror(errno),
zFSOptErrMayExist, fname, pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
if ((stat(p, &sb) != 0) || (errno = EINVAL, ! S_ISDIR(sb.st_mode)))
fserr_exit(pOpts->pzProgName, "stat", p);
/* NOTREACHED */
}
AGFREE(p);
break;
}
case FTYPE_MODE_MUST_EXIST:
if ( (stat(fname, &sb) != 0)
|| (errno = EINVAL, ! S_ISREG(sb.st_mode)) ) {
fprintf(stderr, zFSOptError, errno, strerror(errno),
zFSOptErrMustExist, fname,
pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
|| (errno = EINVAL, ! S_ISREG(sb.st_mode)) )
fserr_exit(pOpts->pzProgName, "stat", fname);
/* NOTREACHED */
}
break;
}
}
@@ -105,12 +102,9 @@ static void
open_file_fd(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
{
int fd = open(pOD->optArg.argString, mode.file_flags);
if (fd < 0) {
fprintf(stderr, zFSOptError, errno, strerror(errno),
zFSOptErrOpen, pOD->optArg.argString, pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
if (fd < 0)
fserr_exit(pOpts->pzProgName, "open", pOD->optArg.argString);
/* NOTREACHED */
}
if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
pOD->optCookie = (void *)pOD->optArg.argString;
@@ -131,13 +125,10 @@ open_file_fd(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
static void
fopen_file_fp(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
{
FILE* fp = fopen(pOD->optArg.argString, mode.file_mode);
if (fp == NULL) {
fprintf(stderr, zFSOptError, errno, strerror(errno),
zFSOptErrFopen, pOD->optArg.argString, pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
FILE * fp = fopen(pOD->optArg.argString, mode.file_mode);
if (fp == NULL)
fserr_exit(pOpts->pzProgName, "fopen", pOD->optArg.argString);
/* NOTREACHED */
}
if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
pOD->optCookie = (void *)pOD->optArg.argString;
@@ -174,11 +165,11 @@ optionFileCheck(tOptions * pOpts, tOptDesc * pOD,
switch (ftype & FTYPE_MODE_EXIST_MASK) {
case FTYPE_MODE_MUST_NOT_EXIST:
fputs(zFileCannotExist, option_usage_fp);
fputs(zFileCannotExist + tab_skip_ct, option_usage_fp);
break;
case FTYPE_MODE_MUST_EXIST:
fputs(zFileMustExist, option_usage_fp);
fputs(zFileMustExist + tab_skip_ct, option_usage_fp);
break;
}
return;
@@ -199,7 +190,9 @@ optionFileCheck(tOptions * pOpts, tOptDesc * pOD,
case FTYPE_MODE_FOPEN_FP: fopen_file_fp(pOpts, pOD, mode); break;
}
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -3,14 +3,16 @@
*
* @brief Hunt for options in the option descriptor list
*
* Time-stamp: "2012-01-29 19:07:30 bkorb"
*
* This file contains the routines that deal with processing quoted strings
* into an internal format.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,13 +24,43 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
static int
parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz);
static void
opt_ambiguities(tOptions * opts, char const * name, int nm_len);
static int
opt_match_ct(tOptions * opts, char const * name, int nm_len,
int * ixp, bool * disable);
static tSuccess
opt_set(tOptions * opts, char * arg, int idx, bool disable, tOptState * st);
static tSuccess
opt_unknown(tOptions * opts, char const * name, char * arg, tOptState * st);
static tSuccess
opt_ambiguous(tOptions * opts, char const * name, int match_ct);
static tSuccess
get_opt_arg_must(tOptions * opts, tOptState * o_st);
static tSuccess
get_opt_arg_may(tOptions * pOpts, tOptState * o_st);
static tSuccess
get_opt_arg_none(tOptions * pOpts, tOptState* o_st);
/* = = = END-STATIC-FORWARD = = = */
/**
* find the name and name length we are looking for
*/
@@ -44,10 +76,7 @@ parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz)
case NUL: return res;
case '=':
if (res >= (int)bufsz)
return -1;
memcpy(buf, *nm_pp, res);
memcpy(buf, *nm_pp, (size_t)res);
buf[res] = NUL;
*nm_pp = buf;
@@ -55,7 +84,8 @@ parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz)
return res;
default:
res++;
if (++res >= (int)bufsz)
return -1;
}
}
}
@@ -75,15 +105,15 @@ opt_ambiguities(tOptions * opts, char const * name, int nm_len)
tOptDesc * pOD = opts->pOptDesc;
int idx = 0;
fputs(zAmbigList, stderr);
fputs(zambig_list_msg, stderr);
do {
if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0)
fprintf(stderr, zAmbiguous, hyph, pOD->pz_Name);
fprintf(stderr, zambig_file, hyph, pOD->pz_Name);
else if ( (pOD->pz_DisableName != NULL)
&& (strneqvcmp(name, pOD->pz_DisableName, nm_len) == 0)
)
fprintf(stderr, zAmbiguous, hyph, pOD->pz_DisableName);
fprintf(stderr, zambig_file, hyph, pOD->pz_DisableName);
} while (pOD++, (++idx < opts->optCt));
}
@@ -257,9 +287,9 @@ static tSuccess
opt_ambiguous(tOptions * opts, char const * name, int match_ct)
{
if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
fprintf(stderr, zAmbigOptStr, opts->pzProgPath, name, match_ct);
fprintf(stderr, zambig_opt_fmt, opts->pzProgPath, name, match_ct);
if (match_ct <= 4)
opt_ambiguities(opts, name, strlen(name));
opt_ambiguities(opts, name, (int)strlen(name));
(*opts->pUsageProc)(opts, EXIT_FAILURE);
/* NOTREACHED */
_exit(EXIT_FAILURE); /* to be certain */
@@ -286,6 +316,12 @@ optionVendorOption(tOptions * pOpts, tOptDesc * pOD)
tOptState opt_st = OPTSTATE_INITIALIZER(PRESET);
char const * vopt_str = pOD->optArg.argString;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((pOD->fOptState & OPTST_RESET) != 0)
return;
if ((pOD->fOptState & OPTPROC_IMMEDIATE) == 0)
opt_st.flags = OPTST_DEFINED;
@@ -293,9 +329,10 @@ optionVendorOption(tOptions * pOpts, tOptDesc * pOD)
|| ! SUCCESSFUL(opt_find_long(pOpts, vopt_str, &opt_st))
|| ! SUCCESSFUL(get_opt_arg(pOpts, &opt_st)) )
{
fprintf(stderr, zIllVendOptStr, vopt_str);
fprintf(stderr, zIllVendOptStr, pOpts->pzProgName, vopt_str);
(*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
/* NOTREACHED */
_exit(EXIT_FAILURE); /* to be certain */
}
/*
@@ -321,31 +358,39 @@ optionVendorOption(tOptions * pOpts, tOptDesc * pOD)
/**
* Find the option descriptor by full name.
*
* @param pOpts option data
* @param opt_name name of option to look for
* @param pOptState state about current option
* @param opts option data
* @param opt_name name of option to look for
* @param state state about current option
*
* @return success status
*/
LOCAL tSuccess
opt_find_long(tOptions * pOpts, char const * opt_name, tOptState * pOptState)
opt_find_long(tOptions * opts, char const * opt_name, tOptState * state)
{
char name_buf[128];
char * opt_arg;
int nm_len = parse_opt(&opt_name, &opt_arg, name_buf, sizeof(name_buf));
int matchIdx = 0;
bool disable = false;
int match_ct =
opt_match_ct(pOpts, opt_name, nm_len, &matchIdx, &disable);
int idx = 0;
bool disable = false;
int ct;
if (nm_len <= 0) {
fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name);
(*opts->pUsageProc)(opts, EXIT_FAILURE);
/* NOTREACHED */
_exit(EXIT_FAILURE); /* to be certain */
}
ct = opt_match_ct(opts, opt_name, nm_len, &idx, &disable);
/*
* See if we found one match, no matches or multiple matches.
*/
switch (match_ct) {
case 1: return opt_set(pOpts, opt_arg, matchIdx, disable, pOptState);
case 0: return opt_unknown(pOpts, opt_name, opt_arg, pOptState);
default: return opt_ambiguous(pOpts, opt_name, match_ct);
switch (ct) {
case 1: return opt_set(opts, opt_arg, idx, disable, state);
case 0: return opt_unknown(opts, opt_name, opt_arg, state);
default: return opt_ambiguous(opts, opt_name, ct);
}
}
@@ -405,7 +450,7 @@ opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState)
return SUCCESS;
}
short_opt_error:
short_opt_error:
/*
* IF we are to stop on errors (the default, actually)
@@ -421,75 +466,235 @@ short_opt_error:
return FAILURE;
}
LOCAL tSuccess
get_opt_arg(tOptions * pOpts, tOptState * pOptState)
/**
* Process option with a required argument. Long options can either have a
* separate command line argument, or an argument attached by the '='
* character. Figure out which.
*
* @param[in,out] opts the program option descriptor
* @param[in,out] o_st the option processing state
* @returns SUCCESS or FAILURE
*/
static tSuccess
get_opt_arg_must(tOptions * opts, tOptState * o_st)
{
pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK);
switch (o_st->optType) {
case TOPT_SHORT:
/*
* See if an arg string follows the flag character
*/
if (*++(opts->pzCurOpt) == NUL)
opts->pzCurOpt = opts->origArgVect[ opts->curOptIdx++ ];
o_st->pzOptArg = opts->pzCurOpt;
break;
case TOPT_LONG:
/*
* See if an arg string has already been assigned (glued on
* with an `=' character)
*/
if (o_st->pzOptArg == NULL)
o_st->pzOptArg = opts->origArgVect[ opts->curOptIdx++ ];
break;
default:
#ifdef DEBUG
fputs("AutoOpts lib error: option type not selected\n", stderr);
exit(EXIT_FAILURE);
#endif
case TOPT_DEFAULT:
/*
* The option was selected by default. The current token is
* the option argument.
*/
break;
}
/*
* Figure out what to do about option arguments. An argument may be
* required, not associated with the option, or be optional. We detect the
* latter by examining for an option marker on the next possible argument.
* Disabled mode option selection also disables option arguments.
* Make sure we did not overflow the argument list.
*/
{
enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE;
tSuccess res;
if ((pOptState->flags & OPTST_DISABLED) != 0)
arg_type = ARG_NONE;
else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE)
arg_type = ARG_NONE;
else if (pOptState->flags & OPTST_ARG_OPTIONAL)
arg_type = ARG_MAY;
else
arg_type = ARG_MUST;
switch (arg_type) {
case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break;
case ARG_MAY: res = next_opt_arg_may( pOpts, pOptState); break;
case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break;
}
return res;
if (opts->curOptIdx > opts->origArgCt) {
fprintf(stderr, zMisArg, opts->pzProgPath, o_st->pOD->pz_Name);
return FAILURE;
}
opts->pzCurOpt = NULL; /* next time advance to next arg */
return SUCCESS;
}
/**
* Find the option descriptor for the current option
* Process an option with an optional argument. For short options, it looks
* at the character after the option character, or it consumes the next full
* argument. For long options, it looks for an '=' character attachment to
* the long option name before deciding to take the next command line
* argument.
*
* @param pOpts the option descriptor
* @param o_st a structure for managing the current processing state
* @returns SUCCESS or does not return
*/
static tSuccess
get_opt_arg_may(tOptions * pOpts, tOptState * o_st)
{
/*
* An option argument is optional.
*/
switch (o_st->optType) {
case TOPT_SHORT:
if (*++pOpts->pzCurOpt != NUL)
o_st->pzOptArg = pOpts->pzCurOpt;
else {
char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
/*
* BECAUSE it is optional, we must make sure
* we did not find another flag and that there
* is such an argument.
*/
if ((pzLA == NULL) || (*pzLA == '-'))
o_st->pzOptArg = NULL;
else {
pOpts->curOptIdx++; /* argument found */
o_st->pzOptArg = pzLA;
}
}
break;
case TOPT_LONG:
/*
* Look for an argument if we don't already have one (glued on
* with a `=' character) *AND* we are not in named argument mode
*/
if ( (o_st->pzOptArg == NULL)
&& (! NAMED_OPTS(pOpts))) {
char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
/*
* BECAUSE it is optional, we must make sure
* we did not find another flag and that there
* is such an argument.
*/
if ((pzLA == NULL) || (*pzLA == '-'))
o_st->pzOptArg = NULL;
else {
pOpts->curOptIdx++; /* argument found */
o_st->pzOptArg = pzLA;
}
}
break;
default:
case TOPT_DEFAULT:
ao_bug(zbad_default_msg);
}
/*
* After an option with an optional argument, we will
* *always* start with the next option because if there
* were any characters following the option name/flag,
* they would be interpreted as the argument.
*/
pOpts->pzCurOpt = NULL;
return SUCCESS;
}
/**
* Process option that does not have an argument.
*
* @param[in,out] opts the program option descriptor
* @param[in,out] o_st the option processing state
* @returns SUCCESS or FAILURE
*/
static tSuccess
get_opt_arg_none(tOptions * pOpts, tOptState* o_st)
{
/*
* No option argument. Make sure next time around we find
* the correct option flag character for short options
*/
if (o_st->optType == TOPT_SHORT)
(pOpts->pzCurOpt)++;
/*
* It is a long option. Make sure there was no ``=xxx'' argument
*/
else if (o_st->pzOptArg != NULL) {
fprintf(stderr, zNoArg, pOpts->pzProgPath, o_st->pOD->pz_Name);
return FAILURE;
}
/*
* It is a long option. Advance to next command line argument.
*/
else
pOpts->pzCurOpt = NULL;
return SUCCESS;
}
/**
* Process option. Figure out whether or not to look for an option argument.
*
* @param[in,out] opts the program option descriptor
* @param[in,out] o_st the option processing state
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
find_opt(tOptions * pOpts, tOptState * pOptState)
get_opt_arg(tOptions * opts, tOptState * o_st)
{
o_st->flags |= (o_st->pOD->fOptState & OPTST_PERSISTENT_MASK);
/*
* Disabled options and options specified to not have arguments
* are handled with the "none" procedure. Otherwise, check the
* optional flag and call either the "may" or "must" function.
*/
if ( ((o_st->flags & OPTST_DISABLED) != 0)
|| (OPTST_GET_ARGTYPE(o_st->flags) == OPARG_TYPE_NONE))
return get_opt_arg_none(opts, o_st);
if (o_st->flags & OPTST_ARG_OPTIONAL)
return get_opt_arg_may( opts, o_st);
return get_opt_arg_must(opts, o_st);
}
/**
* Find the option descriptor for the current option.
*
* @param[in,out] opts the program option descriptor
* @param[in,out] o_st the option processing state
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
find_opt(tOptions * opts, tOptState * o_st)
{
/*
* IF we are continuing a short option list (e.g. -xyz...)
* THEN continue a single flag option.
* OTHERWISE see if there is room to advance and then do so.
*/
if ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL))
return opt_find_short(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
if ((opts->pzCurOpt != NULL) && (*opts->pzCurOpt != NUL))
return opt_find_short(opts, (uint8_t)*(opts->pzCurOpt), o_st);
if (pOpts->curOptIdx >= pOpts->origArgCt)
if (opts->curOptIdx >= opts->origArgCt)
return PROBLEM; /* NORMAL COMPLETION */
pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx ];
opts->pzCurOpt = opts->origArgVect[ opts->curOptIdx ];
/*
* IF all arguments must be named options, ...
*/
if (NAMED_OPTS(pOpts)) {
char * pz = pOpts->pzCurOpt;
int def;
tSuccess res;
tAoUS * def_opt;
if (NAMED_OPTS(opts)) {
char * pz = opts->pzCurOpt;
int def;
tSuccess res;
uint16_t * def_opt;
pOpts->curOptIdx++;
opts->curOptIdx++;
if (*pz != '-')
return opt_find_long(pOpts, pz, pOptState);
return opt_find_long(opts, pz, o_st);
/*
* The name is prefixed with one or more hyphens. Strip them off
@@ -497,37 +702,37 @@ find_opt(tOptions * pOpts, tOptState * pOptState)
* strip off the "const" quality of the "default_opt" field.
*/
while (*(++pz) == '-') ;
def_opt = (void *)&(pOpts->specOptIdx.default_opt);
def = *def_opt;
def_opt = (void *)&(opts->specOptIdx.default_opt);
def = *def_opt;
*def_opt = NO_EQUIVALENT;
res = opt_find_long(pOpts, pz, pOptState);
*def_opt = def;
res = opt_find_long(opts, pz, o_st);
*def_opt = (uint16_t)def;
return res;
}
/*
* Note the kind of flag/option marker
*/
if (*((pOpts->pzCurOpt)++) != '-')
if (*((opts->pzCurOpt)++) != '-')
return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
/*
* Special hack for a hyphen by itself
*/
if (*(pOpts->pzCurOpt) == NUL)
if (*(opts->pzCurOpt) == NUL)
return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
/*
* The current argument is to be processed as an option argument
*/
pOpts->curOptIdx++;
opts->curOptIdx++;
/*
* We have an option marker.
* Test the next character for long option indication
*/
if (pOpts->pzCurOpt[0] == '-') {
if (*++(pOpts->pzCurOpt) == NUL)
if (opts->pzCurOpt[0] == '-') {
if (*++(opts->pzCurOpt) == NUL)
/*
* NORMAL COMPLETION - NOT this arg, but rest are operands
*/
@@ -537,13 +742,12 @@ find_opt(tOptions * pOpts, tOptState * pOptState)
* We do not allow the hyphen to be used as a flag value.
* Therefore, if long options are not to be accepted, we punt.
*/
if ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) {
fprintf(stderr, zIllOptStr, pOpts->pzProgPath,
pOpts->pzCurOpt-2);
if ((opts->fOptSet & OPTPROC_LONGOPT) == 0) {
fprintf(stderr, zIllOptStr, opts->pzProgPath, opts->pzCurOpt-2);
return FAILURE;
}
return opt_find_long(pOpts, pOpts->pzCurOpt, pOptState);
return opt_find_long(opts, opts->pzCurOpt, o_st);
}
/*
@@ -551,13 +755,14 @@ find_opt(tOptions * pOpts, tOptState * pOptState)
* option processing. Otherwise the character must be a
* short (i.e. single character) option.
*/
if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0)
return opt_find_short(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState);
if ((opts->fOptSet & OPTPROC_SHORTOPT) != 0)
return opt_find_short(opts, (uint8_t)*(opts->pzCurOpt), o_st);
return opt_find_long(pOpts, pOpts->pzCurOpt, pOptState);
return opt_find_long(opts, opts->pzCurOpt, o_st);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,12 +1,12 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
*
* DO NOT EDIT THIS FILE (genshell.c)
*
* It has been AutoGen-ed May 6, 2012 at 04:20:59 PM by AutoGen 5.16pre36
*
* It has been AutoGen-ed March 31, 2013 at 10:41:27 AM by AutoGen 5.17.3
* From the definitions genshell.def
* and the template file options
*
* Generated from AutoOpts 36:4:11 templates.
* Generated from AutoOpts 38:0:13 templates.
*
* AutoOpts is a copyrighted work. This source file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
@@ -19,24 +19,24 @@
* The genshellopt program is copyrighted and licensed
* under the following terms:
*
* Copyright (C) 1999-2012 Bruce Korb, all rights reserved.
* Copyright (C) 1999-2013 Bruce Korb, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* GNU General Public License, version 3 or later
* <http://gnu.org/licenses/gpl.html>
* redistribution under the terms of the GNU Lesser General Public License,
* version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
*
* genshellopt 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.
*
* genshellopt is distributed in the hope that it will be useful, but
* The genshellopt library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
*/
#ifndef __doxygen__
@@ -52,11 +52,8 @@
extern "C" {
#endif
extern FILE * option_usage_fp;
/* TRANSLATORS: choose the translation for option names wisely because you
cannot ever change your mind. */
#define zCopyright (genshellopt_opt_strs+0)
#define zLicenseDescrip (genshellopt_opt_strs+260)
#define zLicenseDescrip (genshellopt_opt_strs+285)
extern tUsageProc genshelloptUsage;
@@ -64,81 +61,89 @@ extern tUsageProc genshelloptUsage;
# define NULL 0
#endif
/*
* genshellopt option static const strings
/**
* static const strings for genshellopt options
*/
static char const genshellopt_opt_strs[1690] =
static char const genshellopt_opt_strs[1769] =
/* 0 */ "genshellopt 1\n"
"Copyright (C) 1999-2012 Bruce Korb, all rights reserved.\n"
"Copyright (C) 1999-2013 Bruce Korb, all rights reserved.\n"
"This is free software. It is licensed for use, modification and\n"
"redistribution under the terms of the\n"
"GNU General Public License, version 3 or later\n"
" <http://gnu.org/licenses/gpl.html>\n\0"
/* 260 */ "genshellopt is free software: you can redistribute it and/or modify it\n"
"under the terms of the GNU General Public License as published by the Free\n"
"Software Foundation, either version 3 of the License, or (at your option)\n"
"any later version.\n\n"
"genshellopt is distributed in the hope that it will be useful, but WITHOUT\n"
"redistribution under the terms of the GNU Lesser General Public License,\n"
"version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>\n\0"
/* 285 */ "The genshellopt library is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Library General Public License as\n"
"published by the Free Software Foundation; either version 2 of the License,\n"
"or (at your option) any later version.\n\n"
"This library is distributed in the hope that it will be useful, but WITHOUT\n"
"ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n"
"FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\n"
"more details.\n\n"
"You should have received a copy of the GNU General Public License along\n"
"with this program. If not, see <http://www.gnu.org/licenses/>.\n\0"
/* 871 */ "Output Script File\0"
/* 890 */ "SCRIPT\0"
/* 897 */ "script\0"
/* 904 */ "Shell name (follows \"#!\" magic)\0"
/* 936 */ "SHELL\0"
/* 942 */ "no-shell\0"
/* 951 */ "no\0"
/* 954 */ "Display extended usage information and exit\0"
/* 998 */ "help\0"
/* 1003 */ "Extended usage information passed thru pager\0"
/* 1048 */ "more-help\0"
/* 1058 */ "Output version information and exit\0"
/* 1094 */ "version\0"
/* 1102 */ "GENSHELLOPT\0"
/* 1114 */ "genshellopt - Generate Shell Option Processing Script - Ver. 1\n"
"USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
/* 1235 */ "autogen-users@lists.sourceforge.net\0"
/* 1271 */ "\n"
"Note that ``shell'' is only useful if the output file does not already\n"
"exist. If it does, then the shell name and optional first argument will be\n"
"FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public\n"
"License for more details.\n\n"
"You should have received a copy of the GNU Library General Public License\n"
"along with this library; if not, see\n"
"<http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>\n\0"
/* 957 */ "Output Script File\0"
/* 976 */ "SCRIPT\0"
/* 983 */ "script\0"
/* 990 */ "Shell name (follows \"#!\" magic)\0"
/* 1022 */ "SHELL\0"
/* 1028 */ "no-shell\0"
/* 1037 */ "no\0"
/* 1040 */ "display extended usage information and exit\0"
/* 1084 */ "help\0"
/* 1089 */ "extended usage information passed thru pager\0"
/* 1134 */ "more-help\0"
/* 1144 */ "output version information and exit\0"
/* 1180 */ "version\0"
/* 1188 */ "GENSHELLOPT\0"
/* 1200 */ "genshellopt - Generate Shell Option Processing Script - Ver. 1\n"
"Usage: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
/* 1321 */ "autogen-users@lists.sourceforge.net\0"
/* 1357 */ "Note that 'shell' is only useful if the output file does not already exist.\n"
"If it does, then the shell name and optional first argument will be\n"
"extracted from the script file.\n\0"
/* 1452 */ "\n"
"If the script file already exists and contains Automated Option Processing\n"
/* 1534 */ "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\0"
/* 1676 */ "genshellopt 1";
"by the newly generated text. The first '#!' line will be regenerated.\n\0"
/* 1755 */ "genshellopt 1";
/*
/**
* script option description:
*/
#define SCRIPT_DESC (genshellopt_opt_strs+871)
#define SCRIPT_NAME (genshellopt_opt_strs+890)
#define SCRIPT_name (genshellopt_opt_strs+897)
/** Descriptive text for the script option */
#define SCRIPT_DESC (genshellopt_opt_strs+957)
/** Upper-cased name for the script option */
#define SCRIPT_NAME (genshellopt_opt_strs+976)
/** Name string for the script option */
#define SCRIPT_name (genshellopt_opt_strs+983)
/** Compiled in flag settings for the script option */
#define SCRIPT_FLAGS (OPTST_DISABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
/**
* shell option description:
*/
#define SHELL_DESC (genshellopt_opt_strs+904)
#define SHELL_NAME (genshellopt_opt_strs+936)
#define NOT_SHELL_name (genshellopt_opt_strs+942)
#define NOT_SHELL_PFX (genshellopt_opt_strs+951)
/** Descriptive text for the shell option */
#define SHELL_DESC (genshellopt_opt_strs+990)
/** Upper-cased name for the shell option */
#define SHELL_NAME (genshellopt_opt_strs+1022)
/** disablement name for the shell option */
#define NOT_SHELL_name (genshellopt_opt_strs+1028)
/** disablement prefix for the shell option */
#define NOT_SHELL_PFX (genshellopt_opt_strs+1037)
/** Name string for the shell option */
#define SHELL_name (NOT_SHELL_name + 3)
/** Compiled in flag settings for the shell option */
#define SHELL_FLAGS (OPTST_INITENABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
* Help/More_Help/Version option descriptions:
*/
#define HELP_DESC (genshellopt_opt_strs+954)
#define HELP_name (genshellopt_opt_strs+998)
#define HELP_DESC (genshellopt_opt_strs+1040)
#define HELP_name (genshellopt_opt_strs+1084)
#ifdef HAVE_WORKING_FORK
#define MORE_HELP_DESC (genshellopt_opt_strs+1003)
#define MORE_HELP_name (genshellopt_opt_strs+1048)
#define MORE_HELP_DESC (genshellopt_opt_strs+1089)
#define MORE_HELP_name (genshellopt_opt_strs+1134)
#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
#else
#define MORE_HELP_DESC NULL
@@ -151,9 +156,9 @@ static char const genshellopt_opt_strs[1690] =
# define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
#endif
#define VER_DESC (genshellopt_opt_strs+1058)
#define VER_name (genshellopt_opt_strs+1094)
/*
#define VER_DESC (genshellopt_opt_strs+1144)
#define VER_name (genshellopt_opt_strs+1180)
/**
* Declare option callback procedures
*/
extern tOptProc
@@ -200,7 +205,7 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
/* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_VERSION,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ VER_FLAGS, 0,
/* opt state flags */ VER_FLAGS, AOUSE_VERSION,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
@@ -214,7 +219,7 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
/* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_HELP,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
/* opt state flags */ OPTST_IMM | OPTST_NO_INIT, AOUSE_HELP,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
@@ -226,7 +231,7 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
/* equiv idx value */ NO_EQUIVALENT, VALUE_GENSHELL_OPT_MORE_HELP,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ MORE_HELP_FLAGS, 0,
/* opt state flags */ MORE_HELP_FLAGS, AOUSE_MORE_HELP,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
@@ -236,19 +241,24 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Define the genshellopt Option Environment
*/
#define zPROGNAME (genshellopt_opt_strs+1102)
#define zUsageTitle (genshellopt_opt_strs+1114)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** Reference to the upper cased version of genshellopt. */
#define zPROGNAME (genshellopt_opt_strs+1188)
/** Reference to the title line for genshellopt usage. */
#define zUsageTitle (genshellopt_opt_strs+1200)
/** There is no genshellopt configuration file. */
#define zRcName NULL
/** There are no directories to search for genshellopt config files. */
#define apzHomeList NULL
#define zBugsAddr (genshellopt_opt_strs+1235)
#define zExplain (genshellopt_opt_strs+1271)
#define zDetail (genshellopt_opt_strs+1452)
#define zFullVersion (genshellopt_opt_strs+1676)
/* extracted from optcode.tlib near line 350 */
/** The genshellopt program bug email address. */
#define zBugsAddr (genshellopt_opt_strs+1321)
/** Clarification/explanation of what genshellopt does. */
#define zExplain (genshellopt_opt_strs+1357)
/** Extra detail explaining what genshellopt does. */
#define zDetail (genshellopt_opt_strs+1534)
/** The full version string for genshellopt. */
#define zFullVersion (genshellopt_opt_strs+1755)
/* extracted from optcode.tlib near line 371 */
#if defined(ENABLE_NLS)
# define OPTPROC_BASE OPTPROC_TRANSLATE
@@ -258,9 +268,7 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
# define translate_option_strings NULL
#endif /* ENABLE_NLS */
#define genshellopt_full_usage (NULL)
#define genshellopt_short_usage (NULL)
#endif /* not defined __doxygen__ */
@@ -271,8 +279,8 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
/**
* The callout function that invokes the genshelloptUsage function.
*
* @param pOptions the AutoOpts option description structure
* @param pOptDesc the descriptor for the "help" (usage) option.
* @param[in] pOptions the AutoOpts option description structure
* @param[in] pOptDesc the descriptor for the "help" (usage) option.
* @noreturn
*/
static void
@@ -283,7 +291,7 @@ doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
(void)pOptDesc;
(void)pOptions;
}
/* extracted from optmain.tlib near line 1113 */
/* extracted from optmain.tlib near line 1254 */
/**
* The directory containing the data associated with genshellopt.
@@ -299,6 +307,7 @@ doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
#ifndef WITH_PACKAGER
# define genshellopt_packager_info NULL
#else
/** Packager information for genshellopt. */
static char const genshellopt_packager_info[] =
"Packaged by " WITH_PACKAGER
@@ -352,42 +361,69 @@ tOptions genshelloptOptions = {
};
#if ENABLE_NLS
/**
* This code is designed to translate translatable option text for the
* genshellopt program. These translations happen upon entry
* to optionProcess().
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef HAVE_DCGETTEXT
# include <gettext.h>
#endif
#include <autoopts/usage-txt.h>
static char* AO_gettext(char const* pz);
static void coerce_it(void** s);
static char * AO_gettext(char const * pz);
static void coerce_it(void ** s);
/**
* AutoGen specific wrapper function for gettext.
* It relies on the macro _() to convert from English to the target
* language, then strdup-duplicates the result string.
* AutoGen specific wrapper function for gettext. It relies on the macro _()
* to convert from English to the target language, then strdup-duplicates the
* result string. It tries the "libopts" domain first, then whatever has been
* set via the \a textdomain(3) call.
*
* @param[in] pz the input text used as a lookup key.
* @returns the translated text (if there is one),
* or the original text (if not).
*/
static char *
AO_gettext(char const* pz)
AO_gettext(char const * pz)
{
char* pzRes;
char * res;
if (pz == NULL)
return NULL;
pzRes = _(pz);
if (pzRes == pz)
return pzRes;
pzRes = strdup(pzRes);
if (pzRes == NULL) {
#ifdef HAVE_DCGETTEXT
/*
* While processing the option_xlateable_txt data, try to use the
* "libopts" domain. Once we switch to the option descriptor data,
* do *not* use that domain.
*/
if (option_xlateable_txt.field_ct != 0) {
res = dgettext("libopts", pz);
if (res == pz)
res = (char *)(void *)_(pz);
} else
res = (char *)(void *)_(pz);
#else
res = (char *)(void *)_(pz);
#endif
if (res == pz)
return res;
res = strdup(res);
if (res == NULL) {
fputs(_("No memory for duping translated strings\n"), stderr);
exit(GENSHELLOPT_EXIT_FAILURE);
}
return pzRes;
return res;
}
static void coerce_it(void** s) { *s = AO_gettext(*s);
/**
* All the pointers we use are marked "* const", but they are stored in
* writable memory. Coerce the mutability and set the pointer.
*/
static void coerce_it(void ** s) { *s = AO_gettext(*s);
}
/**
@@ -397,55 +433,411 @@ static void coerce_it(void** s) { *s = AO_gettext(*s);
static void
translate_option_strings(void)
{
tOptions * const pOpt = &genshelloptOptions;
tOptions * const opts = &genshelloptOptions;
/*
* Guard against re-translation. It won't work. The strings will have
* been changed by the first pass through this code. One shot only.
*/
if (option_usage_text.field_ct != 0) {
if (option_xlateable_txt.field_ct != 0) {
/*
* Do the translations. The first pointer follows the field count
* field. The field count field is the size of a pointer.
*/
tOptDesc * pOD = pOpt->pOptDesc;
char ** ppz = (char**)(void*)&(option_usage_text);
int ix = option_usage_text.field_ct;
char ** ppz = (char**)(void*)&(option_xlateable_txt);
int ix = option_xlateable_txt.field_ct;
do {
ppz++;
ppz++; /* skip over field_ct */
*ppz = AO_gettext(*ppz);
} while (--ix > 0);
/* prevent re-translation and disable "libopts" domain lookup */
option_xlateable_txt.field_ct = 0;
coerce_it((void*)&(pOpt->pzCopyright));
coerce_it((void*)&(pOpt->pzCopyNotice));
coerce_it((void*)&(pOpt->pzFullVersion));
coerce_it((void*)&(pOpt->pzUsageTitle));
coerce_it((void*)&(pOpt->pzExplain));
coerce_it((void*)&(pOpt->pzDetail));
coerce_it((void*)&(pOpt->pzPackager));
option_usage_text.field_ct = 0;
for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
coerce_it((void*)&(pOD->pzText));
}
if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
tOptDesc * pOD = pOpt->pOptDesc;
int ix;
for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
coerce_it((void*)&(pOD->pz_Name));
coerce_it((void*)&(pOD->pz_DisableName));
coerce_it((void*)&(pOD->pz_DisablePfx));
coerce_it((void*)&(opts->pzCopyright));
coerce_it((void*)&(opts->pzCopyNotice));
coerce_it((void*)&(opts->pzFullVersion));
coerce_it((void*)&(opts->pzUsageTitle));
coerce_it((void*)&(opts->pzExplain));
coerce_it((void*)&(opts->pzDetail));
{
tOptDesc * od = opts->pOptDesc;
for (ix = opts->optCt; ix > 0; ix--, od++)
coerce_it((void*)&(od->pzText));
}
/* prevent re-translation */
genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
}
}
#endif /* ENABLE_NLS */
#ifdef DO_NOT_COMPILE_THIS_CODE_IT_IS_FOR_GETTEXT
/** I18N function strictly for xgettext. Do not compile. */
static void bogus_function(void) {
/* TRANSLATORS:
The following dummy function was crated solely so that xgettext can extract
the correct strings. These strings are actually referenced by a field name
in the genshelloptOptions structure noted in the comments below. The
literal text is defined in genshellopt_opt_strs.
NOTE: the strings below are segmented with respect to the source string
genshellopt_opt_strs. The strings above are handed off for translation
at run time a paragraph at a time. Consequently, they are presented here
for translation a paragraph at a time.
ALSO: often the description for an option will reference another option
by name. These are set off with apostrophe quotes (I hope). Do not
translate option names.
*/
/* referenced via genshelloptOptions.pzCopyright */
puts(_("genshellopt 1\n\
Copyright (C) 1999-2013 Bruce Korb, all rights reserved.\n\
This is free software. It is licensed for use, modification and\n\
redistribution under the terms of the GNU Lesser General Public License,\n\
version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>\n"));
/* referenced via genshelloptOptions.pzCopyNotice */
puts(_("The genshellopt library is free software; you can redistribute it and/or\n\
modify it under the terms of the GNU Library General Public License as\n\
published by the Free Software Foundation; either version 2 of the License,\n\
or (at your option) any later version.\n\n"));
puts(_("This library is distributed in the hope that it will be useful, but WITHOUT\n\
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public\n\
License for more details.\n\n"));
puts(_("You should have received a copy of the GNU Library General Public License\n\
along with this library; if not, see\n\
<http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>\n"));
/* referenced via genshelloptOptions.pOptDesc->pzText */
puts(_("Output Script File"));
/* referenced via genshelloptOptions.pOptDesc->pzText */
puts(_("Shell name (follows \"#!\" magic)"));
/* referenced via genshelloptOptions.pOptDesc->pzText */
puts(_("display extended usage information and exit"));
/* referenced via genshelloptOptions.pOptDesc->pzText */
puts(_("extended usage information passed thru pager"));
/* referenced via genshelloptOptions.pOptDesc->pzText */
puts(_("output version information and exit"));
/* referenced via genshelloptOptions.pzUsageTitle */
puts(_("genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
Usage: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n"));
/* referenced via genshelloptOptions.pzExplain */
puts(_("Note that 'shell' is only useful if the output file does not already exist.\n\
If it does, then the shell name and optional first argument will be\n\
extracted from the script file.\n"));
/* referenced via genshelloptOptions.pzDetail */
puts(_("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"));
/* referenced via genshelloptOptions.pzFullVersion */
puts(_("genshellopt 1"));
/* referenced via genshelloptOptions.pzFullUsage */
puts(_("<<<NOT-FOUND>>>"));
/* referenced via genshelloptOptions.pzShortUsage */
puts(_("<<<NOT-FOUND>>>"));
/* LIBOPTS-MESSAGES: */
#line 60 "../autoopts.c"
puts(_("allocation of %d bytes failed\n"));
#line 86 "../autoopts.c"
puts(_("allocation of %d bytes failed\n"));
#line 53 "../init.c"
puts(_("AutoOpts function called without option descriptor\n"));
#line 89 "../init.c"
puts(_("\tThis exceeds the compiled library version: "));
#line 87 "../init.c"
puts(_("Automated Options Processing Error!\n"
"\t%s called AutoOpts function with structure version %d:%d:%d.\n"));
#line 73 "../autoopts.c"
puts(_("realloc of %d bytes at 0x%p failed\n"));
#line 91 "../init.c"
puts(_("\tThis is less than the minimum library version: "));
#line 121 "../version.c"
puts(_("Automated Options version %s\n"
"\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n"));
#line 310 "../usage.c"
puts(_("(AutoOpts bug): %s.\n"));
#line 90 "../reset.c"
puts(_("optionResetOpt() called, but reset-option not configured"));
#line 329 "../usage.c"
puts(_("could not locate the 'help' option"));
#line 351 "../autoopts.c"
puts(_("optionProcess() was called with invalid data"));
#line 783 "../usage.c"
puts(_("invalid argument type specified"));
#line 589 "../find.c"
puts(_("defaulted to option with optional arg"));
#line 76 "../alias.c"
puts(_("aliasing option is out of range."));
#line 229 "../enum.c"
puts(_("%s error: the keyword '%s' is ambiguous for %s\n"));
#line 108 "../find.c"
puts(_(" The following options match:\n"));
#line 290 "../find.c"
puts(_("%s: ambiguous option name: %s (matches %d options)\n"));
#line 161 "../check.c"
puts(_("%s: Command line arguments required\n"));
#line 43 "../alias.c"
puts(_("%d %s%s options allowed\n"));
#line 81 "../makeshell.c"
puts(_("%s error %d (%s) calling %s for '%s'\n"));
#line 293 "../makeshell.c"
puts(_("interprocess pipe"));
#line 168 "../version.c"
puts(_("error: version option argument '%c' invalid. Use:\n"
"\t'v' - version only\n"
"\t'c' - version and copyright\n"
"\t'n' - version and full copyright notice\n"));
#line 58 "../check.c"
puts(_("%s error: the '%s' and '%s' options conflict\n"));
#line 214 "../find.c"
puts(_("%s: The '%s' option has been disabled."));
#line 421 "../find.c"
puts(_("%s: The '%s' option has been disabled."));
#line 38 "../alias.c"
puts(_("-equivalence"));
#line 460 "../find.c"
puts(_("%s: illegal option -- %c\n"));
#line 110 "../reset.c"
puts(_("%s: illegal option -- %c\n"));
#line 268 "../find.c"
puts(_("%s: illegal option -- %s\n"));
#line 746 "../find.c"
puts(_("%s: illegal option -- %s\n"));
#line 118 "../reset.c"
puts(_("%s: illegal option -- %s\n"));
#line 332 "../find.c"
puts(_("%s: unknown vendor extension option -- %s\n"));
#line 154 "../enum.c"
puts(_(" or an integer from %d through %d\n"));
#line 164 "../enum.c"
puts(_(" or an integer from %d through %d\n"));
#line 782 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n"));
#line 1110 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n"));
#line 379 "../find.c"
puts(_("%s: invalid option name: %s\n"));
#line 518 "../find.c"
puts(_("%s: The '%s' option requires an argument.\n"));
#line 171 "../autoopts.c"
puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n"
"\t'%s' and '%s'."));
#line 94 "../check.c"
puts(_("%s error: The %s option is required\n"));
#line 623 "../find.c"
puts(_("%s: The '%s' option cannot have an argument.\n"));
#line 151 "../check.c"
puts(_("%s: Command line arguments are not allowed.\n"));
#line 531 "../save.c"
puts(_("error %d (%s) creating %s\n"));
#line 229 "../enum.c"
puts(_("%s error: '%s' does not match any %s keywords.\n"));
#line 93 "../reset.c"
puts(_("%s error: The '%s' option requires an argument.\n"));
#line 184 "../save.c"
puts(_("error %d (%s) stat-ing %s\n"));
#line 238 "../save.c"
puts(_("error %d (%s) stat-ing %s\n"));
#line 143 "../restore.c"
puts(_("%s error: no saved option state\n"));
#line 246 "../autoopts.c"
puts(_("'%s' is not a command line option.\n"));
#line 114 "../time.c"
puts(_("%s error: '%s' is not a recognizable date/time.\n"));
#line 132 "../save.c"
puts(_("'%s' not defined\n"));
#line 53 "../time.c"
puts(_("%s error: '%s' is not a recognizable time duration.\n"));
#line 92 "../check.c"
puts(_("%s error: The %s option must appear %d times.\n"));
#line 157 "../numeric.c"
puts(_("%s error: '%s' is not a recognizable number.\n"));
#line 195 "../enum.c"
puts(_("%s error: %s exceeds %s keyword count\n"));
#line 366 "../usage.c"
puts(_("Try '%s %s' for more information.\n"));
#line 45 "../alias.c"
puts(_("one %s%s option allowed\n"));
#line 195 "../makeshell.c"
puts(_("standard output"));
#line 930 "../makeshell.c"
puts(_("standard output"));
#line 304 "../usage.c"
puts(_("standard output"));
#line 451 "../usage.c"
puts(_("standard output"));
#line 660 "../usage.c"
puts(_("standard output"));
#line 175 "../version.c"
puts(_("standard output"));
#line 304 "../usage.c"
puts(_("standard error"));
#line 451 "../usage.c"
puts(_("standard error"));
#line 660 "../usage.c"
puts(_("standard error"));
#line 175 "../version.c"
puts(_("standard error"));
#line 195 "../makeshell.c"
puts(_("write"));
#line 930 "../makeshell.c"
puts(_("write"));
#line 303 "../usage.c"
puts(_("write"));
#line 450 "../usage.c"
puts(_("write"));
#line 659 "../usage.c"
puts(_("write"));
#line 174 "../version.c"
puts(_("write"));
#line 60 "../numeric.c"
puts(_("%s error: %s option value %ld is out of range.\n"));
#line 44 "../check.c"
puts(_("%s error: %s option requires the %s option\n"));
#line 131 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 183 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 237 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 256 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 530 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n"));
/* END-LIBOPTS-MESSAGES */
/* USAGE-TEXT: */
#line 908 "../usage.c"
puts(_("\t\t\t\t- an alternate for '%s'\n"));
#line 1177 "../usage.c"
puts(_("Version, usage and configuration options:"));
#line 959 "../usage.c"
puts(_("\t\t\t\t- default option for unnamed options\n"));
#line 872 "../usage.c"
puts(_("\t\t\t\t- disabled as '--%s'\n"));
#line 1146 "../usage.c"
puts(_(" --- %-14s %s\n"));
#line 1144 "../usage.c"
puts(_("This option has been disabled"));
#line 899 "../usage.c"
puts(_("\t\t\t\t- enabled by default\n"));
#line 40 "../alias.c"
puts(_("%s error: only "));
#line 1221 "../usage.c"
puts(_(" - examining environment variables named %s_*\n"));
#line 168 "../file.c"
puts(_("\t\t\t\t- file must not pre-exist\n"));
#line 172 "../file.c"
puts(_("\t\t\t\t- file must pre-exist\n"));
#line 416 "../usage.c"
puts(_("Options are specified by doubled hyphens and their name or by a single\n"
"hyphen and the flag character.\n"));
#line 908 "../makeshell.c"
puts(_("\n"
"= = = = = = = =\n\n"
"This incarnation of genshell will produce\n"
"a shell script to parse the options for %s:\n\n"));
#line 161 "../enum.c"
puts(_(" or an integer mask with any of the lower %d bits set\n"));
#line 932 "../usage.c"
puts(_("\t\t\t\t- is a set membership option\n"));
#line 953 "../usage.c"
puts(_("\t\t\t\t- must appear between %d and %d times\n"));
#line 418 "../usage.c"
puts(_("Options are specified by single or double hyphens and their name.\n"));
#line 939 "../usage.c"
puts(_("\t\t\t\t- may appear multiple times\n"));
#line 926 "../usage.c"
puts(_("\t\t\t\t- may not be preset\n"));
#line 1336 "../usage.c"
puts(_(" Arg Option-Name Description\n"));
#line 1272 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n"));
#line 1330 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n"));
#line 1331 "../usage.c"
puts(_(" %3s %s"));
#line 1337 "../usage.c"
puts(_(" %3s %s"));
#line 423 "../usage.c"
puts(_("The '-#<number>' option may omit the hash char\n"));
#line 419 "../usage.c"
puts(_("All arguments are named options.\n"));
#line 1006 "../usage.c"
puts(_(" - reading file %s"));
#line 445 "../usage.c"
puts(_("\n"
"Please send bug reports to: <%s>\n"));
#line 100 "../version.c"
puts(_("\n"
"Please send bug reports to: <%s>\n"));
#line 129 "../version.c"
puts(_("\n"
"Please send bug reports to: <%s>\n"));
#line 938 "../usage.c"
puts(_("\t\t\t\t- may NOT appear - preset only\n"));
#line 978 "../usage.c"
puts(_("\n"
"The following option preset mechanisms are supported:\n"));
#line 1219 "../usage.c"
puts(_("\n"
"The following option preset mechanisms are supported:\n"));
#line 717 "../usage.c"
puts(_("prohibits these options:\n"));
#line 712 "../usage.c"
puts(_("prohibits the option '%s'\n"));
#line 81 "../numeric.c"
puts(_("%s%ld to %ld"));
#line 79 "../numeric.c"
puts(_("%sgreater than or equal to %ld"));
#line 75 "../numeric.c"
puts(_("%s%ld exactly"));
#line 68 "../numeric.c"
puts(_("%sit must lie in one of the ranges:\n"));
#line 68 "../numeric.c"
puts(_("%sit must be in the range:\n"));
#line 88 "../numeric.c"
puts(_(", or\n"));
#line 66 "../numeric.c"
puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n"));
#line 77 "../numeric.c"
puts(_("%sless than or equal to %ld"));
#line 426 "../usage.c"
puts(_("Operands and options may be intermixed. They will be reordered.\n"));
#line 687 "../usage.c"
puts(_("requires the option '%s'\n"));
#line 690 "../usage.c"
puts(_("requires these options:\n"));
#line 1348 "../usage.c"
puts(_(" Arg Option-Name Req? Description\n"));
#line 1342 "../usage.c"
puts(_(" Flg Arg Option-Name Req? Description\n"));
#line 162 "../enum.c"
puts(_("or you may use a numeric representation. Preceding these with a '!'\n"
"will clear the bits, specifying 'none' will clear all bits, and 'all'\n"
"will set them all. Multiple entries may be passed as an option\n"
"argument list.\n"));
#line 945 "../usage.c"
puts(_("\t\t\t\t- may appear up to %d times\n"));
#line 72 "../enum.c"
puts(_("The valid \"%s\" option keywords are:\n"));
#line 1181 "../usage.c"
puts(_("The next option supports vendor supported extra options:"));
#line 808 "../usage.c"
puts(_("These additional options are:"));
/* END-USAGE-TEXT */
}
#endif /* uncompilable code */
#ifdef __cplusplus
}
#endif

View File

@@ -1,12 +1,12 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
*
* DO NOT EDIT THIS FILE (genshell.h)
*
* It has been AutoGen-ed May 6, 2012 at 04:20:59 PM by AutoGen 5.16pre36
*
* It has been AutoGen-ed March 31, 2013 at 10:41:27 AM by AutoGen 5.17.3
* From the definitions genshell.def
* and the template file options
*
* Generated from AutoOpts 36:4:11 templates.
* Generated from AutoOpts 38:0:13 templates.
*
* AutoOpts is a copyrighted work. This header file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
@@ -19,26 +19,26 @@
* The genshellopt program is copyrighted and licensed
* under the following terms:
*
* Copyright (C) 1999-2012 Bruce Korb, all rights reserved.
* Copyright (C) 1999-2013 Bruce Korb, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* GNU General Public License, version 3 or later
* <http://gnu.org/licenses/gpl.html>
* redistribution under the terms of the GNU Lesser General Public License,
* version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
*
* genshellopt 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.
*
* genshellopt is distributed in the hope that it will be useful, but
* The genshellopt library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
*/
/*
/**
* This file contains the programmatic interface to the Automated
* Options generated for the genshellopt program.
* These macros are documented in the AutoGen info file in the
@@ -48,22 +48,22 @@
#define AUTOOPTS_GENSHELL_H_GUARD 1
#include <autoopts/options.h>
/*
/**
* Ensure that the library used for compiling this generated header is at
* least as new as the version current when the header template was released
* (not counting patch version increments). Also ensure that the oldest
* tolerable version is at least as old as what was current when the header
* template was released.
*/
#define AO_TEMPLATE_VERSION 147460
#define AO_TEMPLATE_VERSION 155648
#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
|| (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
# error option template version mismatches autoopts/options.h header
Choke Me.
#endif
/*
* Enumeration of each option:
/**
* Enumeration of each option type for genshellopt
*/
typedef enum {
INDEX_GENSHELL_OPT_SCRIPT = 0,
@@ -72,49 +72,71 @@ typedef enum {
INDEX_GENSHELL_OPT_HELP = 3,
INDEX_GENSHELL_OPT_MORE_HELP = 4
} teGenshell_OptIndex;
/** count of all options for genshellopt */
#define GENSHELL_OPTION_CT 5
/** genshellopt version */
#define GENSHELLOPT_VERSION "1"
/** Full genshellopt version text */
#define GENSHELLOPT_FULL_VERSION "genshellopt 1"
/*
/**
* Interface defines for all options. Replace "n" with the UPPER_CASED
* option name (as in the teGenshell_OptIndex enumeration above).
* e.g. HAVE_GENSHELL_OPT(SCRIPT)
*/
#define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
/** 'true' if an option has been specified in any way */
#define HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
/** The string argument to an option. The argument type must be "string". */
#define GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
/** Mask the option state revealing how an option was specified.
* It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
* \a OPTST_DEFINED, \a OPTST_RESET or zero.
*/
#define STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK)
/** Count of option's occurrances *on the command line*. */
#define COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt)
/** mask of \a OPTST_SET and \a OPTST_DEFINED. */
#define ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n)))
/** 'true' if \a HAVE_OPT would yield 'false'. */
#define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n)))
/** 'true' if OPTST_DISABLED bit not set. */
#define ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n)))
/** number of stacked option arguments.
* Valid only for stacked option arguments. */
#define STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt)
/** stacked argument vector.
* Valid only for stacked option arguments. */
#define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs)
/** Reset an option. */
#define CLEAR_GENSHELL_OPT(n) STMTS( \
GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \
if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
GENSHELL_DESC(n).optCookie = NULL )
/* * * * * *
*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Enumeration of genshellopt exit codes
*/
typedef enum {
GENSHELLOPT_EXIT_SUCCESS = 0,
GENSHELLOPT_EXIT_FAILURE = 1,
GENSHELLOPT_EXIT_SUCCESS = 0,
GENSHELLOPT_EXIT_FAILURE = 1,
GENSHELLOPT_EXIT_USAGE_ERROR = 64,
GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
} genshellopt_exit_code_t;
/* * * * * *
*
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Interface defines for specific options.
* @{
*/
#define VALUE_GENSHELL_OPT_SCRIPT 'o'
#define VALUE_GENSHELL_OPT_SHELL 's'
/** option flag (value) for " (get "val-name") " option */
#define VALUE_GENSHELL_OPT_HELP '?'
/** option flag (value) for " (get "val-name") " option */
#define VALUE_GENSHELL_OPT_MORE_HELP '!'
/** option flag (value) for " (get "val-name") " option */
#define VALUE_GENSHELL_OPT_VERSION 'v'
/*
* Interface defines not associated with particular options
@@ -126,7 +148,7 @@ typedef enum {
genshelloptOptions.pzCurOpt = NULL )
#define START_GENSHELL_OPT RESTART_GENSHELL_OPT(1)
#define GENSHELL_USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
/* extracted from opthead.tlib near line 484 */
/* extracted from opthead.tlib near line 538 */
#ifdef __cplusplus
extern "C" {
@@ -142,6 +164,12 @@ extern tOptions genshelloptOptions;
#if defined(ENABLE_NLS)
# ifndef _
# include <stdio.h>
# ifndef HAVE_GETTEXT
extern char * gettext(char const *);
# else
# include <libintl.h>
# endif
static inline char* aoGetsText(char const* pz) {
if (pz == NULL) return NULL;
return (char*)gettext(pz);

287
libopts/gettext.h Normal file
View File

@@ -0,0 +1,287 @@
/* Convenience header for conditional use of GNU <libintl.h>.
Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef _LIBGETTEXT_H
#define _LIBGETTEXT_H 1
/* NLS can be disabled through the configure --disable-nls option. */
#if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
the gettext() and ngettext() macros. This is an alternative to calling
textdomain(), and is useful for libraries. */
# ifdef DEFAULT_TEXT_DOMAIN
# undef gettext
# define gettext(Msgid) \
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
# endif
#else
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
chokes if dcgettext is defined as a macro. So include it now, to make
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
as well because people using "gettext.h" will not include <libintl.h>,
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is OK. */
#if defined(__sun)
# include <locale.h>
#endif
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
it now, to make later inclusions of <libintl.h> a NOP. */
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
# include <cstdlib>
# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
# include <libintl.h>
# endif
#endif
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# undef gettext
# define gettext(Msgid) ((const char *) (Msgid))
# undef dgettext
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
# undef dcgettext
# define dcgettext(Domainname, Msgid, Category) \
((void) (Category), dgettext (Domainname, Msgid))
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
((N) == 1 \
? ((void) (Msgid2), (const char *) (Msgid1)) \
: ((void) (Msgid1), (const char *) (Msgid2)))
# undef dngettext
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
# undef dcngettext
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
# undef textdomain
# define textdomain(Domainname) ((const char *) (Domainname))
# undef bindtextdomain
# define bindtextdomain(Domainname, Dirname) \
((void) (Domainname), (const char *) (Dirname))
# undef bind_textdomain_codeset
# define bind_textdomain_codeset(Domainname, Codeset) \
((void) (Domainname), (const char *) (Codeset))
#endif
/* Prefer gnulib's setlocale override over libintl's setlocale override. */
#ifdef GNULIB_defined_setlocale
# undef setlocale
# define setlocale rpl_setlocale
#endif
/* A pseudo function call that serves as a marker for the automated
extraction of messages, but does not call gettext(). The run-time
translation is done at a different place in the code.
The argument, String, should be a literal string. Concatenated strings
and other string expressions won't work.
The macro's expansion is not parenthesized, so that it is suitable as
initializer for static 'char[]' or 'const char[]' variables. */
#define gettext_noop(String) String
/* The separator between msgctxt and msgid in a .mo file. */
#define GETTEXT_CONTEXT_GLUE "\004"
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
short and rarely need to change.
The letter 'p' stands for 'particular' or 'special'. */
#ifdef DEFAULT_TEXT_DOMAIN
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#else
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#endif
#define dpgettext(Domainname, Msgctxt, Msgid) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
#ifdef DEFAULT_TEXT_DOMAIN
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#else
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#endif
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
int category)
{
const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id)
return msgid;
else
return translation;
}
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
if (translation == msg_ctxt_id || translation == msgid_plural)
return (n == 1 ? msgid : msgid_plural);
else
return translation;
}
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
can be arbitrary expressions. But for string literals these macros are
less efficient than those above. */
#include <string.h>
#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
/* || __STDC_VERSION__ >= 199901L */ )
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
#else
# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
#endif
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
#include <stdlib.h>
#endif
#define pgettext_expr(Msgctxt, Msgid) \
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (translation != msg_ctxt_id)
return translation;
}
return msgid;
}
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation;
}
return (n == 1 ? msgid : msgid_plural);
}
#endif /* _LIBGETTEXT_H */

297
libopts/init.c Normal file
View File

@@ -0,0 +1,297 @@
/**
* \file initialize.c
*
* initialize the libopts data structures.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (C) 1992-2013 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
* of the user of the license.
*
* The GNU Lesser General Public License, version 3 or later
* See the files "COPYING.lgplv3" and "COPYING.gplv3"
*
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following sha256 sums:
*
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
static tSuccess
do_presets(tOptions * opts);
/* = = = END-STATIC-FORWARD = = = */
/**
* 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
* the call is not the first to the library and, thus, that this has
* already been called.)
*
* Upon successful completion, pzProgName and pzProgPath are set.
*
* @param[in,out] opts program options descriptor
* @param[in] pname name of program, from argv[]
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
validate_struct(tOptions * opts, char const * pname)
{
if (opts == NULL) {
fputs(zno_opt_arg, stderr);
return FAILURE;
}
/*
* IF the client has enabled translation and the translation procedure
* is available, then go do it.
*/
if ( ((opts->fOptSet & OPTPROC_TRANSLATE) != 0)
&& (opts->pTransProc != NULL)
&& (option_xlateable_txt.field_ct != 0) ) {
/*
* If option names are not to be translated at all, then do not do
* it for configuration parsing either. (That is the bit that really
* gets tested anyway.)
*/
if ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT)
opts->fOptSet |= OPTPROC_NXLAT_OPT_CFG;
(*opts->pTransProc)();
}
/*
* IF the struct version is not the current, and also
* either too large (?!) or too small,
* THEN emit error message and fail-exit
*/
if ( ( opts->structVersion != OPTIONS_STRUCT_VERSION )
&& ( (opts->structVersion > OPTIONS_STRUCT_VERSION )
|| (opts->structVersion < OPTIONS_MINIMUM_VERSION )
) ) {
static char const ao_ver_string[] =
STR(AO_CURRENT)":"STR(AO_REVISION)":"STR(AO_AGE)"\n";
fprintf(stderr, zwrong_ver, pname, NUM_TO_VER(opts->structVersion));
if (opts->structVersion > OPTIONS_STRUCT_VERSION )
fputs(ztoo_new, stderr);
else
fputs(ztoo_old, stderr);
fwrite(ao_ver_string, sizeof(ao_ver_string) - 1, 1, stderr);
return FAILURE;
}
/*
* If the program name hasn't been set, then set the name and the path
* and the set of equivalent characters.
*/
if (opts->pzProgName == NULL) {
char const * pz = strrchr(pname, DIRCH);
char const ** pp =
(char const **)(void **)&(opts->pzProgName);
if (pz != NULL) {
*pp = pz+1;
} else {
*pp = pname;
pz = pathfind(getenv("PATH"), (char *)pname, "rx");
if (pz != NULL)
pname = (void *)pz;
}
pp = (char const **)(void **)&(opts->pzProgPath);
*pp = pname;
/*
* when comparing long names, these are equivalent
*/
strequate(zSepChars);
}
return SUCCESS;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* DO PRESETS
*
* The next several routines do the immediate action pass on the command
* line options, then the environment variables, then the config files in
* reverse order. Once done with that, the order is reversed and all
* the config files and environment variables are processed again, this
* time only processing the non-immediate action options. do_presets()
* will then return for optionProcess() to do the final pass on the command
* line arguments.
*/
/**
* scan the command line for immediate action options.
* This is only called the first time through.
* While this procedure is active, the OPTPROC_IMMEDIATE is true.
*
* @param pOpts program options descriptor
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
immediate_opts(tOptions * opts)
{
tSuccess res;
opts->fOptSet |= OPTPROC_IMMEDIATE;
opts->curOptIdx = 1; /* start by skipping program name */
opts->pzCurOpt = NULL;
/*
* Examine all the options from the start. We process any options that
* are marked for immediate processing.
*/
for (;;) {
tOptState opt_st = OPTSTATE_INITIALIZER(PRESET);
res = next_opt(opts, &opt_st);
switch (res) {
case FAILURE: goto failed_option;
case PROBLEM: res = SUCCESS; goto leave;
case SUCCESS: break;
}
/*
* IF this is an immediate-attribute option, then do it.
*/
if (! DO_IMMEDIATELY(opt_st.flags))
continue;
if (! SUCCESSFUL(handle_opt(opts, &opt_st)))
break;
} failed_option:;
if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*opts->pUsageProc)(opts, EXIT_FAILURE);
leave:
opts->fOptSet &= ~OPTPROC_IMMEDIATE;
return res;
}
/**
* check for preset values from a config files or envrionment variables
*
* @param[in,out] opts the structure with the option names to check
*/
static tSuccess
do_presets(tOptions * opts)
{
tOptDesc * od = NULL;
if (! SUCCESSFUL(immediate_opts(opts)))
return FAILURE;
/*
* IF this option set has a --save-opts option, then it also
* has a --load-opts option. See if a command line option has disabled
* option presetting.
*/
if ( (opts->specOptIdx.save_opts != NO_EQUIVALENT)
&& (opts->specOptIdx.save_opts != 0)) {
od = opts->pOptDesc + opts->specOptIdx.save_opts + 1;
if (DISABLED_OPT(od))
return SUCCESS;
}
/*
* Until we return from this procedure, disable non-presettable opts
*/
opts->fOptSet |= OPTPROC_PRESETTING;
/*
* IF there are no config files,
* THEN do any environment presets and leave.
*/
if (opts->papzHomeList == NULL) {
env_presets(opts, ENV_ALL);
}
else {
env_presets(opts, ENV_IMM);
/*
* Check to see if environment variables have disabled presetting.
*/
if ((od != NULL) && ! DISABLED_OPT(od))
intern_file_load(opts);
/*
* ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment
* variable options. Only the loading of .rc files.
*/
env_presets(opts, ENV_NON_IMM);
}
opts->fOptSet &= ~OPTPROC_PRESETTING;
return SUCCESS;
}
/**
* AutoOpts initialization
*
* @param[in,out] opts the structure to initialize
* @param[in] a_ct program argument count
* @param[in] a_v program argument vector
*/
LOCAL bool
ao_initialize(tOptions * opts, int a_ct, char ** a_v)
{
if ((opts->fOptSet & OPTPROC_INITDONE) != 0)
return true;
opts->origArgCt = (unsigned int)a_ct;
opts->origArgVect = a_v;
opts->fOptSet |= OPTPROC_INITDONE;
if (HAS_pzPkgDataDir(opts))
program_pkgdatadir = opts->pzPkgDataDir;
if (! SUCCESSFUL(do_presets(opts)))
return false;
/*
* IF option name conversion was suppressed but it is not suppressed
* for the command line, then it's time to translate option names.
* Usage text will not get retranslated.
*/
if ( ((opts->fOptSet & OPTPROC_TRANSLATE) != 0)
&& (opts->pTransProc != NULL)
&& ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT_CFG)
) {
opts->fOptSet &= ~OPTPROC_NXLAT_OPT_CFG;
(*opts->pTransProc)();
}
if ((opts->fOptSet & OPTPROC_REORDER) != 0)
optionSort(opts);
opts->curOptIdx = 1;
opts->pzCurOpt = NULL;
return true;
}
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"
* indent-tabs-mode: nil
* End:
* end of autoopts/initialize.c */

View File

@@ -5,16 +5,16 @@
#include "autoopts/options.h"
#include "autoopts/usage-txt.h"
#include "genshell.h"
#include "xat-attribute.h"
#include "value-type.h"
#include "option-xat-attribute.h"
#include "option-value-type.h"
#include "ao-strs.h"
#include "ag-char-map.h"
#include "autoopts.h"
#include "proto.h"
#include "parse-duration.c"
#include "ao-strs.c"
#include "value-type.c"
#include "xat-attribute.c"
#include "option-value-type.c"
#include "option-xat-attribute.c"
#include "autoopts.c"
#include "alias.c"
#include "boolean.c"
@@ -43,3 +43,4 @@
#include "tokenize.c"
#include "usage.c"
#include "version.c"
#include "init.c"

View File

@@ -1,15 +1,18 @@
/**
* \file load.c
* Time-stamp: "2012-03-31 13:13:34 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
* rc/ini file.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -21,23 +24,23 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
static bool
add_prog_path(char * pzBuf, int bufSize, char const * pzName,
add_prog_path(char * pzBuf, int b_sz, char const * pzName,
char const * pzProgPath);
static bool
add_env_val(char * pzBuf, int bufSize, char const * pzName);
add_env_val(char * buf, int buf_sz, char const * name);
static char *
assemble_arg_val(char * pzTxt, tOptionLoadMode mode);
assemble_arg_val(char * txt, tOptionLoadMode mode);
/* = = = END-STATIC-FORWARD = = = */
/*=export_func optionMakePath
@@ -92,12 +95,12 @@ assemble_arg_val(char * pzTxt, tOptionLoadMode mode);
* errors (cannot resolve the resulting path).
=*/
bool
optionMakePath(char * pzBuf, int bufSize, char const * pzName,
optionMakePath(char * pzBuf, int b_sz, char const * pzName,
char const * pzProgPath)
{
size_t name_len = strlen(pzName);
if (((size_t)bufSize <= name_len) || (name_len == 0))
if (((size_t)b_sz <= name_len) || (name_len == 0))
return false;
/*
@@ -106,7 +109,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
if (*pzName != '$') {
char const* pzS = pzName;
char* pzD = pzBuf;
int ct = bufSize;
int ct = b_sz;
for (;;) {
if ( (*(pzD++) = *(pzS++)) == NUL)
@@ -126,7 +129,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
return false;
case '$':
if (! add_prog_path(pzBuf, bufSize, pzName, pzProgPath))
if (! add_prog_path(pzBuf, b_sz, pzName, pzProgPath))
return false;
break;
@@ -134,13 +137,13 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
if (program_pkgdatadir[0] == NUL)
return false;
if (snprintf(pzBuf, bufSize, "%s%s", program_pkgdatadir, pzName + 2)
>= bufSize)
if (snprintf(pzBuf, (size_t)b_sz, "%s%s",
program_pkgdatadir, pzName + 2) >= b_sz)
return false;
break;
default:
if (! add_env_val(pzBuf, bufSize, pzName))
if (! add_env_val(pzBuf, b_sz, pzName))
return false;
}
@@ -151,7 +154,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
return false;
name_len = strlen(pz);
if (name_len >= (size_t)bufSize) {
if (name_len >= (size_t)b_sz) {
free(pz);
return false;
}
@@ -168,7 +171,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
return false;
name_len = strlen(z);
if (name_len >= bufSize)
if (name_len >= b_sz)
return false;
memcpy(pzBuf, z, name_len + 1);
@@ -179,7 +182,7 @@ optionMakePath(char * pzBuf, int bufSize, char const * pzName,
}
static bool
add_prog_path(char * pzBuf, int bufSize, char const * pzName,
add_prog_path(char * pzBuf, int b_sz, char const * pzName,
char const * pzProgPath)
{
char const* pzPath;
@@ -224,7 +227,7 @@ add_prog_path(char * pzBuf, int bufSize, char const * pzName,
* Concatenate the file name to the end of the executable path.
* The result may be either a file or a directory.
*/
if ((pz - pzPath)+1 + strlen(pzName) >= (unsigned)bufSize)
if ((unsigned)(pz - pzPath) + 1 + strlen(pzName) >= (unsigned)b_sz)
return false;
memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1));
@@ -239,64 +242,70 @@ add_prog_path(char * pzBuf, int bufSize, char const * pzName,
return true;
}
static bool
add_env_val(char * pzBuf, int bufSize, char const * pzName)
add_env_val(char * buf, int buf_sz, char const * name)
{
char * pzDir = pzBuf;
char * dir_part = buf;
for (;;) {
int ch = (int)*++pzName;
int ch = (int)*++name;
if (! IS_VALUE_NAME_CHAR(ch))
break;
*(pzDir++) = (char)ch;
*(dir_part++) = (char)ch;
}
if (pzDir == pzBuf)
if (dir_part == buf)
return false;
*pzDir = NUL;
*dir_part = NUL;
pzDir = getenv(pzBuf);
dir_part = getenv(buf);
/*
* Environment value not found -- skip the home list entry
*/
if (pzDir == NULL)
if (dir_part == NULL)
return false;
if (strlen(pzDir) + 1 + strlen(pzName) >= (unsigned)bufSize)
if (strlen(dir_part) + 1 + strlen(name) >= (unsigned)buf_sz)
return false;
sprintf(pzBuf, "%s%s", pzDir, pzName);
sprintf(buf, "%s%s", dir_part, name);
return true;
}
/**
* Trim leading and trailing white space.
* If we are cooking the text and the text is quoted, then "cook"
* the string. To cook, the string must be quoted.
*
* @param[in,out] txt the input and output string
* @param[in] mode the handling mode (cooking method)
*/
LOCAL void
mungeString(char* pzTxt, tOptionLoadMode mode)
munge_str(char * txt, tOptionLoadMode mode)
{
char * pzE;
if (mode == OPTION_LOAD_KEEP)
return;
if (IS_WHITESPACE_CHAR(*pzTxt)) {
char * pzS = SPN_WHITESPACE_CHARS(pzTxt+1);
if (IS_WHITESPACE_CHAR(*txt)) {
char * pzS = SPN_WHITESPACE_CHARS(txt+1);
size_t l = strlen(pzS) + 1;
memmove(pzTxt, pzS, l);
pzE = pzTxt + l - 1;
memmove(txt, pzS, l);
pzE = txt + l - 1;
} else
pzE = pzTxt + strlen(pzTxt);
pzE = txt + strlen(txt);
pzE = SPN_WHITESPACE_BACK(pzTxt, pzE);
pzE = SPN_WHITESPACE_BACK(txt, pzE);
*pzE = NUL;
if (mode == OPTION_LOAD_UNCOOKED)
return;
switch (*pzTxt) {
switch (*txt) {
default: return;
case '"':
case '\'': break;
@@ -308,21 +317,20 @@ mungeString(char* pzTxt, tOptionLoadMode mode)
case '\'': break;
}
(void)ao_string_cook(pzTxt, NULL);
(void)ao_string_cook(txt, NULL);
}
static char *
assemble_arg_val(char * pzTxt, tOptionLoadMode mode)
assemble_arg_val(char * txt, tOptionLoadMode mode)
{
char* pzEnd = strpbrk(pzTxt, ARG_BREAK_STR);
char* pzEnd = strpbrk(txt, ARG_BREAK_STR);
int space_break;
/*
* Not having an argument to a configurable name is okay.
*/
if (pzEnd == NULL)
return pzTxt + strlen(pzTxt);
return txt + strlen(txt);
/*
* If we are keeping all whitespace, then the modevalue starts with the
@@ -349,34 +357,41 @@ assemble_arg_val(char * pzTxt, tOptionLoadMode mode)
return pzEnd;
}
/*
/**
* Load an option from a block of text. The text must start with the
* configurable/option name and be followed by its associated value.
* That value may be processed in any of several ways. See "tOptionLoadMode"
* in autoopts.h.
*
* @param[in,out] opts program options descriptor
* @param[in,out] opt_state option processing state
* @param[in,out] line source line with long option name in it
* @param[in] direction current processing direction (preset or not)
* @param[in] load_mode option loading mode (OPTION_LOAD_*)
*/
LOCAL void
loadOptionLine(
tOptions* pOpts,
tOptState* pOS,
char* pzLine,
tOptions * opts,
tOptState * opt_state,
char * line,
tDirection direction,
tOptionLoadMode load_mode )
{
pzLine = SPN_WHITESPACE_CHARS(pzLine);
line = SPN_LOAD_LINE_SKIP_CHARS(line);
{
char* pzArg = assemble_arg_val(pzLine, load_mode);
char * arg = assemble_arg_val(line, load_mode);
if (! SUCCESSFUL(opt_find_long(pOpts, pzLine, pOS)))
if (! SUCCESSFUL(opt_find_long(opts, line, opt_state)))
return;
if (pOS->flags & OPTST_NO_INIT)
if (opt_state->flags & OPTST_NO_INIT)
return;
pOS->pzOptArg = pzArg;
opt_state->pzOptArg = arg;
}
switch (pOS->flags & (OPTST_IMM|OPTST_DISABLE_IMM)) {
switch (opt_state->flags & (OPTST_IMM|OPTST_DISABLE_IMM)) {
case 0:
/*
* The selected option has no immediate action.
@@ -394,7 +409,7 @@ loadOptionLine(
* immediately for enablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((pOS->flags & OPTST_DISABLED) == 0)
if ((opt_state->flags & OPTST_DISABLED) == 0)
return;
} else {
/*
@@ -402,7 +417,7 @@ loadOptionLine(
* immediately for enablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((pOS->flags & OPTST_DISABLED) != 0)
if ((opt_state->flags & OPTST_DISABLED) != 0)
return;
}
break;
@@ -414,7 +429,7 @@ loadOptionLine(
* immediately for disablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((pOS->flags & OPTST_DISABLED) != 0)
if ((opt_state->flags & OPTST_DISABLED) != 0)
return;
} else {
/*
@@ -422,7 +437,7 @@ loadOptionLine(
* immediately for disablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((pOS->flags & OPTST_DISABLED) == 0)
if ((opt_state->flags & OPTST_DISABLED) == 0)
return;
}
break;
@@ -441,43 +456,42 @@ loadOptionLine(
/*
* Fix up the args.
*/
if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
if (*pOS->pzOptArg != NUL)
if (OPTST_GET_ARGTYPE(opt_state->pOD->fOptState) == OPARG_TYPE_NONE) {
if (*opt_state->pzOptArg != NUL)
return;
pOS->pzOptArg = NULL;
opt_state->pzOptArg = NULL;
} else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
if (*pOS->pzOptArg == NUL)
pOS->pzOptArg = NULL;
} else if (opt_state->pOD->fOptState & OPTST_ARG_OPTIONAL) {
if (*opt_state->pzOptArg == NUL)
opt_state->pzOptArg = NULL;
else {
AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument");
pOS->flags |= OPTST_ALLOC_ARG;
AGDUPSTR(opt_state->pzOptArg, opt_state->pzOptArg, "opt arg");
opt_state->flags |= OPTST_ALLOC_ARG;
}
} else {
if (*pOS->pzOptArg == NUL)
pOS->pzOptArg = zNil;
if (*opt_state->pzOptArg == NUL)
opt_state->pzOptArg = zNil;
else {
AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument");
pOS->flags |= OPTST_ALLOC_ARG;
AGDUPSTR(opt_state->pzOptArg, opt_state->pzOptArg, "opt arg");
opt_state->flags |= OPTST_ALLOC_ARG;
}
}
{
tOptionLoadMode sv = option_load_mode;
option_load_mode = load_mode;
handle_opt(pOpts, pOS);
handle_opt(opts, opt_state);
option_load_mode = sv;
}
}
/*=export_func optionLoadLine
*
* what: process a string for an option name and value
*
* arg: tOptions*, pOpts, program options descriptor
* arg: char const*, pzLine, NUL-terminated text
* arg: tOptions*, opts, program options descriptor
* arg: char const*, line, NUL-terminated text
*
* doc:
*
@@ -488,7 +502,8 @@ loadOptionLine(
* When passed a pointer to the option struct and a string, it will find
* the option named by the first token on the string and set the option
* argument to the remainder of the string. The caller must NUL terminate
* the string. Any embedded new lines will be included in the option
* the string. The caller need not skip over any introductory hyphens.
* Any embedded new lines will be included in the option
* argument. If the input looks like one or more quoted strings, then the
* input will be "cooked". The "cooking" is identical to the string
* formation used in AutoGen definition files (@pxref{basic expression}),
@@ -498,15 +513,16 @@ loadOptionLine(
* will cause a warning to print, but the function should return.
=*/
void
optionLoadLine(tOptions * pOpts, char const * pzLine)
optionLoadLine(tOptions * opts, char const * line)
{
tOptState st = OPTSTATE_INITIALIZER(SET);
char* pz;
AGDUPSTR(pz, pzLine, "user option line");
loadOptionLine(pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED);
AGDUPSTR(pz, line, "user option line");
loadOptionLine(opts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED);
AGFREE(pz);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,8 +1,8 @@
dnl -*- buffer-read-only: t -*- vi: set ro:
dnl
dnl
dnl DO NOT EDIT THIS FILE (libopts.m4)
dnl
dnl It has been AutoGen-ed May 6, 2012 at 04:20:55 PM by AutoGen 5.16pre36
dnl
dnl It has been AutoGen-ed March 31, 2013 at 10:41:19 AM by AutoGen 5.17.3
dnl From the definitions libopts.def
dnl and the template file conftest.tpl
dnl
@@ -11,7 +11,7 @@ dnl
AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
AC_REQUIRE([AC_HEADER_STDC])
AC_HEADER_DIRENT
# =================
# AC_CHECK_HEADERS
# =================
@@ -19,26 +19,26 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
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 dlfcn.h errno.h \
fcntl.h libgen.h memory.h netinet/in.h \
setjmp.h stdbool.h sysexits.h unistd.h \
utime.h])
fcntl.h libgen.h libintl.h memory.h \
netinet/in.h setjmp.h stdbool.h sysexits.h \
unistd.h utime.h])
AC_CHECK_HEADERS([stdarg.h varargs.h],
[lo_have_arg_hdr=true;break],
[lo_have_arg_hdr=false])
AC_CHECK_HEADERS([string.h strings.h],
[lo_have_str_hdr=true;break],
[lo_have_str_hdr=false])
AC_CHECK_HEADERS([limits.h sys/limits.h values.h],
[lo_have_lim_hdr=true;break],
[lo_have_lim_hdr=false])
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.
# On OS/X, "wchar.h" needs "runetype.h" to work properly.
@@ -49,31 +49,39 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
# include <runetype.h>
#endif
])
AC_ARG_ENABLE([nls],
AS_HELP_STRING([--disable-nls],[disable nls support in libopts]))
AS_IF([test "x$enable_nls" != "xno" && \
test "X${ac_cv_header_libintl_h}" = Xyes], [
AC_DEFINE([ENABLE_NLS],[1],[nls support in libopts])])
# --------------------------------------------
# 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_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])[
]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])[
[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])
]AC_MSG_ERROR([you must have inttypes.h or stdint.h on your system])[
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}
test "X${as_ac_var}" = Xyes || {
]AC_MSG_ERROR([you must have ${f}.h on your system])[
}
done
test "X${ac_cv_header_inttypes_h-no}" = Xyes || \
echo '#include <stdint.h>' > inttypes.h]
# ----------------------------------------------------------------------
# Checks for typedefs
# ----------------------------------------------------------------------
@@ -93,7 +101,7 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 8)
AC_CHECK_SIZEOF(short, 2)
# ----------------------------------------------------------------------
# AC_CHECK_LIB for SVR4 libgen, and use it if it defines pathfind.
# ----------------------------------------------------------------------
@@ -116,7 +124,7 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
if ! true ; then exit 1 ; fi
echo /bin/sh'`
test -x "$POSIX_SHELL" && break
]AC_ERROR([Cannot locate a working POSIX shell])[
]AC_MSG_ERROR([cannot locate a working POSIX shell])[
done]
AC_DEFINE_UNQUOTED([POSIX_SHELL], ["${POSIX_SHELL}"],
[define to a working POSIX compliant shell])
@@ -142,7 +150,7 @@ AC_DEFUN([LIBOPTS_WITH_REGEX_HEADER],[
else
AC_DEFINE([REGEX_HEADER],[<regex.h>],[name of regex header file])
fi
]) # end of AC_DEFUN of LIBOPTS_WITH_REGEX_HEADER
@@ -209,7 +217,7 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
LIBREGEX_LIBS=""
AC_MSG_CHECKING([whether libregex functions properly])
AC_CACHE_VAL([libopts_cv_with_libregex],[
AC_TRY_RUN([@%:@include <stdio.h>
AC_RUN_IFELSE([@%:@include <stdio.h>
@%:@include <stdlib.h>
@%:@include <sys/types.h>
@%:@include REGEX_HEADER
@@ -230,7 +238,7 @@ int main() {
}
return 0; }],
[libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no],
[libopts_cv_with_libregex=no]) # end of AC_TRY_RUN
[libopts_cv_with_libregex=no]) # end of AC_RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_with_libregex
AC_MSG_RESULT([${libopts_cv_with_libregex}])
if test "X${libopts_cv_with_libregex}" != Xno
@@ -240,22 +248,23 @@ int main() {
else
CPPFLAGS="${libopts_save_CPPFLAGS}"
LIBS="${libopts_save_LIBS}"
AC_MSG_ERROR([the regex library does not work])
fi
]) # end of AC_DEFUN of LIBOPTS_WITHLIB_REGEX
AC_DEFUN([LIBOPTS_RUN_PATHFIND],[
AC_MSG_CHECKING([whether pathfind(3) works])
AC_CACHE_VAL([libopts_cv_run_pathfind],[
AC_TRY_RUN([@%:@include <string.h>
AC_RUN_IFELSE([@%:@include <string.h>
@%:@include <stdlib.h>
int main (int argc, char** argv) {
char* pz = pathfind( getenv( "PATH" ), "sh", "x" );
return (pz == 0) ? 1 : 0;
}],
[libopts_cv_run_pathfind=yes],[libopts_cv_run_pathfind=no],[libopts_cv_run_pathfind=no]
) # end of TRY_RUN
) # end of RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_run_pathfind
AC_MSG_RESULT([${libopts_cv_run_pathfind}])
if test "X${libopts_cv_run_pathfind}" != Xno
@@ -263,7 +272,7 @@ int main (int argc, char** argv) {
AC_DEFINE([HAVE_PATHFIND],[1],
[Define this if pathfind(3) works])
fi
]) # end of AC_DEFUN of LIBOPTS_RUN_PATHFIND
@@ -284,14 +293,14 @@ echo ${dzero}`
AC_DEFINE([HAVE_DEV_ZERO],[1],
[Define this if /dev/zero is readable device])
fi
]) # end of AC_DEFUN of LIBOPTS_TEST_DEV_ZERO
AC_DEFUN([LIBOPTS_RUN_REALPATH],[
AC_MSG_CHECKING([whether we have a functional realpath(3C)])
AC_CACHE_VAL([libopts_cv_run_realpath],[
AC_TRY_RUN([@%:@include <limits.h>
AC_RUN_IFELSE([@%:@include <limits.h>
@%:@include <stdlib.h>
int main (int argc, char** argv) {
@%:@ifndef PATH_MAX
@@ -303,7 +312,7 @@ choke me!!
return (pz == zPath) ? 0 : 1;
}],
[libopts_cv_run_realpath=yes],[libopts_cv_run_realpath=no],[libopts_cv_run_realpath=no]
) # end of TRY_RUN
) # end of RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_run_realpath
AC_MSG_RESULT([${libopts_cv_run_realpath}])
if test "X${libopts_cv_run_realpath}" != Xno
@@ -311,14 +320,14 @@ choke me!!
AC_DEFINE([HAVE_REALPATH],[1],
[Define this if we have a functional realpath(3C)])
fi
]) # end of AC_DEFUN of LIBOPTS_RUN_REALPATH
AC_DEFUN([LIBOPTS_RUN_STRFTIME],[
AC_MSG_CHECKING([whether strftime() works])
AC_CACHE_VAL([libopts_cv_run_strftime],[
AC_TRY_RUN([@%:@include <time.h>
AC_RUN_IFELSE([@%:@include <time.h>
@%:@include <string.h>
char t_buf@<:@ 64 @:>@;
int main() {
@@ -336,7 +345,7 @@ int main() {
strftime( t_buf, sizeof( t_buf ), "%A %b %d %j", &tm );
return (strcmp( t_buf, z ) != 0); }],
[libopts_cv_run_strftime=yes],[libopts_cv_run_strftime=no],[libopts_cv_run_strftime=no]
) # end of TRY_RUN
) # end of RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_run_strftime
AC_MSG_RESULT([${libopts_cv_run_strftime}])
if test "X${libopts_cv_run_strftime}" != Xno
@@ -344,19 +353,19 @@ int main() {
AC_DEFINE([HAVE_STRFTIME],[1],
[Define this if strftime() works])
fi
]) # end of AC_DEFUN of LIBOPTS_RUN_STRFTIME
AC_DEFUN([LIBOPTS_RUN_FOPEN_BINARY],[
AC_MSG_CHECKING([whether fopen accepts "b" mode])
AC_CACHE_VAL([libopts_cv_run_fopen_binary],[
AC_TRY_RUN([@%:@include <stdio.h>
AC_RUN_IFELSE([@%:@include <stdio.h>
int main (int argc, char** argv) {
FILE* fp = fopen("conftest.@S|@ac_ext", "rb");
return (fp == NULL) ? 1 : fclose(fp); }],
[libopts_cv_run_fopen_binary=yes],[libopts_cv_run_fopen_binary=no],[libopts_cv_run_fopen_binary=no]
) # end of TRY_RUN
) # end of RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_binary
AC_MSG_RESULT([${libopts_cv_run_fopen_binary}])
if test "X${libopts_cv_run_fopen_binary}" != Xno
@@ -367,19 +376,19 @@ return (fp == NULL) ? 1 : fclose(fp); }],
AC_DEFINE([FOPEN_BINARY_FLAG],"",
[fopen(3) accepts a 'b' in the mode flag])
fi
]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_BINARY
AC_DEFUN([LIBOPTS_RUN_FOPEN_TEXT],[
AC_MSG_CHECKING([whether fopen accepts "t" mode])
AC_CACHE_VAL([libopts_cv_run_fopen_text],[
AC_TRY_RUN([@%:@include <stdio.h>
AC_RUN_IFELSE([@%:@include <stdio.h>
int main (int argc, char** argv) {
FILE* fp = fopen("conftest.@S|@ac_ext", "rt");
return (fp == NULL) ? 1 : fclose(fp); }],
[libopts_cv_run_fopen_text=yes],[libopts_cv_run_fopen_text=no],[libopts_cv_run_fopen_text=no]
) # end of TRY_RUN
) # end of RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_text
AC_MSG_RESULT([${libopts_cv_run_fopen_text}])
if test "X${libopts_cv_run_fopen_text}" != Xno
@@ -390,7 +399,7 @@ return (fp == NULL) ? 1 : fclose(fp); }],
AC_DEFINE([FOPEN_TEXT_FLAG],"",
[fopen(3) accepts a 't' in the mode flag])
fi
]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_TEXT
@@ -406,7 +415,7 @@ AC_DEFUN([LIBOPTS_DISABLE_OPTIONAL_ARGS],[
AC_DEFINE([NO_OPTIONAL_OPT_ARGS], [1],
[Define this if optional arguments are disallowed])
fi
]) # end of AC_DEFUN of LIBOPTS_DISABLE_OPTIONAL_ARGS
@@ -443,15 +452,13 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[
dnl @synopsis LIBOPTS_CHECK
dnl
dnl Time-stamp: "2012-02-25 12:54:32 bkorb"
dnl
dnl If autoopts-config works, add the linking information to LIBS.
dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all
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-2012 by Bruce Korb - all rights reserved
dnl AutoGen Copyright (C) 1992-2013 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

View File

@@ -1,12 +1,10 @@
# liboptschk.m4 serial 2 (autogen - 5.11.4)
dnl Copyright (c) 2005-2012 by Bruce Korb - all rights reserved
dnl Copyright (C) 2005-2013 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
dnl Time-stamp: "2010-12-07 12:57:56 bkorb"
dnl
AC_DEFUN([ag_FIND_LIBOPTS],
[if test "X${ac_cv_header_autoopts_options_h}" = Xno
then :

File diff suppressed because it is too large Load Diff

View File

@@ -2,13 +2,17 @@
/**
* \file nested.c
*
* Time-stamp: "2012-03-04 13:30:07 bkorb"
* Handle options with arguments that contain nested values.
*
* @addtogroup autoopts
* @{
*/
/*
* Automated Options Nested Values module.
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -20,11 +24,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
typedef struct {
@@ -47,35 +51,44 @@ static xml_xlate_t const xml_xlate[] = {
/* = = = START-STATIC-FORWARD = = = */
static void
remove_continuation(char* pzSrc);
remove_continuation(char * src);
static char const*
scan_q_str(char const* pzTxt);
static tOptionValue *
add_string(void ** pp, char const * pzName, size_t nameLen,
add_string(void ** pp, char const * name, size_t nm_len,
char const* pzValue, size_t dataLen);
static tOptionValue *
add_bool(void ** pp, char const * pzName, size_t nameLen,
char const* pzValue, size_t dataLen);
add_bool(void ** pp, char const * name, size_t nm_len,
char const * val, size_t d_len);
static tOptionValue*
add_number(void** pp, char const* pzName, size_t nameLen,
char const* pzValue, size_t dataLen);
add_number(void** pp, char const* pzName, size_t nm_len,
char const* val, size_t d_len);
static tOptionValue*
add_nested(void** pp, char const* pzName, size_t nameLen,
char* pzValue, size_t dataLen);
add_nested(void** pp, char const* pzName, size_t nm_len,
char* val, size_t d_len);
static char const *
scan_name(char const* pzName, tOptionValue* pRes);
static char const*
scan_xml(char const* pzName, tOptionValue* pRes);
static char const *
unnamed_xml(char const * txt);
static char const *
scan_xml_name(char const * name, size_t * nm_len, tOptionValue * val);
static char const *
find_end_xml(char const * src, size_t nm_len, char const * val, size_t * len);
static char const *
scan_xml(char const * xml_name, tOptionValue * res_val);
static void
sort_list(tArgList* pAL);
sort_list(tArgList * arg_list);
/* = = = END-STATIC-FORWARD = = = */
/**
@@ -83,13 +96,13 @@ sort_list(tArgList* pAL);
* characters, but trim out the backslash:
*/
static void
remove_continuation(char* pzSrc)
remove_continuation(char * src)
{
char* pzD;
do {
while (*pzSrc == NL) pzSrc++;
pzD = strchr(pzSrc, NL);
while (*src == NL) src++;
pzD = strchr(src, NL);
if (pzD == NULL)
return;
@@ -98,20 +111,20 @@ remove_continuation(char* pzSrc)
* points to a newline character. It now becomes the source and
* pzD goes to the previous character.
*/
pzSrc = pzD--;
src = pzD--;
if (*pzD != '\\')
pzD++;
} while (pzD == pzSrc);
} while (pzD == src);
/*
* Start shifting text.
*/
for (;;) {
char ch = ((*pzD++) = *(pzSrc++));
char ch = ((*pzD++) = *(src++));
switch (ch) {
case NUL: return;
case '\\':
if (*pzSrc == NL)
if (*src == NL)
--pzD; /* rewrite on next iteration */
}
}
@@ -158,11 +171,11 @@ scan_q_str(char const* pzTxt)
* Associate a name with either a string or no value.
*/
static tOptionValue *
add_string(void ** pp, char const * pzName, size_t nameLen,
add_string(void ** pp, char const * name, size_t nm_len,
char const* pzValue, size_t dataLen)
{
tOptionValue* pNV;
size_t sz = nameLen + dataLen + sizeof(*pNV);
size_t sz = nm_len + dataLen + sizeof(*pNV);
pNV = AGALOC(sz, "option name/str value pair");
if (pNV == NULL)
@@ -175,14 +188,14 @@ add_string(void ** pp, char const * pzName, size_t nameLen,
} else {
pNV->valType = OPARG_TYPE_STRING;
if (dataLen > 0) {
char const * pzSrc = pzValue;
char const * src = pzValue;
char * pzDst = pNV->v.strVal;
int ct = dataLen;
int ct = (int)dataLen;
do {
int ch = *(pzSrc++) & 0xFF;
int ch = *(src++) & 0xFF;
if (ch == NUL) goto data_copy_done;
if (ch == '&')
ch = get_special_char(&pzSrc, &ct);
ch = get_special_char(&src, &ct);
*(pzDst++) = (char)ch;
} while (--ct > 0);
data_copy_done:
@@ -195,8 +208,8 @@ add_string(void ** pp, char const * pzName, size_t nameLen,
pNV->pzName = pNV->v.strVal + dataLen + 1;
}
memcpy(pNV->pzName, pzName, nameLen);
pNV->pzName[ nameLen ] = NUL;
memcpy(pNV->pzName, name, nm_len);
pNV->pzName[ nm_len ] = NUL;
addArgListEntry(pp, pNV);
return pNV;
}
@@ -205,95 +218,95 @@ add_string(void ** pp, char const * pzName, size_t nameLen,
* Associate a name with either a string or no value.
*/
static tOptionValue *
add_bool(void ** pp, char const * pzName, size_t nameLen,
char const* pzValue, size_t dataLen)
add_bool(void ** pp, char const * name, size_t nm_len,
char const * val, size_t d_len)
{
tOptionValue * pNV;
tOptionValue * new_val;
{
size_t sz = nameLen + sizeof(tOptionValue) + 1;
pNV = AGALOC(sz, "name/bool value");
size_t sz = nm_len + sizeof(tOptionValue) + 1;
new_val = AGALOC(sz, "name/bool value");
}
{
char * p = SPN_WHITESPACE_CHARS(pzValue);
dataLen -= p - pzValue;
pzValue = p;
char * p = SPN_WHITESPACE_CHARS(val);
d_len -= (unsigned long)(p - val);
val = p;
}
if (dataLen == 0)
pNV->v.boolVal = 0;
if (d_len == 0)
new_val->v.boolVal = 0;
else if (IS_DEC_DIGIT_CHAR(*pzValue))
pNV->v.boolVal = atoi(pzValue);
else if (IS_DEC_DIGIT_CHAR(*val))
new_val->v.boolVal = (unsigned)atoi(val);
else pNV->v.boolVal = ! IS_FALSE_TYPE_CHAR(*pzValue);
else new_val->v.boolVal = ! IS_FALSE_TYPE_CHAR(*val);
pNV->valType = OPARG_TYPE_BOOLEAN;
pNV->pzName = (char*)(pNV + 1);
memcpy(pNV->pzName, pzName, nameLen);
pNV->pzName[ nameLen ] = NUL;
addArgListEntry(pp, pNV);
return pNV;
new_val->valType = OPARG_TYPE_BOOLEAN;
new_val->pzName = (char*)(new_val + 1);
memcpy(new_val->pzName, name, nm_len);
new_val->pzName[ nm_len ] = NUL;
addArgListEntry(pp, new_val);
return new_val;
}
/**
* Associate a name with either a string or no value.
*/
static tOptionValue*
add_number(void** pp, char const* pzName, size_t nameLen,
char const* pzValue, size_t dataLen)
add_number(void** pp, char const* pzName, size_t nm_len,
char const* val, size_t d_len)
{
tOptionValue* pNV;
size_t sz = nameLen + sizeof(*pNV) + 1;
tOptionValue* new_val;
size_t sz = nm_len + sizeof(*new_val) + 1;
pNV = AGALOC(sz, "option name/bool value pair");
if (pNV == NULL)
new_val = AGALOC(sz, "bool val");
if (new_val == NULL)
return NULL;
while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) {
dataLen--; pzValue++;
while (IS_WHITESPACE_CHAR(*val) && (d_len > 0)) {
d_len--; val++;
}
if (dataLen == 0)
pNV->v.longVal = 0;
if (d_len == 0)
new_val->v.longVal = 0;
else
pNV->v.longVal = strtol(pzValue, 0, 0);
new_val->v.longVal = strtol(val, 0, 0);
pNV->valType = OPARG_TYPE_NUMERIC;
pNV->pzName = (char*)(pNV + 1);
memcpy(pNV->pzName, pzName, nameLen);
pNV->pzName[ nameLen ] = NUL;
addArgListEntry(pp, pNV);
return pNV;
new_val->valType = OPARG_TYPE_NUMERIC;
new_val->pzName = (char*)(new_val + 1);
memcpy(new_val->pzName, pzName, nm_len);
new_val->pzName[ nm_len ] = NUL;
addArgListEntry(pp, new_val);
return new_val;
}
/**
* Associate a name with either a string or no value.
*/
static tOptionValue*
add_nested(void** pp, char const* pzName, size_t nameLen,
char* pzValue, size_t dataLen)
add_nested(void** pp, char const* pzName, size_t nm_len,
char* val, size_t d_len)
{
tOptionValue* pNV;
tOptionValue* new_val;
if (dataLen == 0) {
size_t sz = nameLen + sizeof(*pNV) + 1;
pNV = AGALOC(sz, "empty nested value pair");
if (pNV == NULL)
if (d_len == 0) {
size_t sz = nm_len + sizeof(*new_val) + 1;
new_val = AGALOC(sz, "empty nest");
if (new_val == NULL)
return NULL;
pNV->v.nestVal = NULL;
pNV->valType = OPARG_TYPE_HIERARCHY;
pNV->pzName = (char*)(pNV + 1);
memcpy(pNV->pzName, pzName, nameLen);
pNV->pzName[ nameLen ] = NUL;
new_val->v.nestVal = NULL;
new_val->valType = OPARG_TYPE_HIERARCHY;
new_val->pzName = (char*)(new_val + 1);
memcpy(new_val->pzName, pzName, nm_len);
new_val->pzName[ nm_len ] = NUL;
} else {
pNV = optionLoadNested(pzValue, pzName, nameLen);
new_val = optionLoadNested(val, pzName, nm_len);
}
if (pNV != NULL)
addArgListEntry(pp, pNV);
if (new_val != NULL)
addArgListEntry(pp, new_val);
return pNV;
return new_val;
}
/**
@@ -303,11 +316,11 @@ add_nested(void** pp, char const* pzName, size_t nameLen,
static char const *
scan_name(char const* pzName, tOptionValue* pRes)
{
tOptionValue* pNV;
tOptionValue* new_val;
char const * pzScan = pzName+1; /* we know first char is a name char */
char const * pzVal;
size_t nameLen = 1;
size_t dataLen = 0;
size_t nm_len = 1;
size_t d_len = 0;
/*
* Scan over characters that name a value. These names may not end
@@ -316,7 +329,7 @@ scan_name(char const* pzName, tOptionValue* pRes)
pzScan = SPN_VALUE_NAME_CHARS(pzName + 1);
if (pzScan[-1] == ':')
pzScan--;
nameLen = pzScan - pzName;
nm_len = (size_t)(pzScan - pzName);
pzScan = SPN_HORIZ_WHITE_CHARS(pzScan);
@@ -336,18 +349,18 @@ scan_name(char const* pzName, tOptionValue* pRes)
/* FALLTHROUGH */
case NUL:
add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
add_string(&(pRes->v.nestVal), pzName, nm_len, NULL, (size_t)0);
break;
case '"':
case '\'':
pzVal = pzScan;
pzScan = scan_q_str(pzScan);
dataLen = pzScan - pzVal;
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);
d_len = (size_t)(pzScan - pzVal);
new_val = add_string(&(pRes->v.nestVal), pzName, nm_len, pzVal,
d_len);
if ((new_val != NULL) && (option_load_mode == OPTION_LOAD_COOKED))
ao_string_cook(new_val->v.strVal, NULL);
break;
default:
@@ -362,7 +375,7 @@ scan_name(char const* pzName, tOptionValue* pRes)
switch (ch) {
case NUL:
pzScan--;
dataLen = pzScan - pzVal;
d_len = (size_t)(pzScan - pzVal);
goto string_done;
/* FALLTHROUGH */
@@ -374,12 +387,12 @@ scan_name(char const* pzName, tOptionValue* pRes)
/* FALLTHROUGH */
case ',':
dataLen = (pzScan - pzVal) - 1;
d_len = (size_t)(pzScan - pzVal) - 1;
string_done:
pNV = add_string(&(pRes->v.nestVal), pzName, nameLen,
pzVal, dataLen);
if (pNV != NULL)
remove_continuation(pNV->v.strVal);
new_val = add_string(&(pRes->v.nestVal), pzName, nm_len,
pzVal, d_len);
if (new_val != NULL)
remove_continuation(new_val->v.strVal);
goto leave_scan_name;
}
}
@@ -389,140 +402,194 @@ scan_name(char const* pzName, tOptionValue* pRes)
return pzScan;
}
/**
* Some xml element that does not start with a name.
* The next character must be either '!' (introducing a comment),
* or '?' (introducing an XML meta-marker of some sort).
* We ignore these and indicate an error (NULL result) otherwise.
*
* @param[in] txt the text within an xml bracket
* @returns the address of the character after the closing marker, or NULL.
*/
static char const *
unnamed_xml(char const * txt)
{
switch (*txt) {
default:
txt = NULL;
break;
case '!':
txt = strstr(txt, "-->");
if (txt != NULL)
txt += 3;
break;
case '?':
txt = strchr(txt, '>');
if (txt != NULL)
txt++;
break;
}
return txt;
}
/**
* Scan off the xml element name, and the rest of the header, too.
* Set the value type to NONE if it ends with "/>".
*
* @param[in] name the first name character (alphabetic)
* @param[out] nm_len the length of the name
* @param[out] val set valType field to STRING or NONE.
*
* @returns the scan resumption point, or NULL on error
*/
static char const *
scan_xml_name(char const * name, size_t * nm_len, tOptionValue * val)
{
char const * scan = SPN_VALUE_NAME_CHARS(name + 1);
*nm_len = (size_t)(scan - name);
if (*nm_len > 64)
return NULL;
val->valType = OPARG_TYPE_STRING;
if (IS_WHITESPACE_CHAR(*scan)) {
/*
* There are attributes following the name. Parse 'em.
*/
scan = SPN_WHITESPACE_CHARS(scan);
scan = parse_attrs(NULL, scan, &option_load_mode, val);
if (scan == NULL)
return NULL; /* oops */
}
if (! IS_END_XML_TOKEN_CHAR(*scan))
return NULL; /* oops */
if (*scan == '/') {
/*
* Single element XML entries get inserted as an empty string.
*/
if (*++scan != '>')
return NULL;
val->valType = OPARG_TYPE_NONE;
}
return scan+1;
}
/**
* We've found a closing '>' without a preceding '/', thus we must search
* the text for '<name/>' where "name" is the name of the XML element.
*
* @param[in] name the start of the name in the element header
* @param[in] nm_len the length of that name
* @param[out] len the length of the value (string between header and
* the trailer/tail.
* @returns the character after the trailer, or NULL if not found.
*/
static char const *
find_end_xml(char const * src, size_t nm_len, char const * val, size_t * len)
{
char z[72] = "</";
char * dst = z + 2;
do {
*(dst++) = *(src++);
} while (--nm_len > 0); /* nm_len is known to be 64 or less */
*(dst++) = '>';
*dst = NUL;
{
char const * res = strstr(val, z);
if (res != NULL) {
char const * end = (option_load_mode != OPTION_LOAD_KEEP)
? SPN_WHITESPACE_BACK(val, res)
: res;
*len = (size_t)(end - val); /* includes trailing white space */
res = SPN_WHITESPACE_CHARS(res + (dst - z));
}
return res;
}
}
/**
* 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.
*
* @param[in] xml_name the name of an xml bracket (usually)
* @param[in,out] res_val the option data derived from the XML element
*
* @returns the place to resume scanning input
*/
static char const*
scan_xml(char const* pzName, tOptionValue* pRes)
static char const *
scan_xml(char const * xml_name, tOptionValue * res_val)
{
size_t nameLen;
size_t valLen;
char const* pzScan = ++pzName;
char const* pzVal;
tOptionValue valu;
tOptionValue* pNewVal;
size_t nm_len, v_len;
char const * scan;
char const * val_str;
tOptionValue valu;
tOptionLoadMode save_mode = option_load_mode;
if (! IS_VAR_FIRST_CHAR(*pzName)) {
switch (*pzName) {
default:
pzName = NULL;
break;
if (! IS_VAR_FIRST_CHAR(*++xml_name))
return unnamed_xml(xml_name);
case '!':
pzName = strstr(pzName, "-->");
if (pzName != NULL)
pzName += 3;
break;
/*
* "scan_xml_name()" may change "option_load_mode".
*/
val_str = scan_xml_name(xml_name, &nm_len, &valu);
if (val_str == NULL)
goto bail_scan_xml;
case '?':
pzName = strchr(pzName, '>');
if (pzName != NULL)
pzName++;
break;
}
return pzName;
if (valu.valType == OPARG_TYPE_NONE)
scan = val_str;
else {
if (option_load_mode != OPTION_LOAD_KEEP)
val_str = SPN_WHITESPACE_CHARS(val_str);
scan = find_end_xml(xml_name, nm_len, val_str, &v_len);
if (scan == NULL)
goto bail_scan_xml;
}
pzScan = SPN_VALUE_NAME_CHARS(pzName+1);
nameLen = pzScan - pzName;
if (nameLen > 64)
return NULL;
valu.valType = OPARG_TYPE_STRING;
switch (*pzScan) {
case ' ':
case '\t':
pzScan = parse_attrs(
NULL, (char*)pzScan, &option_load_mode, &valu );
if (*pzScan == '>') {
pzScan++;
break;
}
if (*pzScan != '/') {
option_load_mode = save_mode;
return NULL;
}
/* FALLTHROUGH */
case '/':
if (*++pzScan != '>') {
option_load_mode = save_mode;
return NULL;
}
add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
option_load_mode = save_mode;
return pzScan+1;
default:
option_load_mode = save_mode;
return NULL;
case '>':
pzScan++;
break;
}
pzVal = pzScan;
{
char z[68];
char* pzD = z;
int ct = nameLen;
char const* pzS = pzName;
*(pzD++) = '<';
*(pzD++) = '/';
do {
*(pzD++) = *(pzS++);
} while (--ct > 0);
*(pzD++) = '>';
*pzD = NUL;
pzScan = strstr(pzScan, z);
if (pzScan == NULL) {
option_load_mode = save_mode;
return NULL;
}
valLen = (pzScan - pzVal);
pzScan += nameLen + 3;
pzScan = SPN_WHITESPACE_CHARS(pzScan);
}
/*
* "scan" now points to where the scan is to resume after returning.
* It either points after "/>" at the end of the XML element header,
* or it points after the "</name>" tail based on the name in the header.
*/
switch (valu.valType) {
case OPARG_TYPE_NONE:
add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
add_string(&(res_val->v.nestVal), xml_name, nm_len, NULL, 0);
break;
case OPARG_TYPE_STRING:
pNewVal = add_string(
&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen);
{
tOptionValue * new_val = add_string(
&(res_val->v.nestVal), xml_name, nm_len, val_str, v_len);
if (option_load_mode != OPTION_LOAD_KEEP)
munge_str(new_val->v.strVal, option_load_mode);
if (option_load_mode == OPTION_LOAD_KEEP)
break;
mungeString(pNewVal->v.strVal, option_load_mode);
break;
}
case OPARG_TYPE_BOOLEAN:
add_bool(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen);
add_bool(&(res_val->v.nestVal), xml_name, nm_len, val_str, v_len);
break;
case OPARG_TYPE_NUMERIC:
add_number(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen);
add_number(&(res_val->v.nestVal), xml_name, nm_len, val_str, v_len);
break;
case OPARG_TYPE_HIERARCHY:
{
char* pz = AGALOC(valLen+1, "hierarchical scan");
char * pz = AGALOC(v_len+1, "h scan");
if (pz == NULL)
break;
memcpy(pz, pzVal, valLen);
pz[valLen] = NUL;
add_nested(&(pRes->v.nestVal), pzName, nameLen, pz, valLen);
memcpy(pz, val_str, v_len);
pz[v_len] = NUL;
add_nested(&(res_val->v.nestVal), xml_name, nm_len, pz, v_len);
AGFREE(pz);
break;
}
@@ -534,7 +601,11 @@ scan_xml(char const* pzName, tOptionValue* pRes)
}
option_load_mode = save_mode;
return pzScan;
return scan;
bail_scan_xml:
option_load_mode = save_mode;
return NULL;
}
@@ -545,19 +616,19 @@ scan_xml(char const* pzName, tOptionValue* pRes)
* knowing what they are doing.
*/
LOCAL void
unload_arg_list(tArgList* pAL)
unload_arg_list(tArgList * arg_list)
{
int ct = pAL->useCt;
tCC** ppNV = pAL->apzArgs;
int ct = arg_list->useCt;
char const ** pnew_val = arg_list->apzArgs;
while (ct-- > 0) {
tOptionValue* pNV = (tOptionValue*)(void*)*(ppNV++);
if (pNV->valType == OPARG_TYPE_HIERARCHY)
unload_arg_list(pNV->v.nestVal);
AGFREE(pNV);
tOptionValue* new_val = (tOptionValue*)(void*)*(pnew_val++);
if (new_val->valType == OPARG_TYPE_HIERARCHY)
unload_arg_list(new_val->v.nestVal);
AGFREE(new_val);
}
AGFREE((void*)pAL);
AGFREE((void*)arg_list);
}
/*=export_func optionUnloadNested
@@ -571,17 +642,17 @@ unload_arg_list(tArgList* pAL)
* @pxref{libopts-configFileLoad}).
=*/
void
optionUnloadNested(tOptionValue const * pOV)
optionUnloadNested(tOptionValue const * opt_val)
{
if (pOV == NULL) return;
if (pOV->valType != OPARG_TYPE_HIERARCHY) {
if (opt_val == NULL) return;
if (opt_val->valType != OPARG_TYPE_HIERARCHY) {
errno = EINVAL;
return;
}
unload_arg_list(pOV->v.nestVal);
unload_arg_list(opt_val->v.nestVal);
AGFREE((void*)pOV);
AGFREE((void*)opt_val);
}
/**
@@ -590,27 +661,27 @@ optionUnloadNested(tOptionValue const * pOV)
* Typically, we also hope the input is sorted.
*/
static void
sort_list(tArgList* pAL)
sort_list(tArgList * arg_list)
{
int ix;
int lm = pAL->useCt;
int lm = arg_list->useCt;
/*
* This loop iterates "useCt" - 1 times.
*/
for (ix = 0; ++ix < lm;) {
int iy = ix-1;
tOptionValue* pNewNV = (tOptionValue*)(void*)(pAL->apzArgs[ix]);
tOptionValue* pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[iy]);
tOptionValue * new_v = C(tOptionValue *, arg_list->apzArgs[ix]);
tOptionValue * old_v = C(tOptionValue *, arg_list->apzArgs[iy]);
/*
* For as long as the new entry precedes the "old" entry,
* move the old pointer. Stop before trying to extract the
* "-1" entry.
*/
while (strcmp(pOldNV->pzName, pNewNV->pzName) > 0) {
pAL->apzArgs[iy+1] = (void*)pOldNV;
pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[--iy]);
while (strcmp(old_v->pzName, new_v->pzName) > 0) {
arg_list->apzArgs[iy+1] = (void*)old_v;
old_v = (tOptionValue*)(void*)(arg_list->apzArgs[--iy]);
if (iy < 0)
break;
}
@@ -619,7 +690,7 @@ sort_list(tArgList* pAL)
* Always store the pointer. Sometimes it is redundant,
* but the redundancy is cheaper than a test and branch sequence.
*/
pAL->apzArgs[iy+1] = (void*)pNewNV;
arg_list->apzArgs[iy+1] = (void*)new_v;
}
}
@@ -627,9 +698,9 @@ sort_list(tArgList* pAL)
* private:
*
* what: parse a hierarchical option argument
* arg: + char const* + pzTxt + the text to scan +
* arg: + char const* + pzName + the name for the text +
* arg: + size_t + nameLen + the length of "name" +
* arg: + char const * + pzTxt + the text to scan +
* arg: + char const * + pzName + the name for the text +
* arg: + size_t + nm_len + the length of "name" +
*
* ret_type: tOptionValue*
* ret_desc: An allocated, compound value structure
@@ -649,65 +720,57 @@ sort_list(tArgList* pAL)
* @code{ENOMSG} no configuration values were found
* @end itemize
=*/
LOCAL tOptionValue*
optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen)
LOCAL tOptionValue *
optionLoadNested(char const * text, char const * name, size_t nm_len)
{
tOptionValue* pRes;
tOptionValue* res_val;
/*
* Make sure we have some data and we have space to put what we find.
*/
if (pzTxt == NULL) {
if (text == NULL) {
errno = EINVAL;
return NULL;
}
pzTxt = SPN_WHITESPACE_CHARS(pzTxt);
if (*pzTxt == NUL) {
text = SPN_WHITESPACE_CHARS(text);
if (*text == NUL) {
errno = ENOMSG;
return NULL;
}
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;
res_val = AGALOC(sizeof(*res_val) + nm_len + 1, "nest args");
res_val->valType = OPARG_TYPE_HIERARCHY;
res_val->pzName = (char*)(res_val + 1);
memcpy(res_val->pzName, name, nm_len);
res_val->pzName[nm_len] = NUL;
{
tArgList * pAL = AGALOC(sizeof(*pAL), "nested arg list");
if (pAL == NULL) {
AGFREE(pRes);
return NULL;
}
tArgList * arg_list = AGALOC(sizeof(*arg_list), "nest arg l");
pRes->v.nestVal = pAL;
pAL->useCt = 0;
pAL->allocCt = MIN_ARG_ALLOC_CT;
res_val->v.nestVal = arg_list;
arg_list->useCt = 0;
arg_list->allocCt = MIN_ARG_ALLOC_CT;
}
/*
* Scan until we hit a NUL.
*/
do {
pzTxt = SPN_WHITESPACE_CHARS(pzTxt);
if (IS_VAR_FIRST_CHAR(*pzTxt))
pzTxt = scan_name(pzTxt, pRes);
text = SPN_WHITESPACE_CHARS(text);
if (IS_VAR_FIRST_CHAR(*text))
text = scan_name(text, res_val);
else switch (*pzTxt) {
else switch (*text) {
case NUL: goto scan_done;
case '<': pzTxt = scan_xml(pzTxt, pRes);
if (pzTxt == NULL) goto woops;
if (*pzTxt == ',') pzTxt++; break;
case '#': pzTxt = strchr(pzTxt, NL); break;
case '<': text = scan_xml(text, res_val);
if (text == NULL) goto woops;
if (*text == ',') text++; break;
case '#': text = strchr(text, NL); break;
default: goto woops;
}
} while (pzTxt != NULL); scan_done:;
} while (text != NULL); scan_done:;
{
tArgList * al = pRes->v.nestVal;
tArgList * al = res_val->v.nestVal;
if (al->useCt == 0) {
errno = ENOMSG;
goto woops;
@@ -716,11 +779,11 @@ optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen)
sort_list(al);
}
return pRes;
return res_val;
woops:
AGFREE(pRes->v.nestVal);
AGFREE(pRes);
AGFREE(res_val->v.nestVal);
AGFREE(res_val);
return NULL;
}
@@ -728,45 +791,45 @@ optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen)
* private:
*
* what: parse a hierarchical option argument
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + tOptions* + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg +
*
* doc:
* Nested value was found on the command line
=*/
void
optionNestedVal(tOptions* pOpts, tOptDesc* pOD)
optionNestedVal(tOptions * opts, tOptDesc * od)
{
if (pOpts < OPTPROC_EMIT_LIMIT)
if (opts < OPTPROC_EMIT_LIMIT)
return;
if (pOD->fOptState & OPTST_RESET) {
tArgList* pAL = pOD->optCookie;
int ct;
tCC ** av;
if (od->fOptState & OPTST_RESET) {
tArgList * arg_list = od->optCookie;
int ct;
char const ** av;
if (pAL == NULL)
if (arg_list == NULL)
return;
ct = pAL->useCt;
av = pAL->apzArgs;
ct = arg_list->useCt;
av = arg_list->apzArgs;
while (--ct >= 0) {
void * p = (void *)*(av++);
optionUnloadNested((tOptionValue const *)p);
}
AGFREE(pOD->optCookie);
AGFREE(od->optCookie);
} else {
tOptionValue* pOV = optionLoadNested(
pOD->optArg.argString, pOD->pz_Name, strlen(pOD->pz_Name));
tOptionValue * opt_val = optionLoadNested(
od->optArg.argString, od->pz_Name, strlen(od->pz_Name));
if (pOV != NULL)
addArgListEntry(&(pOD->optCookie), (void*)pOV);
if (opt_val != NULL)
addArgListEntry(&(od->optCookie), (void*)opt_val);
}
}
/*
/**
* get_special_char
*/
LOCAL int
@@ -789,7 +852,7 @@ get_special_char(char const ** ppz, int * ct)
retch = (int)strtoul(pz, (char **)&pz, base);
if (*pz != ';')
return '&';
base = ++pz - *ppz;
base = (int)(++pz - *ppz);
if (base > *ct)
return '&';
@@ -804,7 +867,7 @@ get_special_char(char const ** ppz, int * ct)
for (;;) {
if ( (*ct >= xlatp->xml_len)
&& (strncmp(pz, xlatp->xml_txt, xlatp->xml_len) == 0)) {
&& (strncmp(pz, xlatp->xml_txt, (size_t)xlatp->xml_len) == 0)) {
*ppz += xlatp->xml_len;
*ct -= xlatp->xml_len;
return xlatp->xml_ch;
@@ -818,7 +881,7 @@ get_special_char(char const ** ppz, int * ct)
return '&';
}
/*
/**
* emit_special_char
*/
LOCAL void
@@ -840,7 +903,8 @@ emit_special_char(FILE * fp, int ch)
fprintf(fp, XML_HEX_BYTE_FMT, (ch & 0xFF));
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,11 +2,15 @@
/**
* \file numeric.c
*
* Time-stamp: "2012-02-25 12:54:32 bkorb"
* Handle options with numeric (integer) arguments.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -18,17 +22,17 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*=export_func optionShowRange
* private:
*
* what:
* what: Show info about range constraints
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + void * + rng_table + the value range tables +
@@ -42,7 +46,7 @@ optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct)
{
const struct {long const rmin, rmax;} * rng = rng_table;
char const * pz_indent = BULLET_STR;
char const * pz_indent = zTabHyp + tab_skip_ct;
/*
* The range is shown only for full usage requests and an error
@@ -62,7 +66,9 @@ optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct)
fprintf(option_usage_fp, zRangeScaled, pz_indent);
fprintf(option_usage_fp, (rng_ct > 1) ? zRangeLie : zRangeOnly, pz_indent);
pz_indent = (pOpts != OPTPROC_EMIT_USAGE) ? ONE_TAB_STR : DEEP_INDENT_STR;
pz_indent = (pOpts != OPTPROC_EMIT_USAGE)
? ONE_TAB_STR
: (zTabSpace + tab_skip_ct);
for (;;) {
if (rng->rmax == LONG_MIN)
@@ -91,14 +97,14 @@ optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct)
* private:
*
* what: process an option with a numeric value.
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + tOptions* + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg +
*
* doc:
* Decipher a numeric value.
=*/
void
optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
optionNumericVal(tOptions * opts, tOptDesc * od)
{
char* pz;
long val;
@@ -106,20 +112,20 @@ optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
/*
* Numeric options may have a range associated with it.
* If it does, the usage procedure requests that it be
* emitted by passing a NULL pOD pointer. Also bail out
* emitted by passing a NULL od pointer. Also bail out
* if there is no option argument or if we are being reset.
*/
if ( (pOD == NULL)
|| (pOD->optArg.argString == NULL)
|| ((pOD->fOptState & OPTST_RESET) != 0))
if ( (od == NULL)
|| (od->optArg.argString == NULL)
|| ((od->fOptState & OPTST_RESET) != 0))
return;
errno = 0;
val = strtol(pOD->optArg.argString, &pz, 0);
if ((pz == pOD->optArg.argString) || (errno != 0))
val = strtol(od->optArg.argString, &pz, 0);
if ((pz == od->optArg.argString) || (errno != 0))
goto bad_number;
if ((pOD->fOptState & OPTST_SCALED_NUM) != 0)
if ((od->fOptState & OPTST_SCALED_NUM) != 0)
switch (*(pz++)) {
case NUL: pz--; break;
case 't': val *= 1000;
@@ -138,25 +144,26 @@ optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
if (*pz != NUL)
goto bad_number;
if (pOD->fOptState & OPTST_ALLOC_ARG) {
AGFREE(pOD->optArg.argString);
pOD->fOptState &= ~OPTST_ALLOC_ARG;
if (od->fOptState & OPTST_ALLOC_ARG) {
AGFREE(od->optArg.argString);
od->fOptState &= ~OPTST_ALLOC_ARG;
}
pOD->optArg.argInt = val;
od->optArg.argInt = val;
return;
bad_number:
fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
fprintf( stderr, zNotNumber, opts->pzProgName, od->optArg.argString );
if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
(*(opts->pUsageProc))(opts, EXIT_FAILURE);
errno = EINVAL;
pOD->optArg.argInt = ~0;
od->optArg.argInt = ~0;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

156
libopts/option-value-type.c Normal file
View File

@@ -0,0 +1,156 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (stdin.c)
*
* It has been AutoGen-ed March 31, 2013 at 10:41:26 AM by AutoGen 5.17.3
* From the definitions stdin
* and the template file str2enum
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "option-value-type.h"
/* ANSI-C code produced by gperf version 3.0.4 */
/* Command-line: gperf option-value-type.gp */
/* Computed positions: -k'1' */
# if 0 /* gperf build options: */
// %struct-type
// %language=ANSI-C
// %includes
// %global-table
// %omit-struct-type
// %readonly-tables
// %compare-strncmp
//
// %define slot-name vtp_name
// %define hash-function-name option_value_type_hash
// %define lookup-function-name find_option_value_type_name
// %define word-array-name option_value_type_table
// %define initializer-suffix ,VTP_COUNT_CMD
//
# endif
#include "option-value-type.h"
typedef struct {
char const * vtp_name;
option_value_type_enum_t vtp_id;
} option_value_type_map_t;
#include <string.h>
/* maximum key range = 15, duplicates = 0 */
static unsigned int
option_value_type_hash (register const char *str, register unsigned int len)
{
static const unsigned char asso_values[] =
{
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 0, 18,
18, 18, 18, 18, 0, 10, 18, 5, 18, 18,
5, 18, 18, 18, 18, 0, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18
};
return len + asso_values[(unsigned char)str[0]];
}
static const option_value_type_map_t option_value_type_table[] =
{
{"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
{"",VTP_COUNT_CMD},
{"set", VTP_CMD_SET},
{"bool", VTP_CMD_BOOL},
{"",VTP_COUNT_CMD},
{"string", VTP_CMD_STRING},
{"boolean", VTP_CMD_BOOLEAN},
{"",VTP_COUNT_CMD},
{"hierarchy", VTP_CMD_HIERARCHY},
{"",VTP_COUNT_CMD},
{"nested", VTP_CMD_NESTED},
{"keyword", VTP_CMD_KEYWORD},
{"",VTP_COUNT_CMD},
{"set-membership", VTP_CMD_SET_MEMBERSHIP},
{"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
{"integer", VTP_CMD_INTEGER}
};
static inline const option_value_type_map_t *
find_option_value_type_name (register const char *str, register unsigned int len)
{
if (len <= 14 && len >= 3)
{
register int key = (int)option_value_type_hash (str, len);
if (key <= 17 && key >= 0)
{
register const char *s = option_value_type_table[key].vtp_name;
if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
return &option_value_type_table[key];
}
}
return 0;
}
/**
* Convert a command (keyword) to a option_value_type_enum_t enumeration value.
*
* @param[in] str a string that should start with a known key word.
* @param[in] len the provided length of the keyword at \a str.
* @returns the enumeration value.
* If not found, that value is VTP_INVALID_CMD.
*/
option_value_type_enum_t
find_option_value_type_cmd(char const * str, size_t len)
{
option_value_type_map_t const * map;
map = find_option_value_type_name(str, (unsigned int)len);
return (map == NULL) ? VTP_INVALID_CMD : map->vtp_id;
}
/* end of option-value-type.c */

View File

@@ -0,0 +1,60 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (stdin.h)
*
* It has been AutoGen-ed March 31, 2013 at 10:41:25 AM by AutoGen 5.17.3
* From the definitions stdin
* and the template file str2enum
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Command/Keyword Dispatcher
*/
#ifndef STR2ENUM_OPTION_VALUE_TYPE_H_GUARD
#define STR2ENUM_OPTION_VALUE_TYPE_H_GUARD 1
#include <sys/types.h>
#ifndef MISSING_INTTYPES_H
# include <inttypes.h>
#endif
typedef enum {
VTP_INVALID_CMD = 0,
VTP_CMD_STRING = 1,
VTP_CMD_INTEGER = 2,
VTP_CMD_BOOL = 3,
VTP_CMD_BOOLEAN = 4,
VTP_CMD_KEYWORD = 5,
VTP_CMD_SET = 6,
VTP_CMD_SET_MEMBERSHIP = 7,
VTP_CMD_NESTED = 8,
VTP_CMD_HIERARCHY = 9,
VTP_COUNT_CMD
} option_value_type_enum_t;
extern option_value_type_enum_t
find_option_value_type_cmd(char const * str, size_t len);
#endif /* STR2ENUM_OPTION_VALUE_TYPE_H_GUARD */
/* end of option-value-type.h */

View File

@@ -0,0 +1,148 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (stdin.c)
*
* It has been AutoGen-ed March 31, 2013 at 10:41:24 AM by AutoGen 5.17.3
* From the definitions stdin
* and the template file str2enum
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "option-xat-attribute.h"
/* ANSI-C code produced by gperf version 3.0.4 */
/* Command-line: gperf option-xat-attribute.gp */
/* Computed positions: -k'1' */
# if 0 /* gperf build options: */
// %struct-type
// %language=ANSI-C
// %includes
// %global-table
// %omit-struct-type
// %readonly-tables
// %compare-strncmp
//
// %define slot-name xat_name
// %define hash-function-name option_xat_attribute_hash
// %define lookup-function-name find_option_xat_attribute_name
// %define word-array-name option_xat_attribute_table
// %define initializer-suffix ,XAT_COUNT_CMD
//
# endif
#include "option-xat-attribute.h"
typedef struct {
char const * xat_name;
option_xat_attribute_enum_t xat_id;
} option_xat_attribute_map_t;
#include <string.h>
/* maximum key range = 6, duplicates = 0 */
static unsigned int
option_xat_attribute_hash (register const char *str, register unsigned int len)
{
static const unsigned char asso_values[] =
{
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10, 0,
10,10,10,10,10,10,10, 5,10, 0,
10,10,10,10,10,10, 0, 0,10, 0,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10
};
return len + asso_values[(unsigned char)str[0]];
}
static const option_xat_attribute_map_t option_xat_attribute_table[] =
{
{"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
{"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
{"type", XAT_CMD_TYPE},
{"words", XAT_CMD_WORDS},
{"cooked", XAT_CMD_COOKED},
{"members", XAT_CMD_MEMBERS},
{"uncooked", XAT_CMD_UNCOOKED},
{"keep", XAT_CMD_KEEP}
};
static inline const option_xat_attribute_map_t *
find_option_xat_attribute_name (register const char *str, register unsigned int len)
{
if (len <= 8 && len >= 4)
{
register int key = (int)option_xat_attribute_hash (str, len);
if (key <= 9 && key >= 0)
{
register const char *s = option_xat_attribute_table[key].xat_name;
if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
return &option_xat_attribute_table[key];
}
}
return 0;
}
/**
* Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
*
* @param[in] str a string that should start with a known key word.
* @param[in] len the provided length of the keyword at \a str.
* @returns the enumeration value.
* If not found, that value is XAT_INVALID_CMD.
*/
option_xat_attribute_enum_t
find_option_xat_attribute_cmd(char const * str, size_t len)
{
option_xat_attribute_map_t const * map;
map = find_option_xat_attribute_name(str, (unsigned int)len);
return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
}
/* end of option-xat-attribute.c */

View File

@@ -0,0 +1,57 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (stdin.h)
*
* It has been AutoGen-ed March 31, 2013 at 10:41:24 AM by AutoGen 5.17.3
* From the definitions stdin
* and the template file str2enum
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name ``Bruce Korb'' nor the name of any other
* contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Command/Keyword Dispatcher
*/
#ifndef STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD
#define STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD 1
#include <sys/types.h>
#ifndef MISSING_INTTYPES_H
# include <inttypes.h>
#endif
typedef enum {
XAT_INVALID_CMD = 0,
XAT_CMD_TYPE = 1,
XAT_CMD_WORDS = 2,
XAT_CMD_MEMBERS = 3,
XAT_CMD_COOKED = 4,
XAT_CMD_UNCOOKED = 5,
XAT_CMD_KEEP = 6,
XAT_COUNT_CMD
} option_xat_attribute_enum_t;
extern option_xat_attribute_enum_t
find_option_xat_attribute_cmd(char const * str, size_t len);
#endif /* STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD */
/* end of option-xat-attribute.h */

View File

@@ -1,18 +1,18 @@
/* Parse a time duration and return a seconds count
Copyright (C) 2008-2012 Free Software Foundation, Inc.
Copyright (C) 2008-2013 Free Software Foundation, Inc.
Written by Bruce Korb <bkorb@gnu.org>, 2008.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
@@ -54,14 +54,14 @@ typedef enum {
#define TIME_MAX 0x7FFFFFFF
/* Wrapper around strtoul that does not require a cast. */
inline static unsigned long
static unsigned long
str_const_to_ul (cch_t * str, cch_t ** ppz, int base)
{
return strtoul (str, (char **)ppz, base);
}
/* Wrapper around strtol that does not require a cast. */
inline static long
static long
str_const_to_l (cch_t * str, cch_t ** ppz, int base)
{
return strtol (str, (char **)ppz, base);
@@ -70,7 +70,7 @@ str_const_to_l (cch_t * str, cch_t ** ppz, int base)
/* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME
with errno set as an error situation, and returning BAD_TIME
with errno set in an error situation. */
inline static time_t
static time_t
scale_n_add (time_t base, time_t val, int scale)
{
if (base == BAD_TIME)

View File

@@ -1,18 +1,18 @@
/* Parse a time duration and return a seconds count
Copyright (C) 2008-2012 Free Software Foundation, Inc.
Copyright (C) 2008-2013 Free Software Foundation, Inc.
Written by Bruce Korb <bkorb@gnu.org>, 2008.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*

View File

@@ -2,16 +2,18 @@
/**
* \file pgusage.c
*
* Time-stamp: "2012-02-28 19:49:32 bkorb"
*
* Automated Options Paged Usage module.
*
* @addtogroup autoopts
* @{
*/
/*
* This routine will run run-on options through a pager so the
* user may examine, print or edit them at their leisure.
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -23,19 +25,19 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*=export_func optionPagedUsage
* private:
*
* what: Decipher a boolean value
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + tOptions* + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg +
*
* doc:
* Run the usage output through a pager.
@@ -43,16 +45,16 @@
* This is disabled on platforms without a working fork() function.
=*/
void
optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
optionPagedUsage(tOptions * opts, tOptDesc * od)
{
#if ! defined(HAVE_WORKING_FORK)
if ((pOD->fOptState & OPTST_RESET) != 0)
if ((od->fOptState & OPTST_RESET) != 0)
return;
(*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS);
(*opts->pUsageProc)(opts, EXIT_SUCCESS);
#else
static pid_t my_pid;
char zPageUsage[ 1024 ];
char fil_name[1024];
/*
* IF we are being called after the usage proc is done
@@ -62,17 +64,18 @@ optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
switch (pagerState) {
case PAGER_STATE_INITIAL:
{
if ((pOD->fOptState & OPTST_RESET) != 0)
if ((od->fOptState & OPTST_RESET) != 0)
return;
my_pid = getpid();
snprintf(zPageUsage, sizeof(zPageUsage), TMP_USAGE_FMT, (tAoUL)my_pid);
unlink(zPageUsage);
snprintf(fil_name, sizeof(fil_name), TMP_USAGE_FMT,
(unsigned long)my_pid);
unlink(fil_name);
/*
* Set usage output to this temporary file
*/
option_usage_fp = fopen(zPageUsage, "w" FOPEN_BINARY_FLAG);
option_usage_fp = fopen(fil_name, "w" FOPEN_BINARY_FLAG);
if (option_usage_fp == NULL)
_exit(EXIT_FAILURE);
@@ -87,7 +90,7 @@ optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
* The usage procedure will now put the usage information into
* the temporary file we created above.
*/
(*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS);
(*opts->pUsageProc)(opts, EXIT_SUCCESS);
/* NOTREACHED */
_exit(EXIT_FAILURE);
@@ -95,23 +98,23 @@ optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
case PAGER_STATE_READY:
{
tCC* pzPager = (tCC*)getenv(PAGER_NAME);
char const * pager = (char const *)getenv(PAGER_NAME);
/*
* Use the "more(1)" program if "PAGER" has not been defined
*/
if (pzPager == NULL)
pzPager = MORE_STR;
if (pager == NULL)
pager = MORE_STR;
/*
* Page the file and remove it when done.
*/
snprintf(zPageUsage, sizeof(zPageUsage), PAGE_USAGE_FMT, pzPager,
(tAoUL)my_pid);
snprintf(fil_name, sizeof(fil_name), PAGE_USAGE_FMT, pager,
(unsigned long)my_pid);
fclose(stderr);
dup2(STDOUT_FILENO, STDERR_FILENO);
(void)system(zPageUsage);
ignore_val( system( fil_name));
}
case PAGER_STATE_CHILD:
@@ -123,7 +126,8 @@ optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
#endif
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,130 +1,147 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* Prototypes for autoopts
* Generated Sun May 6 16:21:08 PDT 2012
* Generated Sun Mar 31 10:41:38 PDT 2013
*/
#ifndef AUTOOPTS_PROTO_H_GUARD
#define AUTOOPTS_PROTO_H_GUARD 1
#ifndef LOCAL
# define LOCAL extern
# define REDEF_LOCAL 1
#else
# undef REDEF_LOCAL
#endif
/*
* Extracted from alias.c
*/
static tSuccess
too_many_occurrences(tOptions * opts, tOptDesc * od);
/*
* Extracted from autoopts.c
*/
LOCAL void *
static void *
ao_malloc(size_t sz);
LOCAL void *
static void *
ao_realloc(void *p, size_t sz);
LOCAL char *
static char *
ao_strdup(char const *str);
LOCAL tSuccess
handle_opt(tOptions * pOpts, tOptState* pOptState);
static tSuccess
handle_opt(tOptions * opts, tOptState * o_st);
LOCAL tSuccess
immediate_opts(tOptions * pOpts);
static tSuccess
next_opt(tOptions * opts, tOptState * o_st);
LOCAL tSuccess
regular_opts(tOptions * pOpts);
static tSuccess
regular_opts(tOptions * opts);
/*
* Extracted from check.c
*/
LOCAL bool
static bool
is_consistent(tOptions * pOpts);
/*
* Extracted from configfile.c
*/
LOCAL void
intern_file_load(tOptions* pOpts);
static void
intern_file_load(tOptions * opts);
LOCAL char*
parse_attrs(tOptions * pOpts, char * pzText, tOptionLoadMode * pMode,
static char const *
parse_attrs(tOptions * opts, char const * txt, tOptionLoadMode * pMode,
tOptionValue * pType);
LOCAL tSuccess
validate_struct(tOptions * pOpts, char const * pzProgram);
/*
* Extracted from env.c
*/
LOCAL void
static void
doPrognameEnv(tOptions * pOpts, teEnvPresetType type);
LOCAL void
static void
env_presets(tOptions * pOpts, teEnvPresetType type);
/*
* Extracted from find.c
*/
LOCAL tSuccess
opt_find_long(tOptions * pOpts, char const * opt_name, tOptState * pOptState);
static tSuccess
opt_find_long(tOptions * opts, char const * opt_name, tOptState * state);
LOCAL tSuccess
static tSuccess
opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState);
LOCAL tSuccess
get_opt_arg(tOptions * pOpts, tOptState * pOptState);
static tSuccess
get_opt_arg(tOptions * opts, tOptState * o_st);
LOCAL tSuccess
find_opt(tOptions * pOpts, tOptState * pOptState);
static tSuccess
find_opt(tOptions * opts, tOptState * o_st);
/*
* Extracted from init.c
*/
static tSuccess
validate_struct(tOptions * opts, char const * pname);
static tSuccess
immediate_opts(tOptions * opts);
static bool
ao_initialize(tOptions * opts, int a_ct, char ** a_v);
/*
* Extracted from load.c
*/
LOCAL void
mungeString(char* pzTxt, tOptionLoadMode mode);
static void
munge_str(char * txt, tOptionLoadMode mode);
LOCAL void
static void
loadOptionLine(
tOptions* pOpts,
tOptState* pOS,
char* pzLine,
tOptions * opts,
tOptState * opt_state,
char * line,
tDirection direction,
tOptionLoadMode load_mode );
/*
* Extracted from makeshell.c
*/
static void
fserr_warn(char const * prog, char const * op, char const * fname);
static void
fserr_exit(char const * prog, char const * op, char const * fname);
/*
* Extracted from nested.c
*/
LOCAL void
unload_arg_list(tArgList* pAL);
static void
unload_arg_list(tArgList * arg_list);
LOCAL tOptionValue*
optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen);
static tOptionValue *
optionLoadNested(char const * text, char const * name, size_t nm_len);
LOCAL int
static int
get_special_char(char const ** ppz, int * ct);
LOCAL void
static void
emit_special_char(FILE * fp, int ch);
/*
* Extracted from sort.c
*/
LOCAL void
optionSort(tOptions* pOpts);
static void
optionSort(tOptions * opts);
/*
* Extracted from stack.c
*/
LOCAL void
static void
addArgListEntry(void** ppAL, void* entry);
/*
* Extracted from usage.c
*/
LOCAL void
static void
set_usage_flags(tOptions * opts, char const * flg_txt);
#ifdef REDEF_LOCAL
# undef LOCAL
# define LOCAL
#endif
static void
ao_bug(char const * msg);
#endif /* AUTOOPTS_PROTO_H_GUARD */

View File

@@ -2,15 +2,17 @@
/**
* \file putshell.c
*
* Time-stamp: "2012-03-31 13:14:18 bkorb"
*
* This module will interpret the options set in the tOptions
* structure and print them to standard out in a fashion that
* will allow them to be interpreted by the Bourne or Korn shells.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,16 +24,23 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#define APOSTROPHE '\''
/* = = = START-STATIC-FORWARD = = = */
static size_t
string_size(char const * scan, size_t nl_len);
static char const *
print_quoted_apostrophes(char const * str);
static void
print_quot_str(char const * pzStr);
print_quot_str(char const * str);
static void
print_enumeration(tOptions * pOpts, tOptDesc * pOD);
@@ -43,20 +52,179 @@ static void
print_stacked_arg(tOptions * pOpts, tOptDesc * pOD);
static void
print_reordering(tOptions * pOpts);
print_reordering(tOptions * opts);
/* = = = END-STATIC-FORWARD = = = */
/*
* Make sure embedded single quotes come out okay. The initial quote has
* been emitted and the closing quote will be upon return.
/**
* Count the number of bytes required to represent a string as a
* compilable string.
*
* @param[in] scan the text to be rewritten as a C program text string.
* @param[in] nl_len the number of bytes used for each embedded newline.
*
* @returns the count, including the terminating NUL byte.
*/
static size_t
string_size(char const * scan, size_t nl_len)
{
/*
* Start by counting the start and end quotes, plus the NUL.
*/
size_t res_ln = 3;
for (;;) {
char ch = *(scan++);
if ((ch >= ' ') && (ch <= '~')) {
/*
* a backslash allowance for double quotes and baskslashes
*/
res_ln += ((ch == '"') || (ch == '\\')) ? 2 : 1;
}
/*
* When not a normal character, then count the characters
* required to represent whatever it is.
*/
else switch (ch) {
case NUL:
return res_ln;
case NL:
res_ln += nl_len;
break;
case HT:
case BEL:
case BS:
case FF:
case CR:
case VT:
res_ln += 2;
break;
default:
res_ln += 4; /* text len for \xNN */
}
}
}
/*=export_func optionQuoteString
* private:
*
* what: Print a string as quoted text suitable for a C compiler.
* arg: + char const * + text + a block of text to quote +
* arg: + char const * + nl + line splice text +
*
* ret_type: char const *
* ret_desc: the allocated input string as a quoted string
*
* doc:
* This is for internal use by autogen and autoopts.
* It takes an input string and produces text the C compiler can process
* to produce an exact copy of the original string.
* The caller must deallocate the result. Standard C strings and
* K&R strings are distinguished by the "nl" string.
=*/
char const *
optionQuoteString(char const * text, char const * nl)
{
size_t nl_len = strlen(nl);
char * out;
char * res = out = AGALOC(string_size(text, nl_len), "quot str");
*(out++) = '"';
for (;;) {
unsigned char ch = (unsigned char)*text;
if ((ch >= ' ') && (ch <= '~')) {
if ((ch == '"') || (ch == '\\'))
/*
* We must escape these characters in the output string
*/
*(out++) = '\\';
*(out++) = (char)ch;
} else switch (ch) {
# define add_esc_ch(_ch) { *(out++) = '\\'; *(out++) = (_ch); }
case BEL: add_esc_ch('a'); break;
case BS: add_esc_ch('b'); break;
case HT: add_esc_ch('t'); break;
case VT: add_esc_ch('v'); break;
case FF: add_esc_ch('f'); break;
case CR: add_esc_ch('r'); break;
case LF:
/*
* Place contiguous new-lines on a single line.
* The current character is a NL, check the next one.
*/
while (*++text == NL)
add_esc_ch('n');
/*
* Insert a splice before starting next line
*/
if (*text != NUL) {
memcpy(out, nl, nl_len);
out += nl_len;
continue; /* text is already at the next character */
}
add_esc_ch('n');
/* FALLTHROUGH */
case NUL:
/*
* End of string. Terminate the quoted output. If necessary,
* deallocate the text string. Return the scan resumption point.
*/
*(out++) = '"';
*out = NUL;
return res;
default:
/*
* sprintf is safe here, because we already computed
* the amount of space we will be using.
*/
sprintf(out, MK_STR_OCT_FMT, ch);
out += 4;
}
text++;
# undef add_esc_ch
}
}
/**
* Print out escaped apostorophes.
*
* @param[in] str the apostrophies to print
*/
static char const *
print_quoted_apostrophes(char const * str)
{
while (*str == APOSTROPHE) {
fputs(QUOT_APOS, stdout);
str++;
}
return str;
}
/**
* Print a single quote (apostrophe quoted) string.
* Other than somersaults for apostrophes, nothing else needs quoting.
*
* @param[in] str the string to print
*/
static void
print_quot_str(char const * pzStr)
print_quot_str(char const * str)
{
/*
* Handle empty strings to make the rest of the logic simpler.
*/
if ((pzStr == NULL) || (*pzStr == NUL)) {
if ((str == NULL) || (*str == NUL)) {
fputs(EMPTY_ARG, stdout);
return;
}
@@ -65,46 +233,42 @@ print_quot_str(char const * pzStr)
* Emit any single quotes/apostrophes at the start of the string and
* bail if that is all we need to do.
*/
while (*pzStr == '\'') {
fputs(QUOT_APOS, stdout);
pzStr++;
}
if (*pzStr == NUL)
str = print_quoted_apostrophes(str);
if (*str == NUL)
return;
/*
* Start the single quote string
*/
fputc('\'', stdout);
fputc(APOSTROPHE, stdout);
for (;;) {
char const * pz = strchr(pzStr, '\'');
char const * pz = strchr(str, APOSTROPHE);
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);
pzStr = pz;
(void)fwrite(str, (size_t)(pz - str), (size_t)1, stdout);
/*
* Emit an escaped apostrophe for every one we find.
* If that ends the string, do not re-open the single quotes.
* Close the current string, emit the apostrophes and re-open the
* string (IFF there is more text to print).
*/
while (*++pzStr == '\'') fputs("\\'", stdout);
if (*pzStr == NUL)
fputc(APOSTROPHE, stdout);
str = print_quoted_apostrophes(pz);
if (*str == NUL)
return;
fputc('\'', stdout);
fputc(APOSTROPHE, 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(str, stdout);
fputc(APOSTROPHE, stdout);
}
static void
@@ -164,9 +328,9 @@ print_membership(tOptions * pOpts, tOptDesc * pOD)
static void
print_stacked_arg(tOptions * pOpts, tOptDesc * pOD)
{
tArgList* pAL = (tArgList*)pOD->optCookie;
tCC** ppz = pAL->apzArgs;
int ct = pAL->useCt;
tArgList* pAL = (tArgList*)pOD->optCookie;
char const ** ppz = pAL->apzArgs;
int ct = pAL->useCt;
printf(zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct);
@@ -179,34 +343,24 @@ print_stacked_arg(tOptions * pOpts, tOptDesc * pOD)
}
}
/**
* emit the arguments as readily parsed text.
* The program options are set by emitting the shell "set" command.
*
* @param[in] opts the program options structure
*/
static void
print_reordering(tOptions * pOpts)
print_reordering(tOptions * opts)
{
unsigned int optIx;
unsigned int ix;
fputs(set_dash, stdout);
for (optIx = pOpts->curOptIdx;
optIx < pOpts->origArgCt;
optIx++) {
char* pzArg = pOpts->origArgVect[ optIx ];
if (strchr(pzArg, '\'') == NULL)
printf(arg_fmt, pzArg);
else {
fputs(" '", stdout);
for (;;) {
char ch = *(pzArg++);
switch (ch) {
case '\'': fputs(apostrophy, stdout); break;
case NUL: goto arg_done;
default: fputc(ch, stdout); break;
}
} arg_done:;
fputc('\'', stdout);
}
for (ix = opts->curOptIdx;
ix < opts->origArgCt;
ix++) {
fputc(' ', stdout);
print_quot_str(opts->origArgVect[ ix ]);
}
fputs(init_optct, stdout);
}
@@ -352,7 +506,8 @@ optionPutShell(tOptions* pOpts)
fflush(stdout);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,11 +2,15 @@
/**
* \file reset.c
*
* Time-stamp: "2011-05-24 18:07:16 bkorb"
* Reset the option state to the compiled state.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -18,11 +22,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
static void
@@ -67,7 +71,7 @@ optionResetEverything(tOptions * pOpts)
* For example, --reset=foo will cause the --foo option to be reset.
=*/
void
optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
optionResetOpt(tOptions * pOpts, tOptDesc * pOD)
{
static bool reset_active = false;
@@ -75,17 +79,18 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
char const * pzArg = pOD->optArg.argString;
tSuccess succ;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if (reset_active)
return;
if ( (! HAS_originalOptArgArray(pOpts))
|| (pOpts->originalOptArgCookie == NULL)) {
fputs(zResetNotConfig, stderr);
_exit(EX_SOFTWARE);
}
|| (pOpts->originalOptArgCookie == NULL))
ao_bug(zno_reset);
if ((pzArg == NULL) || (*pzArg == NUL)) {
fputs(zNoResetArg, stderr);
fprintf(stderr, zreset_arg, pOpts->pzProgName, pOD->pz_Name);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
/* NOTREACHED */
assert(0 == 1);
@@ -100,7 +105,7 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
return;
}
succ = opt_find_short(pOpts, (tAoUC)*pzArg, &opt_state);
succ = opt_find_short(pOpts, (uint8_t)*pzArg, &opt_state);
if (! SUCCESSFUL(succ)) {
fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
pOpts->pUsageProc(pOpts, EXIT_FAILURE);
@@ -126,7 +131,8 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
optionReset(pOpts, opt_state.pOD);
reset_active = false;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,15 +2,17 @@
/*
* \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,
* then the initial state will be restored.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,11 +24,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*
@@ -92,29 +94,20 @@ fixupSavedOptionArgs(tOptions* pOpts)
* Otherwise, it will always succeed.
=*/
void
optionSaveState(tOptions* pOpts)
optionSaveState(tOptions * pOpts)
{
tOptions* p = (tOptions*)pOpts->pSavedState;
tOptions * p = (tOptions*)pOpts->pSavedState;
if (p == NULL) {
size_t sz = sizeof(*pOpts) + (pOpts->optCt * sizeof(tOptDesc));
size_t sz = sizeof(*pOpts)
+ ((size_t)pOpts->optCt * sizeof(tOptDesc));
p = AGALOC(sz, "saved option state");
if (p == NULL) {
tCC* pzName = pOpts->pzProgName;
if (pzName == NULL) {
pzName = pOpts->pzPROGNAME;
if (pzName == NULL)
pzName = zNil;
}
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 + 1, pOpts->pOptDesc, (size_t)p->optCt * sizeof(tOptDesc));
fixupSavedOptionArgs(pOpts);
}
@@ -141,7 +134,7 @@ optionRestore(tOptions* pOpts)
tOptions* p = (tOptions*)pOpts->pSavedState;
if (p == NULL) {
tCC* pzName = pOpts->pzProgName;
char const * pzName = pOpts->pzProgName;
if (pzName == NULL) {
pzName = pOpts->pzPROGNAME;
if (pzName == NULL)
@@ -155,7 +148,7 @@ optionRestore(tOptions* pOpts)
optionFree(pOpts);
memcpy(pOpts, p, sizeof(*p));
memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc));
memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
pOpts->pSavedState = p;
fixupSavedOptionArgs(pOpts);
@@ -213,13 +206,15 @@ 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));
memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
AGFREE(pOpts->pSavedState);
pOpts->pSavedState = NULL;
goto free_saved_state;
}
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,15 +2,17 @@
/*
* \file save.c
*
* Time-stamp: "2012-03-31 13:15:19 bkorb"
*
* This module's routines will take the currently set options and
* store them into an ".rc" file for re-interpretation the next
* time the invoking program is run.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -22,22 +24,22 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
static char const *
find_dir_name(tOptions * pOpts, int * p_free);
find_dir_name(tOptions * opts, int * p_free);
static char const *
find_file_name(tOptions * pOpts, int * p_free_name);
find_file_name(tOptions * opts, int * p_free_name);
static void
prt_entry(FILE * fp, tOptDesc * p, char const * pzLA);
prt_entry(FILE * fp, tOptDesc * od, char const * l_arg);
static void
prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp);
@@ -52,7 +54,7 @@ static void
prt_nested(FILE * fp, tOptDesc * p);
static FILE *
open_sv_file(tOptions* pOpts);
open_sv_file(tOptions * opts);
static void
prt_no_arg_opt(FILE * fp, tOptDesc * p, tOptDesc * pOD);
@@ -64,22 +66,24 @@ static void
prt_enum_arg(FILE * fp, tOptDesc * pOD);
static void
prt_set_arg(FILE * fp, tOptDesc * pOD);
prt_set_arg(FILE * fp, tOptDesc * od);
static void
prt_file_arg(FILE * fp, tOptDesc * pOD, tOptions* pOpts);
prt_file_arg(FILE * fp, tOptDesc * od, tOptions * opts);
/* = = = END-STATIC-FORWARD = = = */
/**
*/
static char const *
find_dir_name(tOptions * pOpts, int * p_free)
find_dir_name(tOptions * opts, int * p_free)
{
char const * pzDir;
if ( (pOpts->specOptIdx.save_opts == NO_EQUIVALENT)
|| (pOpts->specOptIdx.save_opts == 0))
if ( (opts->specOptIdx.save_opts == NO_EQUIVALENT)
|| (opts->specOptIdx.save_opts == 0))
return NULL;
pzDir = pOpts->pOptDesc[ pOpts->specOptIdx.save_opts ].optArg.argString;
pzDir = opts->pOptDesc[ opts->specOptIdx.save_opts ].optArg.argString;
if ((pzDir != NULL) && (*pzDir != NUL))
return pzDir;
@@ -88,7 +92,7 @@ find_dir_name(tOptions * pOpts, int * p_free)
* we can stash the RC (INI) file.
*/
{
char const * const* papz = pOpts->papzHomeList;
char const * const* papz = opts->papzHomeList;
if (papz == NULL)
return NULL;
@@ -124,7 +128,7 @@ find_dir_name(tOptions * pOpts, int * p_free)
}
if (pzEnv == NULL) {
fprintf(stderr, SAVE_WARN, pOpts->pzProgName);
fprintf(stderr, zsave_warn, opts->pzProgName);
fprintf(stderr, zNotDef, pzDir);
return NULL;
}
@@ -150,14 +154,15 @@ find_dir_name(tOptions * pOpts, int * p_free)
}
}
/**
*/
static char const *
find_file_name(tOptions * pOpts, int * p_free_name)
find_file_name(tOptions * opts, int * p_free_name)
{
struct stat stBuf;
int free_dir_name = 0;
char const * pzDir = find_dir_name(pOpts, &free_dir_name);
char const * pzDir = find_dir_name(opts, &free_dir_name);
if (pzDir == NULL)
return NULL;
@@ -175,7 +180,7 @@ find_file_name(tOptions * pOpts, int * p_free_name)
*/
if (errno != ENOENT) {
bogus_name:
fprintf(stderr, SAVE_WARN, pOpts->pzProgName);
fprintf(stderr, zsave_warn, opts->pzProgName);
fprintf(stderr, zNoStat, errno, strerror(errno), pzDir);
if (free_dir_name)
AGFREE((void*)pzDir);
@@ -208,14 +213,14 @@ find_file_name(tOptions * pOpts, int * p_free_name)
* THEN tack on the config file name
*/
if (S_ISDIR(stBuf.st_mode)) {
size_t sz = strlen(pzDir) + strlen(pOpts->pzRcName) + 2;
size_t sz = strlen(pzDir) + strlen(opts->pzRcName) + 2;
{
char * pzPath = (char*)AGALOC(sz, "file name");
#ifdef HAVE_SNPRINTF
snprintf(pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName);
snprintf(pzPath, sz, "%s/%s", pzDir, opts->pzRcName);
#else
sprintf(pzPath, "%s/%s", pzDir, pOpts->pzRcName);
sprintf(pzPath, "%s/%s", pzDir, opts->pzRcName);
#endif
if (free_dir_name)
AGFREE((void*)pzDir);
@@ -229,7 +234,7 @@ find_file_name(tOptions * pOpts, int * p_free_name)
*/
if (stat(pzDir, &stBuf) != 0) {
if (errno != ENOENT) {
fprintf(stderr, SAVE_WARN, pOpts->pzProgName);
fprintf(stderr, zsave_warn, opts->pzProgName);
fprintf(stderr, zNoStat, errno, strerror(errno),
pzDir);
AGFREE((void*)pzDir);
@@ -248,8 +253,7 @@ find_file_name(tOptions * pOpts, int * p_free_name)
* or will soon be a file.
*/
if (! S_ISREG(stBuf.st_mode)) {
fprintf(stderr, SAVE_WARN, pOpts->pzProgName);
fprintf(stderr, zNotFile, pzDir);
fprintf(stderr, zsave_warn, opts->pzProgName, pzDir);
if (free_dir_name)
AGFREE((void*)pzDir);
return NULL;
@@ -263,9 +267,15 @@ find_file_name(tOptions * pOpts, int * p_free_name)
return pzDir;
}
/**
* print one option entry to the save file.
*
* @param[in] fp the file pointer for the save file
* @param[in] od the option descriptor to print
* @param[in] l_arg the last argument for the option
*/
static void
prt_entry(FILE * fp, tOptDesc * p, char const * pzLA)
prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
{
/*
* There is an argument. Pad the name so values line up.
@@ -275,10 +285,10 @@ prt_entry(FILE * fp, tOptDesc * p, char const * pzLA)
*/
{
char const * pz;
if (! DISABLED_OPT(p) || (p->optEquivIndex != NO_EQUIVALENT))
pz = p->pz_Name;
if (! DISABLED_OPT(od) || (od->optEquivIndex != NO_EQUIVALENT))
pz = od->pz_Name;
else
pz = p->pz_DisableName;
pz = od->pz_DisableName;
fprintf(fp, "%-18s", pz);
}
@@ -286,44 +296,45 @@ prt_entry(FILE * fp, tOptDesc * p, char const * pzLA)
* IF the option is numeric only,
* 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);
if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NUMERIC)
fprintf(fp, " %d\n", (int)(t_word)l_arg);
/*
* OTHERWISE, FOR each line of the value text, ...
*/
else if (pzLA == NULL)
else if (l_arg == NULL)
fputc(NL, fp);
else {
fputc(' ', fp); fputc(' ', fp);
for (;;) {
char const * pzNl = strchr(pzLA, NL);
char const * eol = strchr(l_arg, NL);
/*
* IF this is the last line
* THEN bail and print it
*/
if (pzNl == NULL)
if (eol == NULL)
break;
/*
* Print the continuation and the text from the current line
*/
(void)fwrite(pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp);
pzLA = pzNl+1; /* advance the Last Arg pointer */
(void)fwrite(l_arg, (size_t)(eol - l_arg), (size_t)1, fp);
l_arg = eol+1; /* advance the Last Arg pointer */
fputs("\\\n", fp);
}
/*
* Terminate the entry
*/
fputs(pzLA, fp);
fputs(l_arg, fp);
fputc(NL, fp);
}
}
/**
*/
static void
prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
{
@@ -343,7 +354,7 @@ prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
if (pOD != NULL) {
tAoUI opt_state = pOD->fOptState;
uint32_t opt_state = pOD->fOptState;
uintptr_t val = pOD->optArg.argEnum;
char const * typ = (ovp->valType == OPARG_TYPE_ENUMERATION)
? "keyword" : "set-membership";
@@ -388,7 +399,8 @@ prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
}
}
/**
*/
static void
prt_string(FILE * fp, char const * name, char const * pz)
{
@@ -423,7 +435,8 @@ prt_string(FILE * fp, char const * name, char const * pz)
fprintf(fp, END_XML_FMT, name);
}
/**
*/
static void
prt_val_list(FILE * fp, char const * name, tArgList * al)
{
@@ -458,7 +471,8 @@ prt_val_list(FILE * fp, char const * name, tArgList * al)
fprintf(fp, "</%s>\n", name);
}
/**
*/
static void
prt_nested(FILE * fp, tOptDesc * p)
{
@@ -494,21 +508,26 @@ prt_nested(FILE * fp, tOptDesc * p)
} while (--opt_ct > 0);
}
/**
* open the file for saving option state.
*
* @param[in] opts the program options structure
* @returns the open file pointer. It may be NULL.
*/
static FILE *
open_sv_file(tOptions* pOpts)
open_sv_file(tOptions * opts)
{
FILE * fp;
{
int free_name = 0;
char const * pzFName = find_file_name(pOpts, &free_name);
char const * pzFName = find_file_name(opts, &free_name);
if (pzFName == NULL)
return NULL;
fp = fopen(pzFName, "w" FOPEN_BINARY_FLAG);
if (fp == NULL) {
fprintf(stderr, SAVE_WARN, pOpts->pzProgName);
fprintf(stderr, zsave_warn, opts->pzProgName);
fprintf(stderr, zNoCreat, errno, strerror(errno), pzFName);
if (free_name)
AGFREE((void*) pzFName );
@@ -519,30 +538,33 @@ open_sv_file(tOptions* pOpts)
AGFREE((void*)pzFName);
}
fputs("# ", fp);
{
char const * pz = pOpts->pzUsageTitle;
fputs("# ", fp);
do { fputc(*pz, fp); } while (*(pz++) != NL);
char const * e = strchr(opts->pzUsageTitle, NL);
if (e++ != NULL)
fwrite(opts->pzUsageTitle, 1, e - opts->pzUsageTitle, fp);
}
{
time_t timeVal = time(NULL);
char * pzTime = ctime(&timeVal);
time_t cur_time = time(NULL);
char * time_str = ctime(&cur_time);
fprintf(fp, zPresetFile, pzTime);
fprintf(fp, zPresetFile, time_str);
#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*)time_str);
#endif
}
return fp;
}
/**
*/
static void
prt_no_arg_opt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
{
@@ -564,6 +586,8 @@ prt_no_arg_opt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
fprintf(fp, "%s\n", pznm);
}
/**
*/
static void
prt_str_arg(FILE * fp, tOptDesc * pOD)
{
@@ -585,6 +609,8 @@ prt_str_arg(FILE * fp, tOptDesc * pOD)
}
}
/**
*/
static void
prt_enum_arg(FILE * fp, tOptDesc * pOD)
{
@@ -600,56 +626,72 @@ prt_enum_arg(FILE * fp, tOptDesc * pOD)
pOD->optArg.argEnum = val;
}
/**
* Print the bits set in a bit mask option.
* We call the option handling function with a magic value for
* the options pointer and it allocates and fills in the string.
* We print that with a call to prt_entry().
*
* @param[in] fp the file pointer to write to
* @param[in] od the option descriptor with a bit mask value type
*/
static void
prt_set_arg(FILE * fp, tOptDesc * pOD)
prt_set_arg(FILE * fp, tOptDesc * od)
{
uintptr_t val = pOD->optArg.argEnum;
uintptr_t val = od->optArg.argEnum;
/*
* This is a magic incantation that will convert the
* bit flag values back into a string suitable for printing.
*/
(*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
prt_entry(fp, pOD, (void*)(pOD->optArg.argString));
(*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od);
prt_entry(fp, od, (void*)(od->optArg.argString));
if (pOD->optArg.argString != NULL) {
if (od->optArg.argString != NULL) {
/*
* set membership strings get allocated
*/
AGFREE((void*)pOD->optArg.argString);
pOD->fOptState &= ~OPTST_ALLOC_ARG;
AGFREE((void*)od->optArg.argString);
od->fOptState &= ~OPTST_ALLOC_ARG;
}
pOD->optArg.argEnum = val;
od->optArg.argEnum = val;
}
/**
* figure out what the option file name argument is.
* If one can be found, call prt_entry() to emit it.
*
* @param[in] fp the file pointer to write to.
* @param[in] od the option descriptor with a bit mask value type
* @param[in] opts the program options descriptor
*/
static void
prt_file_arg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
prt_file_arg(FILE * fp, tOptDesc * od, tOptions * opts)
{
/*
* If the cookie is not NULL, then it has the file name, period.
* Otherwise, if we have a non-NULL string argument, then....
*/
if (pOD->optCookie != NULL)
prt_entry(fp, pOD, pOD->optCookie);
if (od->optCookie != NULL)
prt_entry(fp, od, od->optCookie);
else if (HAS_originalOptArgArray(pOpts)) {
else if (HAS_originalOptArgArray(opts)) {
char const * orig =
pOpts->originalOptArgArray[pOD->optIndex].argString;
opts->originalOptArgArray[od->optIndex].argString;
if (pOD->optArg.argString == orig)
if (od->optArg.argString == orig)
return;
prt_entry(fp, pOD, pOD->optArg.argString);
prt_entry(fp, od, od->optArg.argString);
}
}
/*=export_func optionSaveFile
*
* what: saves the option state to a file
*
* arg: tOptions*, pOpts, program options descriptor
* arg: tOptions*, opts, program options descriptor
*
* doc:
*
@@ -675,11 +717,11 @@ prt_file_arg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
* will be printed to @code{stderr} and the routine will return.
=*/
void
optionSaveFile(tOptions* pOpts)
optionSaveFile(tOptions * opts)
{
tOptDesc* pOD;
int ct;
FILE * fp = open_sv_file(pOpts);
tOptDesc * od;
int ct;
FILE * fp = open_sv_file(opts);
if (fp == NULL)
return;
@@ -687,8 +729,8 @@ optionSaveFile(tOptions* pOpts)
/*
* FOR each of the defined options, ...
*/
ct = pOpts->presetOptCt;
pOD = pOpts->pOptDesc;
ct = opts->presetOptCt;
od = opts->pOptDesc;
do {
tOptDesc * p;
@@ -701,14 +743,14 @@ optionSaveFile(tOptions* pOpts)
* Equivalenced options get picked up when the equivalenced-to
* option is processed.
*/
if (UNUSED_OPT(pOD))
if (UNUSED_OPT(od))
continue;
if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
if ((od->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
continue;
if ( (pOD->optEquivIndex != NO_EQUIVALENT)
&& (pOD->optEquivIndex != pOD->optIndex))
if ( (od->optEquivIndex != NO_EQUIVALENT)
&& (od->optEquivIndex != od->optIndex))
continue;
/*
@@ -716,12 +758,12 @@ optionSaveFile(tOptions* pOpts)
* but the actual option argument type comes from the original
* option descriptor. Be careful!
*/
p = ((pOD->fOptState & OPTST_EQUIVALENCE) != 0)
? (pOpts->pOptDesc + pOD->optActualIndex) : pOD;
p = ((od->fOptState & OPTST_EQUIVALENCE) != 0)
? (opts->pOptDesc + od->optActualIndex) : od;
switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_NONE:
prt_no_arg_opt(fp, p, pOD);
prt_no_arg_opt(fp, p, od);
break;
case OPARG_TYPE_NUMERIC:
@@ -749,17 +791,18 @@ optionSaveFile(tOptions* pOpts)
break;
case OPARG_TYPE_FILE:
prt_file_arg(fp, p, pOpts);
prt_file_arg(fp, p, opts);
break;
default:
break; /* cannot handle - skip it */
}
} while (pOD++, (--ct > 0));
} while (od++, (--ct > 0));
fclose(fp);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,13 +2,15 @@
/*
* \file sort.c
*
* Time-stamp: "2011-05-24 18:07:14 bkorb"
*
* This module implements argument sorting.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -20,35 +22,35 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/* = = = START-STATIC-FORWARD = = = */
static tSuccess
mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
char** ppzOpts, int* pOptsIdx);
must_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx);
static tSuccess
mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
char** ppzOpts, int* pOptsIdx);
maybe_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx);
static tSuccess
checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS,
char** ppzOpts, int* pOptsIdx);
short_opt_ck(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx);
/* = = = END-STATIC-FORWARD = = = */
/*
* "mustHandleArg" and "mayHandleArg" are really similar. The biggest
* "must_arg" and "maybe_arg" are really similar. The biggest
* difference is that "may" will consume the next argument only if it
* 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)
must_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx)
{
/*
* An option argument is required. Long options can either have
@@ -61,7 +63,7 @@ mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
* See if an arg string follows the flag character. If not,
* the next arg must be the option argument.
*/
if (*pzArg != NUL)
if (*arg_txt != NUL)
return SUCCESS;
break;
@@ -77,16 +79,16 @@ mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
default:
return FAILURE;
}
if (pOpts->curOptIdx >= pOpts->origArgCt)
if (opts->curOptIdx >= opts->origArgCt)
return FAILURE;
ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
opt_txt[ (*opt_idx)++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
return SUCCESS;
}
static tSuccess
mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
char** ppzOpts, int* pOptsIdx)
maybe_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx)
{
/*
* An option argument is optional.
@@ -98,7 +100,7 @@ mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
* THEN see if there is another argument. If so and if it
* does *NOT* start with a hyphen, then it is the option arg.
*/
if (*pzArg != NUL)
if (*arg_txt != NUL)
return SUCCESS;
break;
@@ -114,12 +116,12 @@ mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS,
default:
return FAILURE;
}
if (pOpts->curOptIdx >= pOpts->origArgCt)
if (opts->curOptIdx >= opts->origArgCt)
return PROBLEM;
pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
if (*pzArg != '-')
ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
arg_txt = opts->origArgVect[ opts->curOptIdx ];
if (*arg_txt != '-')
opt_txt[ (*opt_idx)++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
return SUCCESS;
}
@@ -128,31 +130,31 @@ 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)
short_opt_ck(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx)
{
while (*pzArg != NUL) {
if (FAILED(opt_find_short(pOpts, (tAoUC)*pzArg, pOS)))
while (*arg_txt != NUL) {
if (FAILED(opt_find_short(opts, (uint8_t)*arg_txt, pOS)))
return FAILURE;
/*
* See if we can have an arg.
*/
if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
pzArg++;
arg_txt++;
} else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
/*
* Take an argument if it is not attached and it does not
* start with a hyphen.
*/
if (pzArg[1] != NUL)
if (arg_txt[1] != NUL)
return SUCCESS;
pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
if (*pzArg != '-')
ppzOpts[ (*pOptsIdx)++ ] =
pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
arg_txt = opts->origArgVect[ opts->curOptIdx ];
if (*arg_txt != '-')
opt_txt[ (*opt_idx)++ ] =
opts->origArgVect[ (opts->curOptIdx)++ ];
return SUCCESS;
} else {
@@ -160,11 +162,11 @@ checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS,
* IF we need another argument, be sure it is there and
* take it.
*/
if (pzArg[1] == NUL) {
if (pOpts->curOptIdx >= pOpts->origArgCt)
if (arg_txt[1] == NUL) {
if (opts->curOptIdx >= opts->origArgCt)
return FAILURE;
ppzOpts[ (*pOptsIdx)++ ] =
pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
opt_txt[ (*opt_idx)++ ] =
opts->origArgVect[ (opts->curOptIdx)++ ];
}
return SUCCESS;
}
@@ -177,12 +179,12 @@ checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS,
* then this routine will to the trick.
*/
LOCAL void
optionSort(tOptions* pOpts)
optionSort(tOptions * opts)
{
char** ppzOpts;
char** ppzOpds;
int optsIdx = 0;
int opdsIdx = 0;
char ** opt_txt;
char ** ppzOpds;
uint32_t optsIdx = 0;
uint32_t opdsIdx = 0;
tOptState os = OPTSTATE_INITIALIZER(DEFINED);
@@ -190,24 +192,24 @@ optionSort(tOptions* pOpts)
* Disable for POSIX conformance, or if there are no operands.
*/
if ( (getenv("POSIXLY_CORRECT") != NULL)
|| NAMED_OPTS(pOpts))
|| NAMED_OPTS(opts))
return;
/*
* Make sure we can allocate two full-sized arg vectors.
*/
ppzOpts = malloc(pOpts->origArgCt * sizeof(char*));
if (ppzOpts == NULL)
opt_txt = malloc(opts->origArgCt * sizeof(char*));
if (opt_txt == NULL)
goto exit_no_mem;
ppzOpds = malloc(pOpts->origArgCt * sizeof(char*));
ppzOpds = malloc(opts->origArgCt * sizeof(char*));
if (ppzOpds == NULL) {
free(ppzOpts);
free(opt_txt);
goto exit_no_mem;
}
pOpts->curOptIdx = 1;
pOpts->pzCurOpt = NULL;
opts->curOptIdx = 1;
opts->pzCurOpt = NULL;
/*
* Now, process all the options from our current position onward.
@@ -215,30 +217,30 @@ optionSort(tOptions* pOpts)
* non-standard programs that require it.)
*/
for (;;) {
char* pzArg;
char * arg_txt;
tSuccess res;
/*
* If we're out of arguments, we're done. Join the option and
* operand lists into the original argument vector.
*/
if (pOpts->curOptIdx >= pOpts->origArgCt) {
if (opts->curOptIdx >= opts->origArgCt) {
errno = 0;
goto joinLists;
}
pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
if (*pzArg != '-') {
ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
arg_txt = opts->origArgVect[ opts->curOptIdx ];
if (*arg_txt != '-') {
ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
continue;
}
switch (pzArg[1]) {
switch (arg_txt[1]) {
case NUL:
/*
* A single hyphen is an operand.
*/
ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
continue;
case '-':
@@ -246,12 +248,12 @@ optionSort(tOptions* pOpts)
* Two consecutive hypens. Put them on the options list and then
* _always_ force the remainder of the arguments to be operands.
*/
if (pzArg[2] == NUL) {
ppzOpts[ optsIdx++ ] =
pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
if (arg_txt[2] == NUL) {
opt_txt[ optsIdx++ ] =
opts->origArgVect[ (opts->curOptIdx)++ ];
goto restOperands;
}
res = opt_find_long(pOpts, pzArg+2, &os);
res = opt_find_long(opts, arg_txt+2, &os);
break;
default:
@@ -260,10 +262,10 @@ optionSort(tOptions* pOpts)
* option processing. Otherwise the character must be a
* short (i.e. single character) option.
*/
if ((pOpts->fOptSet & OPTPROC_SHORTOPT) == 0) {
res = opt_find_long(pOpts, pzArg+1, &os);
if ((opts->fOptSet & OPTPROC_SHORTOPT) == 0) {
res = opt_find_long(opts, arg_txt+1, &os);
} else {
res = opt_find_short(pOpts, (tAoUC)pzArg[1], &os);
res = opt_find_short(opts, (uint8_t)arg_txt[1], &os);
}
break;
}
@@ -277,7 +279,7 @@ optionSort(tOptions* pOpts)
* Next, we have to see if we need to pull another argument to be
* used as the option argument.
*/
ppzOpts[ optsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
opt_txt[ optsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
if (OPTST_GET_ARGTYPE(os.pOD->fOptState) == OPARG_TYPE_NONE) {
/*
@@ -286,20 +288,20 @@ optionSort(tOptions* pOpts)
* of the argument string.
*/
if ( (os.optType == TOPT_SHORT)
&& FAILED(checkShortOpts(pOpts, pzArg+2, &os, ppzOpts,
&optsIdx)) ) {
&& FAILED(short_opt_ck(opts, arg_txt+2, &os, opt_txt,
&optsIdx)) ) {
errno = EINVAL;
goto freeTemps;
}
} else if (os.pOD->fOptState & OPTST_ARG_OPTIONAL) {
switch (mayHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) {
switch (maybe_arg(opts, arg_txt+2, &os, opt_txt, &optsIdx)) {
case FAILURE: errno = EIO; goto freeTemps;
case PROBLEM: errno = 0; goto joinLists;
}
} else {
switch (mustHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) {
switch (must_arg(opts, arg_txt+2, &os, opt_txt, &optsIdx)) {
case PROBLEM:
case FAILURE: errno = EIO; goto freeTemps;
}
@@ -307,18 +309,19 @@ optionSort(tOptions* pOpts)
} /* for (;;) */
restOperands:
while (pOpts->curOptIdx < pOpts->origArgCt)
ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
while (opts->curOptIdx < opts->origArgCt)
ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
joinLists:
if (optsIdx > 0)
memcpy(pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof(char*));
memcpy(opts->origArgVect + 1, opt_txt,
(size_t)optsIdx * sizeof(char*));
if (opdsIdx > 0)
memcpy(pOpts->origArgVect + 1 + optsIdx, ppzOpds,
opdsIdx * sizeof(char*));
memcpy(opts->origArgVect + 1 + optsIdx, ppzOpds,
(size_t)opdsIdx * sizeof(char*));
freeTemps:
free(ppzOpts);
free(opt_txt);
free(ppzOpds);
return;
@@ -327,7 +330,8 @@ optionSort(tOptions* pOpts)
return;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,14 +2,16 @@
/**
* \file stack.c
*
* Time-stamp: "2012-03-31 13:16:41 bkorb"
*
* This is a special option processing routine that will save the
* argument to an option in a FIFO queue.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -21,11 +23,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#ifdef WITH_LIBREGEX
@@ -49,8 +51,12 @@ optionUnstackArg(tOptions * pOpts, tOptDesc * pOptDesc)
(void)pOpts;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((pOptDesc->fOptState & OPTST_RESET) != 0)
return;
pAL = (tArgList*)pOptDesc->optCookie;
/*
@@ -127,8 +133,8 @@ optionUnstackArg(tOptions * pOpts, tOptDesc * pOptDesc)
* we are keeping a define.
*/
for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) {
tCC* pzSrc = pAL->apzArgs[ i ];
char* pzEq = strchr(pzSrc, '=');
const char ** pzSrc = pAL->apzArgs[ i ];
char * pzEq = strchr(pzSrc, '=');
if (pzEq != NULL)
*pzEq = NUL;
@@ -205,7 +211,7 @@ addArgListEntry(void** ppAL, void* entry)
* The base structure contains space for MIN_ARG_ALLOC_CT
* pointers. We subtract it off to find our augment size.
*/
sz += sizeof(char*) * (pAL->allocCt - MIN_ARG_ALLOC_CT);
sz += sizeof(char*) * ((size_t)pAL->allocCt - MIN_ARG_ALLOC_CT);
pAL = (tArgList*)AGREALOC((void*)pAL, sz, "expanded opt arg stack");
if (pAL == NULL)
return;
@@ -234,7 +240,8 @@ optionStackArg(tOptions * pOpts, tOptDesc * pOD)
{
char * pz;
(void)pOpts;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((pOD->fOptState & OPTST_RESET) != 0) {
tArgList* pAL = (void*)pOD->optCookie;
@@ -255,7 +262,8 @@ optionStackArg(tOptions * pOpts, tOptDesc * pOD)
addArgListEntry(&(pOD->optCookie), (void*)pz);
}
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,8 +2,6 @@
/**
* \file streqvcmp.c
*
* Time-stamp: "2012-03-31 13:17:39 bkorb"
*
* String Equivalence Comparison
*
* These routines allow any character to be mapped to any other
@@ -11,9 +9,13 @@
* the characters "-", "_" and "^" all need to be equivalent
* (because they are treated so by different development environments).
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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,11 +27,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*
* This array is designed for mapping upper and lower case letter
* together for a case independent comparison. The mappings are
@@ -98,12 +100,19 @@ static unsigned char charmap[] = {
* err: none checked. Caller responsible for seg faults.
=*/
int
strneqvcmp(tCC* s1, tCC* s2, int ct)
strneqvcmp(char const * s1, char const * s2, int ct)
{
for (; ct > 0; --ct) {
unsigned char u1 = (unsigned char) *s1++;
unsigned char u2 = (unsigned char) *s2++;
int dif = charmap[ u1 ] - charmap[ u2 ];
int dif;
if (u1 == u2) {
if (u1 == NUL)
return 0;
continue;
}
dif = charmap[ u1 ] - charmap[ u2 ];
if (dif != 0)
return dif;
@@ -137,12 +146,19 @@ strneqvcmp(tCC* s1, tCC* s2, int ct)
* err: none checked. Caller responsible for seg faults.
=*/
int
streqvcmp(tCC* s1, tCC* s2)
streqvcmp(char const * s1, char const * s2)
{
for (;;) {
unsigned char u1 = (unsigned char) *s1++;
unsigned char u2 = (unsigned char) *s2++;
int dif = charmap[ u1 ] - charmap[ u2 ];
int dif;
if (u1 == u2) {
if (u1 == NUL)
return 0;
continue;
}
dif = charmap[ u1 ] - charmap[ u2 ];
if (dif != 0)
return dif;
@@ -157,8 +173,8 @@ streqvcmp(tCC* s1, tCC* s2)
*
* what: Set the character mappings for the streqv functions
*
* arg: + char + From + Input character +
* arg: + char + To + Mapped-to character +
* arg: + char + from + Input character +
* arg: + char + to + Mapped-to character +
* arg: + int + ct + compare length +
*
* doc:
@@ -182,7 +198,7 @@ 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;
@@ -192,14 +208,14 @@ streqvmap(char From, char To, int ct)
}
else {
unsigned int chTo = (int)To & 0xFF;
unsigned int chFrom = (int)From & 0xFF;
unsigned int i_to = (int)to & 0xFF;
unsigned int i_from = (int)from & 0xFF;
do {
charmap[chFrom] = (unsigned char)chTo;
chFrom++;
chTo++;
if ((chFrom >= sizeof(charmap)) || (chTo >= sizeof(charmap)))
charmap[i_from] = (unsigned char)i_to;
i_from++;
i_to++;
if ((i_from >= sizeof(charmap)) || (i_to >= sizeof(charmap)))
break;
} while (--ct > 0);
}
@@ -225,7 +241,7 @@ void
strequate(char const* s)
{
if ((s != NULL) && (*s != NUL)) {
unsigned char equiv = (unsigned)*s;
unsigned char equiv = (unsigned char)*s;
while (*s != NUL)
charmap[ (unsigned)*(s++) ] = equiv;
}
@@ -258,7 +274,8 @@ strtransform(char* d, char const* s)
} while (*(s++) != NUL);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -3,11 +3,13 @@
*
* Map a text file, ensuring the text always has an ending NUL byte.
*
* Time-stamp: "2012-01-29 09:40:21 bkorb"
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -19,11 +21,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#if defined(HAVE_MMAP)
# ifndef MAP_ANONYMOUS
@@ -97,8 +99,7 @@ load_text_file(tmap_info_t * mapinfo, char const * pzFile)
ssize_t rdct = read(mapinfo->txt_fd, pz, sz);
if (rdct <= 0) {
mapinfo->txt_errno = errno;
fprintf(stderr, zFSErrReadFile,
errno, strerror(errno), pzFile);
fserr_warn("libopts", "read", pzFile);
free(mapinfo->txt_data);
return;
}
@@ -113,7 +114,7 @@ load_text_file(tmap_info_t * mapinfo, char const * pzFile)
mapinfo->txt_errno = 0;
#else /* HAVE mmap */
size_t const pgsz = GETPAGESIZE();
size_t const pgsz = (size_t)GETPAGESIZE();
void * map_addr = NULL;
(void)pzFile;
@@ -189,7 +190,7 @@ validate_mmap(char const * fname, int prot, int flags, tmap_info_t * mapinfo)
return;
}
mapinfo->txt_size = sb.st_size;
mapinfo->txt_size = (size_t)sb.st_size;
}
/*
@@ -361,7 +362,8 @@ text_munmap(tmap_info_t * mi)
return mi->txt_errno;
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -2,11 +2,13 @@
/**
* \file time.c
*
* Time-stamp: "2012-01-29 12:52:31 bkorb"
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -18,11 +20,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*=export_func optionTimeVal
@@ -40,6 +42,9 @@ optionTimeVal(tOptions * pOpts, tOptDesc * pOD)
{
time_t val;
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((pOD->fOptState & OPTST_RESET) != 0)
return;
@@ -55,7 +60,7 @@ optionTimeVal(tOptions * pOpts, tOptDesc * pOD)
pOD->fOptState &= ~OPTST_ALLOC_ARG;
}
pOD->optArg.argInt = (unsigned long)val;
pOD->optArg.argInt = (long)val;
}
/*=export_func optionTimeDate
@@ -72,6 +77,9 @@ void
optionTimeDate(tOptions * pOpts, tOptDesc * pOD)
{
#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV)
if (pOpts <= OPTPROC_EMIT_LIMIT)
return;
if ((! HAS_pzPkgDataDir(pOpts)) || (pOpts->pzPkgDataDir == NULL))
goto default_action;
@@ -121,14 +129,15 @@ optionTimeDate(tOptions * pOpts, tOptDesc * pOD)
}
return;
default_action:
default_action:
#endif
optionTimeVal(pOpts, pOD);
if (pOD->optArg.argInt != BAD_TIME)
pOD->optArg.argInt += (unsigned long)time(NULL);
pOD->optArg.argInt += (long)time(NULL);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

View File

@@ -1,10 +1,15 @@
/** \file tokenize.c
*
* Tokenize a string, accommodating quoted strings.
*
* @addtogroup autoopts
* @{
*/
/*
* This file defines the string_tokenize interface
* Time-stamp: "2012-03-04 13:23:50 bkorb"
*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -16,11 +21,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
#include <errno.h>
@@ -145,8 +150,8 @@ alloc_token_list(char const * str)
pz = SPN_WHITESPACE_CHARS(pz);
} while (*pz != NUL);
res = malloc(sizeof(*res) + (pz - str)
+ (max_token_ct * sizeof(ch_t*)));
res = malloc(sizeof(*res) + (size_t)(pz - str)
+ ((size_t)max_token_ct * sizeof(ch_t*)));
}
if (res == NULL)
@@ -324,7 +329,8 @@ main(int argc, char** argv)
}
#endif
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,16 @@
/*
* Time-stamp: "2012-01-29 19:44:24 bkorb"
/** \file version.c
*
* This module implements the default usage procedure for
* Automated Options. It may be overridden, of course.
*
* @addtogroup autoopts
* @{
*/
/*
* This file is part of AutoOpts, a companion to AutoGen.
* AutoOpts is free software.
* AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
* AutoOpts is Copyright (C) 1992-2013 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
@@ -21,11 +22,11 @@
* The Modified Berkeley Software Distribution License
* See the file "COPYING.mbsd"
*
* These files have the following md5sums:
* These files have the following sha256 sums:
*
* 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
* 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
* 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
* 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/
/*=export_func optionVersion
@@ -40,122 +41,128 @@
char const*
optionVersion(void)
{
static char const zVersion[] =
STR(AO_CURRENT.AO_REVISION);
static char const ver[] = OPTIONS_DOTTED_VERSION;
return ver;
}
return zVersion;
static void
emit_first_line(
FILE * fp, char const * alt1, char const * alt2, char const * alt3)
{
char const * p = (alt1 != NULL) ? alt1 : ((alt2 != NULL) ? alt2 : alt3);
char const * e;
if (p == NULL)
return;
e = strchr(p, NL);
if (e == NULL)
fputs(p, fp);
else
fwrite(p, 1, (e - p), fp);
fputc(NL, fp);
}
/**
* Select among various ways to emit version information.
*
* @param pOpts the option descriptor
* @param fp the output stream
* @param[in] o the option descriptor
* @param[in] fp the output stream
*/
static void
emit_simple_ver(tOptions * pOpts, FILE * fp)
emit_simple_ver(tOptions * o, FILE * fp)
{
/*
* Use the supplied string
*/
if (pOpts->pzFullVersion != NULL)
fputs(pOpts->pzFullVersion, fp);
/*
* Extract the interesting part of the copyright string
*/
else if (pOpts->pzCopyright != NULL) {
char const * pe = strchr(pOpts->pzCopyright, NL);
if (pe == NULL)
pe = pOpts->pzCopyright + strlen(pOpts->pzCopyright);
fwrite(pOpts->pzCopyright, 1, pe - pOpts->pzCopyright, fp);
}
/*
* Extract the interesting part of the usage title string
*/
else {
char const * pe = strchr(pOpts->pzUsageTitle, NL);
if (pe == NULL)
pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzUsageTitle, fp);
}
fputc(NL, fp);
emit_first_line(fp, o->pzFullVersion, o->pzCopyright, o->pzUsageTitle);
}
/**
* print the version with a copyright notice.
*
* @param[in] o the option descriptor
* @param[in] fp the output stream
*/
static void
emit_copy_ver(tOptions * pOpts, FILE * fp)
emit_copy_full(tOptions * o, FILE * fp)
{
if (pOpts->pzCopyright != NULL)
fputs(pOpts->pzCopyright, fp);
if (o->pzCopyright != NULL)
fputs(o->pzCopyright, fp);
else if (pOpts->pzFullVersion != NULL)
fputs(pOpts->pzFullVersion, fp);
else if (o->pzFullVersion != NULL)
fputs(o->pzFullVersion, fp);
else {
char const * pe = strchr(pOpts->pzUsageTitle, NL);
if (pe == NULL)
pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp);
else
emit_first_line(fp, o->pzUsageTitle, NULL, NULL);
if (HAS_pzPkgDataDir(o) && (o->pzPackager != NULL)) {
fputc(NL, fp);
fputs(o->pzPackager, fp);
} else if (o->pzBugAddr != NULL) {
fputc(NL, fp);
fprintf(fp, zPlsSendBugs, o->pzBugAddr);
}
}
/**
* print the version and any copyright notice.
* The version with a full copyright and additional notes.
*
* @param[in] opts the option descriptor
* @param[in] fp the output stream
*/
static void
emit_copy_note(tOptions * opts, FILE * fp)
{
if (opts->pzCopyright != NULL)
fputs(opts->pzCopyright, fp);
if (opts->pzCopyNotice != NULL)
fputs(opts->pzCopyNotice, fp);
fputc(NL, fp);
fprintf(fp, zao_ver_fmt, optionVersion());
if (HAS_pzPkgDataDir(opts) && (opts->pzPackager != NULL)) {
fputc(NL, fp);
fputs(opts->pzPackager, fp);
if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL))
fputs(pOpts->pzPackager, fp);
else if (pOpts->pzBugAddr != NULL)
fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr);
} else if (opts->pzBugAddr != NULL) {
fputc(NL, fp);
fprintf(fp, zPlsSendBugs, opts->pzBugAddr);
}
}
/**
* Handle the version printing. We must see how much information
* is being requested and select the correct printing routine.
*/
static void
emit_copy_note(tOptions * pOpts, FILE * fp)
{
if (pOpts->pzCopyright != NULL) {
fputs(pOpts->pzCopyright, fp);
fputc(NL, fp);
}
if (pOpts->pzCopyNotice != NULL) {
fputs(pOpts->pzCopyNotice, fp);
fputc(NL, fp);
}
fprintf(fp, zAO_Ver, optionVersion());
if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL))
fputs(pOpts->pzPackager, fp);
else if (pOpts->pzBugAddr != NULL)
fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr);
}
static void
print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
print_ver(tOptions * opts, tOptDesc * od, FILE * fp)
{
char ch;
if (opts <= OPTPROC_EMIT_LIMIT)
return;
/*
* IF we have an argument for this option, use it
* Otherwise, default to version only or copyright note,
* depending on whether the layout is GNU standard form or not.
*/
if ( (pOD->fOptState & OPTST_ARG_OPTIONAL)
&& (pOD->optArg.argString != NULL)
&& (pOD->optArg.argString[0] != NUL))
if ( (od->fOptState & OPTST_ARG_OPTIONAL)
&& (od->optArg.argString != NULL)
&& (od->optArg.argString[0] != NUL))
ch = pOD->optArg.argString[0];
ch = od->optArg.argString[0];
else {
set_usage_flags(pOpts, NULL);
ch = (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
set_usage_flags(opts, NULL);
ch = (opts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
}
switch (ch) {
case NUL: /* arg provided, but empty */
case 'v': case 'V': emit_simple_ver(pOpts, fp); break;
case 'c': case 'C': emit_copy_ver(pOpts, fp); break;
case 'n': case 'N': emit_copy_note(pOpts, fp); break;
case 'v': case 'V': emit_simple_ver(opts, fp); break;
case 'c': case 'C': emit_copy_full( opts, fp); break;
case 'n': case 'N': emit_copy_note( opts, fp); break;
default:
fprintf(stderr, zBadVerArg, ch);
@@ -163,10 +170,10 @@ print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
}
fflush(fp);
if (ferror(fp) != 0) {
fputs(zOutputFail, stderr);
exit(EXIT_FAILURE);
}
if (ferror(fp))
fserr_exit(opts->pzProgName, zwriting,
(fp == stdout) ? zstdout_name : zstderr_name);
exit(EXIT_SUCCESS);
}
@@ -174,35 +181,36 @@ print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
* private:
*
* what: Print the program version
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + tOptions* + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg +
*
* doc:
* This routine will print the version to stdout.
=*/
void
optionPrintVersion(tOptions * pOpts, tOptDesc * pOD)
optionPrintVersion(tOptions * opts, tOptDesc * od)
{
print_ver(pOpts, pOD, stdout);
print_ver(opts, od, stdout);
}
/*=export_func optionVersionStderr
* private:
*
* what: Print the program version to stderr
* arg: + tOptions* + pOpts + program options descriptor +
* arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
* arg: + tOptions* + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg +
*
* doc:
* This routine will print the version to stderr.
=*/
void
optionVersionStderr(tOptions * pOpts, tOptDesc * pOD)
optionVersionStderr(tOptions * opts, tOptDesc * od)
{
print_ver(pOpts, pOD, stderr);
print_ver(opts, od, stderr);
}
/*
/** @}
*
* Local Variables:
* mode: C
* c-file-style: "stroustrup"