updated libopts to 5.18

This commit is contained in:
Nikos Mavrogiannopoulos
2013-11-05 21:04:56 +01:00
parent 6cfa963a1b
commit e7e29b8396
34 changed files with 1152 additions and 926 deletions
+6 -6
View File
@@ -8,16 +8,16 @@ libopts_a_CPPFLAGS = -I$(top_srcdir)
EXTRA_DIST = \ EXTRA_DIST = \
ag-char-map.h alias.c ao-strs.c \ ag-char-map.h alias.c ao-strs.c \
ao-strs.h autoopts/options.h autoopts/project.h \ ao-strs.h autoopts/options.h autoopts/usage-txt.h \
autoopts/usage-txt.h autoopts.c autoopts.h \ autoopts/project.h autoopts.c autoopts.h \
boolean.c check.c compat/strchr.c \ boolean.c check.c compat/strdup.c \
compat/snprintf.c compat/compat.h compat/windows-config.h \ compat/strchr.c compat/snprintf.c compat/compat.h \
compat/pathfind.c compat/strdup.c configfile.c \ compat/pathfind.c compat/windows-config.h configfile.c \
cook.c COPYING.gplv3 COPYING.lgplv3 \ cook.c COPYING.gplv3 COPYING.lgplv3 \
COPYING.mbsd enum.c env.c \ COPYING.mbsd enum.c env.c \
file.c find.c genshell.c \ file.c find.c genshell.c \
genshell.h gettext.h init.c \ genshell.h gettext.h init.c \
load.c m4/libopts.m4 m4/liboptschk.m4 \ load.c m4/liboptschk.m4 m4/libopts.m4 \
MakeDefs.inc makeshell.c nested.c \ MakeDefs.inc makeshell.c nested.c \
numeric.c option-value-type.c option-value-type.h \ numeric.c option-value-type.c option-value-type.h \
option-xat-attribute.c option-xat-attribute.h parse-duration.c \ option-xat-attribute.c option-xat-attribute.h parse-duration.c \
+6 -6
View File
@@ -1,6 +1,6 @@
/* /*
* 29 bits for 46 character classifications * 29 bits for 46 character classifications
* generated by char-mapper on 03/31/13 at 10:41:23 * generated by char-mapper on 07/14/13 at 17:37:05
* *
* This file contains the character classifications * This file contains the character classifications
* used by AutoGen and AutoOpts for identifying tokens. * used by AutoGen and AutoOpts for identifying tokens.
@@ -103,7 +103,7 @@
// file-name +dir-sep +suffix // file-name +dir-sep +suffix
// end-token +nul-byte +whitespace // end-token +nul-byte +whitespace
// end-list-entry +comma +end-token // end-list-entry +comma +end-token
// set-separator "|+" +end-list-entry // set-separator "|+-!" +end-list-entry
// signed-number +inversion +dec-digit // signed-number +inversion +dec-digit
// make-script +dollar +newline // make-script +dollar +newline
// load-line-skip +horiz-white +option-marker // load-line-skip +horiz-white +option-marker
@@ -489,7 +489,7 @@ spn_ag_char_map_chars(char const * p, unsigned int mask_ix)
unsigned char const * v = ag_char_map_spanners[mask_ix]; unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL) if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix); v = calc_ag_char_map_spanners(mask_ix);
while (v[(unsigned char)*p]) p++; while (v[(unsigned)*p]) p++;
return (char *)(uintptr_t)p; return (char *)(uintptr_t)p;
} }
@@ -499,7 +499,7 @@ brk_ag_char_map_chars(char const * p, unsigned int mask_ix)
unsigned char const * v = ag_char_map_spanners[mask_ix]; unsigned char const * v = ag_char_map_spanners[mask_ix];
if (v == NULL) if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix); v = calc_ag_char_map_spanners(mask_ix);
while ((*p != '\0') && (! v[(unsigned char)*p])) p++; while ((*p != '\0') && (! v[(unsigned)*p])) p++;
return (char *)(uintptr_t)p; return (char *)(uintptr_t)p;
} }
@@ -510,7 +510,7 @@ spn_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
if (v == NULL) if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix); v = calc_ag_char_map_spanners(mask_ix);
if (s >= e) e = s + strlen(s); if (s >= e) e = s + strlen(s);
while ((e > s) && v[(unsigned char)e[-1]]) e--; while ((e > s) && v[(unsigned)e[-1]]) e--;
return (char *)(uintptr_t)e; return (char *)(uintptr_t)e;
} }
@@ -521,7 +521,7 @@ brk_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
if (v == NULL) if (v == NULL)
v = calc_ag_char_map_spanners(mask_ix); v = calc_ag_char_map_spanners(mask_ix);
if (s == e) e += strlen(e); if (s == e) e += strlen(e);
while ((e > s) && (! v[(unsigned char)e[-1]])) e--; while ((e > s) && (! v[(unsigned)e[-1]])) e--;
return (char *)(uintptr_t)e; return (char *)(uintptr_t)e;
} }
#endif /* AG_CHAR_MAP_H_GUARD */ #endif /* AG_CHAR_MAP_H_GUARD */
+1 -1
View File
@@ -74,7 +74,7 @@ optionAlias(tOptions * opts, tOptDesc * old_od, unsigned int alias)
new_od = opts->pOptDesc + alias; new_od = opts->pOptDesc + alias;
if ((unsigned)opts->optCt <= alias) { if ((unsigned)opts->optCt <= alias) {
fputs(zbad_alias_id, stderr); fputs(zbad_alias_id, stderr);
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
} }
/* /*
+58 -56
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ao-strs.c) * DO NOT EDIT THIS FILE (ao-strs.c)
* *
* It has been AutoGen-ed March 31, 2013 at 10:41:23 AM by AutoGen 5.17.3 * It has been AutoGen-ed July 14, 2013 at 05:37:05 PM by AutoGen 5.18
* From the definitions ao-strs.def * From the definitions ao-strs.def
* and the template file strings * and the template file strings
* *
@@ -38,7 +38,7 @@
*/ */
#include "ao-strs.h" #include "ao-strs.h"
char const ao_strs_strtable[6637] = char const ao_strs_strtable[6633] =
/* 0 */ "-_^\0" /* 0 */ "-_^\0"
/* 4 */ " %s%s\n\0" /* 4 */ " %s%s\n\0"
/* 12 */ "auto-options\0" /* 12 */ "auto-options\0"
@@ -130,65 +130,67 @@ char const ao_strs_strtable[6637] =
/* 625 */ "=%1$lu # 0x%1$lX\n\0" /* 625 */ "=%1$lu # 0x%1$lX\n\0"
/* 643 */ "stdout\0" /* 643 */ "stdout\0"
/* 650 */ "%A %B %e, %Y at %r %Z\0" /* 650 */ "%A %B %e, %Y at %r %Z\0"
/* 672 */ "/tmp/use.%lu\0" /* 672 */ "%s/use-%u.XXXXXX\0"
/* 685 */ "true\0" /* 689 */ "true\0"
/* 690 */ "<%s type=%s>\0" /* 694 */ "<%s type=%s>\0"
/* 703 */ "VERSION\0" /* 707 */ "VERSION\0"
/* 711 */ "#x%02X;\0" /* 715 */ "#x%02X;\0"
/* 719 */ "OPT_ARG_NEEDED=YES\0" /* 723 */ "OPT_ARG_NEEDED=YES\0"
/* 738 */ "'\\''\0" /* 742 */ "'\\''\0"
/* 743 */ " '%s'\0" /* 747 */ " '%s'\0"
/* 749 */ "\n" /* 753 */ "\n"
"OPTION_CT=0\n\0" "OPTION_CT=0\n\0"
/* 763 */ "set --\0" /* 767 */ "set --\0"
/* 770 */ " ;;\n\n\0" /* 774 */ " ;;\n\n\0"
/* 787 */ " '%c' )\n\0" /* 791 */ " '%c' )\n\0"
/* 803 */ " '%s' )\n\0" /* 807 */ " '%s' )\n\0"
/* 819 */ " '%s' | \\\n\0" /* 823 */ " '%s' | \\\n\0"
/* 837 */ "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu\0" /* 841 */ "TMPDIR\0"
/* 880 */ "<%1$s type=boolean>%2$s</%1$s>\n\0" /* 848 */ "/tmp\0"
/* 912 */ "# From the %s option definitions\n" /* 853 */ "%1$s %2$s ; rm -f %2$s\0"
/* 876 */ "<%1$s type=boolean>%2$s</%1$s>\n\0"
/* 908 */ "# From the %s option definitions\n"
"#\n\0" "#\n\0"
/* 949 */ "echo 'Warning: Cannot load options files' >&2\0" /* 945 */ "echo 'Warning: Cannot load options files' >&2\0"
/* 996 */ "echo 'Warning: Cannot save options files' >&2\0" /* 992 */ "echo 'Warning: Cannot save options files' >&2\0"
/* 1043 */ "echo 'Warning: Cannot suppress the loading of options files' >&2\0" /* 1039 */ "echo 'Warning: Cannot suppress the loading of options files' >&2\0"
/* 1109 */ "<%1$s type=integer>0x%2$lX</%1$s>\n\0" /* 1105 */ "<%1$s type=integer>0x%2$lX</%1$s>\n\0"
/* 1144 */ "%1$s_%2$s_TEXT='no %2$s text'\n\0" /* 1140 */ "%1$s_%2$s_TEXT='no %2$s text'\n\0"
/* 1175 */ "%1$s_%2$s_MODE='%3$s'\n" /* 1171 */ "%1$s_%2$s_MODE='%3$s'\n"
"export %1$s_%2$s_MODE\n\0" "export %1$s_%2$s_MODE\n\0"
/* 1220 */ "%1$s_%2$s='%3$s'\n" /* 1216 */ "%1$s_%2$s='%3$s'\n"
"export %1$s_%2$s\n\0" "export %1$s_%2$s\n\0"
/* 1255 */ "%1$s_%2$s_CT=%3$d\n" /* 1251 */ "%1$s_%2$s_CT=%3$d\n"
"export %1$s_%2$s_CT\n\0" "export %1$s_%2$s_CT\n\0"
/* 1294 */ "OPTION_CT=%d\n" /* 1290 */ "OPTION_CT=%d\n"
"export OPTION_CT\n\0" "export OPTION_CT\n\0"
/* 1325 */ "%1$s_%2$s=%3$s\n" /* 1321 */ "%1$s_%2$s=%3$s\n"
"export %1$s_%2$s\n\0" "export %1$s_%2$s\n\0"
/* 1358 */ "%1$s_%2$s=%3$d # 0x%3$X\n" /* 1354 */ "%1$s_%2$s=%3$d # 0x%3$X\n"
"export %1$s_%2$s\n\0" "export %1$s_%2$s\n\0"
/* 1400 */ " case \"${OPT_CODE}\" in\n\0" /* 1396 */ " case \"${OPT_CODE}\" in\n\0"
/* 1431 */ " if [ $%1$s_%2$s_CT -gt %3$u ] ; then\n" /* 1427 */ " if [ $%1$s_%2$s_CT -gt %3$u ] ; then\n"
" echo 'Error: more than %3$d %2$s options'\n" " echo 'Error: more than %3$d %2$s options'\n"
" echo \"$%1$s_USAGE_TEXT\"\n" " echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n" " exit 1\n"
" fi >&2\n\0" " fi >&2\n\0"
/* 1622 */ "test ${%1$s_%2$s_CT-0} -ge %3$u || {\n" /* 1618 */ "test ${%1$s_%2$s_CT-0} -ge %3$u || {\n"
" echo %1$s_%2$s has not been set\n" " echo %1$s_%2$s has not been set\n"
" exit 1\n" " exit 1\n"
"} 1>&2\n\0" "} 1>&2\n\0"
/* 1714 */ "test -n \"$%1$s_%2$s\" || {\n" /* 1710 */ "test -n \"$%1$s_%2$s\" || {\n"
" echo %1$s_%2$s has not been set\n" " echo %1$s_%2$s has not been set\n"
" exit 1\n" " exit 1\n"
"} 1>&2\n\0" "} 1>&2\n\0"
/* 1795 */ " echo \"$%s_%s_TEXT\"\n" /* 1791 */ " echo \"$%s_%s_TEXT\"\n"
" exit 0\n\0" " exit 0\n\0"
/* 1846 */ "\n" /* 1842 */ "\n"
"# # # # # # # # # #\n" "# # # # # # # # # #\n"
"#\n" "#\n"
"# END OF AUTOMATED OPTION PROCESSING\n" "# END OF AUTOMATED OPTION PROCESSING\n"
"#\n" "#\n"
"# # # # # # # # # # -- do not modify this marker --\n\0" "# # # # # # # # # # -- do not modify this marker --\n\0"
/* 1962 */ " if [ -n \"${OPT_ARG_VAL}\" ]\n" /* 1958 */ " if [ -n \"${OPT_ARG_VAL}\" ]\n"
" then\n" " then\n"
" eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n" " eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n"
" export %1$s_${OPT_NAME}${OPT_ELEMENT}\n" " export %1$s_${OPT_NAME}${OPT_ELEMENT}\n"
@@ -203,15 +205,15 @@ char const ao_strs_strtable[6637] =
"unset OPT_NAME || :\n" "unset OPT_NAME || :\n"
"unset OPT_CODE || :\n" "unset OPT_CODE || :\n"
"unset OPT_ARG_VAL || :\n\0" "unset OPT_ARG_VAL || :\n\0"
/* 2341 */ " OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n" /* 2337 */ " OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n"
" shift\n" " shift\n"
" OPT_ARG=$1\n" " OPT_ARG=$1\n"
" case \"${OPT_CODE}\" in *=* )\n" " case \"${OPT_CODE}\" in *=* )\n"
" OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n" " OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n"
" OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\0" " OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\0"
/* 2592 */ " OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n" /* 2588 */ " OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n"
" OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\0" " OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\0"
/* 2709 */ "\n" /* 2705 */ "\n"
"ARG_COUNT=$#\n" "ARG_COUNT=$#\n"
"OPT_PROCESS=true\n" "OPT_PROCESS=true\n"
"OPT_ARG=$1\n" "OPT_ARG=$1\n"
@@ -224,7 +226,7 @@ char const ao_strs_strtable[6637] =
" OPT_PROCESS=false\n" " OPT_PROCESS=false\n"
" shift\n" " shift\n"
" ;;\n\0" " ;;\n\0"
/* 2916 */ " case \"${OPT_ARG_NEEDED}\" in\n" /* 2912 */ " case \"${OPT_ARG_NEEDED}\" in\n"
" NO )\n" " NO )\n"
" OPT_ARG_VAL=''\n" " OPT_ARG_VAL=''\n"
" ;;\n" " ;;\n"
@@ -252,10 +254,10 @@ char const ao_strs_strtable[6637] =
" fi\n" " fi\n"
" ;;\n" " ;;\n"
" esac\n\0" " esac\n\0"
/* 3695 */ " %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n" /* 3691 */ " %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n"
" OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n" " OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n"
" OPT_NAME='%2$s'\n\0" " OPT_NAME='%2$s'\n\0"
/* 3819 */ "\n" /* 3815 */ "\n"
"if test -z \"${%1$s_%2$s}\"\n" "if test -z \"${%1$s_%2$s}\"\n"
"then\n" "then\n"
" %1$s_%2$s_CT=0\n" " %1$s_%2$s_CT=0\n"
@@ -265,16 +267,16 @@ char const ao_strs_strtable[6637] =
" %1$s_%2$s_1=${%1$s_%2$s}\n" " %1$s_%2$s_1=${%1$s_%2$s}\n"
" export %1$s_%2$s_CT %1$s_%2$s_1\n" " export %1$s_%2$s_CT %1$s_%2$s_1\n"
"fi\n\0" "fi\n\0"
/* 3977 */ " * )\n" /* 3973 */ " * )\n"
" OPT_PROCESS=false\n" " OPT_PROCESS=false\n"
" ;;\n" " ;;\n"
" esac\n\0" " esac\n\0"
/* 4034 */ " %1$s_%2$s_CT=0\n" /* 4030 */ " %1$s_%2$s_CT=0\n"
" OPT_ELEMENT=''\n" " OPT_ELEMENT=''\n"
" %1$s_%2$s='%3$s'\n" " %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n" " export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0" " OPT_NAME='%2$s'\n\0"
/* 4175 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n" /* 4171 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo 'Error: duplicate %2$s option'\n" " echo 'Error: duplicate %2$s option'\n"
" echo \"$%1$s_USAGE_TEXT\"\n" " echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n" " exit 1\n"
@@ -283,7 +285,7 @@ char const ao_strs_strtable[6637] =
" %1$s_%2$s='%3$s'\n" " %1$s_%2$s='%3$s'\n"
" export %1$s_%2$s\n" " export %1$s_%2$s\n"
" OPT_NAME='%2$s'\n\0" " OPT_NAME='%2$s'\n\0"
/* 4492 */ "\n" /* 4488 */ "\n"
"ARG_COUNT=$#\n" "ARG_COUNT=$#\n"
"OPT_ARG=$1\n" "OPT_ARG=$1\n"
"while [ $# -gt 0 ]\n" "while [ $# -gt 0 ]\n"
@@ -291,7 +293,7 @@ char const ao_strs_strtable[6637] =
" OPT_ELEMENT=''\n" " OPT_ELEMENT=''\n"
" OPT_ARG_VAL=''\n" " OPT_ARG_VAL=''\n"
" OPT_ARG=${1}\n\0" " OPT_ARG=${1}\n\0"
/* 4595 */ " case \"${OPT_ARG_NEEDED}\" in\n" /* 4591 */ " case \"${OPT_ARG_NEEDED}\" in\n"
" NO )\n" " NO )\n"
" if [ -n \"${OPT_ARG}\" ]\n" " if [ -n \"${OPT_ARG}\" ]\n"
" then\n" " then\n"
@@ -336,33 +338,33 @@ char const ao_strs_strtable[6637] =
" fi\n" " fi\n"
" ;;\n" " ;;\n"
" esac\n\0" " esac\n\0"
/* 5749 */ " echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n" /* 5745 */ " echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n"
" exit 0\n\0" " exit 0\n\0"
/* 5823 */ "%s OF %s\n" /* 5819 */ "%s OF %s\n"
"#\n" "#\n"
"# From here to the next `-- do not modify this marker --',\n" "# From here to the next `-- do not modify this marker --',\n"
"# the text has been generated %s\n\0" "# the text has been generated %s\n\0"
/* 5929 */ " eval %1$s_%2$s${OPT_ELEMENT}=true\n" /* 5925 */ " eval %1$s_%2$s${OPT_ELEMENT}=true\n"
" export %1$s_%2$s${OPT_ELEMENT}\n\0" " export %1$s_%2$s${OPT_ELEMENT}\n\0"
/* 6019 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n" /* 6015 */ " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
" echo 'Error: duplicate %2$s option'\n" " echo 'Error: duplicate %2$s option'\n"
" echo \"$%1$s_USAGE_TEXT\"\n" " echo \"$%1$s_USAGE_TEXT\"\n"
" exit 1\n" " exit 1\n"
" fi >&2\n" " fi >&2\n"
" %1$s_%2$s_set=true\n" " %1$s_%2$s_set=true\n"
" OPT_NAME='%2$s'\n\0" " OPT_NAME='%2$s'\n\0"
/* 6278 */ "\n" /* 6274 */ "\n"
"%1$s_%2$s=${%1$s_%2$s-'%3$s'}\n" "%1$s_%2$s=${%1$s_%2$s-'%3$s'}\n"
"%1$s_%2$s_set=false\n" "%1$s_%2$s_set=false\n"
"export %1$s_%2$s\n\0" "export %1$s_%2$s\n\0"
/* 6347 */ "\n" /* 6343 */ "\n"
"%1$s_%2$s=${%1$s_%2$s}\n" "%1$s_%2$s=${%1$s_%2$s}\n"
"%1$s_%2$s_set=false\n" "%1$s_%2$s_set=false\n"
"export %1$s_%2$s\n\0" "export %1$s_%2$s\n\0"
/* 6409 */ "# # # # # # # # # # -- do not modify this marker --\n" /* 6405 */ "# # # # # # # # # # -- do not modify this marker --\n"
"#\n" "#\n"
"# DO NOT EDIT THIS SECTION\n\0" "# DO NOT EDIT THIS SECTION\n\0"
/* 6492 */ " * )\n" /* 6488 */ " * )\n"
" echo Unknown %s: \"${OPT_CODE}\" >&2\n" " echo Unknown %s: \"${OPT_CODE}\" >&2\n"
" echo \"$%s_USAGE_TEXT\" >&2\n" " echo \"$%s_USAGE_TEXT\" >&2\n"
" exit 1\n" " exit 1\n"
+64 -60
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ao-strs.h) * DO NOT EDIT THIS FILE (ao-strs.h)
* *
* It has been AutoGen-ed March 31, 2013 at 10:41:23 AM by AutoGen 5.17.3 * It has been AutoGen-ed July 14, 2013 at 05:37:05 PM by AutoGen 5.18
* From the definitions ao-strs.def * From the definitions ao-strs.def
* and the template file strings * and the template file strings
* *
@@ -39,29 +39,29 @@
#ifndef STRINGS_AO_STRS_H_GUARD #ifndef STRINGS_AO_STRS_H_GUARD
#define STRINGS_AO_STRS_H_GUARD 1 #define STRINGS_AO_STRS_H_GUARD 1
/* /*
* 140 strings in ao_strs_strtable string table * 142 strings in ao_strs_strtable string table
*/ */
#define ARG_BREAK_STR (ao_strs_strtable+261) #define ARG_BREAK_STR (ao_strs_strtable+261)
#define ARG_BREAK_STR_LEN 5 #define ARG_BREAK_STR_LEN 5
#define ARG_BY_NUM_FMT (ao_strs_strtable+267) #define ARG_BY_NUM_FMT (ao_strs_strtable+267)
#define ARG_BY_NUM_FMT_LEN 9 #define ARG_BY_NUM_FMT_LEN 9
#define BOOL_ATR_FMT (ao_strs_strtable+880) #define BOOL_ATR_FMT (ao_strs_strtable+876)
#define BOOL_ATR_FMT_LEN 31 #define BOOL_ATR_FMT_LEN 31
#define CHK_MAX_COUNT (ao_strs_strtable+1431) #define CHK_MAX_COUNT (ao_strs_strtable+1427)
#define CHK_MAX_COUNT_LEN 190 #define CHK_MAX_COUNT_LEN 190
#define CHK_MIN_COUNT (ao_strs_strtable+1622) #define CHK_MIN_COUNT (ao_strs_strtable+1618)
#define CHK_MIN_COUNT_LEN 91 #define CHK_MIN_COUNT_LEN 91
#define CHK_ONE_REQUIRED (ao_strs_strtable+1714) #define CHK_ONE_REQUIRED (ao_strs_strtable+1710)
#define CHK_ONE_REQUIRED_LEN 80 #define CHK_ONE_REQUIRED_LEN 80
#define ECHO_N_EXIT (ao_strs_strtable+1795) #define ECHO_N_EXIT (ao_strs_strtable+1791)
#define ECHO_N_EXIT_LEN 50 #define ECHO_N_EXIT_LEN 50
#define EMPTY_ARG (ao_strs_strtable+277) #define EMPTY_ARG (ao_strs_strtable+277)
#define EMPTY_ARG_LEN 2 #define EMPTY_ARG_LEN 2
#define END_MARK (ao_strs_strtable+1846) #define END_MARK (ao_strs_strtable+1842)
#define END_MARK_LEN 115 #define END_MARK_LEN 115
#define END_OPT_SEL_STR (ao_strs_strtable+280) #define END_OPT_SEL_STR (ao_strs_strtable+280)
#define END_OPT_SEL_STR_LEN 12 #define END_OPT_SEL_STR_LEN 12
#define END_PRE_FMT (ao_strs_strtable+912) #define END_PRE_FMT (ao_strs_strtable+908)
#define END_PRE_FMT_LEN 36 #define END_PRE_FMT_LEN 36
#define END_SET_TEXT (ao_strs_strtable+293) #define END_SET_TEXT (ao_strs_strtable+293)
#define END_SET_TEXT_LEN 3 #define END_SET_TEXT_LEN 3
@@ -75,15 +75,15 @@
#define EXPORT_ARG_FMT_LEN 17 #define EXPORT_ARG_FMT_LEN 17
#define FALSE_STR (ao_strs_strtable+335) #define FALSE_STR (ao_strs_strtable+335)
#define FALSE_STR_LEN 5 #define FALSE_STR_LEN 5
#define FINISH_LOOP (ao_strs_strtable+1962) #define FINISH_LOOP (ao_strs_strtable+1958)
#define FINISH_LOOP_LEN 378 #define FINISH_LOOP_LEN 378
#define FLAG_OPT_MARK (ao_strs_strtable+341) #define FLAG_OPT_MARK (ao_strs_strtable+341)
#define FLAG_OPT_MARK_LEN 9 #define FLAG_OPT_MARK_LEN 9
#define FLAG_STR (ao_strs_strtable+351) #define FLAG_STR (ao_strs_strtable+351)
#define FLAG_STR_LEN 4 #define FLAG_STR_LEN 4
#define INIT_LOPT_STR (ao_strs_strtable+2341) #define INIT_LOPT_STR (ao_strs_strtable+2337)
#define INIT_LOPT_STR_LEN 250 #define INIT_LOPT_STR_LEN 250
#define INIT_OPT_STR (ao_strs_strtable+2592) #define INIT_OPT_STR (ao_strs_strtable+2588)
#define INIT_OPT_STR_LEN 116 #define INIT_OPT_STR_LEN 116
#define INVALID_FMT (ao_strs_strtable+356) #define INVALID_FMT (ao_strs_strtable+356)
#define INVALID_FMT_LEN 10 #define INVALID_FMT_LEN 10
@@ -97,9 +97,9 @@
#define LONG_OPT_MARK_LEN 10 #define LONG_OPT_MARK_LEN 10
#define LONG_USE_STR (ao_strs_strtable+396) #define LONG_USE_STR (ao_strs_strtable+396)
#define LONG_USE_STR_LEN 9 #define LONG_USE_STR_LEN 9
#define LOOP_STR (ao_strs_strtable+2709) #define LOOP_STR (ao_strs_strtable+2705)
#define LOOP_STR_LEN 206 #define LOOP_STR_LEN 206
#define LOPT_ARG_FMT (ao_strs_strtable+2916) #define LOPT_ARG_FMT (ao_strs_strtable+2912)
#define LOPT_ARG_FMT_LEN 778 #define LOPT_ARG_FMT_LEN 778
#define LVL3_CMD (ao_strs_strtable+406) #define LVL3_CMD (ao_strs_strtable+406)
#define LVL3_CMD_LEN 15 #define LVL3_CMD_LEN 15
@@ -107,9 +107,9 @@
#define MK_STR_OCT_FMT_LEN 5 #define MK_STR_OCT_FMT_LEN 5
#define MORE_STR (ao_strs_strtable+428) #define MORE_STR (ao_strs_strtable+428)
#define MORE_STR_LEN 4 #define MORE_STR_LEN 4
#define MULTI_ARG_FMT (ao_strs_strtable+3695) #define MULTI_ARG_FMT (ao_strs_strtable+3691)
#define MULTI_ARG_FMT_LEN 123 #define MULTI_ARG_FMT_LEN 123
#define MULTI_DEF_FMT (ao_strs_strtable+3819) #define MULTI_DEF_FMT (ao_strs_strtable+3815)
#define MULTI_DEF_FMT_LEN 157 #define MULTI_DEF_FMT_LEN 157
#define NESTED_OPT_FMT (ao_strs_strtable+433) #define NESTED_OPT_FMT (ao_strs_strtable+433)
#define NESTED_OPT_FMT_LEN 17 #define NESTED_OPT_FMT_LEN 17
@@ -119,29 +119,29 @@
#define NLSTR_SPACE_FMT_LEN 5 #define NLSTR_SPACE_FMT_LEN 5
#define NONE_STR (ao_strs_strtable+91) #define NONE_STR (ao_strs_strtable+91)
#define NONE_STR_LEN 4 #define NONE_STR_LEN 4
#define NOT_FOUND_STR (ao_strs_strtable+3977) #define NOT_FOUND_STR (ao_strs_strtable+3973)
#define NOT_FOUND_STR_LEN 56 #define NOT_FOUND_STR_LEN 56
#define NO_ARG_NEEDED (ao_strs_strtable+461) #define NO_ARG_NEEDED (ao_strs_strtable+461)
#define NO_ARG_NEEDED_LEN 17 #define NO_ARG_NEEDED_LEN 17
#define NO_LOAD_WARN (ao_strs_strtable+949) #define NO_LOAD_WARN (ao_strs_strtable+945)
#define NO_LOAD_WARN_LEN 46 #define NO_LOAD_WARN_LEN 46
#define NO_MULTI_ARG_FMT (ao_strs_strtable+4034) #define NO_MULTI_ARG_FMT (ao_strs_strtable+4030)
#define NO_MULTI_ARG_FMT_LEN 140 #define NO_MULTI_ARG_FMT_LEN 140
#define NO_SAVE_OPTS (ao_strs_strtable+996) #define NO_SAVE_OPTS (ao_strs_strtable+992)
#define NO_SAVE_OPTS_LEN 46 #define NO_SAVE_OPTS_LEN 46
#define NO_SGL_ARG_FMT (ao_strs_strtable+4175) #define NO_SGL_ARG_FMT (ao_strs_strtable+4171)
#define NO_SGL_ARG_FMT_LEN 316 #define NO_SGL_ARG_FMT_LEN 316
#define NO_SUPPRESS_LOAD (ao_strs_strtable+1043) #define NO_SUPPRESS_LOAD (ao_strs_strtable+1039)
#define NO_SUPPRESS_LOAD_LEN 65 #define NO_SUPPRESS_LOAD_LEN 65
#define NULL_ATR_FMT (ao_strs_strtable+479) #define NULL_ATR_FMT (ao_strs_strtable+479)
#define NULL_ATR_FMT_LEN 6 #define NULL_ATR_FMT_LEN 6
#define NUMB_ATR_FMT (ao_strs_strtable+1109) #define NUMB_ATR_FMT (ao_strs_strtable+1105)
#define NUMB_ATR_FMT_LEN 34 #define NUMB_ATR_FMT_LEN 34
#define OK_NEED_OPT_ARG (ao_strs_strtable+486) #define OK_NEED_OPT_ARG (ao_strs_strtable+486)
#define OK_NEED_OPT_ARG_LEN 17 #define OK_NEED_OPT_ARG_LEN 17
#define ONE_TAB_STR (ao_strs_strtable+504) #define ONE_TAB_STR (ao_strs_strtable+504)
#define ONE_TAB_STR_LEN 1 #define ONE_TAB_STR_LEN 1
#define ONLY_OPTS_LOOP (ao_strs_strtable+4492) #define ONLY_OPTS_LOOP (ao_strs_strtable+4488)
#define ONLY_OPTS_LOOP_LEN 102 #define ONLY_OPTS_LOOP_LEN 102
#define OPEN_CLOSE_FMT (ao_strs_strtable+479) #define OPEN_CLOSE_FMT (ao_strs_strtable+479)
#define OPEN_CLOSE_FMT_LEN 6 #define OPEN_CLOSE_FMT_LEN 6
@@ -149,7 +149,7 @@
#define OPEN_XML_FMT_LEN 4 #define OPEN_XML_FMT_LEN 4
#define OPTION_STR (ao_strs_strtable+511) #define OPTION_STR (ao_strs_strtable+511)
#define OPTION_STR_LEN 6 #define OPTION_STR_LEN 6
#define OPT_ARG_FMT (ao_strs_strtable+4595) #define OPT_ARG_FMT (ao_strs_strtable+4591)
#define OPT_ARG_FMT_LEN 1153 #define OPT_ARG_FMT_LEN 1153
#define OPT_END_FMT (ao_strs_strtable+518) #define OPT_END_FMT (ao_strs_strtable+518)
#define OPT_END_FMT_LEN 14 #define OPT_END_FMT_LEN 14
@@ -159,15 +159,13 @@
#define OR_STR_LEN 3 #define OR_STR_LEN 3
#define PAGER_NAME (ao_strs_strtable+544) #define PAGER_NAME (ao_strs_strtable+544)
#define PAGER_NAME_LEN 5 #define PAGER_NAME_LEN 5
#define PAGE_USAGE_FMT (ao_strs_strtable+837) #define PAGE_USAGE_FMT (ao_strs_strtable+853)
#define PAGE_USAGE_FMT (ao_strs_strtable+837) #define PAGE_USAGE_FMT_LEN 22
#define PAGE_USAGE_FMT_LEN 42 #define PAGE_USAGE_TEXT (ao_strs_strtable+5745)
#define PAGE_USAGE_FMT_LEN 42
#define PAGE_USAGE_TEXT (ao_strs_strtable+5749)
#define PAGE_USAGE_TEXT_LEN 73 #define PAGE_USAGE_TEXT_LEN 73
#define PLUS_STR (ao_strs_strtable+550) #define PLUS_STR (ao_strs_strtable+550)
#define PLUS_STR_LEN 3 #define PLUS_STR_LEN 3
#define PREAMBLE_FMT (ao_strs_strtable+5823) #define PREAMBLE_FMT (ao_strs_strtable+5819)
#define PREAMBLE_FMT_LEN 105 #define PREAMBLE_FMT_LEN 105
#define PUTS_FMT (ao_strs_strtable+554) #define PUTS_FMT (ao_strs_strtable+554)
#define PUTS_FMT_LEN 15 #define PUTS_FMT_LEN 15
@@ -175,19 +173,19 @@
#define QUOT_APOS_LEN 2 #define QUOT_APOS_LEN 2
#define QUOT_ARG_FMT (ao_strs_strtable+573) #define QUOT_ARG_FMT (ao_strs_strtable+573)
#define QUOT_ARG_FMT_LEN 4 #define QUOT_ARG_FMT_LEN 4
#define SET_MULTI_ARG (ao_strs_strtable+5929) #define SET_MULTI_ARG (ao_strs_strtable+5925)
#define SET_MULTI_ARG_LEN 89 #define SET_MULTI_ARG_LEN 89
#define SET_NO_TEXT_FMT (ao_strs_strtable+1144) #define SET_NO_TEXT_FMT (ao_strs_strtable+1140)
#define SET_NO_TEXT_FMT_LEN 30 #define SET_NO_TEXT_FMT_LEN 30
#define SET_OFF_FMT (ao_strs_strtable+578) #define SET_OFF_FMT (ao_strs_strtable+578)
#define SET_OFF_FMT_LEN 6 #define SET_OFF_FMT_LEN 6
#define SET_TEXT_FMT (ao_strs_strtable+585) #define SET_TEXT_FMT (ao_strs_strtable+585)
#define SET_TEXT_FMT_LEN 12 #define SET_TEXT_FMT_LEN 12
#define SGL_ARG_FMT (ao_strs_strtable+6019) #define SGL_ARG_FMT (ao_strs_strtable+6015)
#define SGL_ARG_FMT_LEN 258 #define SGL_ARG_FMT_LEN 258
#define SGL_DEF_FMT (ao_strs_strtable+6278) #define SGL_DEF_FMT (ao_strs_strtable+6274)
#define SGL_DEF_FMT_LEN 68 #define SGL_DEF_FMT_LEN 68
#define SGL_NO_DEF_FMT (ao_strs_strtable+6347) #define SGL_NO_DEF_FMT (ao_strs_strtable+6343)
#define SGL_NO_DEF_FMT_LEN 61 #define SGL_NO_DEF_FMT_LEN 61
#define SHELL_MAGIC (ao_strs_strtable+598) #define SHELL_MAGIC (ao_strs_strtable+598)
#define SHELL_MAGIC_LEN 6 #define SHELL_MAGIC_LEN 6
@@ -195,49 +193,55 @@
#define SHOW_PROG_ENV_LEN 19 #define SHOW_PROG_ENV_LEN 19
#define SHOW_VAL_FMT (ao_strs_strtable+625) #define SHOW_VAL_FMT (ao_strs_strtable+625)
#define SHOW_VAL_FMT_LEN 17 #define SHOW_VAL_FMT_LEN 17
#define START_MARK (ao_strs_strtable+6409) #define START_MARK (ao_strs_strtable+6405)
#define START_MARK_LEN 82 #define START_MARK_LEN 82
#define STDOUT (ao_strs_strtable+643) #define STDOUT (ao_strs_strtable+643)
#define STDOUT_LEN 6 #define STDOUT_LEN 6
#define TIME_FMT (ao_strs_strtable+650) #define TIME_FMT (ao_strs_strtable+650)
#define TIME_FMT_LEN 21 #define TIME_FMT_LEN 21
#define TMPDIR (ao_strs_strtable+841)
#define TMPDIR_LEN 6
#define TMP_FILE_FMT (ao_strs_strtable+672)
#define TMP_FILE_FMT_LEN 16
#define TMP_USAGE_FMT (ao_strs_strtable+672) #define TMP_USAGE_FMT (ao_strs_strtable+672)
#define TMP_USAGE_FMT_LEN 12 #define TMP_USAGE_FMT_LEN 16
#define TRUE_STR (ao_strs_strtable+685) #define TRUE_STR (ao_strs_strtable+689)
#define TRUE_STR_LEN 4 #define TRUE_STR_LEN 4
#define TWO_SPACES_STR (ao_strs_strtable+254) #define TWO_SPACES_STR (ao_strs_strtable+254)
#define TWO_SPACES_STR_LEN 2 #define TWO_SPACES_STR_LEN 2
#define TYPE_ATR_FMT (ao_strs_strtable+690) #define TYPE_ATR_FMT (ao_strs_strtable+694)
#define TYPE_ATR_FMT_LEN 12 #define TYPE_ATR_FMT_LEN 12
#define UNK_OPT_FMT (ao_strs_strtable+6492) #define UNK_OPT_FMT (ao_strs_strtable+6488)
#define UNK_OPT_FMT_LEN 144 #define UNK_OPT_FMT_LEN 144
#define VER_STR (ao_strs_strtable+703) #define VER_STR (ao_strs_strtable+707)
#define VER_STR_LEN 7 #define VER_STR_LEN 7
#define XML_HEX_BYTE_FMT (ao_strs_strtable+711) #define XML_HEX_BYTE_FMT (ao_strs_strtable+715)
#define XML_HEX_BYTE_FMT_LEN 7 #define XML_HEX_BYTE_FMT_LEN 7
#define YES_NEED_OPT_ARG (ao_strs_strtable+719) #define YES_NEED_OPT_ARG (ao_strs_strtable+723)
#define YES_NEED_OPT_ARG_LEN 18 #define YES_NEED_OPT_ARG_LEN 18
#define apostrophe (ao_strs_strtable+738) #define apostrophe (ao_strs_strtable+742)
#define apostrophe_LEN 4 #define apostrophe_LEN 4
#define arg_fmt (ao_strs_strtable+743) #define arg_fmt (ao_strs_strtable+747)
#define arg_fmt_LEN 5 #define arg_fmt_LEN 5
#define init_optct (ao_strs_strtable+749) #define init_optct (ao_strs_strtable+753)
#define init_optct_LEN 13 #define init_optct_LEN 13
#define set_dash (ao_strs_strtable+763) #define set_dash (ao_strs_strtable+767)
#define set_dash_LEN 6 #define set_dash_LEN 6
#define tmp_dir (ao_strs_strtable+848)
#define tmp_dir_LEN 4
#define zAll (ao_strs_strtable+257) #define zAll (ao_strs_strtable+257)
#define zAll_LEN 3 #define zAll_LEN 3
#define zCfgAO_Flags (ao_strs_strtable+12) #define zCfgAO_Flags (ao_strs_strtable+12)
#define zCfgAO_Flags_LEN 12 #define zCfgAO_Flags_LEN 12
#define zCfgProg (ao_strs_strtable+25) #define zCfgProg (ao_strs_strtable+25)
#define zCfgProg_LEN 7 #define zCfgProg_LEN 7
#define zEquivMode (ao_strs_strtable+1175) #define zEquivMode (ao_strs_strtable+1171)
#define zEquivMode_LEN 44 #define zEquivMode_LEN 44
#define zFiveSpaces (ao_strs_strtable+244) #define zFiveSpaces (ao_strs_strtable+244)
#define zFiveSpaces_LEN 5 #define zFiveSpaces_LEN 5
#define zFmtFmt (ao_strs_strtable+33) #define zFmtFmt (ao_strs_strtable+33)
#define zFmtFmt_LEN 11 #define zFmtFmt_LEN 11
#define zFullOptFmt (ao_strs_strtable+1220) #define zFullOptFmt (ao_strs_strtable+1216)
#define zFullOptFmt_LEN 34 #define zFullOptFmt_LEN 34
#define zGnuBreak (ao_strs_strtable+45) #define zGnuBreak (ao_strs_strtable+45)
#define zGnuBreak_LEN 5 #define zGnuBreak_LEN 5
@@ -255,23 +259,23 @@
#define zGnuTimeArg_LEN 4 #define zGnuTimeArg_LEN 4
#define zNone (ao_strs_strtable+91) #define zNone (ao_strs_strtable+91)
#define zNone_LEN 4 #define zNone_LEN 4
#define zOptCookieCt (ao_strs_strtable+1255) #define zOptCookieCt (ao_strs_strtable+1251)
#define zOptCookieCt_LEN 38 #define zOptCookieCt_LEN 38
#define zOptCtFmt (ao_strs_strtable+1294) #define zOptCtFmt (ao_strs_strtable+1290)
#define zOptCtFmt_LEN 30 #define zOptCtFmt_LEN 30
#define zOptDisabl (ao_strs_strtable+1325) #define zOptDisabl (ao_strs_strtable+1321)
#define zOptDisabl_LEN 32 #define zOptDisabl_LEN 32
#define zOptNumFmt (ao_strs_strtable+1358) #define zOptNumFmt (ao_strs_strtable+1354)
#define zOptNumFmt_LEN 41 #define zOptNumFmt_LEN 41
#define zOptionCase (ao_strs_strtable+1400) #define zOptionCase (ao_strs_strtable+1396)
#define zOptionCase_LEN 30 #define zOptionCase_LEN 30
#define zOptionEndSelect (ao_strs_strtable+770) #define zOptionEndSelect (ao_strs_strtable+774)
#define zOptionEndSelect_LEN 16 #define zOptionEndSelect_LEN 16
#define zOptionFlag (ao_strs_strtable+787) #define zOptionFlag (ao_strs_strtable+791)
#define zOptionFlag_LEN 15 #define zOptionFlag_LEN 15
#define zOptionFullName (ao_strs_strtable+803) #define zOptionFullName (ao_strs_strtable+807)
#define zOptionFullName_LEN 15 #define zOptionFullName_LEN 15
#define zOptionPartName (ao_strs_strtable+819) #define zOptionPartName (ao_strs_strtable+823)
#define zOptionPartName_LEN 17 #define zOptionPartName_LEN 17
#define zPresetFile (ao_strs_strtable+96) #define zPresetFile (ao_strs_strtable+96)
#define zPresetFile_LEN 37 #define zPresetFile_LEN 37
@@ -321,6 +325,6 @@
#define zTwoSpaces_LEN 2 #define zTwoSpaces_LEN 2
#define zambig_file (ao_strs_strtable+4) #define zambig_file (ao_strs_strtable+4)
#define zambig_file_LEN 7 #define zambig_file_LEN 7
extern char const ao_strs_strtable[6637]; extern char const ao_strs_strtable[6633];
#endif /* STRINGS_AO_STRS_H_GUARD */ #endif /* STRINGS_AO_STRS_H_GUARD */
+40 -55
View File
@@ -32,65 +32,11 @@
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/ */
#ifndef PKGDATADIR
# define PKGDATADIR ""
#endif
static char const zNil[] = "";
static arg_types_t argTypes = { NULL };
static char line_fmt_buf[32];
static bool displayEnum = false;
static char const pkgdatadir_default[] = PKGDATADIR;
static char const * program_pkgdatadir = pkgdatadir_default;
static tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED;
static tePagerState pagerState = PAGER_STATE_INITIAL;
FILE * option_usage_fp = NULL;
/** /**
* The number of tab characters to skip when printing continuation lines. * The number of tab characters to skip when printing continuation lines.
*/ */
static unsigned int tab_skip_ct = 0; static unsigned int tab_skip_ct = 0;
LOCAL void *
ao_malloc(size_t sz)
{
void * res = malloc(sz);
if (res == NULL) {
fprintf(stderr, zalloc_fail, (int)sz);
exit(EXIT_FAILURE);
}
return res;
}
#undef malloc
#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, zrealloc_fail, (int)sz, p);
exit(EXIT_FAILURE);
}
return res;
}
#undef realloc
#define realloc(_p,_s) ao_realloc(_p,_s)
LOCAL char *
ao_strdup(char const *str)
{
char * res = strdup(str);
if (res == NULL) {
fprintf(stderr, zalloc_fail, (int)strlen(str));
exit(EXIT_FAILURE);
}
return res;
}
#undef strdup
#define strdup(_p) ao_strdup(_p)
#ifndef HAVE_PATHFIND #ifndef HAVE_PATHFIND
# define pathfind(_p, _n, _m) option_pathfind(_p, _n, _m) # define pathfind(_p, _n, _m) option_pathfind(_p, _n, _m)
# include "compat/pathfind.c" # include "compat/pathfind.c"
@@ -113,6 +59,45 @@ ao_strdup(char const *str)
# include "compat/strchr.c" # include "compat/strchr.c"
#endif #endif
LOCAL void *
ao_malloc(size_t sz)
{
void * res = malloc(sz);
if (res == NULL) {
fprintf(stderr, zalloc_fail, (int)sz);
option_exits(EXIT_FAILURE);
}
return res;
}
#undef malloc
#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, zrealloc_fail, (int)sz, p);
option_exits(EXIT_FAILURE);
}
return res;
}
#undef realloc
#define realloc(_p,_s) ao_realloc(_p,_s)
LOCAL char *
ao_strdup(char const *str)
{
char * res = strdup(str);
if (res == NULL) {
fprintf(stderr, zalloc_fail, (int)strlen(str));
option_exits(EXIT_FAILURE);
}
return res;
}
#undef strdup
#define strdup(_p) ao_strdup(_p)
/** /**
* handle an option. * handle an option.
* *
@@ -386,7 +371,7 @@ optionProcess(tOptions * opts, int a_ct, char ** a_v)
if (SELECTED_OPT(od)) { if (SELECTED_OPT(od)) {
optionSaveFile(opts); optionSaveFile(opts);
exit(EXIT_SUCCESS); option_exits(EXIT_SUCCESS);
} }
} }
} }
+70
View File
@@ -129,8 +129,19 @@
#define SKIP_OPT(p) (((p)->fOptState & OPTST_IMMUTABLE_MASK) != 0) #define SKIP_OPT(p) (((p)->fOptState & OPTST_IMMUTABLE_MASK) != 0)
typedef int tDirection; typedef int tDirection;
/**
* handling option presets. Start with command line and work through
* config settings in reverse order.
*/
#define DIRECTION_PRESET -1 #define DIRECTION_PRESET -1
/**
* handling normal options. Start with first config file, then environment
* variables and finally the command line.
*/
#define DIRECTION_PROCESS 1 #define DIRECTION_PROCESS 1
/**
* An initialzation phase or an option being loaded from program sources.
*/
#define DIRECTION_CALLED 0 #define DIRECTION_CALLED 0
#define PROCESSING(d) ((d)>0) #define PROCESSING(d) ((d)>0)
@@ -392,6 +403,65 @@ static char const * program_pkgdatadir;
*/ */
extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt; extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
#ifdef AUTOOPTS_INTERNAL
#ifndef PKGDATADIR
# define PKGDATADIR ""
#endif
#define APOSTROPHE '\''
#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_
static char const zNil[] = "";
static arg_types_t argTypes = { NULL };
static char line_fmt_buf[32];
static bool displayEnum = false;
static char const pkgdatadir_default[] = PKGDATADIR;
static char const * program_pkgdatadir = pkgdatadir_default;
static tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED;
static tePagerState pagerState = PAGER_STATE_INITIAL;
FILE * option_usage_fp = NULL;
static char const * pz_enum_err_fmt;
tOptions * optionParseShellOptions = NULL;
static char const * shell_prog = NULL;
static char * script_leader = NULL;
static char * script_trailer = NULL;
static char * script_text = NULL;
static bool print_exit = false;
#endif /* AUTOOPTS_INTERNAL */
#endif /* AUTOGEN_AUTOOPTS_H */ #endif /* AUTOGEN_AUTOOPTS_H */
/** /**
* @} * @}
+22 -6
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (options.h) * DO NOT EDIT THIS FILE (options.h)
* *
* It has been AutoGen-ed March 31, 2013 at 10:41:30 AM by AutoGen 5.17.3 * It has been AutoGen-ed July 14, 2013 at 05:37:12 PM by AutoGen 5.18
* From the definitions funcs.def * From the definitions funcs.def
* and the template file options_h * and the template file options_h
* *
@@ -101,15 +101,15 @@
* @{ * @{
*/ */
/// autoopts structure version /// autoopts structure version
#define OPTIONS_STRUCT_VERSION 155648 #define OPTIONS_STRUCT_VERSION 163840
/// autoopts structure version string /// autoopts structure version string
#define OPTIONS_VERSION_STRING "38:0:13" #define OPTIONS_VERSION_STRING "40:0:15"
/// minimum version the autoopts library supports /// minimum version the autoopts library supports
#define OPTIONS_MINIMUM_VERSION 102400 #define OPTIONS_MINIMUM_VERSION 102400
/// minimum version the autoopts library supports as a string /// minimum version the autoopts library supports as a string
#define OPTIONS_MIN_VER_STRING "25:0:0" #define OPTIONS_MIN_VER_STRING "25:0:0"
/// the display version of the autoopts library, as a string /// the display version of the autoopts library, as a string
#define OPTIONS_DOTTED_VERSION "38.0" #define OPTIONS_DOTTED_VERSION "40.0"
/// convert a version/release number pair to an integer value /// convert a version/release number pair to an integer value
#define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r)) #define OPTIONS_VER_TO_NUM(_v, _r) (((_v) * 4096) + (_r))
/// @} /// @}
@@ -375,13 +375,16 @@ typedef uint32_t proc_state_mask_t;
#define OPTPROC_PRESETTING 0x080000U #define OPTPROC_PRESETTING 0x080000U
/** proc_state_mask_t - Ignore pzFullUsage, compute usage text */ /** proc_state_mask_t - Ignore pzFullUsage, compute usage text */
#define OPTPROC_COMPUTE 0x100000U #define OPTPROC_COMPUTE 0x100000U
/** proc_state_mask_t - Program outputs digested option state for shell scripts.
Usage text always written to stderr */
#define OPTPROC_SHELL_OUTPUT 0x200000U
/** bits in NO_XLAT mask: /** bits in NO_XLAT mask:
* nxlat_opt_cfg nxlat_opt */ * nxlat_opt_cfg nxlat_opt */
#define OPTPROC_NO_XLAT_MASK 0x030000U #define OPTPROC_NO_XLAT_MASK 0x030000U
/** all bits in proc_state_mask_t masks */ /** all bits in proc_state_mask_t masks */
#define OPTPROC_MASK_ALL 0x1FFFFFU #define OPTPROC_MASK_ALL 0x3FFFFFU
/** no bits in proc_state_mask_t */ /** no bits in proc_state_mask_t */
#define OPTPROC_NONE 0x000000U #define OPTPROC_NONE 0x000000U
@@ -911,6 +914,19 @@ extern const tOptionValue* optionGetValue(const tOptionValue*, char const*);
extern void optionLoadLine(tOptions*, char const*); extern void optionLoadLine(tOptions*, char const*);
/**
* optionMemberList - Get the list of members of a bit mask set
*
* This converts the OPT_VALUE_name mask value to a allocated string.
* It is the caller's responsibility to free the string.
*
* @param od the set membership option description
*
* @return char* - the names of the set bits
*/
extern char* optionMemberList(tOptDesc *);
/** /**
* optionNextValue - get the next value from a hierarchical list * optionNextValue - get the next value from a hierarchical list
* *
@@ -1167,7 +1183,7 @@ extern void optionNestedVal(tOptions*, tOptDesc*);
extern void optionNumericVal(tOptions*, tOptDesc*); extern void optionNumericVal(tOptions*, tOptDesc*);
extern void optionPagedUsage(tOptions*, tOptDesc*); extern void optionPagedUsage(tOptions *, tOptDesc *);
extern void optionParseShell(tOptions*); extern void optionParseShell(tOptions*);
+2
View File
@@ -71,5 +71,7 @@ typedef int tSuccess;
# define MODE extern # define MODE extern
#endif #endif
#define parse_duration option_parse_duration
#endif /* AUTOGEN_PROJECT_H */ #endif /* AUTOGEN_PROJECT_H */
/* end of project.h */ /* end of project.h */
+91 -91
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (usage-txt.h) * 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 * It has been AutoGen-ed July 14, 2013 at 05:37:10 PM by AutoGen 5.18
* From the definitions usage-txt.def * From the definitions usage-txt.def
* and the template file usage-txt.tpl * and the template file usage-txt.tpl
* *
@@ -362,51 +362,51 @@ do not compile this section.
*/ */
static void dummy_func(void) { static void dummy_func(void) {
/* LIBOPTS-MESSAGES: */ /* LIBOPTS-MESSAGES: */
#line 60 "../autoopts.c" #line 67 "../autoopts.c"
puts(_("allocation of %d bytes failed\n")); puts(_("allocation of %d bytes failed\n"));
#line 86 "../autoopts.c" #line 93 "../autoopts.c"
puts(_("allocation of %d bytes failed\n")); puts(_("allocation of %d bytes failed\n"));
#line 53 "../init.c" #line 53 "../init.c"
puts(_("AutoOpts function called without option descriptor\n")); puts(_("AutoOpts function called without option descriptor\n"));
#line 89 "../init.c" #line 90 "../init.c"
puts(_("\tThis exceeds the compiled library version: ")); puts(_("\tThis exceeds the compiled library version: "));
#line 87 "../init.c" #line 88 "../init.c"
puts(_("Automated Options Processing Error!\n" puts(_("Automated Options Processing Error!\n"
"\t%s called AutoOpts function with structure version %d:%d:%d.\n")); "\t%s called AutoOpts function with structure version %d:%d:%d.\n"));
#line 73 "../autoopts.c" #line 80 "../autoopts.c"
puts(_("realloc of %d bytes at 0x%p failed\n")); puts(_("realloc of %d bytes at 0x%p failed\n"));
#line 91 "../init.c" #line 92 "../init.c"
puts(_("\tThis is less than the minimum library version: ")); puts(_("\tThis is less than the minimum library version: "));
#line 121 "../version.c" #line 121 "../version.c"
puts(_("Automated Options version %s\n" puts(_("Automated Options version %s\n"
"\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n")); "\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n"));
#line 310 "../usage.c" #line 82 "../makeshell.c"
puts(_("(AutoOpts bug): %s.\n")); puts(_("(AutoOpts bug): %s.\n"));
#line 90 "../reset.c" #line 90 "../reset.c"
puts(_("optionResetOpt() called, but reset-option not configured")); puts(_("optionResetOpt() called, but reset-option not configured"));
#line 329 "../usage.c" #line 292 "../usage.c"
puts(_("could not locate the 'help' option")); puts(_("could not locate the 'help' option"));
#line 351 "../autoopts.c" #line 336 "../autoopts.c"
puts(_("optionProcess() was called with invalid data")); puts(_("optionProcess() was called with invalid data"));
#line 783 "../usage.c" #line 747 "../usage.c"
puts(_("invalid argument type specified")); puts(_("invalid argument type specified"));
#line 589 "../find.c" #line 598 "../find.c"
puts(_("defaulted to option with optional arg")); puts(_("defaulted to option with optional arg"));
#line 76 "../alias.c" #line 76 "../alias.c"
puts(_("aliasing option is out of range.")); puts(_("aliasing option is out of range."));
#line 229 "../enum.c" #line 234 "../enum.c"
puts(_("%s error: the keyword '%s' is ambiguous for %s\n")); puts(_("%s error: the keyword '%s' is ambiguous for %s\n"));
#line 108 "../find.c" #line 108 "../find.c"
puts(_(" The following options match:\n")); puts(_(" The following options match:\n"));
#line 290 "../find.c" #line 293 "../find.c"
puts(_("%s: ambiguous option name: %s (matches %d options)\n")); puts(_("%s: ambiguous option name: %s (matches %d options)\n"));
#line 161 "../check.c" #line 161 "../check.c"
puts(_("%s: Command line arguments required\n")); puts(_("%s: Command line arguments required\n"));
#line 43 "../alias.c" #line 43 "../alias.c"
puts(_("%d %s%s options allowed\n")); puts(_("%d %s%s options allowed\n"));
#line 81 "../makeshell.c" #line 89 "../makeshell.c"
puts(_("%s error %d (%s) calling %s for '%s'\n")); puts(_("%s error %d (%s) calling %s for '%s'\n"));
#line 293 "../makeshell.c" #line 301 "../makeshell.c"
puts(_("interprocess pipe")); puts(_("interprocess pipe"));
#line 168 "../version.c" #line 168 "../version.c"
puts(_("error: version option argument '%c' invalid. Use:\n" puts(_("error: version option argument '%c' invalid. Use:\n"
@@ -415,48 +415,48 @@ static void dummy_func(void) {
"\t'n' - version and full copyright notice\n")); "\t'n' - version and full copyright notice\n"));
#line 58 "../check.c" #line 58 "../check.c"
puts(_("%s error: the '%s' and '%s' options conflict\n")); puts(_("%s error: the '%s' and '%s' options conflict\n"));
#line 214 "../find.c" #line 217 "../find.c"
puts(_("%s: The '%s' option has been disabled.")); puts(_("%s: The '%s' option has been disabled."));
#line 421 "../find.c" #line 430 "../find.c"
puts(_("%s: The '%s' option has been disabled.")); puts(_("%s: The '%s' option has been disabled."));
#line 38 "../alias.c" #line 38 "../alias.c"
puts(_("-equivalence")); puts(_("-equivalence"));
#line 460 "../find.c" #line 469 "../find.c"
puts(_("%s: illegal option -- %c\n")); puts(_("%s: illegal option -- %c\n"));
#line 110 "../reset.c" #line 110 "../reset.c"
puts(_("%s: illegal option -- %c\n")); puts(_("%s: illegal option -- %c\n"));
#line 268 "../find.c" #line 271 "../find.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 746 "../find.c" #line 755 "../find.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 118 "../reset.c" #line 118 "../reset.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 332 "../find.c" #line 335 "../find.c"
puts(_("%s: unknown vendor extension option -- %s\n")); puts(_("%s: unknown vendor extension option -- %s\n"));
#line 154 "../enum.c" #line 159 "../enum.c"
puts(_(" or an integer from %d through %d\n")); puts(_(" or an integer from %d through %d\n"));
#line 164 "../enum.c" #line 169 "../enum.c"
puts(_(" or an integer from %d through %d\n")); puts(_(" or an integer from %d through %d\n"));
#line 782 "../usage.c" #line 746 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n")); puts(_("%s error: invalid option descriptor for %s\n"));
#line 1110 "../usage.c" #line 1080 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n")); puts(_("%s error: invalid option descriptor for %s\n"));
#line 379 "../find.c" #line 385 "../find.c"
puts(_("%s: invalid option name: %s\n")); puts(_("%s: invalid option name: %s\n"));
#line 518 "../find.c" #line 527 "../find.c"
puts(_("%s: The '%s' option requires an argument.\n")); puts(_("%s: The '%s' option requires an argument.\n"));
#line 171 "../autoopts.c" #line 156 "../autoopts.c"
puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n" puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n"
"\t'%s' and '%s'.")); "\t'%s' and '%s'."));
#line 94 "../check.c" #line 94 "../check.c"
puts(_("%s error: The %s option is required\n")); puts(_("%s error: The %s option is required\n"));
#line 623 "../find.c" #line 632 "../find.c"
puts(_("%s: The '%s' option cannot have an argument.\n")); puts(_("%s: The '%s' option cannot have an argument.\n"));
#line 151 "../check.c" #line 151 "../check.c"
puts(_("%s: Command line arguments are not allowed.\n")); puts(_("%s: Command line arguments are not allowed.\n"));
#line 531 "../save.c" #line 535 "../save.c"
puts(_("error %d (%s) creating %s\n")); puts(_("error %d (%s) creating %s\n"));
#line 229 "../enum.c" #line 234 "../enum.c"
puts(_("%s error: '%s' does not match any %s keywords.\n")); puts(_("%s error: '%s' does not match any %s keywords.\n"));
#line 93 "../reset.c" #line 93 "../reset.c"
puts(_("%s error: The '%s' option requires an argument.\n")); puts(_("%s error: The '%s' option requires an argument.\n"));
@@ -466,7 +466,7 @@ static void dummy_func(void) {
puts(_("error %d (%s) stat-ing %s\n")); puts(_("error %d (%s) stat-ing %s\n"));
#line 143 "../restore.c" #line 143 "../restore.c"
puts(_("%s error: no saved option state\n")); puts(_("%s error: no saved option state\n"));
#line 246 "../autoopts.c" #line 231 "../autoopts.c"
puts(_("'%s' is not a command line option.\n")); puts(_("'%s' is not a command line option.\n"));
#line 114 "../time.c" #line 114 "../time.c"
puts(_("%s error: '%s' is not a recognizable date/time.\n")); puts(_("%s error: '%s' is not a recognizable date/time.\n"));
@@ -478,41 +478,41 @@ static void dummy_func(void) {
puts(_("%s error: The %s option must appear %d times.\n")); puts(_("%s error: The %s option must appear %d times.\n"));
#line 157 "../numeric.c" #line 157 "../numeric.c"
puts(_("%s error: '%s' is not a recognizable number.\n")); puts(_("%s error: '%s' is not a recognizable number.\n"));
#line 195 "../enum.c" #line 200 "../enum.c"
puts(_("%s error: %s exceeds %s keyword count\n")); puts(_("%s error: %s exceeds %s keyword count\n"));
#line 366 "../usage.c" #line 329 "../usage.c"
puts(_("Try '%s %s' for more information.\n")); puts(_("Try '%s %s' for more information.\n"));
#line 45 "../alias.c" #line 45 "../alias.c"
puts(_("one %s%s option allowed\n")); puts(_("one %s%s option allowed\n"));
#line 195 "../makeshell.c" #line 203 "../makeshell.c"
puts(_("standard output")); puts(_("standard output"));
#line 930 "../makeshell.c" #line 938 "../makeshell.c"
puts(_("standard output")); puts(_("standard output"));
#line 304 "../usage.c" #line 274 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 451 "../usage.c" #line 414 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 660 "../usage.c" #line 624 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 175 "../version.c" #line 175 "../version.c"
puts(_("standard output")); puts(_("standard output"));
#line 304 "../usage.c" #line 274 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 451 "../usage.c" #line 414 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 660 "../usage.c" #line 624 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 175 "../version.c" #line 175 "../version.c"
puts(_("standard error")); puts(_("standard error"));
#line 195 "../makeshell.c" #line 203 "../makeshell.c"
puts(_("write")); puts(_("write"));
#line 930 "../makeshell.c" #line 938 "../makeshell.c"
puts(_("write")); puts(_("write"));
#line 303 "../usage.c" #line 273 "../usage.c"
puts(_("write")); puts(_("write"));
#line 450 "../usage.c" #line 413 "../usage.c"
puts(_("write")); puts(_("write"));
#line 659 "../usage.c" #line 623 "../usage.c"
puts(_("write")); puts(_("write"));
#line 174 "../version.c" #line 174 "../version.c"
puts(_("write")); puts(_("write"));
@@ -528,70 +528,70 @@ static void dummy_func(void) {
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 256 "../save.c" #line 256 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 530 "../save.c" #line 534 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
/* END-LIBOPTS-MESSAGES */ /* END-LIBOPTS-MESSAGES */
/* USAGE-TEXT: */ /* 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" #line 872 "../usage.c"
puts(_("\t\t\t\t- an alternate for '%s'\n"));
#line 1147 "../usage.c"
puts(_("Version, usage and configuration options:"));
#line 923 "../usage.c"
puts(_("\t\t\t\t- default option for unnamed options\n"));
#line 836 "../usage.c"
puts(_("\t\t\t\t- disabled as '--%s'\n")); puts(_("\t\t\t\t- disabled as '--%s'\n"));
#line 1146 "../usage.c" #line 1116 "../usage.c"
puts(_(" --- %-14s %s\n")); puts(_(" --- %-14s %s\n"));
#line 1144 "../usage.c" #line 1114 "../usage.c"
puts(_("This option has been disabled")); puts(_("This option has been disabled"));
#line 899 "../usage.c" #line 863 "../usage.c"
puts(_("\t\t\t\t- enabled by default\n")); puts(_("\t\t\t\t- enabled by default\n"));
#line 40 "../alias.c" #line 40 "../alias.c"
puts(_("%s error: only ")); puts(_("%s error: only "));
#line 1221 "../usage.c" #line 1193 "../usage.c"
puts(_(" - examining environment variables named %s_*\n")); puts(_(" - examining environment variables named %s_*\n"));
#line 168 "../file.c" #line 168 "../file.c"
puts(_("\t\t\t\t- file must not pre-exist\n")); puts(_("\t\t\t\t- file must not pre-exist\n"));
#line 172 "../file.c" #line 172 "../file.c"
puts(_("\t\t\t\t- file must pre-exist\n")); puts(_("\t\t\t\t- file must pre-exist\n"));
#line 416 "../usage.c" #line 379 "../usage.c"
puts(_("Options are specified by doubled hyphens and their name or by a single\n" puts(_("Options are specified by doubled hyphens and their name or by a single\n"
"hyphen and the flag character.\n")); "hyphen and the flag character.\n"));
#line 908 "../makeshell.c" #line 916 "../makeshell.c"
puts(_("\n" puts(_("\n"
"= = = = = = = =\n\n" "= = = = = = = =\n\n"
"This incarnation of genshell will produce\n" "This incarnation of genshell will produce\n"
"a shell script to parse the options for %s:\n\n")); "a shell script to parse the options for %s:\n\n"));
#line 161 "../enum.c" #line 166 "../enum.c"
puts(_(" or an integer mask with any of the lower %d bits set\n")); puts(_(" or an integer mask with any of the lower %d bits set\n"));
#line 932 "../usage.c" #line 896 "../usage.c"
puts(_("\t\t\t\t- is a set membership option\n")); puts(_("\t\t\t\t- is a set membership option\n"));
#line 953 "../usage.c" #line 917 "../usage.c"
puts(_("\t\t\t\t- must appear between %d and %d times\n")); puts(_("\t\t\t\t- must appear between %d and %d times\n"));
#line 418 "../usage.c" #line 381 "../usage.c"
puts(_("Options are specified by single or double hyphens and their name.\n")); puts(_("Options are specified by single or double hyphens and their name.\n"));
#line 939 "../usage.c" #line 903 "../usage.c"
puts(_("\t\t\t\t- may appear multiple times\n")); puts(_("\t\t\t\t- may appear multiple times\n"));
#line 926 "../usage.c" #line 890 "../usage.c"
puts(_("\t\t\t\t- may not be preset\n")); puts(_("\t\t\t\t- may not be preset\n"));
#line 1336 "../usage.c" #line 1308 "../usage.c"
puts(_(" Arg Option-Name Description\n")); puts(_(" Arg Option-Name Description\n"));
#line 1272 "../usage.c" #line 1244 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n")); puts(_(" Flg Arg Option-Name Description\n"));
#line 1330 "../usage.c" #line 1302 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n")); puts(_(" Flg Arg Option-Name Description\n"));
#line 1331 "../usage.c" #line 1303 "../usage.c"
puts(_(" %3s %s")); puts(_(" %3s %s"));
#line 1337 "../usage.c" #line 1309 "../usage.c"
puts(_(" %3s %s")); puts(_(" %3s %s"));
#line 423 "../usage.c" #line 386 "../usage.c"
puts(_("The '-#<number>' option may omit the hash char\n")); puts(_("The '-#<number>' option may omit the hash char\n"));
#line 419 "../usage.c" #line 382 "../usage.c"
puts(_("All arguments are named options.\n")); puts(_("All arguments are named options.\n"));
#line 1006 "../usage.c" #line 970 "../usage.c"
puts(_(" - reading file %s")); puts(_(" - reading file %s"));
#line 445 "../usage.c" #line 408 "../usage.c"
puts(_("\n" puts(_("\n"
"Please send bug reports to: <%s>\n")); "Please send bug reports to: <%s>\n"));
#line 100 "../version.c" #line 100 "../version.c"
@@ -600,17 +600,17 @@ static void dummy_func(void) {
#line 129 "../version.c" #line 129 "../version.c"
puts(_("\n" puts(_("\n"
"Please send bug reports to: <%s>\n")); "Please send bug reports to: <%s>\n"));
#line 938 "../usage.c" #line 902 "../usage.c"
puts(_("\t\t\t\t- may NOT appear - preset only\n")); puts(_("\t\t\t\t- may NOT appear - preset only\n"));
#line 978 "../usage.c" #line 943 "../usage.c"
puts(_("\n" puts(_("\n"
"The following option preset mechanisms are supported:\n")); "The following option preset mechanisms are supported:\n"));
#line 1219 "../usage.c" #line 1191 "../usage.c"
puts(_("\n" puts(_("\n"
"The following option preset mechanisms are supported:\n")); "The following option preset mechanisms are supported:\n"));
#line 717 "../usage.c" #line 681 "../usage.c"
puts(_("prohibits these options:\n")); puts(_("prohibits these options:\n"));
#line 712 "../usage.c" #line 676 "../usage.c"
puts(_("prohibits the option '%s'\n")); puts(_("prohibits the option '%s'\n"));
#line 81 "../numeric.c" #line 81 "../numeric.c"
puts(_("%s%ld to %ld")); puts(_("%s%ld to %ld"));
@@ -628,28 +628,28 @@ static void dummy_func(void) {
puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n")); puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n"));
#line 77 "../numeric.c" #line 77 "../numeric.c"
puts(_("%sless than or equal to %ld")); puts(_("%sless than or equal to %ld"));
#line 426 "../usage.c" #line 389 "../usage.c"
puts(_("Operands and options may be intermixed. They will be reordered.\n")); puts(_("Operands and options may be intermixed. They will be reordered.\n"));
#line 687 "../usage.c" #line 651 "../usage.c"
puts(_("requires the option '%s'\n")); puts(_("requires the option '%s'\n"));
#line 690 "../usage.c" #line 654 "../usage.c"
puts(_("requires these options:\n")); puts(_("requires these options:\n"));
#line 1348 "../usage.c" #line 1320 "../usage.c"
puts(_(" Arg Option-Name Req? Description\n")); puts(_(" Arg Option-Name Req? Description\n"));
#line 1342 "../usage.c" #line 1314 "../usage.c"
puts(_(" Flg Arg Option-Name Req? Description\n")); puts(_(" Flg Arg Option-Name Req? Description\n"));
#line 162 "../enum.c" #line 167 "../enum.c"
puts(_("or you may use a numeric representation. Preceding these with a '!'\n" 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 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" "will set them all. Multiple entries may be passed as an option\n"
"argument list.\n")); "argument list.\n"));
#line 945 "../usage.c" #line 909 "../usage.c"
puts(_("\t\t\t\t- may appear up to %d times\n")); puts(_("\t\t\t\t- may appear up to %d times\n"));
#line 72 "../enum.c" #line 77 "../enum.c"
puts(_("The valid \"%s\" option keywords are:\n")); puts(_("The valid \"%s\" option keywords are:\n"));
#line 1181 "../usage.c" #line 1151 "../usage.c"
puts(_("The next option supports vendor supported extra options:")); puts(_("The next option supports vendor supported extra options:"));
#line 808 "../usage.c" #line 772 "../usage.c"
puts(_("These additional options are:")); puts(_("These additional options are:"));
/* END-USAGE-TEXT */ /* END-USAGE-TEXT */
} }
+22 -76
View File
@@ -8,7 +8,7 @@
static char * static char *
pathfind( char const * path, pathfind( char const * path,
char const * fileName, char const * fname,
char const * mode ); char const * mode );
#include "compat.h" #include "compat.h"
@@ -16,10 +16,10 @@ pathfind( char const * path,
#if defined(__windows__) && !defined(__CYGWIN__) #if defined(__windows__) && !defined(__CYGWIN__)
static char * static char *
pathfind( char const * path, pathfind( char const * path,
char const * fileName, char const * fname,
char const * mode ) char const * mode )
{ {
return NULL; return strdup(fname);
} }
#else #else
@@ -27,70 +27,22 @@ static char* make_absolute( char const *string, char const *dot_path );
static char* canonicalize_pathname( char *path ); static char* canonicalize_pathname( char *path );
static char* extract_colon_unit( char* dir, char const *string, int *p_index ); static char* extract_colon_unit( char* dir, char const *string, int *p_index );
/**
/*=export_func pathfind * local implementation of pathfind.
* * @param[in] path colon separated list of directories
* what: fild a file in a list of directories * @param[in] fname the name we are hunting for
* * @param[in] mode the required file mode
* ifndef: HAVE_PATHFIND * @returns an allocated string with the full path, or NULL
* */
* arg: + char const* + path + colon separated list of search directories +
* arg: + char const* + file + the name of the file to look for +
* arg: + char const* + mode + the mode bits that must be set to match +
*
* ret_type: char*
* ret_desc: the path to the located file
*
* doc:
*
* 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
*
* example:
* To find the "ls" command using the "PATH" environment variable:
* @example
* #include <stdlib.h>
* char* pz_ls = pathfind( getenv("PATH"), "ls", "rx" );
* <<do whatever with pz_ls>>
* free( pz_ls );
* @end example
* The path is allocated with @code{malloc(3C)}, so you must @code{free(3C)}
* the result. Also, do not use unimplemented file modes. :-)
*
* err: returns NULL if the file is not found.
=*/
static char * static char *
pathfind( char const * path, pathfind( char const * path,
char const * fileName, char const * fname,
char const * mode ) char const * mode )
{ {
int p_index = 0; int p_index = 0;
int mode_bits = 0; int mode_bits = 0;
char* pathName = NULL; char * res_path = NULL;
char zPath[ AG_PATH_MAX + 1 ]; char zPath[ AG_PATH_MAX + 1 ];
if (strchr( mode, 'r' )) mode_bits |= R_OK; if (strchr( mode, 'r' )) mode_bits |= R_OK;
if (strchr( mode, 'w' )) mode_bits |= W_OK; if (strchr( mode, 'w' )) mode_bits |= W_OK;
@@ -103,9 +55,6 @@ pathfind( char const * path,
DIR* dirP; DIR* dirP;
char* colon_unit = extract_colon_unit( zPath, path, &p_index ); char* colon_unit = extract_colon_unit( zPath, path, &p_index );
/*
* IF no more entries, THEN quit
*/
if (colon_unit == NULL) if (colon_unit == NULL)
break; break;
@@ -117,9 +66,6 @@ pathfind( char const * path,
if (dirP == NULL) if (dirP == NULL)
continue; continue;
/*
* FOR every entry in the given directory, ...
*/
for (;;) { for (;;) {
struct dirent *entP = readdir( dirP ); struct dirent *entP = readdir( dirP );
@@ -129,31 +75,31 @@ pathfind( char const * path,
/* /*
* IF the file name matches the one we are looking for, ... * IF the file name matches the one we are looking for, ...
*/ */
if (strcmp( entP->d_name, fileName ) == 0) { if (strcmp(entP->d_name, fname) == 0) {
char* pzFullName = make_absolute( fileName, colon_unit); char * abs_name = make_absolute(fname, colon_unit);
/* /*
* Make sure we can access it in the way we want * Make sure we can access it in the way we want
*/ */
if (access( pzFullName, mode_bits ) >= 0) { if (access(abs_name, mode_bits) >= 0) {
/* /*
* We can, so normalize the name and return it below * We can, so normalize the name and return it below
*/ */
pathName = canonicalize_pathname( pzFullName ); res_path = canonicalize_pathname(abs_name);
} }
free( (void*)pzFullName ); free(abs_name);
break; break;
} }
} }
closedir( dirP ); closedir( dirP );
if (pathName != NULL) if (res_path != NULL)
break; break;
} }
return pathName; return res_path;
} }
/* /*
+5 -5
View File
@@ -519,7 +519,7 @@ handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir)
if (txt > pzEnd) { if (txt > pzEnd) {
name_only: name_only:
*pzEnd++ = NUL; *pzEnd++ = NUL;
loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); load_opt_line(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED);
return pzEnd; return pzEnd;
} }
@@ -575,7 +575,7 @@ handle_cfg(tOptions * opts, tOptState * ost, char * txt, int dir)
* "pzName" points to what looks like text for one option/configurable. * "pzName" points to what looks like text for one option/configurable.
* It is NUL terminated. Process it. * It is NUL terminated. Process it.
*/ */
loadOptionLine(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED); load_opt_line(opts, ost, pzName, dir, OPTION_LOAD_UNCOOKED);
return pzEnd; return pzEnd;
} }
@@ -939,7 +939,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir)
return NULL; return NULL;
*txt = NUL; *txt = NUL;
txt += 2; txt += 2;
loadOptionLine(opts, ost, pzName, dir, mode); load_opt_line(opts, ost, pzName, dir, mode);
return txt; return txt;
case '>': case '>':
@@ -963,7 +963,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir)
return txt; return txt;
/* /*
* Rejoin the name and value for parsing by "loadOptionLine()". * Rejoin the name and value for parsing by "load_opt_line()".
* Erase any attributes parsed by "parse_attrs()". * Erase any attributes parsed by "parse_attrs()".
*/ */
memset(pcNulPoint, ' ', (size_t)(pzData - pcNulPoint)); memset(pcNulPoint, ' ', (size_t)(pzData - pcNulPoint));
@@ -980,7 +980,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir)
* "pzName" points to what looks like text for one option/configurable. * "pzName" points to what looks like text for one option/configurable.
* It is NUL terminated. Process it. * It is NUL terminated. Process it.
*/ */
loadOptionLine(opts, ost, pzName, dir, mode); load_opt_line(opts, ost, pzName, dir, mode);
return txt; return txt;
} }
+209 -93
View File
@@ -33,8 +33,6 @@
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/ */
static char const * pz_enum_err_fmt;
/* = = = START-STATIC-FORWARD = = = */ /* = = = START-STATIC-FORWARD = = = */
static void static void
enum_err(tOptions * pOpts, tOptDesc * pOD, enum_err(tOptions * pOpts, tOptDesc * pOD,
@@ -49,8 +47,15 @@ set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
unsigned int name_ct); unsigned int name_ct);
static void static void
set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, set_memb_names(tOptions * opts, tOptDesc * od, char const * const * nm_list,
unsigned int name_ct); unsigned int nm_ct);
static uintptr_t
check_membership_start(tOptDesc * od, char const ** argp, bool * invert);
static uintptr_t
find_member_bit(tOptions * opts, tOptDesc * od, char const * pz, int len,
char const * const * nm_list, unsigned int nm_ct);
/* = = = END-STATIC-FORWARD = = = */ /* = = = END-STATIC-FORWARD = = = */
static void static void
@@ -360,16 +365,14 @@ set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
} }
static void static void
set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, set_memb_names(tOptions * opts, tOptDesc * od, char const * const * nm_list,
unsigned int name_ct) unsigned int nm_ct)
{ {
char * pz; char * pz;
uintptr_t bits = (uintptr_t)pOD->optCookie; uintptr_t mask = (1UL << (uintptr_t)nm_ct) - 1UL;
uintptr_t bits = (uintptr_t)od->optCookie & mask;
unsigned int ix = 0; unsigned int ix = 0;
size_t len = NONE_STR_LEN + 1; size_t len = 1;
(void)pOpts;
bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
/* /*
* Replace the enumeration value with the name string. * Replace the enumeration value with the name string.
@@ -377,46 +380,161 @@ set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
*/ */
while (bits != 0) { while (bits != 0) {
if (bits & 1) if (bits & 1)
len += strlen(paz_names[ix]) + PLUS_STR_LEN + 1; len += strlen(nm_list[ix]) + PLUS_STR_LEN + 1;
if (++ix >= name_ct) break; if (++ix >= nm_ct) break;
bits >>= 1; bits >>= 1;
} }
pOD->optArg.argString = pz = AGALOC(len, "enum"); od->optArg.argString = pz = AGALOC(len, "enum");
bits = (uintptr_t)od->optCookie & mask;
if (bits == 0) {
*pz = NUL;
return;
}
/* for (ix = 0; ; ix++) {
* Start by clearing all the bits. We want to turn off any defaults size_t nln;
* because we will be restoring to current state, not adding to int doit = bits & 1;
* the default set of bits.
*/
memcpy(pz, NONE_STR, NONE_STR_LEN);
pz += NONE_STR_LEN;
bits = (uintptr_t)pOD->optCookie;
bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
ix = 0;
while (bits != 0) {
if (bits & 1) {
size_t nln = strlen(paz_names[ix]);
memcpy(pz, PLUS_STR, PLUS_STR_LEN);
memcpy(pz+PLUS_STR_LEN, paz_names[ix], nln);
pz += nln + PLUS_STR_LEN;
}
if (++ix >= name_ct) break;
bits >>= 1; bits >>= 1;
if (doit == 0)
continue;
nln = strlen(nm_list[ix]);
memcpy(pz, nm_list[ix], nln);
pz += nln;
if (bits == 0)
break;
memcpy(pz, PLUS_STR, PLUS_STR_LEN);
pz += PLUS_STR_LEN;
} }
*pz = NUL; *pz = NUL;
(void)opts;
}
/**
* Check membership start conditions. An equal character (@samp{=}) says to
* clear the result and not carry over any residual value. A carat
* (@samp{^}), which may follow the equal character, says to invert the
* result. The scanning pointer is advanced past these characters and any
* leading white space. Invalid sequences are indicated by setting the
* scanning pointer to NULL.
*
* @param od the set membership option description
* @param argp a pointer to the string scanning pointer
* @param invert a pointer to the boolean inversion indicator
*
* @returns either zero or the original value for the optCookie.
*/
static uintptr_t
check_membership_start(tOptDesc * od, char const ** argp, bool * invert)
{
uintptr_t res = (uintptr_t)od->optCookie;
char const * arg = SPN_WHITESPACE_CHARS(od->optArg.argString);
if ((arg == NULL) || (*arg == NUL))
goto member_start_fail;
*invert = false;
switch (*arg) {
case '=':
res = 0UL;
arg = SPN_WHITESPACE_CHARS(arg + 1);
switch (*arg) {
case '=': case ',':
goto member_start_fail;
case '^':
goto inversion;
default:
break;
}
break;
case '^':
inversion:
*invert = true;
arg = SPN_WHITESPACE_CHARS(arg + 1);
if (*arg != ',')
break;
/* FALLTHROUGH */
case ',':
goto member_start_fail;
default:
break;
}
*argp = arg;
return res;
member_start_fail:
*argp = NULL;
return 0UL;
}
/**
* convert a name to a bit. Look up a name string to get a bit number
* and shift the value "1" left that number of bits.
*
* @param opts program options descriptor
* @param od the set membership option description
* @param pz address of the start of the bit name
* @param nm_list the list of names for this option
* @param nm_ct the number of entries in this list
*
* @returns 0UL on error, other an unsigned long with the correct bit set.
*/
static uintptr_t
find_member_bit(tOptions * opts, tOptDesc * od, char const * pz, int len,
char const * const * nm_list, unsigned int nm_ct)
{
char nm_buf[ AO_NAME_SIZE ];
memcpy(nm_buf, pz, len);
nm_buf[len] = NUL;
{
unsigned int shift_ct = (unsigned int)
find_name(nm_buf, opts, od, nm_list, nm_ct);
if (shift_ct >= nm_ct)
return 0UL;
return 1UL << shift_ct;
}
}
/*=export_func optionMemberList
* what: Get the list of members of a bit mask set
*
* arg: tOptDesc *, od, the set membership option description
*
* ret_type: char*
* ret_desc: the names of the set bits
*
* doc: This converts the OPT_VALUE_name mask value to a allocated string.
* It is the caller's responsibility to free the string.
=*/
char *
optionMemberList(tOptDesc * od)
{
uintptr_t sv = od->optArg.argIntptr;
char * res;
(*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od);
res = (void *)od->optArg.argString;
od->optArg.argIntptr = sv;
return res;
} }
/*=export_func optionSetMembers /*=export_func optionSetMembers
* what: Convert between bit flag values and strings * what: Convert between bit flag values and strings
* private: * private:
* *
* arg: tOptions*, pOpts, the program options descriptor * arg: tOptions*, opts, the program options descriptor
* arg: tOptDesc*, pOD, enumeration option description * arg: tOptDesc*, od, the set membership option description
* arg: char const * const *, * arg: char const * const *,
* paz_names, list of enumeration names * nm_list, list of enumeration names
* arg: unsigned int, name_ct, number of names in list * arg: unsigned int, nm_ct, number of names in list
* *
* doc: This converts the optArg.argString string from the option description * doc: This converts the optArg.argString string from the option description
* into the index corresponding to an entry in the name list. * into the index corresponding to an entry in the name list.
@@ -425,105 +543,103 @@ set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
* if there is only one partial match. * if there is only one partial match.
=*/ =*/
void void
optionSetMembers(tOptions * pOpts, tOptDesc * pOD, optionSetMembers(tOptions * opts, tOptDesc * od,
char const* const * paz_names, unsigned int name_ct) char const * const * nm_list, unsigned int nm_ct)
{ {
/* /*
* IF the program option descriptor pointer is invalid, * IF the program option descriptor pointer is invalid,
* then it is some sort of special request. * then it is some sort of special request.
*/ */
switch ((uintptr_t)pOpts) { switch ((uintptr_t)opts) {
case (uintptr_t)OPTPROC_EMIT_USAGE: case (uintptr_t)OPTPROC_EMIT_USAGE:
enum_err(OPTPROC_EMIT_USAGE, pOD, paz_names, name_ct); enum_err(OPTPROC_EMIT_USAGE, od, nm_list, nm_ct);
return; return;
case (uintptr_t)OPTPROC_EMIT_SHELL: case (uintptr_t)OPTPROC_EMIT_SHELL:
set_memb_shell(pOpts, pOD, paz_names, name_ct); set_memb_shell(opts, od, nm_list, nm_ct);
return; return;
case (uintptr_t)OPTPROC_RETURN_VALNAME: case (uintptr_t)OPTPROC_RETURN_VALNAME:
set_memb_names(pOpts, pOD, paz_names, name_ct); set_memb_names(opts, od, nm_list, nm_ct);
return; return;
default: default:
break; break;
} }
if ((pOD->fOptState & OPTST_RESET) != 0) if ((od->fOptState & OPTST_RESET) != 0)
return; return;
{ {
char const * pzArg = pOD->optArg.argString; char const * arg;
uintptr_t res; bool invert;
if ((pzArg == NULL) || (*pzArg == NUL)) { uintptr_t res = check_membership_start(od, &arg, &invert);
pOD->optCookie = (void*)0; if (arg == NULL)
return; goto fail_return;
}
res = (uintptr_t)pOD->optCookie; while (*arg != NUL) {
for (;;) { bool inv_val = false;
int iv, len; int len;
pzArg = SPN_SET_SEPARATOR_CHARS(pzArg); switch (*arg) {
iv = (*pzArg == '!'); case ',':
if (iv) arg = SPN_WHITESPACE_CHARS(arg+1);
pzArg = SPN_WHITESPACE_CHARS(pzArg+1); if ((*arg == ',') || (*arg == '|'))
goto fail_return;
continue;
len = (int)(BRK_SET_SEPARATOR_CHARS(pzArg) - pzArg); case '-':
case '!':
inv_val = true;
/* FALLTHROUGH */
case '+':
case '|':
arg = SPN_WHITESPACE_CHARS(arg+1);
}
len = (int)(BRK_SET_SEPARATOR_CHARS(arg) - arg);
if (len == 0) if (len == 0)
break; break;
if ((len == 3) && (strncmp(pzArg, zAll, 3) == 0)) { if ((len == 3) && (strncmp(arg, zAll, 3) == 0)) {
if (iv) if (inv_val)
res = 0; res = 0;
else res = ~0UL; else res = ~0UL;
} }
else if ((len == 4) && (strncmp(pzArg, zNone, 4) == 0)) { else if ((len == 4) && (strncmp(arg, zNone, 4) == 0)) {
if (! iv) if (! inv_val)
res = 0; res = 0;
} }
else do { else do {
char* pz; char * pz;
uintptr_t bit = strtoul(pzArg, &pz, 0); uintptr_t bit = strtoul(arg, &pz, 0);
if (pz != pzArg + len) { if (pz != arg + len) {
char z[ AO_NAME_SIZE ]; bit = find_member_bit(opts, od, pz, len, nm_list, nm_ct);
char const* p; if (bit == 0UL)
unsigned int shift_ct; goto fail_return;
if (*pz != NUL) {
if (len >= AO_NAME_LIMIT)
break;
memcpy(z, pzArg, (size_t)len);
z[len] = NUL;
p = z;
} else {
p = pzArg;
}
shift_ct = (unsigned int)
find_name(p, pOpts, pOD, paz_names, name_ct);
if (shift_ct >= name_ct) {
pOD->optCookie = (void*)0;
return;
}
bit = 1UL << shift_ct;
} }
if (iv) if (inv_val)
res &= ~bit; res &= ~bit;
else res |= bit; else res |= bit;
} while (false); } while (false);
if (pzArg[len] == NUL) arg = SPN_WHITESPACE_CHARS(arg + len);
break;
pzArg += len + 1;
}
if (name_ct < (8 * sizeof(uintptr_t))) {
res &= (1UL << name_ct) - 1UL;
} }
pOD->optCookie = (void*)res; if (invert)
res ^= ~0UL;
if (nm_ct < (8 * sizeof(uintptr_t)))
res &= (1UL << nm_ct) - 1UL;
od->optCookie = (void *)res;
} }
return;
fail_return:
od->optCookie = (void *)0;
} }
/** @} /** @}
+11 -2
View File
@@ -107,6 +107,9 @@ opt_ambiguities(tOptions * opts, char const * name, int nm_len)
fputs(zambig_list_msg, stderr); fputs(zambig_list_msg, stderr);
do { do {
if (pOD->pz_Name == NULL)
continue; /* doc option */
if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0) if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0)
fprintf(stderr, zambig_file, hyph, pOD->pz_Name); fprintf(stderr, zambig_file, hyph, pOD->pz_Name);
@@ -375,7 +378,10 @@ opt_find_long(tOptions * opts, char const * opt_name, tOptState * state)
bool disable = false; bool disable = false;
int ct; int ct;
if (nm_len <= 0) { if (nm_len <= 1) {
if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0)
return FAILURE;
fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name); fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name);
(*opts->pUsageProc)(opts, EXIT_FAILURE); (*opts->pUsageProc)(opts, EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
@@ -418,6 +424,9 @@ opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState)
if (SKIP_OPT(pRes)) { if (SKIP_OPT(pRes)) {
if ( (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) if ( (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT))
&& (pRes->pz_Name != NULL)) { && (pRes->pz_Name != NULL)) {
if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
return FAILURE;
fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name); fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name);
if (pRes->pzText != NULL) if (pRes->pzText != NULL)
fprintf(stderr, SET_OFF_FMT, pRes->pzText); fprintf(stderr, SET_OFF_FMT, pRes->pzText);
@@ -500,7 +509,7 @@ get_opt_arg_must(tOptions * opts, tOptState * o_st)
default: default:
#ifdef DEBUG #ifdef DEBUG
fputs("AutoOpts lib error: option type not selected\n", stderr); fputs("AutoOpts lib error: option type not selected\n", stderr);
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
#endif #endif
case TOPT_DEFAULT: case TOPT_DEFAULT:
+108 -106
View File
@@ -2,11 +2,11 @@
* *
* DO NOT EDIT THIS FILE (genshell.c) * DO NOT EDIT THIS FILE (genshell.c)
* *
* It has been AutoGen-ed March 31, 2013 at 10:41:27 AM by AutoGen 5.17.3 * It has been AutoGen-ed July 14, 2013 at 05:37:09 PM by AutoGen 5.18
* From the definitions genshell.def * From the definitions genshell.def
* and the template file options * and the template file options
* *
* Generated from AutoOpts 38:0:13 templates. * Generated from AutoOpts 40:0:15 templates.
* *
* AutoOpts is a copyrighted work. This source file is not encumbered * AutoOpts is a copyrighted work. This source file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen * by AutoOpts licensing, but is provided under the licensing terms chosen
@@ -146,8 +146,8 @@ static char const genshellopt_opt_strs[1769] =
#define MORE_HELP_name (genshellopt_opt_strs+1134) #define MORE_HELP_name (genshellopt_opt_strs+1134)
#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) #define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
#else #else
#define MORE_HELP_DESC NULL #define MORE_HELP_DESC HELP_DESC
#define MORE_HELP_name NULL #define MORE_HELP_name HELP_name
#define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) #define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
#endif #endif
#ifdef NO_OPTIONAL_OPT_ARGS #ifdef NO_OPTIONAL_OPT_ARGS
@@ -258,7 +258,7 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
#define zDetail (genshellopt_opt_strs+1534) #define zDetail (genshellopt_opt_strs+1534)
/** The full version string for genshellopt. */ /** The full version string for genshellopt. */
#define zFullVersion (genshellopt_opt_strs+1755) #define zFullVersion (genshellopt_opt_strs+1755)
/* extracted from optcode.tlib near line 371 */ /* extracted from optcode.tlib near line 364 */
#if defined(ENABLE_NLS) #if defined(ENABLE_NLS)
# define OPTPROC_BASE OPTPROC_TRANSLATE # define OPTPROC_BASE OPTPROC_TRANSLATE
@@ -279,19 +279,21 @@ static tOptDesc optDesc[GENSHELL_OPTION_CT] = {
/** /**
* The callout function that invokes the genshelloptUsage function. * The callout function that invokes the genshelloptUsage function.
* *
* @param[in] pOptions the AutoOpts option description structure * @param[in] opts the AutoOpts option description structure
* @param[in] pOptDesc the descriptor for the "help" (usage) option. * @param[in] od the descriptor for the "help" (usage) option.
* @noreturn * @noreturn
*/ */
static void static void
doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) doUsageOpt(tOptions * opts, tOptDesc * od)
{ {
genshelloptUsage(&genshelloptOptions, GENSHELLOPT_EXIT_SUCCESS); int ex_code;
ex_code = GENSHELLOPT_EXIT_SUCCESS;
genshelloptUsage(&genshelloptOptions, ex_code);
/* NOTREACHED */ /* NOTREACHED */
(void)pOptDesc; (void)opts;
(void)pOptions; (void)od;
} }
/* extracted from optmain.tlib near line 1254 */ /* extracted from optmain.tlib near line 1266 */
/** /**
* The directory containing the data associated with genshellopt. * The directory containing the data associated with genshellopt.
@@ -474,10 +476,10 @@ translate_option_strings(void)
static void bogus_function(void) { static void bogus_function(void) {
/* TRANSLATORS: /* TRANSLATORS:
The following dummy function was crated solely so that xgettext can extract The following dummy function was crated solely so that xgettext can
the correct strings. These strings are actually referenced by a field name extract the correct strings. These strings are actually referenced
in the genshelloptOptions structure noted in the comments below. The by a field name in the genshelloptOptions structure noted in the
literal text is defined in genshellopt_opt_strs. comments below. The literal text is defined in genshellopt_opt_strs.
NOTE: the strings below are segmented with respect to the source string NOTE: the strings below are segmented with respect to the source string
genshellopt_opt_strs. The strings above are handed off for translation genshellopt_opt_strs. The strings above are handed off for translation
@@ -546,51 +548,51 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
/* referenced via genshelloptOptions.pzShortUsage */ /* referenced via genshelloptOptions.pzShortUsage */
puts(_("<<<NOT-FOUND>>>")); puts(_("<<<NOT-FOUND>>>"));
/* LIBOPTS-MESSAGES: */ /* LIBOPTS-MESSAGES: */
#line 60 "../autoopts.c" #line 67 "../autoopts.c"
puts(_("allocation of %d bytes failed\n")); puts(_("allocation of %d bytes failed\n"));
#line 86 "../autoopts.c" #line 93 "../autoopts.c"
puts(_("allocation of %d bytes failed\n")); puts(_("allocation of %d bytes failed\n"));
#line 53 "../init.c" #line 53 "../init.c"
puts(_("AutoOpts function called without option descriptor\n")); puts(_("AutoOpts function called without option descriptor\n"));
#line 89 "../init.c" #line 90 "../init.c"
puts(_("\tThis exceeds the compiled library version: ")); puts(_("\tThis exceeds the compiled library version: "));
#line 87 "../init.c" #line 88 "../init.c"
puts(_("Automated Options Processing Error!\n" puts(_("Automated Options Processing Error!\n"
"\t%s called AutoOpts function with structure version %d:%d:%d.\n")); "\t%s called AutoOpts function with structure version %d:%d:%d.\n"));
#line 73 "../autoopts.c" #line 80 "../autoopts.c"
puts(_("realloc of %d bytes at 0x%p failed\n")); puts(_("realloc of %d bytes at 0x%p failed\n"));
#line 91 "../init.c" #line 92 "../init.c"
puts(_("\tThis is less than the minimum library version: ")); puts(_("\tThis is less than the minimum library version: "));
#line 121 "../version.c" #line 121 "../version.c"
puts(_("Automated Options version %s\n" puts(_("Automated Options version %s\n"
"\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n")); "\tCopyright (C) 1999-2013 by Bruce Korb - all rights reserved\n"));
#line 310 "../usage.c" #line 82 "../makeshell.c"
puts(_("(AutoOpts bug): %s.\n")); puts(_("(AutoOpts bug): %s.\n"));
#line 90 "../reset.c" #line 90 "../reset.c"
puts(_("optionResetOpt() called, but reset-option not configured")); puts(_("optionResetOpt() called, but reset-option not configured"));
#line 329 "../usage.c" #line 292 "../usage.c"
puts(_("could not locate the 'help' option")); puts(_("could not locate the 'help' option"));
#line 351 "../autoopts.c" #line 336 "../autoopts.c"
puts(_("optionProcess() was called with invalid data")); puts(_("optionProcess() was called with invalid data"));
#line 783 "../usage.c" #line 747 "../usage.c"
puts(_("invalid argument type specified")); puts(_("invalid argument type specified"));
#line 589 "../find.c" #line 598 "../find.c"
puts(_("defaulted to option with optional arg")); puts(_("defaulted to option with optional arg"));
#line 76 "../alias.c" #line 76 "../alias.c"
puts(_("aliasing option is out of range.")); puts(_("aliasing option is out of range."));
#line 229 "../enum.c" #line 234 "../enum.c"
puts(_("%s error: the keyword '%s' is ambiguous for %s\n")); puts(_("%s error: the keyword '%s' is ambiguous for %s\n"));
#line 108 "../find.c" #line 108 "../find.c"
puts(_(" The following options match:\n")); puts(_(" The following options match:\n"));
#line 290 "../find.c" #line 293 "../find.c"
puts(_("%s: ambiguous option name: %s (matches %d options)\n")); puts(_("%s: ambiguous option name: %s (matches %d options)\n"));
#line 161 "../check.c" #line 161 "../check.c"
puts(_("%s: Command line arguments required\n")); puts(_("%s: Command line arguments required\n"));
#line 43 "../alias.c" #line 43 "../alias.c"
puts(_("%d %s%s options allowed\n")); puts(_("%d %s%s options allowed\n"));
#line 81 "../makeshell.c" #line 89 "../makeshell.c"
puts(_("%s error %d (%s) calling %s for '%s'\n")); puts(_("%s error %d (%s) calling %s for '%s'\n"));
#line 293 "../makeshell.c" #line 301 "../makeshell.c"
puts(_("interprocess pipe")); puts(_("interprocess pipe"));
#line 168 "../version.c" #line 168 "../version.c"
puts(_("error: version option argument '%c' invalid. Use:\n" puts(_("error: version option argument '%c' invalid. Use:\n"
@@ -599,48 +601,48 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
"\t'n' - version and full copyright notice\n")); "\t'n' - version and full copyright notice\n"));
#line 58 "../check.c" #line 58 "../check.c"
puts(_("%s error: the '%s' and '%s' options conflict\n")); puts(_("%s error: the '%s' and '%s' options conflict\n"));
#line 214 "../find.c" #line 217 "../find.c"
puts(_("%s: The '%s' option has been disabled.")); puts(_("%s: The '%s' option has been disabled."));
#line 421 "../find.c" #line 430 "../find.c"
puts(_("%s: The '%s' option has been disabled.")); puts(_("%s: The '%s' option has been disabled."));
#line 38 "../alias.c" #line 38 "../alias.c"
puts(_("-equivalence")); puts(_("-equivalence"));
#line 460 "../find.c" #line 469 "../find.c"
puts(_("%s: illegal option -- %c\n")); puts(_("%s: illegal option -- %c\n"));
#line 110 "../reset.c" #line 110 "../reset.c"
puts(_("%s: illegal option -- %c\n")); puts(_("%s: illegal option -- %c\n"));
#line 268 "../find.c" #line 271 "../find.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 746 "../find.c" #line 755 "../find.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 118 "../reset.c" #line 118 "../reset.c"
puts(_("%s: illegal option -- %s\n")); puts(_("%s: illegal option -- %s\n"));
#line 332 "../find.c" #line 335 "../find.c"
puts(_("%s: unknown vendor extension option -- %s\n")); puts(_("%s: unknown vendor extension option -- %s\n"));
#line 154 "../enum.c" #line 159 "../enum.c"
puts(_(" or an integer from %d through %d\n")); puts(_(" or an integer from %d through %d\n"));
#line 164 "../enum.c" #line 169 "../enum.c"
puts(_(" or an integer from %d through %d\n")); puts(_(" or an integer from %d through %d\n"));
#line 782 "../usage.c" #line 746 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n")); puts(_("%s error: invalid option descriptor for %s\n"));
#line 1110 "../usage.c" #line 1080 "../usage.c"
puts(_("%s error: invalid option descriptor for %s\n")); puts(_("%s error: invalid option descriptor for %s\n"));
#line 379 "../find.c" #line 385 "../find.c"
puts(_("%s: invalid option name: %s\n")); puts(_("%s: invalid option name: %s\n"));
#line 518 "../find.c" #line 527 "../find.c"
puts(_("%s: The '%s' option requires an argument.\n")); puts(_("%s: The '%s' option requires an argument.\n"));
#line 171 "../autoopts.c" #line 156 "../autoopts.c"
puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n" puts(_("(AutoOpts bug): Equivalenced option '%s' was equivalenced to both\n"
"\t'%s' and '%s'.")); "\t'%s' and '%s'."));
#line 94 "../check.c" #line 94 "../check.c"
puts(_("%s error: The %s option is required\n")); puts(_("%s error: The %s option is required\n"));
#line 623 "../find.c" #line 632 "../find.c"
puts(_("%s: The '%s' option cannot have an argument.\n")); puts(_("%s: The '%s' option cannot have an argument.\n"));
#line 151 "../check.c" #line 151 "../check.c"
puts(_("%s: Command line arguments are not allowed.\n")); puts(_("%s: Command line arguments are not allowed.\n"));
#line 531 "../save.c" #line 535 "../save.c"
puts(_("error %d (%s) creating %s\n")); puts(_("error %d (%s) creating %s\n"));
#line 229 "../enum.c" #line 234 "../enum.c"
puts(_("%s error: '%s' does not match any %s keywords.\n")); puts(_("%s error: '%s' does not match any %s keywords.\n"));
#line 93 "../reset.c" #line 93 "../reset.c"
puts(_("%s error: The '%s' option requires an argument.\n")); puts(_("%s error: The '%s' option requires an argument.\n"));
@@ -650,7 +652,7 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
puts(_("error %d (%s) stat-ing %s\n")); puts(_("error %d (%s) stat-ing %s\n"));
#line 143 "../restore.c" #line 143 "../restore.c"
puts(_("%s error: no saved option state\n")); puts(_("%s error: no saved option state\n"));
#line 246 "../autoopts.c" #line 231 "../autoopts.c"
puts(_("'%s' is not a command line option.\n")); puts(_("'%s' is not a command line option.\n"));
#line 114 "../time.c" #line 114 "../time.c"
puts(_("%s error: '%s' is not a recognizable date/time.\n")); puts(_("%s error: '%s' is not a recognizable date/time.\n"));
@@ -662,41 +664,41 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
puts(_("%s error: The %s option must appear %d times.\n")); puts(_("%s error: The %s option must appear %d times.\n"));
#line 157 "../numeric.c" #line 157 "../numeric.c"
puts(_("%s error: '%s' is not a recognizable number.\n")); puts(_("%s error: '%s' is not a recognizable number.\n"));
#line 195 "../enum.c" #line 200 "../enum.c"
puts(_("%s error: %s exceeds %s keyword count\n")); puts(_("%s error: %s exceeds %s keyword count\n"));
#line 366 "../usage.c" #line 329 "../usage.c"
puts(_("Try '%s %s' for more information.\n")); puts(_("Try '%s %s' for more information.\n"));
#line 45 "../alias.c" #line 45 "../alias.c"
puts(_("one %s%s option allowed\n")); puts(_("one %s%s option allowed\n"));
#line 195 "../makeshell.c" #line 203 "../makeshell.c"
puts(_("standard output")); puts(_("standard output"));
#line 930 "../makeshell.c" #line 938 "../makeshell.c"
puts(_("standard output")); puts(_("standard output"));
#line 304 "../usage.c" #line 274 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 451 "../usage.c" #line 414 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 660 "../usage.c" #line 624 "../usage.c"
puts(_("standard output")); puts(_("standard output"));
#line 175 "../version.c" #line 175 "../version.c"
puts(_("standard output")); puts(_("standard output"));
#line 304 "../usage.c" #line 274 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 451 "../usage.c" #line 414 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 660 "../usage.c" #line 624 "../usage.c"
puts(_("standard error")); puts(_("standard error"));
#line 175 "../version.c" #line 175 "../version.c"
puts(_("standard error")); puts(_("standard error"));
#line 195 "../makeshell.c" #line 203 "../makeshell.c"
puts(_("write")); puts(_("write"));
#line 930 "../makeshell.c" #line 938 "../makeshell.c"
puts(_("write")); puts(_("write"));
#line 303 "../usage.c" #line 273 "../usage.c"
puts(_("write")); puts(_("write"));
#line 450 "../usage.c" #line 413 "../usage.c"
puts(_("write")); puts(_("write"));
#line 659 "../usage.c" #line 623 "../usage.c"
puts(_("write")); puts(_("write"));
#line 174 "../version.c" #line 174 "../version.c"
puts(_("write")); puts(_("write"));
@@ -712,70 +714,70 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 256 "../save.c" #line 256 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
#line 530 "../save.c" #line 534 "../save.c"
puts(_("%s warning: cannot save options - %s not regular file\n")); puts(_("%s warning: cannot save options - %s not regular file\n"));
/* END-LIBOPTS-MESSAGES */ /* END-LIBOPTS-MESSAGES */
/* USAGE-TEXT: */ /* 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" #line 872 "../usage.c"
puts(_("\t\t\t\t- an alternate for '%s'\n"));
#line 1147 "../usage.c"
puts(_("Version, usage and configuration options:"));
#line 923 "../usage.c"
puts(_("\t\t\t\t- default option for unnamed options\n"));
#line 836 "../usage.c"
puts(_("\t\t\t\t- disabled as '--%s'\n")); puts(_("\t\t\t\t- disabled as '--%s'\n"));
#line 1146 "../usage.c" #line 1116 "../usage.c"
puts(_(" --- %-14s %s\n")); puts(_(" --- %-14s %s\n"));
#line 1144 "../usage.c" #line 1114 "../usage.c"
puts(_("This option has been disabled")); puts(_("This option has been disabled"));
#line 899 "../usage.c" #line 863 "../usage.c"
puts(_("\t\t\t\t- enabled by default\n")); puts(_("\t\t\t\t- enabled by default\n"));
#line 40 "../alias.c" #line 40 "../alias.c"
puts(_("%s error: only ")); puts(_("%s error: only "));
#line 1221 "../usage.c" #line 1193 "../usage.c"
puts(_(" - examining environment variables named %s_*\n")); puts(_(" - examining environment variables named %s_*\n"));
#line 168 "../file.c" #line 168 "../file.c"
puts(_("\t\t\t\t- file must not pre-exist\n")); puts(_("\t\t\t\t- file must not pre-exist\n"));
#line 172 "../file.c" #line 172 "../file.c"
puts(_("\t\t\t\t- file must pre-exist\n")); puts(_("\t\t\t\t- file must pre-exist\n"));
#line 416 "../usage.c" #line 379 "../usage.c"
puts(_("Options are specified by doubled hyphens and their name or by a single\n" puts(_("Options are specified by doubled hyphens and their name or by a single\n"
"hyphen and the flag character.\n")); "hyphen and the flag character.\n"));
#line 908 "../makeshell.c" #line 916 "../makeshell.c"
puts(_("\n" puts(_("\n"
"= = = = = = = =\n\n" "= = = = = = = =\n\n"
"This incarnation of genshell will produce\n" "This incarnation of genshell will produce\n"
"a shell script to parse the options for %s:\n\n")); "a shell script to parse the options for %s:\n\n"));
#line 161 "../enum.c" #line 166 "../enum.c"
puts(_(" or an integer mask with any of the lower %d bits set\n")); puts(_(" or an integer mask with any of the lower %d bits set\n"));
#line 932 "../usage.c" #line 896 "../usage.c"
puts(_("\t\t\t\t- is a set membership option\n")); puts(_("\t\t\t\t- is a set membership option\n"));
#line 953 "../usage.c" #line 917 "../usage.c"
puts(_("\t\t\t\t- must appear between %d and %d times\n")); puts(_("\t\t\t\t- must appear between %d and %d times\n"));
#line 418 "../usage.c" #line 381 "../usage.c"
puts(_("Options are specified by single or double hyphens and their name.\n")); puts(_("Options are specified by single or double hyphens and their name.\n"));
#line 939 "../usage.c" #line 903 "../usage.c"
puts(_("\t\t\t\t- may appear multiple times\n")); puts(_("\t\t\t\t- may appear multiple times\n"));
#line 926 "../usage.c" #line 890 "../usage.c"
puts(_("\t\t\t\t- may not be preset\n")); puts(_("\t\t\t\t- may not be preset\n"));
#line 1336 "../usage.c" #line 1308 "../usage.c"
puts(_(" Arg Option-Name Description\n")); puts(_(" Arg Option-Name Description\n"));
#line 1272 "../usage.c" #line 1244 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n")); puts(_(" Flg Arg Option-Name Description\n"));
#line 1330 "../usage.c" #line 1302 "../usage.c"
puts(_(" Flg Arg Option-Name Description\n")); puts(_(" Flg Arg Option-Name Description\n"));
#line 1331 "../usage.c" #line 1303 "../usage.c"
puts(_(" %3s %s")); puts(_(" %3s %s"));
#line 1337 "../usage.c" #line 1309 "../usage.c"
puts(_(" %3s %s")); puts(_(" %3s %s"));
#line 423 "../usage.c" #line 386 "../usage.c"
puts(_("The '-#<number>' option may omit the hash char\n")); puts(_("The '-#<number>' option may omit the hash char\n"));
#line 419 "../usage.c" #line 382 "../usage.c"
puts(_("All arguments are named options.\n")); puts(_("All arguments are named options.\n"));
#line 1006 "../usage.c" #line 970 "../usage.c"
puts(_(" - reading file %s")); puts(_(" - reading file %s"));
#line 445 "../usage.c" #line 408 "../usage.c"
puts(_("\n" puts(_("\n"
"Please send bug reports to: <%s>\n")); "Please send bug reports to: <%s>\n"));
#line 100 "../version.c" #line 100 "../version.c"
@@ -784,17 +786,17 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
#line 129 "../version.c" #line 129 "../version.c"
puts(_("\n" puts(_("\n"
"Please send bug reports to: <%s>\n")); "Please send bug reports to: <%s>\n"));
#line 938 "../usage.c" #line 902 "../usage.c"
puts(_("\t\t\t\t- may NOT appear - preset only\n")); puts(_("\t\t\t\t- may NOT appear - preset only\n"));
#line 978 "../usage.c" #line 943 "../usage.c"
puts(_("\n" puts(_("\n"
"The following option preset mechanisms are supported:\n")); "The following option preset mechanisms are supported:\n"));
#line 1219 "../usage.c" #line 1191 "../usage.c"
puts(_("\n" puts(_("\n"
"The following option preset mechanisms are supported:\n")); "The following option preset mechanisms are supported:\n"));
#line 717 "../usage.c" #line 681 "../usage.c"
puts(_("prohibits these options:\n")); puts(_("prohibits these options:\n"));
#line 712 "../usage.c" #line 676 "../usage.c"
puts(_("prohibits the option '%s'\n")); puts(_("prohibits the option '%s'\n"));
#line 81 "../numeric.c" #line 81 "../numeric.c"
puts(_("%s%ld to %ld")); puts(_("%s%ld to %ld"));
@@ -812,28 +814,28 @@ by the newly generated text. The first '#!' line will be regenerated.\n"));
puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n")); puts(_("%sis scalable with a suffix: k/K/m/M/g/G/t/T\n"));
#line 77 "../numeric.c" #line 77 "../numeric.c"
puts(_("%sless than or equal to %ld")); puts(_("%sless than or equal to %ld"));
#line 426 "../usage.c" #line 389 "../usage.c"
puts(_("Operands and options may be intermixed. They will be reordered.\n")); puts(_("Operands and options may be intermixed. They will be reordered.\n"));
#line 687 "../usage.c" #line 651 "../usage.c"
puts(_("requires the option '%s'\n")); puts(_("requires the option '%s'\n"));
#line 690 "../usage.c" #line 654 "../usage.c"
puts(_("requires these options:\n")); puts(_("requires these options:\n"));
#line 1348 "../usage.c" #line 1320 "../usage.c"
puts(_(" Arg Option-Name Req? Description\n")); puts(_(" Arg Option-Name Req? Description\n"));
#line 1342 "../usage.c" #line 1314 "../usage.c"
puts(_(" Flg Arg Option-Name Req? Description\n")); puts(_(" Flg Arg Option-Name Req? Description\n"));
#line 162 "../enum.c" #line 167 "../enum.c"
puts(_("or you may use a numeric representation. Preceding these with a '!'\n" 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 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" "will set them all. Multiple entries may be passed as an option\n"
"argument list.\n")); "argument list.\n"));
#line 945 "../usage.c" #line 909 "../usage.c"
puts(_("\t\t\t\t- may appear up to %d times\n")); puts(_("\t\t\t\t- may appear up to %d times\n"));
#line 72 "../enum.c" #line 77 "../enum.c"
puts(_("The valid \"%s\" option keywords are:\n")); puts(_("The valid \"%s\" option keywords are:\n"));
#line 1181 "../usage.c" #line 1151 "../usage.c"
puts(_("The next option supports vendor supported extra options:")); puts(_("The next option supports vendor supported extra options:"));
#line 808 "../usage.c" #line 772 "../usage.c"
puts(_("These additional options are:")); puts(_("These additional options are:"));
/* END-USAGE-TEXT */ /* END-USAGE-TEXT */
} }
+9 -11
View File
@@ -2,11 +2,11 @@
* *
* DO NOT EDIT THIS FILE (genshell.h) * DO NOT EDIT THIS FILE (genshell.h)
* *
* It has been AutoGen-ed March 31, 2013 at 10:41:27 AM by AutoGen 5.17.3 * It has been AutoGen-ed July 14, 2013 at 05:37:09 PM by AutoGen 5.18
* From the definitions genshell.def * From the definitions genshell.def
* and the template file options * and the template file options
* *
* Generated from AutoOpts 38:0:13 templates. * Generated from AutoOpts 40:0:15 templates.
* *
* AutoOpts is a copyrighted work. This header file is not encumbered * AutoOpts is a copyrighted work. This header file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen * by AutoOpts licensing, but is provided under the licensing terms chosen
@@ -55,7 +55,7 @@
* tolerable version is at least as old as what was current when the header * tolerable version is at least as old as what was current when the header
* template was released. * template was released.
*/ */
#define AO_TEMPLATE_VERSION 155648 #define AO_TEMPLATE_VERSION 163840
#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
|| (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
# error option template version mismatches autoopts/options.h header # error option template version mismatches autoopts/options.h header
@@ -87,7 +87,7 @@ typedef enum {
#define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n]) #define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
/** 'true' if an option has been specified in any way */ /** 'true' if an option has been specified in any way */
#define HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n))) #define HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
/** The string argument to an option. The argument type must be "string". */ /** The string argument to an option. The argument type must be \"string\". */
#define GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString) #define GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
/** Mask the option state revealing how an option was specified. /** Mask the option state revealing how an option was specified.
* It will be one and only one of \a OPTST_SET, \a OPTST_PRESET, * It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
@@ -114,18 +114,16 @@ typedef enum {
if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \ if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \ GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
GENSHELL_DESC(n).optCookie = NULL ) GENSHELL_DESC(n).optCookie = NULL )
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** /**
* Enumeration of genshellopt exit codes * Enumeration of genshellopt exit codes
*/ */
typedef enum { typedef enum {
GENSHELLOPT_EXIT_SUCCESS = 0, GENSHELLOPT_EXIT_SUCCESS = 0,
GENSHELLOPT_EXIT_FAILURE = 1, GENSHELLOPT_EXIT_FAILURE = 1,
GENSHELLOPT_EXIT_USAGE_ERROR = 64, GENSHELLOPT_EXIT_USAGE_ERROR = 64,
GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70 GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
} genshellopt_exit_code_t; } genshellopt_exit_code_t;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** /**
* Interface defines for specific options. * Interface defines for specific options.
* @{ * @{
@@ -148,7 +146,6 @@ typedef enum {
genshelloptOptions.pzCurOpt = NULL ) genshelloptOptions.pzCurOpt = NULL )
#define START_GENSHELL_OPT RESTART_GENSHELL_OPT(1) #define START_GENSHELL_OPT RESTART_GENSHELL_OPT(1)
#define GENSHELL_USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c) #define GENSHELL_USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
/* extracted from opthead.tlib near line 538 */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -203,4 +200,5 @@ static inline char* aoGetsText(char const* pz) {
} }
#endif #endif
#endif /* AUTOOPTS_GENSHELL_H_GUARD */ #endif /* AUTOOPTS_GENSHELL_H_GUARD */
/* genshell.h ends here */ /* genshell.h ends here */
+1
View File
@@ -20,6 +20,7 @@
/* NLS can be disabled through the configure --disable-nls option. */ /* NLS can be disabled through the configure --disable-nls option. */
#if ENABLE_NLS #if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */ /* Get declarations of GNU message catalog functions. */
# include <libintl.h> # include <libintl.h>
+7 -6
View File
@@ -53,6 +53,7 @@ validate_struct(tOptions * opts, char const * pname)
fputs(zno_opt_arg, stderr); fputs(zno_opt_arg, stderr);
return FAILURE; return FAILURE;
} }
print_exit = ((opts->fOptSet & OPTPROC_SHELL_OUTPUT) != 0);
/* /*
* IF the client has enabled translation and the translation procedure * IF the client has enabled translation and the translation procedure
@@ -103,14 +104,14 @@ validate_struct(tOptions * opts, char const * pname)
char const ** pp = char const ** pp =
(char const **)(void **)&(opts->pzProgName); (char const **)(void **)&(opts->pzProgName);
if (pz != NULL) { if (pz != NULL)
*pp = pz+1; *pp = pz+1;
} else { else
*pp = pname; *pp = pname;
pz = pathfind(getenv("PATH"), (char *)pname, "rx");
if (pz != NULL) pz = pathfind(getenv("PATH"), (char *)pname, "rx");
pname = (void *)pz; if (pz != NULL)
} pname = (void *)pz;
pp = (char const **)(void **)&(opts->pzProgPath); pp = (char const **)(void **)&(opts->pzProgPath);
*pp = pname; *pp = pname;
+214 -157
View File
@@ -33,24 +33,71 @@
/* = = = START-STATIC-FORWARD = = = */ /* = = = START-STATIC-FORWARD = = = */
static bool static bool
add_prog_path(char * pzBuf, int b_sz, char const * pzName, get_realpath(char * buf, size_t b_sz);
char const * pzProgPath);
static bool
add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path);
static bool static bool
add_env_val(char * buf, int buf_sz, char const * name); add_env_val(char * buf, int buf_sz, char const * name);
static char * static char *
assemble_arg_val(char * txt, tOptionLoadMode mode); assemble_arg_val(char * txt, tOptionLoadMode mode);
static char *
trim_quotes(char * arg);
static bool
direction_ok(opt_state_mask_t f, int dir);
/* = = = END-STATIC-FORWARD = = = */ /* = = = END-STATIC-FORWARD = = = */
static bool
get_realpath(char * buf, size_t b_sz)
{
#if defined(HAVE_CANONICALIZE_FILE_NAME)
{
size_t name_len;
char * pz = canonicalize_file_name(buf);
if (pz == NULL)
return false;
name_len = strlen(pz);
if (name_len >= (size_t)b_sz) {
free(pz);
return false;
}
memcpy(buf, pz, name_len + 1);
free(pz);
}
#elif defined(HAVE_REALPATH)
{
size_t name_len;
char z[PATH_MAX+1];
if (realpath(buf, z) == NULL)
return false;
name_len = strlen(z);
if (name_len >= b_sz)
return false;
memcpy(buf, z, name_len + 1);
}
#endif
return true;
}
/*=export_func optionMakePath /*=export_func optionMakePath
* private: * private:
* *
* what: translate and construct a path * what: translate and construct a path
* arg: + char* + pzBuf + The result buffer + * arg: + char* + p_buf + The result buffer +
* arg: + int + bufSize + The size of this buffer + * arg: + int + b_sz + The size of this buffer +
* arg: + char const* + pzName + The input name + * arg: + char const* + fname + The input name +
* arg: + char const* + pzProgPath + The full path of the current program + * arg: + char const* + prg_path + The full path of the current program +
* *
* ret-type: bool * ret-type: bool
* ret-desc: true if the name was handled, otherwise false. * ret-desc: true if the name was handled, otherwise false.
@@ -95,24 +142,25 @@ assemble_arg_val(char * txt, tOptionLoadMode mode);
* errors (cannot resolve the resulting path). * errors (cannot resolve the resulting path).
=*/ =*/
bool bool
optionMakePath(char * pzBuf, int b_sz, char const * pzName, optionMakePath(char * p_buf, int b_sz, char const * fname, char const * prg_path)
char const * pzProgPath)
{ {
size_t name_len = strlen(pzName); {
size_t len = strlen(fname);
if (((size_t)b_sz <= name_len) || (name_len == 0)) if (((size_t)b_sz <= len) || (len == 0))
return false; return false;
}
/* /*
* IF not an environment variable, just copy the data * IF not an environment variable, just copy the data
*/ */
if (*pzName != '$') { if (*fname != '$') {
char const* pzS = pzName; char const * src = fname;
char* pzD = pzBuf; char * dst = p_buf;
int ct = b_sz; int ct = b_sz;
for (;;) { for (;;) {
if ( (*(pzD++) = *(pzS++)) == NUL) if ( (*(dst++) = *(src++)) == NUL)
break; break;
if (--ct <= 0) if (--ct <= 0)
return false; return false;
@@ -124,12 +172,12 @@ optionMakePath(char * pzBuf, int b_sz, char const * pzName,
* it must start with "$$/". In either event, replace the "$$" * it must start with "$$/". In either event, replace the "$$"
* with the path to the executable and append a "/" character. * with the path to the executable and append a "/" character.
*/ */
else switch (pzName[1]) { else switch (fname[1]) {
case NUL: case NUL:
return false; return false;
case '$': case '$':
if (! add_prog_path(pzBuf, b_sz, pzName, pzProgPath)) if (! add_prog_path(p_buf, b_sz, fname, prg_path))
return false; return false;
break; break;
@@ -137,59 +185,30 @@ optionMakePath(char * pzBuf, int b_sz, char const * pzName,
if (program_pkgdatadir[0] == NUL) if (program_pkgdatadir[0] == NUL)
return false; return false;
if (snprintf(pzBuf, (size_t)b_sz, "%s%s", if (snprintf(p_buf, (size_t)b_sz, "%s%s",
program_pkgdatadir, pzName + 2) >= b_sz) program_pkgdatadir, fname + 2) >= b_sz)
return false; return false;
break; break;
default: default:
if (! add_env_val(pzBuf, b_sz, pzName)) if (! add_env_val(p_buf, b_sz, fname))
return false; return false;
} }
#if defined(HAVE_CANONICALIZE_FILE_NAME) return get_realpath(p_buf, b_sz);
{
char * pz = canonicalize_file_name(pzBuf);
if (pz == NULL)
return false;
name_len = strlen(pz);
if (name_len >= (size_t)b_sz) {
free(pz);
return false;
}
memcpy(pzBuf, pz, name_len + 1);
free(pz);
}
#elif defined(HAVE_REALPATH)
{
char z[PATH_MAX+1];
if (realpath(pzBuf, z) == NULL)
return false;
name_len = strlen(z);
if (name_len >= b_sz)
return false;
memcpy(pzBuf, z, name_len + 1);
}
#endif
return true;
} }
/**
* convert a leading "$$" into a path to the executable.
*/
static bool static bool
add_prog_path(char * pzBuf, int b_sz, char const * pzName, add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path)
char const * pzProgPath)
{ {
char const* pzPath; char const * path;
char const* pz; char const * pz;
int skip = 2; int skip = 2;
switch (pzName[2]) { switch (fname[2]) {
case DIRCH: case DIRCH:
skip = 3; skip = 3;
case NUL: case NUL:
@@ -203,16 +222,16 @@ add_prog_path(char * pzBuf, int b_sz, char const * pzName,
* If it is, we're done. Otherwise, we have to hunt * If it is, we're done. Otherwise, we have to hunt
* for the program using "pathfind". * for the program using "pathfind".
*/ */
if (strchr(pzProgPath, DIRCH) != NULL) if (strchr(prg_path, DIRCH) != NULL)
pzPath = pzProgPath; path = prg_path;
else { else {
pzPath = pathfind(getenv("PATH"), (char*)pzProgPath, "rx"); path = pathfind(getenv("PATH"), (char*)prg_path, "rx");
if (pzPath == NULL) if (path == NULL)
return false; return false;
} }
pz = strrchr(pzPath, DIRCH); pz = strrchr(path, DIRCH);
/* /*
* IF we cannot find a directory name separator, * IF we cannot find a directory name separator,
@@ -221,27 +240,30 @@ add_prog_path(char * pzBuf, int b_sz, char const * pzName,
if (pz == NULL) if (pz == NULL)
return false; return false;
pzName += skip; fname += skip;
/* /*
* Concatenate the file name to the end of the executable path. * Concatenate the file name to the end of the executable path.
* The result may be either a file or a directory. * The result may be either a file or a directory.
*/ */
if ((unsigned)(pz - pzPath) + 1 + strlen(pzName) >= (unsigned)b_sz) if ((unsigned)(pz - path) + 1 + strlen(fname) >= (unsigned)b_sz)
return false; return false;
memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1)); memcpy(buf, path, (size_t)((pz - path)+1));
strcpy(pzBuf + (pz - pzPath) + 1, pzName); strcpy(buf + (pz - path) + 1, fname);
/* /*
* If the "pzPath" path was gotten from "pathfind()", then it was * If the "path" path was gotten from "pathfind()", then it was
* allocated and we need to deallocate it. * allocated and we need to deallocate it.
*/ */
if (pzPath != pzProgPath) if (path != prg_path)
AGFREE(pzPath); AGFREE(path);
return true; return true;
} }
/**
* Add an environment variable value.
*/
static bool static bool
add_env_val(char * buf, int buf_sz, char const * name) add_env_val(char * buf, int buf_sz, char const * name)
{ {
@@ -291,9 +313,9 @@ munge_str(char * txt, tOptionLoadMode mode)
return; return;
if (IS_WHITESPACE_CHAR(*txt)) { if (IS_WHITESPACE_CHAR(*txt)) {
char * pzS = SPN_WHITESPACE_CHARS(txt+1); char * src = SPN_WHITESPACE_CHARS(txt+1);
size_t l = strlen(pzS) + 1; size_t l = strlen(src) + 1;
memmove(txt, pzS, l); memmove(txt, src, l);
pzE = txt + l - 1; pzE = txt + l - 1;
} else } else
@@ -323,13 +345,13 @@ munge_str(char * txt, tOptionLoadMode mode)
static char * static char *
assemble_arg_val(char * txt, tOptionLoadMode mode) assemble_arg_val(char * txt, tOptionLoadMode mode)
{ {
char* pzEnd = strpbrk(txt, ARG_BREAK_STR); char * end = strpbrk(txt, ARG_BREAK_STR);
int space_break; int space_break;
/* /*
* Not having an argument to a configurable name is okay. * Not having an argument to a configurable name is okay.
*/ */
if (pzEnd == NULL) if (end == NULL)
return txt + strlen(txt); return txt + strlen(txt);
/* /*
@@ -338,8 +360,8 @@ assemble_arg_val(char * txt, tOptionLoadMode mode)
* of which character caused it. * of which character caused it.
*/ */
if (mode == OPTION_LOAD_KEEP) { if (mode == OPTION_LOAD_KEEP) {
*(pzEnd++) = NUL; *(end++) = NUL;
return pzEnd; return end;
} }
/* /*
@@ -347,14 +369,99 @@ assemble_arg_val(char * txt, tOptionLoadMode mode)
* because we'll have to skip over an immediately following ':' or '=' * because we'll have to skip over an immediately following ':' or '='
* (and the white space following *that*). * (and the white space following *that*).
*/ */
space_break = IS_WHITESPACE_CHAR(*pzEnd); space_break = IS_WHITESPACE_CHAR(*end);
*(pzEnd++) = NUL; *(end++) = NUL;
pzEnd = SPN_WHITESPACE_CHARS(pzEnd); end = SPN_WHITESPACE_CHARS(end);
if (space_break && ((*pzEnd == ':') || (*pzEnd == '='))) if (space_break && ((*end == ':') || (*end == '=')))
pzEnd = SPN_WHITESPACE_CHARS(pzEnd+1); end = SPN_WHITESPACE_CHARS(end+1);
return pzEnd; return end;
}
static char *
trim_quotes(char * arg)
{
switch (*arg) {
case '"':
case '\'':
ao_string_cook(arg, NULL);
}
return arg;
}
/**
* See if the option is to be processed in the current scan direction
* (-1 or +1).
*/
static bool
direction_ok(opt_state_mask_t f, int dir)
{
if (dir == 0)
return true;
switch (f & (OPTST_IMM|OPTST_DISABLE_IMM)) {
case 0:
/*
* The selected option has no immediate action.
* THEREFORE, if the direction is PRESETTING
* THEN we skip this option.
*/
if (PRESETTING(dir))
return false;
break;
case OPTST_IMM:
if (PRESETTING(dir)) {
/*
* We are in the presetting direction with an option we handle
* immediately for enablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((f & OPTST_DISABLED) == 0)
return false;
} else {
/*
* We are in the processing direction with an option we handle
* immediately for enablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((f & OPTST_DISABLED) != 0)
return false;
}
break;
case OPTST_DISABLE_IMM:
if (PRESETTING(dir)) {
/*
* We are in the presetting direction with an option we handle
* immediately for disablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((f & OPTST_DISABLED) != 0)
return false;
} else {
/*
* We are in the processing direction with an option we handle
* immediately for disablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((f & OPTST_DISABLED) == 0)
return false;
}
break;
case OPTST_IMM|OPTST_DISABLE_IMM:
/*
* The selected option is always for immediate action.
* THEREFORE, if the direction is PROCESSING
* THEN we skip this option.
*/
if (PROCESSING(dir))
return false;
break;
}
return true;
} }
/** /**
@@ -370,88 +477,35 @@ assemble_arg_val(char * txt, tOptionLoadMode mode)
* @param[in] load_mode option loading mode (OPTION_LOAD_*) * @param[in] load_mode option loading mode (OPTION_LOAD_*)
*/ */
LOCAL void LOCAL void
loadOptionLine( load_opt_line(tOptions * opts, tOptState * opt_state, char * line,
tOptions * opts, tDirection direction, tOptionLoadMode load_mode )
tOptState * opt_state,
char * line,
tDirection direction,
tOptionLoadMode load_mode )
{ {
/*
* When parsing a stored line, we only look at the characters after
* a hyphen. Long names must always be at least two characters and
* short options are always exactly one character long.
*/
line = SPN_LOAD_LINE_SKIP_CHARS(line); line = SPN_LOAD_LINE_SKIP_CHARS(line);
{ {
char * arg = assemble_arg_val(line, load_mode); char * arg = assemble_arg_val(line, load_mode);
if (! SUCCESSFUL(opt_find_long(opts, line, opt_state))) if (IS_OPTION_NAME_CHAR(line[1])) {
if (! SUCCESSFUL(opt_find_long(opts, line, opt_state)))
return;
} else if (! SUCCESSFUL(opt_find_short(opts, *line, opt_state)))
return; return;
if (opt_state->flags & OPTST_NO_INIT) if ((! CALLED(direction)) && (opt_state->flags & OPTST_NO_INIT))
return; return;
opt_state->pzOptArg = arg; opt_state->pzOptArg = trim_quotes(arg);
} }
switch (opt_state->flags & (OPTST_IMM|OPTST_DISABLE_IMM)) { if (! direction_ok(opt_state->flags, direction))
case 0: return;
/*
* The selected option has no immediate action.
* THEREFORE, if the direction is PRESETTING
* THEN we skip this option.
*/
if (PRESETTING(direction))
return;
break;
case OPTST_IMM:
if (PRESETTING(direction)) {
/*
* We are in the presetting direction with an option we handle
* immediately for enablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((opt_state->flags & OPTST_DISABLED) == 0)
return;
} else {
/*
* We are in the processing direction with an option we handle
* immediately for enablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((opt_state->flags & OPTST_DISABLED) != 0)
return;
}
break;
case OPTST_DISABLE_IMM:
if (PRESETTING(direction)) {
/*
* We are in the presetting direction with an option we handle
* immediately for disablement, but normally for disablement.
* Therefore, skip if NOT disabled.
*/
if ((opt_state->flags & OPTST_DISABLED) != 0)
return;
} else {
/*
* We are in the processing direction with an option we handle
* immediately for disablement, but normally for disablement.
* Therefore, skip if disabled.
*/
if ((opt_state->flags & OPTST_DISABLED) == 0)
return;
}
break;
case OPTST_IMM|OPTST_DISABLE_IMM:
/*
* The selected option is always for immediate action.
* THEREFORE, if the direction is PROCESSING
* THEN we skip this option.
*/
if (PROCESSING(direction))
return;
break;
}
/* /*
* Fix up the args. * Fix up the args.
@@ -516,10 +570,13 @@ void
optionLoadLine(tOptions * opts, char const * line) optionLoadLine(tOptions * opts, char const * line)
{ {
tOptState st = OPTSTATE_INITIALIZER(SET); tOptState st = OPTSTATE_INITIALIZER(SET);
char* pz; char * pz;
AGDUPSTR(pz, line, "user option line"); proc_state_mask_t sv_flags = opts->fOptSet;
loadOptionLine(opts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED); opts->fOptSet &= ~OPTPROC_ERRSTOP;
AGDUPSTR(pz, line, "opt line");
load_opt_line(opts, &st, pz, DIRECTION_CALLED, OPTION_LOAD_COOKED);
AGFREE(pz); AGFREE(pz);
opts->fOptSet = sv_flags;
} }
/** @} /** @}
* *
+10 -12
View File
@@ -2,7 +2,7 @@ dnl -*- buffer-read-only: t -*- vi: set ro:
dnl dnl
dnl DO NOT EDIT THIS FILE (libopts.m4) dnl DO NOT EDIT THIS FILE (libopts.m4)
dnl dnl
dnl It has been AutoGen-ed March 31, 2013 at 10:41:19 AM by AutoGen 5.17.3 dnl It has been AutoGen-ed July 14, 2013 at 05:37:02 PM by AutoGen 5.18
dnl From the definitions libopts.def dnl From the definitions libopts.def
dnl and the template file conftest.tpl dnl and the template file conftest.tpl
dnl dnl
@@ -72,8 +72,7 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
${lo_have_typ_hdr} || \ ${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_param sys_stat \ for f in sys_types sys_param sys_stat string errno stdlib memory setjmp
string errno stdlib memory setjmp
do eval as_ac_var=\${ac_cv_header_${f}_h} do eval as_ac_var=\${ac_cv_header_${f}_h}
test "X${as_ac_var}" = Xyes || { test "X${as_ac_var}" = Xyes || {
]AC_MSG_ERROR([you must have ${f}.h on your system])[ ]AC_MSG_ERROR([you must have ${f}.h on your system])[
@@ -102,10 +101,11 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
AC_CHECK_SIZEOF(long, 8) AC_CHECK_SIZEOF(long, 8)
AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(short, 2)
# ---------------------------------------------------------------------- # ------------
# AC_CHECK_LIB for SVR4 libgen, and use it if it defines pathfind. # AC_CHECK_LIB
# ---------------------------------------------------------------------- # ------------
AC_CHECK_LIB(gen, pathfind) AC_CHECK_LIB(gen, pathfind)
AC_CHECK_LIB(intl,gettext)
AC_FUNC_VPRINTF AC_FUNC_VPRINTF
AC_FUNC_FORK AC_FUNC_FORK
AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \ AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \
@@ -200,7 +200,6 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
esac esac
libopts_save_CPPFLAGS="${CPPFLAGS}" libopts_save_CPPFLAGS="${CPPFLAGS}"
libopts_save_LIBS="${LIBS}" libopts_save_LIBS="${LIBS}"
case "X${libopts_cv_with_libregex_cflags}" in case "X${libopts_cv_with_libregex_cflags}" in
Xyes|Xno|X ) Xyes|Xno|X )
libopts_cv_with_libregex_cflags="" ;; libopts_cv_with_libregex_cflags="" ;;
@@ -239,9 +238,8 @@ int main() {
[libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no], [libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no],
[libopts_cv_with_libregex=no]) # end of AC_RUN_IFELSE [libopts_cv_with_libregex=no]) # end of AC_RUN_IFELSE
]) # end of AC_CACHE_VAL for libopts_cv_with_libregex ]) # end of AC_CACHE_VAL for libopts_cv_with_libregex
AC_MSG_RESULT([${libopts_cv_with_libregex}])
fi ## disabled by request fi ## disabled by request
AC_MSG_RESULT([${libopts_cv_with_libregex}])
if test "X${libopts_cv_with_libregex}" != Xno if test "X${libopts_cv_with_libregex}" != Xno
then then
AC_DEFINE([WITH_LIBREGEX],[1], AC_DEFINE([WITH_LIBREGEX],[1],
@@ -250,9 +248,9 @@ int main() {
CPPFLAGS="${libopts_save_CPPFLAGS}" CPPFLAGS="${libopts_save_CPPFLAGS}"
LIBS="${libopts_save_LIBS}" LIBS="${libopts_save_LIBS}"
libopts_cv_with_libregex_root=no libopts_cv_with_libregex_root=no
libopts_cv_with_libregex_cflags=no libopts_cv_with_libregex_cflags=no
libopts_cv_with_libregex_libs=no libopts_cv_with_libregex_libs=no
AC_MSG_RESULT([the regex library does not work and will not be used]) libopts_cv_with_libregex=no
fi fi
]) # end of AC_DEFUN of LIBOPTS_WITHLIB_REGEX ]) # end of AC_DEFUN of LIBOPTS_WITHLIB_REGEX
+19 -11
View File
@@ -30,13 +30,6 @@
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/ */
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 = = = */ /* = = = START-STATIC-FORWARD = = = */
static void static void
emit_var_text(char const * prog, char const * var, int fdin); emit_var_text(char const * prog, char const * var, int fdin);
@@ -75,6 +68,21 @@ static void
open_out(char const * fname, char const * pname); open_out(char const * fname, char const * pname);
/* = = = END-STATIC-FORWARD = = = */ /* = = = END-STATIC-FORWARD = = = */
LOCAL void
option_exits(int exit_code)
{
if (print_exit)
printf("\nexit %d\n", exit_code);
exit(exit_code);
}
LOCAL void
ao_bug(char const * msg)
{
fprintf(stderr, zao_bug_msg, msg);
option_exits(EX_SOFTWARE);
}
LOCAL void LOCAL void
fserr_warn(char const * prog, char const * op, char const * fname) fserr_warn(char const * prog, char const * op, char const * fname)
{ {
@@ -86,7 +94,7 @@ LOCAL void
fserr_exit(char const * prog, char const * op, char const * fname) fserr_exit(char const * prog, char const * op, char const * fname)
{ {
fserr_warn(prog, op, fname); fserr_warn(prog, op, fname);
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
} }
/*=export_func optionParseShell /*=export_func optionParseShell
@@ -325,7 +333,7 @@ text_to_var(tOptions * opts, teTextTo which, tOptDesc * od)
/* NOTREACHED */ /* NOTREACHED */
default: default:
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
} }
/* NOTREACHED */ /* NOTREACHED */
@@ -862,7 +870,7 @@ genshelloptUsage(tOptions * opts, int exit_cd)
fflush(stderr); fflush(stderr);
fflush(stdout); fflush(stdout);
if (ferror(stdout) || ferror(stderr)) if (ferror(stdout) || ferror(stderr))
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
option_usage_fp = stdout; option_usage_fp = stdout;
@@ -929,7 +937,7 @@ genshelloptUsage(tOptions * opts, int exit_cd)
if (ferror(stdout)) if (ferror(stdout))
fserr_exit(opts->pzProgName, zwriting, zstdout_name); fserr_exit(opts->pzProgName, zwriting, zstdout_name);
exit(EXIT_SUCCESS); option_exits(EXIT_SUCCESS);
#endif #endif
} }
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (stdin.c) * 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 * It has been AutoGen-ed July 14, 2013 at 05:37:08 PM by AutoGen 5.18
* From the definitions stdin * From the definitions stdin
* and the template file str2enum * and the template file str2enum
* *
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (stdin.h) * 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 * It has been AutoGen-ed July 14, 2013 at 05:37:08 PM by AutoGen 5.18
* From the definitions stdin * From the definitions stdin
* and the template file str2enum * and the template file str2enum
* *
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (stdin.c) * 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 * It has been AutoGen-ed July 14, 2013 at 05:37:07 PM by AutoGen 5.18
* From the definitions stdin * From the definitions stdin
* and the template file str2enum * and the template file str2enum
* *
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (stdin.h) * 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 * It has been AutoGen-ed July 14, 2013 at 05:37:07 PM by AutoGen 5.18
* From the definitions stdin * From the definitions stdin
* and the template file str2enum * and the template file str2enum
* *
+80 -33
View File
@@ -32,12 +32,70 @@
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/ */
#if defined(HAVE_WORKING_FORK)
static FILE *
open_tmp_usage(char ** buf)
{
char * bf;
size_t bfsz;
{
unsigned int my_pid = (unsigned int)getpid();
char const * tmpdir = getenv(TMPDIR);
if (tmpdir == NULL)
tmpdir = tmp_dir;
bfsz = TMP_FILE_FMT_LEN + strlen(tmpdir) + 10;
bf = AGALOC(bfsz, "tmp fil");
snprintf(bf, bfsz, TMP_FILE_FMT, tmpdir, my_pid);
}
{
int fd = mkstemp(bf);
if (fd < 0) {
AGFREE(bf);
return NULL;
}
*buf = bf;
return fdopen(fd, "w");
}
}
static char *
mk_pager_cmd(char const * fname)
{
/*
* Page the file and remove it when done. For shell script processing,
* we must redirect the output to the current stderr, otherwise stdout.
*/
fclose(option_usage_fp);
option_usage_fp = NULL;
{
char const * pager = (char const *)getenv(PAGER_NAME);
size_t bfsz;
char * res;
/*
* Use the "more(1)" program if "PAGER" has not been defined
*/
if (pager == NULL)
pager = MORE_STR;
bfsz = strlen(fname) + strlen(pager) + PAGE_USAGE_FMT_LEN;
res = AGALOC(bfsz, "more cmd");
snprintf(res, bfsz, PAGE_USAGE_FMT, pager, fname);
AGFREE((void*)fname);
return res;
}
}
#endif
/*=export_func optionPagedUsage /*=export_func optionPagedUsage
* private: * private:
* *
* what: Decipher a boolean value * what: emit help text and pass through a pager program.
* arg: + tOptions* + opts + program options descriptor + * arg: + tOptions * + opts + program options descriptor +
* arg: + tOptDesc* + od + the descriptor for this arg + * arg: + tOptDesc * + od + the descriptor for this arg +
* *
* doc: * doc:
* Run the usage output through a pager. * Run the usage output through a pager.
@@ -53,8 +111,8 @@ optionPagedUsage(tOptions * opts, tOptDesc * od)
(*opts->pUsageProc)(opts, EXIT_SUCCESS); (*opts->pUsageProc)(opts, EXIT_SUCCESS);
#else #else
static pid_t my_pid; static bool sv_print_exit = false;
char fil_name[1024]; static char * fil_name = NULL;
/* /*
* IF we are being called after the usage proc is done * IF we are being called after the usage proc is done
@@ -66,20 +124,12 @@ optionPagedUsage(tOptions * opts, tOptDesc * od)
{ {
if ((od->fOptState & OPTST_RESET) != 0) if ((od->fOptState & OPTST_RESET) != 0)
return; return;
option_usage_fp = open_tmp_usage(&fil_name);
my_pid = getpid();
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(fil_name, "w" FOPEN_BINARY_FLAG);
if (option_usage_fp == NULL) if (option_usage_fp == NULL)
_exit(EXIT_FAILURE); (*opts->pUsageProc)(opts, EXIT_SUCCESS);
pagerState = PAGER_STATE_READY; pagerState = PAGER_STATE_READY;
sv_print_exit = print_exit;
/* /*
* Set up so this routine gets called during the exit logic * Set up so this routine gets called during the exit logic
@@ -88,8 +138,10 @@ optionPagedUsage(tOptions * opts, tOptDesc * od)
/* /*
* The usage procedure will now put the usage information into * The usage procedure will now put the usage information into
* the temporary file we created above. * the temporary file we created above. Keep any shell commands
* out of the result.
*/ */
print_exit = false;
(*opts->pUsageProc)(opts, EXIT_SUCCESS); (*opts->pUsageProc)(opts, EXIT_SUCCESS);
/* NOTREACHED */ /* NOTREACHED */
@@ -97,25 +149,20 @@ optionPagedUsage(tOptions * opts, tOptDesc * od)
} }
case PAGER_STATE_READY: case PAGER_STATE_READY:
{ fil_name = mk_pager_cmd(fil_name);
char const * pager = (char const *)getenv(PAGER_NAME);
/* if (sv_print_exit) {
* Use the "more(1)" program if "PAGER" has not been defined fputs("\nexit 0\n", stdout);
*/ fclose(stdout);
if (pager == NULL) dup2(STDERR_FILENO, STDOUT_FILENO);
pager = MORE_STR;
/* } else {
* Page the file and remove it when done. fclose(stderr);
*/ dup2(STDOUT_FILENO, STDERR_FILENO);
snprintf(fil_name, sizeof(fil_name), PAGE_USAGE_FMT, pager, }
(unsigned long)my_pid);
fclose(stderr);
dup2(STDOUT_FILENO, STDERR_FILENO);
ignore_val( system( fil_name)); ignore_val( system( fil_name));
} AGFREE(fil_name);
case PAGER_STATE_CHILD: case PAGER_STATE_CHILD:
/* /*
+9 -10
View File
@@ -1,7 +1,7 @@
/* -*- buffer-read-only: t -*- vi: set ro: /* -*- buffer-read-only: t -*- vi: set ro:
* *
* Prototypes for autoopts * Prototypes for autoopts
* Generated Sun Mar 31 10:41:38 PDT 2013 * Generated Sun Jul 14 17:37:20 PDT 2013
*/ */
#ifndef AUTOOPTS_PROTO_H_GUARD #ifndef AUTOOPTS_PROTO_H_GUARD
#define AUTOOPTS_PROTO_H_GUARD 1 #define AUTOOPTS_PROTO_H_GUARD 1
@@ -92,16 +92,18 @@ static void
munge_str(char * txt, tOptionLoadMode mode); munge_str(char * txt, tOptionLoadMode mode);
static void static void
loadOptionLine( load_opt_line(tOptions * opts, tOptState * opt_state, char * line,
tOptions * opts, tDirection direction, tOptionLoadMode load_mode );
tOptState * opt_state,
char * line,
tDirection direction,
tOptionLoadMode load_mode );
/* /*
* Extracted from makeshell.c * Extracted from makeshell.c
*/ */
static void
option_exits(int exit_code);
static void
ao_bug(char const * msg);
static void static void
fserr_warn(char const * prog, char const * op, char const * fname); fserr_warn(char const * prog, char const * op, char const * fname);
@@ -141,7 +143,4 @@ addArgListEntry(void** ppAL, void* entry);
static void static void
set_usage_flags(tOptions * opts, char const * flg_txt); set_usage_flags(tOptions * opts, char const * flg_txt);
static void
ao_bug(char const * msg);
#endif /* AUTOOPTS_PROTO_H_GUARD */ #endif /* AUTOOPTS_PROTO_H_GUARD */
+4 -9
View File
@@ -30,7 +30,6 @@
* 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
*/ */
#define APOSTROPHE '\''
/* = = = START-STATIC-FORWARD = = = */ /* = = = START-STATIC-FORWARD = = = */
static size_t static size_t
@@ -292,6 +291,7 @@ print_enumeration(tOptions * pOpts, tOptDesc * pOD)
static void static void
print_membership(tOptions * pOpts, tOptDesc * pOD) print_membership(tOptions * pOpts, tOptDesc * pOD)
{ {
char const * svstr = pOD->optArg.argString;
char const * pz; char const * pz;
uintptr_t val = 1; uintptr_t val = 1;
printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
@@ -299,13 +299,9 @@ print_membership(tOptions * pOpts, tOptDesc * pOD)
pOD->optCookie = (void*)(uintptr_t)~0UL; pOD->optCookie = (void*)(uintptr_t)~0UL;
(*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
/* pz = pOD->optArg.argString;
* We are building the typeset list. The list returned starts with
* 'none + ' for use by option saving stuff. We must ignore that.
*/
pz = pOD->optArg.argString + 7;
while (*pz != NUL) { while (*pz != NUL) {
printf("typeset -x -i %s_", pOD->pz_NAME); printf("readonly %s_", pOD->pz_NAME);
pz = SPN_PLUS_N_SPACE_CHARS(pz); pz = SPN_PLUS_N_SPACE_CHARS(pz);
for (;;) { for (;;) {
@@ -321,8 +317,7 @@ print_membership(tOptions * pOpts, tOptDesc * pOD)
} }
AGFREE(pOD->optArg.argString); AGFREE(pOD->optArg.argString);
pOD->optArg.argString = NULL; pOD->optArg.argString = svstr;
pOD->fOptState &= ~OPTST_ALLOC_ARG;
} }
static void static void
+1 -1
View File
@@ -141,7 +141,7 @@ optionRestore(tOptions* pOpts)
pzName = zNil; pzName = zNil;
} }
fprintf(stderr, zNoState, pzName); fprintf(stderr, zNoState, pzName);
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
} }
pOpts->pSavedState = NULL; pOpts->pSavedState = NULL;
+39 -41
View File
@@ -63,7 +63,7 @@ static void
prt_str_arg(FILE * fp, tOptDesc * pOD); prt_str_arg(FILE * fp, tOptDesc * pOD);
static void static void
prt_enum_arg(FILE * fp, tOptDesc * pOD); prt_enum_arg(FILE * fp, tOptDesc * od);
static void static void
prt_set_arg(FILE * fp, tOptDesc * od); prt_set_arg(FILE * fp, tOptDesc * od);
@@ -138,7 +138,7 @@ find_dir_name(tOptions * opts, int * p_free)
{ {
size_t sz = strlen(pzEnv) + strlen(pzEndDir) + 2; size_t sz = strlen(pzEnv) + strlen(pzEndDir) + 2;
pzFileName = (char*)AGALOC(sz, "dir name"); pzFileName = (char *)AGALOC(sz, "dir name");
} }
if (pzFileName == NULL) if (pzFileName == NULL)
@@ -277,6 +277,8 @@ find_file_name(tOptions * opts, int * p_free_name)
static void static void
prt_entry(FILE * fp, tOptDesc * od, char const * l_arg) prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
{ {
int space_ct;
/* /*
* There is an argument. Pad the name so values line up. * There is an argument. Pad the name so values line up.
* Not disabled *OR* this got equivalenced to another opt, * Not disabled *OR* this got equivalenced to another opt,
@@ -284,29 +286,29 @@ prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
* Otherwise, there must be a disablement name. * Otherwise, there must be a disablement name.
*/ */
{ {
char const * pz; char const * pz =
if (! DISABLED_OPT(od) || (od->optEquivIndex != NO_EQUIVALENT)) (! DISABLED_OPT(od) || (od->optEquivIndex != NO_EQUIVALENT))
pz = od->pz_Name; ? od->pz_Name
else : od->pz_DisableName;
pz = od->pz_DisableName; space_ct = 17 - strlen(pz);
fputs(pz, fp);
fprintf(fp, "%-18s", pz);
} }
if ( (l_arg == NULL)
&& (OPTST_GET_ARGTYPE(od->fOptState) != OPARG_TYPE_NUMERIC))
goto end_entry;
fputs(" = ", fp);
while (space_ct-- > 0) fputc(' ', fp);
/* /*
* IF the option is numeric only, * IF the option is numeric only,
* THEN the char pointer is really the number * THEN the char pointer is really the number
*/ */
if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NUMERIC) if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NUMERIC)
fprintf(fp, " %d\n", (int)(t_word)l_arg); fprintf(fp, "%d", (int)(t_word)l_arg);
/*
* OTHERWISE, FOR each line of the value text, ...
*/
else if (l_arg == NULL)
fputc(NL, fp);
else { else {
fputc(' ', fp); fputc(' ', fp);
for (;;) { for (;;) {
char const * eol = strchr(l_arg, NL); char const * eol = strchr(l_arg, NL);
@@ -329,8 +331,10 @@ prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
* Terminate the entry * Terminate the entry
*/ */
fputs(l_arg, fp); fputs(l_arg, fp);
fputc(NL, fp);
} }
end_entry:
fputc(NL, fp);
} }
/** /**
@@ -610,20 +614,24 @@ prt_str_arg(FILE * fp, tOptDesc * pOD)
} }
/** /**
* print the string value of an enumeration.
*
* @param[in] fp the file pointer to write to
* @param[in] od the option descriptor with the enumerated value
*/ */
static void static void
prt_enum_arg(FILE * fp, tOptDesc * pOD) prt_enum_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 * This is a magic incantation that will convert the
* bit flag values back into a string suitable for printing. * bit flag values back into a string suitable for printing.
*/ */
(*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); (*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od);
prt_entry(fp, pOD, (void*)(pOD->optArg.argString)); prt_entry(fp, od, (void*)(od->optArg.argString));
pOD->optArg.argEnum = val; od->optArg.argEnum = val;
} }
/** /**
@@ -638,24 +646,14 @@ prt_enum_arg(FILE * fp, tOptDesc * pOD)
static void static void
prt_set_arg(FILE * fp, tOptDesc * od) prt_set_arg(FILE * fp, tOptDesc * od)
{ {
uintptr_t val = od->optArg.argEnum; char * list = optionMemberList(od);
size_t len = strlen(list);
/* char * buf = (char *)AGALOC(len + 3, "dir name");
* This is a magic incantation that will convert the *buf= '=';
* bit flag values back into a string suitable for printing. memcpy(buf+1, list, len + 1);
*/ prt_entry(fp, od, buf);
(*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od); AGFREE(buf);
prt_entry(fp, od, (void*)(od->optArg.argString)); AGFREE(list);
if (od->optArg.argString != NULL) {
/*
* set membership strings get allocated
*/
AGFREE((void*)od->optArg.argString);
od->fOptState &= ~OPTST_ALLOC_ARG;
}
od->optArg.argEnum = val;
} }
/** /**
+2 -2
View File
@@ -133,8 +133,8 @@ optionUnstackArg(tOptions * pOpts, tOptDesc * pOptDesc)
* we are keeping a define. * we are keeping a define.
*/ */
for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) { for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) {
const char ** pzSrc = pAL->apzArgs[ i ]; const char * pzSrc = pAL->apzArgs[ i ];
char * pzEq = strchr(pzSrc, '='); char * pzEq = strchr(pzSrc, '=');
if (pzEq != NULL) if (pzEq != NULL)
*pzEq = NUL; *pzEq = NUL;
+1 -1
View File
@@ -233,7 +233,7 @@ close_mmap_files(tmap_info_t * mi)
close(mi->txt_fd); close(mi->txt_fd);
mi->txt_fd = AO_INVALID_FD; mi->txt_fd = AO_INVALID_FD;
#if ! defined(MAP_ANONYMOUS) #if defined(HAVE_MMAP) && ! defined(MAP_ANONYMOUS)
if (mi->txt_zero_fd == AO_INVALID_FD) if (mi->txt_zero_fd == AO_INVALID_FD)
return; return;
+34 -62
View File
@@ -37,36 +37,6 @@
* 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd * 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 = = = */ /* = = = START-STATIC-FORWARD = = = */
static unsigned int static unsigned int
parse_usage_flags(ao_flag_names_t const * fnt, char const * txt); parse_usage_flags(ao_flag_names_t const * fnt, char const * txt);
@@ -100,8 +70,8 @@ static void
prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title); prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title);
static void static void
prt_ini_list(char const * const * papz, bool * need_intro, prt_ini_list(char const * const * papz, char const * ini_file,
char const * ini_file, char const * path_nm); char const * path_nm);
static void static void
prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at); prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at);
@@ -304,13 +274,6 @@ optionOnlyUsage(tOptions * pOpts, int ex_code)
? zstderr_name : zstdout_name); ? 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. * Print a message suggesting how to get help.
* *
@@ -626,7 +589,8 @@ optionUsage(tOptions * opts, int usage_exit_code)
? opts->pzFullUsage : NULL; ? opts->pzFullUsage : NULL;
if (option_usage_fp == NULL) if (option_usage_fp == NULL)
option_usage_fp = stdout; option_usage_fp = print_exit ? stderr : stdout;
} else { } else {
pz = (opts->structVersion >= 30 * 4096) pz = (opts->structVersion >= 30 * 4096)
? opts->pzShortUsage : NULL; ? opts->pzShortUsage : NULL;
@@ -659,7 +623,7 @@ optionUsage(tOptions * opts, int usage_exit_code)
fserr_exit(opts->pzProgName, zwriting, (option_usage_fp == stdout) fserr_exit(opts->pzProgName, zwriting, (option_usage_fp == stdout)
? zstdout_name : zstderr_name); ? zstdout_name : zstderr_name);
exit(exit_code); option_exits(exit_code);
} }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -959,24 +923,24 @@ prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title)
fputs(zDefaultOpt + tab_skip_ct, option_usage_fp); fputs(zDefaultOpt + tab_skip_ct, option_usage_fp);
} }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Figure out where all the initialization files might live. This requires
* translating some environment variables and testing to see if a name is a
* directory or a file. It's squishy, but important to tell users how to
* find these files.
* *
* Figure out where all the initialization files might live. * @param[in] papz search path
* This requires translating some environment variables and * @param[out] ini_file an output buffer of AG_PATH_MAX+1 bytes
* testing to see if a name is a directory or a file. It's * @param[in] path_nm the name of the file we're hunting for
* squishy, but important to tell users how to find these files.
*/ */
static void static void
prt_ini_list(char const * const * papz, bool * need_intro, prt_ini_list(char const * const * papz, char const * ini_file,
char const * ini_file, char const * path_nm) char const * path_nm)
{ {
char pth_buf[AG_PATH_MAX+1]; char pth_buf[AG_PATH_MAX+1];
if (papz == NULL)
return;
fputs(zPresetIntro, option_usage_fp); fputs(zPresetIntro, option_usage_fp);
*need_intro = false;
for (;;) { for (;;) {
char const * path = *(papz++); char const * path = *(papz++);
@@ -1021,7 +985,13 @@ prt_ini_list(char const * const * papz, bool * need_intro,
} }
} }
/**
* Print the usage line preamble text
*
* @param opts the program option descriptor
* @param od the option descriptor
* @param at names of the option argument types
*/
static void static void
prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at) prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at)
{ {
@@ -1108,10 +1078,10 @@ prt_one_usage(tOptions * opts, tOptDesc * od, arg_types_t * at)
bogus_desc: bogus_desc:
fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name); fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name);
exit(EX_SOFTWARE); option_exits(EX_SOFTWARE);
} }
/* /**
* Print out the usage information for just the options. * Print out the usage information for just the options.
*/ */
static void static void
@@ -1196,20 +1166,22 @@ prt_opt_usage(tOptions * opts, int ex_code, char const * title)
} }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* /**
* PROGRAM DETAILS * Print program details.
* @param[in] opts the program option descriptor
*/ */
static void static void
prt_prog_detail(tOptions * opts) prt_prog_detail(tOptions * opts)
{ {
bool need_intro = true; bool need_intro = (opts->papzHomeList == NULL);
/* /*
* Display all the places we look for config files * Display all the places we look for config files, if we have
* a list of directories to search.
*/ */
prt_ini_list(opts->papzHomeList, &need_intro, if (! need_intro)
opts->pzRcName, opts->pzProgPath); prt_ini_list(opts->papzHomeList, opts->pzRcName, opts->pzProgPath);
/* /*
* Let the user know about environment variable settings * Let the user know about environment variable settings
+3 -3
View File
@@ -166,7 +166,7 @@ print_ver(tOptions * opts, tOptDesc * od, FILE * fp)
default: default:
fprintf(stderr, zBadVerArg, ch); fprintf(stderr, zBadVerArg, ch);
exit(EXIT_FAILURE); option_exits(EXIT_FAILURE);
} }
fflush(fp); fflush(fp);
@@ -174,7 +174,7 @@ print_ver(tOptions * opts, tOptDesc * od, FILE * fp)
fserr_exit(opts->pzProgName, zwriting, fserr_exit(opts->pzProgName, zwriting,
(fp == stdout) ? zstdout_name : zstderr_name); (fp == stdout) ? zstdout_name : zstderr_name);
exit(EXIT_SUCCESS); option_exits(EXIT_SUCCESS);
} }
/*=export_func optionPrintVersion /*=export_func optionPrintVersion
@@ -190,7 +190,7 @@ print_ver(tOptions * opts, tOptDesc * od, FILE * fp)
void void
optionPrintVersion(tOptions * opts, tOptDesc * od) optionPrintVersion(tOptions * opts, tOptDesc * od)
{ {
print_ver(opts, od, stdout); print_ver(opts, od, print_exit ? stderr : stdout);
} }
/*=export_func optionVersionStderr /*=export_func optionVersionStderr