Previous: Parsing with an Executable, Up: AutoOpts for Shell Scripts [Contents][Index]
If you had used test-main = optionParseShell
instead, then you can,
at this point, merely run the program and it will write the parsing
script to standard out. You may also provide this program with command
line options to specify the shell script file to create or edit, and you
may specify the shell program to use on the first shell script line.
That program’s usage text would look something like the following
and the script parser itself would be very verbose:
genshellopt - Generate Shell Option Processing Script - Ver. 1 Usage: genshellopt [ -<flag> [<val>] | --<name>[{=| }<val>] ]... Flg Arg Option-Name Description -o Str script Output Script File -s Str shell Shell name (follows "#!" magic) - disabled as '--no-shell' - enabled by default -v opt version output version information and exit -? no help display extended usage information and exit -! no more-help extended usage information passed thru pager Options are specified by doubled hyphens and their name or by a single hyphen and the flag character. Note that 'shell' is only useful if the output file does not already exist. If it does, then the shell name and optional first argument will be extracted from the script file. If the script file already exists and contains Automated Option Processing text, the second line of the file through the ending tag will be replaced by the newly generated text. The first '#!' line will be regenerated. Please send bug reports to: <autogen-users@lists.sourceforge.net> = = = = = = = = This incarnation of genshell will produce a shell script to parse the options for getdefs: getdefs (GNU AutoGen) - AutoGen Definition Extraction Tool - Ver. 1.5 Usage: getdefs [ <option-name>[{=| }<val>] ]... Arg Option-Name Description Str defs-to-get Regexp to look for after the "/*=" Str subblock subblock definition names Str listattr attribute with list of values opt ordering Alphabetize or use named file Num first-index The first index to apply to groups opt filelist Insert source file names into defs Str assign Global assignments Str common-assign Assignments common to all blocks Str copy File(s) to copy into definitions opt srcfile Insert source file name into each def opt linenum Insert source line number into each def Str input Input file to search for defs Str output Output file to open opt autogen Invoke AutoGen with defs Str template Template Name Str agarg AutoGen Argument Str base-name Base name for output file(s)
Resulting in the following script:
#! /bin/sh # # # # # # # # # # -- do not modify this marker -- # # DO NOT EDIT THIS SECTION OF /u/bkorb/tools/ag/autogen-bld/doc/ag-texi-32340.d/.ag-5GQlKL/genshellopt.sh # # From here to the next `-- do not modify this marker --', # the text has been generated Sunday August 26, 2018 at 10:46:02 AM PDT # From the GETDEFS option definitions # GETDEFS_LONGUSAGE_TEXT='getdefs error: invalid option descriptor for version getdefs (GNU AutoGen) - AutoGen Definition Extraction Tool - Ver. 1.5 Usage: getdefs [ <option-name>[{=| }<val>] ]... Specify which definitions are of interest and what to say about them: Arg Option-Name Description Str defs-to-get Regexp to look for after the "/*=" Str subblock subblock definition names - may appear multiple times Str listattr attribute with list of values - may appear multiple times specify how to number the definitions: Arg Option-Name Description opt ordering Alphabetize or use named file - disabled as '\''--no-ordering'\'' - enabled by default Num first-index The first index to apply to groups Definition insertion options: Arg Option-Name Description opt filelist Insert source file names into defs Str assign Global assignments - may appear multiple times Str common-assign Assignments common to all blocks - may appear multiple times Str copy File(s) to copy into definitions - may appear multiple times opt srcfile Insert source file name into each def opt linenum Insert source line number into each def specify which files to search for markers: Arg Option-Name Description Str input Input file to search for defs - may appear multiple times - default option for unnamed options Definition output disposition options:: Arg Option-Name Description Str output Output file to open - an alternate for '\''autogen'\'' opt autogen Invoke AutoGen with defs - disabled as '\''--no-autogen'\'' - enabled by default Str template Template Name Str agarg AutoGen Argument - prohibits the option '\''output'\'' - may appear multiple times Str base-name Base name for output file(s) - prohibits the option '\''output'\'' Version, usage and configuration options: Arg Option-Name Description ' GETDEFS_USAGE_TEXT='getdefs (GNU AutoGen) - AutoGen Definition Extraction Tool - Ver. 1.5 Usage: getdefs [ <option-name>[{=| }<val>] ]... Arg Option-Name Description Str defs-to-get Regexp to look for after the "/*=" Str subblock subblock definition names Str listattr attribute with list of values opt ordering Alphabetize or use named file Num first-index The first index to apply to groups opt filelist Insert source file names into defs Str assign Global assignments Str common-assign Assignments common to all blocks Str copy File(s) to copy into definitions opt srcfile Insert source file name into each def opt linenum Insert source line number into each def Str input Input file to search for defs Str output Output file to open opt autogen Invoke AutoGen with defs Str template Template Name Str agarg AutoGen Argument Str base-name Base name for output file(s) getdefs error: invalid option descriptor for version' GETDEFS_DEFS_TO_GET=${GETDEFS_DEFS_TO_GET} GETDEFS_DEFS_TO_GET_set=false export GETDEFS_DEFS_TO_GET if test -z "${GETDEFS_SUBBLOCK}" then GETDEFS_SUBBLOCK_CT=0 export GETDEFS_SUBBLOCK_CT else GETDEFS_SUBBLOCK_CT=1 GETDEFS_SUBBLOCK_1=${GETDEFS_SUBBLOCK} export GETDEFS_SUBBLOCK_CT GETDEFS_SUBBLOCK_1 fi if test -z "${GETDEFS_LISTATTR}" then GETDEFS_LISTATTR_CT=0 export GETDEFS_LISTATTR_CT else GETDEFS_LISTATTR_CT=1 GETDEFS_LISTATTR_1=${GETDEFS_LISTATTR} export GETDEFS_LISTATTR_CT GETDEFS_LISTATTR_1 fi GETDEFS_ORDERING=${GETDEFS_ORDERING} GETDEFS_ORDERING_set=false export GETDEFS_ORDERING GETDEFS_FIRST_INDEX=${GETDEFS_FIRST_INDEX-'0'} GETDEFS_FIRST_INDEX_set=false export GETDEFS_FIRST_INDEX GETDEFS_FILELIST=${GETDEFS_FILELIST} GETDEFS_FILELIST_set=false export GETDEFS_FILELIST if test -z "${GETDEFS_ASSIGN}" then GETDEFS_ASSIGN_CT=0 export GETDEFS_ASSIGN_CT else GETDEFS_ASSIGN_CT=1 GETDEFS_ASSIGN_1=${GETDEFS_ASSIGN} export GETDEFS_ASSIGN_CT GETDEFS_ASSIGN_1 fi if test -z "${GETDEFS_COMMON_ASSIGN}" then GETDEFS_COMMON_ASSIGN_CT=0 export GETDEFS_COMMON_ASSIGN_CT else GETDEFS_COMMON_ASSIGN_CT=1 GETDEFS_COMMON_ASSIGN_1=${GETDEFS_COMMON_ASSIGN} export GETDEFS_COMMON_ASSIGN_CT GETDEFS_COMMON_ASSIGN_1 fi if test -z "${GETDEFS_COPY}" then GETDEFS_COPY_CT=0 export GETDEFS_COPY_CT else GETDEFS_COPY_CT=1 GETDEFS_COPY_1=${GETDEFS_COPY} export GETDEFS_COPY_CT GETDEFS_COPY_1 fi GETDEFS_SRCFILE=${GETDEFS_SRCFILE} GETDEFS_SRCFILE_set=false export GETDEFS_SRCFILE GETDEFS_LINENUM=${GETDEFS_LINENUM} GETDEFS_LINENUM_set=false export GETDEFS_LINENUM if test -z "${GETDEFS_INPUT}" then GETDEFS_INPUT_CT=0 export GETDEFS_INPUT_CT else GETDEFS_INPUT_CT=1 GETDEFS_INPUT_1=${GETDEFS_INPUT} export GETDEFS_INPUT_CT GETDEFS_INPUT_1 fi GETDEFS_OUTPUT=${GETDEFS_OUTPUT} GETDEFS_OUTPUT_set=false export GETDEFS_OUTPUT GETDEFS_AUTOGEN=${GETDEFS_AUTOGEN} GETDEFS_AUTOGEN_set=false export GETDEFS_AUTOGEN GETDEFS_TEMPLATE=${GETDEFS_TEMPLATE} GETDEFS_TEMPLATE_set=false export GETDEFS_TEMPLATE if test -z "${GETDEFS_AGARG}" then GETDEFS_AGARG_CT=0 export GETDEFS_AGARG_CT else GETDEFS_AGARG_CT=1 GETDEFS_AGARG_1=${GETDEFS_AGARG} export GETDEFS_AGARG_CT GETDEFS_AGARG_1 fi GETDEFS_BASE_NAME=${GETDEFS_BASE_NAME} GETDEFS_BASE_NAME_set=false export GETDEFS_BASE_NAME ARG_COUNT=$# OPT_ARG=$1 while [ $# -gt 0 ] do OPT_ELEMENT='' OPT_ARG_VAL='' OPT_ARG=${1} OPT_CODE=`echo "X${OPT_ARG}"|sed 's/^X-*//'` shift OPT_ARG=$1 case "${OPT_CODE}" in *=* ) OPT_ARG_VAL=`echo "${OPT_CODE}"|sed 's/^[^=]*=//'` OPT_CODE=`echo "${OPT_CODE}"|sed 's/=.*$//'` ;; esac case "${OPT_CODE}" in 'de' | \ 'def' | \ 'defs' | \ 'defs-' | \ 'defs-t' | \ 'defs-to' | \ 'defs-to-' | \ 'defs-to-g' | \ 'defs-to-ge' | \ 'defs-to-get' ) if [ -n "${GETDEFS_DEFS_TO_GET}" ] && ${GETDEFS_DEFS_TO_GET_set} ; then echo 'Error: duplicate DEFS_TO_GET option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_DEFS_TO_GET_set=true OPT_NAME='DEFS_TO_GET' OPT_ARG_NEEDED=YES ;; 'su' | \ 'sub' | \ 'subb' | \ 'subbl' | \ 'subblo' | \ 'subbloc' | \ 'subblock' ) GETDEFS_SUBBLOCK_CT=`expr ${GETDEFS_SUBBLOCK_CT} + 1` OPT_ELEMENT="_${GETDEFS_SUBBLOCK_CT}" OPT_NAME='SUBBLOCK' OPT_ARG_NEEDED=YES ;; 'li' | \ 'lis' | \ 'list' | \ 'lista' | \ 'listat' | \ 'listatt' | \ 'listattr' ) GETDEFS_LISTATTR_CT=`expr ${GETDEFS_LISTATTR_CT} + 1` OPT_ELEMENT="_${GETDEFS_LISTATTR_CT}" OPT_NAME='LISTATTR' OPT_ARG_NEEDED=YES ;; 'or' | \ 'ord' | \ 'orde' | \ 'order' | \ 'orderi' | \ 'orderin' | \ 'ordering' ) if [ -n "${GETDEFS_ORDERING}" ] && ${GETDEFS_ORDERING_set} ; then echo 'Error: duplicate ORDERING option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_ORDERING_set=true OPT_NAME='ORDERING' eval GETDEFS_ORDERING${OPT_ELEMENT}=true export GETDEFS_ORDERING${OPT_ELEMENT} OPT_ARG_NEEDED=OK ;; 'no-' | \ 'no-o' | \ 'no-or' | \ 'no-ord' | \ 'no-orde' | \ 'no-order' | \ 'no-orderi' | \ 'no-orderin' | \ 'no-ordering' ) if [ -n "${GETDEFS_ORDERING}" ] && ${GETDEFS_ORDERING_set} ; then echo 'Error: duplicate ORDERING option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_ORDERING_set=true GETDEFS_ORDERING='no' export GETDEFS_ORDERING OPT_NAME='ORDERING' OPT_ARG_NEEDED=NO ;; 'fi' | \ 'fir' | \ 'firs' | \ 'first' | \ 'first-' | \ 'first-i' | \ 'first-in' | \ 'first-ind' | \ 'first-inde' | \ 'first-index' ) if [ -n "${GETDEFS_FIRST_INDEX}" ] && ${GETDEFS_FIRST_INDEX_set} ; then echo 'Error: duplicate FIRST_INDEX option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_FIRST_INDEX_set=true OPT_NAME='FIRST_INDEX' OPT_ARG_NEEDED=YES ;; 'fi' | \ 'fil' | \ 'file' | \ 'filel' | \ 'fileli' | \ 'filelis' | \ 'filelist' ) if [ -n "${GETDEFS_FILELIST}" ] && ${GETDEFS_FILELIST_set} ; then echo 'Error: duplicate FILELIST option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_FILELIST_set=true OPT_NAME='FILELIST' eval GETDEFS_FILELIST${OPT_ELEMENT}=true export GETDEFS_FILELIST${OPT_ELEMENT} OPT_ARG_NEEDED=OK ;; 'as' | \ 'ass' | \ 'assi' | \ 'assig' | \ 'assign' ) GETDEFS_ASSIGN_CT=`expr ${GETDEFS_ASSIGN_CT} + 1` OPT_ELEMENT="_${GETDEFS_ASSIGN_CT}" OPT_NAME='ASSIGN' OPT_ARG_NEEDED=YES ;; 'co' | \ 'com' | \ 'comm' | \ 'commo' | \ 'common' | \ 'common-' | \ 'common-a' | \ 'common-as' | \ 'common-ass' | \ 'common-assi' | \ 'common-assig' | \ 'common-assign' ) GETDEFS_COMMON_ASSIGN_CT=`expr ${GETDEFS_COMMON_ASSIGN_CT} + 1` OPT_ELEMENT="_${GETDEFS_COMMON_ASSIGN_CT}" OPT_NAME='COMMON_ASSIGN' OPT_ARG_NEEDED=YES ;; 'co' | \ 'cop' | \ 'copy' ) GETDEFS_COPY_CT=`expr ${GETDEFS_COPY_CT} + 1` OPT_ELEMENT="_${GETDEFS_COPY_CT}" OPT_NAME='COPY' OPT_ARG_NEEDED=YES ;; 'sr' | \ 'src' | \ 'srcf' | \ 'srcfi' | \ 'srcfil' | \ 'srcfile' ) if [ -n "${GETDEFS_SRCFILE}" ] && ${GETDEFS_SRCFILE_set} ; then echo 'Error: duplicate SRCFILE option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_SRCFILE_set=true OPT_NAME='SRCFILE' eval GETDEFS_SRCFILE${OPT_ELEMENT}=true export GETDEFS_SRCFILE${OPT_ELEMENT} OPT_ARG_NEEDED=OK ;; 'li' | \ 'lin' | \ 'line' | \ 'linen' | \ 'linenu' | \ 'linenum' ) if [ -n "${GETDEFS_LINENUM}" ] && ${GETDEFS_LINENUM_set} ; then echo 'Error: duplicate LINENUM option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_LINENUM_set=true OPT_NAME='LINENUM' eval GETDEFS_LINENUM${OPT_ELEMENT}=true export GETDEFS_LINENUM${OPT_ELEMENT} OPT_ARG_NEEDED=OK ;; 'in' | \ 'inp' | \ 'inpu' | \ 'input' ) GETDEFS_INPUT_CT=`expr ${GETDEFS_INPUT_CT} + 1` OPT_ELEMENT="_${GETDEFS_INPUT_CT}" OPT_NAME='INPUT' OPT_ARG_NEEDED=YES ;; 'ou' | \ 'out' | \ 'outp' | \ 'outpu' | \ 'output' ) if [ -n "${GETDEFS_OUTPUT}" ] && ${GETDEFS_OUTPUT_set} ; then echo 'Error: duplicate OUTPUT option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_OUTPUT_set=true OPT_NAME='OUTPUT' OPT_ARG_NEEDED=YES ;; 'au' | \ 'aut' | \ 'auto' | \ 'autog' | \ 'autoge' | \ 'autogen' ) if [ -n "${GETDEFS_AUTOGEN}" ] && ${GETDEFS_AUTOGEN_set} ; then echo 'Error: duplicate AUTOGEN option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_AUTOGEN_set=true OPT_NAME='AUTOGEN' eval GETDEFS_AUTOGEN${OPT_ELEMENT}=true export GETDEFS_AUTOGEN${OPT_ELEMENT} OPT_ARG_NEEDED=OK ;; 'no-' | \ 'no-a' | \ 'no-au' | \ 'no-aut' | \ 'no-auto' | \ 'no-autog' | \ 'no-autoge' | \ 'no-autogen' ) if [ -n "${GETDEFS_AUTOGEN}" ] && ${GETDEFS_AUTOGEN_set} ; then echo 'Error: duplicate AUTOGEN option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_AUTOGEN_set=true GETDEFS_AUTOGEN='no' export GETDEFS_AUTOGEN OPT_NAME='AUTOGEN' OPT_ARG_NEEDED=NO ;; 'te' | \ 'tem' | \ 'temp' | \ 'templ' | \ 'templa' | \ 'templat' | \ 'template' ) if [ -n "${GETDEFS_TEMPLATE}" ] && ${GETDEFS_TEMPLATE_set} ; then echo 'Error: duplicate TEMPLATE option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_TEMPLATE_set=true OPT_NAME='TEMPLATE' OPT_ARG_NEEDED=YES ;; 'ag' | \ 'aga' | \ 'agar' | \ 'agarg' ) GETDEFS_AGARG_CT=`expr ${GETDEFS_AGARG_CT} + 1` OPT_ELEMENT="_${GETDEFS_AGARG_CT}" OPT_NAME='AGARG' OPT_ARG_NEEDED=YES ;; 'ba' | \ 'bas' | \ 'base' | \ 'base-' | \ 'base-n' | \ 'base-na' | \ 'base-nam' | \ 'base-name' ) if [ -n "${GETDEFS_BASE_NAME}" ] && ${GETDEFS_BASE_NAME_set} ; then echo 'Error: duplicate BASE_NAME option' echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 GETDEFS_BASE_NAME_set=true OPT_NAME='BASE_NAME' OPT_ARG_NEEDED=YES ;; 've' | \ 'ver' | \ 'vers' | \ 'versi' | \ 'versio' | \ 'version' ) echo "$GETDEFS_LONGUSAGE_TEXT" exit 0 ;; 'he' | \ 'hel' | \ 'help' ) echo "$GETDEFS_LONGUSAGE_TEXT" exit 0 ;; 'mo' | \ 'mor' | \ 'more' | \ 'more-' | \ 'more-h' | \ 'more-he' | \ 'more-hel' | \ 'more-help' ) echo "$GETDEFS_LONGUSAGE_TEXT" | ${PAGER-more} exit 0 ;; 'sa' | \ 'sav' | \ 'save' | \ 'save-' | \ 'save-o' | \ 'save-op' | \ 'save-opt' | \ 'save-opts' ) echo 'Warning: Cannot save options files' >&2 OPT_ARG_NEEDED=OK ;; 'lo' | \ 'loa' | \ 'load' | \ 'load-' | \ 'load-o' | \ 'load-op' | \ 'load-opt' | \ 'load-opts' ) echo 'Warning: Cannot load options files' >&2 OPT_ARG_NEEDED=YES ;; 'no-' | \ 'no-l' | \ 'no-lo' | \ 'no-loa' | \ 'no-load' | \ 'no-load-' | \ 'no-load-o' | \ 'no-load-op' | \ 'no-load-opt' | \ 'no-load-opts' ) echo 'Warning: Cannot suppress the loading of options files' >&2 OPT_ARG_NEEDED=NO ;; * ) echo Unknown option: "${OPT_CODE}" >&2 echo "$GETDEFS_USAGE_TEXT" >&2 exit 1 ;; esac case "${OPT_ARG_NEEDED}" in NO ) OPT_ARG_VAL='' ;; YES ) if [ -z "${OPT_ARG_VAL}" ] then if [ $# -eq 0 ] then echo No argument provided for ${OPT_NAME} option echo "$GETDEFS_USAGE_TEXT" exit 1 fi >&2 OPT_ARG_VAL=${OPT_ARG} shift OPT_ARG=$1 fi ;; OK ) if [ -z "${OPT_ARG_VAL}" ] && [ $# -gt 0 ] then case "${OPT_ARG}" in -* ) ;; * ) OPT_ARG_VAL=${OPT_ARG} shift OPT_ARG=$1 ;; esac fi ;; esac if [ -n "${OPT_ARG_VAL}" ] then eval GETDEFS_${OPT_NAME}${OPT_ELEMENT}="'${OPT_ARG_VAL}'" export GETDEFS_${OPT_NAME}${OPT_ELEMENT} fi done OPTION_COUNT=`expr $ARG_COUNT - $#` OPERAND_COUNT=$# unset OPT_PROCESS || : unset OPT_ELEMENT || : unset OPT_ARG || : unset OPT_ARG_NEEDED || : unset OPT_NAME || : unset OPT_CODE || : unset OPT_ARG_VAL || : # # # # # # # # # # # # END OF AUTOMATED OPTION PROCESSING # # # # # # # # # # # -- do not modify this marker -- env | grep '^GETDEFS_'
Previous: Parsing with an Executable, Up: AutoOpts for Shell Scripts [Contents][Index]