AutoGen: getopt_long

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

## 7.12 Using getopt(3C)

There is now a template named, "`getopt.tpl`" that is distributed with autoopts. With it, you will have another source file generated for you that will utilize either the standard `getopt(3C)` or the GNU `getopt_long(3GNU)` function for parsing the command line arguments. Which is used is selected by the presence or absence of the `long-opts` program attribute. It will save you from being dependent upon the `libopts` library and it produces code ready for internationalization. However, it also carries with it some limitations on the use of AutoOpts features:

1. You cannot automatically take advantage of environment variable options or rc (ini) files.

2. You cannot use set membership, enumerated, range checked or stacked argument type options. These all depend upon the `libopts` library.

3. You must specify every option as "settable" because the emitted code depends upon the `SET_OPT_XXX` macros having been defined.

4. "test-main" must be specified. The ``getopt.tpl'` template depends upon being able to compile the traditional .c file into a program and get it to emit the usage text.

5. For the same reason, the traditional option parsing table code must be emitted before the ``getopt.tpl'` template gets expanded.

6. The usage text is, therefore, statically defined.

7. The code is fairly new. I am sure that more can be done and that there are some glitches to be ironed out. Likely all simple stuff, but as I do not use it for my own work, it likely isn't exercised quite as much as the rest...

To use this, simply invoke autogen twice, in the following order:

    autogen myprog-opts.def
    autogen -T getopt.tpl myprog-opts.def

and you will have three new files: ``myprog-opts.h'`, ``myprog-opts.c'`, and ``getopt-progname.c'`, where "progname" is the name specified with the global `prog-name` attribute in the option definition file.

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

This document was generated by Bruce Korb on October 24, 2004 using texi2html