diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-05-05 12:27:49 +0300 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-05-05 12:51:42 +0300 |
commit | c3c3c9b844f7fd4c9fcd19ba19b306d88b75e65a (patch) | |
tree | d9c26136a5b92b368806a3848ff2898d1b43ac25 | |
parent | b3bab6daacff9126b194ca78485fdc7073d05a42 (diff) | |
download | gnutls-c3c3c9b844f7fd4c9fcd19ba19b306d88b75e65a.tar.gz |
updated libopts to autogen 5.17.3
58 files changed, 7402 insertions, 4770 deletions
diff --git a/src/libopts/COPYING.gplv3 b/src/libopts/COPYING.gplv3 index f22cdbb209..e9bf0ffd15 100644 --- a/src/libopts/COPYING.gplv3 +++ b/src/libopts/COPYING.gplv3 @@ -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. diff --git a/src/libopts/COPYING.lgplv3 b/src/libopts/COPYING.lgplv3 index a1bc40ddf8..b8a3768e33 100644 --- a/src/libopts/COPYING.lgplv3 +++ b/src/libopts/COPYING.lgplv3 @@ -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. diff --git a/src/libopts/Makefile.am b/src/libopts/Makefile.am index bb7361342e..550299bfee 100644 --- a/src/libopts/Makefile.am +++ b/src/libopts/Makefile.am @@ -1,31 +1,30 @@ ## LIBOPTS Makefile MAINTAINERCLEANFILES = Makefile.in -if INSTALL_LIBOPTS -lib_LTLIBRARIES = libopts.la -else + noinst_LTLIBRARIES = libopts.la -endif + libopts_la_SOURCES = libopts.c libopts_la_CPPFLAGS = -I$(top_srcdir) libopts_la_LIBADD = $(LTLIBINTL) -libopts_la_LDFLAGS = -version-info 36:4:11 + 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 diff --git a/src/libopts/README b/src/libopts/README index 0d9ac649f6..184473d85a 100644 --- a/src/libopts/README +++ b/src/libopts/README @@ -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 diff --git a/src/libopts/ag-char-map.h b/src/libopts/ag-char-map.h index 33d4fe63ec..ff91b2c928 100644 --- a/src/libopts/ag-char-map.h +++ b/src/libopts/ag-char-map.h @@ -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 */ diff --git a/src/libopts/alias.c b/src/libopts/alias.c index 18a2fd6e1e..d05cc4be9b 100644 --- a/src/libopts/alias.c +++ b/src/libopts/alias.c @@ -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" diff --git a/src/libopts/ao-strs.c b/src/libopts/ao-strs.c index 30bcbe53fa..13a7e4f35b 100644 --- a/src/libopts/ao-strs.c +++ b/src/libopts/ao-strs.c @@ -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,188 +38,193 @@ */ #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" +/* 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" +/* 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" -/* 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" +/* 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" -/* 169 */ "''\0" -/* 172 */ "\\'\0" -/* 175 */ "'%s'\0" -/* 180 */ "%s_%s_%d=\0" -/* 190 */ "\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" +/* 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" - "OPT_PROCESS=true\n" - "OPT_ARG=$1\n" - "while ${OPT_PROCESS} && [ $# -gt 0 ]\n" - "do\n" - " OPT_ELEMENT=''\n" - " OPT_ARG_VAL=''\n\n" - " case \"${OPT_ARG}\" in\n" - " -- )\n" - " 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" +/* 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" - "%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" + "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" -/* 3639 */ " case \"${OPT_ARG_NEEDED}\" in\n" +/* 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" + "do\n" + " OPT_ELEMENT=''\n" + " OPT_ARG_VAL=''\n\n" + " case \"${OPT_ARG}\" in\n" + " -- )\n" + " OPT_PROCESS=false\n" + " shift\n" + " ;;\n\0" +/* 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" - "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" +/* 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" -/* 5834 */ "%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" -/* 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 */ diff --git a/src/libopts/ao-strs.h b/src/libopts/ao-strs.h index 30bbc3bfc5..0ea42ff964 100644 --- a/src/libopts/ao-strs.h +++ b/src/libopts/ao-strs.h @@ -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 */ diff --git a/src/libopts/autoopts.c b/src/libopts/autoopts.c index 1eff7002fa..ff54b1619c 100644 --- a/src/libopts/autoopts.c +++ b/src/libopts/autoopts.c @@ -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" diff --git a/src/libopts/autoopts.h b/src/libopts/autoopts.h index 194ea5a839..67fb86d7d0 100644 --- a/src/libopts/autoopts.h +++ b/src/libopts/autoopts.h @@ -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" diff --git a/src/libopts/autoopts/options.h b/src/libopts/autoopts/options.h index 356e7e9ff5..5bb31fde50 100644 --- a/src/libopts/autoopts/options.h +++ b/src/libopts/autoopts/options.h @@ -1,31 +1,43 @@ /* -*- buffer-read-only: t -*- vi: set ro: - * + * * DO NOT EDIT THIS FILE (options.h) - * - * It has been AutoGen-ed May 6, 2012 at 04:21:03 PM by AutoGen 5.16pre36 + * + * It has been AutoGen-ed March 31, 2013 at 10:41:30 AM by AutoGen 5.17.3 * From the definitions funcs.def * and the template file options_h * * This file defines all the global structures and special values * used in the automated option processing library. * - * Automated Options Copyright (C) 1992-2012 by Bruce Korb - * - * * AutoOpts 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 3 of the License, or - * (at your option) any later version. - * - * AutoOpts 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/>."; + * Automated Options Copyright (C) 1992-2013 by Bruce Korb + * + * 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 AUTOOPTS_OPTIONS_H_GUARD #define AUTOOPTS_OPTIONS_H_GUARD 1 +/** \file options.h + * + * @addtogroup autoopts + * @{ + */ #include <sys/types.h> #include <stdio.h> @@ -64,13 +76,13 @@ // END-CONFIGURED-HEADERS /** - * Defined to normal value of EX_USAGE. Used to indicate that paged usage + * Defined to abnormal value of EX_USAGE. Used to indicate that paged usage * was requested. It is used to distinguish a --usage from a --help request. * --usage is abbreviated and --help gives as much help as possible. */ -#define AO_EXIT_REQ_USAGE 64 +#define AO_EXIT_REQ_USAGE 10064 -/* +/** * PUBLIC DEFINES * * The following defines may be used in applications that need to test the @@ -85,166 +97,208 @@ * * See the relevant generated header file to determine which and what * values for "opt_name" are available. + * @group version + * @{ */ -#define OPTIONS_STRUCT_VERSION 147460 -#define OPTIONS_VERSION_STRING "36:4:11" +/// autoopts structure version +#define OPTIONS_STRUCT_VERSION 155648 +/// autoopts structure version string +#define OPTIONS_VERSION_STRING "38:0:13" +/// minimum version the autoopts library supports #define OPTIONS_MINIMUM_VERSION 102400 +/// minimum version the autoopts library supports as a string #define OPTIONS_MIN_VER_STRING "25:0:0" +/// the display version of the autoopts library, as a string +#define OPTIONS_DOTTED_VERSION "38.0" +/// convert a version/release number pair to an integer value #define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r)) - +/// @} + +/** + * Option argument types. This must fit in the OPTST_ARG_TYPE_MASK + * field of the fOptState field of an option descriptor (tOptDesc). + * It will be a problem to extend beyond 4 bits. + */ typedef enum { - OPARG_TYPE_NONE = 0, - OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ - OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ - OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ - OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ - OPARG_TYPE_NUMERIC = 5, /* opt arg is a long int */ - OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */ - OPARG_TYPE_FILE = 7, /* option arg names a file */ - OPARG_TYPE_TIME = 8, /* opt arg is a time duration */ - OPARG_TYPE_FLOAT = 9, /* opt arg is a floating point num */ - OPARG_TYPE_DOUBLE = 10, /* opt arg is a double prec. float */ - OPARG_TYPE_LONG_DOUBLE = 11, /* opt arg is a long double prec. */ - OPARG_TYPE_LONG_LONG = 12 /* opt arg is a long long int */ + OPARG_TYPE_NONE = 0, ///< does not take an argument + OPARG_TYPE_STRING = 1, ///< default type/ vanilla string + OPARG_TYPE_ENUMERATION = 2, ///< opt arg is an enum (keyword list) + OPARG_TYPE_BOOLEAN = 3, ///< opt arg is boolean-valued + OPARG_TYPE_MEMBERSHIP = 4, ///< opt arg sets set membership bits + OPARG_TYPE_NUMERIC = 5, ///< opt arg is a long int + OPARG_TYPE_HIERARCHY = 6, ///< option arg is hierarchical value + OPARG_TYPE_FILE = 7, ///< option arg names a file + OPARG_TYPE_TIME = 8, ///< opt arg is a time duration + OPARG_TYPE_FLOAT = 9, ///< opt arg is a floating point num + OPARG_TYPE_DOUBLE = 10, ///< opt arg is a double prec. float + OPARG_TYPE_LONG_DOUBLE = 11, ///< opt arg is a long double prec. + OPARG_TYPE_LONG_LONG = 12 ///< opt arg is a long long int } teOptArgType; +/** + * value descriptor for sub options + */ typedef struct optionValue { - teOptArgType valType; - char* pzName; + teOptArgType valType; ///< which argument type + char * pzName; ///< name of the sub-option union { - char strVal[1]; /* OPARG_TYPE_STRING */ - unsigned int enumVal; /* OPARG_TYPE_ENUMERATION */ - unsigned int boolVal; /* OPARG_TYPE_BOOLEAN */ - unsigned long setVal; /* OPARG_TYPE_MEMBERSHIP */ - long longVal; /* OPARG_TYPE_NUMERIC */ - void* nestVal; /* OPARG_TYPE_HIERARCHY */ + char strVal[1]; ///< OPARG_TYPE_STRING + unsigned int enumVal; ///< OPARG_TYPE_ENUMERATION + unsigned int boolVal; ///< OPARG_TYPE_BOOLEAN + unsigned long setVal; ///< OPARG_TYPE_MEMBERSHIP + long longVal; ///< OPARG_TYPE_NUMERIC + void* nestVal; ///< OPARG_TYPE_HIERARCHY } v; } tOptionValue; +/** + * file argument state and handling. + */ typedef enum { - FTYPE_MODE_MAY_EXIST = 0x00, - FTYPE_MODE_MUST_EXIST = 0x01, - FTYPE_MODE_MUST_NOT_EXIST = 0x02, - FTYPE_MODE_EXIST_MASK = 0x03, - FTYPE_MODE_NO_OPEN = 0x00, - FTYPE_MODE_OPEN_FD = 0x10, - FTYPE_MODE_FOPEN_FP = 0x20, - FTYPE_MODE_OPEN_MASK = 0x30 + FTYPE_MODE_MAY_EXIST = 0x00, ///< may or may not exist + FTYPE_MODE_MUST_EXIST = 0x01, ///< must pre-exist + FTYPE_MODE_MUST_NOT_EXIST = 0x02, ///< must *not* pre-exist + FTYPE_MODE_EXIST_MASK = 0x03, ///< mask for these bits + FTYPE_MODE_NO_OPEN = 0x00, ///< leave file closed + FTYPE_MODE_OPEN_FD = 0x10, ///< call open(2) + FTYPE_MODE_FOPEN_FP = 0x20, ///< call fopen(3) + FTYPE_MODE_OPEN_MASK = 0x30 ///< open/fopen/not open } teOptFileType; +/** + * the open flag bits or the mode string, depending on the open type. + */ typedef union { - int file_flags; - char const * file_mode; + int file_flags; ///< open(2) flag bits + char const * file_mode; ///< fopen(3) mode string } tuFileMode; -typedef struct argList tArgList; +/// initial number of option argument holders to allocate #define MIN_ARG_ALLOC_CT 6 -#define INCR_ARG_ALLOC_CT 8 -struct argList { - int useCt; +/// amount by which to increment the argument holder allocation. +#define INCR_ARG_ALLOC_CT 8 +/** + * an argument list. When an option appears multiple times and + * the values get "stacked". \a apzArgs holds 8 pointers initially + * and is incremented by \a INCR_ARG_ALLOC_CT as needed. + */ +typedef struct { + int useCt; ///< elements in use + + /// allocated elements, mininum \a MIN_ARG_ALLOC_CT + /// steps by \a INCR_ARG_ALLOC_CT int allocCt; - char const * apzArgs[MIN_ARG_ALLOC_CT]; -}; + char const * apzArgs[MIN_ARG_ALLOC_CT]; ///< element array +} tArgList; -/* +/** * Bits in the fOptState option descriptor field. + * @{ */ -typedef enum { - OPTST_SET_ID = 0, /* Set via the "SET_OPT()" macro */ - OPTST_PRESET_ID = 1, /* Set via an RC/INI file */ - OPTST_DEFINED_ID = 2, /* Set via a command line option */ - OPTST_RESET_ID = 3, /* Reset via command line option */ - OPTST_EQUIVALENCE_ID = 4, /* selected by equiv'ed option */ - OPTST_DISABLED_ID = 5, /* option is in disabled state */ - OPTST_ALLOC_ARG_ID = 6, /* pzOptArg was allocated */ - OPTST_NO_INIT_ID = 8, /* option cannot be preset */ - OPTST_NUMBER_OPT_ID = 9, /* opt value (flag) is any digit */ - OPTST_STACKED_ID = 10, /* opt uses optionStackArg proc */ - OPTST_INITENABLED_ID = 11, /* option defaults to enabled */ - OPTST_ARG_TYPE_1_ID = 12, /* bit 1 of arg type enum */ - OPTST_ARG_TYPE_2_ID = 13, /* bit 2 of arg type enum */ - OPTST_ARG_TYPE_3_ID = 14, /* bit 3 of arg type enum */ - OPTST_ARG_TYPE_4_ID = 15, /* bit 4 of arg type enum */ - OPTST_ARG_OPTIONAL_ID = 16, /* the option arg not required */ - OPTST_IMM_ID = 17, /* process opt on first pass */ - OPTST_DISABLE_IMM_ID = 18, /* process disablement immed. */ - OPTST_OMITTED_ID = 19, /* compiled out of program */ - OPTST_MUST_SET_ID = 20, /* must be set or pre-set */ - OPTST_DOCUMENT_ID = 21, /* opt is for doc only */ - OPTST_TWICE_ID = 22, /* process opt twice - imm + reg */ - OPTST_DISABLE_TWICE_ID = 23, /* process disabled option twice */ - OPTST_SCALED_NUM_ID = 24, /* scaled integer value */ - OPTST_NO_COMMAND_ID = 25, /* disable from cmd line */ - OPTST_DEPRECATED_ID = 26, /* support is being removed */ - OPTST_ALIAS_ID = 27 /* alias for other option */ -} opt_state_enum_t; - -#define OPTST_INIT 0U -#define OPTST_SET (1U << OPTST_SET_ID) -#define OPTST_PRESET (1U << OPTST_PRESET_ID) -#define OPTST_DEFINED (1U << OPTST_DEFINED_ID) -#define OPTST_RESET (1U << OPTST_RESET_ID) -#define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID) -#define OPTST_DISABLED (1U << OPTST_DISABLED_ID) -#define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID) -#define OPTST_NO_INIT (1U << OPTST_NO_INIT_ID) -#define OPTST_NUMBER_OPT (1U << OPTST_NUMBER_OPT_ID) -#define OPTST_STACKED (1U << OPTST_STACKED_ID) -#define OPTST_INITENABLED (1U << OPTST_INITENABLED_ID) -#define OPTST_ARG_TYPE_1 (1U << OPTST_ARG_TYPE_1_ID) -#define OPTST_ARG_TYPE_2 (1U << OPTST_ARG_TYPE_2_ID) -#define OPTST_ARG_TYPE_3 (1U << OPTST_ARG_TYPE_3_ID) -#define OPTST_ARG_TYPE_4 (1U << OPTST_ARG_TYPE_4_ID) -#define OPTST_ARG_OPTIONAL (1U << OPTST_ARG_OPTIONAL_ID) -#define OPTST_IMM (1U << OPTST_IMM_ID) -#define OPTST_DISABLE_IMM (1U << OPTST_DISABLE_IMM_ID) -#define OPTST_OMITTED (1U << OPTST_OMITTED_ID) -#define OPTST_MUST_SET (1U << OPTST_MUST_SET_ID) -#define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID) -#define OPTST_TWICE (1U << OPTST_TWICE_ID) -#define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID) -#define OPTST_SCALED_NUM (1U << OPTST_SCALED_NUM_ID) -#define OPTST_NO_COMMAND (1U << OPTST_NO_COMMAND_ID) -#define OPTST_DEPRECATED (1U << OPTST_DEPRECATED_ID) -#define OPTST_ALIAS (1U << OPTST_ALIAS_ID) -#define OPT_STATE_MASK 0x0FFFFF7FU - -#define OPTST_SET_MASK ( \ - OPTST_DEFINED | OPTST_PRESET | OPTST_RESET | \ - OPTST_SET \ - /* 0x0000000FU */ ) - -#define OPTST_MUTABLE_MASK ( \ - OPTST_ALLOC_ARG | OPTST_DEFINED | \ - OPTST_DISABLED | OPTST_EQUIVALENCE | \ - OPTST_PRESET | OPTST_RESET | \ - OPTST_SET \ - /* 0x0000007FU */ ) - -#define OPTST_SELECTED_MASK ( \ - OPTST_DEFINED | OPTST_SET \ - /* 0x00000005U */ ) - -#define OPTST_ARG_TYPE_MASK ( \ - OPTST_ARG_TYPE_1 | OPTST_ARG_TYPE_2 | OPTST_ARG_TYPE_3 | \ - OPTST_ARG_TYPE_4 \ - /* 0x0000F000U */ ) - -#define OPTST_NO_USAGE_MASK ( \ - OPTST_DEPRECATED | OPTST_NO_COMMAND | OPTST_OMITTED \ - /* 0x06080000U */ ) - -#define OPTST_IMMUTABLE_MASK ( \ - OPTST_DOCUMENT | OPTST_OMITTED \ - /* 0x00280000U */ ) - -#define OPTST_DO_NOT_SAVE_MASK ( \ - OPTST_DOCUMENT | OPTST_NO_INIT | OPTST_OMITTED \ - /* 0x00280100U */ ) - -#define OPTST_NO_OUTPUT_MASK ( \ - OPTST_ALIAS | OPTST_DOCUMENT | OPTST_OMITTED \ - /* 0x08280000U */ ) + +/** integral type for holding opt_state masks */ +typedef uint32_t opt_state_mask_t; + +#define OPTST_ARG_TYPE_SHIFT 12 +/** bits defined for opt_state_mask_t */ +/** opt_state_mask_t - Set via the "SET_OPT()" macro */ +#define OPTST_SET 0x0000001U +/** opt_state_mask_t - Set via an RC/INI file */ +#define OPTST_PRESET 0x0000002U +/** opt_state_mask_t - Set via a command line option */ +#define OPTST_DEFINED 0x0000004U +/** opt_state_mask_t - Reset via command line option */ +#define OPTST_RESET 0x0000008U +/** opt_state_mask_t - selected by equiv'ed option */ +#define OPTST_EQUIVALENCE 0x0000010U +/** opt_state_mask_t - option is in disabled state */ +#define OPTST_DISABLED 0x0000020U +/** opt_state_mask_t - pzOptArg was allocated */ +#define OPTST_ALLOC_ARG 0x0000040U +/** opt_state_mask_t - option cannot be preset */ +#define OPTST_NO_INIT 0x0000100U +/** opt_state_mask_t - opt value (flag) is any digit */ +#define OPTST_NUMBER_OPT 0x0000200U +/** opt_state_mask_t - opt uses optionStackArg proc */ +#define OPTST_STACKED 0x0000400U +/** opt_state_mask_t - option defaults to enabled */ +#define OPTST_INITENABLED 0x0000800U +/** opt_state_mask_t - bit 1 of arg type enum */ +#define OPTST_ARG_TYPE_1 0x0001000U +/** opt_state_mask_t - bit 2 of arg type enum */ +#define OPTST_ARG_TYPE_2 0x0002000U +/** opt_state_mask_t - bit 3 of arg type enum */ +#define OPTST_ARG_TYPE_3 0x0004000U +/** opt_state_mask_t - bit 4 of arg type enum */ +#define OPTST_ARG_TYPE_4 0x0008000U +/** opt_state_mask_t - the option arg not required */ +#define OPTST_ARG_OPTIONAL 0x0010000U +/** opt_state_mask_t - process opt on first pass */ +#define OPTST_IMM 0x0020000U +/** opt_state_mask_t - process disablement immed. */ +#define OPTST_DISABLE_IMM 0x0040000U +/** opt_state_mask_t - compiled out of program */ +#define OPTST_OMITTED 0x0080000U +/** opt_state_mask_t - must be set or pre-set */ +#define OPTST_MUST_SET 0x0100000U +/** opt_state_mask_t - opt is for doc only */ +#define OPTST_DOCUMENT 0x0200000U +/** opt_state_mask_t - process opt twice - imm + reg */ +#define OPTST_TWICE 0x0400000U +/** opt_state_mask_t - process disabled option twice */ +#define OPTST_DISABLE_TWICE 0x0800000U +/** opt_state_mask_t - scaled integer value */ +#define OPTST_SCALED_NUM 0x1000000U +/** opt_state_mask_t - disable from cmd line */ +#define OPTST_NO_COMMAND 0x2000000U +/** opt_state_mask_t - support is being removed */ +#define OPTST_DEPRECATED 0x4000000U +/** opt_state_mask_t - alias for other option */ +#define OPTST_ALIAS 0x8000000U + +/** bits in SET mask: + * set preset reset defined */ +#define OPTST_SET_MASK 0x000000FU + +/** bits in MUTABLE mask: + * set preset reset defined equivalence disabled + * alloc_arg */ +#define OPTST_MUTABLE_MASK 0x000007FU + +/** bits omitted from PERSISTENT mask: + * mutable_mask */ +#define OPTST_PERSISTENT_MASK 0xFFFFF00U + +/** bits in SELECTED mask: + * set defined */ +#define OPTST_SELECTED_MASK 0x0000005U + +/** bits in ARG_TYPE mask: + * arg_type_1 arg_type_2 arg_type_3 arg_type_4 */ +#define OPTST_ARG_TYPE_MASK 0x000F000U + +/** bits in NO_USAGE mask: + * omitted no_command deprecated */ +#define OPTST_NO_USAGE_MASK 0x6080000U + +/** bits in IMMUTABLE mask: + * document omitted */ +#define OPTST_IMMUTABLE_MASK 0x0280000U + +/** bits in DO_NOT_SAVE mask: + * document omitted no_init */ +#define OPTST_DO_NOT_SAVE_MASK 0x0280100U + +/** bits in NO_OUTPUT mask: + * document omitted alias */ +#define OPTST_NO_OUTPUT_MASK 0x8280000U + +/** all bits in opt_state_mask_t masks */ +#define OPTST_MASK_ALL 0xFFFFF7FU + +/** no bits in opt_state_mask_t */ +#define OPTST_INIT 0x0000000U +/** @} */ #ifdef NO_OPTIONAL_OPT_ARGS # undef OPTST_ARG_OPTIONAL @@ -253,16 +307,16 @@ typedef enum { #define VENDOR_OPTION_VALUE 'W' -#define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK) - #define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK) #define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0) #define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED) #define OPTION_STATE(_od) ((_od)->fOptState) -#define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_1_ID) -#define OPTST_GET_ARGTYPE(_f) (((_f)&OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID) +#define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_SHIFT) +#define OPTST_GET_ARGTYPE(_f) \ + (((_f)&OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT) -/* +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * PRIVATE INTERFACES * * The following values are used in the generated code to communicate @@ -270,243 +324,370 @@ typedef enum { * and may be subject to change. */ -/* +/** * Define the processing state flags + * @{ */ -typedef enum { - OPTPROC_LONGOPT_ID = 0, /* Process long style options */ - OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */ - OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */ - OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */ - OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */ - OPTPROC_NUM_OPT_ID = 5, /* there is a number option */ - OPTPROC_INITDONE_ID = 6, /* have inits been done? */ - OPTPROC_NEGATIONS_ID = 7, /* any negation options? */ - OPTPROC_ENVIRON_ID = 8, /* check environment? */ - OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */ - OPTPROC_ARGS_REQ_ID = 10, /* Require args after options */ - OPTPROC_REORDER_ID = 11, /* reorder operands after opts */ - OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */ - OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */ - OPTPROC_MISUSE_ID = 14, /* no usage on usage error */ - OPTPROC_IMMEDIATE_ID = 15, /* immediate options active */ - OPTPROC_NXLAT_OPT_CFG_ID = 16, /* suppress for config only */ - OPTPROC_NXLAT_OPT_ID = 17, /* suppress xlation always */ - OPTPROC_VENDOR_OPT_ID = 18, /* vendor options active */ - OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */ -} optproc_state_enum_t; - -#define OPTPROC_NONE 0U -#define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID) -#define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID) -#define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID) -#define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID) -#define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID) -#define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID) -#define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID) -#define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID) -#define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID) -#define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID) -#define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID) -#define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID) -#define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID) -#define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID) -#define OPTPROC_MISUSE (1U << OPTPROC_MISUSE_ID) -#define OPTPROC_IMMEDIATE (1U << OPTPROC_IMMEDIATE_ID) -#define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID) -#define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID) -#define OPTPROC_VENDOR_OPT (1U << OPTPROC_VENDOR_OPT_ID) -#define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID) -#define OPTPROC_STATE_MASK 0x000FFFFFU - -#define OPTPROC_NO_XLAT_MASK ( \ - OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \ - /* 0x00030000U */ ) + +/** integral type for holding proc_state masks */ +typedef uint32_t proc_state_mask_t; + +/** bits defined for proc_state_mask_t */ +/** proc_state_mask_t - Process long style options */ +#define OPTPROC_LONGOPT 0x000001U +/** proc_state_mask_t - Process short style "flags" */ +#define OPTPROC_SHORTOPT 0x000002U +/** proc_state_mask_t - Stop on argument errors */ +#define OPTPROC_ERRSTOP 0x000004U +/** proc_state_mask_t - Current option is disabled */ +#define OPTPROC_DISABLEDOPT 0x000008U +/** proc_state_mask_t - no options are required */ +#define OPTPROC_NO_REQ_OPT 0x000010U +/** proc_state_mask_t - there is a number option */ +#define OPTPROC_NUM_OPT 0x000020U +/** proc_state_mask_t - have inits been done? */ +#define OPTPROC_INITDONE 0x000040U +/** proc_state_mask_t - any negation options? */ +#define OPTPROC_NEGATIONS 0x000080U +/** proc_state_mask_t - check environment? */ +#define OPTPROC_ENVIRON 0x000100U +/** proc_state_mask_t - Disallow remaining arguments */ +#define OPTPROC_NO_ARGS 0x000200U +/** proc_state_mask_t - Require args after options */ +#define OPTPROC_ARGS_REQ 0x000400U +/** proc_state_mask_t - reorder operands after opts */ +#define OPTPROC_REORDER 0x000800U +/** proc_state_mask_t - emit usage in GNU style */ +#define OPTPROC_GNUUSAGE 0x001000U +/** proc_state_mask_t - Translate strings in tOptions */ +#define OPTPROC_TRANSLATE 0x002000U +/** proc_state_mask_t - no usage on usage error */ +#define OPTPROC_MISUSE 0x004000U +/** proc_state_mask_t - immediate options active */ +#define OPTPROC_IMMEDIATE 0x008000U +/** proc_state_mask_t - suppress for config only */ +#define OPTPROC_NXLAT_OPT_CFG 0x010000U +/** proc_state_mask_t - suppress xlation always */ +#define OPTPROC_NXLAT_OPT 0x020000U +/** proc_state_mask_t - vendor options active */ +#define OPTPROC_VENDOR_OPT 0x040000U +/** proc_state_mask_t - opt processing in preset state */ +#define OPTPROC_PRESETTING 0x080000U +/** proc_state_mask_t - Ignore pzFullUsage, compute usage text */ +#define OPTPROC_COMPUTE 0x100000U + +/** bits in NO_XLAT mask: + * nxlat_opt_cfg nxlat_opt */ +#define OPTPROC_NO_XLAT_MASK 0x030000U + +/** all bits in proc_state_mask_t masks */ +#define OPTPROC_MASK_ALL 0x1FFFFFU + +/** no bits in proc_state_mask_t */ +#define OPTPROC_NONE 0x000000U +/** @} */ #define STMTS(s) do { s; } while (false) -/* - * The following must be #defined instead of typedef-ed - * because "static const" cannot both be applied to a type, - * tho each individually can...so they all are +/** + * Abbreviation for const memory character. */ -#define tSCC static char const #define tCC char const -#define tAoSC static char -#define tAoUC unsigned char -#define tAoUI unsigned int -#define tAoUL unsigned long -#define tAoUS unsigned short -/* - * It is so disgusting that there must be so many ways - * of specifying TRUE and FALSE. +/** + * Magical values for the program's option pointer + * @{ */ -typedef enum { AG_FALSE = 0, AG_TRUE } ag_bool; +typedef enum { + OP_VAL_EMIT_USAGE = 1, ///< request for usage + OP_VAL_EMIT_SHELL = 2, ///< emit value for Bourne shell evaluation + OP_VAL_RETURN_VALNAME = 3, ///< return the value as a string + OP_VAL_EMIT_LIMIT = 15 ///< limit for magic values +} opt_proc_vals_t; -/* - * Define a structure that describes each option and - * a pointer to the procedure that handles it. - * The argument is the count of this flag previously seen. +/// \a OPT_VAL_EMIT_USAGE cast as a pointer +#define OPTPROC_EMIT_USAGE ((tOptions *)OP_VAL_EMIT_USAGE) + +/// \a OPT_VAL_EMIT_SHELL cast as a pointer +#define OPTPROC_EMIT_SHELL ((tOptions *)OP_VAL_EMIT_SHELL) + +/// \a OPT_VAL_RETURN_VALNAME cast as a pointer +#define OPTPROC_RETURN_VALNAME ((tOptions *)OP_VAL_RETURN_VALNAME) + +/// \a OPT_VAL_EMIT_LIMIT cast as a pointer +#define OPTPROC_EMIT_LIMIT ((tOptions *)OP_VAL_EMIT_LIMIT) +/** @} */ + +/** group option processing procedure types + * @{ */ +/** forward declaration for tOptDesc */ +typedef struct opt_desc tOptDesc; +/** forward declaration for tOptiond */ typedef struct options tOptions; -typedef struct optDesc tOptDesc; -typedef struct optNames tOptNames; -#define OPTPROC_EMIT_USAGE ((tOptions *)0x01UL) -#define OPTPROC_EMIT_SHELL ((tOptions *)0x02UL) -#define OPTPROC_RETURN_VALNAME ((tOptions *)0x03UL) -#define OPTPROC_EMIT_LIMIT ((tOptions *)0x0FUL) -/* +/** * The option procedures do the special processing for each * option flag that needs it. */ -typedef void (tOptProc)(tOptions* pOpts, tOptDesc* pOptDesc); -typedef tOptProc* tpOptProc; +typedef void (tOptProc)(tOptions * pOpts, tOptDesc * pOptDesc); -/* +/** + * a pointer to an option processing procedure + */ +typedef tOptProc * tpOptProc; + +/** * The usage procedure will never return. It calls "exit(2)" * with the "exitCode" argument passed to it. */ // coverity[+kill] typedef void (tUsageProc)(tOptions* pOpts, int exitCode); + +/** + * a pointer to a procedure that prints usage and exits. + */ typedef tUsageProc * tpUsageProc; +/** @} */ -/* +/** * Special definitions. "NOLIMIT" is the 'max' value to use when * a flag may appear multiple times without limit. "NO_EQUIVALENT" * is an illegal value for 'optIndex' (option description index). + * @{ */ -#define NOLIMIT USHRT_MAX -#define OPTION_LIMIT SHRT_MAX +#define NOLIMIT USHRT_MAX ///< no occurrance count limit +#define OPTION_LIMIT SHRT_MAX ///< maximum number of option types +/// option index to indicate no equivalance or alias #define NO_EQUIVALENT (OPTION_LIMIT+1) +/** @} */ +/** + * Option argument value. Which is valid is determined by: + * (fOptState & OPTST_ARG_TYPE_MASK) >> OPTST_ARG_TYPE_SHIFT + * which will yield one of the teOptArgType values. + */ typedef union { - char const * argString; - uintptr_t argEnum; - uintptr_t argIntptr; - long argInt; - unsigned long argUint; - unsigned int argBool; - FILE * argFp; - int argFd; -} optArgBucket_t; - -#define pzLastArg optArg.argString + char const * argString; ///< as a string + uintptr_t argEnum; ///< as an enumeration value + uintptr_t argIntptr; ///< as an integer big enough to hold pointer + long argInt; ///< as a long integer + unsigned long argUint; ///< as an unsigned long ingeger + unsigned int argBool; ///< as a boolean value + FILE * argFp; ///< as a FILE * pointer + int argFd; ///< as a file descriptor (int) +} opt_arg_union_t; + +/// Compatibility define: \a pzLastArg is now \a optArg.argString +#define pzLastArg optArg.argString +/// The old amorphous argument bucket is now the opt_arg_union_t union. +#define optArgBucket_t opt_arg_union_t -/* +/** + * Enumeration of AutoOpts defined options. The enumeration is used in + * marking each option that is defined by AutoOpts so libopts can find + * the correct descriptor. This renders \a option_spec_idx_t redundant. + */ +typedef enum { + AOUSE_USER_DEFINED = 0, ///< user specified option + AOUSE_RESET_OPTION, ///< reset option state option + AOUSE_VERSION, ///< request version + AOUSE_HELP, ///< request usage help + AOUSE_MORE_HELP, ///< request paged usage + AOUSE_USAGE, ///< request short usage + AOUSE_SAVE_OPTS, ///< save option state + AOUSE_LOAD_OPTS, ///< load options from file + AOUSE_VENDOR_OPT ///< specify a vendor option +} opt_usage_t; + +/** * Descriptor structure for each option. * Only the fields marked "PUBLIC" are for public use. */ -struct optDesc { - tAoUS const optIndex; /* PUBLIC */ - tAoUS const optValue; /* PUBLIC */ - tAoUS optActualIndex; /* PUBLIC */ - tAoUS optActualValue; /* PUBLIC */ - - tAoUS const optEquivIndex; /* PUBLIC */ - tAoUS const optMinCt; - tAoUS const optMaxCt; - tAoUS optOccCt; /* PUBLIC */ - - tAoUI fOptState; /* PUBLIC */ - tAoUI reserved; - optArgBucket_t optArg; /* PUBLIC */ - void* optCookie; /* PUBLIC */ - - int const * const pOptMust; - int const * const pOptCant; - tpOptProc const pOptProc; - char const* const pzText; - - char const* const pz_NAME; - char const* const pz_Name; - char const* const pz_DisableName; - char const* const pz_DisablePfx; +struct opt_desc { + /// Public, the index of this descriptor + uint16_t const optIndex; + /// Public, the flag character (value) + uint16_t const optValue; + /// Public, the index of the option used to activate option + uint16_t optActualIndex; + /// Public, the flag character of the activating option + uint16_t optActualValue; + + /// Public, the index of the equivalenced-to option. + /// This is NO_EQUIVALENT unless activated. + uint16_t const optEquivIndex; + /// Private, the minimum occurrance count + uint16_t const optMinCt; + /// Private, the maximum occurrance count (NOLIMIT, if unlimited) + uint16_t const optMaxCt; + /// Public, the actual occurrance count + uint16_t optOccCt; + + /// Public, the option processing state + opt_state_mask_t fOptState; + /// Private, how the option is used (opt_usage_t) + uint32_t optUsage; + /// Public, The current option argument value + opt_arg_union_t optArg; + /// Public, data that is actually private to the code that handles + /// this particular option. It is public IFF you have your own + /// handling function. + void * optCookie; + + /// Private, a list of options that must be specified when this option + /// has been specified + int const * const pOptMust; + + /// Private, a list of options that cannot be specified when this option + /// has been specified + int const * const pOptCant; + + /// Private, the function to call for handling this option + tpOptProc const pOptProc; + + /// Private, usage information about this option + char const * const pzText; + + /// Public, the UPPER CASE, shell variable name syntax name of the option + char const * const pz_NAME; + + /// the unmodified name of the option + char const * const pz_Name; + + /// the option name to use to disable the option. Long options names + /// must be active. + char const * const pz_DisableName; + + /// the special prefix that makes the normal option name become the + /// disablement name. + char const * const pz_DisablePfx; }; -/* +/** * Some options need special processing, so we store their - * indexes in a known place: + * indexes in a known place. */ -typedef struct optSpecIndex tOptSpecIndex; -struct optSpecIndex { - const tAoUS more_help; - const tAoUS save_opts; - const tAoUS number_option; - const tAoUS default_opt; -}; +typedef struct { + uint16_t const more_help; ///< passes help text through pager + uint16_t const save_opts; ///< stores option state to a file + uint16_t const number_option; ///< the option "name" is an integer + /// all arguments are options, this is the default option that must + /// take an argument. That argument is the unrecognized option. + uint16_t const default_opt; +} option_spec_idx_t; -/* +/** * The procedure generated for translating option text */ typedef void (tOptionXlateProc)(void); -/* +/** * Everything marked "PUBLIC" is also marked "const". Public access is not * a license to modify. Other fields are used and modified by the library. * They are also subject to change without any notice. * Do not even look at these outside of libopts. */ struct options { - int const structVersion; - unsigned int origArgCt; - char** origArgVect; - unsigned int fOptSet; - unsigned int curOptIdx; - char* pzCurOpt; - - char const* const pzProgPath; /* PUBLIC */ - char const* const pzProgName; /* PUBLIC */ - char const* const pzPROGNAME; /* PUBLIC */ - char const* const pzRcName; /* PUBLIC */ - char const* const pzCopyright; /* PUBLIC */ - char const* const pzCopyNotice; /* PUBLIC */ - char const* const pzFullVersion; /* PUBLIC */ - char const* const* const papzHomeList; - char const* const pzUsageTitle; - char const* const pzExplain; - char const* const pzDetail; - tOptDesc* const pOptDesc; /* PUBLIC */ - char const* const pzBugAddr; /* PUBLIC */ - - void* pExtensions; - void* pSavedState; - + int const structVersion; ///< The version of this struct + unsigned int origArgCt; ///< program argument count + char ** origArgVect; ///< program argument vector + proc_state_mask_t fOptSet; ///< option proc. state flags + unsigned int curOptIdx; ///< current option index + char * pzCurOpt; ///< current option text + + /// Public, the full path of the program + char const * const pzProgPath; + /// Public, the name of the executable, without any path + char const * const pzProgName; + /// Public, the upper-cased, shell variable syntax-ed program name + char const * const pzPROGNAME; + /// the name of the "rc file" (configuration file) + char const * const pzRcName; + /// the copyright text + char const * const pzCopyright; + /// the full copyright notice + char const * const pzCopyNotice; + /// a string with the program name, project name and version + char const * const pzFullVersion; + /// a list of pointers to directories to search for the config file + char const * const * const papzHomeList; + /// the title line for usage + char const * const pzUsageTitle; + /// some added explanation for what this program is trying to do + char const * const pzExplain; + /// a detailed explanation of the program's purpose, for use when + /// full help has been requested + char const * const pzDetail; + /// The public array of option descriptors + tOptDesc * const pOptDesc; + /// the email address for reporting bugs + char const * const pzBugAddr; + + /// Reserved for future use + void * pExtensions; + /// A copy of the option state when optionSaveState was called. + void * pSavedState; + + /// The procedure to call to print usage text // coverity[+kill] - tpUsageProc pUsageProc; - tOptionXlateProc* pTransProc; - - tOptSpecIndex specOptIdx; - int const optCt; - int const presetOptCt; - char const * pzFullUsage; - char const * pzShortUsage; - /* PUBLIC: */ - optArgBucket_t const * const originalOptArgArray; - void * const * const originalOptArgCookie; - char const * const pzPkgDataDir; - char const * const pzPackager; + tpUsageProc pUsageProc; + /// The procedure to call to translate translatable option messages + tOptionXlateProc * pTransProc; + + /// Special option indexes. + option_spec_idx_t specOptIdx; + /// the total number of options for the program + int const optCt; + /// The number of "presettable" options, though some may be marked + /// "no-preset". Includes all user specified options, plus a few + /// that are specified by AutoOpts. + int const presetOptCt; + /// user specified full usage text + char const * pzFullUsage; + /// user specifed short usage (usage error triggered) message + char const * pzShortUsage; + /// The option argument settings active when optionSaveState was called + opt_arg_union_t const * const originalOptArgArray; + /// any saved cookie value + void * const * const originalOptArgCookie; + /// the package data directory (e.g. global configuration files) + char const * const pzPkgDataDir; + /// email address of the project packager + char const * const pzPackager; }; /* * Versions where in various fields first appear: * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero) */ -#define originalOptArgArray_STRUCT_VERSION 131072 /* AO_CURRENT = 32 */ +/** + * The version that first stored the original argument vector + */ +#define originalOptArgArray_STRUCT_VERSION 0x20000 /* AO_CURRENT = 32 */ #define HAS_originalOptArgArray(_opt) \ ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION) -#define pzPkgDataDir_STRUCT_VERSION 139264 /* AO_CURRENT = 34 */ +/** + * The version that first stored the package data directory + */ +#define pzPkgDataDir_STRUCT_VERSION 0x22000 /* AO_CURRENT = 34 */ #define HAS_pzPkgDataDir(_opt) \ ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION) -/* +/** + * The version that first stored the option usage in each option descriptor + */ +#define opt_usage_t_STRUCT_VERSION 0x26000 /* AO_CURRENT = 38 */ +#define HAS_opt_usage_t(_opt) \ + ((_opt)->structVersion >= opt_usage_t_STRUCT_VERSION) + +/** * "token list" structure returned by "string_tokenize()" */ typedef struct { - unsigned long tkn_ct; - unsigned char* tkn_list[1]; + unsigned long tkn_ct; ///< number of tokens found + unsigned char* tkn_list[1]; ///< array of pointers to tokens } token_list_t; /* @@ -531,16 +712,19 @@ typedef struct { * is not zero, then there *may* not be a terminating NUL. */ typedef struct { - void * txt_data; /*@< text file data */ - size_t txt_size; /*@< actual file size */ - size_t txt_full_size; /*@< mmaped mem size */ - int txt_fd; /*@< file descriptor */ - int txt_zero_fd; /*@< fd for /dev/zero */ - int txt_errno; /*@< warning code */ - int txt_prot; /*@< "prot" flags */ - int txt_flags; /*@< mapping type */ + void * txt_data; ///< text file data + size_t txt_size; ///< actual file size + size_t txt_full_size; ///< mmaped mem size + int txt_fd; ///< file descriptor + int txt_zero_fd; ///< fd for /dev/zero + int txt_errno; ///< warning code + int txt_prot; ///< "prot" flags + int txt_flags; ///< mapping type } tmap_info_t; +/** + * mmap result wrapper that yields "true" when mmap has failed. + */ #define TEXT_MMAP_FAILED_ADDR(a) ((void*)(a) == (void*)MAP_FAILED) #ifdef __cplusplus @@ -551,29 +735,23 @@ CPLUSPLUS_OPENER #define CPLUSPLUS_CLOSER #endif -/* +/** * The following routines may be coded into AutoOpts client code: */ -/* From: tokenize.c line 164 - * +/** * ao_string_tokenize - tokenize an input string * - * Arguments: - * string string to be tokenized - * - * Returns: token_list_t* - pointer to a structure that lists each token - * * This function will convert one input string into a list of strings. * The list of strings is derived by separating the input based on * white space separation. However, if the input contains either single * or double quote characters, then the text after that character up to * a matching quote will become the string in the list. - * + * * The returned pointer should be deallocated with @code{free(3C)} when * are done using the data. The data are placed in a single block of * allocated memory. Do not deallocate individual token/strings. - * + * * The structure pointed to will contain at least these two fields: * @table @samp * @item tkn_ct @@ -582,7 +760,7 @@ CPLUSPLUS_OPENER * An array of @code{tkn_ct + 1} pointers to substring tokens, with * the last pointer set to NULL. * @end table - * + * * There are two types of quoted strings: single quoted (@code{'}) and * double quoted (@code{"}). Singly quoted strings are fairly raw in that * escape characters (@code{\\}) are simply another character, except when @@ -592,22 +770,20 @@ CPLUSPLUS_OPENER * @code{'} incorporates the single quote into the string * @code{\n} suppresses both the backslash and newline character * @end example - * + * * Double quote strings are formed according to the rules of string * constants in ANSI-C programs. + * + * @param string string to be tokenized + * + * @return token_list_t* - pointer to a structure that lists each token */ extern token_list_t* ao_string_tokenize(char const*); -/* From: configfile.c line 77 - * +/** * configFileLoad - parse a configuration file * - * Arguments: - * pzFile the file to load - * - * Returns: const tOptionValue* - An allocated, compound value structure - * * This routine will load a named configuration file and parse the * text as a hierarchically valued option. The option descriptor * created from an option definition file is not used via this interface. @@ -615,20 +791,17 @@ extern token_list_t* ao_string_tokenize(char const*); * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to * @code{optionGetValue()}, @code{optionNextValue()} and * @code{optionUnloadNested()}. + * + * @param fname the file to load + * + * @return const tOptionValue* - An allocated, compound value structure */ extern const tOptionValue* configFileLoad(char const*); -/* From: configfile.c line 1066 - * +/** * optionFileLoad - Load the locatable config files, in order * - * Arguments: - * pOpts program options descriptor - * pzProg program name - * - * Returns: int - 0 -> SUCCESS, -1 -> FAILURE - * * This function looks in all the specified directories for a configuration * file ("rc" file or "ini" file) and processes any found twice. The first * time through, they are processed in reverse order (last file first). At @@ -636,164 +809,148 @@ extern const tOptionValue* configFileLoad(char const*); * example, if the last named file specifies not processing any more * configuration files, then no more configuration files will be processed. * Such an option in the @strong{first} named directory will have no effect. - * + * * Once the immediate action configurables have been handled, then the * directories are handled in normal, forward order. In that way, later * config files can override the settings of earlier config files. - * + * * See the AutoOpts documentation for a thorough discussion of the * config file format. - * + * * Configuration files not found or not decipherable are simply ignored. + * + * @param opts program options descriptor + * @param prog program name + * + * @return int - 0 -> SUCCESS, -1 -> FAILURE */ extern int optionFileLoad(tOptions*, char const*); -/* From: configfile.c line 211 - * +/** * optionFindNextValue - find a hierarcicaly valued option instance * - * Arguments: - * pOptDesc an option with a nested arg type - * pPrevVal the last entry - * name name of value to find - * value the matching value - * - * Returns: const tOptionValue* - a compound value structure - * * This routine will find the next entry in a nested value option or * configurable. It will search through the list and return the next entry * that matches the criteria. + * + * @param odesc an option with a nested arg type + * @param pPrevVal the last entry + * @param name name of value to find + * @param value the matching value + * + * @return const tOptionValue* - a compound value structure */ extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*); -/* From: configfile.c line 137 - * +/** * optionFindValue - find a hierarcicaly valued option instance * - * Arguments: - * pOptDesc an option with a nested arg type - * name name of value to find - * value the matching value - * - * Returns: const tOptionValue* - a compound value structure - * * This routine will find an entry in a nested value option or configurable. * It will search through the list and return a matching entry. + * + * @param odesc an option with a nested arg type + * @param name name of value to find + * @param val the matching value + * + * @return const tOptionValue* - a compound value structure */ extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char const*); -/* From: restore.c line 166 - * +/** * optionFree - free allocated option processing memory * - * Arguments: - * pOpts program options descriptor - * * AutoOpts sometimes allocates memory and puts pointers to it in the * option state structures. This routine deallocates all such memory. + * + * @param pOpts program options descriptor */ extern void optionFree(tOptions*); -/* From: configfile.c line 280 - * +/** * optionGetValue - get a specific value from a hierarcical list * - * Arguments: - * pOptValue a hierarchcal value - * valueName name of value to get - * - * Returns: const tOptionValue* - a compound value structure - * * This routine will find an entry in a nested value option or configurable. * If "valueName" is NULL, then the first entry is returned. Otherwise, * the first entry with a name that exactly matches the argument will be * returned. If there is no matching value, NULL is returned and errno is * set to ENOENT. If the provided option value is not a hierarchical value, * NULL is also returned and errno is set to EINVAL. + * + * @param pOptValue a hierarchcal value + * @param valueName name of value to get + * + * @return const tOptionValue* - a compound value structure */ extern const tOptionValue* optionGetValue(const tOptionValue*, char const*); -/* From: load.c line 475 - * +/** * optionLoadLine - process a string for an option name and value * - * Arguments: - * pOpts program options descriptor - * pzLine NUL-terminated text - * * This is a client program callable routine for setting options from, for * example, the contents of a file that they read in. Only one option may * appear in the text. It will be treated as a normal (non-preset) option. - * + * * 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}), * except that you may not use backquotes. + * + * @param opts program options descriptor + * @param line NUL-terminated text */ extern void optionLoadLine(tOptions*, char const*); -/* From: configfile.c line 340 - * +/** * optionNextValue - get the next value from a hierarchical list * - * Arguments: - * pOptValue a hierarchcal list value - * pOldValue a value from this list - * - * Returns: const tOptionValue* - a compound value structure - * * This routine will return the next entry after the entry passed in. At the * end of the list, NULL will be returned. If the entry is not found on the * list, NULL will be returned and "@var{errno}" will be set to EINVAL. * The "@var{pOldValue}" must have been gotten from a prior call to this * routine or to "@code{opitonGetValue()}". + * + * @param pOptValue a hierarchcal list value + * @param pOldValue a value from this list + * + * @return const tOptionValue* - a compound value structure */ extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*); -/* From: usage.c line 201 - * +/** * optionOnlyUsage - Print usage text for just the options * - * Arguments: - * pOpts program options descriptor - * ex_code exit code for calling exit(3) - * * This routine will print only the usage for each option. * This function may be used when the emitted usage must incorporate * information not available to AutoOpts. + * + * @param pOpts program options descriptor + * @param ex_code exit code for calling exit(3) */ extern void optionOnlyUsage(tOptions*, int); -/* From: autoopts.c line 607 - * +/** * optionProcess - this is the main option processing routine * - * Arguments: - * pOpts program options descriptor - * argc program arg count - * argv program arg vector - * - * Returns: int - the count of the arguments processed - * * This is the main entry point for processing options. It is intended * that this procedure be called once at the beginning of the execution of * a program. Depending on options selected earlier, it is sometimes * necessary to stop and restart option processing, or to select completely * different sets of options. This can be done easily, but you generally * do not want to do this. - * + * * The number of arguments processed always includes the program name. * If one of the arguments is "--", then it is counted and the processing * stops. If an error was encountered and errors are to be tolerated, then @@ -802,41 +959,41 @@ extern void optionOnlyUsage(tOptions*, int); * @emph{not} be counted among the processed arguments. A hyphen by itself * is treated as an operand. Encountering an operand stops option * processing. + * + * @param opts program options descriptor + * @param a_ct program arg count + * @param a_v program arg vector + * + * @return int - the count of the arguments processed */ extern int optionProcess(tOptions*, int, char**); -/* From: restore.c line 123 - * +/** * optionRestore - restore option state from memory copy * - * Arguments: - * pOpts program options descriptor - * * Copy back the option state from saved memory. * The allocated memory is left intact, so this routine can be * called repeatedly without having to call optionSaveState again. * If you are restoring a state that was saved before the first call * to optionProcess(3AO), then you may change the contents of the * argc/argv parameters to optionProcess. + * + * @param pOpts program options descriptor */ extern void optionRestore(tOptions*); -/* From: save.c line 648 - * +/** * optionSaveFile - saves the option state to a file * - * Arguments: - * pOpts program options descriptor - * * This routine will save the state of option processing to a file. The name * of that file can be specified with the argument to the @code{--save-opts} * option, or by appending the @code{rcfile} attribute to the last * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it * will default to @code{.@i{programname}rc}. If you wish to specify another * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro. - * + * * The recommend usage is as follows: * @example * optionProcess(&progOptions, argc, argv); @@ -844,145 +1001,88 @@ extern void optionRestore(tOptions*); * SET_OPT_SAVE_OPTS("myfilename"); * optionSaveFile(&progOptions); * @end example + * + * @param opts program options descriptor */ extern void optionSaveFile(tOptions*); -/* From: restore.c line 71 - * +/** * optionSaveState - saves the option state to memory * - * Arguments: - * pOpts program options descriptor - * * This routine will allocate enough memory to save the current option * processing state. If this routine has been called before, that memory * will be reused. You may only save one copy of the option state. This * routine may be called before optionProcess(3AO). If you do call it * before the first call to optionProcess, then you may also change the * contents of argc/argv after you call optionRestore(3AO) - * + * * In fact, more strongly put: it is safest to only use this function * before having processed any options. In particular, the saving and * restoring of stacked string arguments and hierarchical values is * disabled. The values are not saved. + * + * @param pOpts program options descriptor */ extern void optionSaveState(tOptions*); -/* From: nested.c line 563 - * +/** * optionUnloadNested - Deallocate the memory for a nested value * - * Arguments: - * pOptVal the hierarchical value - * * A nested value needs to be deallocated. The pointer passed in should * have been gotten from a call to @code{configFileLoad()} (See * @pxref{libopts-configFileLoad}). + * + * @param pOptVal the hierarchical value */ extern void optionUnloadNested(tOptionValue const *); -/* From: version.c line 31 - * +/** * optionVersion - return the compiled AutoOpts version number * - * Returns: char const* - the version string in constant memory - * * Returns the full version string compiled into the library. * The returned string cannot be modified. - */ -extern char const* optionVersion(void); - - -/* From: ../compat/pathfind.c line 29 - * - * pathfind - fild a file in a list of directories - * - * Arguments: - * path colon separated list of search directories - * file the name of the file to look for - * mode the mode bits that must be set to match - * - * Returns: char* - the path to the located file * - * the pathfind function is available only if HAVE_PATHFIND is not defined - * - * pathfind looks for a a file with name "FILE" and "MODE" access - * along colon delimited "PATH", and returns the full pathname as a - * string, or NULL if not found. If "FILE" contains a slash, then - * it is treated as a relative or absolute path and "PATH" is ignored. - * - * @strong{NOTE}: this function is compiled into @file{libopts} only if - * it is not natively supplied. - * - * The "MODE" argument is a string of option letters chosen from the - * list below: - * @example - * Letter Meaning - * r readable - * w writable - * x executable - * f normal file (NOT IMPLEMENTED) - * b block special (NOT IMPLEMENTED) - * c character special (NOT IMPLEMENTED) - * d directory (NOT IMPLEMENTED) - * p FIFO (pipe) (NOT IMPLEMENTED) - * u set user ID bit (NOT IMPLEMENTED) - * g set group ID bit (NOT IMPLEMENTED) - * k sticky bit (NOT IMPLEMENTED) - * s size nonzero (NOT IMPLEMENTED) - * @end example + * @return char const* - the version string in constant memory */ -#ifndef HAVE_PATHFIND -extern char* pathfind(char const*, char const*, char const*); -#endif /* HAVE_PATHFIND */ +extern char const* optionVersion(void); -/* From: streqvcmp.c line 209 - * +/** * strequate - map a list of characters to the same value * - * Arguments: - * ch_list characters to equivalence - * * Each character in the input string get mapped to the first character * in the string. * This function name is mapped to option_strequate so as to not conflict * with the POSIX name space. + * + * @param ch_list characters to equivalence */ extern void strequate(char const*); -/* From: streqvcmp.c line 119 - * +/** * streqvcmp - compare two strings with an equivalence mapping * - * Arguments: - * str1 first string - * str2 second string - * - * Returns: int - the difference between two differing characters - * * Using a character mapping, two strings are compared for "equivalence". * Each input character is mapped to a comparison character and the * mapped-to characters are compared for the two NUL terminated input strings. * This function name is mapped to option_streqvcmp so as to not conflict * with the POSIX name space. + * + * @param str1 first string + * @param str2 second string + * + * @return int - the difference between two differing characters */ extern int streqvcmp(char const*, char const*); -/* From: streqvcmp.c line 156 - * +/** * streqvmap - Set the character mappings for the streqv functions * - * Arguments: - * From Input character - * To Mapped-to character - * ct compare length - * * Set the character mapping. If the count (@code{ct}) is set to zero, then * the map is cleared by setting all entries in the map to their index * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}" @@ -995,48 +1095,48 @@ extern int streqvcmp(char const*, char const*); * @noindent * will alter the mapping so that all English lower case letters * will map to upper case. - * + * * This function name is mapped to option_streqvmap so as to not conflict * with the POSIX name space. + * + * @param from Input character + * @param to Mapped-to character + * @param ct compare length */ extern void streqvmap(char, char, int); -/* From: streqvcmp.c line 78 - * +/** * strneqvcmp - compare two strings with an equivalence mapping * - * Arguments: - * str1 first string - * str2 second string - * ct compare length - * - * Returns: int - the difference between two differing characters - * * Using a character mapping, two strings are compared for "equivalence". * Each input character is mapped to a comparison character and the * mapped-to characters are compared for the two NUL terminated input strings. * The comparison is limited to @code{ct} bytes. * This function name is mapped to option_strneqvcmp so as to not conflict * with the POSIX name space. + * + * @param str1 first string + * @param str2 second string + * @param ct compare length + * + * @return int - the difference between two differing characters */ extern int strneqvcmp(char const*, char const*, int); -/* From: streqvcmp.c line 235 - * +/** * strtransform - convert a string into its mapped-to value * - * Arguments: - * dest output string - * src input string - * * Each character in the input string is mapped and the mapped-to * character is put into the output. * This function name is mapped to option_strtransform so as to not conflict * with the POSIX name space. - * + * * The source and destination may be the same. + * + * @param dest output string + * @param src input string */ extern void strtransform(char*, char const*); @@ -1049,7 +1149,7 @@ extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int) extern void genshelloptUsage(tOptions*, int); -extern int optionAlias(tOptions*, tOptDesc*, unsigned int); +extern int optionAlias(tOptions *, tOptDesc *, unsigned int); extern void optionBooleanVal(tOptions*, tOptDesc*); @@ -1071,10 +1171,14 @@ extern void optionPagedUsage(tOptions*, tOptDesc*); extern void optionParseShell(tOptions*); +extern void optionPrintParagraphs(char const *, bool, FILE *); + extern void optionPrintVersion(tOptions*, tOptDesc*); extern void optionPutShell(tOptions*); +extern char const * optionQuoteString(char const *, char const *); + extern void optionResetOpt(tOptions*, tOptDesc*); extern void optionSetMembers(tOptions*, tOptDesc*, char const * const *, unsigned int); @@ -1101,7 +1205,8 @@ extern int text_munmap(tmap_info_t*); CPLUSPLUS_CLOSER #endif /* AUTOOPTS_OPTIONS_H_GUARD */ -/* +/** @} + * * Local Variables: * c-file-style: "stroustrup" * indent-tabs-mode: nil diff --git a/src/libopts/autoopts/project.h b/src/libopts/autoopts/project.h index c0df391bc1..34a215368d 100644 --- a/src/libopts/autoopts/project.h +++ b/src/libopts/autoopts/project.h @@ -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 */ diff --git a/src/libopts/autoopts/usage-txt.h b/src/libopts/autoopts/usage-txt.h index 3ed7f3b4f0..bf4bf44048 100644 --- a/src/libopts/autoopts/usage-txt.h +++ b/src/libopts/autoopts/usage-txt.h @@ -1,433 +1,657 @@ -/* -*- buffer-read-only: t -*- vi: set ro: - * - * DO NOT EDIT THIS FILE (usage-txt.h) - * - * It has been AutoGen-ed May 6, 2012 at 04:21:00 PM by AutoGen 5.16pre36 - * From the definitions usage-txt.def - * and the template file usage-txt.tpl +/* -*- buffer-read-only: t -*- vi: set ro: + * + * DO NOT EDIT THIS FILE (usage-txt.h) + * + * It has been AutoGen-ed March 31, 2013 at 10:41:28 AM by AutoGen 5.17.3 + * From the definitions usage-txt.def + * and the template file usage-txt.tpl + * + * 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 + */ +/** @file usage-txt.h * * This file handles all the bookkeeping required for tracking all the little - * tiny strings used by the AutoOpts library. There are 145 + * tiny strings used by the AutoOpts library. There are 108 * of them. This is not versioned because it is entirely internal to the * library and accessed by client code only in a very well-controlled way: * they may substitute translated strings using a procedure that steps through * all the string pointers. - * - * Copyright (C) 1992-2012 Bruce Korb, all rights reserved. - * This is free software. It is licensed for use, modification and - * redistribution under the terms of the - * GNU Lesser General Public License, version 3 or later - * <http://gnu.org/licenses/lgpl.html> - * - * AutoOpts 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 3 of the License, or - * (at your option) any later version. - * - * AutoOpts 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 AUTOOPTS_USAGE_TXT_H_GUARD #define AUTOOPTS_USAGE_TXT_H_GUARD 1 -#undef cch_t -#define cch_t char const - /* - * One structure to hold all the pointers to all the stringlets. + * One structure to hold all the pointers to all the translatable strings. */ typedef struct { - int field_ct; - char* utpz_GnuBoolArg; - char* utpz_GnuKeyArg; - char* utpz_GnuFileArg; - char* utpz_GnuKeyLArg; - char* utpz_GnuTimeArg; - char* utpz_GnuNumArg; - char* utpz_GnuStrArg; - cch_t* apz_str[ 138 ]; + int field_ct; + char * utpz_GnuBoolArg; + char * utpz_GnuKeyArg; + char * utpz_GnuNumArg; + char * utpz_GnuStrArg; + char const * apz_str[104]; } usage_text_t; /* - * Declare the global structure with all the pointers to translated - * strings. This is then used by the usage generation procedure. + * Declare the global structure with all the pointers to translatable + * strings and the text array containing untranslatable strings. */ -extern usage_text_t option_usage_text; +extern usage_text_t option_xlateable_txt; +extern char const option_lib_text[4285]; -#if defined(AUTOOPTS_INTERNAL) /* DEFINE ALL THE STRINGS = = = = = */ +#if defined(AUTOOPTS_INTERNAL) /* - * Provide a mapping from a short name to fields in this structure. + * Provide a mapping from a short name to either the text directly + * (for untranslatable strings), or to pointers to the text, rendering + * them translatable. */ -#define zAO_Alloc (option_usage_text.apz_str[ 0]) -#define zAO_Bad (option_usage_text.apz_str[ 1]) -#define zAO_Big (option_usage_text.apz_str[ 2]) -#define zAO_Err (option_usage_text.apz_str[ 3]) -#define zAO_Realloc (option_usage_text.apz_str[ 4]) -#define zAO_Sml (option_usage_text.apz_str[ 5]) -#define zAO_Strdup (option_usage_text.apz_str[ 6]) -#define zAO_Ver (option_usage_text.apz_str[ 7]) -#define zAO_Woops (option_usage_text.apz_str[ 8]) -#define zAliasRange (option_usage_text.apz_str[ 9]) -#define zAll (option_usage_text.apz_str[ 10]) -#define zAlt (option_usage_text.apz_str[ 11]) -#define zAmbigKey (option_usage_text.apz_str[ 12]) -#define zAmbigList (option_usage_text.apz_str[ 13]) -#define zAmbigOptStr (option_usage_text.apz_str[ 14]) -#define zAmbiguous (option_usage_text.apz_str[ 15]) -#define zArgsMust (option_usage_text.apz_str[ 16]) -#define zAtMost (option_usage_text.apz_str[ 17]) -#define zAuto (option_usage_text.apz_str[ 18]) -#define zBadPipe (option_usage_text.apz_str[ 19]) -#define zBadVerArg (option_usage_text.apz_str[ 20]) -#define zCantFmt (option_usage_text.apz_str[ 21]) -#define zCantSave (option_usage_text.apz_str[ 22]) -#define zCfgAO_Flags (option_usage_text.apz_str[ 23]) -#define zCfgProg (option_usage_text.apz_str[ 24]) -#define zDefaultOpt (option_usage_text.apz_str[ 25]) -#define zDis (option_usage_text.apz_str[ 26]) -#define zDisabledErr (option_usage_text.apz_str[ 27]) -#define zDisabledOpt (option_usage_text.apz_str[ 28]) -#define zDisabledWhy (option_usage_text.apz_str[ 29]) -#define zEnab (option_usage_text.apz_str[ 30]) -#define zEquiv (option_usage_text.apz_str[ 31]) -#define zErrOnly (option_usage_text.apz_str[ 32]) -#define zExamineFmt (option_usage_text.apz_str[ 33]) -#define zFiveSpaces (option_usage_text.apz_str[ 34]) -#define zFlagOkay (option_usage_text.apz_str[ 35]) -#define zFmtFmt (option_usage_text.apz_str[ 36]) -#define zForkFail (option_usage_text.apz_str[ 37]) -#define zFreopenFail (option_usage_text.apz_str[ 38]) -#define zFSErrOptLoad (option_usage_text.apz_str[ 39]) -#define zFSErrReadFile (option_usage_text.apz_str[ 40]) -#define zFSOptError (option_usage_text.apz_str[ 41]) -#define zFSOptErrMayExist (option_usage_text.apz_str[ 42]) -#define zFSOptErrMustExist (option_usage_text.apz_str[ 43]) -#define zFSOptErrNoExist (option_usage_text.apz_str[ 44]) -#define zFSOptErrOpen (option_usage_text.apz_str[ 45]) -#define zFSOptErrFopen (option_usage_text.apz_str[ 46]) -#define zFileCannotExist (option_usage_text.apz_str[ 47]) -#define zFileMustExist (option_usage_text.apz_str[ 48]) -#define zGenshell (option_usage_text.apz_str[ 49]) -#define zGnuBoolArg (option_usage_text.utpz_GnuBoolArg) -#define zGnuBreak (option_usage_text.apz_str[ 50]) -#define zGnuKeyArg (option_usage_text.utpz_GnuKeyArg) -#define zGnuFileArg (option_usage_text.utpz_GnuFileArg) -#define zGnuKeyLArg (option_usage_text.utpz_GnuKeyLArg) -#define zGnuTimeArg (option_usage_text.utpz_GnuTimeArg) -#define zGnuNestArg (option_usage_text.apz_str[ 51]) -#define zGnuNumArg (option_usage_text.utpz_GnuNumArg) -#define zGnuOptArg (option_usage_text.apz_str[ 52]) -#define zGnuOptFmt (option_usage_text.apz_str[ 53]) -#define zGnuStrArg (option_usage_text.utpz_GnuStrArg) -#define zIllOptChr (option_usage_text.apz_str[ 54]) -#define zIllOptStr (option_usage_text.apz_str[ 55]) -#define zIllVendOptStr (option_usage_text.apz_str[ 56]) -#define zIntRange (option_usage_text.apz_str[ 57]) -#define zInvalOptDesc (option_usage_text.apz_str[ 58]) -#define zLowerBits (option_usage_text.apz_str[ 59]) -#define zMembers (option_usage_text.apz_str[ 60]) -#define zMisArg (option_usage_text.apz_str[ 61]) -#define zMultiEquiv (option_usage_text.apz_str[ 62]) -#define zMust (option_usage_text.apz_str[ 63]) -#define zNeedOne (option_usage_text.apz_str[ 64]) -#define zNoArg (option_usage_text.apz_str[ 65]) -#define zNoArgs (option_usage_text.apz_str[ 66]) -#define zNoCreat (option_usage_text.apz_str[ 67]) -#define zNoFlags (option_usage_text.apz_str[ 68]) -#define zNoKey (option_usage_text.apz_str[ 69]) -#define zNoLim (option_usage_text.apz_str[ 70]) -#define zNoPreset (option_usage_text.apz_str[ 71]) -#define zNoResetArg (option_usage_text.apz_str[ 72]) -#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 73]) -#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 74]) -#define zNoStat (option_usage_text.apz_str[ 75]) -#define zNoState (option_usage_text.apz_str[ 76]) -#define zNone (option_usage_text.apz_str[ 77]) -#define zNotDef (option_usage_text.apz_str[ 78]) -#define zNotCmdOpt (option_usage_text.apz_str[ 79]) -#define zNotEnough (option_usage_text.apz_str[ 80]) -#define zNotFile (option_usage_text.apz_str[ 81]) -#define zNotNumber (option_usage_text.apz_str[ 82]) -#define zNotDate (option_usage_text.apz_str[ 83]) -#define zNotDuration (option_usage_text.apz_str[ 84]) -#define zNrmOptFmt (option_usage_text.apz_str[ 85]) -#define zNumberOpt (option_usage_text.apz_str[ 86]) -#define zOnlyOne (option_usage_text.apz_str[ 87]) -#define zOptsOnly (option_usage_text.apz_str[ 88]) -#define zOutputFail (option_usage_text.apz_str[ 89]) -#define zPathFmt (option_usage_text.apz_str[ 90]) -#define zPlsSendBugs (option_usage_text.apz_str[ 91]) -#define zPreset (option_usage_text.apz_str[ 92]) -#define zPresetFile (option_usage_text.apz_str[ 93]) -#define zPresetIntro (option_usage_text.apz_str[ 94]) -#define zProhib (option_usage_text.apz_str[ 95]) -#define zReorder (option_usage_text.apz_str[ 96]) -#define zRange (option_usage_text.apz_str[ 97]) -#define zRangeAbove (option_usage_text.apz_str[ 98]) -#define zRangeLie (option_usage_text.apz_str[ 99]) -#define zRangeOnly (option_usage_text.apz_str[100]) -#define zRangeOr (option_usage_text.apz_str[101]) -#define zRangeErr (option_usage_text.apz_str[102]) -#define zRangeExact (option_usage_text.apz_str[103]) -#define zRangeScaled (option_usage_text.apz_str[104]) -#define zRangeUpto (option_usage_text.apz_str[105]) -#define zResetNotConfig (option_usage_text.apz_str[106]) -#define zReqFmt (option_usage_text.apz_str[107]) -#define zReqOptFmt (option_usage_text.apz_str[108]) -#define zReqThese (option_usage_text.apz_str[109]) -#define zReq_NoShrtTtl (option_usage_text.apz_str[110]) -#define zReq_ShrtTtl (option_usage_text.apz_str[111]) -#define zSepChars (option_usage_text.apz_str[112]) -#define zSetMemberSettings (option_usage_text.apz_str[113]) -#define zShrtGnuOptFmt (option_usage_text.apz_str[114]) -#define zSixSpaces (option_usage_text.apz_str[115]) -#define zStdBoolArg (option_usage_text.apz_str[116]) -#define zStdBreak (option_usage_text.apz_str[117]) -#define zStdFileArg (option_usage_text.apz_str[118]) -#define zStdKeyArg (option_usage_text.apz_str[119]) -#define zStdKeyLArg (option_usage_text.apz_str[120]) -#define zStdTimeArg (option_usage_text.apz_str[121]) -#define zStdNestArg (option_usage_text.apz_str[122]) -#define zStdNoArg (option_usage_text.apz_str[123]) -#define zStdNumArg (option_usage_text.apz_str[124]) -#define zStdOptArg (option_usage_text.apz_str[125]) -#define zStdReqArg (option_usage_text.apz_str[126]) -#define zStdStrArg (option_usage_text.apz_str[127]) -#define zTabHyp (option_usage_text.apz_str[128]) -#define zTabHypAnd (option_usage_text.apz_str[129]) -#define zTabout (option_usage_text.apz_str[130]) -#define zThreeSpaces (option_usage_text.apz_str[131]) -#define zTooLarge (option_usage_text.apz_str[132]) -#define zTwoSpaces (option_usage_text.apz_str[133]) -#define zUpTo (option_usage_text.apz_str[134]) -#define zValidKeys (option_usage_text.apz_str[135]) -#define zVendOptsAre (option_usage_text.apz_str[136]) -#define zVendIntro (option_usage_text.apz_str[137]) +#define zalloc_fail (option_xlateable_txt.apz_str[ 0]) +#define zno_opt_arg (option_xlateable_txt.apz_str[ 1]) +#define ztoo_new (option_xlateable_txt.apz_str[ 2]) +#define zwrong_ver (option_xlateable_txt.apz_str[ 3]) +#define zrealloc_fail (option_xlateable_txt.apz_str[ 4]) +#define ztoo_old (option_xlateable_txt.apz_str[ 5]) +#define zao_ver_fmt (option_xlateable_txt.apz_str[ 6]) +#define zao_bug_msg (option_xlateable_txt.apz_str[ 7]) +#define zno_reset (option_xlateable_txt.apz_str[ 8]) +#define zmissing_help_msg (option_xlateable_txt.apz_str[ 9]) +#define zbad_data_msg (option_xlateable_txt.apz_str[ 10]) +#define zbad_arg_type_msg (option_xlateable_txt.apz_str[ 11]) +#define zbad_default_msg (option_xlateable_txt.apz_str[ 12]) +#define zbad_alias_id (option_xlateable_txt.apz_str[ 13]) +#define zambiguous_key (option_xlateable_txt.apz_str[ 14]) +#define zambig_list_msg (option_xlateable_txt.apz_str[ 15]) +#define zambig_opt_fmt (option_xlateable_txt.apz_str[ 16]) +#define zargs_must (option_xlateable_txt.apz_str[ 17]) +#define zat_most (option_xlateable_txt.apz_str[ 18]) +#define zfserr_fmt (option_xlateable_txt.apz_str[ 19]) +#define zinter_proc_pipe (option_xlateable_txt.apz_str[ 20]) +#define zBadVerArg (option_xlateable_txt.apz_str[ 21]) +#define zconflict_fmt (option_xlateable_txt.apz_str[ 22]) +#define zDisabledErr (option_xlateable_txt.apz_str[ 23]) +#define zequiv (option_xlateable_txt.apz_str[ 24]) +#define zGnuBoolArg (option_xlateable_txt.utpz_GnuBoolArg) +#define zGnuKeyArg (option_xlateable_txt.utpz_GnuKeyArg) +#define zGnuNumArg (option_xlateable_txt.utpz_GnuNumArg) +#define zGnuStrArg (option_xlateable_txt.utpz_GnuStrArg) +#define zIllOptChr (option_xlateable_txt.apz_str[ 25]) +#define zIllOptStr (option_xlateable_txt.apz_str[ 26]) +#define zIllVendOptStr (option_xlateable_txt.apz_str[ 27]) +#define zIntRange (option_xlateable_txt.apz_str[ 28]) +#define zbad_od (option_xlateable_txt.apz_str[ 29]) +#define zInvalOptName (option_xlateable_txt.apz_str[ 30]) +#define zMisArg (option_xlateable_txt.apz_str[ 31]) +#define zmultiway_bug (option_xlateable_txt.apz_str[ 32]) +#define zneed_one (option_xlateable_txt.apz_str[ 33]) +#define zNoArg (option_xlateable_txt.apz_str[ 34]) +#define zNoArgs (option_xlateable_txt.apz_str[ 35]) +#define zNoCreat (option_xlateable_txt.apz_str[ 36]) +#define zNoKey (option_xlateable_txt.apz_str[ 37]) +#define zreset_arg (option_xlateable_txt.apz_str[ 38]) +#define zNoStat (option_xlateable_txt.apz_str[ 39]) +#define zNoState (option_xlateable_txt.apz_str[ 40]) +#define zNotCmdOpt (option_xlateable_txt.apz_str[ 41]) +#define zNotDate (option_xlateable_txt.apz_str[ 42]) +#define zNotDef (option_xlateable_txt.apz_str[ 43]) +#define zNotDuration (option_xlateable_txt.apz_str[ 44]) +#define zneed_more (option_xlateable_txt.apz_str[ 45]) +#define zNotNumber (option_xlateable_txt.apz_str[ 46]) +#define znum_too_large (option_xlateable_txt.apz_str[ 47]) +#define zoffer_usage_fmt (option_xlateable_txt.apz_str[ 48]) +#define zonly_one (option_xlateable_txt.apz_str[ 49]) +#define zstdout_name (option_xlateable_txt.apz_str[ 50]) +#define zstderr_name (option_xlateable_txt.apz_str[ 51]) +#define zwriting (option_xlateable_txt.apz_str[ 52]) +#define zRangeErr (option_xlateable_txt.apz_str[ 53]) +#define zneed_fmt (option_xlateable_txt.apz_str[ 54]) +#define zsave_warn (option_xlateable_txt.apz_str[ 55]) +#define zalt_opt (option_xlateable_txt.apz_str[ 56]) +#define zAuto (option_xlateable_txt.apz_str[ 57]) +#define zDefaultOpt (option_xlateable_txt.apz_str[ 58]) +#define zDis (option_xlateable_txt.apz_str[ 59]) +#define zDisabledOpt (option_xlateable_txt.apz_str[ 60]) +#define zDisabledWhy (option_xlateable_txt.apz_str[ 61]) +#define zEnab (option_xlateable_txt.apz_str[ 62]) +#define ztoo_often_fmt (option_xlateable_txt.apz_str[ 63]) +#define zExamineFmt (option_xlateable_txt.apz_str[ 64]) +#define zFileCannotExist (option_xlateable_txt.apz_str[ 65]) +#define zFileMustExist (option_xlateable_txt.apz_str[ 66]) +#define zFlagOkay (option_xlateable_txt.apz_str[ 67]) +#define zGenshell (option_xlateable_txt.apz_str[ 68]) +#define zLowerBits (option_xlateable_txt.apz_str[ 69]) +#define zMembers (option_xlateable_txt.apz_str[ 70]) +#define zMust (option_xlateable_txt.apz_str[ 71]) +#define zNoFlags (option_xlateable_txt.apz_str[ 72]) +#define zNoLim (option_xlateable_txt.apz_str[ 73]) +#define zNoPreset (option_xlateable_txt.apz_str[ 74]) +#define zNoRq_NoShrtTtl (option_xlateable_txt.apz_str[ 75]) +#define zNoRq_ShrtTtl (option_xlateable_txt.apz_str[ 76]) +#define zNrmOptFmt (option_xlateable_txt.apz_str[ 77]) +#define zNumberOpt (option_xlateable_txt.apz_str[ 78]) +#define zOptsOnly (option_xlateable_txt.apz_str[ 79]) +#define zPathFmt (option_xlateable_txt.apz_str[ 80]) +#define zPlsSendBugs (option_xlateable_txt.apz_str[ 81]) +#define zPreset (option_xlateable_txt.apz_str[ 82]) +#define zPresetIntro (option_xlateable_txt.apz_str[ 83]) +#define zProhib (option_xlateable_txt.apz_str[ 84]) +#define zProhibOne (option_xlateable_txt.apz_str[ 85]) +#define zRange (option_xlateable_txt.apz_str[ 86]) +#define zRangeAbove (option_xlateable_txt.apz_str[ 87]) +#define zRangeExact (option_xlateable_txt.apz_str[ 88]) +#define zRangeLie (option_xlateable_txt.apz_str[ 89]) +#define zRangeOnly (option_xlateable_txt.apz_str[ 90]) +#define zRangeOr (option_xlateable_txt.apz_str[ 91]) +#define zRangeScaled (option_xlateable_txt.apz_str[ 92]) +#define zRangeUpto (option_xlateable_txt.apz_str[ 93]) +#define zReorder (option_xlateable_txt.apz_str[ 94]) +#define zReqOne (option_xlateable_txt.apz_str[ 95]) +#define zReqThese (option_xlateable_txt.apz_str[ 96]) +#define zReq_NoShrtTtl (option_xlateable_txt.apz_str[ 97]) +#define zReq_ShrtTtl (option_xlateable_txt.apz_str[ 98]) +#define zSetMemberSettings (option_xlateable_txt.apz_str[ 99]) +#define zUpTo (option_xlateable_txt.apz_str[100]) +#define zValidKeys (option_xlateable_txt.apz_str[101]) +#define zVendIntro (option_xlateable_txt.apz_str[102]) +#define zVendOptsAre (option_xlateable_txt.apz_str[103]) /* * First, set up the strings. Some of these are writable. These are all in * English. This gets compiled into libopts and is distributed here so that * xgettext (or equivalents) can extract these strings for translation. */ - - static char eng_zGnuBoolArg[] = "=T/F"; - static char eng_zGnuKeyArg[] = "=KWd"; - static char eng_zGnuFileArg[] = "=file"; - static char eng_zGnuKeyLArg[] = "=Mbr"; - static char eng_zGnuTimeArg[] = "=Tim"; - static char eng_zGnuNumArg[] = "=num"; - static char eng_zGnuStrArg[] = "=str"; -static char const usage_txt[4631] = -/* 0 */ "malloc of %d bytes failed\n\0" -/* 27 */ "AutoOpts function called without option descriptor\n\0" -/* 79 */ "\tThis exceeds the compiled library version: \0" -/* 125 */ "Automated Options Processing Error!\n" +static char eng_zGnuBoolArg[] = "=T/F"; +static char eng_zGnuKeyArg[] = "=KWd"; +static char eng_zGnuNumArg[] = "=num"; +static char eng_zGnuStrArg[] = "=str"; +char const option_lib_text[4285] = +/* 0 */ "allocation of %d bytes failed\n\0" +/* 31 */ "AutoOpts function called without option descriptor\n\0" +/* 83 */ "\tThis exceeds the compiled library version: \0" +/* 129 */ "Automated Options Processing Error!\n" "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0" -/* 224 */ "realloc of %d bytes at 0x%p failed\n\0" -/* 260 */ "\tThis is less than the minimum library version: \0" -/* 310 */ "strdup of %d byte string failed\n\0" -/* 343 */ "Automated Options version %s\n" - "\tcopyright (c) 1999-2012 by Bruce Korb - all rights reserved\n\0" -/* 434 */ "AutoOpts lib error: defaulted to option with optional arg\n\0" -/* 493 */ "(AutoOpts bug): Aliasing option is out of range.\0" -/* 543 */ "all\0" -/* 547 */ "\t\t\t\t- an alternate for %s\n\0" -/* 574 */ "%s error: the keyword `%s' is ambiguous for %s\n\0" -/* 623 */ " The following options match:\n\0" -/* 655 */ "%s: ambiguous option name: %s (matches %d options)\n\0" -/* 707 */ " %s%s\n\0" -/* 715 */ "%s: Command line arguments required\n\0" -/* 752 */ "%d %s%s options allowed\n\0" -/* 777 */ "version, usage and configuration options:\0" -/* 819 */ "Error %d (%s) from the pipe(2) syscall\n\0" -/* 859 */ "ERROR: version option argument '%c' invalid. Use:\n" +/* 228 */ "realloc of %d bytes at 0x%p failed\n\0" +/* 264 */ "\tThis is less than the minimum library version: \0" +/* 314 */ "Automated Options version %s\n" + "\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n\0" +/* 405 */ "(AutoOpts bug): %s.\n\0" +/* 427 */ "optionResetOpt() called, but reset-option not configured\0" +/* 484 */ "could not locate the 'help' option\0" +/* 519 */ "optionProcess() was called with invalid data\0" +/* 564 */ "invalid argument type specified\0" +/* 596 */ "defaulted to option with optional arg\0" +/* 634 */ "aliasing option is out of range.\0" +/* 667 */ "%s error: the keyword '%s' is ambiguous for %s\n\0" +/* 716 */ " The following options match:\n\0" +/* 748 */ "%s: ambiguous option name: %s (matches %d options)\n\0" +/* 800 */ "%s: Command line arguments required\n\0" +/* 837 */ "%d %s%s options allowed\n\0" +/* 862 */ "%s error %d (%s) calling %s for '%s'\n\0" +/* 900 */ "interprocess pipe\0" +/* 918 */ "error: version option argument '%c' invalid. Use:\n" "\t'v' - version only\n" "\t'c' - version and copyright\n" - "\t'n' - version and copyright notice\n\0" -/* 996 */ "ERROR: %s option conflicts with the %s option\n\0" -/* 1044 */ "%s(optionSaveState): error: cannot allocate %d bytes\n\0" -/* 1098 */ "auto-options\0" -/* 1111 */ "program\0" -/* 1119 */ "\t\t\t\t- default option for unnamed options\n\0" -/* 1161 */ "\t\t\t\t- disabled as --%s\n\0" -/* 1185 */ "%s: The ``%s'' option has been disabled\0" -/* 1225 */ " --- %-14s %s\n\0" -/* 1240 */ "This option has been disabled\0" -/* 1270 */ "\t\t\t\t- enabled by default\n\0" -/* 1296 */ "-equivalence\0" -/* 1309 */ "ERROR: only \0" -/* 1323 */ " - examining environment variables named %s_*\n\0" -/* 1370 */ " \0" -/* 1376 */ "Options are specified by doubled hyphens and their name or by a single\n" + "\t'n' - version and full copyright notice\n\0" +/* 1060 */ "%s error: the '%s' and '%s' options conflict\n\0" +/* 1107 */ "%s: The '%s' option has been disabled.\0" +/* 1146 */ "-equivalence\0" +/* 1159 */ "%s: illegal option -- %c\n\0" +/* 1185 */ "%s: illegal option -- %s\n\0" +/* 1211 */ "%s: unknown vendor extension option -- %s\n\0" +/* 1254 */ " or an integer from %d through %d\n\0" +/* 1290 */ "%s error: invalid option descriptor for %s\n\0" +/* 1335 */ "%s: invalid option name: %s\n\0" +/* 1364 */ "%s: The '%s' option requires an argument.\n\0" +/* 1407 */ "(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n" + "\t'%s' and '%s'.\0" +/* 1490 */ "%s error: The %s option is required\n\0" +/* 1528 */ "%s: The '%s' option cannot have an argument.\n\0" +/* 1574 */ "%s: Command line arguments are not allowed.\n\0" +/* 1619 */ "error %d (%s) creating %s\n\0" +/* 1646 */ "%s error: '%s' does not match any %s keywords.\n\0" +/* 1695 */ "%s error: The '%s' option requires an argument.\n\0" +/* 1744 */ "error %d (%s) stat-ing %s\n\0" +/* 1771 */ "%s error: no saved option state\n\0" +/* 1804 */ "'%s' is not a command line option.\n\0" +/* 1840 */ "%s error: '%s' is not a recognizable date/time.\n\0" +/* 1890 */ "'%s' not defined\n\0" +/* 1908 */ "%s error: '%s' is not a recognizable time duration.\n\0" +/* 1962 */ "%s error: The %s option must appear %d times.\n\0" +/* 2010 */ "%s error: '%s' is not a recognizable number.\n\0" +/* 2057 */ "%s error: %s exceeds %s keyword count\n\0" +/* 2097 */ "Try '%s %s' for more information.\n\0" +/* 2132 */ "one %s%s option allowed\n\0" +/* 2157 */ "standard output\0" +/* 2173 */ "standard error\0" +/* 2188 */ "write\0" +/* 2194 */ "%s error: %s option value %ld is out of range.\n\0" +/* 2243 */ "%s error: %s option requires the %s option\n\0" +/* 2288 */ "%s warning: cannot save options - %s not regular file\n\0" +/* 2344 */ "\t\t\t\t- an alternate for '%s'\n\0" +/* 2373 */ "Version, usage and configuration options:\0" +/* 2415 */ "\t\t\t\t- default option for unnamed options\n\0" +/* 2457 */ "\t\t\t\t- disabled as '--%s'\n\0" +/* 2483 */ " --- %-14s %s\n\0" +/* 2498 */ "This option has been disabled\0" +/* 2528 */ "\t\t\t\t- enabled by default\n\0" +/* 2554 */ "%s error: only \0" +/* 2571 */ " - examining environment variables named %s_*\n\0" +/* 2618 */ "\t\t\t\t- file must not pre-exist\n\0" +/* 2649 */ "\t\t\t\t- file must pre-exist\n\0" +/* 2676 */ "Options are specified by doubled hyphens and their name or by a single\n" "hyphen and the flag character.\n\0" -/* 1479 */ "%%-%ds %%s\n\0" -/* 1491 */ "fs error %d (%s) on fork - cannot obtain %s usage\n\0" -/* 1542 */ "fs error %d (%s) on freopen\n\0" -/* 1571 */ "File error %d (%s) opening %s for loading options\n\0" -/* 1622 */ "fs error %d (%s) reading file %s\n\0" -/* 1656 */ "fs error %d (%s) on %s %s for option %s\n\0" -/* 1697 */ "stat-ing for directory\0" -/* 1720 */ "stat-ing for regular file\0" -/* 1746 */ "stat-ing for non-existant file\0" -/* 1777 */ "open-ing file\0" -/* 1791 */ "fopen-ing file\0" -/* 1806 */ "\t\t\t\t- file must not pre-exist\n\0" -/* 1837 */ "\t\t\t\t- file must pre-exist\n\0" -/* 1864 */ "\n" +/* 2779 */ "\n" "= = = = = = = =\n\n" "This incarnation of genshell will produce\n" "a shell script to parse the options for %s:\n\n\0" -/* 1970 */ "\n" - "%s\n\n\0" -/* 1976 */ "=Cplx\0" -/* 1982 */ "[=arg]\0" -/* 1989 */ "--%2$s%1$s\0" -/* 2000 */ "%s: illegal option -- %c\n\0" -/* 2026 */ "%s: illegal option -- %s\n\0" -/* 2052 */ "%s: unknown vendor extension option -- %s\n\0" -/* 2095 */ " or an integer from %d through %d\n\0" -/* 2131 */ "AutoOpts ERROR: invalid option descriptor for %s\n\0" -/* 2182 */ " or an integer mask with any of the lower %d bits set\n\0" -/* 2238 */ "\t\t\t\t- is a set membership option\n\0" -/* 2272 */ "%s: option `%s' requires an argument\n\0" -/* 2310 */ "Equivalenced option '%s' was equivalenced to both\n" - "\t'%s' and '%s'\0" -/* 2375 */ "\t\t\t\t- must appear between %d and %d times\n\0" -/* 2418 */ "ERROR: The %s option is required\n\0" -/* 2453 */ "%s: option `%s' cannot have an argument\n\0" -/* 2494 */ "%s: Command line arguments not allowed\n\0" -/* 2534 */ "error %d (%s) creating %s\n\0" -/* 2561 */ "Options are specified by single or double hyphens and their name.\n\0" -/* 2628 */ "%s error: `%s' does not match any %s keywords\n\0" -/* 2676 */ "\t\t\t\t- may appear multiple times\n\0" -/* 2709 */ "\t\t\t\t- may not be preset\n\0" -/* 2734 */ "The 'reset-option' option requires an argument\n\0" -/* 2782 */ " Arg Option-Name Description\n\0" -/* 2817 */ " Flg Arg Option-Name Description\n\0" -/* 2855 */ "error %d (%s) stat-ing %s\n\0" -/* 2882 */ "%s(optionRestore): error: no saved option state\n\0" -/* 2931 */ "none\0" -/* 2936 */ "'%s' not defined\n\0" -/* 2954 */ "'%s' is not a command line option\n\0" -/* 2989 */ "ERROR: The %s option must appear %d times\n\0" -/* 3033 */ "error: cannot load options from non-regular file %s\n\0" -/* 3087 */ "%s error: `%s' is not a recognizable number\n\0" -/* 3133 */ "%s error: `%s' is not a recognizable date/time\n\0" -/* 3182 */ "%s error: `%s' is not a recognizable time duration\n\0" -/* 3235 */ " %3s %s\0" -/* 3243 */ "The '-#<number>' option may omit the hash char\n\0" -/* 3291 */ "one %s%s option allowed\n\0" -/* 3316 */ "All arguments are named options.\n\0" -/* 3350 */ "Write failure to output file\0" -/* 3379 */ " - reading file %s\0" -/* 3398 */ "\n" - "please send bug reports to: %s\n\0" -/* 3432 */ "\t\t\t\t- may NOT appear - preset only\n\0" -/* 3468 */ "# preset/initialization file\n" - "# %s#\n\0" -/* 3506 */ "\n" +/* 2885 */ " or an integer mask with any of the lower %d bits set\n\0" +/* 2941 */ "\t\t\t\t- is a set membership option\n\0" +/* 2975 */ "\t\t\t\t- must appear between %d and %d times\n\0" +/* 3018 */ "Options are specified by single or double hyphens and their name.\n\0" +/* 3085 */ "\t\t\t\t- may appear multiple times\n\0" +/* 3118 */ "\t\t\t\t- may not be preset\n\0" +/* 3143 */ " Arg Option-Name Description\n\0" +/* 3178 */ " Flg Arg Option-Name Description\n\0" +/* 3216 */ " %3s %s\0" +/* 3224 */ "The '-#<number>' option may omit the hash char\n\0" +/* 3272 */ "All arguments are named options.\n\0" +/* 3306 */ " - reading file %s\0" +/* 3325 */ "\n" + "Please send bug reports to: <%s>\n\0" +/* 3361 */ "\t\t\t\t- may NOT appear - preset only\n\0" +/* 3397 */ "\n" "The following option preset mechanisms are supported:\n\0" -/* 3562 */ "prohibits these options:\n\0" -/* 3588 */ "Operands and options may be intermixed. They will be reordered.\n\0" -/* 3654 */ "%s%ld to %ld\0" -/* 3667 */ "%sgreater than or equal to %ld\0" -/* 3698 */ "%sIt must lie in one of the ranges:\n\0" -/* 3735 */ "%sIt must be in the range:\n\0" -/* 3763 */ ", or\n\0" -/* 3769 */ "%s error: %s option value %ld is out of range.\n\0" -/* 3818 */ "%s%ld exactly\0" -/* 3832 */ "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0" -/* 3878 */ "%sless than or equal to %ld\0" -/* 3906 */ "The --reset-option has not been configured.\n\0" -/* 3951 */ "ERROR: %s option requires the %s option\n\0" -/* 3993 */ " %3s %-14s %s\0" -/* 4007 */ "requires these options:\n\0" -/* 4032 */ " Arg Option-Name Req? Description\n\0" -/* 4072 */ " Flg Arg Option-Name Req? Description\n\0" -/* 4115 */ "-_^\0" -/* 4119 */ "or you may use a numeric representation. Preceding these with a '!' will\n" - "clear the bits, specifying 'none' will clear all bits, and 'all' will set them\n" - "all. Multiple entries may be passed as an option argument list.\n\0" -/* 4338 */ "%s\0" -/* 4341 */ " \0" -/* 4348 */ "T/F\0" -/* 4352 */ "\n" - "%s\n\n" - "%s\0" -/* 4360 */ "Fil\0" -/* 4364 */ "KWd\0" -/* 4368 */ "Mbr\0" -/* 4372 */ "Tim\0" -/* 4376 */ "Cpx\0" -/* 4380 */ "no \0" -/* 4384 */ "Num\0" -/* 4388 */ "opt\0" -/* 4392 */ "YES\0" -/* 4396 */ "Str\0" -/* 4400 */ "\t\t\t\t- \0" -/* 4407 */ "\t\t\t\t-- and \0" -/* 4419 */ "\t\t\t\t%s\n\0" -/* 4427 */ " \0" -/* 4431 */ "%s error: %s exceeds %s keyword count\n\0" -/* 4471 */ " \0" -/* 4474 */ "\t\t\t\t- may appear up to %d times\n\0" -/* 4507 */ "The valid \"%s\" option keywords are:\n\0" -/* 4544 */ "These additional options are:\0" -/* 4574 */ "The next option supports vendor supported extra options:"; +/* 3453 */ "prohibits these options:\n\0" +/* 3479 */ "prohibits the option '%s'\n\0" +/* 3506 */ "%s%ld to %ld\0" +/* 3519 */ "%sgreater than or equal to %ld\0" +/* 3550 */ "%s%ld exactly\0" +/* 3564 */ "%sit must lie in one of the ranges:\n\0" +/* 3601 */ "%sit must be in the range:\n\0" +/* 3629 */ ", or\n\0" +/* 3635 */ "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0" +/* 3681 */ "%sless than or equal to %ld\0" +/* 3709 */ "Operands and options may be intermixed. They will be reordered.\n\0" +/* 3775 */ "requires the option '%s'\n\0" +/* 3801 */ "requires these options:\n\0" +/* 3826 */ " Arg Option-Name Req? Description\n\0" +/* 3866 */ " Flg Arg Option-Name Req? Description\n\0" +/* 3909 */ "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\0" +/* 4128 */ "\t\t\t\t- may appear up to %d times\n\0" +/* 4161 */ "The valid \"%s\" option keywords are:\n\0" +/* 4198 */ "The next option supports vendor supported extra options:\0" +/* 4255 */ "These additional options are:"; - - /* - * Now, define (and initialize) the structure that contains - * the pointers to all these strings. - * Aren't you glad you don't maintain this by hand? - */ - usage_text_t option_usage_text = { - 145, - eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuFileArg, eng_zGnuKeyLArg, - eng_zGnuTimeArg, eng_zGnuNumArg, eng_zGnuStrArg, +/* + * Now, define (and initialize) the structure that contains + * the pointers to all these strings. + * Aren't you glad you don't maintain this by hand? + */ +usage_text_t option_xlateable_txt = { + 108, + eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuNumArg, eng_zGnuStrArg, { - usage_txt + 0, usage_txt + 27, usage_txt + 79, usage_txt + 125, - usage_txt + 224, usage_txt + 260, usage_txt + 310, usage_txt + 343, - usage_txt + 434, usage_txt + 493, usage_txt + 543, usage_txt + 547, - usage_txt + 574, usage_txt + 623, usage_txt + 655, usage_txt + 707, - usage_txt + 715, usage_txt + 752, usage_txt + 777, usage_txt + 819, - usage_txt + 859, usage_txt + 996, usage_txt +1044, usage_txt +1098, - usage_txt +1111, usage_txt +1119, usage_txt +1161, usage_txt +1185, - usage_txt +1225, usage_txt +1240, usage_txt +1270, usage_txt +1296, - usage_txt +1309, usage_txt +1323, usage_txt +1370, usage_txt +1376, - usage_txt +1479, usage_txt +1491, usage_txt +1542, usage_txt +1571, - usage_txt +1622, usage_txt +1656, usage_txt +1697, usage_txt +1720, - usage_txt +1746, usage_txt +1777, usage_txt +1791, usage_txt +1806, - usage_txt +1837, usage_txt +1864, usage_txt +1970, usage_txt +1976, - usage_txt +1982, usage_txt +1989, usage_txt +2000, usage_txt +2026, - usage_txt +2052, usage_txt +2095, usage_txt +2131, usage_txt +2182, - usage_txt +2238, usage_txt +2272, usage_txt +2310, usage_txt +2375, - usage_txt +2418, usage_txt +2453, usage_txt +2494, usage_txt +2534, - usage_txt +2561, usage_txt +2628, usage_txt +2676, usage_txt +2709, - usage_txt +2734, usage_txt +2782, usage_txt +2817, usage_txt +2855, - usage_txt +2882, usage_txt +2931, usage_txt +2936, usage_txt +2954, - usage_txt +2989, usage_txt +3033, usage_txt +3087, usage_txt +3133, - usage_txt +3182, usage_txt +3235, usage_txt +3243, usage_txt +3291, - usage_txt +3316, usage_txt +3350, usage_txt +3379, usage_txt +3398, - usage_txt +3432, usage_txt +3468, usage_txt +3506, usage_txt +3562, - usage_txt +3588, usage_txt +3654, usage_txt +3667, usage_txt +3698, - usage_txt +3735, usage_txt +3763, usage_txt +3769, usage_txt +3818, - usage_txt +3832, usage_txt +3878, usage_txt +3906, usage_txt +3951, - usage_txt +3993, usage_txt +4007, usage_txt +4032, usage_txt +4072, - usage_txt +4115, usage_txt +4119, usage_txt +4338, usage_txt +4341, - usage_txt +4348, usage_txt +4352, usage_txt +4360, usage_txt +4364, - usage_txt +4368, usage_txt +4372, usage_txt +4376, usage_txt +4380, - usage_txt +4384, usage_txt +4388, usage_txt +4392, usage_txt +4396, - usage_txt +4400, usage_txt +4407, usage_txt +4419, usage_txt +4427, - usage_txt +4431, usage_txt +4471, usage_txt +4474, usage_txt +4507, - usage_txt +4544, usage_txt +4574 - } - }; + option_lib_text + 0, option_lib_text + 31, option_lib_text + 83, + option_lib_text + 129, option_lib_text + 228, option_lib_text + 264, + option_lib_text + 314, option_lib_text + 405, option_lib_text + 427, + option_lib_text + 484, option_lib_text + 519, option_lib_text + 564, + option_lib_text + 596, option_lib_text + 634, option_lib_text + 667, + option_lib_text + 716, option_lib_text + 748, option_lib_text + 800, + option_lib_text + 837, option_lib_text + 862, option_lib_text + 900, + option_lib_text + 918, option_lib_text + 1060, option_lib_text + 1107, + option_lib_text + 1146, option_lib_text + 1159, option_lib_text + 1185, + option_lib_text + 1211, option_lib_text + 1254, option_lib_text + 1290, + option_lib_text + 1335, option_lib_text + 1364, option_lib_text + 1407, + option_lib_text + 1490, option_lib_text + 1528, option_lib_text + 1574, + option_lib_text + 1619, option_lib_text + 1646, option_lib_text + 1695, + option_lib_text + 1744, option_lib_text + 1771, option_lib_text + 1804, + option_lib_text + 1840, option_lib_text + 1890, option_lib_text + 1908, + option_lib_text + 1962, option_lib_text + 2010, option_lib_text + 2057, + option_lib_text + 2097, option_lib_text + 2132, option_lib_text + 2157, + option_lib_text + 2173, option_lib_text + 2188, option_lib_text + 2194, + option_lib_text + 2243, option_lib_text + 2288, option_lib_text + 2344, + option_lib_text + 2373, option_lib_text + 2415, option_lib_text + 2457, + option_lib_text + 2483, option_lib_text + 2498, option_lib_text + 2528, + option_lib_text + 2554, option_lib_text + 2571, option_lib_text + 2618, + option_lib_text + 2649, option_lib_text + 2676, option_lib_text + 2779, + option_lib_text + 2885, option_lib_text + 2941, option_lib_text + 2975, + option_lib_text + 3018, option_lib_text + 3085, option_lib_text + 3118, + option_lib_text + 3143, option_lib_text + 3178, option_lib_text + 3216, + option_lib_text + 3224, option_lib_text + 3272, option_lib_text + 3306, + option_lib_text + 3325, option_lib_text + 3361, option_lib_text + 3397, + option_lib_text + 3453, option_lib_text + 3479, option_lib_text + 3506, + option_lib_text + 3519, option_lib_text + 3550, option_lib_text + 3564, + option_lib_text + 3601, option_lib_text + 3629, option_lib_text + 3635, + option_lib_text + 3681, option_lib_text + 3709, option_lib_text + 3775, + option_lib_text + 3801, option_lib_text + 3826, option_lib_text + 3866, + option_lib_text + 3909, option_lib_text + 4128, option_lib_text + 4161, + option_lib_text + 4198, option_lib_text + 4255 + } }; +#endif /* AUTOOPTS_INTERNAL */ + +#ifdef XGETTEXT_SCAN_DO_NOT_COMPILE +do not compile this section. +/* TRANSLATORS: The following dummy functions were crated solely so that + * xgettext can extract the correct strings. These strings are actually + * referenced where the preceding "#line" directive states, though you will + * not see the literal string there. The literal string is defined above in + * the @code{option_lib_text} table and referenced via a #define name that + * redirects into the @code{option_xlateable_txt} structure above. When + * translating is activated, the pointers in @code{option_xlateable_txt} are + * updated to point to translated strings. + */ +static void dummy_func(void) { + /* 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 */ -#endif /* DO_TRANSLATIONS */ + /* 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 /* XGETTEXT_SCAN_DO_NOT_COMPILE */ #endif /* AUTOOPTS_USAGE_TXT_H_GUARD */ diff --git a/src/libopts/boolean.c b/src/libopts/boolean.c index f0e5498a88..e2dff14cdf 100644 --- a/src/libopts/boolean.c +++ b/src/libopts/boolean.c @@ -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" diff --git a/src/libopts/check.c b/src/libopts/check.c index 019a23505a..3196b00093 100644 --- a/src/libopts/check.c +++ b/src/libopts/check.c @@ -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 */ diff --git a/src/libopts/compat/compat.h b/src/libopts/compat/compat.h index 9d1c02ac4a..e7b30ea3ab 100644 --- a/src/libopts/compat/compat.h +++ b/src/libopts/compat/compat.h @@ -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. - * - * AutoGen Copyright (c) 1992-2012 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. + * This file is part of AutoGen and AutoOpts. * - * 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. + * AutoGen Copyright (C) 1992-2013 by Bruce Korb - all rights reserved * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. + * 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. * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in the release of compat.h. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * 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. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * These files have the following sha256 sums: * - * 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 */ diff --git a/src/libopts/compat/pathfind.c b/src/libopts/compat/pathfind.c index 2e6f881ec9..ec380bc8fa 100644 --- a/src/libopts/compat/pathfind.c +++ b/src/libopts/compat/pathfind.c @@ -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) diff --git a/src/libopts/compat/snprintf.c b/src/libopts/compat/snprintf.c index fc91d63a9c..eccea1faf0 100644 --- a/src/libopts/compat/snprintf.c +++ b/src/libopts/compat/snprintf.c @@ -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 diff --git a/src/libopts/compat/strchr.c b/src/libopts/compat/strchr.c index 413f999ff9..0def700f86 100644 --- a/src/libopts/compat/strchr.c +++ b/src/libopts/compat/strchr.c @@ -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); diff --git a/src/libopts/compat/strdup.c b/src/libopts/compat/strdup.c index e2933a8afd..f3a40770d0 100644 --- a/src/libopts/compat/strdup.c +++ b/src/libopts/compat/strdup.c @@ -3,6 +3,9 @@ */ static char * +strdup( char const *s ); + +static char * strdup( char const *s ) { char *cp; diff --git a/src/libopts/compat/windows-config.h b/src/libopts/compat/windows-config.h index 076c046602..194d2280eb 100644 --- a/src/libopts/compat/windows-config.h +++ b/src/libopts/compat/windows-config.h @@ -1,24 +1,33 @@ -/* - * Time-stamp: "2010-02-24 08:39:04 bkorb" +/** + * \file windows-config.h + * + * 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. + * + * 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 * - * This file is part of AutoGen. + * 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 Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * 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. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * 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. + * These files have the following sha256 sums: * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. + * 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 */ diff --git a/src/libopts/configfile.c b/src/libopts/configfile.c index 56e22b5db7..8c71111c5b 100644 --- a/src/libopts/configfile.c +++ b/src/libopts/configfile.c @@ -1,13 +1,15 @@ /** * \file configfile.c * - * Time-stamp: "2012-03-31 13:56:11 bkorb" - * * configuration/rc/ini file handling. * + * @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,34 +21,34 @@ * 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 void file_preset(tOptions * opts, char const * fname, int dir); -static char* -handle_comment(char* pzText); +static char * +handle_comment(char* txt); static char * -handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); +handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir); static char * -handle_directive(tOptions * pOpts, char * pzText); +handle_directive(tOptions * opts, char * txt); static char * -aoflags_directive(tOptions * pOpts, char * pzText); +aoflags_directive(tOptions * opts, char * txt); static char * -program_directive(tOptions * pOpts, char * pzText); +program_directive(tOptions * opts, char * txt); static char * -handle_section(tOptions * pOpts, char * pzText); +handle_section(tOptions * opts, char * txt); static int parse_xml_encoding(char ** ppz); @@ -58,26 +60,34 @@ static void cook_xml_text(char * pzData); static char * -handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); +handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir); -static char* -parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType); +static char const * +parse_keyword(tOptions * opts, char const * txt, tOptionValue * typ); -static char* -parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType); +static char const * +parse_set_mem(tOptions * opts, char const * txt, tOptionValue * typ); -static char * -parse_value(char * pzText, tOptionValue * pType); - -static char * -skip_unkn(char* pzText); +static char const * +parse_value(char const * txt, tOptionValue * typ); /* = = = END-STATIC-FORWARD = = = */ +/** + * Skip over some unknown attribute + * @param[in] txt start of skpped text + * @returns character after skipped text + */ +inline static char const * +skip_unkn(char const * txt) +{ + txt = BRK_END_XML_TOKEN_CHARS(txt); + return (*txt == NUL) ? NULL : txt; +} /*=export_func configFileLoad * * what: parse a configuration file - * arg: + char const* + pzFile + the file to load + + * arg: + char const* + fname + the file to load + * * ret_type: const tOptionValue* * ret_desc: An allocated, compound value structure @@ -106,23 +116,22 @@ skip_unkn(char* pzText); * @code{ENOMEM} - not enough memory to allocate the needed structures. * @end itemize =*/ -const tOptionValue* -configFileLoad(char const* pzFile) +const tOptionValue * +configFileLoad(char const * fname) { - tmap_info_t cfgfile; - tOptionValue* pRes = NULL; + tmap_info_t cfgfile; + tOptionValue * res = NULL; tOptionLoadMode save_mode = option_load_mode; - char* pzText = - text_mmap(pzFile, PROT_READ, MAP_PRIVATE, &cfgfile); + char * txt = text_mmap(fname, PROT_READ, MAP_PRIVATE, &cfgfile); - if (TEXT_MMAP_FAILED_ADDR(pzText)) + if (TEXT_MMAP_FAILED_ADDR(txt)) return NULL; /* errno is set */ option_load_mode = OPTION_LOAD_COOKED; - pRes = optionLoadNested(pzText, pzFile, strlen(pzFile)); + res = optionLoadNested(txt, fname, strlen(fname)); - if (pRes == NULL) { + if (res == NULL) { int err = errno; text_munmap(&cfgfile); errno = err; @@ -130,16 +139,16 @@ configFileLoad(char const* pzFile) text_munmap(&cfgfile); option_load_mode = save_mode; - return pRes; + return res; } /*=export_func optionFindValue * * what: find a hierarcicaly valued option instance - * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type + - * arg: + char const* + name + name of value to find + - * arg: + char const* + value + the matching value + + * arg: + const tOptDesc* + odesc + an option with a nested arg type + + * arg: + char const* + name + name of value to find + + * arg: + char const* + val + the matching value + * * ret_type: const tOptionValue* * ret_desc: a compound value structure @@ -158,53 +167,52 @@ configFileLoad(char const* pzFile) * @code{ENOENT} - no entry matched the given name. * @end itemize =*/ -const tOptionValue* -optionFindValue(const tOptDesc* pOptDesc, char const* pzName, - char const* pzVal) +const tOptionValue * +optionFindValue(const tOptDesc * odesc, char const * name, char const * val) { - const tOptionValue* pRes = NULL; + const tOptionValue * res = NULL; - if ( (pOptDesc == NULL) - || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) { + if ( (odesc == NULL) + || (OPTST_GET_ARGTYPE(odesc->fOptState) != OPARG_TYPE_HIERARCHY)) { errno = EINVAL; } - else if (pOptDesc->optCookie == NULL) { + else if (odesc->optCookie == NULL) { errno = ENOENT; } else do { - tArgList* pAL = pOptDesc->optCookie; - int ct = pAL->useCt; - void** ppOV = (void**)(pAL->apzArgs); + tArgList* argl = odesc->optCookie; + int argct = argl->useCt; + void ** poptv = (void**)(argl->apzArgs); - if (ct == 0) { + if (argct == 0) { errno = ENOENT; break; } - if (pzName == NULL) { - pRes = (tOptionValue*)*ppOV; + if (name == NULL) { + res = (tOptionValue*)*poptv; break; } - while (--ct >= 0) { - const tOptionValue* pOV = *(ppOV++); - const tOptionValue* pRV = optionGetValue(pOV, pzName); + while (--argct >= 0) { + const tOptionValue * ov = *(poptv++); + const tOptionValue * rv = optionGetValue(ov, name); - if (pRV == NULL) + if (rv == NULL) continue; - if (pzVal == NULL) { - pRes = pOV; + if (val == NULL) { + res = ov; break; } } - if (pRes == NULL) + if (res == NULL) errno = ENOENT; } while (false); - return pRes; + return res; } @@ -213,7 +221,7 @@ optionFindValue(const tOptDesc* pOptDesc, char const* pzName, * FIXME: the handling of 'pzName' and 'pzVal' is just wrong. * * what: find a hierarcicaly valued option instance - * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type + + * arg: + const tOptDesc* + odesc + an option with a nested arg type + * arg: + const tOptionValue* + pPrevVal + the last entry + * arg: + char const* + name + name of value to find + * arg: + char const* + value + the matching value + @@ -237,43 +245,43 @@ optionFindValue(const tOptDesc* pOptDesc, char const* pzName, * @end itemize =*/ tOptionValue const * -optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal, +optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal, char const * pzName, char const * pzVal) { bool old_found = false; - tOptionValue* pRes = NULL; + tOptionValue* res = NULL; (void)pzName; (void)pzVal; - if ( (pOptDesc == NULL) - || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) { + if ( (odesc == NULL) + || (OPTST_GET_ARGTYPE(odesc->fOptState) != OPARG_TYPE_HIERARCHY)) { errno = EINVAL; } - else if (pOptDesc->optCookie == NULL) { + else if (odesc->optCookie == NULL) { errno = ENOENT; } else do { - tArgList* pAL = pOptDesc->optCookie; - int ct = pAL->useCt; - void** ppOV = (void**)pAL->apzArgs; + tArgList* argl = odesc->optCookie; + int ct = argl->useCt; + void** poptv = (void**)argl->apzArgs; while (--ct >= 0) { - tOptionValue* pOV = *(ppOV++); + tOptionValue* pOV = *(poptv++); if (old_found) { - pRes = pOV; + res = pOV; break; } if (pOV == pPrevVal) old_found = true; } - if (pRes == NULL) + if (res == NULL) errno = ENOENT; } while (false); - return pRes; + return res; } @@ -304,39 +312,38 @@ optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal, * @code{ENOENT} - no entry matched the given name. * @end itemize =*/ -const tOptionValue* -optionGetValue(tOptionValue const * pOld, char const * pzValName) +tOptionValue const * +optionGetValue(tOptionValue const * oov, char const * vname) { - tArgList * pAL; - tOptionValue * pRes = NULL; + tArgList * arg_list; + tOptionValue * res = NULL; - if ((pOld == NULL) || (pOld->valType != OPARG_TYPE_HIERARCHY)) { + if ((oov == NULL) || (oov->valType != OPARG_TYPE_HIERARCHY)) { errno = EINVAL; - return pRes; + return res; } - pAL = pOld->v.nestVal; + arg_list = oov->v.nestVal; - if (pAL->useCt > 0) { - int ct = pAL->useCt; - void ** papOV = (void**)(pAL->apzArgs); + if (arg_list->useCt > 0) { + int ct = arg_list->useCt; + void ** ovlist = (void**)(arg_list->apzArgs); - if (pzValName == NULL) { - pRes = (tOptionValue*)*papOV; + if (vname == NULL) { + res = (tOptionValue*)*ovlist; } else do { - tOptionValue * pOV = *(papOV++); - if (strcmp(pOV->pzName, pzValName) == 0) { - pRes = pOV; + tOptionValue * opt_val = *(ovlist++); + if (strcmp(opt_val->pzName, vname) == 0) { + res = opt_val; break; } } while (--ct > 0); } - if (pRes == NULL) + if (res == NULL) errno = ENOENT; - return pRes; + return res; } - /*=export_func optionNextValue * * what: get the next value from a hierarchical list @@ -365,30 +372,30 @@ optionGetValue(tOptionValue const * pOld, char const * pzValName) * @end itemize =*/ tOptionValue const * -optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV ) +optionNextValue(tOptionValue const * ov_list,tOptionValue const * oov ) { - tArgList* pAL; - tOptionValue* pRes = NULL; - int err = EINVAL; + tArgList * arg_list; + tOptionValue * res = NULL; + int err = EINVAL; - if ((pOVList == NULL) || (pOVList->valType != OPARG_TYPE_HIERARCHY)) { + if ((ov_list == NULL) || (ov_list->valType != OPARG_TYPE_HIERARCHY)) { errno = EINVAL; return NULL; } - pAL = pOVList->v.nestVal; + arg_list = ov_list->v.nestVal; { - int ct = pAL->useCt; - void** papNV = (void**)(pAL->apzArgs); + int ct = arg_list->useCt; + void ** o_list = (void**)(arg_list->apzArgs); while (ct-- > 0) { - tOptionValue* pNV = *(papNV++); - if (pNV == pOldOV) { + tOptionValue * nov = *(o_list++); + if (nov == oov) { if (ct == 0) { err = ENOENT; } else { - err = 0; - pRes = (tOptionValue*)*papNV; + err = 0; + res = (tOptionValue*)*o_list; } break; } @@ -396,20 +403,19 @@ optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV ) } if (err != 0) errno = err; - return pRes; + return res; } - /** * Load a file containing presetting information (a configuration file). */ static void file_preset(tOptions * opts, char const * fname, int dir) { - tmap_info_t cfgfile; - tOptState optst = OPTSTATE_INITIALIZER(PRESET); - unsigned long st_flags = optst.flags; - char * ftext = + tmap_info_t cfgfile; + tOptState optst = OPTSTATE_INITIALIZER(PRESET); + opt_state_mask_t st_flags = optst.flags; + char * ftext = text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile); if (TEXT_MMAP_FAILED_ADDR(ftext)) @@ -456,8 +462,10 @@ file_preset(tOptions * opts, char const * fname, int dir) break; default: - goto all_done; + ftext = NULL; } + if (ftext == NULL) + goto all_done; break; case '[': @@ -473,47 +481,45 @@ file_preset(tOptions * opts, char const * fname, int dir) } } while (ftext != NULL); -all_done: + all_done: text_munmap(&cfgfile); } - /** - * "pzText" points to a "<!" sequence. + * "txt" points to a "<!" sequence. * Theoretically, we should ensure that it begins with "<!--", * but actually I don't care that much. It ends with "-->". */ -static char* -handle_comment(char* pzText) +static char * +handle_comment(char* txt) { - char* pz = strstr(pzText, "-->"); + char* pz = strstr(txt, "-->"); if (pz != NULL) pz += 3; return pz; } - /** - * "pzText" points to the start of some value name. + * "txt" points to the start of some value name. * The end of the entry is the end of the line that is not preceded by * a backslash escape character. The string value is always processed * in "cooked" mode. */ static char * -handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) +handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir) { - char* pzName = pzText++; - char* pzEnd = strchr(pzText, NL); + char* pzName = txt++; + char* pzEnd = strchr(txt, NL); if (pzEnd == NULL) - return pzText + strlen(pzText); + return txt + strlen(txt); - pzText = SPN_VALUE_NAME_CHARS(pzText); - pzText = SPN_WHITESPACE_CHARS(pzText); - if (pzText > pzEnd) { + txt = SPN_VALUE_NAME_CHARS(txt); + txt = SPN_WHITESPACE_CHARS(txt); + if (txt > pzEnd) { name_only: *pzEnd++ = NUL; - loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); + loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } @@ -522,11 +528,11 @@ handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) * or else we must have skipped over white space. Anything else * is an invalid format and we give up parsing the text. */ - if ((*pzText == '=') || (*pzText == ':')) { - pzText = SPN_WHITESPACE_CHARS(pzText+1); - if (pzText > pzEnd) + if ((*txt == '=') || (*txt == ':')) { + txt = SPN_WHITESPACE_CHARS(txt+1); + if (txt > pzEnd) goto name_only; - } else if (! IS_WHITESPACE_CHAR(pzText[-1])) + } else if (! IS_WHITESPACE_CHAR(txt[-1])) return NULL; /* @@ -542,6 +548,7 @@ handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) switch (ch) { case NUL: pcS = NULL; + /* FALLTHROUGH */ case NL: *pcD = NUL; @@ -549,9 +556,8 @@ handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) goto copy_done; case '\\': - if (*pcS == NL) { + if (*pcS == NL) ch = *(pcS++); - } /* FALLTHROUGH */ default: *(pcD++) = ch; @@ -569,19 +575,22 @@ handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); + loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } - /** - * "pzText" points to a "<?" sequence. + * "txt" points to a "<?" sequence. * We handle "<?program" and "<?auto-options" directives. * All others are treated as comments. + * + * @param[in,out] opts program option descriptor + * @param[in] txt scanning pointer + * @returns the next character to look at */ static char * -handle_directive(tOptions * pOpts, char * pzText) +handle_directive(tOptions * opts, char * txt) { # define DIRECTIVE_TABLE \ _dt_(zCfgProg, program_directive) \ @@ -610,112 +619,124 @@ handle_directive(tOptions * pOpts, char * pzText) for (ix = 0; ix < dir_ct; ix++) { size_t len = strlen(dir_names[ix]); - if ( (strncmp(pzText + 2, dir_names[ix], len) == 0) - && (! IS_VALUE_NAME_CHAR(pzText[len+2])) ) - return dir_disp[ix](pOpts, pzText + len + 2); + if ( (strncmp(txt + 2, dir_names[ix], len) == 0) + && (! IS_VALUE_NAME_CHAR(txt[len+2])) ) + return dir_disp[ix](opts, txt + len + 2); } /* * We don't know what this is. Skip it. */ - pzText = strchr(pzText+2, '>'); - if (pzText != NULL) - pzText++; - return pzText; + txt = strchr(txt+2, '>'); + if (txt != NULL) + txt++; + return txt; +# undef DIRECTIVE_TABLE } /** - * handle AutoOpts mode flags + * handle AutoOpts mode flags. + * + * @param[in,out] opts program option descriptor + * @param[in] txt scanning pointer + * @returns the next character to look at */ static char * -aoflags_directive(tOptions * pOpts, char * pzText) +aoflags_directive(tOptions * opts, char * txt) { char * pz; - pz = SPN_WHITESPACE_CHARS(pzText+1); - pzText = strchr(pz, '>'); - if (pzText != NULL) { + pz = SPN_WHITESPACE_CHARS(txt+1); + txt = strchr(pz, '>'); + if (txt != NULL) { - size_t len = pzText - pz; + size_t len = (unsigned)(txt - pz); char * ftxt = AGALOC(len + 1, "aoflags"); memcpy(ftxt, pz, len); ftxt[len] = NUL; - set_usage_flags(pOpts, ftxt); + set_usage_flags(opts, ftxt); AGFREE(ftxt); - pzText++; + txt++; } - return pzText; + return txt; } /** * handle program segmentation of config file. + * + * @param[in,out] opts program option descriptor + * @param[in] txt scanning pointer + * @returns the next character to look at */ static char * -program_directive(tOptions * pOpts, char * pzText) +program_directive(tOptions * opts, char * txt) { static char const ttlfmt[] = "<?"; size_t ttl_len = sizeof(ttlfmt) + strlen(zCfgProg); char * ttl = AGALOC(ttl_len, "prog title"); - size_t name_len = strlen(pOpts->pzProgName); + size_t name_len = strlen(opts->pzProgName); memcpy(ttl, ttlfmt, sizeof(ttlfmt) - 1); memcpy(ttl + sizeof(ttlfmt) - 1, zCfgProg, ttl_len - (sizeof(ttlfmt) - 1)); do { - pzText = SPN_WHITESPACE_CHARS(pzText+1); + txt = SPN_WHITESPACE_CHARS(txt+1); - if ( (strneqvcmp(pzText, pOpts->pzProgName, (int)name_len) == 0) - && (IS_END_XML_TOKEN_CHAR(pzText[name_len])) ) { - pzText += name_len; + if ( (strneqvcmp(txt, opts->pzProgName, (int)name_len) == 0) + && (IS_END_XML_TOKEN_CHAR(txt[name_len])) ) { + txt += name_len; break; } - pzText = strstr(pzText, ttl); - } while (pzText != NULL); + txt = strstr(txt, ttl); + } while (txt != NULL); AGFREE(ttl); - if (pzText != NULL) + if (txt != NULL) for (;;) { - if (*pzText == NUL) { - pzText = NULL; + if (*txt == NUL) { + txt = NULL; break; } - if (*(pzText++) == '>') + if (*(txt++) == '>') break; } - return pzText; + return txt; } - /** - * "pzText" points to a '[' character. + * "txt" points to a '[' character. * The "traditional" [PROG_NAME] segmentation of the config file. * Do not ever mix with the "<?program prog-name>" variation. + * + * @param[in,out] opts program option descriptor + * @param[in] txt scanning pointer + * @returns the next character to look at */ static char * -handle_section(tOptions * pOpts, char * pzText) +handle_section(tOptions * opts, char * txt) { - size_t len = strlen(pOpts->pzPROGNAME); - if ( (strncmp(pzText+1, pOpts->pzPROGNAME, len) == 0) - && (pzText[len+1] == ']')) - return strchr(pzText + len + 2, NL); + size_t len = strlen(opts->pzPROGNAME); + if ( (strncmp(txt+1, opts->pzPROGNAME, len) == 0) + && (txt[len+1] == ']')) + return strchr(txt + len + 2, NL); if (len > 16) return NULL; { char z[24]; - sprintf(z, "[%s]", pOpts->pzPROGNAME); - pzText = strstr(pzText, z); + sprintf(z, "[%s]", opts->pzPROGNAME); + txt = strstr(txt, z); } - if (pzText != NULL) - pzText = strchr(pzText, NL); - return pzText; + if (txt != NULL) + txt = strchr(txt, NL); + return txt; } /** @@ -820,7 +841,7 @@ trim_xml_text(char * intxt, char const * pznm, tOptionLoadMode mode) if (len >= sizeof(z)) pz = AGALOC(len, "scan name"); - len = sprintf(pz, fmt, pznm); + len = (size_t)sprintf(pz, fmt, pznm); *intxt = ' '; etext = strstr(intxt, pz); if (pz != z) AGFREE(pz); @@ -872,7 +893,7 @@ cook_xml_text(char * pzData) return; } - ch = strtoul(bf, NULL, 16); + ch = (int)strtoul(bf, NULL, 16); /* FALLTHROUGH */ default: @@ -882,67 +903,70 @@ cook_xml_text(char * pzData) } /** - * "pzText" points to a '<' character, followed by an alpha. + * "txt" points to a '<' character, followed by an alpha. * The end of the entry is either the "/>" following the name, or else a * "</name>" string. */ static char * -handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) +handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir) { tOptionLoadMode mode = option_load_mode; tOptionValue valu; - char* pzName = ++pzText; + char* pzName = ++txt; char* pzData; char* pcNulPoint; - pzText = SPN_VALUE_NAME_CHARS(pzText); - pcNulPoint = pzText; + txt = SPN_VALUE_NAME_CHARS(txt); + pcNulPoint = txt; valu.valType = OPARG_TYPE_STRING; - switch (*pzText) { + switch (*txt) { case ' ': case '\t': - pzText = parse_attrs(pOpts, pzText, &mode, &valu); - if (*pzText == '>') + txt = (void *)parse_attrs( + opts, SPN_WHITESPACE_CHARS(txt), &mode, &valu); + if (txt == NULL) + return txt; + if (*txt == '>') break; - if (*pzText != '/') + if (*txt != '/') return NULL; /* FALLTHROUGH */ case '/': - if (pzText[1] != '>') + if (txt[1] != '>') return NULL; - *pzText = NUL; - pzText += 2; - loadOptionLine(pOpts, pOS, pzName, dir, mode); - return pzText; + *txt = NUL; + txt += 2; + loadOptionLine(opts, ost, pzName, dir, mode); + return txt; case '>': break; default: - pzText = strchr(pzText, '>'); - if (pzText != NULL) - pzText++; - return pzText; + txt = strchr(txt, '>'); + if (txt != NULL) + txt++; + return txt; } /* - * If we are here, we have a value. "pzText" points to a closing angle + * If we are here, we have a value. "txt" points to a closing angle * bracket. Separate the name from the value for a moment. */ *pcNulPoint = NUL; - pzData = ++pzText; - pzText = trim_xml_text(pzText, pzName, mode); - if (pzText == NULL) - return pzText; + pzData = ++txt; + txt = trim_xml_text(txt, pzName, mode); + if (txt == NULL) + return txt; /* * Rejoin the name and value for parsing by "loadOptionLine()". * Erase any attributes parsed by "parse_attrs()". */ - memset(pcNulPoint, ' ', pzData - pcNulPoint); + memset(pcNulPoint, ' ', (size_t)(pzData - pcNulPoint)); /* * If we are getting a "string" value that is to be cooked, @@ -956,40 +980,39 @@ handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine(pOpts, pOS, pzName, dir, mode); + loadOptionLine(opts, ost, pzName, dir, mode); - return pzText; + return txt; } - /** * Load a configuration file. This may be invoked either from * scanning the "homerc" list, or from a specific file request. * (see "optionFileLoad()", the implementation for --load-opts) */ LOCAL void -intern_file_load(tOptions* pOpts) +intern_file_load(tOptions * opts) { uint32_t svfl; int idx; int inc; - char zFileName[ AG_PATH_MAX+1 ]; + char f_name[ AG_PATH_MAX+1 ]; - if (pOpts->papzHomeList == NULL) + if (opts->papzHomeList == NULL) return; - svfl = pOpts->fOptSet; + svfl = opts->fOptSet; inc = DIRECTION_PRESET; /* * Never stop on errors in config files. */ - pOpts->fOptSet &= ~OPTPROC_ERRSTOP; + opts->fOptSet &= ~OPTPROC_ERRSTOP; /* * Find the last RC entry (highest priority entry) */ - for (idx = 0; pOpts->papzHomeList[ idx+1 ] != NULL; ++idx) ; + for (idx = 0; opts->papzHomeList[ idx+1 ] != NULL; ++idx) ; /* * For every path in the home list, ... *TWICE* We start at the last @@ -998,8 +1021,8 @@ intern_file_load(tOptions* pOpts) * Then we go back up, doing the normal options. */ for (;;) { - struct stat StatBuf; - cch_t* pzPath; + struct stat sb; + cch_t * path; /* * IF we've reached the bottom end, change direction @@ -1009,18 +1032,18 @@ intern_file_load(tOptions* pOpts) idx = 0; } - pzPath = pOpts->papzHomeList[ idx ]; + path = opts->papzHomeList[ idx ]; /* * IF we've reached the top end, bail out */ - if (pzPath == NULL) + if (path == NULL) break; idx += inc; - if (! optionMakePath(zFileName, (int)sizeof(zFileName), - pzPath, pOpts->pzProgPath)) + if (! optionMakePath(f_name, (int)sizeof(f_name), + path, opts->pzProgPath)) continue; /* @@ -1028,47 +1051,46 @@ intern_file_load(tOptions* pOpts) * THEN append the Resource Configuration file name * ELSE we must have the complete file name */ - if (stat(zFileName, &StatBuf) != 0) + if (stat(f_name, &sb) != 0) continue; /* bogus name - skip the home list entry */ - if (S_ISDIR(StatBuf.st_mode)) { - size_t len = strlen(zFileName); - size_t nln = strlen(pOpts->pzRcName) + 1; - char * pz = zFileName + len; + if (S_ISDIR(sb.st_mode)) { + size_t len = strlen(f_name); + size_t nln = strlen(opts->pzRcName) + 1; + char * pz = f_name + len; - if (len + 1 + nln >= sizeof(zFileName)) + if (len + 1 + nln >= sizeof(f_name)) continue; if (pz[-1] != DIRCH) *(pz++) = DIRCH; - memcpy(pz, pOpts->pzRcName, nln); + memcpy(pz, opts->pzRcName, nln); } - file_preset(pOpts, zFileName, inc); + file_preset(opts, f_name, inc); /* * IF we are now to skip config files AND we are presetting, * THEN change direction. We must go the other way. */ { - tOptDesc * pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts+1; - if (DISABLED_OPT(pOD) && PRESETTING(inc)) { + tOptDesc * od = opts->pOptDesc + opts->specOptIdx.save_opts + 1; + if (DISABLED_OPT(od) && PRESETTING(inc)) { idx -= inc; /* go back and reprocess current file */ inc = DIRECTION_PROCESS; } } } /* twice for every path in the home list, ... */ - pOpts->fOptSet = svfl; + opts->fOptSet = svfl; } - /*=export_func optionFileLoad * * what: Load the locatable config files, in order * - * arg: + tOptions* + pOpts + program options descriptor + - * arg: + char const* + pzProg + program name + + * arg: + tOptions* + opts + program options descriptor + + * arg: + char const* + prog + program name + * * ret_type: int * ret_desc: 0 -> SUCCESS, -1 -> FAILURE @@ -1097,330 +1119,254 @@ intern_file_load(tOptions* pOpts) * always be returned. =*/ int -optionFileLoad(tOptions * pOpts, char const * pzProgram) +optionFileLoad(tOptions * opts, char const * prog) { - if (! SUCCESSFUL(validate_struct(pOpts, pzProgram))) + if (! SUCCESSFUL(validate_struct(opts, prog))) return -1; + /* + * The pointer to the program name is "const". However, the + * structure is in writable memory, so we coerce the address + * of this pointer to point to writable memory. + */ { char const ** pp = - (char const **)(void *)&(pOpts->pzProgName); - *pp = pzProgram; + (char const **)(void *)&(opts->pzProgName); + *pp = prog; } - intern_file_load(pOpts); + intern_file_load(opts); return 0; } - /*=export_func optionLoadOpt * private: * * what: Load an option rc/ini file - * arg: + tOptions* + pOpts + program options descriptor + - * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * arg: + tOptions* + opts + program options descriptor + + * arg: + tOptDesc* + odesc + the descriptor for this arg + * * doc: * Processes the options found in the file named with - * pOptDesc->optArg.argString. + * odesc->optArg.argString. =*/ void -optionLoadOpt(tOptions * pOpts, tOptDesc * pOptDesc) +optionLoadOpt(tOptions * opts, tOptDesc * odesc) { struct stat sb; + if (opts <= OPTPROC_EMIT_LIMIT) + return; + /* * IF the option is not being disabled, THEN load the file. There must * be a file. (If it is being disabled, then the disablement processing * already took place. It must be done to suppress preloading of ini/rc * files.) */ - if ( DISABLED_OPT(pOptDesc) - || ((pOptDesc->fOptState & OPTST_RESET) != 0)) + if ( DISABLED_OPT(odesc) + || ((odesc->fOptState & OPTST_RESET) != 0)) return; - if (stat(pOptDesc->optArg.argString, &sb) != 0) { - if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) + if (stat(odesc->optArg.argString, &sb) != 0) { + if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0) return; - fprintf(stderr, zFSErrOptLoad, errno, strerror(errno), - pOptDesc->optArg.argString); - exit(EX_NOINPUT); + fserr_exit(opts->pzProgName, "stat", odesc->optArg.argString); /* NOT REACHED */ } if (! S_ISREG(sb.st_mode)) { - if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) + if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0) return; - - fprintf(stderr, zNotFile, pOptDesc->optArg.argString); - exit(EX_NOINPUT); + errno = EINVAL; + fserr_exit(opts->pzProgName, "stat", odesc->optArg.argString); /* NOT REACHED */ } - file_preset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED); + file_preset(opts, odesc->optArg.argString, DIRECTION_CALLED); } - /** * Parse the various attributes of an XML-styled config file entry + * + * @returns NULL on failure, otherwise the scan point */ -LOCAL char* -parse_attrs(tOptions * pOpts, char * pzText, tOptionLoadMode * pMode, +LOCAL char const * +parse_attrs(tOptions * opts, char const * txt, tOptionLoadMode * pMode, tOptionValue * pType) { - size_t len; - - do { - if (! IS_WHITESPACE_CHAR(*pzText)) - switch (*pzText) { - case '/': pType->valType = OPARG_TYPE_NONE; - case '>': return pzText; - - default: - case NUL: return NULL; - } + size_t len = 0; - pzText = SPN_WHITESPACE_CHARS(pzText+1); - len = SPN_LOWER_CASE_CHARS(pzText) - pzText; + for (;;) { + len = (size_t)(SPN_LOWER_CASE_CHARS(txt) - txt); - switch (find_xat_attribute_id(pzText, len)) { - case XAT_KWD_TYPE: - pzText = parse_value(pzText+len, pType); + /* + * The enumeration used in this switch is derived from this switch + * statement itself. The "find_option_xat_attribute_cmd" function + * will return XAT_CMD_MEMBERS for the "txt" string value + * "members", etc. + */ + switch (find_option_xat_attribute_cmd(txt, len)) { + case XAT_CMD_TYPE: + txt = parse_value(txt+len, pType); break; - case XAT_KWD_WORDS: - pzText = parse_keyword(pOpts, pzText+len, pType); + case XAT_CMD_WORDS: + txt = parse_keyword(opts, txt+len, pType); break; - case XAT_KWD_MEMBERS: - pzText = parse_set_mem(pOpts, pzText+len, pType); + case XAT_CMD_MEMBERS: + txt = parse_set_mem(opts, txt+len, pType); break; - case XAT_KWD_COOKED: - pzText += len; - if (! IS_END_XML_TOKEN_CHAR(*pzText)) + case XAT_CMD_COOKED: + txt += len; + if (! IS_END_XML_TOKEN_CHAR(*txt)) goto invalid_kwd; *pMode = OPTION_LOAD_COOKED; break; - case XAT_KWD_UNCOOKED: - pzText += len; - if (! IS_END_XML_TOKEN_CHAR(*pzText)) + case XAT_CMD_UNCOOKED: + txt += len; + if (! IS_END_XML_TOKEN_CHAR(*txt)) goto invalid_kwd; *pMode = OPTION_LOAD_UNCOOKED; break; - case XAT_KWD_KEEP: - pzText += len; - if (! IS_END_XML_TOKEN_CHAR(*pzText)) + case XAT_CMD_KEEP: + txt += len; + if (! IS_END_XML_TOKEN_CHAR(*txt)) goto invalid_kwd; *pMode = OPTION_LOAD_KEEP; break; default: - case XAT_KWD_INVALID: + case XAT_INVALID_CMD: invalid_kwd: pType->valType = OPARG_TYPE_NONE; - return skip_unkn(pzText); + return skip_unkn(txt); } - } while (pzText != NULL); - return pzText; + if (txt == NULL) + return NULL; + txt = SPN_WHITESPACE_CHARS(txt); + switch (*txt) { + case '/': pType->valType = OPARG_TYPE_NONE; + /* FALLTHROUGH */ + case '>': return txt; + } + if (! IS_LOWER_CASE_CHAR(*txt)) + return NULL; + } } - /** - * "pzText" points to the character after "words=". + * "txt" points to the character after "words=". * What should follow is a name of a keyword (enumeration) list. + * + * @param opts unused + * @param[in] txt keyword to skip over + * @param type unused value type + * @returns pointer after skipped text */ -static char* -parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType) +static char const * +parse_keyword(tOptions * opts, char const * txt, tOptionValue * typ) { - (void)pOpts; - (void)pType; + (void)opts; + (void)typ; - return skip_unkn(pzText); + return skip_unkn(txt); } - /** - * "pzText" points to the character after "members=" + * "txt" points to the character after "members=" * What should follow is a name of a "set membership". * A collection of bit flags. + * + * @param opts unused + * @param[in] txt keyword to skip over + * @param type unused value type + * @returns pointer after skipped text */ -static char* -parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType) +static char const * +parse_set_mem(tOptions * opts, char const * txt, tOptionValue * typ) { - (void)pOpts; - (void)pType; + (void)opts; + (void)typ; - return skip_unkn(pzText); + return skip_unkn(txt); } - /** - * "pzText" points to the character after "type=" + * parse the type. The keyword "type" was found, now figure out + * the type that follows the type. + * + * @param[in] txt points to the '=' character after the "type" keyword. + * @param[out] typ where to store the type found + * @returns the next byte after the type name */ -static char * -parse_value(char * pzText, tOptionValue * pType) +static char const * +parse_value(char const * txt, tOptionValue * typ) { size_t len = 0; - if (*(pzText++) != '=') + if (*(txt++) != '=') goto woops; - len = SPN_OPTION_NAME_CHARS(pzText) - pzText; + len = (size_t)(SPN_OPTION_NAME_CHARS(txt) - txt); - if ((len == 0) || (! IS_END_XML_TOKEN_CHAR(pzText[len]))) { + if ((len == 0) || (! IS_END_XML_TOKEN_CHAR(txt[len]))) { woops: - pType->valType = OPARG_TYPE_NONE; - return skip_unkn(pzText + len); + typ->valType = OPARG_TYPE_NONE; + return skip_unkn(txt + len); } - switch (find_value_type_id(pzText, len)) { + /* + * The enumeration used in this switch is derived from this switch + * statement itself. The "find_option_value_type_cmd" function + * will return VTP_CMD_INTEGER for the "txt" string value + * "integer", etc. + */ + switch (find_option_value_type_cmd(txt, len)) { default: - case VTP_KWD_INVALID: goto woops; + case VTP_INVALID_CMD: goto woops; - case VTP_KWD_STRING: - pType->valType = OPARG_TYPE_STRING; + case VTP_CMD_STRING: + typ->valType = OPARG_TYPE_STRING; break; - case VTP_KWD_INTEGER: - pType->valType = OPARG_TYPE_NUMERIC; + case VTP_CMD_INTEGER: + typ->valType = OPARG_TYPE_NUMERIC; break; - case VTP_KWD_BOOL: - case VTP_KWD_BOOLEAN: - pType->valType = OPARG_TYPE_BOOLEAN; + case VTP_CMD_BOOL: + case VTP_CMD_BOOLEAN: + typ->valType = OPARG_TYPE_BOOLEAN; break; - case VTP_KWD_KEYWORD: - pType->valType = OPARG_TYPE_ENUMERATION; + case VTP_CMD_KEYWORD: + typ->valType = OPARG_TYPE_ENUMERATION; break; - case VTP_KWD_SET: - case VTP_KWD_SET_MEMBERSHIP: - pType->valType = OPARG_TYPE_MEMBERSHIP; + case VTP_CMD_SET: + case VTP_CMD_SET_MEMBERSHIP: + typ->valType = OPARG_TYPE_MEMBERSHIP; break; - case VTP_KWD_NESTED: - case VTP_KWD_HIERARCHY: - pType->valType = OPARG_TYPE_HIERARCHY; + case VTP_CMD_NESTED: + case VTP_CMD_HIERARCHY: + typ->valType = OPARG_TYPE_HIERARCHY; } - return pzText + len; -} - - -/** - * Skip over some unknown attribute - */ -static char * -skip_unkn(char* pzText) -{ - for (;; pzText++) { - if (IS_END_XML_TOKEN_CHAR(*pzText)) return pzText; - if (*pzText == NUL) return NULL; - } + return txt + len; } - -/** - * 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 pOpts program options descriptor - * @param pzProgram name of program, from argv[] - * @returns SUCCESS or FAILURE - */ -LOCAL tSuccess -validate_struct(tOptions * pOpts, char const * pzProgram) -{ - if (pOpts == NULL) { - fputs(zAO_Bad, stderr); - return FAILURE; - } - - /* - * IF the client has enabled translation and the translation procedure - * is available, then go do it. - */ - if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0) - && (pOpts->pTransProc != NULL) ) { - /* - * 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 ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT) - pOpts->fOptSet |= OPTPROC_NXLAT_OPT_CFG; - (*pOpts->pTransProc)(); - pOpts->fOptSet &= ~OPTPROC_TRANSLATE; - } - - /* - * IF the struct version is not the current, and also - * either too large (?!) or too small, - * THEN emit error message and fail-exit - */ - if ( ( pOpts->structVersion != OPTIONS_STRUCT_VERSION ) - && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) - || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION ) - ) ) { - static char const aover[] = - STR(AO_CURRENT)":"STR(AO_REVISION)":"STR(AO_AGE)"\n"; - - fprintf(stderr, zAO_Err, pzProgram, NUM_TO_VER(pOpts->structVersion)); - if (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) - fputs(zAO_Big, stderr); - else - fputs(zAO_Sml, stderr); - - fwrite(aover, sizeof(aover) - 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 (pOpts->pzProgName == NULL) { - char const * pz = strrchr(pzProgram, DIRCH); - char const ** pp = - (char const **)(void **)&(pOpts->pzProgName); - - if (pz != NULL) { - *pp = pz+1; - } else { - *pp = pzProgram; - pz = pathfind(getenv("PATH"), (char *)pzProgram, "rx"); - if (pz != NULL) - pzProgram = (void *)pz; - } - - pp = (char const **)(void **)&(pOpts->pzProgPath); - *pp = pzProgram; - - /* - * when comparing long names, these are equivalent - */ - strequate(zSepChars); - } - - return SUCCESS; -} - - -/** * Local Variables: * mode: C * c-file-style: "stroustrup" diff --git a/src/libopts/cook.c b/src/libopts/cook.c index f34a6edd78..7c08b87dd4 100644 --- a/src/libopts/cook.c +++ b/src/libopts/cook.c @@ -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; + + z[ct++] = *--pzIn; + while (IS_OCT_DIGIT_CHAR(pzIn[ct])) { + z[ct] = pzIn[ct]; + if (++ct >= 3) + break; + } - while (IS_OCT_DIGIT_CHAR(*pzIn) && (pz < z + 3)) - *(pz++) = *(pzIn++); - *pz = NUL; + 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" diff --git a/src/libopts/enum.c b/src/libopts/enum.c index 2a9f9bc2b5..6529083b0c 100644 --- a/src/libopts/enum.c +++ b/src/libopts/enum.c @@ -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,14 +41,10 @@ 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) { @@ -334,17 +336,6 @@ optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD, } 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 */ diff --git a/src/libopts/env.c b/src/libopts/env.c index 4dd18faaba..dacb55121c 100644 --- a/src/libopts/env.c +++ b/src/libopts/env.c @@ -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" diff --git a/src/libopts/file.c b/src/libopts/file.c index 5a5b3eb53f..9218b5f43a 100644 --- a/src/libopts/file.c +++ b/src/libopts/file.c @@ -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" diff --git a/src/libopts/find.c b/src/libopts/find.c index f6510ee745..e3534291d1 100644 --- a/src/libopts/find.c +++ b/src/libopts/find.c @@ -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 (opts->curOptIdx > opts->origArgCt) { + fprintf(stderr, zMisArg, opts->pzProgPath, o_st->pOD->pz_Name); + return FAILURE; + } - if ((pOptState->flags & OPTST_DISABLED) != 0) - arg_type = ARG_NONE; + opts->pzCurOpt = NULL; /* next time advance to next arg */ + return SUCCESS; +} - else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE) - arg_type = ARG_NONE; +/** + * 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 ]; - else if (pOptState->flags & OPTST_ARG_OPTIONAL) - arg_type = ARG_MAY; + /* + * 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; - else - arg_type = ARG_MUST; + 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 ]; - 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; + /* + * 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; - return res; + 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; } /** - * Find the option descriptor for the current option + * 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" diff --git a/src/libopts/genshell.c b/src/libopts/genshell.c index 16ca245081..3d4f63be30 100644 --- a/src/libopts/genshell.c +++ b/src/libopts/genshell.c @@ -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> + * + * 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. * - * 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 + * 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); - - 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)); + /* prevent re-translation and disable "libopts" domain lookup */ + option_xlateable_txt.field_ct = 0; + + 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 diff --git a/src/libopts/genshell.h b/src/libopts/genshell.h index d91c069e1e..37ecc3bc7b 100644 --- a/src/libopts/genshell.h +++ b/src/libopts/genshell.h @@ -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); diff --git a/src/libopts/gettext.h b/src/libopts/gettext.h new file mode 100644 index 0000000000..5cd8d6d1e8 --- /dev/null +++ b/src/libopts/gettext.h @@ -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 */ diff --git a/src/libopts/init.c b/src/libopts/init.c new file mode 100644 index 0000000000..25dc07bd05 --- /dev/null +++ b/src/libopts/init.c @@ -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 */ diff --git a/src/libopts/libopts.c b/src/libopts/libopts.c index 07cc035781..a0ff362474 100644 --- a/src/libopts/libopts.c +++ b/src/libopts/libopts.c @@ -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" diff --git a/src/libopts/load.c b/src/libopts/load.c index 1ea7808061..7f69cdad00 100644 --- a/src/libopts/load.c +++ b/src/libopts/load.c @@ -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" diff --git a/src/libopts/m4/libopts.m4 b/src/libopts/m4/libopts.m4 index ce083de1f7..1de161a2f9 100644 --- a/src/libopts/m4/libopts.m4 +++ b/src/libopts/m4/libopts.m4 @@ -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 diff --git a/src/libopts/m4/liboptschk.m4 b/src/libopts/m4/liboptschk.m4 index 4a45bdefc6..b607191bec 100644 --- a/src/libopts/m4/liboptschk.m4 +++ b/src/libopts/m4/liboptschk.m4 @@ -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 : diff --git a/src/libopts/makeshell.c b/src/libopts/makeshell.c index d2ce6615b8..f22e9f0b84 100644 --- a/src/libopts/makeshell.c +++ b/src/libopts/makeshell.c @@ -2,14 +2,16 @@ /** * \file makeshell.c * - * Time-stamp: "2012-04-07 09:03:16 bkorb" - * * This module will interpret the options set in the tOptions * structure and create a Bourne shell script capable of parsing them. * + * @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,59 +23,72 @@ * 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 <config.h> - -/* Work around problem reported in - <http://permalink.gmane.org/gmane.comp.lib.gnulib.bugs/15755>.*/ -#if GETTIMEOFDAY_CLOBBERS_LOCALTIME -#undef localtime -#endif - tOptions * optionParseShellOptions = NULL; static char const * shell_prog = NULL; static char * script_leader = NULL; static char * script_trailer = NULL; +static char * script_text = NULL; /* = = = START-STATIC-FORWARD = = = */ static void emit_var_text(char const * prog, char const * var, int fdin); static void -text_to_var(tOptions * pOpts, teTextTo whichVar, tOptDesc * pOD); +text_to_var(tOptions * opts, teTextTo which, tOptDesc * od); + +static void +emit_usage(tOptions * opts); static void -emit_usage(tOptions * pOpts); +emit_wrapup(tOptions * opts); static void -emit_setup(tOptions * pOpts); +emit_setup(tOptions * opts); static void -emit_action(tOptions * pOpts, tOptDesc* pOptDesc); +emit_action(tOptions * opts, tOptDesc * od); static void -emit_inaction(tOptions * pOpts, tOptDesc* pOptDesc); +emit_inaction(tOptions * opts, tOptDesc * od); static void -emit_flag(tOptions * pOpts); +emit_flag(tOptions * opts); static void -emit_match_expr(char const * pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts); +emit_match_expr(char const * name, tOptDesc * cod, tOptions * opts); static void -emitLong(tOptions * pOpts); +emit_long(tOptions * opts); + +static char * +load_old_output(char const * fname, char const * pname); static void -open_out(char const * pzFile); +open_out(char const * fname, char const * pname); /* = = = END-STATIC-FORWARD = = = */ +LOCAL void +fserr_warn(char const * prog, char const * op, char const * fname) +{ + fprintf(stderr, zfserr_fmt, prog, errno, strerror(errno), + op, fname); +} + +LOCAL void +fserr_exit(char const * prog, char const * op, char const * fname) +{ + fserr_warn(prog, op, fname); + exit(EXIT_FAILURE); +} + /*=export_func optionParseShell * private: * @@ -84,7 +99,7 @@ open_out(char const * pzFile); * Emit a shell script that will parse the command line options. =*/ void -optionParseShell(tOptions * pOpts) +optionParseShell(tOptions * opts) { /* * Check for our SHELL option now. @@ -106,22 +121,22 @@ optionParseShell(tOptions * pOpts) * Check for a specified output file */ if (HAVE_GENSHELL_OPT(SCRIPT)) - open_out(GENSHELL_OPT_ARG(SCRIPT)); - - emit_usage(pOpts); - emit_setup(pOpts); + open_out(GENSHELL_OPT_ARG(SCRIPT), opts->pzProgName); + + emit_usage(opts); + emit_setup(opts); /* * There are four modes of option processing. */ - switch (pOpts->fOptSet & (OPTPROC_LONGOPT|OPTPROC_SHORTOPT)) { + switch (opts->fOptSet & (OPTPROC_LONGOPT|OPTPROC_SHORTOPT)) { case OPTPROC_LONGOPT: fputs(LOOP_STR, stdout); fputs(LONG_OPT_MARK, stdout); fputs(INIT_LOPT_STR, stdout); - emitLong(pOpts); - printf(LOPT_ARG_FMT, pOpts->pzPROGNAME); + emit_long(opts); + printf(LOPT_ARG_FMT, opts->pzPROGNAME); fputs(END_OPT_SEL_STR, stdout); fputs(NOT_FOUND_STR, stdout); @@ -130,8 +145,8 @@ optionParseShell(tOptions * pOpts) case 0: fputs(ONLY_OPTS_LOOP, stdout); fputs(INIT_LOPT_STR, stdout); - emitLong(pOpts); - printf(LOPT_ARG_FMT, pOpts->pzPROGNAME); + emit_long(opts); + printf(LOPT_ARG_FMT, opts->pzPROGNAME); break; case OPTPROC_SHORTOPT: @@ -139,8 +154,8 @@ optionParseShell(tOptions * pOpts) fputs(FLAG_OPT_MARK, stdout); fputs(INIT_OPT_STR, stdout); - emit_flag(pOpts); - printf(OPT_ARG_FMT, pOpts->pzPROGNAME); + emit_flag(opts); + printf(OPT_ARG_FMT, opts->pzPROGNAME); fputs(END_OPT_SEL_STR, stdout); fputs(NOT_FOUND_STR, stdout); @@ -151,38 +166,53 @@ optionParseShell(tOptions * pOpts) fputs(LONG_OPT_MARK, stdout); fputs(INIT_LOPT_STR, stdout); - emitLong(pOpts); - printf(LOPT_ARG_FMT, pOpts->pzPROGNAME); + emit_long(opts); + printf(LOPT_ARG_FMT, opts->pzPROGNAME); fputs(END_OPT_SEL_STR, stdout); fputs(FLAG_OPT_MARK, stdout); fputs(INIT_OPT_STR, stdout); - emit_flag(pOpts); - printf(OPT_ARG_FMT, pOpts->pzPROGNAME); + emit_flag(opts); + printf(OPT_ARG_FMT, opts->pzPROGNAME); fputs(END_OPT_SEL_STR, stdout); fputs(NOT_FOUND_STR, stdout); break; } - printf(zLoopEnd, pOpts->pzPROGNAME, END_MARK); + emit_wrapup(opts); if ((script_trailer != NULL) && (*script_trailer != NUL)) fputs(script_trailer, stdout); else if (ENABLED_GENSHELL_OPT(SHELL)) - printf(SHOW_PROG_ENV, pOpts->pzPROGNAME); + printf(SHOW_PROG_ENV, opts->pzPROGNAME); #ifdef HAVE_FCHMOD fchmod(STDOUT_FILENO, 0755); #endif fclose(stdout); - if (ferror(stdout)) { - fputs(zOutputFail, stderr); - exit(EXIT_FAILURE); - } + if (ferror(stdout)) + fserr_exit(opts->pzProgName, zwriting, zstdout_name); + + AGFREE(script_text); + script_leader = NULL; + script_trailer = NULL; + script_text = NULL; } #ifdef HAVE_WORKING_FORK +/** + * Print the value of "var" to a file descriptor. + * The "fdin" is the read end of a pipe to a forked process that + * is writing usage text to it. We read that text in and re-emit + * to standard out, formatting it so that it is assigned to a + * shell variable. + * + * @param[in] prog The capitalized, c-variable-formatted program name + * @param[in] var a similarly formatted type name + * (LONGUSAGE, USAGE or VERSION) + * @param[in] fdin the input end of a pipe + */ static void emit_var_text(char const * prog, char const * var, int fdin) { @@ -206,11 +236,11 @@ emit_var_text(char const * prog, char const * var, int fdin) fputc(NL, stdout); nlct--; } - fputs(apostrophy, stdout); + fputs(apostrophe, stdout); break; case EOF: - goto endCharLoop; + goto done; default: while (nlct > 0) { @@ -220,97 +250,102 @@ emit_var_text(char const * prog, char const * var, int fdin) fputc(ch, stdout); break; } - } endCharLoop:; + } done:; fclose(fp); -skip_text: + skip_text: fputs(END_SET_TEXT, stdout); } - #endif -/* +/** * The purpose of this function is to assign "long usage", short usage * and version information to a shell variable. Rather than wind our * way through all the logic necessary to emit the text directly, we * fork(), have our child process emit the text the normal way and * capture the output in the parent process. + * + * @param[in] opts the program options + * @param[in] which what to print: long usage, usage or version + * @param[in] od for TT_VERSION, it is the version option */ static void -text_to_var(tOptions * pOpts, teTextTo whichVar, tOptDesc * pOD) +text_to_var(tOptions * opts, teTextTo which, tOptDesc * od) { # define _TT_(n) static char const z ## n [] = #n; TEXTTO_TABLE # undef _TT_ # define _TT_(n) z ## n , - static char const * apzTTNames[] = { TEXTTO_TABLE }; + static char const * ttnames[] = { TEXTTO_TABLE }; # undef _TT_ #if ! defined(HAVE_WORKING_FORK) - printf(SET_NO_TEXT_FMT, pOpts->pzPROGNAME, apzTTNames[ whichVar]); + printf(SET_NO_TEXT_FMT, opts->pzPROGNAME, ttnames[which]); #else - int pipeFd[2]; + int fdpair[2]; fflush(stdout); fflush(stderr); - if (pipe(pipeFd) != 0) { - fprintf(stderr, zBadPipe, errno, strerror(errno)); - exit(EXIT_FAILURE); - } + if (pipe(fdpair) != 0) + fserr_exit(opts->pzProgName, "pipe", zinter_proc_pipe); switch (fork()) { case -1: - fprintf(stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName); - exit(EXIT_FAILURE); - break; + fserr_exit(opts->pzProgName, "fork", opts->pzProgName); + /* NOTREACHED */ case 0: /* * Send both stderr and stdout to the pipe. No matter which * descriptor is used, we capture the output on the read end. */ - dup2(pipeFd[1], STDERR_FILENO); - dup2(pipeFd[1], STDOUT_FILENO); - close(pipeFd[0]); + dup2(fdpair[1], STDERR_FILENO); + dup2(fdpair[1], STDOUT_FILENO); + close(fdpair[0]); - switch (whichVar) { + switch (which) { case TT_LONGUSAGE: - (*(pOpts->pUsageProc))(pOpts, EXIT_SUCCESS); + (*(opts->pUsageProc))(opts, EXIT_SUCCESS); /* NOTREACHED */ case TT_USAGE: - (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); + (*(opts->pUsageProc))(opts, EXIT_FAILURE); /* NOTREACHED */ case TT_VERSION: - 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.argString = "c"; - optionPrintVersion(pOpts, pOD); + od->optArg.argString = "c"; + optionPrintVersion(opts, od); /* NOTREACHED */ default: exit(EXIT_FAILURE); + /* NOTREACHED */ } + /* NOTREACHED */ default: - close(pipeFd[1]); + close(fdpair[1]); } - emit_var_text(pOpts->pzPROGNAME, apzTTNames[whichVar], pipeFd[0]); + emit_var_text(opts->pzPROGNAME, ttnames[which], fdpair[0]); #endif } - +/** + * capture usage text in shell variables. + * + */ static void -emit_usage(tOptions * pOpts) +emit_usage(tOptions * opts) { - char zTimeBuf[AO_NAME_SIZE]; + char tm_nm_buf[AO_NAME_SIZE]; /* * First, switch stdout to the output file name. @@ -327,7 +362,7 @@ emit_usage(tOptions * pOpts) { time_t c_tim = time(NULL); struct tm * ptm = localtime(&c_tim); - strftime(zTimeBuf, AO_NAME_SIZE, TIME_FMT, ptm ); + strftime(tm_nm_buf, AO_NAME_SIZE, TIME_FMT, ptm ); } if (HAVE_GENSHELL_OPT(SCRIPT)) @@ -337,41 +372,42 @@ emit_usage(tOptions * pOpts) if ((script_leader == NULL) && (shell_prog != NULL)) printf(SHELL_MAGIC, shell_prog); - printf(PREAMBLE_FMT, START_MARK, out_nm, zTimeBuf); + printf(PREAMBLE_FMT, START_MARK, out_nm, tm_nm_buf); } - printf(END_PRE_FMT, pOpts->pzPROGNAME); + printf(END_PRE_FMT, opts->pzPROGNAME); /* * Get a copy of the original program name in lower case and * fill in an approximation of the program name from it. */ { - char * pzPN = zTimeBuf; - char const * pz = pOpts->pzPROGNAME; + char * pzPN = tm_nm_buf; + char const * pz = opts->pzPROGNAME; char ** pp; + /* Copy the program name into the time/name buffer */ for (;;) { if ((*pzPN++ = (char)tolower(*pz++)) == NUL) break; } - pp = (char **)(void *)&(pOpts->pzProgPath); - *pp = zTimeBuf; - pp = (char **)(void *)&(pOpts->pzProgName); - *pp = zTimeBuf; + pp = (char **)(void *)&(opts->pzProgPath); + *pp = tm_nm_buf; + pp = (char **)(void *)&(opts->pzProgName); + *pp = tm_nm_buf; } - text_to_var(pOpts, TT_LONGUSAGE, NULL); - text_to_var(pOpts, TT_USAGE, NULL); + text_to_var(opts, TT_LONGUSAGE, NULL); + text_to_var(opts, TT_USAGE, NULL); { - tOptDesc* pOptDesc = pOpts->pOptDesc; - int optionCt = pOpts->optCt; + tOptDesc* pOptDesc = opts->pOptDesc; + int optionCt = opts->optCt; for (;;) { if (pOptDesc->pOptProc == optionPrintVersion) { - text_to_var(pOpts, TT_VERSION, pOptDesc); + text_to_var(opts, TT_VERSION, pOptDesc); break; } @@ -382,249 +418,289 @@ emit_usage(tOptions * pOpts) } } +static void +emit_wrapup(tOptions * opts) +{ + tOptDesc * od = opts->pOptDesc; + int opt_ct = opts->presetOptCt; + char const * fmt; + + printf(FINISH_LOOP, opts->pzPROGNAME); + for (;opt_ct > 0; od++, --opt_ct) { + /* + * Options that are either usage documentation or are compiled out + * are not to be processed. + */ + if (SKIP_OPT(od) || (od->pz_NAME == NULL)) + continue; + + /* + * do not presence check if there is no minimum/must-set + */ + if ((od->optMinCt == 0) && ((od->fOptState & OPTST_MUST_SET) == 0)) + continue; + + if (od->optMaxCt > 1) + fmt = CHK_MIN_COUNT; + else fmt = CHK_ONE_REQUIRED; + + { + int min = (od->optMinCt == 0) ? 1 : od->optMinCt; + printf(fmt, opts->pzPROGNAME, od->pz_NAME, min); + } + } + fputs(END_MARK, stdout); +} static void -emit_setup(tOptions * pOpts) +emit_setup(tOptions * opts) { - tOptDesc * pOptDesc = pOpts->pOptDesc; - int optionCt = pOpts->presetOptCt; - char const * pzFmt; - char const * pzDefault; + tOptDesc * od = opts->pOptDesc; + int opt_ct = opts->presetOptCt; + char const * fmt; + char const * def_val; - for (;optionCt > 0; pOptDesc++, --optionCt) { - char zVal[32]; + for (;opt_ct > 0; od++, --opt_ct) { + char int_val_buf[32]; /* * Options that are either usage documentation or are compiled out * are not to be processed. */ - if (SKIP_OPT(pOptDesc) || (pOptDesc->pz_NAME == NULL)) + if (SKIP_OPT(od) || (od->pz_NAME == NULL)) continue; - if (pOptDesc->optMaxCt > 1) - pzFmt = MULTI_DEF_FMT; - else pzFmt = SGL_DEF_FMT; + if (od->optMaxCt > 1) + fmt = MULTI_DEF_FMT; + else fmt = SGL_DEF_FMT; /* * IF this is an enumeration/bitmask option, then convert the value * to a string before printing the default value. */ - switch (OPTST_GET_ARGTYPE(pOptDesc->fOptState)) { + switch (OPTST_GET_ARGTYPE(od->fOptState)) { case OPARG_TYPE_ENUMERATION: - (*(pOptDesc->pOptProc))(OPTPROC_EMIT_SHELL, pOptDesc ); - pzDefault = pOptDesc->optArg.argString; + (*(od->pOptProc))(OPTPROC_EMIT_SHELL, od ); + def_val = od->optArg.argString; break; /* * Numeric and membership bit options are just printed as a number. */ case OPARG_TYPE_NUMERIC: - snprintf(zVal, sizeof(zVal), "%d", - (int)pOptDesc->optArg.argInt); - pzDefault = zVal; + snprintf(int_val_buf, sizeof(int_val_buf), "%d", + (int)od->optArg.argInt); + def_val = int_val_buf; break; case OPARG_TYPE_MEMBERSHIP: - snprintf(zVal, sizeof(zVal), "%lu", - (unsigned long)pOptDesc->optArg.argIntptr); - pzDefault = zVal; + snprintf(int_val_buf, sizeof(int_val_buf), "%lu", + (unsigned long)od->optArg.argIntptr); + def_val = int_val_buf; break; case OPARG_TYPE_BOOLEAN: - pzDefault = (pOptDesc->optArg.argBool) ? TRUE_STR : FALSE_STR; + def_val = (od->optArg.argBool) ? TRUE_STR : FALSE_STR; break; default: - if (pOptDesc->optArg.argString == NULL) { - if (pzFmt == SGL_DEF_FMT) - pzFmt = SGL_NO_DEF_FMT; - pzDefault = NULL; + if (od->optArg.argString == NULL) { + if (fmt == SGL_DEF_FMT) + fmt = SGL_NO_DEF_FMT; + def_val = NULL; } else - pzDefault = pOptDesc->optArg.argString; + def_val = od->optArg.argString; } - printf(pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault); + printf(fmt, opts->pzPROGNAME, od->pz_NAME, def_val); } } static void -emit_action(tOptions * pOpts, tOptDesc* pOptDesc) +emit_action(tOptions * opts, tOptDesc * od) { - if (pOptDesc->pOptProc == optionPrintVersion) - printf(zTextExit, pOpts->pzPROGNAME, VER_STR); + if (od->pOptProc == optionPrintVersion) + printf(ECHO_N_EXIT, opts->pzPROGNAME, VER_STR); - else if (pOptDesc->pOptProc == optionPagedUsage) - printf(zPagedUsageExit, pOpts->pzPROGNAME); + else if (od->pOptProc == optionPagedUsage) + printf(PAGE_USAGE_TEXT, opts->pzPROGNAME); - else if (pOptDesc->pOptProc == optionLoadOpt) { - printf(zCmdFmt, NO_LOAD_WARN); - printf(zCmdFmt, YES_NEED_OPT_ARG); + else if (od->pOptProc == optionLoadOpt) { + printf(LVL3_CMD, NO_LOAD_WARN); + printf(LVL3_CMD, YES_NEED_OPT_ARG); - } else if (pOptDesc->pz_NAME == NULL) { + } else if (od->pz_NAME == NULL) { - if (pOptDesc->pOptProc == NULL) { - printf(zCmdFmt, NO_SAVE_OPTS); - printf(zCmdFmt, OK_NEED_OPT_ARG); + if (od->pOptProc == NULL) { + printf(LVL3_CMD, NO_SAVE_OPTS); + printf(LVL3_CMD, OK_NEED_OPT_ARG); } else - printf(zTextExit, pOpts->pzPROGNAME, LONG_USE_STR); + printf(ECHO_N_EXIT, opts->pzPROGNAME, LONG_USE_STR); } else { - if (pOptDesc->optMaxCt == 1) - printf(SGL_ARG_FMT, pOpts->pzPROGNAME, pOptDesc->pz_NAME); + if (od->optMaxCt == 1) + printf(SGL_ARG_FMT, opts->pzPROGNAME, od->pz_NAME); else { - if ((unsigned)pOptDesc->optMaxCt < NOLIMIT) - printf(zCountTest, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->optMaxCt); + if ((unsigned)od->optMaxCt < NOLIMIT) + printf(CHK_MAX_COUNT, opts->pzPROGNAME, + od->pz_NAME, od->optMaxCt); - printf(MULTI_ARG_FMT, pOpts->pzPROGNAME, pOptDesc->pz_NAME); + printf(MULTI_ARG_FMT, opts->pzPROGNAME, od->pz_NAME); } /* * Fix up the args. */ - if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) { - printf(zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); + if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NONE) { + printf(SET_MULTI_ARG, opts->pzPROGNAME, od->pz_NAME); + printf(LVL3_CMD, NO_ARG_NEEDED); - } else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) { - printf(zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); + } else if (od->fOptState & OPTST_ARG_OPTIONAL) { + printf(SET_MULTI_ARG, opts->pzPROGNAME, od->pz_NAME); + printf(LVL3_CMD, OK_NEED_OPT_ARG); } else { - fputs(zMustArg, stdout); + printf(LVL3_CMD, YES_NEED_OPT_ARG); } } fputs(zOptionEndSelect, stdout); } - static void -emit_inaction(tOptions * pOpts, tOptDesc* pOptDesc) +emit_inaction(tOptions * opts, tOptDesc * od) { - if (pOptDesc->pOptProc == optionLoadOpt) { - printf(zCmdFmt, NO_SUPPRESS_LOAD); + if (od->pOptProc == optionLoadOpt) { + printf(LVL3_CMD, NO_SUPPRESS_LOAD); - } else if (pOptDesc->optMaxCt == 1) - printf(NO_SGL_ARG_FMT, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); + } else if (od->optMaxCt == 1) + printf(NO_SGL_ARG_FMT, opts->pzPROGNAME, + od->pz_NAME, od->pz_DisablePfx); else - printf(NO_MULTI_ARG_FMT, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); + printf(NO_MULTI_ARG_FMT, opts->pzPROGNAME, + od->pz_NAME, od->pz_DisablePfx); - printf(zCmdFmt, NO_ARG_NEEDED); + printf(LVL3_CMD, NO_ARG_NEEDED); fputs(zOptionEndSelect, stdout); } - +/** + * recognize flag options. These go at the end. + * At the end, emit code to handle options we don't recognize. + * + * @param[in] opts the program options + */ static void -emit_flag(tOptions * pOpts) +emit_flag(tOptions * opts) { - tOptDesc* pOptDesc = pOpts->pOptDesc; - int optionCt = pOpts->optCt; + tOptDesc* od = opts->pOptDesc; + int opt_ct = opts->optCt; fputs(zOptionCase, stdout); - for (;optionCt > 0; pOptDesc++, --optionCt) { + for (;opt_ct > 0; od++, --opt_ct) { - if (SKIP_OPT(pOptDesc)) + if (SKIP_OPT(od) || ! IS_GRAPHIC_CHAR(od->optValue)) continue; - if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) { - printf(zOptionFlag, pOptDesc->optValue); - emit_action(pOpts, pOptDesc); - } + printf(zOptionFlag, od->optValue); + emit_action(opts, od); } - printf(UNK_OPT_FMT, FLAG_STR, pOpts->pzPROGNAME); + printf(UNK_OPT_FMT, FLAG_STR, opts->pzPROGNAME); } - -/* - * Emit the match text for a long option +/** + * Emit the match text for a long option. The passed in \a name may be + * either the enablement name or the disablement name. + * + * @param[in] name The current name to check. + * @param[in] cod current option descriptor + * @param[in] opts the program options */ static void -emit_match_expr(char const * pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts) +emit_match_expr(char const * name, tOptDesc * cod, tOptions * opts) { - tOptDesc* pOD = pOpts->pOptDesc; - int oCt = pOpts->optCt; - int min = 1; - char zName[ 256 ]; - char* pz = zName; + char name_bf[32]; + unsigned int min_match_ct = 2; + unsigned int max_match_ct = strlen(name) - 1; - for (;;) { - int matchCt = 0; - - /* - * Omit the current option, Documentation opts and compiled out opts. - */ - if ((pOD == pCurOpt) || SKIP_OPT(pOD)){ - if (--oCt <= 0) - break; - pOD++; - continue; - } - - /* - * Check each character of the name case insensitively. - * They must not be the same. They cannot be, because it would - * not compile correctly if they were. - */ - while ( toupper(pOD->pz_Name[matchCt]) - == toupper(pzMatchName[matchCt])) - matchCt++; - - if (matchCt > min) - min = matchCt; - - /* - * Check the disablement name, too. - */ - if (pOD->pz_DisableName != NULL) { - matchCt = 0; - while ( toupper(pOD->pz_DisableName[matchCt]) - == toupper(pzMatchName[matchCt])) - matchCt++; - if (matchCt > min) - min = matchCt; + if (max_match_ct >= sizeof(name_bf) - 1) + goto leave; + + { + tOptDesc * od = opts->pOptDesc; + int ct = opts->optCt; + + for (; ct-- > 0; od++) { + unsigned int match_ct = 0; + + /* + * Omit the current option, Doc opts and compiled out opts. + */ + if ((od == cod) || SKIP_OPT(od)) + continue; + + /* + * Check each character of the name case insensitively. + * They must not be the same. They cannot be, because it would + * not compile correctly if they were. + */ + while (toupper(od->pz_Name[match_ct]) == toupper(name[match_ct])) + match_ct++; + + if (match_ct > min_match_ct) + min_match_ct = match_ct; + + /* + * Check the disablement name, too. + */ + if (od->pz_DisableName == NULL) + continue; + + match_ct = 0; + while ( toupper(od->pz_DisableName[match_ct]) + == toupper(name[match_ct])) + match_ct++; + if (match_ct > min_match_ct) + min_match_ct = match_ct; } - if (--oCt <= 0) - break; - pOD++; } /* - * IF the 'min' is all or one short of the name length, - * THEN the entire string must be matched. + * Don't bother emitting partial matches if there is only one possible + * partial match. */ - if ( (pzMatchName[min ] == NUL) - || (pzMatchName[min+1] == NUL) ) - printf(zOptionFullName, pzMatchName); + if (min_match_ct < max_match_ct) { + char * pz = name_bf + min_match_ct; + int nm_ix = min_match_ct; - else { - int matchCt = 0; - for (; matchCt <= min; matchCt++) - *pz++ = pzMatchName[matchCt]; + memcpy(name_bf, name, min_match_ct); for (;;) { *pz = NUL; - printf(zOptionPartName, zName); - *pz++ = pzMatchName[matchCt++]; - if (pzMatchName[matchCt] == NUL) { + printf(zOptionPartName, name_bf); + *pz++ = name[nm_ix++]; + if (name[nm_ix] == NUL) { *pz = NUL; - printf(zOptionFullName, zName); break; } } } -} +leave: + printf(zOptionFullName, name); +} -/* - * Emit GNU-standard long option handling code +/** + * Emit GNU-standard long option handling code. + * + * @param[in] opts the program options */ static void -emitLong(tOptions * pOpts) +emit_long(tOptions * opts) { - tOptDesc* pOD = pOpts->pOptDesc; - int ct = pOpts->optCt; + tOptDesc * od = opts->pOptDesc; + int ct = opts->optCt; fputs(zOptionCase, stdout); @@ -635,88 +711,113 @@ emitLong(tOptions * pOpts) /* * Documentation & compiled-out options */ - if (SKIP_OPT(pOD)) + if (SKIP_OPT(od)) continue; - emit_match_expr(pOD->pz_Name, pOD, pOpts); - emit_action(pOpts, pOD); + emit_match_expr(od->pz_Name, od, opts); + emit_action(opts, od); /* * Now, do the same thing for the disablement version of the option. */ - if (pOD->pz_DisableName != NULL) { - emit_match_expr(pOD->pz_DisableName, pOD, pOpts); - emit_inaction(pOpts, pOD); + if (od->pz_DisableName != NULL) { + emit_match_expr(od->pz_DisableName, od, opts); + emit_inaction(opts, od); } - } while (pOD++, --ct > 0); + } while (od++, --ct > 0); - printf(UNK_OPT_FMT, OPTION_STR, pOpts->pzPROGNAME); + printf(UNK_OPT_FMT, OPTION_STR, opts->pzPROGNAME); } - -static void -open_out(char const * pzFile) +/** + * Load the previous shell script output file. We need to preserve any + * hand-edited additions outside of the START_MARK and END_MARKs. + * + * @param[in] fname the output file name + */ +static char * +load_old_output(char const * fname, char const * pname) { - FILE* fp; - char* pzData = NULL; + /* + * IF we cannot stat the file, + * THEN assume we are creating a new file. + * Skip the loading of the old data. + */ + FILE * fp = fopen(fname, "r" FOPEN_BINARY_FLAG); struct stat stbf; + char * text; + char * scan; - do { - char* pzScan; - size_t sizeLeft; + if (fp == NULL) + return NULL; - /* - * IF we cannot stat the file, - * THEN assume we are creating a new file. - * Skip the loading of the old data. - */ - if (stat(pzFile, &stbf) != 0) + /* + * If we opened it, we should be able to stat it and it needs + * to be a regular file + */ + if ((fstat(fileno(fp), &stbf) != 0) || (! S_ISREG(stbf.st_mode))) + fserr_exit(pname, "fstat", fname); + + scan = text = AGALOC(stbf.st_size + 1, "f data"); + + /* + * Read in all the data as fast as our OS will let us. + */ + for (;;) { + size_t inct = fread((void*)scan, 1, (size_t)stbf.st_size, fp); + if (inct == 0) break; - /* - * The file must be a regular file - */ - if (! S_ISREG(stbf.st_mode)) { - fprintf(stderr, zNotFile, pzFile); - exit(EXIT_FAILURE); - } + stbf.st_size -= (ssize_t)inct; - pzData = AGALOC(stbf.st_size + 1, "f data"); - fp = fopen(pzFile, "r" FOPEN_BINARY_FLAG); + if (stbf.st_size == 0) + break; - sizeLeft = (unsigned)stbf.st_size; - pzScan = pzData; + scan += inct; + } - /* - * Read in all the data as fast as our OS will let us. - */ - for (;;) { - int inct = fread((void*)pzScan, (size_t)1, sizeLeft, fp); - if (inct == 0) - break; + *scan = NUL; + fclose(fp); - pzScan += inct; - sizeLeft -= inct; + return text; +} - if (sizeLeft == 0) - break; - } +/** + * Open the specified output file. If it already exists, load its + * contents and save the non-generated (hand edited) portions. + * If a "start mark" is found, everything before it is preserved leader. + * If not, the entire thing is a trailer. Assuming the start is found, + * then everything after the end marker is the trailer. If the end + * mark is not found, the file is actually corrupt, but we take the + * remainder to be the trailer. + * + * @param[in] fname the output file name + */ +static void +open_out(char const * fname, char const * pname) +{ - /* - * NUL-terminate the leader and look for the trailer - */ - *pzScan = NUL; - fclose(fp); - pzScan = strstr(pzData, START_MARK); - if (pzScan == NULL) { - script_trailer = pzData; + do { + char * txt = script_text = load_old_output(fname, pname); + char * scn; + + if (txt == NULL) + break; + + scn = strstr(txt, START_MARK); + if (scn == NULL) { + script_trailer = txt; break; } - *(pzScan++) = NUL; - pzScan = strstr(pzScan, END_MARK); - if (pzScan == NULL) { - script_trailer = pzData; + *(scn++) = NUL; + scn = strstr(scn, END_MARK); + if (scn == NULL) { + /* + * The file is corrupt. Set the trailer to be everything + * after the start mark. The user will need to fix it up. + */ + script_trailer = txt + strlen(txt) + START_MARK_LEN + 1; break; } @@ -724,23 +825,20 @@ open_out(char const * pzFile) * Check to see if the data contains our marker. * If it does, then we will skip over it */ - script_trailer = pzScan + END_MARK_LEN; - script_leader = pzData; + script_trailer = scn + END_MARK_LEN; + script_leader = txt; } while (false); - if (freopen(pzFile, "w" FOPEN_BINARY_FLAG, stdout) != stdout) { - fprintf(stderr, zFreopenFail, errno, strerror(errno)); - exit(EXIT_FAILURE); - } + if (freopen(fname, "w" FOPEN_BINARY_FLAG, stdout) != stdout) + fserr_exit(pname, "freopen", fname); } - /*=export_func genshelloptUsage * private: * what: The usage function for the genshellopt generated program * - * arg: + tOptions* + pOpts + program options descriptor + - * arg: + int + exitCode + usage text type to produce + + * arg: + tOptions* + opts + program options descriptor + + * arg: + int + exit_cd + usage text type to produce + * * doc: * This function is used to create the usage strings for the option @@ -750,17 +848,17 @@ open_out(char const * pzFile) * and create shell script variables containing the two types of text. =*/ void -genshelloptUsage(tOptions * pOpts, int exitCode) +genshelloptUsage(tOptions * opts, int exit_cd) { #if ! defined(HAVE_WORKING_FORK) - optionUsage(pOpts, exitCode); + optionUsage(opts, exit_cd); #else /* * IF not EXIT_SUCCESS, * THEN emit the short form of usage. */ - if (exitCode != EXIT_SUCCESS) - optionUsage(pOpts, exitCode); + if (exit_cd != EXIT_SUCCESS) + optionUsage(opts, exit_cd); fflush(stderr); fflush(stdout); if (ferror(stdout) || ferror(stderr)) @@ -773,12 +871,12 @@ genshelloptUsage(tOptions * pOpts, int exitCode) */ switch (fork()) { case -1: - optionUsage(pOpts, EXIT_FAILURE); + optionUsage(opts, EXIT_FAILURE); /* NOTREACHED */ case 0: pagerState = PAGER_STATE_CHILD; - optionUsage(pOpts, EXIT_SUCCESS); + optionUsage(opts, EXIT_SUCCESS); /* NOTREACHED */ _exit(EXIT_FAILURE); @@ -799,7 +897,7 @@ genshelloptUsage(tOptions * pOpts, int exitCode) AGDUPSTR(pz, optionParseShellOptions->pzPROGNAME, "prog name"); *pp = pz; while (*pz != NUL) { - *pz = tolower(*pz); + *pz = (char)tolower(*pz); pz++; } } @@ -828,16 +926,15 @@ genshelloptUsage(tOptions * pOpts, int exitCode) } fflush(stdout); - if (ferror(stdout)) { - fputs(zOutputFail, stderr); - exit(EXIT_FAILURE); - } + if (ferror(stdout)) + fserr_exit(opts->pzProgName, zwriting, zstdout_name); exit(EXIT_SUCCESS); #endif } -/* +/** @} + * * Local Variables: * mode: C * c-file-style: "stroustrup" diff --git a/src/libopts/nested.c b/src/libopts/nested.c index ed23fd2036..bf55f6f18a 100644 --- a/src/libopts/nested.c +++ b/src/libopts/nested.c @@ -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); - - 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->v.longVal = strtol(val, 0, 0); + + 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; } } @@ -390,139 +403,193 @@ scan_name(char const* pzName, tOptionValue* pRes) } /** - * 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. + * 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* -scan_xml(char const* pzName, tOptionValue* pRes) +static char const * +unnamed_xml(char const * txt) { - size_t nameLen; - size_t valLen; - char const* pzScan = ++pzName; - char const* pzVal; - tOptionValue valu; - tOptionValue* pNewVal; - tOptionLoadMode save_mode = option_load_mode; - - if (! IS_VAR_FIRST_CHAR(*pzName)) { - switch (*pzName) { - default: - pzName = NULL; - break; + switch (*txt) { + default: + txt = NULL; + break; - case '!': - pzName = strstr(pzName, "-->"); - if (pzName != NULL) - pzName += 3; - break; + case '!': + txt = strstr(txt, "-->"); + if (txt != NULL) + txt += 3; + break; - case '?': - pzName = strchr(pzName, '>'); - if (pzName != NULL) - pzName++; - break; - } - return pzName; + case '?': + txt = strchr(txt, '>'); + if (txt != NULL) + txt++; + break; } + return txt; +} - pzScan = SPN_VALUE_NAME_CHARS(pzName+1); - nameLen = pzScan - pzName; - if (nameLen > 64) +/** + * 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; - valu.valType = OPARG_TYPE_STRING; + val->valType = OPARG_TYPE_STRING; - switch (*pzScan) { - case ' ': - case '\t': - pzScan = parse_attrs( - NULL, (char*)pzScan, &option_load_mode, &valu ); - if (*pzScan == '>') { - pzScan++; - break; - } + 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 (*pzScan != '/') { - option_load_mode = save_mode; - return NULL; - } - /* FALLTHROUGH */ + if (! IS_END_XML_TOKEN_CHAR(*scan)) + return NULL; /* oops */ - case '/': - if (*++pzScan != '>') { - option_load_mode = save_mode; + if (*scan == '/') { + /* + * Single element XML entries get inserted as an empty string. + */ + if (*++scan != '>') 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; + 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; - pzVal = pzScan; + do { + *(dst++) = *(src++); + } while (--nm_len > 0); /* nm_len is known to be 64 or less */ + *(dst++) = '>'; + *dst = NUL; { - 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; + 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)); } - valLen = (pzScan - pzVal); - pzScan += nameLen + 3; - pzScan = SPN_WHITESPACE_CHARS(pzScan); + 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 * xml_name, tOptionValue * res_val) +{ + 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(*++xml_name)) + return unnamed_xml(xml_name); + + /* + * "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; + + 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; + } + + /* + * "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" diff --git a/src/libopts/numeric.c b/src/libopts/numeric.c index b709d0708f..260f539c75 100644 --- a/src/libopts/numeric.c +++ b/src/libopts/numeric.c @@ -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" diff --git a/src/libopts/option-value-type.c b/src/libopts/option-value-type.c new file mode 100644 index 0000000000..d3b0a6c65c --- /dev/null +++ b/src/libopts/option-value-type.c @@ -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 */ diff --git a/src/libopts/option-value-type.h b/src/libopts/option-value-type.h new file mode 100644 index 0000000000..2d99b4b0b4 --- /dev/null +++ b/src/libopts/option-value-type.h @@ -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 */ diff --git a/src/libopts/option-xat-attribute.c b/src/libopts/option-xat-attribute.c new file mode 100644 index 0000000000..9f6cbdb7f2 --- /dev/null +++ b/src/libopts/option-xat-attribute.c @@ -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 */ diff --git a/src/libopts/option-xat-attribute.h b/src/libopts/option-xat-attribute.h new file mode 100644 index 0000000000..c6ac0847dc --- /dev/null +++ b/src/libopts/option-xat-attribute.h @@ -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 */ diff --git a/src/libopts/parse-duration.c b/src/libopts/parse-duration.c index 655a5e542b..5f4496dbcc 100644 --- a/src/libopts/parse-duration.c +++ b/src/libopts/parse-duration.c @@ -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) diff --git a/src/libopts/parse-duration.h b/src/libopts/parse-duration.h index caefb759b4..cbe31b87ff 100644 --- a/src/libopts/parse-duration.h +++ b/src/libopts/parse-duration.h @@ -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/>. */ /* diff --git a/src/libopts/pgusage.c b/src/libopts/pgusage.c index 7eae2b0f5b..3bc7fc31e2 100644 --- a/src/libopts/pgusage.c +++ b/src/libopts/pgusage.c @@ -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" diff --git a/src/libopts/proto.h b/src/libopts/proto.h index ae1a110a65..7cf6c53289 100644 --- a/src/libopts/proto.h +++ b/src/libopts/proto.h @@ -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); + +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); -LOCAL tSuccess -find_opt(tOptions * pOpts, tOptState * pOptState); +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 */ diff --git a/src/libopts/putshell.c b/src/libopts/putshell.c index d8e2d91aea..d210392946 100644 --- a/src/libopts/putshell.c +++ b/src/libopts/putshell.c @@ -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" diff --git a/src/libopts/reset.c b/src/libopts/reset.c index b8c5b9e274..2abe7ccf91 100644 --- a/src/libopts/reset.c +++ b/src/libopts/reset.c @@ -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" diff --git a/src/libopts/restore.c b/src/libopts/restore.c index 4fd76f88e1..09ecb33264 100644 --- a/src/libopts/restore.c +++ b/src/libopts/restore.c @@ -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" diff --git a/src/libopts/save.c b/src/libopts/save.c index 9e95056bab..3ae046feaa 100644 --- a/src/libopts/save.c +++ b/src/libopts/save.c @@ -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" diff --git a/src/libopts/sort.c b/src/libopts/sort.c index a05588dd1b..0d70e341a1 100644 --- a/src/libopts/sort.c +++ b/src/libopts/sort.c @@ -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" diff --git a/src/libopts/stack.c b/src/libopts/stack.c index 094b2a1de3..dc73702afd 100644 --- a/src/libopts/stack.c +++ b/src/libopts/stack.c @@ -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" diff --git a/src/libopts/streqvcmp.c b/src/libopts/streqvcmp.c index 54a063affc..8fae58fac2 100644 --- a/src/libopts/streqvcmp.c +++ b/src/libopts/streqvcmp.c @@ -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" diff --git a/src/libopts/text_mmap.c b/src/libopts/text_mmap.c index 4a7aa1a238..8b117c0599 100644 --- a/src/libopts/text_mmap.c +++ b/src/libopts/text_mmap.c @@ -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" diff --git a/src/libopts/time.c b/src/libopts/time.c index 7348bdb406..6cf7faad89 100644 --- a/src/libopts/time.c +++ b/src/libopts/time.c @@ -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" diff --git a/src/libopts/tokenize.c b/src/libopts/tokenize.c index 9563713e80..15e7cb956f 100644 --- a/src/libopts/tokenize.c +++ b/src/libopts/tokenize.c @@ -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" diff --git a/src/libopts/usage.c b/src/libopts/usage.c index 52a271ae06..54ae86be7c 100644 --- a/src/libopts/usage.c +++ b/src/libopts/usage.c @@ -2,11 +2,13 @@ /* * \file usage.c * - * Time-stamp: "2012-03-31 19:19:26 bkorb" - * * This module implements the default usage procedure for * Automated Options. It may be overridden, of course. * + * @addtogroup autoopts + * @{ + */ +/* * Sort options: --start=END-[S]TATIC-FORWARD --patt='^/\*($|[^:])' \ --out=xx.c key='^[a-zA-Z0-9_]+\(' --trail='^/\*:' \ @@ -16,7 +18,7 @@ /* * 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 @@ -28,16 +30,47 @@ * 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 OPTPROC_L_N_S (OPTPROC_LONGOPT | OPTPROC_SHORTOPT) +#if defined(ENABLE_NLS) && defined(HAVE_LIBINTL_H) +# include <libintl.h> +#endif + +typedef struct { + size_t fnm_len; + uint32_t fnm_mask; + char const * fnm_name; +} ao_flag_names_t; + +/** + * Automated Options Usage Flags. + * NB: no entry may be a prefix of another entry + */ +#define AOFLAG_TABLE \ + _aof_(gnu, OPTPROC_GNUUSAGE ) \ + _aof_(autoopts, ~OPTPROC_GNUUSAGE) \ + _aof_(no_misuse_usage, OPTPROC_MISUSE ) \ + _aof_(misuse_usage, ~OPTPROC_MISUSE ) \ + _aof_(compute, OPTPROC_COMPUTE ) + +#define _aof_(_n, _f) AOUF_ ## _n ## _ID, +typedef enum { AOFLAG_TABLE AOUF_COUNT } ao_flag_id_t; +#undef _aof_ + +#define _aof_(_n, _f) AOUF_ ## _n = (1 << AOUF_ ## _n ## _ID), +typedef enum { AOFLAG_TABLE } ao_flags_t; +#undef _aof_ /* = = = START-STATIC-FORWARD = = = */ +static unsigned int +parse_usage_flags(ao_flag_names_t const * fnt, char const * txt); + static inline bool do_gnu_usage(tOptions * pOpts); @@ -45,133 +78,169 @@ static inline bool skip_misuse_usage(tOptions * pOpts); static void +print_offer_usage(tOptions * opts); + +static void print_usage_details(tOptions * opts, int exit_code); static void -prt_conflicts(tOptions * pOptions, tOptDesc * pOD); +print_one_paragraph(char const * text, bool plain, FILE * fp); static void -prt_one_vendor(tOptions * pOptions, tOptDesc * pOD, - arg_types_t * pAT, char const * usefmt); +prt_conflicts(tOptions * opts, tOptDesc * od); static void -prt_vendor_opts(tOptions * pOpts, char const * pOptTitle); +prt_one_vendor(tOptions * opts, tOptDesc * od, + arg_types_t * argtp, char const * usefmt); static void -prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, - char const * pOptTitle); +prt_vendor_opts(tOptions * opts, char const * title); static void -prt_ini_list(char const * const * papz, bool * pInitIntro, - char const * pzRc, char const * pzPN); +prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title); static void -prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); +prt_ini_list(char const * const * papz, bool * need_intro, + char const * ini_file, char const * path_nm); static void -prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); +prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at); static void -prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle); +prt_one_usage(tOptions * opts, tOptDesc * od, arg_types_t * at); static void -prt_prog_detail(tOptions* pOptions); +prt_opt_usage(tOptions * opts, int ex_code, char const * title); + +static void +prt_prog_detail(tOptions * opts); static int -setGnuOptFmts(tOptions* pOpts, tCC** ppT); +setGnuOptFmts(tOptions * opts, char const ** ptxt); static int -setStdOptFmts(tOptions* pOpts, tCC** ppT); +setStdOptFmts(tOptions * opts, char const ** ptxt); /* = = = END-STATIC-FORWARD = = = */ -/* - * NB: no entry may be a prefix of another entry +/** + * Parse the option usage flags string. Any parsing problems yield + * a zero (no flags set) result. This function is internal to + * set_usage_flags(). + * + * @param[in] fnt Flag Name Table - maps a name to a mask + * @param[in] txt the text to process. If NULL, then + * getenv("AUTOOPTS_USAGE") is used. + * @returns a bit mask indicating which \a fnt entries were found. */ -#define AOFLAG_TABLE \ - _aof_(gnu, OPTPROC_GNUUSAGE ) \ - _aof_(autoopts, ~OPTPROC_GNUUSAGE) \ - _aof_(no_misuse_usage, OPTPROC_MISUSE ) \ - _aof_(misuse_usage, ~OPTPROC_MISUSE ) - -LOCAL void -set_usage_flags(tOptions * opts, char const * flg_txt) +static unsigned int +parse_usage_flags(ao_flag_names_t const * fnt, char const * txt) { - typedef struct { - size_t fnm_len; - uint32_t fnm_mask; - char const * fnm_name; - } ao_flag_names_t; - -# define _aof_(_n, _f) AOUF_ ## _n ## _ID, - typedef enum { AOFLAG_TABLE AOUF_COUNT } ao_flag_id_t; -# undef _aof_ - -# define _aof_(_n, _f) AOUF_ ## _n = (1 << AOUF_ ## _n ## _ID), - typedef enum { AOFLAG_TABLE } ao_flags_t; -# undef _aof_ + unsigned int res = 0; -# define _aof_(_n, _f) { sizeof(#_n)-1, _f, #_n }, - static ao_flag_names_t const fn_table[AOUF_COUNT] = { - AOFLAG_TABLE - }; -# undef _aof_ - - unsigned int flg = (ao_flags_t)0; - - if (flg_txt == NULL) { - flg_txt = getenv("AUTOOPTS_USAGE"); - if (flg_txt == NULL) return; + /* + * The text may be passed in. If not, use the environment variable. + */ + if (txt == NULL) { + txt = getenv("AUTOOPTS_USAGE"); + if (txt == NULL) + return 0; } - flg_txt = SPN_WHITESPACE_CHARS(flg_txt); - if (*flg_txt == NUL) - return; + txt = SPN_WHITESPACE_CHARS(txt); + if (*txt == NUL) + return 0; + /* + * search the string for table entries. We must understand everything + * we see in the string, or we give up on it. + */ for (;;) { int ix = 0; - ao_flag_names_t const * fnt = fn_table; for (;;) { - if (strneqvcmp(flg_txt, fnt->fnm_name, fnt->fnm_len) == 0) + if (strneqvcmp(txt, fnt[ix].fnm_name, (int)fnt[ix].fnm_len) == 0) break; if (++ix >= AOUF_COUNT) - return; - fnt++; + return 0; } /* * Make sure we have a full match. Look for whitespace, * a comma, or a NUL byte. */ - if (! IS_END_LIST_ENTRY_CHAR(flg_txt[fnt->fnm_len])) - return; + if (! IS_END_LIST_ENTRY_CHAR(txt[fnt[ix].fnm_len])) + return 0; - flg |= 1 << ix; - flg_txt = SPN_WHITESPACE_CHARS(flg_txt + fnt->fnm_len); + res |= 1U << ix; + txt = SPN_WHITESPACE_CHARS(txt + fnt[ix].fnm_len); - if (*flg_txt == NUL) - break; + switch (*txt) { + case NUL: + return res; - if (*flg_txt == ',') { - /* - * skip the comma and following white space - */ - flg_txt = SPN_WHITESPACE_CHARS(flg_txt + 1); - if (*flg_txt == NUL) - break; + case ',': + txt = SPN_WHITESPACE_CHARS(txt + 1); + /* Something must follow the comma */ + + default: + continue; } } +} +/** + * Set option usage flags. Any parsing problems yield no changes to options. + * Three different bits may be fiddled: \a OPTPROC_GNUUSAGE, \a OPTPROC_MISUSE + * and \a OPTPROC_COMPUTE. + * + * @param[in] flg_txt text to parse. If NULL, then the AUTOOPTS_USAGE + * environment variable is parsed. + * @param[in,out] opts the program option descriptor + */ +LOCAL void +set_usage_flags(tOptions * opts, char const * flg_txt) +{ +# define _aof_(_n, _f) { sizeof(#_n)-1, _f, #_n }, + static ao_flag_names_t const fn_table[AOUF_COUNT] = { + AOFLAG_TABLE + }; +# undef _aof_ + + /* + * the flag word holds a bit for each selected table entry. + */ + unsigned int flg = parse_usage_flags(fn_table, flg_txt); + if (flg == 0) return; + + /* + * Ensure we do not have conflicting selections + */ { - ao_flag_names_t const * fnm = fn_table; + static unsigned int const form_mask = + AOUF_gnu | AOUF_autoopts; + static unsigned int const misuse_mask = + AOUF_no_misuse_usage | AOUF_misuse_usage; + if ( ((flg & form_mask) == form_mask) + || ((flg & misuse_mask) == misuse_mask) ) + return; + } - while (flg != 0) { + /* + * Now fiddle the fOptSet bits, based on settings. + * The OPTPROC_LONGOPT bit is immutable, thus if it is set, + * then fnm points to a mask off mask. + */ + { + ao_flag_names_t const * fnm = fn_table; + for (;;) { if ((flg & 1) != 0) { if ((fnm->fnm_mask & OPTPROC_LONGOPT) != 0) opts->fOptSet &= fnm->fnm_mask; else opts->fOptSet |= fnm->fnm_mask; } flg >>= 1; + if (flg == 0) + break; fnm++; } } @@ -230,28 +299,97 @@ optionOnlyUsage(tOptions * pOpts, int ex_code) prt_opt_usage(pOpts, ex_code, pOptTitle); fflush(option_usage_fp); - if (ferror(option_usage_fp) != 0) { - fputs(zOutputFail, stderr); - exit(EXIT_FAILURE); + if (ferror(option_usage_fp) != 0) + fserr_exit(pOpts->pzProgName, zwriting, (option_usage_fp == stderr) + ? zstderr_name : zstdout_name); +} + +LOCAL void +ao_bug(char const * msg) +{ + fprintf(stderr, zao_bug_msg, msg); + exit(EX_SOFTWARE); +} + +/** + * Print a message suggesting how to get help. + * + * @param[in] opts the program options + */ +static void +print_offer_usage(tOptions * opts) +{ + char help[24]; + + if (HAS_opt_usage_t(opts)) { + int ix = opts->presetOptCt; + tOptDesc * od = opts->pOptDesc + ix; + while (od->optUsage != AOUSE_HELP) { + if (++ix >= opts->optCt) + ao_bug(zmissing_help_msg); + od++; + } + switch (opts->fOptSet & (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)) { + case OPTPROC_SHORTOPT: + help[0] = '-'; + help[1] = od->optValue; + help[2] = NUL; + break; + + case OPTPROC_LONGOPT: + case (OPTPROC_LONGOPT | OPTPROC_SHORTOPT): + help[0] = help[1] = '-'; + strncpy(help + 2, od->pz_Name, 20); + break; + + case 0: + strncpy(help, od->pz_Name, 20); + break; + } + + } else { + switch (opts->fOptSet & (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)) { + case OPTPROC_SHORTOPT: + strcpy(help, "-h"); + break; + + case OPTPROC_LONGOPT: + case (OPTPROC_LONGOPT | OPTPROC_SHORTOPT): + strcpy(help, "--help"); + + case 0: + strcpy(help, "help"); + break; + } } + + fprintf(option_usage_fp, zoffer_usage_fmt, opts->pzProgName, help); } +/** + * Print information about each option. + * + * @param[in] opts the program options + * @param[in] exit_code whether or not there was a usage error reported. + * used to select full usage versus abbreviated. + */ static void print_usage_details(tOptions * opts, int exit_code) { { char const * pOptTitle = NULL; + int flen; /* * Determine which header and which option formatting strings to use */ if (do_gnu_usage(opts)) { - int flen = setGnuOptFmts(opts, &pOptTitle); + flen = setGnuOptFmts(opts, &pOptTitle); sprintf(line_fmt_buf, zFmtFmt, flen); fputc(NL, option_usage_fp); } else { - int flen = setStdOptFmts(opts, &pOptTitle); + flen = setStdOptFmts(opts, &pOptTitle); sprintf(line_fmt_buf, zFmtFmt, flen); /* @@ -265,6 +403,9 @@ print_usage_details(tOptions * opts, int exit_code) fputs(pOptTitle, option_usage_fp); } + flen = 4 - ((flen + 15) / 8); + if (flen > 0) + tab_skip_ct = flen; prt_opt_usage(opts, exit_code, pOptTitle); } @@ -305,18 +446,150 @@ print_usage_details(tOptions * opts, int exit_code) fflush(option_usage_fp); - if (ferror(option_usage_fp) != 0) { - fputs(zOutputFail, stderr); - exit(EXIT_FAILURE); + if (ferror(option_usage_fp) != 0) + fserr_exit(opts->pzProgName, zwriting, (option_usage_fp == stderr) + ? zstderr_name : zstdout_name); +} + +static void +print_one_paragraph(char const * text, bool plain, FILE * fp) +{ + if (plain) { +#ifdef ENABLE_NLS +#ifdef HAVE_LIBINTL_H +#ifdef DEBUG_ENABLED +#undef gettext +#endif + char * buf = dgettext("libopts", text); + if (buf == text) + text = gettext(text); +#endif /* HAVE_LIBINTL_H */ +#endif /* ENABLE_NLS */ + fputs(text, fp); + } + + else { + char const * t = optionQuoteString(text, LINE_SPLICE); + fprintf(fp, PUTS_FMT, t); + AGFREE((void *)t); } } + +/*=export_func optionPrintParagraphs + * private: + * + * what: Print a paragraph of usage text + * arg: + char const * + text + a block of text that has bee i18n-ed + + * arg: + bool + plain + false -> wrap text in fputs() + + * arg: + FILE * + fp + the stream file pointer for output + + * + * doc: + * This procedure is called in two contexts: when a full or short usage text + * has been provided for display, and when autogen is assembling a list of + * translatable texts in the optmain.tlib template. In the former case, \a + * plain is set to \a true, otherwise \a false. + * + * Anything less than 256 characters in size is printed as a single unit. + * Otherwise, paragraphs are detected. A paragraph break is defined as just + * before a non-empty line preceded by two newlines or a line that starts + * with at least one space character but fewer than 8 space characters. + * Lines indented with tabs or more than 7 spaces are considered continuation + * lines. + * + * If 'plain' is true, we are emitting text for a user to see. So, if it is + * true and NLS is not enabled, then just write the whole thing at once. +=*/ +void +optionPrintParagraphs(char const * text, bool plain, FILE * fp) +{ + size_t len = strlen(text); + char * buf; +#ifndef ENABLE_NLS + if (plain || (len < 256)) +#else + if (len < 256) +#endif + { + print_one_paragraph(text, plain, fp); + return; + } + + AGDUPSTR(buf, text, "ppara"); + text = buf; + + for (;;) { + char * scan; + + if (len < 256) { + done: + print_one_paragraph(buf, plain, fp); + break; + } + scan = buf; + + try_longer: + scan = strchr(scan, NL); + if (scan == NULL) + goto done; + + if ((scan - buf) < 40) { + scan++; + goto try_longer; + } + + scan++; + if ((! isspace((int)*scan)) || (*scan == HT)) + /* + * line starts with tab or non-whitespace --> continuation + */ + goto try_longer; + + if (*scan == NL) { + /* + * Double newline -> paragraph break + * Include all newlines in current paragraph. + */ + while (*++scan == NL) /*continue*/; + } else { + char * p = scan; + int sp_ct = 0; + + while (*p == ' ') { + if (++sp_ct >= 8) { + /* + * Too many spaces --> continuation line + */ + scan = p; + goto try_longer; + } + p++; + } + } + + /* + * "scan" points to the first character of a paragraph or the + * terminating NUL byte. + */ + { + char svch = *scan; + *scan = NUL; + print_one_paragraph(buf, plain, fp); + len -= scan - buf; + if (len <= 0) + break; + *scan = svch; + buf = scan; + } + } + AGFREE((void *)text); +} /*=export_func optionUsage * private: * * what: Print usage text - * arg: + tOptions* + pOptions + program options descriptor + + * arg: + tOptions* + opts + program options descriptor + * arg: + int + exitCode + exit code for calling exit(3) + * * doc: @@ -329,12 +602,13 @@ print_usage_details(tOptions * opts, int exit_code) * to stdout and the actual exit code will be "EXIT_SUCCESS". =*/ void -optionUsage(tOptions * pOptions, int usage_exit_code) +optionUsage(tOptions * opts, int usage_exit_code) { int exit_code = (usage_exit_code == AO_EXIT_REQ_USAGE) ? EXIT_SUCCESS : usage_exit_code; displayEnum = false; + set_usage_flags(opts, NULL); /* * Paged usage will preset option_usage_fp to an output file. @@ -348,32 +622,42 @@ optionUsage(tOptions * pOptions, int usage_exit_code) char const * pz; if (exit_code == EXIT_SUCCESS) { - pz = (pOptions->structVersion >= 30 * 4096) - ? pOptions->pzFullUsage : NULL; + pz = (opts->structVersion >= 30 * 4096) + ? opts->pzFullUsage : NULL; if (option_usage_fp == NULL) option_usage_fp = stdout; } else { - pz = (pOptions->structVersion >= 30 * 4096) - ? pOptions->pzShortUsage : NULL; + pz = (opts->structVersion >= 30 * 4096) + ? opts->pzShortUsage : NULL; if (option_usage_fp == NULL) option_usage_fp = stderr; } - if (pz != NULL) { - fputs(pz, option_usage_fp); - exit(exit_code); + if (((opts->fOptSet & OPTPROC_COMPUTE) == 0) && (pz != NULL)) { + if ((opts->fOptSet & OPTPROC_TRANSLATE) != 0) + optionPrintParagraphs(pz, true, option_usage_fp); + else + fputs(pz, option_usage_fp); + goto flush_and_exit; } } - fprintf(option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName); - set_usage_flags(pOptions, NULL); + fprintf(option_usage_fp, opts->pzUsageTitle, opts->pzProgName); if ((exit_code == EXIT_SUCCESS) || - (! skip_misuse_usage(pOptions))) + (! skip_misuse_usage(opts))) - print_usage_details(pOptions, usage_exit_code); + print_usage_details(opts, usage_exit_code); + else + print_offer_usage(opts); + + flush_and_exit: + fflush(option_usage_fp); + if (ferror(option_usage_fp) != 0) + fserr_exit(opts->pzProgName, zwriting, (option_usage_fp == stdout) + ? zstdout_name : zstderr_name); exit(exit_code); } @@ -384,62 +668,74 @@ optionUsage(tOptions * pOptions, int usage_exit_code) /** * print option conflicts. * - * @param pOptions the program option descriptor - * @param pOD the option descriptor - * @param pAT names of the option argument types + * @param opts the program option descriptor + * @param od the option descriptor */ static void -prt_conflicts(tOptions * pOptions, tOptDesc * pOD) +prt_conflicts(tOptions * opts, tOptDesc * od) { - - fputs(zTabHyp, option_usage_fp); + const int * opt_no; + fputs(zTabHyp + tab_skip_ct, option_usage_fp); /* * REQUIRED: */ - if (pOD->pOptMust != NULL) { - const int* pOptNo = pOD->pOptMust; + if (od->pOptMust != NULL) { + opt_no = od->pOptMust; - fputs(zReqThese, option_usage_fp); - for (;;) { - fprintf(option_usage_fp, zTabout, - pOptions->pOptDesc[*pOptNo].pz_Name); - if (*++pOptNo == NO_EQUIVALENT) - break; + if (opt_no[1] == NO_EQUIVALENT) { + fprintf(option_usage_fp, zReqOne, + opts->pOptDesc[*opt_no].pz_Name); + } else { + fputs(zReqThese, option_usage_fp); + for (;;) { + fprintf(option_usage_fp, zTabout + tab_skip_ct, + opts->pOptDesc[*opt_no].pz_Name); + if (*++opt_no == NO_EQUIVALENT) + break; + } } - if (pOD->pOptCant != NULL) - fputs(zTabHypAnd, option_usage_fp); + if (od->pOptCant != NULL) + fputs(zTabHypAnd + tab_skip_ct, option_usage_fp); } /* * CONFLICTS: */ - if (pOD->pOptCant != NULL) { - const int* pOptNo = pOD->pOptCant; + if (od->pOptCant == NULL) + return; - fputs(zProhib, option_usage_fp); - for (;;) { - fprintf(option_usage_fp, zTabout, - pOptions->pOptDesc[*pOptNo].pz_Name); - if (*++pOptNo == NO_EQUIVALENT) - break; - } + opt_no = od->pOptCant; + + if (opt_no[1] == NO_EQUIVALENT) { + fprintf(option_usage_fp, zProhibOne, + opts->pOptDesc[*opt_no].pz_Name); + return; + } + + fputs(zProhib, option_usage_fp); + for (;;) { + fprintf(option_usage_fp, zTabout + tab_skip_ct, + opts->pOptDesc[*opt_no].pz_Name); + if (*++opt_no == NO_EQUIVALENT) + break; } } /** * Print the usage information for a single vendor option. * - * @param pOpts the program option descriptor - * @param pOD the option descriptor - * @param pAT names of the option argument types + * @param[in] opts the program option descriptor + * @param[in] od the option descriptor + * @param[in] argtp names of the option argument types + * @param[in] usefmt format for primary usage line */ static void -prt_one_vendor(tOptions * pOptions, tOptDesc * pOD, - arg_types_t * pAT, char const * usefmt) +prt_one_vendor(tOptions * opts, tOptDesc * od, + arg_types_t * argtp, char const * usefmt) { - prt_preamble(pOptions, pOD, pAT); + prt_preamble(opts, od, argtp); { char z[ 80 ]; @@ -450,52 +746,52 @@ prt_one_vendor(tOptions * pOptions, tOptDesc * pOD, * when the option argument is required, base the type string on the * argument type. */ - if (pOD->fOptState & OPTST_ARG_OPTIONAL) { - pzArgType = pAT->pzOpt; - - } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { - case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break; - case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break; - case OPARG_TYPE_FILE: pzArgType = pAT->pzFile; break; - case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break; - case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break; - case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break; - case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break; - case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break; - case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break; + if (od->fOptState & OPTST_ARG_OPTIONAL) { + pzArgType = argtp->pzOpt; + + } else switch (OPTST_GET_ARGTYPE(od->fOptState)) { + case OPARG_TYPE_NONE: pzArgType = argtp->pzNo; break; + case OPARG_TYPE_ENUMERATION: pzArgType = argtp->pzKey; break; + case OPARG_TYPE_FILE: pzArgType = argtp->pzFile; break; + case OPARG_TYPE_MEMBERSHIP: pzArgType = argtp->pzKeyL; break; + case OPARG_TYPE_BOOLEAN: pzArgType = argtp->pzBool; break; + case OPARG_TYPE_NUMERIC: pzArgType = argtp->pzNum; break; + case OPARG_TYPE_HIERARCHY: pzArgType = argtp->pzNest; break; + case OPARG_TYPE_STRING: pzArgType = argtp->pzStr; break; + case OPARG_TYPE_TIME: pzArgType = argtp->pzTime; break; default: goto bogus_desc; } pzArgType = SPN_WHITESPACE_CHARS(pzArgType); if (*pzArgType == NUL) - snprintf(z, sizeof(z), "%s", pOD->pz_Name); + snprintf(z, sizeof(z), "%s", od->pz_Name); else - snprintf(z, sizeof(z), "%s=%s", pOD->pz_Name, pzArgType); - fprintf(option_usage_fp, usefmt, z, pOD->pzText); + snprintf(z, sizeof(z), "%s=%s", od->pz_Name, pzArgType); + fprintf(option_usage_fp, usefmt, z, od->pzText); - switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + switch (OPTST_GET_ARGTYPE(od->fOptState)) { case OPARG_TYPE_ENUMERATION: case OPARG_TYPE_MEMBERSHIP: - displayEnum = (pOD->pOptProc != NULL) ? true : displayEnum; + displayEnum = (od->pOptProc != NULL) ? true : displayEnum; } } return; -bogus_desc: - fprintf(stderr, zInvalOptDesc, pOD->pz_Name); - exit(EX_SOFTWARE); + bogus_desc: + fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name); + ao_bug(zbad_arg_type_msg); } /** * Print the long options processed with "-W". These options will be the * ones that do *not* have flag characters. * - * @param pOptions the program option descriptor - * @param pOD the option descriptor + * @param opts the program option descriptor + * @param title the title for the options */ static void -prt_vendor_opts(tOptions * pOpts, char const * pOptTitle) +prt_vendor_opts(tOptions * opts, char const * title) { static unsigned int const not_vended_mask = OPTST_NO_USAGE_MASK | OPTST_DOCUMENT; @@ -507,51 +803,57 @@ prt_vendor_opts(tOptions * pOpts, char const * pOptTitle) * Only handle client specified options. The "vendor option" follows * "presetOptCt", so we won't loop/recurse indefinitely. */ - int ct = pOpts->presetOptCt; - tOptDesc * pOD = pOpts->pOptDesc; - size_t nmlen = 0; + int ct = opts->presetOptCt; + tOptDesc * od = opts->pOptDesc; + fprintf(option_usage_fp, zTabout + tab_skip_ct, zVendOptsAre); + + { + size_t nmlen = 0; + do { + size_t l; + if ( ((od->fOptState & not_vended_mask) != 0) + || IS_GRAPHIC_CHAR(od->optValue)) + continue; - fprintf(option_usage_fp, zTabout, zVendOptsAre); + l = strlen(od->pz_Name); + if (l > nmlen) nmlen = l; + } while (od++, (--ct > 0)); - do { - size_t l; - if ( ((pOD->fOptState & not_vended_mask) != 0) - || IS_GRAPHIC_CHAR(pOD->optValue)) - continue; + snprintf(vfmt, sizeof(vfmt), vfmtfmt, (unsigned int)nmlen + 4); + } - l = strlen(pOD->pz_Name); - if (l > nmlen) nmlen = l; - } while (pOD++, (--ct > 0)); + if (tab_skip_ct > 0) + tab_skip_ct--; - sprintf(vfmt, vfmtfmt, (unsigned int)nmlen + 4); - ct = pOpts->presetOptCt; - pOD = pOpts->pOptDesc; + ct = opts->presetOptCt; + od = opts->pOptDesc; do { - if ( ((pOD->fOptState & not_vended_mask) != 0) - || IS_GRAPHIC_CHAR(pOD->optValue)) + if ( ((od->fOptState & not_vended_mask) != 0) + || IS_GRAPHIC_CHAR(od->optValue)) continue; - prt_one_vendor(pOpts, pOD, &argTypes, vfmt); - prt_extd_usage(pOpts, pOD, pOptTitle); + prt_one_vendor(opts, od, &argTypes, vfmt); + prt_extd_usage(opts, od, title); + + } while (od++, (--ct > 0)); - } while (pOD++, (--ct > 0)); + /* no need to restore "tab_skip_ct" - options are done now */ } /** * Print extended usage. Usage/help was requested. * - * @param pOptions the program option descriptor - * @param pOD the option descriptor - * @param pAT names of the option argument types + * @param opts the program option descriptor + * @param od the option descriptor + * @param title the title for the options */ static void -prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, - char const * pOptTitle) +prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title) { - if ( ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) != 0) - && (pOD->optActualValue == VENDOR_OPTION_VALUE)) { - prt_vendor_opts(pOpts, pOptTitle); + if ( ((opts->fOptSet & OPTPROC_VENDOR_OPT) != 0) + && (od->optActualValue == VENDOR_OPTION_VALUE)) { + prt_vendor_opts(opts, title); return; } @@ -559,34 +861,33 @@ prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, * IF there are option conflicts or dependencies, * THEN print them here. */ - if ( (pOD->pOptMust != NULL) - || (pOD->pOptCant != NULL) ) - prt_conflicts(pOpts, pOD); + if ((od->pOptMust != NULL) || (od->pOptCant != NULL)) + prt_conflicts(opts, od); /* * IF there is a disablement string * THEN print the disablement info */ - if (pOD->pz_DisableName != NULL ) - fprintf(option_usage_fp, zDis, pOD->pz_DisableName); + if (od->pz_DisableName != NULL ) + fprintf(option_usage_fp, zDis + tab_skip_ct, od->pz_DisableName); /* * Check for argument types that have callbacks with magical properties */ - switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + switch (OPTST_GET_ARGTYPE(od->fOptState)) { case OPARG_TYPE_NUMERIC: /* * IF the numeric option has a special callback, * THEN call it, requesting the range or other special info */ - if ( (pOD->pOptProc != NULL) - && (pOD->pOptProc != optionNumericVal) ) { - (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); + if ( (od->pOptProc != NULL) + && (od->pOptProc != optionNumericVal) ) { + (*(od->pOptProc))(OPTPROC_EMIT_USAGE, od); } break; case OPARG_TYPE_FILE: - (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); + (*(od->pOptProc))(OPTPROC_EMIT_USAGE, od); break; } @@ -594,18 +895,18 @@ prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, * IF the option defaults to being enabled, * THEN print that out */ - if (pOD->fOptState & OPTST_INITENABLED) - fputs(zEnab, option_usage_fp); + if (od->fOptState & OPTST_INITENABLED) + fputs(zEnab + tab_skip_ct, option_usage_fp); /* * IF the option is in an equivalence class * AND not the designated lead * THEN print equivalence and leave it at that. */ - if ( (pOD->optEquivIndex != NO_EQUIVALENT) - && (pOD->optEquivIndex != pOD->optActualIndex ) ) { - fprintf(option_usage_fp, zAlt, - pOpts->pOptDesc[ pOD->optEquivIndex ].pz_Name); + if ( (od->optEquivIndex != NO_EQUIVALENT) + && (od->optEquivIndex != od->optActualIndex ) ) { + fprintf(option_usage_fp, zalt_opt + tab_skip_ct, + opts->pOptDesc[ od->optEquivIndex ].pz_Name); return; } @@ -615,32 +916,33 @@ prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, * AND it is not an auto-managed option (e.g. --help, et al.) * THEN advise that this option may not be preset. */ - if ( ((pOD->fOptState & OPTST_NO_INIT) != 0) - && ( (pOpts->papzHomeList != NULL) - || (pOpts->pzPROGNAME != NULL) + if ( ((od->fOptState & OPTST_NO_INIT) != 0) + && ( (opts->papzHomeList != NULL) + || (opts->pzPROGNAME != NULL) ) - && (pOD->optIndex < pOpts->presetOptCt) + && (od->optIndex < opts->presetOptCt) ) - fputs(zNoPreset, option_usage_fp); + fputs(zNoPreset + tab_skip_ct, option_usage_fp); /* * Print the appearance requirements. */ - if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) - fputs(zMembers, option_usage_fp); + if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_MEMBERSHIP) + fputs(zMembers + tab_skip_ct, option_usage_fp); - else switch (pOD->optMinCt) { + else switch (od->optMinCt) { case 1: case 0: - switch (pOD->optMaxCt) { - case 0: fputs(zPreset, option_usage_fp); break; - case NOLIMIT: fputs(zNoLim, option_usage_fp); break; + switch (od->optMaxCt) { + case 0: fputs(zPreset + tab_skip_ct, option_usage_fp); break; + case NOLIMIT: fputs(zNoLim + tab_skip_ct, option_usage_fp); break; case 1: break; /* * IF the max is more than one but limited, print "UP TO" message */ - default: fprintf(option_usage_fp, zUpTo, pOD->optMaxCt); break; + default: + fprintf(option_usage_fp, zUpTo + tab_skip_ct, od->optMaxCt); break; } break; @@ -648,12 +950,13 @@ prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, /* * More than one is required. Print the range. */ - fprintf(option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt); + fprintf(option_usage_fp, zMust + tab_skip_ct, + od->optMinCt, od->optMaxCt); } - if ( NAMED_OPTS(pOpts) - && (pOpts->specOptIdx.default_opt == pOD->optIndex)) - fputs(zDefaultOpt, option_usage_fp); + if ( NAMED_OPTS(opts) + && (opts->specOptIdx.default_opt == od->optIndex)) + fputs(zDefaultOpt + tab_skip_ct, option_usage_fp); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -664,53 +967,53 @@ prt_extd_usage(tOptions * pOpts, tOptDesc * pOD, * squishy, but important to tell users how to find these files. */ static void -prt_ini_list(char const * const * papz, bool * pInitIntro, - char const * pzRc, char const * pzPN) +prt_ini_list(char const * const * papz, bool * need_intro, + char const * ini_file, char const * path_nm) { - char zPath[AG_PATH_MAX+1]; + char pth_buf[AG_PATH_MAX+1]; if (papz == NULL) return; fputs(zPresetIntro, option_usage_fp); - *pInitIntro = false; + *need_intro = false; for (;;) { - char const * pzPath = *(papz++); - char const * pzReal = zPath; + char const * path = *(papz++); + char const * nm_buf = pth_buf; - if (pzPath == NULL) + if (path == NULL) break; /* * Ignore any invalid paths */ - if (! optionMakePath(zPath, (int)sizeof(zPath), pzPath, pzPN)) - pzReal = pzPath; + if (! optionMakePath(pth_buf, (int)sizeof(pth_buf), path, path_nm)) + nm_buf = path; /* * Expand paths that are relative to the executable or installation * directories. Leave alone paths that use environment variables. */ - else if ((*pzPath == '$') - && ((pzPath[1] == '$') || (pzPath[1] == '@'))) - pzPath = pzReal; + else if ((*path == '$') + && ((path[1] == '$') || (path[1] == '@'))) + path = nm_buf; /* * Print the name of the "homerc" file. If the "rcfile" name is * not empty, we may or may not print that, too... */ - fprintf(option_usage_fp, zPathFmt, pzPath); - if (*pzRc != NUL) { + fprintf(option_usage_fp, zPathFmt, path); + if (*ini_file != NUL) { struct stat sb; /* * IF the "homerc" file is a directory, * then append the "rcfile" name. */ - if ((stat(pzReal, &sb) == 0) && S_ISDIR(sb.st_mode)) { - fputc(DIRCH, option_usage_fp); - fputs(pzRc, option_usage_fp); + if ((stat(nm_buf, &sb) == 0) && S_ISDIR(sb.st_mode)) { + fputc(DIRCH, option_usage_fp); + fputs(ini_file, option_usage_fp); } } @@ -720,7 +1023,7 @@ prt_ini_list(char const * const * papz, bool * pInitIntro, static void -prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) +prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at) { /* * Flag prefix: IF no flags at all, then omit it. If not printable @@ -728,18 +1031,18 @@ prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) * Follow it with a comma if we are doing GNU usage and long * opts are to be printed too. */ - if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0) - fputs(pAT->pzSpc, option_usage_fp); + if ((opts->fOptSet & OPTPROC_SHORTOPT) == 0) + fputs(at->pzSpc, option_usage_fp); - else if (! IS_GRAPHIC_CHAR(pOD->optValue)) { - if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) + else if (! IS_GRAPHIC_CHAR(od->optValue)) { + if ( (opts->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) fputc(' ', option_usage_fp); - fputs(pAT->pzNoF, option_usage_fp); + fputs(at->pzNoF, option_usage_fp); } else { - fprintf(option_usage_fp, " -%c", pOD->optValue); - if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) + fprintf(option_usage_fp, " -%c", od->optValue); + if ( (opts->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) fputs(", ", option_usage_fp); } @@ -748,63 +1051,63 @@ prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) /** * Print the usage information for a single option. * - * @param pOpts the program option descriptor - * @param pOD the option descriptor - * @param pAT names of the option argument types + * @param opts the program option descriptor + * @param od the option descriptor + * @param at names of the option argument types */ static void -prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) +prt_one_usage(tOptions * opts, tOptDesc * od, arg_types_t * at) { - prt_preamble(pOptions, pOD, pAT); + prt_preamble(opts, od, at); { - char z[ 80 ]; - char const * pzArgType; + char z[80]; + char const * atyp; /* * Determine the argument type string first on its usage, then, * when the option argument is required, base the type string on the * argument type. */ - if (pOD->fOptState & OPTST_ARG_OPTIONAL) { - pzArgType = pAT->pzOpt; - - } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { - case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break; - case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break; - case OPARG_TYPE_FILE: pzArgType = pAT->pzFile; break; - case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break; - case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break; - case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break; - case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break; - case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break; - case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break; + if (od->fOptState & OPTST_ARG_OPTIONAL) { + atyp = at->pzOpt; + + } else switch (OPTST_GET_ARGTYPE(od->fOptState)) { + case OPARG_TYPE_NONE: atyp = at->pzNo; break; + case OPARG_TYPE_ENUMERATION: atyp = at->pzKey; break; + case OPARG_TYPE_FILE: atyp = at->pzFile; break; + case OPARG_TYPE_MEMBERSHIP: atyp = at->pzKeyL; break; + case OPARG_TYPE_BOOLEAN: atyp = at->pzBool; break; + case OPARG_TYPE_NUMERIC: atyp = at->pzNum; break; + case OPARG_TYPE_HIERARCHY: atyp = at->pzNest; break; + case OPARG_TYPE_STRING: atyp = at->pzStr; break; + case OPARG_TYPE_TIME: atyp = at->pzTime; break; default: goto bogus_desc; } #ifdef _WIN32 - if (pAT->pzOptFmt == zGnuOptFmt) - snprintf(z, sizeof(z), "--%s%s", pOD->pz_Name, pzArgType); - else if (pAT->pzOptFmt == zGnuOptFmt + 2) - snprintf(z, sizeof(z), "%s%s", pOD->pz_Name, pzArgType); + if (at->pzOptFmt == zGnuOptFmt) + snprintf(z, sizeof(z), "--%s%s", od->pz_Name, atyp); + else if (at->pzOptFmt == zGnuOptFmt + 2) + snprintf(z, sizeof(z), "%s%s", od->pz_Name, atyp); else #endif - snprintf(z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name, - (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt); + snprintf(z, sizeof(z), at->pzOptFmt, atyp, od->pz_Name, + (od->optMinCt != 0) ? at->pzReq : at->pzOpt); - fprintf(option_usage_fp, line_fmt_buf, z, pOD->pzText); + fprintf(option_usage_fp, line_fmt_buf, z, od->pzText); - switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + switch (OPTST_GET_ARGTYPE(od->fOptState)) { case OPARG_TYPE_ENUMERATION: case OPARG_TYPE_MEMBERSHIP: - displayEnum = (pOD->pOptProc != NULL) ? true : displayEnum; + displayEnum = (od->pOptProc != NULL) ? true : displayEnum; } } return; -bogus_desc: - fprintf(stderr, zInvalOptDesc, pOD->pz_Name); + bogus_desc: + fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name); exit(EX_SOFTWARE); } @@ -812,11 +1115,11 @@ bogus_desc: * Print out the usage information for just the options. */ static void -prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) +prt_opt_usage(tOptions * opts, int ex_code, char const * title) { - int ct = pOpts->optCt; + int ct = opts->optCt; int optNo = 0; - tOptDesc * pOD = pOpts->pOptDesc; + tOptDesc * od = opts->pOptDesc; int docCt = 0; do { @@ -825,7 +1128,7 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) * deprecated -- strongly discouraged (OPTST_DEPRECATED), or * compiled out of current object code (OPTST_OMITTED) */ - if ((pOD->fOptState & OPTST_NO_USAGE_MASK) != 0) { + if ((od->fOptState & OPTST_NO_USAGE_MASK) != 0) { /* * IF this is a compiled-out option @@ -833,23 +1136,23 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) * *AND* this is NOT abbreviated usage * THEN display this option. */ - if ( (pOD->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) - && (pOD->pz_Name != NULL) + if ( (od->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) + && (od->pz_Name != NULL) && (ex_code == EXIT_SUCCESS)) { char const * why_pz = - (pOD->pzText == NULL) ? zDisabledWhy : pOD->pzText; - prt_preamble(pOpts, pOD, &argTypes); - fprintf(option_usage_fp, zDisabledOpt, pOD->pz_Name, why_pz); + (od->pzText == NULL) ? zDisabledWhy : od->pzText; + prt_preamble(opts, od, &argTypes); + fprintf(option_usage_fp, zDisabledOpt, od->pz_Name, why_pz); } continue; } - if ((pOD->fOptState & OPTST_DOCUMENT) != 0) { + if ((od->fOptState & OPTST_DOCUMENT) != 0) { if (ex_code == EXIT_SUCCESS) { - fprintf(option_usage_fp, argTypes.pzBrk, pOD->pzText, - pOptTitle); + fprintf(option_usage_fp, argTypes.pzBrk, od->pzText, + title); docCt++; } @@ -857,8 +1160,8 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) } /* Skip name only options when we have a vendor option */ - if ( ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) != 0) - && (! IS_GRAPHIC_CHAR(pOD->optValue))) + if ( ((opts->fOptSet & OPTPROC_VENDOR_OPT) != 0) + && (! IS_GRAPHIC_CHAR(od->optValue))) continue; /* @@ -869,25 +1172,25 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) * THEN document that the remaining options are not user opts */ if ((docCt > 0) && (ex_code == EXIT_SUCCESS)) { - if (pOpts->presetOptCt == optNo) { - if ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) - fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle); + if (opts->presetOptCt == optNo) { + if ((od[-1].fOptState & OPTST_DOCUMENT) == 0) + fprintf(option_usage_fp, argTypes.pzBrk, zAuto, title); } else if ((ct == 1) && - (pOpts->fOptSet & OPTPROC_VENDOR_OPT)) - fprintf(option_usage_fp, argTypes.pzBrk, zVendIntro, pOptTitle); + (opts->fOptSet & OPTPROC_VENDOR_OPT)) + fprintf(option_usage_fp, argTypes.pzBrk, zVendIntro, title); } - prt_one_usage(pOpts, pOD, &argTypes); + prt_one_usage(opts, od, &argTypes); /* * IF we were invoked because of the --help option, * THEN print all the extra info */ if (ex_code == EXIT_SUCCESS) - prt_extd_usage(pOpts, pOD, pOptTitle); + prt_extd_usage(opts, od, title); - } while (pOD++, optNo++, (--ct > 0)); + } while (od++, optNo++, (--ct > 0)); fputc(NL, option_usage_fp); } @@ -898,24 +1201,24 @@ prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) * PROGRAM DETAILS */ static void -prt_prog_detail(tOptions* pOptions) +prt_prog_detail(tOptions * opts) { - bool initIntro = true; + bool need_intro = true; /* * Display all the places we look for config files */ - prt_ini_list(pOptions->papzHomeList, &initIntro, - pOptions->pzRcName, pOptions->pzProgPath); + prt_ini_list(opts->papzHomeList, &need_intro, + opts->pzRcName, opts->pzProgPath); /* * Let the user know about environment variable settings */ - if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) { - if (initIntro) + if ((opts->fOptSet & OPTPROC_ENVIRON) != 0) { + if (need_intro) fputs(zPresetIntro, option_usage_fp); - fprintf(option_usage_fp, zExamineFmt, pOptions->pzPROGNAME); + fprintf(option_usage_fp, zExamineFmt, opts->pzPROGNAME); } /* @@ -924,26 +1227,26 @@ prt_prog_detail(tOptions* pOptions) * option struct pointer. That tells it to display the keywords. */ if (displayEnum) { - int ct = pOptions->optCt; + int ct = opts->optCt; int optNo = 0; - tOptDesc* pOD = pOptions->pOptDesc; + tOptDesc * od = opts->pOptDesc; fputc(NL, option_usage_fp); fflush(option_usage_fp); do { - switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + switch (OPTST_GET_ARGTYPE(od->fOptState)) { case OPARG_TYPE_ENUMERATION: case OPARG_TYPE_MEMBERSHIP: - (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); + (*(od->pOptProc))(OPTPROC_EMIT_USAGE, od); } - } while (pOD++, optNo++, (--ct > 0)); + } while (od++, optNo++, (--ct > 0)); } /* * If there is a detail string, now is the time for that. */ - if (pOptions->pzDetail != NULL) - fputs(pOptions->pzDetail, option_usage_fp); + if (opts->pzDetail != NULL) + fputs(opts->pzDetail, option_usage_fp); } @@ -962,11 +1265,11 @@ prt_prog_detail(tOptions* pOptions) * Set up the formatting for GNU-style output */ static int -setGnuOptFmts(tOptions* pOpts, tCC** ppT) +setGnuOptFmts(tOptions * opts, char const ** ptxt) { static char const zOneSpace[] = " "; int flen = 22; - *ppT = zNoRq_ShrtTtl; + *ptxt = zNoRq_ShrtTtl; argTypes.pzStr = zGnuStrArg; argTypes.pzReq = zOneSpace; @@ -983,7 +1286,7 @@ setGnuOptFmts(tOptions* pOpts, tCC** ppT) argTypes.pzNoF = zSixSpaces; argTypes.pzSpc = zThreeSpaces; - switch (pOpts->fOptSet & OPTPROC_L_N_S) { + switch (opts->fOptSet & OPTPROC_L_N_S) { case OPTPROC_L_N_S: argTypes.pzOptFmt = zGnuOptFmt; break; case OPTPROC_LONGOPT: argTypes.pzOptFmt = zGnuOptFmt; break; case 0: argTypes.pzOptFmt = zGnuOptFmt + 2; break; @@ -1003,7 +1306,7 @@ setGnuOptFmts(tOptions* pOpts, tCC** ppT) * Standard (AutoOpts normal) option line formatting */ static int -setStdOptFmts(tOptions* pOpts, tCC** ppT) +setStdOptFmts(tOptions * opts, char const ** ptxt) { int flen = 0; @@ -1022,27 +1325,27 @@ setStdOptFmts(tOptions* pOpts, tCC** ppT) argTypes.pzNoF = zFiveSpaces; argTypes.pzSpc = zTwoSpaces; - switch (pOpts->fOptSet & (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT)) { + switch (opts->fOptSet & (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT)) { case (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT): - *ppT = zNoRq_ShrtTtl; + *ptxt = zNoRq_ShrtTtl; argTypes.pzOptFmt = zNrmOptFmt; flen = 19; break; case OPTPROC_NO_REQ_OPT: - *ppT = zNoRq_NoShrtTtl; + *ptxt = zNoRq_NoShrtTtl; argTypes.pzOptFmt = zNrmOptFmt; flen = 19; break; case OPTPROC_SHORTOPT: - *ppT = zReq_ShrtTtl; + *ptxt = zReq_ShrtTtl; argTypes.pzOptFmt = zReqOptFmt; flen = 24; break; case 0: - *ppT = zReq_NoShrtTtl; + *ptxt = zReq_NoShrtTtl; argTypes.pzOptFmt = zReqOptFmt; flen = 24; } @@ -1050,8 +1353,8 @@ setStdOptFmts(tOptions* pOpts, tCC** ppT) return flen; } - -/*: +/** @} + * * Local Variables: * mode: C * c-file-style: "stroustrup" diff --git a/src/libopts/version.c b/src/libopts/version.c index 24041b2013..8f2b1db322 100644 --- a/src/libopts/version.c +++ b/src/libopts/version.c @@ -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); - - else if (pOpts->pzFullVersion != NULL) - fputs(pOpts->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); - } + if (o->pzCopyright != NULL) + fputs(o->pzCopyright, fp); - fputc(NL, fp); + else if (o->pzFullVersion != NULL) + fputs(o->pzFullVersion, fp); - if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL)) - fputs(pOpts->pzPackager, 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 (pOpts->pzBugAddr != NULL) - fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr); + } 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 * pOpts, FILE * fp) +emit_copy_note(tOptions * opts, FILE * fp) { - if (pOpts->pzCopyright != NULL) { - fputs(pOpts->pzCopyright, 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 (pOpts->pzCopyNotice != NULL) { - fputs(pOpts->pzCopyNotice, fp); + } else if (opts->pzBugAddr != NULL) { fputc(NL, fp); + fprintf(fp, zPlsSendBugs, opts->pzBugAddr); } - - 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); } +/** + * Handle the version printing. We must see how much information + * is being requested and select the correct printing routine. + */ 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" |