[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.7 AutoOpts for Shell Scripts

AutoOpts may be used with shell scripts by automatically creating a complete program that will process command line options and pass back the results to the invoking shell by issuing shell variable assignment commands. It may also be used to generate portable shell code that can be inserted into your script.

The functionality of these features, of course, is somewhat constrained compared with the normal program facilities. Specifically, you cannot invoke callout procedures with either of these methods. Additionally, if you generate a shell script:

  1. You cannot obtain options from RC/INI files.
  2. You cannot obtain options from environment variables.
  3. You cannot save the option state to an option file.
  4. Option conflict/requirement verification is disabled.

Both of these methods are enabled by running AutoGen on the definitions file with the additional global attribute:

 
test-main [ = proc-to-call ] ;

If you do not supply a proc-to-call, it will default to putBourneShell. That will produce a program that will process the options and generate shell text for the invoking shell to interpret. If you supply the name, putShellParse, then you will have a program that will generate a shell script that can parse the options. If you supply a different procedure name, you will have to provide that routine and it may do whatever you like.

In summary, you will need to issue approximately the following two commands to have a working program:

 
autogen -L <opt-template-dir> program.def
cc -o progopts -L <opt-lib-dir> -I <opt-include-dir> \
        -DTEST_program_OPTS program.c -lopts

The resulting program can be used within your shell script as follows:

 
eval `./progopts $@`
if [ -z "${OPTION_CT}" ] ; then exit 1 ; fi
shift ${OPTION_CT}

If you had used test-main = putShellParse 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 this:

 
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 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-bugs@lists.sf.net

= = = = = = = =

This incarnation of genshell will produce
a shell script to parse the options for getdefs:

getdefs - AutoGen Definition Extraction Tool - Ver. 1.4
USAGE:  getdefs [ <option-name>[{=| }<val>] ]...
   Arg Option-Name    Description
   Str defs-to-get    Regexp to look for after the "/*="
   opt ordering       Alphabetize or use named file
   Num first-index    The first index to apply to groups
   Str input          Input file to search for defs
   Str subblock       subblock definition names
   Str listattr       attribute with list of values
   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 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)
   opt version        Output version information and exit
   no  help           Display usage information and exit
   no  more-help      Extended usage information passed thru pager
   opt save-opts      Save the option state to an rc file
   Str load-opts      Load options from an rc file

All arguments are named options.

If no ``input'' argument is provided or is set to simply "-", and if
``stdin'' is not a ``tty'', then the list of input files will be
read from ``stdin''.

please send bug reports to:  autogen-bugs@lists.sf.net


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on May 5, 2003 using texi2html

Viewable With Any Browser   AutoGen Home