Next: , Previous: , Up: Program Description Attributes   [Contents][Index]


7.5.1.3 Programming Details

These attributes affect some of the ways that the option data are used and made available to the program.

config-header

The contents of this attribute should be just the name of the configuration file. A "#include" naming this file will be inserted at the top of the generated header.

exit-name
exit-desc

These values should be defined as indexed values, thus:

exit-name[0] = success;
exit-desc[0] = 'Successful program execution.';
exit-name[1] = failure;
exit-desc[1] = 'The operation failed or command syntax was not valid.';

By default, all programs have these effectively defined for them. They may be overridden by explicitly defining any or all of these values. Additional names and descriptions may be defined. They will cause an enumeration to be emitted, like this one for getdefs:

typedef enum {
    GETDEFS_EXIT_SUCCESS = 0,
    GETDEFS_EXIT_FAILURE = 1
} getdefs_exit_code_t;

which will be augmented by any exit-name definitions beyond ‘1’.

Some of the generated code will exit non-zero if there is an allocation error. This exit will always be code ‘1’, unless there is an exit named ‘no_mem’ or ‘nomem’. In that case, that value will be used. Additionally, if there is such a value, and if die-code is specified, then a function nomem_err(size_t len, char const * what) will be emitted as an inline function for reporting out-of-memory conditions.

usage-message

This attribute will cause two procedures to be added to the code file: usage_message() and vusage_message(), with any applicable prefix (see prefix, below). They are declared in the generated header, thus:

noreturn extern void vusage_message(char const * fmt, va_list ap);
noreturn extern void usage_message(char const * fmt, ...);

These functions print the message to stderr and invoke the usage function with the exit code set to 1 (EXIT_FAILURE).

die-code

This tells AutoOpts templates to emit code for vdie(), die(), fserr(), and, possibly the nomem_err() functions. The latter is emitted if an exit name of ‘no-mem’ or ‘nomem’ is specified. If the die-code is assigned a text value, then that code will be inserted in the vdie function immediately before it prints the death rattle message.

The profiles for these functions are:

noreturn extern void vdie( int exit_code, char const * fmt, va_list);
noreturn extern void die(  int exit_code, char const * fmt, ...);
noreturn extern void fserr(int exit_code, char const * op, char const * fname);
noreturn static inline void
nomem_err(size_t sz, char const * what) {...}
export

This string is inserted into the .h interface file. Generally used for global variables or #include directives required by flag-code text and shared with other program text. Do not specify your configuration header (config.h) in this attribute or the include attribute. Instead, use config-header, above.

guard-option-names

AutoOpts generates macros that presume that there are no cpp macros with the same name as the option name. For example, if you have an option named, --debug, then you must not use #ifdef DEBUG in your code. If you specify this attribute, every option name will be guarded. If the name is #define-d, then a warning will be issued and the name undefined. If you do not specify this and there is a conflict, you will get strange error messages.

This attribute may be set to any of four recognized states:

  • Not defined. AutoOpts will behave as described above.
  • Defined, but set to the empty string. Text will be emitted into the header to undefine (#undef) any conflicting preprocessor macros. The code will include compiler warnings (via #warning). Some compilers are not ANSI-C-99 compliant yet and will error out on those warnings. You may compile with -DNO_OPTION_NAME_WARNINGS to silence or mostly silence them.
  • Defined and set to the string, no-warning. All of the needed #undefs will be emitted, without any conflict checking #warning directives emitted.
  • Defined and set to the string, full-enum. The option manipulation preprocessor macros will not token paste the option names to the index enumeration prefix. e.g. you will need to use HAVE_OPT(INDEX_OPT_DEBUG) instead of HAVE_OPT(DEBUG).
include

This string is inserted into the .c file. Generally used for global variables required only by flag-code program text.

no-libopts

If you are going to handle your option processing with the getopt.tpl template instead of using libopts, then specify this attribute. It will suppress mention of --more-help in the generated documentation. (getopt_long does not support --more-help.)

prefix

This value is inserted into all global names. This will disambiguate them if more than one set of options are to be compiled into a single program.


Next: User Presentation Attributes, Previous: Program Configuration, Up: Program Description Attributes   [Contents][Index]