Fixed build with HWASan
[platform/upstream/autogen.git] / doc / autogen-texi.txt
1 @c -*- Mode: texinfo -*-
2 @setfilename autogen.info
3 @ignore
4 This file serves two purposes:
5
6 1) it provides that stupid (at)setfilename so that automake will
7    deign to produce the documentation
8
9 2) a text repository for documentation that would make the doc
10    template more confusing.
11
12
13   This file is part of AutoGen.
14   AutoGen Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
15
16   AutoGen is free software: you can redistribute it and/or modify it
17   under the terms of the GNU General Public License as published by the
18   Free Software Foundation, either version 3 of the License, or
19   (at your option) any later version.
20
21   AutoGen is distributed in the hope that it will be useful, but
22   WITHOUT ANY WARRANTY; without even the implied warranty of
23   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24   See the GNU General Public License for more details.
25
26   You should have received a copy of the GNU General Public License along
27   with this program.  If not, see <http://www.gnu.org/licenses/>.
28 @end ignore
29
30 @ignore
31 START == COMMENTS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
32 Extraction from autogen.texi
33 @end ignore
34
35 @ignore
36 Resume input from autogen.texi
37 @end ignore
38
39 @c === SECTION MARKER
40
41 @node Predefines
42 @section Pre-defined Names
43 @cindex predefines
44
45 When AutoGen starts, it tries to determine several names from the
46 operating environment and put them into environment variables for use in
47 both @code{#ifdef} tests in the definitions files and in shell scripts
48 with environment variable tests.  @env{__autogen__} is always defined.
49 For other names, AutoGen will first try to use the POSIX version of the
50 @code{sysinfo(2)} system call.  Failing that, it will try for the POSIX
51 @code{uname(2)} call.  If neither is available, then only
52 "@env{__autogen__}" will be inserted into the environment.
53 In all cases, the associated names are converted to lower case, surrounded
54 by doubled underscores and non-symbol characters are replaced with
55 underscores.
56
57 With Solaris on a sparc platform, @code{sysinfo(2)} is available.
58 The following strings are used:
59
60 @itemize @bullet
61 @item
62 @code{SI_SYSNAME} (e.g., "__sunos__")
63 @item
64 @code{SI_HOSTNAME} (e.g., "__ellen__")
65 @item
66 @code{SI_ARCHITECTURE} (e.g., "__sparc__")
67 @item
68 @code{SI_HW_PROVIDER} (e.g., "__sun_microsystems__")
69 @item
70 @code{SI_PLATFORM} (e.g., "__sun_ultra_5_10__")
71 @item
72 @code{SI_MACHINE} (e.g., "__sun4u__")
73 @end itemize
74
75 For Linux and other operating systems that only support the
76 @code{uname(2)} call, AutoGen will use these values:
77
78 @itemize @bullet
79 @item
80 @code{sysname} (e.g., "__linux__")
81 @item
82 @code{machine} (e.g., "__i586__")
83 @item
84 @code{nodename} (e.g., "__bach__")
85 @end itemize
86
87 By testing these pre-defines in my definitions, you can select
88 pieces of the definitions without resorting to writing shell
89 scripts that parse the output of @code{uname(1)}.  You can also
90 segregate real C code from autogen definitions by testing for
91 "@code{__autogen__}".
92
93 @example
94 #ifdef __bach__
95   location = home;
96 #else
97   location = work;
98 #endif
99 @end example
100
101 @c === SECTION MARKER
102
103 @node Comments
104 @section Commenting Your Definitions
105 @cindex comments
106
107 The definitions file may contain C and C++ style comments.
108
109 @example
110 /*
111  *  This is a comment.  It continues for several lines and closes
112  *  when the characters '*' and '/' appear together.
113  */
114 // this comment is a single line comment
115 @end example
116
117 @c === SECTION MARKER
118
119 @node Example
120 @section What it all looks like.
121
122 @noindent
123 This is an extended example:
124
125 @example
126 autogen definitions @samp{template-name};
127 /*
128  *  This is a comment that describes what these
129  *  definitions are all about.
130  */
131 global = "value for a global text definition.";
132
133 /*
134  *  Include a standard set of definitions
135  */
136 #include standards.def
137
138 a_block = @{
139     a_field;
140     a_subblock = @{
141         sub_name  = first;
142         sub_field = "sub value.";
143     @};
144
145 #ifdef FEATURE
146     a_subblock = @{
147         sub_name  = second;
148     @};
149 #endif
150
151 @};
152 @end example
153
154 @ignore
155 END   == COMMENTS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
156 Extraction from autogen.texi
157 @end ignore
158
159 @ignore
160 START == TEMPLATE == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
161 Extraction from autogen.texi
162 @end ignore
163
164 @c === SECTION MARKER
165
166 @node Alternate Definition
167 @section Alternate Definition Forms
168 @cindex Alternate Definition
169
170 There are several methods for supplying data values for templates.
171
172 @table @samp
173 @item no definitions
174 It is entirely possible to write a template that does not depend upon
175 external definitions.  Such a template would likely have an unvarying
176 output, but be convenient nonetheless because of an external library
177 of either AutoGen or Scheme functions, or both.  This can be accommodated
178 by providing the @option{--override-tpl} and @option{--no-definitions}
179 options on the command line.  @xref{autogen Invocation}.
180
181 @item CGI
182 AutoGen behaves as a CGI server if the definitions input is from stdin
183 and the environment variable @env{REQUEST_METHOD} is defined
184 and set to either "GET" or "POST", @xref{AutoGen CGI}.  Obviously,
185 all the values are constrained to strings because there is no way
186 to represent nested values.
187
188 @item XML
189 AutoGen comes with a program named, @command{xml2ag}.  Its output can
190 either be redirected to a file for later use, or the program can
191 be used as an AutoGen wrapper.  @xref{xml2ag Invocation}.
192
193 The introductory template example (@pxref{Example Usage}) can be rewritten
194 in XML as follows:
195
196 @example
197 <EXAMPLE  template="list.tpl">
198 <LIST list_element="alpha"
199       list_info="some alpha stuff"/>
200 <LIST list_info="more beta stuff"
201       list_element="beta"/>
202 <LIST list_element="omega"
203       list_info="final omega stuff"/>
204 </EXAMPLE>
205 @end example
206
207 A more XML-normal form might look like this:
208 @example
209 <EXAMPLE  template="list.tpl">
210 <LIST list_element="alpha">some alpha stuff</LIST>
211 <LIST list_element="beta" >more beta stuff</LIST>
212 <LIST list_element="omega">final omega stuff</LIST>
213 </EXAMPLE>
214 @end example
215 @noindent
216 but you would have to change the template @code{list-info} references
217 into @code{text} references.
218
219 @item standard AutoGen definitions
220 Of course.  :-)
221
222 @end table
223
224 @ignore
225 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
226 @end ignore
227 @page
228 @node Template File
229 @chapter Template File
230 @cindex template file
231 @cindex .tpl file
232
233 The AutoGen template file defines the content of the output text.
234 It is composed of two parts.  The first part consists of a pseudo
235 macro invocation and commentary.  It is followed by the template proper.
236
237 @cindex pseudo macro
238 @cindex macro, pseudo
239 This pseudo macro is special.  It is used to identify the file as a
240 AutoGen template file, fixing the starting and ending marks for
241 the macro invocations in the rest of the file, specifying the list
242 of suffixes to be generated by the template and, optionally, the
243 shell to use for processing shell commands embedded in the template.
244
245 AutoGen-ing a file consists of copying text from the template to the
246 output file until a start macro marker is found.  The text from the
247 start marker to the end marker constitutes the macro text.  AutoGen
248 macros may cause sections of the template to be skipped or processed
249 several times.  The process continues until the end of the template is
250 reached.  The process is repeated once for each suffix specified in the
251 pseudo macro.
252
253 This chapter describes the format of the AutoGen template macros
254 and the usage of the AutoGen native macros.  Users may augment
255 these by defining their own macros, @xref{DEFINE}.
256
257 @menu
258 * pseudo macro::       Format of the Pseudo Macro
259 * naming values::      Naming a value
260 * expression syntax::  Macro Expression Syntax
261 * AutoGen Functions::  AutoGen Scheme Functions
262 * Common Functions::   Common Scheme Functions
263 * native macros::      AutoGen Native Macros
264 * output controls::    Redirecting Output
265 @end menu
266
267 @c === SECTION MARKER
268
269 @node pseudo macro
270 @section Format of the Pseudo Macro
271 @cindex pseudo macro
272
273 The pseudo macro is used to tell AutoGen how to process a template.
274 It tells autogen:
275
276 @enumerate
277 @item
278 The start macro marker.  It consists of punctuation characters used to
279 demarcate the start of a macro.  It may be up to seven characters long and
280 must be the first non-whitespace characters in the file.
281
282 @noindent
283 It is generally a good idea to use some sort of opening
284 bracket in the starting macro and closing bracket in the ending
285 macro  (e.g. @code{@{}, @code{(}, @code{[}, or even @code{<}
286 in the starting macro).  It helps both visually and with editors
287 capable of finding a balancing parenthesis.
288
289 @item
290 That start marker must be immediately followed by the identifier strings
291 "AutoGen5" and then "template", though capitalization is not important.
292 @end enumerate
293
294 @noindent
295 The next several components may be intermingled:
296
297 @enumerate 3
298 @item
299 Zero, one or more suffix specifications tell AutoGen how many times to
300 process the template file.  No suffix specifications mean that it is to
301 be processed once and that the generated text is to be written to
302 @file{stdout}.  The current suffix for each pass can be determined with the
303 @code{(suffix)} scheme function (@pxref{SCM suffix}).
304
305 The suffix specification consists of a sequence of POSIX compliant file name
306 characters and, optionally, an equal sign and a file name formatting
307 specification.  That specification may be either an ordinary sequence of
308 file name characters with zero, one or two "%s" formatting sequences in it,
309 or else it may be a Scheme expression that, when evaluated, produces such a
310 string.  The Scheme result may not be empty.  The two string arguments
311 allowed for that string are the base name of the definition file, and the
312 current suffix (that being the text to the left of the equal sign).  (Note:
313 "POSIX compliant file name characters" consist of alphanumerics plus the
314 period (@code{.}), hyphen (@code{-}) and underscore (@code{_}) characters.)
315
316 If the suffix begins with one of these three latter characters and
317 a formatting string is not specified, then that character is presumed to
318 be the suffix separator.  Otherwise, without a specified format string,
319 a single period will separate the suffix from the base name in constructing
320 the output file name.
321
322 @item
323 Shell specification: to specify that the template was written expecting a
324 particular shell to run the shell commands.  By default, the shell used is the
325 autoconf-ed @env{CONFIG_SHELL}.  This will usually be @file{/bin/sh}.  The
326 shell is specified by a hash mark (@code{#}) followed by an exclamation mark
327 (@code{!}) followed by a full-path file name (e.g. @file{/usr/xpg4/bin/sh} on
328 Solaris):
329 @example
330 [= Autogen5 Template c
331 #!/usr/xpg4/bin/sh
332 =]
333 @end example
334
335 @item
336 Comments: blank lines, lines starting with a hash mark (@code{#}) and not
337 specifying a shell, and edit mode markers (text between pairs of @code{-*-}
338 strings) are all treated as comments.
339
340 @item
341 Some scheme expressions may be inserted in order to make configuration
342 changes before template processing begins.
343 @i{before template processing begins} means that there is no current
344 output file, no current suffix and, basically, none of the AutoGen
345 specific functions
346 (@pxref{AutoGen Functions}) may be invoked.
347
348 The scheme expression can also be used, for example, to save a pre-existing
349 output file for later text extraction (@pxref{SCM extract}).
350
351 @example
352 (shellf "mv -f %1$s.c %1$s.sav" (base-name))
353 @end example
354 @end enumerate
355
356 @noindent
357 After these must come the end macro marker:
358
359 @enumerate 6
360 @item
361 The punctuation characters used to demarcate the end of a macro.
362 Like the start marker, it must consist of seven or fewer punctuation
363 characters.
364 @end enumerate
365
366 The ending macro marker has a few constraints on its content.  Some of
367 them are just advisory, though.  There is no special check for advisory
368 restrictions.
369
370 @itemize @bullet
371 @item
372 It must not begin with a POSIX file name character (hyphen @code{-},
373 underscore @code{_} or period @code{.}), the backslash (@code{\}) or
374 open parenthesis (@code{(}).  These are used to identify a suffix
375 specification, indicate Scheme code and trim white space.
376
377 @item
378 If it begins with an equal sign, then it
379 must be separated from any suffix specification by white space.
380
381 @item
382 The closing marker may not begin with an open parenthesis, as that is used
383 to enclose a scheme expression.
384
385 @item
386 It cannot begin with a backslash, as that is used to indicate white
387 space trimming after the end macro mark.  If, in the body of the template,
388 you put the backslash character (@code{\}) before the end macro mark, then
389 any white space characters after the mark and through the newline character
390 are trimmed.
391
392 @item
393 It is also helpful to avoid using the comment marker (@code{#}).
394 It might be seen as a comment within the pseudo macro.
395
396 @item
397 You should avoid using any of the quote characters@:  double,
398 single or back-quote.  It won't confuse AutoGen, but it might well
399 confuse you and/or your editor.
400 @end itemize
401
402 As an example, assume we want to use @code{[+} and @code{+]} as the start
403 and end macro markers, and we wish to produce a @file{.c} and a @file{.h}
404 file, then the pseudo macro might look something like this:
405
406 @example
407 [+ AutoGen5 template -*- Mode: emacs-mode-of-choice -*-
408 h=chk-%s.h
409 c
410 # make sure we don't use csh:
411 (setenv "SHELL" "/bin/sh")  +]
412 @end example
413
414 The template proper starts after the pseudo-macro.  The starting
415 character is either the first non-whitespace character or the first
416 character after the newline that follows the end macro marker.
417
418 @c === SECTION MARKER
419
420 @node naming values
421 @section Naming a value
422 @cindex naming values
423
424 When an AutoGen value is specified in a template, it is specified by name.
425 The name may be a simple name, or a compound name of several components.
426 Since each named value in AutoGen is implicitly an array of one or more
427 values, each component may have an index associated with it.
428
429 @noindent
430 It looks like this:
431
432 @example
433 comp-name-1 . comp-name-2 [ 2 ]
434 @end example
435
436 Note that if there are multiple components to a name, each component
437 name is separated by a dot (@code{.}).  Indexes follow a component name,
438 enclosed in square brackets (@code{[} and @code{]}).  The index may be
439 either an integer or an integer-valued define name.  The first component
440 of the name is searched for in the current definition level.  If not
441 found, higher levels will be searched until either a value is found,
442 or there are no more definition levels.  Subsequent components of the
443 name must be found within the context of the newly-current definition
444 level.  Also, if the named value is prefixed by a dot (@code{.}),
445 @cindex .
446 then the value search is started in the current context only.
447 Backtracking
448 @cindex backtrack
449 into other definition levels is prevented.
450
451 If someone rewrites this, I'll incorporate it.  :-)
452
453 @c === SECTION MARKER
454
455 @node expression syntax
456 @section Macro Expression Syntax
457 @cindex expression syntax
458
459 AutoGen has two types of expressions:  full expressions and basic ones.
460 A full AutoGen expression can appear by itself, or as the argument
461 to certain AutoGen built-in macros:  CASE, IF, ELIF, INCLUDE,
462 INVOKE (explicit invocation, @pxref{INVOKE}), and WHILE.
463 If it appears by itself, the result is inserted into the output.
464 If it is an argument to one of these macros, the macro code
465 will act on it sensibly.
466
467 You are constrained to basic expressions only when passing
468 arguments to user defined macros, @xref{DEFINE}.
469
470 The syntax of a full AutoGen expression is:
471
472 @example
473 [[ <apply-code> ] <value-name> ] [ <basic-expr-1> [ <basic-expr-2> ]]
474 @end example
475
476 How the expression is evaluated depends upon the presence or absence
477 of the apply code and value name.  The "value name" is the name of
478 an AutoGen defined value, or not.  If it does not name such a value,
479 the expression result is generally the empty string.  All expressions
480 must contain either a @var{value-name} or a @var{basic-expr}.
481
482 @menu
483 * apply code::           Apply Code
484 * basic expression::     Basic Expression
485 @end menu
486
487 @node apply code
488 @subsection Apply Code
489
490 The "apply code" selected determines the method of evaluating the
491 expression.  There are five apply codes, including the non-use
492 of an apply code.
493
494 @table @samp
495 @item no apply code
496 This is the most common expression type.
497 Expressions of this sort come in three flavors:
498
499 @table @samp
500 @item <value-name>
501 The result is the value of @var{value-name}, if defined.
502 Otherwise it is the empty string.
503
504 @item <basic-expr>
505 The result of the basic expression is the result of the full expression,
506 @xref{basic expression}.
507
508 @item <value-name> <basic-expr>
509 If there is a defined value for @var{value-name}, then the @var{basic-expr}
510 is evaluated.  Otherwise, the result is the empty string.
511 @end table
512
513 @item % <value-name> <basic-expr>
514 If @var{value-name} is defined, use @var{basic-expr} as a format
515 string for sprintf.  Then, if the @var{basic-expr} is either a back-quoted
516 string or a parenthesized expression, then hand the result to the
517 appropriate interpreter for further evaluation.  Otherwise, for single
518 and double quote strings, the result is the result of the sprintf operation.
519 Naturally, if @var{value-name} is not defined, the result is the empty
520 string.
521
522 For example, assume that @samp{fumble} had the string value, @samp{stumble}:
523 @example
524 [+ % fumble `printf '%%x\\n' $%s` +]
525 @end example
526 This would cause the shell to evaluate "@samp{printf '%x\n' $stumble}".
527 Assuming that the shell variable @samp{stumble} had a numeric value,
528 the expression result would be that number, in hex.  Note the need
529 for doubled percent characters and backslashes.
530
531 @item ? <value-name> <basic-expr-1> <basic-expr-2>
532 Two @var{basic-expr}-s are required.  If the @var{value-name} is
533 defined, then the first @var{basic-expr-1} is evaluated, otherwise
534 @var{basic-expr-2} is.
535
536 @item - <value-name> <basic-expr>
537 Evaluate @var{basic-expr} only if @var{value-name} is @i{not} defined.
538
539 @item ?% <value-name> <basic-expr-1> <basic-expr-2>
540 This combines the functions of @samp{?} and @samp{%}.  If @var{value-name} is
541 defined, it behaves exactly like @samp{%}, above, using @var{basic-expr-1}.
542 If not defined, then @var{basic-expr-2} is evaluated.
543
544 For example, assume again that @samp{fumble} had the string value,
545 @samp{stumble}:
546 @example
547 [+ ?% fumble `cat $%s` `pwd` +]
548 @end example
549 This would cause the shell to evaluate "@samp{cat $stumble}".
550 If @samp{fumble} were not defined, then the result would be the name
551 of our current directory.
552 @end table
553
554 @node basic expression
555 @subsection Basic Expression
556
557 A basic expression can have one of the following forms:
558
559 @table @samp
560 @item 'STRING'
561 A single quoted string.  Backslashes can be used to protect single
562 quotes (@code{'}), hash characters (@code{#}), or backslashes (@code{\})
563 in the string.  All other characters of STRING are output as-is when the
564 single quoted string is evaluated.  Backslashes are processed before the hash
565 character for consistency with the definition syntax.  It is needed there
566 to avoid preprocessing conflicts.
567
568 @item "STRING"
569 A double quoted string.  This is a cooked text string as in C,
570 except that they are not concatenated with adjacent strings.
571 Evaluating "@samp{STRING}" will output STRING with all
572 backslash sequences interpreted.
573
574 @item `STRING`
575 A back quoted string.  When this expression is evaluated, STRING
576 is first interpreted as a cooked string (as in `"STRING"') and
577 evaluated as a shell expression by the AutoGen server shell.  This
578 expression is replaced by the @file{stdout} output of
579 the shell.
580
581 @item (STRING)
582 A parenthesized expression.  It will be passed to the Guile
583 interpreter for evaluation and replaced by the resulting value.
584 If there is a Scheme error in this expression, Guile 1.4 and Guile 1.6
585 will report the template line number where the error occurs.  Guile 1.7
586 has lost this capability.
587
588 Guile has the capability of creating and manipulating variables that
589 can be referenced later on in the template processing.  If you define
590 such a variable, it is invisible to AutoGen.  To reference its value,
591 you must use a Guile expression.  For example,
592 @example
593 [+ (define my-var "some-string-value") +]
594 @end example
595 can have that string inserted later, but only as in:
596 @example
597 [+ (. my-var) +]
598 @end example
599
600 Additionally, other than in the @code{%} and @code{?%} expressions, the
601 Guile expressions may be introduced with the Guile comment character
602 (@code{;}) and you may put a series of Guile expressions within a single
603 macro.  They will be implicitly evaluated as if they were arguments
604 to the @code{(begin ...)} expression.  The result will be the
605 result of the last Guile expression evaluated.
606 @end table
607
608 @ignore
609 END   == TEMPLATE == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
610 Extraction from autogen.texi
611 @end ignore
612
613 @ignore
614 START == MACROS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
615 Extraction from autogen.texi
616 @end ignore
617
618 @c === SECTION MARKER
619
620 @node native macros
621 @section AutoGen Native Macros
622 @cindex native macros
623
624 This section describes the various AutoGen natively defined macros.
625 Unlike the Scheme functions, some of these macros are "block macros"
626 with a scope that extends through a terminating macro.  Block macros
627 must not overlap.  That is to say, a block macro started within the
628 scope of an encompassing block macro must have its matching end macro
629 appear before the encompassing block macro is either ended or subdivided.
630
631 The block macros are these:
632
633 @table @code
634 @item CASE
635 This macro has scope through the @code{ESAC} macro.
636 The scope is subdivided by @code{SELECT} macros.
637 You must have at least one @code{SELECT} macro.
638
639 @item DEFINE
640 This macro has scope through the @code{ENDDEF} macro.  The defined
641 user macro can never be a block macro.  This macro is extracted from
642 the template @i{before} the template is processed.  Consequently, you
643 cannot select a definition based on context.  You can, however, place
644 them all at the end of the file.
645
646 @item FOR
647 This macro has scope through the @code{ENDFOR} macro.
648
649 @item IF
650 This macro has scope through the @code{ENDIF} macro.
651 The scope may be subdivided by @code{ELIF} and @code{ELSE}
652 macros.  Obviously, there may be only one @code{ELSE} macro
653 and it must be the last of these subdivisions.
654
655 @item INCLUDE
656 This macro has the scope of the included file.
657 It is a block macro in the sense that the included
658 file must not contain any incomplete block macros.
659
660 @item WHILE
661 This macro has scope through the @code{ENDWHILE} macro.
662 @end table
663 @ignore
664 END   == MACROS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
665 Extraction from autogen.texi
666 @end ignore
667
668 @ignore
669 START == AUGMENTING == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
670 Extraction from autogen.texi
671 @end ignore
672
673 @c === SECTION MARKER
674
675 @node output controls
676 @section Redirecting Output
677 @cindex Redirecting Output
678 @cindex diversion
679
680 AutoGen provides a means for redirecting the template output to different
681 files or, in @file{M4} parlance, to various diversions.  It is accomplished
682 by providing a set of Scheme functions named @code{out-*}
683 (@pxref{AutoGen Functions}).
684
685 @table @samp
686 @item out-push-new (@pxref{SCM out-push-new})
687 This allows you to logically "push" output files onto a stack.
688 If you supply a string name, then a file by that name is created
689 to hold the output.  If you do not supply a name, then the text is
690 written to a scratch pad and retrieved by passing a @code{#t} argument
691 to the @code{out-pop} (@pxref{SCM out-pop}) function.
692
693 @item out-pop (@pxref{SCM out-pop})
694 This function closes the current output file and resumes output to the next
695 one in the stack.  At least one output must have been pushed onto the output
696 stack with the @code{out-push-new} (@pxref{SCM out-push-new}) function.  If
697 @code{#t} is passed in as an argument, then the entire contents of the
698 diversion (or file) is returned.
699
700 @item out-suspend (@pxref{SCM out-suspend})
701 This function does not close the current output, but instead sets it aside
702 for resumption by the given name with @code{out-resume}.  The current output
703 must have been pushed on the output queue with @code{out-push-new}
704 (@pxref{SCM out-push-new}).
705
706 @item out-resume (@pxref{SCM out-resume})
707 This will put a named file descriptor back onto the top of
708 stack so that it becomes the current output again.
709
710 @item out-switch (@pxref{SCM out-switch})
711 This closes the current output and creates a new file,
712 purging any preexisting one.  This is a shortcut for "pop"
713 followed by "push", but this can also be done at the base level.
714
715 @item out-move (@pxref{SCM out-move})
716 Renames the current output file without closing it.
717 @end table
718
719 There are also several functions for determining the output
720 status.  @xref{AutoGen Functions}.
721
722 @ignore
723
724 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
725
726 @end ignore
727
728 @page
729 @node Augmenting AutoGen
730 @chapter Augmenting AutoGen Features
731 @cindex Augmenting AutoGen
732
733 AutoGen was designed to be simple to enhance.  You can do it by
734 providing shell commands, Guile/Scheme macros or callout functions
735 that can be invoked as a Guile macro.  Here is how you do these.
736
737 @menu
738 * shell commands::       Shell Output Commands
739 * guile macros::         Guile Macros
740 * guile callouts::       Guile Callout Functions
741 * AutoGen macros::       AutoGen Macros
742 @end menu
743
744 @c === SECTION MARKER
745
746 @node shell commands
747 @section Shell Output Commands
748
749 Shell commands are run inside of a server process.  This means that,
750 unlike @file{make}, context is kept from one command to the next.
751 Consequently, you can define a shell function in one place inside of
752 your template and invoke it in another.  You may also store values
753 in shell variables for later reference.  If you load functions from
754 a file containing shell functions, they will remain until AutoGen exits.
755
756 If your shell script should determine that AutoGen should stop
757 processing, the recommended method for stopping AutoGen is:
758 @example
759 die "some error text"
760 @end example
761
762 @noindent
763 That is a shell function added by AutoGen.  It will send a SIGTERM
764 to autogen and exit from the "persistent" shell.
765
766 @c === SECTION MARKER
767
768 @node guile macros
769 @section Guile Macros
770
771 Guile also maintains context from one command to the next.  This means you may
772 define functions and variables in one place and reference them elsewhere.
773 If your Scheme script should determine that AutoGen should stop
774 processing, the recommended method for stopping AutoGen is:
775 @example
776 (error "some error text")
777 @end example
778
779 @c === SECTION MARKER
780
781 @node guile callouts
782 @section Guile Callout Functions
783
784 Callout functions must be registered with Guile to work.  This can
785 be accomplished either by putting your routines into a shared library
786 that contains a @code{void scm_init(void)} routine that registers
787 these routines, or by building them into AutoGen.
788
789 To build them into AutoGen, you must place your routines in the source
790 directory and name the files @file{exp*.c}.  You also must have a stylized
791 comment that @file{getdefs} can find that conforms to the following:
792
793 @example
794 /*=gfunc <function-name>
795  *
796  *  what:    <short one-liner>
797  *  general_use:
798  *  string:  <invocation-name-string>
799  *  exparg:  <name>, <description> [, ['optional'] [, 'list']]
800  *  doc:     A long description telling people how to use
801  *           this function.
802 =*/
803 SCM
804 ag_scm_<function-name>( SCM arg_name[, ...] )
805 @{ <code> @}
806 @end example
807
808 @table @samp
809 @item gfunc
810 You must have this exactly thus.
811
812 @item <function-name>
813 This must follow C syntax for variable names
814
815 @item <short one-liner>
816 This should be about a half a line long.
817 It is used as a subsection title in this document.
818
819 @item general_use:
820 You must supply this unless you are an AutoGen maintainer and are writing
821 a function that queries or modifies the state of AutoGen.
822
823 @item <invocation-name-string>
824 Normally, the @var{function-name} string will be transformed into
825 a reasonable invocation name.  However, that is not always true.
826 If the result does not suit your needs, then supply an alternate string.
827
828 @item exparg:
829 You must supply one for each argument to your function.
830 All optional arguments must be last.
831 The last of the optional arguments may be a list, if you choose.
832
833 @item doc:
834 Please say something meaningful.
835
836 @item [, ...]
837 Do not actually specify an ANSI ellipsis here.  You must provide
838 for all the arguments you specified with @var{exparg}.
839 @end table
840
841 See the Guile documentation for more details.
842 More information is also available in a large comment at the
843 beginning of the @file{agen5/snarf.tpl} template file.
844
845 @c === SECTION MARKER
846
847 @node AutoGen macros
848 @section AutoGen Macros
849
850 There are two kinds@:  those you define yourself and AutoGen native.
851 The user-defined macros may be defined in your templates,
852 @xref{DEFINE}.
853
854 As for AutoGen native macros, do not add any. It is easy to do, but I
855 won't like it.  The basic functions needed to accomplish looping over
856 and selecting blocks of text have proved to be sufficient over a period
857 of several years.  New text transformations can be easily added via any
858 of the AutoGen extension methods, as discussed above.
859
860 @ignore
861 END   == AUGMENTING == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
862 Extraction from autogen.texi
863 @end ignore
864
865 @ignore
866 START == INSTALLATION == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
867 Extraction from autogen.texi
868 @end ignore
869
870 @page
871 @node Installation
872 @chapter Configuring and Installing
873
874 @menu
875 * configuring::    Configuring AutoGen
876 * AutoGen CGI::    AutoGen as a CGI server
877 * signal names::   Signal Names
878 * installing::     Installing AutoGen
879 @end menu
880
881 @c === SECTION MARKER
882
883 @node configuring
884 @section Configuring AutoGen
885 @cindex configuring
886
887 AutoGen is configured and built using Libtool, Automake and Autoconf.
888 Consequently, you can install it wherever you wish using the @samp{--prefix}
889 and other options.  To the various configuration options supplied by these
890 tools, AutoGen adds a few of its own:
891
892 @table @samp
893 @item --disable-shell
894 AutoGen is now capable of acting as a CGI forms server, @xref{AutoGen CGI}.
895 As such, it will gather its definitions using either @samp{GET} or
896 @samp{POST} methods.  All you need to do is have a template named
897 @file{cgi.tpl} handy or specify a different one with a command line
898 option.
899
900 However, doing this without disabling the server shell brings
901 considerable risk.  If you were to pass user input to a script
902 that contained, say, the classic "@samp{`rm -rf /`}", you might have
903 a problem.  This configuration option will cause shell template
904 commands to simply return the command string as the result.
905 No mistakes.  Much safer.  Strongly recommended.
906 The default is to have server shell scripting enabled.
907
908 Disabling the shell will have some build side effects, too.
909
910 @itemize @bullet
911 @item
912 Many of the make check tests will fail, since they assume
913 a working server shell.
914 @item
915 The getdefs and columns programs are not built.
916 The options are distributed as definition files and they
917 cannot be expanded with a shell-disabled AutoGen.
918 @item
919 Similarly, the documentation cannot be regenerated because
920 the documentation templates depend on subshell functionality.
921 @end itemize
922
923 @item --enable-debug
924 Turning on AutoGen debugging enables very detailed inspection of
925 the input definitions and monitoring shell script processing.
926 These options are not particularly useful to anyone not directly
927 involved in maintaining AutoGen.  If you do choose to enable AutoGen
928 debugging, be aware that the usage page was generated without these
929 options, so when the build process reaches the documentation rebuild,
930 there will be a failure.  @samp{cd} into the @file{agen5} build
931 directory, @samp{make} the @samp{autogen.texi} file and all will
932 be well thereafter.
933
934 @item --with-regex-header
935 @itemx --with-header-path
936 @itemx --with-regex-lib
937 These three work together to specify how to compile with and link to a
938 particular POSIX regular expression library.  The value for
939 @file{--with-regex-header=value} must be the name of the relevant header file.
940 The AutoGen sources will attempt to include that source with a
941 @code{#include <value>} C preprocessing statement.  The @var{path} from the
942 @option{--with-header-path=path} will be added to @code{CPPFLAGS} as
943 @option{-Ipath}.  The @var{lib-specs} from @option{--with-regex-lib=lib-specs}
944 will be added to @code{LDFLAGS} without any adornment.
945 @end table
946
947 @c === SECTION MARKER
948
949 @page
950 @node AutoGen CGI
951 @section AutoGen as a CGI server
952
953 AutoGen is now capable of acting as a CGI forms server.
954 It behaves as a CGI server if the definitions input is from stdin
955 and the environment variable @env{REQUEST_METHOD} is defined
956 and set to either "GET" or "POST".  If set to anything else,
957 AutoGen will exit with a failure message.  When set to one of those
958 values, the CGI data will be converted to AutoGen definitions
959 (@pxref{Definitions File}) and the template named "@file{cgi.tpl}"
960 will be processed.
961
962 This works by including the name of the real template to process
963 in the form data and having the "@file{cgi.tpl}" template include
964 that template for processing.  I do this for processing the form
965 @url{http://autogen.sourceforge.net/conftest.html}.  The "@file{cgi.tpl}"
966 looks approximately like this:
967
968 @example
969 <? AutoGen5 Template ?>
970 <?
971 IF (not (exist? "template"))                       ?><?
972   form-error                                       ?><?
973
974 ELIF (=* (get "template") "/")                     ?><?
975   form-error                                       ?><?
976
977 ELIF (define tpl-file (string-append "cgi-tpl/"
978                       (get "template")))
979      (access? tpl-file R_OK)                       ?><?
980   INCLUDE (. tpl-file)                             ?><?
981
982 ELIF (set! tpl-file (string-append tpl-file ".tpl"))
983      (access? tpl-file R_OK)                       ?><?
984   INCLUDE (. tpl-file)                             ?><?
985
986 ELSE                                               ?><?
987   form-error                                       ?><?
988 ENDIF                                              ?>
989 @end example
990
991 @noindent
992 This forces the template to be found in the "@file{cgi-tpl/}"
993 directory.  Note also that there is no suffix specified in the
994 pseudo macro (@pxref{pseudo macro}).  That tells AutoGen to emit
995 the output to @file{stdout}.
996
997 The output is actually spooled until it is complete so that,
998 in the case of an error, the output can be discarded and a proper
999 error message can be written in its stead.
1000
1001 @strong{Please also note} that it is advisable, @emph{especially} for network
1002 accessible machines, to configure AutoGen (@pxref{configuring}) with
1003 shell processing disabled (@option{--disable-shell}).  That will make it
1004 impossible for any referenced template to hand data to a subshell for
1005 interpretation.
1006
1007 @c === SECTION MARKER
1008
1009 @node signal names
1010 @section Signal Names
1011 @cindex Signal Names
1012
1013 When AutoGen is first built, it tries to use @code{psignal(3)},
1014 @code{sys_siglist}, @code{strsigno(3)} and @code{strsignal(3)} from the
1015 host operating system.  If your system does not supply these, the
1016 AutoGen distribution will.  However, it will use the distributed mapping
1017 and this mapping is unlikely to match what your system uses.  This can
1018 be fixed.  Once you have installed autogen, the mapping can be rebuilt
1019 on the host operating system.  To do so, you must perform the
1020 following steps:
1021
1022 @enumerate
1023 @item
1024 Build and install AutoGen in a place where it will be found in your
1025 search path.
1026 @item
1027 @file{cd $@{top_srcdir@}/compat}
1028 @item
1029 @samp{autogen strsignal.def}
1030 @item
1031 Verify the results by examining the @file{strsignal.h} file produced.
1032 @item
1033 Re-build and re-install AutoGen.
1034 @end enumerate
1035
1036 If you have any problems or peculiarities that cause this process to
1037 fail on your platform, please send me copies of the header files
1038 containing the signal names and numbers, along with the full path names
1039 of these files.  I will endeavor to fix it.  There is a shell script
1040 inside of @file{strsignal.def} that tries to hunt down the information.
1041
1042 @c === SECTION MARKER
1043
1044 @node installing
1045 @section Installing AutoGen
1046 @cindex Installing
1047
1048 There are several files that get installed.  The number depend
1049 whether or not both shared and archive libraries are to be
1050 installed.  The following assumes that everything is installed
1051 relative to @env{$prefix}.  You can, of course, use
1052 @command{configure} to place these files where you wish.
1053
1054 @strong{NB}@:  AutoGen does not contain any compiled-in path names.
1055 All support directories are located via option processing,
1056 the environment variable @env{HOME} or finding the directory where
1057 the executable came from.
1058
1059 The installed files are:
1060
1061 @enumerate
1062 @item
1063 The executables in @file{bin} (autogen, getdefs and columns).
1064
1065 @item
1066 The AutoOpts link libraries as @file{lib/libopts.*}.
1067
1068 @item
1069 An include file in @file{include/options.h}, needed for
1070 Automated Option Processing (see next chapter).
1071
1072 @item
1073 Several template files and a scheme script in @file{share/autogen}, needed
1074 for Automated Option Processing (@pxref{AutoOpts}), parsing definitions
1075 written with scheme syntax (@pxref{Dynamic Text}), the templates for
1076 producing documentation for your program (@pxref{documentation attributes}),
1077 autoconf test macros, and AutoFSM.
1078
1079 @item
1080 Info-style help files as @file{info/autogen.info*}.
1081 These files document AutoGen, the option processing
1082 library AutoOpts, and several add-on components.
1083
1084 @item
1085 The three man pages for the three executables are installed in man/man1.
1086 @end enumerate
1087
1088 This program, library and supporting files can be installed
1089 with three commands:
1090
1091 @itemize @bullet
1092 @item
1093 <src-dir>/configure [ <configure-options> ]
1094 @item
1095 make
1096 @item
1097 make install
1098 @end itemize
1099
1100 However, you may wish to insert @samp{make check}
1101 before the @samp{make install} command.
1102
1103 If you do perform a @samp{make check} and there are any failures, you
1104 will find the results in @file{<module>/test/FAILURES}.  Needless to say, I
1105 would be interested in seeing the contents of those files and any
1106 associated messages.  If you choose to go on and analyze one of these
1107 failures, you will need to invoke the test scripts individually.  You
1108 may do so by specifying the test (or list of test) in the TESTS make
1109 variable, thus:
1110
1111 @example
1112 gmake TESTS=test-name.test check
1113 @end example
1114
1115 I specify @command{gmake} because most makes will not let you override
1116 internal definitions with command line arguments.  @command{gmake} does.
1117
1118 All of the AutoGen tests are written to honor the contents of the
1119 @t{VERBOSE} environment variable.  Normally, any commentary generated
1120 during a test run is discarded unless the @t{VERBOSE} environment
1121 variable is set.  So, to see what is happening during the test, you
1122 might invoke the following with @i{bash} or @i{ksh}:
1123
1124 @example
1125 VERBOSE=1 gmake TESTS="for.test forcomma.test" check
1126 @end example
1127
1128 @noindent
1129 Or equivalently with @i{csh}:
1130
1131 @example
1132 env VERBOSE=1 gmake TESTS="for.test forcomma.test" check
1133 @end example
1134
1135 @ignore
1136 END   == INSTALLATION == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1137 Extraction from autogen.texi
1138 @end ignore
1139
1140 @ignore
1141 START == AUTOFSM == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1142 Extraction from autogen.texi
1143 @end ignore
1144
1145 @c === SECTION MARKER
1146
1147 @node AutoFSM
1148 @section Automated Finite State Machine
1149 @cindex AutoFSM
1150 @cindex finite state machine
1151
1152 The templates to generate a finite state machine in C or C++ is included
1153 with AutoGen.  The documentation is not.  The documentation is in HTML
1154 format for @uref{http://www.gnu.org/software/autogen/autofsm.html,viewing},
1155 or you can @uref{http://download.sourceforge.net/autogen/,download FSM}.
1156
1157 @node AutoXDR
1158 @section Combined RPC Marshalling
1159 @cindex RPC
1160 @cindex rpcgen
1161 @cindex remote procedure call
1162 @cindex AutoXDR
1163 @cindex XDR
1164
1165 The templates and NFSv4 definitions are not included with AutoGen in any way.
1166 The folks that designed NFSv4 noticed that much time and bandwidth was
1167 wasted sending queries and responses when many of them could be bundled.
1168 The protocol bundles the data, but there is no support for it in rpcgen.
1169 That means you have to write your own code to do that.  Until now.
1170 Download this and you will have a large, complex example of how to use
1171 @code{AutoXDR} for generating the marshaling and unmarshaling of combined
1172 RPC calls.  There is a brief example
1173 @uref{http://www.gnu.org/software/autogen/xdr/index.html,on the web}, but
1174 you should @uref{http://download.sourceforge.net/autogen/,download AutoXDR}.
1175
1176 @c === SECTION MARKER
1177
1178 @node AutoEvents
1179 @section Automated Event Management
1180 @cindex AutoEvents
1181
1182 Large software development projects invariably have a need to manage
1183 the distribution and display of state information and state changes.
1184 In other words, they need to manage their software events.  Generally,
1185 each such project invents its own way of accomplishing this and then
1186 struggles to get all of its components to play the same way.  It is a
1187 difficult process and not always completely successful.  This project
1188 helps with that.
1189
1190 AutoEvents completely separates the tasks of supplying the data
1191 needed for a particular event from the methods used to manage the
1192 distribution and display of that event.  Consequently, the programmer
1193 writing the code no longer has to worry about that part of the
1194 problem.  Likewise the persons responsible for designing the event
1195 management and distribution no longer have to worry about getting
1196 programmers to write conforming code.
1197
1198 This is a work in progress.  See my
1199 @uref{http://www.gnu.org/software/autogen/autoevents.html,web page}
1200 on the subject, if you are interested.
1201 I have some useful things put together, but it is not ready
1202 to call a product.
1203
1204 @ignore
1205 END   == AUTOFSM == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1206 Extraction from autogen.texi
1207 @end ignore
1208
1209 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1210 @c
1211 @c  AUTOOPTS SECTIONS
1212 @c
1213 @c
1214 @ignore
1215 START == AUTOOPTS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1216 Extraction from autogen.texi
1217 @end ignore
1218
1219 All the features notwithstanding, some applications simply have
1220 well-established command line interfaces.  Even still, those programs
1221 may use the configuration file parsing portion of the library.
1222 See the ``AutoOpts Features'' and ``Configuration File Format'' sections.
1223
1224 @menu
1225 * Features::            AutoOpts Features
1226 * Licensing::           AutoOpts Licensing
1227 * Caveats::             Developer and User Notes
1228 * Quick Start::         Quick Start
1229 * Option Definitions::  Option Definitions
1230 * AutoOpts API::        Programmatic Interface
1231 * Multi-Threading::     Multi-Threading
1232 * option descriptor::   Option Descriptor File
1233 * Using AutoOpts::      Using AutoOpts
1234 * Presetting Options::  Configuring your program
1235 * Config File Format::  Configuration File Format
1236 * shell options::       AutoOpts for Shell Scripts
1237 * AutoInfo::            Automated Info Docs
1238 * AutoMan pages::       Automated Man Pages
1239 * getopt_long::         Using getopt(3C)
1240 * i18n::                Internationalizing AutoOpts
1241 * Naming Conflicts::    Naming Conflicts
1242 * All Attribute Names:: All Attribute Names
1243 * Option Define Names:: Option Definition Name Index
1244 @end menu
1245
1246 @c === SECTION MARKER
1247
1248 @node Features
1249 @section AutoOpts Features
1250 @cindex features
1251
1252 AutoOpts supports option processing; option state saving; and
1253 program documentation with innumerable features.  Here, we list
1254 a few obvious ones and some important ones, but the full list is
1255 really defined by all the attributes defined in the @ref{Option Definitions}
1256 section.
1257
1258 @enumerate
1259 @item
1260 POSIX-compliant short (flag) option processing.
1261
1262 @item
1263 GNU-style long options processing.  Long options
1264 are recognized without case sensitivity, and they may be abbreviated.
1265
1266 @item
1267 Environment variable initializations, @xref{environrc}.
1268
1269 @item
1270 Initialization from configuration files (aka RC or INI files), and
1271 saving the option state back into one, @xref{loading rcfile}.
1272
1273 @item
1274 Config files may be partitioned.  One config file may be used by several
1275 programs by partitioning it with lines containing,
1276 @code{[PROGRAM_NAME]} or @code{<?program-name>}, @xref{loading rcfile}.
1277
1278 @item
1279 Config files may contain AutoOpts directives.
1280 @code{<?auto-options [[option-text]]>}
1281 may be used to set @code{AutoOpts} option processing options.
1282 Viz., @acronym{GNU} usage layout versus @code{AutoOpts} conventional layout,
1283 and @code{misuse-usage} versus @code{no-misuse-usage}, @xref{usage attributes}.
1284
1285 @item
1286 Options may be marked as @code{@i{dis}-abled} with a disablement prefix.
1287 Such options may default to either an enabled or a disabled state.  You
1288 may also provide an enablement prefix, too, e.g., @option{--allow-mumble}
1289 and @option{--prevent-mumble} (@pxref{Common Attributes}).
1290
1291 @item
1292 Verify that required options are present between the minimum and maximum
1293 number of times on the command line.  Verify that conflicting options do not
1294 appear together.  Verify that options requiring the presence of other options
1295 are, in fact, used in the presence of other options.
1296 See @xref{Common Attributes}, and @xref{Option Conflict Attributes}.
1297
1298 @item
1299 There are several @ref{automatic options, automatically supported options}.
1300 They will have short flags if any options have option flags and the flags
1301 are not suppressed.  The associated flag may be altered or suppressed by
1302 specifying no value or an alternate character for @code{xxx-value;} in
1303 the option definition file.  @code{xxx} is the name of the option below:
1304
1305 @table @samp
1306 @item --help
1307 @itemx --more-help
1308 These are always available.  @samp{--more-help} will pass the full usage
1309 text through a pager.
1310 @item --usage
1311 @vindex usage-opt
1312 This is added to the option list if @code{usage-opt} is specified.
1313 It yields the abbreviated usage to @file{stdout}.
1314 @item --version
1315 This is added to the option list if @code{version = xxx;} is specified.
1316 @item --load-opts
1317 @itemx --save-opts
1318 These are added to the option list if @code{homerc} is specified.  Mostly.
1319 If, @code{disable-save} is specified, then @option{--save-opts} is disabled.
1320 @end table
1321
1322 @item
1323 Various forms of main procedures can be added to the output,
1324 @xref{Generated main}.  There are four basic forms:
1325
1326 @enumerate a
1327 @item
1328 A program that processes the arguments and writes to standard out
1329 portable shell commands containing the digested options.
1330
1331 @item
1332 A program that will generate portable shell commands to parse the defined
1333 options.  The expectation is that this result will be copied into a
1334 shell script and used there.
1335
1336 @item
1337 A @code{for-each} main that will invoke a named function once for either
1338 each non-option argument on the command line or, if there are none,
1339 then once for each non-blank, non-comment input line read from stdin.
1340
1341 @item
1342 A main procedure of your own design.  Its code can be supplied in the
1343 option description template or by incorporating another template.
1344 @end enumerate
1345
1346 @item
1347 There are several methods for handling option arguments.
1348 @itemize @bullet
1349 @item
1350 nothing (@pxref{OPT_ARG}) option argument strings are globally available.
1351 @item
1352 user supplied (@pxref{Option Argument Handling})
1353 @item
1354 stack option arguments (@pxref{Option Argument Handling})
1355 @item
1356 integer numbers (@pxref{arg-type number})
1357 @item
1358 true or false valued (@pxref{arg-type boolean})
1359 @item
1360 enumerated list of names (@pxref{arg-type keyword})
1361 @item
1362 an enumeration (membership) set (@pxref{arg-type set membership})
1363 @item
1364 a list of name/value pairs (option @code{subopts})
1365 (@pxref{arg-type hierarchy})
1366 @item
1367 a time duration or a specific time and date
1368 @item
1369 validated file name (@pxref{arg-type file name})
1370 @item
1371 optional option argument (@pxref{arg-optional})
1372 @end itemize
1373
1374 @item
1375 The generated usage text can be emitted in either AutoOpts standard format
1376 (maximizing the information about each option), or GNU-ish normal form.  The
1377 default form is selected by either specifying or not specifying the
1378 @code{gnu-usage} attribute (@pxref{information attributes}).  This can be
1379 overridden by the user himself with the @env{AUTOOPTS_USAGE} environment
1380 variable.  If it exists and is set to the string @samp{gnu}, it will force
1381 GNU-ish style format; if it is set to the string @samp{autoopts}, it will
1382 force AutoOpts standard format; otherwise, it will have no effect.
1383
1384 @item
1385 The usage text and many other strings are stored in a single character array
1386 (@pxref{SCM string-table-new,string table functions}).  This reduces fixup
1387 costs when loading the program or library.  The downside is that if GCC
1388 detects that any of these strings are used in a printf format, you may get the
1389 warning, @code{embedded '\0' in format}.  To eliminate the warning, you must
1390 provide GCC with the @option{-Wno-format-contains-nul} option.
1391
1392 @item
1393 If you compile with @code{ENABLE_NLS} defined and @code{_()} defined to a
1394 localization function (e.g. @code{gettext(3GNU)}), then the option processing
1395 code will be localizable (@pxref{i18n}).  Provided also that you do not define
1396 the @code{no-xlate} attribute to @emph{anything}
1397 (@pxref{presentation attributes}).
1398
1399 You should also ensure that the @code{ATTRIBUTE_FORMAT_ARG()} gets
1400 @code{#define}-ed to something useful.  There is an autoconf macro
1401 named @code{AG_COMPILE_FORMAT_ARG} in @file{ag_macros.m4} that will
1402 set it appropriately for you.  If you do not do this, then translated
1403 formatting strings may trigger GCC compiler warnings.
1404
1405 @item
1406 Provides a callable routine to parse
1407 a text string as if it were from one of the rc/ini/config files,
1408 hereafter referred to as a configuration file.
1409
1410 @item
1411 By adding a @samp{doc} and @samp{arg-name} attributes to each option,
1412 AutoGen will also be able to produce a man page and the @samp{invoking}
1413 section of a texinfo document.
1414
1415 @item
1416 Intermingled option processing.  AutoOpts options may be intermingled with
1417 command line operands and options processed with other parsing techniques.
1418 This is accomplished by setting the @code{allow-errors}
1419 (@pxref{program attributes}) attribute.  When processing reaches a point
1420 where @code{optionProcess} (@pxref{libopts-optionProcess}) needs to be called
1421 again, the current option can be set with @code{RESTART_OPT(n)}
1422 (@pxref{RESTART_OPT}) before calling @code{optionProcess}.
1423
1424 See: @xref{library attributes}.
1425
1426 @item
1427 Library suppliers can specify command line options that their
1428 client programs will accept.  They specify option definitions
1429 that get @code{#include}-d into the client option definitions
1430 and they specify an "anchor" option that has a callback and must be invoked.
1431 That will give the library access to the option state for their options.
1432
1433 @item
1434 library options.  An AutoOpt-ed library may export its options for use in
1435 an AutoOpt-ed program.  This is done by providing an option definition file
1436 that client programs @code{#include} into their own option definitions.
1437 See ``AutoOpt-ed Library for AutoOpt-ed Program'' (@pxref{lib and program})
1438 for more details.
1439 @end enumerate
1440
1441 @c === SECTION MARKER
1442
1443 @node Licensing
1444 @section AutoOpts Licensing
1445 @cindex Licensing
1446
1447 When AutoGen is installed, the AutoOpts project is installed with it.
1448 AutoOpts includes various AutoGen templates and a pair of shared
1449 libraries.  These libraries may be used under the terms of version 3
1450 of the GNU Lesser General Public License (LGPL).
1451
1452 One of these libraries (@code{libopts}) is needed by programs that are built
1453 using AutoOpts generated code.  This library is available as a separate
1454 ``tear-off'' source tarball.  It is redistributable for use under either of
1455 two licenses: The above mentioned GNU Lesser General Public License, and
1456 the advertising-clause-free BSD license.  Both of these license terms are
1457 incorporated into appropriate COPYING files included with the @code{libopts}
1458 source tarball.  This source may be incorporated into your package with
1459 the following simple commands:
1460
1461 @example
1462 rm -rf libopts libopts-*
1463 gunzip -c `autoopts-config libsrc` | \
1464    tar -xvf -
1465 mv libopts-*.*.* libopts
1466 @end example
1467
1468 View the @file{libopts/README} file for further integration information.
1469
1470 @c === SECTION MARKER
1471
1472 @page
1473 @node Caveats
1474 @section Developer and User Notes
1475
1476 The formatting of the usage message can be controlled with the use of the
1477 @env{AUTOOPTS_USAGE} environment variable.  If it contains any of five
1478 possible comma separated values, it will affect @file{libopts} behavior.
1479 Any extraneous or conflicting data will cause its value to be ignored.
1480
1481 If the program attributes @code{long-usage} and @code{short-usage} have been
1482 specified (@pxref{usage attributes,Usage and Version Info Display}), these
1483 strings are used for displaying full usage and abbreviated usage.
1484 ``Full usage'' is used when usage is requested, ``abbreviated usage''
1485 when a usage error is detected.  If these strings are not provided,
1486 the usage text is computed.
1487
1488 The @env{AUTOOPTS_USAGE} environment variable may be set to the comma and/or
1489 white space separated list of the following strings:
1490
1491 @table @samp
1492 @item compute
1493 Ignore the provision of @code{long-usage} and @code{short-usage} attributes,
1494 and compute the usage strings.  This is useful, for example, if you wish to
1495 regenerate the basic form of these strings and either tweak them or translate
1496 them.  The methods used to compute the usage text are not suitable for
1497 translation.
1498
1499 @item gnu
1500 @cindex gnu
1501 The format of the usage text will be displayed in GNU-normal form.
1502 The default display for @option{--version} will be to include a note
1503 on licensing terms.
1504
1505 @item autoopts
1506 @cindex autoopts
1507 The format of the extended usage will be in AutoOpts' native layout.  The
1508 default version display will be one line of text with the last token the
1509 version.  @code{gnu} and @code{autoopts} conflict and may not be used
1510 together.
1511
1512 @item no-misuse-usage
1513 @cindex no-misuse-usage
1514 When an option error is made on the command line, the abbreviated usage text
1515 will be suppressed.  An error message and the method for getting full usage
1516 information will be displayed.
1517
1518 @item misuse-usage
1519 @cindex misuse-usage
1520 When an option error is made on the command line, the abbreviated usage text
1521 will be shown.  @code{misuse-usage} and @code{no-misuse-usage} conflict and
1522 may not be used together.
1523 @end table
1524
1525 @code{misuse-usage} and @code{autoopts} are the defaults.
1526 These defaults may be flipped to @code{no-misuse-usage} and @code{gnu}
1527 by specifying @code{gnu-usage} and @code{no-misuse-usage}
1528 program attributes, respectively, in the option definition file.
1529
1530 @noindent
1531 @i{Note for developers}:
1532
1533 The templates used to implement AutoOpts depend heavily upon token pasting.
1534 That mens that if you name an option, @code{debug}, for example, the generated
1535 header will expect to be able to emit @code{#define} macros such as this:
1536 @example
1537 #define DESC(n) (autogenOptions.pOptDesc[INDEX_OPT_## n])
1538 @end example
1539 and expect @code{DESC(DEBUG)} to expand correctly into
1540 @code{(autogenOptions.pOptDesc[INDEX_OPT_DEBUG])}.
1541 If @code{DEBUG} is @code{#defined} to something else, then
1542 that something else will be in the above expansion.
1543
1544 If you discover you are having strange problems like this,
1545 you may wish to use some variation of the @code{guard-option-names}
1546 @xref{program attributes}.
1547
1548 @c === SECTION MARKER
1549
1550 @page
1551 @node Quick Start
1552 @section Quick Start
1553 @cindex example, simple AutoOpts
1554
1555 Since it is generally easier to start with a simple example than it is
1556 to look at the options that AutoGen uses itself, here is a very simple
1557 AutoOpts example.  You can copy this example out of the Info file and
1558 into a source file to try it.  You can then embellish it into what you
1559 really need.  For more extensive examples, you can also examine the help
1560 output and option definitions for the commands @command{columns},
1561 @command{getdefs} and @command{autogen} itself.
1562
1563 If you are looking for a more extensive example,
1564 you may search the autogen sources for files named @file{*opts.def}.
1565 @command{xml2ag} is ridiculous and @command{autogen} is very lengthy,
1566 but @command{columns} and @command{getdefs} are not too difficult.
1567 The @command{sharutils} sources are fairly reasonable, too.
1568
1569 @menu
1570 * quick ao problem::    Example option requirements
1571 * quick ao def::        Example option definitions
1572 * quick ao build::      Build the example options
1573 * quick ao help::       Example option help text
1574 * quick ao usage::      Using the example options
1575 * quick ao docs::       Example option documentation
1576 @end menu
1577
1578 @node quick ao problem
1579 @subsection Example option requirements
1580
1581 For our simple example, assume you have a program named @command{check}
1582 that takes two options:
1583
1584 @enumerate
1585 @item
1586 A list of directories to check over for whatever it is @command{check} does.
1587 You want this option available as a POSIX-style flag option
1588 and a GNU long option.  You want to allow as many of these
1589 as the user wishes.
1590 @item
1591 An option to show or not show the definition tree being used.
1592 Only one occurrence is to be allowed, specifying one or the other.
1593 @end enumerate
1594
1595 @node quick ao def
1596 @subsection Example option definitions
1597
1598 @noindent
1599 First, specify your program attributes and its options to AutoOpts,
1600 as with the following example.
1601
1602 @example
1603 @ignore
1604 END   == AUTOOPTS == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1605 Extraction from autogen.texi
1606 @end ignore
1607
1608 @ignore
1609 START == AUTOOPTS-MAIN == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
1610 Extraction from autogen.texi
1611 @end ignore
1612
1613 @node quick ao usage
1614 @subsection Using the example options
1615
1616 Normally, however, you would not use the @code{main} clause.  Instead,
1617 the file would be named something like @file{checkopt.def}, you would
1618 compile @file{checkopt.c} the usual way, and link the object with the rest
1619 of your program.
1620
1621 The options are processed by calling @code{optionProcess}
1622 (@pxref{libopts-optionProcess}):
1623
1624 @example
1625 main( int argc, char** argv )
1626 @{
1627   @{
1628     int optct = optionProcess( &checkOptions, argc, argv );
1629     argc -= optct;
1630     argv += optct;
1631   @}
1632 @end example
1633
1634 The options are tested and used as in the following fragment.
1635 @code{ENABLED_OPT} is used instead of @code{HAVE_OPT} for the
1636 @option{--show-defs} option because it is an enabled/disabled option type:
1637
1638 @example
1639   if (  ENABLED_OPT( SHOW_DEFS )
1640      && HAVE_OPT( CHECK_DIRS )) @{
1641     int    dirct = STACKCT_OPT( CHECK_DIRS );
1642     char** dirs  = STACKLST_OPT( CHECK_DIRS );
1643     while (dirct-- > 0) @{
1644       char* dir = *dirs++;
1645       ...
1646 @end example
1647
1648 @node quick ao docs
1649 @subsection Example option documentation
1650
1651 The @code{doc} clauses are used in the flag stanzas for man pages and texinfo
1652 invoking documentation.  With the definition file described above, the two
1653 following commands will produce the two documentation files @file{check.1} and
1654 @file{invoke-check.texi}.  The latter file will be generated as a chapter,
1655 rather than a section or subsection.
1656
1657 @example
1658 autogen -Tagman-cmd check.def
1659 autogen -DLEVEL=chapter -Tagtexi-cmd -binvoke-check.texi check.def
1660 @end example
1661
1662 @noindent
1663 The result of which is left as an exercise for the reader.
1664
1665 A lot of magic happens to make this happen.
1666 The rest of this chapter will describe the myriad of option attributes
1667 supported by AutoOpts.  However, keep in mind that, in general, you won't
1668 need much more than what was described in this "quick start" section.
1669
1670 @node Option Definitions
1671 @section Option Definitions
1672 @cindex Option Definitions
1673
1674 AutoOpts uses an AutoGen definitions file for the definitions of the
1675 program options and overall configuration attributes.
1676 The complete list of program and option attributes is quite extensive,
1677 so if you are reading to understand how to use AutoOpts, I recommend
1678 reading the "Quick Start" section (@pxref{Quick Start}) and paying
1679 attention to the following:
1680
1681 @enumerate
1682 @item
1683 @code{prog-name}, @code{prog-title}, and @code{argument}, program
1684 attributes, @xref{program attributes}.
1685 @item
1686 @code{name} and @code{descrip} option attributes, @xref{Required Attributes}.
1687 @item
1688 @code{value} (flag character) and @code{min} (occurrence counts)
1689 option attributes, @xref{Common Attributes}.
1690 @item
1691 @code{arg-type} from the option argument specification section,
1692 @xref{Option Arguments}.
1693 @item
1694 Read the overall how to, @xref{Using AutoOpts}.
1695 @item
1696 Highly recommended, but not required, are the several "man" and
1697 "info" documentation attributes, @xref{documentation attributes}.
1698 @end enumerate
1699
1700 Keep in mind that the majority are rarely used and can be safely
1701 ignored.  However, when you have special option processing requirements,
1702 the flexibility is there.
1703
1704 @menu
1705 * program attributes::          Program Description Attributes
1706 * library attributes::          Options for Library Code
1707 * information attributes::      Program Information Attributes
1708 * Generated main::              Generating main procedures
1709 * option attributes::           Option Attributes
1710 * Option Arguments::            Option Argument Specification
1711 * Option Argument Handling::    Option Argument Handling
1712 * Internationalizing Options::  Internationalizing Options
1713 * documentation attributes::    Man and Info doc Attributes
1714 * automatic options::           Automatically Supported Options
1715 * standard options::            Library of Standard Options
1716 @end menu
1717
1718 @node program attributes
1719 @subsection Program Description Attributes
1720 @cindex program attributes
1721
1722 The following global definitions are used to define attributes of the entire
1723 program.  These generally alter the configuration or global behavior of the
1724 AutoOpts option parser.  The first two are required of every program.  The
1725 third is required if there are to be any left over arguments (operands)
1726 after option processing.  The rest have been grouped below.  Except as noted,
1727 there may be only one copy of each of these definitions:
1728
1729 @table @samp
1730
1731 @item prog-name
1732 @vindex prog-name
1733 This attribute is required.  Variable names derived from this name
1734 are derived using @code{string->c_name!} (@pxref{SCM string->c-name!}).
1735
1736 @item prog-title
1737 @vindex prog-title
1738 This attribute is required and may be any descriptive text.
1739
1740 @item argument
1741 @vindex argument
1742 This attribute is required if your program uses operand arguments.
1743 It specifies the syntax of the arguments that @strong{follow} the options.
1744 It may not be empty, but if it is not supplied, then option processing
1745 must consume all the arguments.  If it is supplied and starts with an
1746 open bracket (@code{[}), then there is no requirement on the presence or
1747 absence of command line arguments following the options.  Lastly, if it
1748 is supplied and does not start with an open bracket, then option
1749 processing must @strong{not} consume all of the command line arguments.
1750
1751 @item config-header
1752 @vindex config-header
1753 If your build has a configuration header, it must be included before
1754 anything else.  Specifying the configuration header file name with this
1755 attribute will cause that to happen.
1756 @end table
1757
1758 @menu
1759 * usage attributes::            Usage and Version Info Display
1760 * config attributes::           Program Configuration
1761 * programming attributes::      Programming Details
1762 * presentation attributes::     User Presentation Attributes
1763 @end menu
1764
1765 @c
1766 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1767 @c
1768 @node usage attributes
1769 @subsubsection Usage and Version Info Display
1770
1771 These will affect the way usage is seen and whether or not version
1772 information gets displayed.
1773
1774 @table @samp
1775 @item full-usage
1776 @vindex full-usage
1777 If this attribute is provided, it may specify the full length
1778 usage text, or a variable name assignable to a @code{char const *} pointer,
1779 or it may be empty.  The meanings are determined by  the length.
1780 @itemize @bullet
1781 @item
1782 If not provided, the text will be computed as normal.
1783 @item
1784 If the length is zero, then the usage text will be derived from
1785 the current settings and inserted as text into the generated .c file.
1786 @item
1787 If the length is 1 to 32 bytes, then it is presumed to be a variable
1788 name that either points to or is an array of const chars.
1789 @item
1790 If it is longer than that, it is presumed to be the help text itself.
1791 This text will be inserted into the generated .c file.
1792 @end itemize
1793
1794 This string should be readily translatable.  Provision will be made
1795 to translate it if this is provided, if the source code is compiled with
1796 @code{ENABLE_NLS} defined, and @code{no-xlate} has not been set to the
1797 value @emph{anything}.  The untranslated text will be handed to
1798 @code{dgettext("libopts", @i{txt})} and then @code{gettext(@i{txt})}
1799 for translation, one paragraph at a time.
1800
1801 To facilitate the creation and maintenance of this text, you can
1802 force the string to be ignored and recomputed by specifying
1803 @example
1804 AUTOOPTS_USAGE=compute
1805 @end example
1806 @noindent
1807 in the environment and requesting help or usage information.
1808 See @xref{Caveats, Developer and User Notes}.
1809
1810 @item short-usage
1811 @vindex short-usage
1812 If this attribute is provided, it is used to specify an abbreviated
1813 version of the usage text.  This text is constructed in the same way
1814 as the @code{full-usage}, described above.
1815
1816 @item gnu-usage
1817 @vindex gnu-usage
1818 AutoOpts normaly displays usage text in a format that provides more
1819 information than the standard GNU layout, but that also means it is
1820 not the standard GNU layout.  This attribute changes the default to
1821 GNU layout, with the @env{AUTOOPTS_USAGE} environment variable used
1822 to request @code{autoopts} layout.
1823 See @xref{Caveats, Developer and User Notes}.
1824
1825 @item usage-opt
1826 @vindex usage-opt
1827 I apologize for too many confusing usages of usage.
1828 This attribute specifies that @option{--usage} and/or @option{-u} be
1829 supported.  The help (usage) text displayed will be abbreviated
1830 when compared to the default help text.
1831
1832 @item no-misuse-usage
1833 @vindex no-misuse-usage
1834 When there is a command line syntax error, by default AutoOpts will
1835 display the abbreviated usage text, rather than just a one line
1836 ``you goofed it, ask for usage'' message.  You can change the default
1837 behavior for your program by supplying this attribute.  The user may
1838 override this choice, again, with the @env{AUTOOPTS_USAGE} environment
1839 variable.  See @xref{Caveats, Developer and User Notes}.
1840
1841 @item prog-group
1842 @vindex prog-group
1843 The version text in the @file{getopt.tpl} template will include this
1844 text in parentheses after the program name, when this attribute is specified.
1845 For example:
1846 @example
1847 mumble (stumble) 1.0
1848 @end example
1849 @noindent
1850 says that the @samp{mumble} program is version 1.0 and is part of the
1851 @samp{stumble} group of programs.
1852
1853 @item usage
1854 @vindex usage
1855 If your program has some cleanup work that must be done before exiting
1856 on usage mode issues, or if you have to customize the usage message in
1857 some way, specify this procedure and it will be called instead of the
1858 default @code{optionUsage()} function.  For example, if a program is
1859 using the curses library and needs to invoke the usage display, then
1860 you must arrange to call @code{endwin()} before invoking the library
1861 function @code{optionUsage()}.  This can be handled by specifying your
1862 own usage function, thus:
1863 @example
1864 void
1865 my_usage(tOptions * opts, int ex)
1866 @{
1867     if (curses_window_active)
1868         endwin();
1869     optionUsage(opts, ex);
1870 @}
1871 @end example
1872
1873 @item version
1874 @vindex version
1875 Specifies the program version and activates the VERSION option,
1876 @xref{automatic options}.
1877 @end table
1878
1879 @c
1880 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1881 @c
1882 @node config attributes
1883 @subsubsection Program Configuration
1884
1885 Programs may be ``pre-configured'' before normal command line options
1886 are processed (See @pxref{Immediate Action, Immediate Action Attributes}).
1887 How configuration files and environment variables are handled get
1888 specified with these attributes.
1889
1890 @table @samp
1891 @item disable-load
1892 @itemx disable-save
1893 @vindex disable-load
1894 @vindex disable-save
1895 Indicates that the command line usage of @option{--load-opts} and/or
1896 @option{--save-opts} are disallowed.
1897
1898 @item environrc
1899 @vindex environrc
1900 Indicates looking in the environment for values of variables named,
1901 @env{PROGRAM_OPTNAME} or @env{PROGRAM}, where @env{PROGRAM} is the
1902 upper cased @var{C-name} of the program and @samp{OPTNAME} is the
1903 upper cased @var{C-name} of a specific option.  The contents of
1904 the @env{PROGRAM} variable, if found, are tokenized and processed.
1905 The contents of @env{PROGRAM_OPTNAME} environment variables are taken
1906 as the option argument to the option nameed @option{--optname}.
1907
1908 @item homerc
1909 @vindex homerc
1910 Specifies that option settings may be loaded from and stored into
1911 configuration files.  Each instance of this attribute is either a directory
1912 or a file using a specific path, a path based on an environment variable or
1913 a path relative to installation directories.  The method used depends on
1914 the name.  If the one entry is empty, it enables the loading and storing of
1915 settings, but no specific files are searched for.  Otherwise, a series of
1916 configuration files are hunted down and, if found, loaded.
1917
1918 If the first character of the @samp{homerc} value is not the dollar
1919 character (@code{$}), then it is presumed to be a path name based on the
1920 current directory.  Otherwise, the method depends on the second character:
1921
1922 @table @code
1923 @item $
1924 The path is relative to the directory where the executable was found.
1925 @item @@
1926 The path is relative to the package data directory, e.g.
1927 @file{/usr/local/share/autogen}.
1928 @item [a-zA-Z]
1929 The path is derived from the named environment variable.
1930 @end table
1931
1932 Use as many as you like.  The presence of this attribute
1933 activates the @option{--save-opts} and @option{--load-opts} options.
1934 However, saving into a file may be disabled with the @samp{disable-save}.
1935 @xref{loading rcfile}.
1936 See the @code{optionMakePath(3AGEN)} man page for excruciating details.
1937
1938 @item rcfile
1939 @vindex rcfile
1940 Specifies the configuration file name.  This is only useful if you
1941 have provided at least one @code{homerc} attribute.
1942 @example
1943 default: .<prog-name>rc
1944 @end example
1945
1946 @item vendor-opt
1947 @vindex vendor-opt
1948 This option implements the @option{-W} vendor option command line option.
1949
1950 For POSIX specified utilities, the options are constrained to the options
1951 that are specified by POSIX.  Extensions should be handled with @option{-W}
1952 command line options, the short flag form.  Long option name processing
1953 must be disabled.  In fact, the @code{long-opts} attribute must not be
1954 provided, and some options must be specified without flag values.
1955
1956 The @option{-W long-name} is processed by looking up the long option
1957 name that follows it.  It cannot be a short flag because that would
1958 conflict with the POSIX flag name space.  It will be processed as if
1959 long options were accepted and @option{--long-name} were found on the
1960 command line.
1961 @end table
1962
1963 @c
1964 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1965 @c
1966 @node programming attributes
1967 @subsubsection Programming Details
1968
1969 These attributes affect some of the ways that the option data are
1970 used and made available to the program.
1971
1972 @table @samp
1973 @item config-header
1974 @vindex config-header
1975 The contents of this attribute should be just the name of the configuration
1976 file.  A "#include" naming this file will be inserted at the top of the
1977 generated header.
1978
1979 @item exit-name
1980 @itemx exit-desc
1981 @vindex exit-name
1982 @vindex exit-desc
1983 These values should be defined as indexed values, thus:
1984 @example
1985 exit-name[0] = success;
1986 exit-desc[0] = 'Successful program execution.';
1987 exit-name[1] = failure;
1988 exit-desc[1] = 'The operation failed or command syntax was not valid.';
1989 @end example
1990 By default, all programs have these effectively defined for them.
1991 They may be overridden by explicitly defining any or all of these values.
1992 Additional names and descriptions may be defined.
1993 They will cause an enumeration to be emitted, like this one
1994 for @command{getdefs}:
1995 @example
1996 typedef enum @{
1997     GETDEFS_EXIT_SUCCESS = 0,
1998     GETDEFS_EXIT_FAILURE = 1
1999 @} getdefs_exit_code_t;
2000 @end example
2001 @noindent
2002 which will be augmented by any @code{exit-name} definitions beyond @samp{1}.
2003
2004 Some of the generated code will exit non-zero if there is an allocation error.
2005 This exit will always be code @samp{1}, unless there is an exit named @samp{no_mem}
2006 or @samp{nomem}.  In that case, that value will be used.  Additionally, if
2007 there is such a value, and if @code{die-code} is specified, then a function
2008 @code{nomem_err(size_t len, char const * what)} will be emitted as an inline
2009 function for reporting out-of-memory conditions.
2010
2011 @item usage-message
2012 @vindex usage-message
2013 This attribute will cause two procedures to be added to the code file:
2014 @code{usage_message()} and @code{vusage_message()}, with any applicable prefix
2015 (see @code{prefix}, below).  They are declared in the
2016 generated header, thus:
2017 @example
2018 noreturn extern void vusage_message(char const * fmt, va_list ap);
2019 noreturn extern void usage_message(char const * fmt, ...);
2020 @end example
2021 @noindent
2022 These functions print the message to @file{stderr} and invoke the usage
2023 function with the exit code set to @code{1} (@code{EXIT_FAILURE}).
2024
2025 @item die-code
2026 @vindex die-code
2027 This tells AutoOpts templates to emit code for @code{vdie()}, @code{die()},
2028 @code{fserr()}, and, possibly the @code{nomem_err()} functions.  The latter is
2029 emitted if an exit name of @samp{no-mem} or @samp{nomem} is specified.  If the
2030 @code{die-code} is assigned a text value, then that code will be inserted in
2031 the @code{vdie} function immediately before it prints the death rattle
2032 message.
2033
2034 The profiles for these functions are:
2035 @example
2036 noreturn extern void vdie( int exit_code, char const * fmt, va_list);
2037 noreturn extern void die(  int exit_code, char const * fmt, ...);
2038 noreturn extern void fserr(int exit_code, char const * op, char const * fname);
2039 noreturn static inline void
2040 nomem_err(size_t sz, char const * what) @{...@}
2041 @end example
2042
2043 @item export
2044 @vindex export
2045 This string is inserted into the .h interface file.  Generally used for
2046 global variables or @code{#include} directives required by
2047 @code{flag-code} text and shared with other program text.
2048 Do not specify your configuration header (@file{config.h}) in this
2049 attribute or the @code{include} attribute.  Instead, use
2050 @code{config-header}, above.
2051
2052 @item guard-option-names
2053 @vindex guard-option-names
2054 AutoOpts generates macros that presume that there are no @command{cpp} macros
2055 with the same name as the option name.  For example, if you have an option
2056 named, @option{--debug}, then you must not use @code{#ifdef DEBUG} in your
2057 code.  If you specify this attribute, every option name will be guarded.  If
2058 the name is @code{#define}-d, then a warning will be issued and the name
2059 undefined.  If you do not specify this and there is a conflict, you will get
2060 strange error messages.
2061
2062 This attribute may be set to any of four recognized states:
2063
2064 @itemize @bullet
2065 @item
2066 Not defined.  AutoOpts will behave as described above.
2067
2068 @item
2069 Defined, but set to the empty string.  Text will be emitted into the header
2070 to undefine (@code{#undef}) any conflicting preprocessor macros.  The code
2071 will include compiler warnings (via @code{#warning}).  Some compilers are
2072 not ANSI-C-99 compliant yet and will error out on those warnings.  You may
2073 compile with @option{-DNO_OPTION_NAME_WARNINGS} to silence or mostly silence
2074 them.
2075
2076 @item
2077 Defined and set to the string, @code{no-warning}.  All of the needed
2078 @code{#undef}s will be emitted, without any conflict checking @code{#warning}
2079 directives emitted.
2080
2081 @item
2082 Defined and set to the string, @code{full-enum}.  The option manipulation
2083 preprocessor macros will not token paste the option names to the index
2084 enumeration prefix.  e.g. you will need to use @code{HAVE_OPT(INDEX_OPT_DEBUG)}
2085 instead of @code{HAVE_OPT(DEBUG)}.
2086 @end itemize
2087
2088 @item include
2089 @vindex include
2090 This string is inserted into the .c file.  Generally used for global
2091 variables required only by @code{flag-code} program text.
2092
2093 @item no-libopts
2094 @vindex no-libopts
2095 If you are going to handle your option processing with the @file{getopt.tpl}
2096 template instead of using libopts, then specify this attribute.  It will
2097 suppress mention of @option{--more-help} in the generated documentation.
2098 (@code{getopt_long} does not support @option{--more-help}.)
2099
2100 @item prefix
2101 @vindex prefix
2102 This value is inserted into @strong{all} global names.  This will
2103 disambiguate them if more than one set of options are to be compiled
2104 into a single program.
2105 @end table
2106
2107 @c
2108 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2109 @c
2110 @node presentation attributes
2111 @subsubsection User Presentation Attributes
2112
2113 Attributes that affect the user's experience.
2114
2115 @table @samp
2116 @item allow-errors
2117 @vindex allow-errors
2118 The presence of this attribute indicates ignoring any command line
2119 option errors.  This may also be turned on and off by invoking the
2120 macros @code{ERRSKIP_OPTERR} and @code{ERRSTOP_OPTERR} from the
2121 generated interface file.
2122
2123 @item long-opts
2124 @vindex long-opts
2125 @cindex named option mode
2126 Presence indicates GNU-standard long option processing.  Partial name
2127 matches are accepted, if they are at least two characters long and the
2128 partial match is unique.  The matching is not case sensitive, and the
2129 underscore, hyphen and carat characters are all equivalent (they match).
2130
2131 If any options do not have an option value (flag character) specified,
2132 and least one does specify such a value, then you must specify
2133 @code{long-opts}.  If none of your options specify an option value
2134 (flag character) and you do not specify @code{long-opts}, then command
2135 line arguments are processed in "named option mode".  This means that:
2136
2137 @itemize @bullet
2138 @item
2139 Every command line argument must be a long option.
2140 @item
2141 The flag markers @option{-} and @option{--} are completely optional.
2142 @item
2143 The @code{argument} program attribute is disallowed.
2144 @item
2145 One of the options may be specified as the default
2146 (as long as it has a required option argument).
2147 @end itemize
2148
2149 @item no-xlate
2150 @vindex no-xlate
2151 Modifies when or whether option names get translated.  If provided,
2152 it must be assigned one of these values:
2153 @table @samp
2154 @item opt-cfg
2155 to suppress option name translation for configuration file and and environment
2156 variable processing.
2157 @item opt
2158 to suppress option name translation completely.  The usage text will
2159 always be translated if @code{ENABLE_NLS} is defined and you have
2160 translations for that text.
2161 @item anything
2162 Specifies disabling all internationalization support for option code, completely.
2163 @end table
2164 See also the various @code{XLAT} interface entries in the
2165 AutoOpts Programmatic Interface section (@pxref{AutoOpts API}).
2166
2167 @item reorder-args
2168 @vindex reorder-args
2169 Normally, POSIX compliant commands do not allow for options to be interleaved
2170 with operands.  If this is necessary for historical reasons, there are two
2171 approaches available:
2172 @itemize @bullet
2173 @item
2174 Allow @code{optionProcess} to return the index of the operand like it normally
2175 does and process the operand(s).  When an operand is encountered that starts
2176 with a hyphen, then set the AutoOpts current index with the @code{RESTART_OPT}
2177 macro (see @pxref{RESTART_OPT}), and re-invoke @code{optionProcess}.  This
2178 will also allow you to process the operands in context.
2179
2180 @item
2181 Specify this attribute.  AutoOpts will re-order the command arguments
2182 so that the operands appear (in the original order) at the end of
2183 the argument list.  Differing configuration state is not possible
2184 to detect after all options have been processed.
2185 @end itemize
2186
2187 @item resettable
2188 @vindex resettable
2189 Specifies that the @option{--reset-option} command line option is to be
2190 supported.  This makes it possible to suppress any setting that might be
2191 found in a configuration file or environment variable.
2192 @end table
2193
2194 @node library attributes
2195 @subsection Options for Library Code
2196 @cindex library attributes
2197
2198 Some libraries provide their own code for processing command line
2199 options, and this may be used by programs that utilize AutoOpts.
2200 You may also wish to write a library that gets configured with AutoOpts
2201 options and config files.  Such a library may either supply its own
2202 configury routine and process its own options, or it may export its
2203 option descriptions to programs that also use AutoOpts.  This section
2204 will describe how to do all of these different things.
2205
2206 @menu
2207 * lib and program::         AutoOpt-ed Library for AutoOpt-ed Program
2208 * lib called::              AutoOpt-ed Library for Regular Program
2209 * prog calls lib::          AutoOpt-ed Program Calls Regular Library
2210 @end menu
2211
2212 @node lib and program
2213 @subsubsection AutoOpt-ed Library for AutoOpt-ed Program
2214
2215 The library source code must provide an option definition file that consists
2216 of only the attribute @code{library}
2217 @vindex library
2218 and @code{flag} entries.  The @code{library} attribute does not need any
2219 associated value, so it will generally appeary by itself on a line folowed
2220 by a semi-colon.  The first @code{flag} entry must contain the following
2221 attributes:
2222
2223 @table @samp
2224 @item name
2225 This name is used in the construction of a global pointer of type
2226 @code{tOptDesc const*}.  It is always required.
2227 @item documentation
2228 @vindex documentation
2229 It tells @code{AutoOpts} that this option serves no normal purpose.
2230 It will be used to add usage clarity and to locate option descriptors
2231 in the library code.
2232 @item descrip
2233 This is a string that is inserted in the extended usage display
2234 before the options specific to the current library.  It is always required.
2235 @item lib-name
2236 @vindex lib-name
2237 This should match the name of the library.  This string is also used in
2238 the construction of the option descriptor pointer name.  In the end, it
2239 looks like this:
2240 @example
2241 extern tOptDesc const* <<lib-name>>_<<name>>_optDesc_p;
2242 @end example
2243 @noindent
2244 and is used in the macros generated for the library's @file{.h} file.
2245 @end table
2246
2247 In order to compile this @code{AutoOpts} using library, you must create a
2248 special header that is not used by the client program.  This is accomplished
2249 by creating an option definition file that contains essentially exactly the
2250 following:
2251
2252 @example
2253 AutoGen definitions options;
2254 prog-name  = does-not-matter;  // but is always required
2255 prog-title = 'also does not matter';  // also required
2256 config-header = 'config.h'; // optional, but common
2257 library;
2258 #include library-options-only.def
2259 @end example
2260
2261 @noindent
2262 and nothing else.  AutoGen will produce only the @file{.h} file.
2263 You may now compile your library, referencing just this @file{.h} file.
2264 The macros it creates will utilize a global variable that will be defined
2265 by the @code{AutoOpts}-using client program.  That program will need to
2266 have the following @code{#include} in @i{its} option definition file:
2267
2268 @example
2269 #include library-options-only.def
2270 @end example
2271
2272 @noindent
2273 All the right things will magically happen so that the global variables
2274 named @var{<<lib-name>>_<<name>>_optDesc_p} are initialized correctly.
2275 For an example, please see the @code{AutoOpts} test script:
2276 @file{autoopts/test/library.test}.
2277
2278 @node lib called
2279 @subsubsection AutoOpt-ed Library for Regular Program
2280
2281 In this case, your library must provide an option processing function
2282 to a calling program.  This is accomplished by setting the @code{allow-errors}
2283 global option attribute.  Each time your option handling function is called,
2284 you must determine where your scan is to resume and tell the AutoOpts library
2285 by invoking:
2286
2287 @example
2288 RESTART_OPT(next_arg_index);
2289 @end example
2290
2291 @noindent
2292 and then invoke @code{not_opt_index = optionProcess(...)}.
2293 The @code{not_opt_index} value can be used to set @code{optind},
2294 if that is the global being used to scan the program argument array.
2295
2296 In this method, do @strong{NOT} utilize the global @code{library} attribute.
2297 Your library must specify its options as if it were a complete program.
2298 You may choose to specify an alternate @code{usage()} function so that
2299 usage for other parts of the option interface may be displayed as well.
2300 See ``Program Information Attributes'' (@pxref{information attributes}).
2301
2302 At the moment, there is no method for calling @code{optionUsage()} telling
2303 it to produce just the information about the options and not the program
2304 as a whole.  Some later revision after somebody asks.
2305
2306 @node prog calls lib
2307 @subsubsection AutoOpt-ed Program Calls Regular Library
2308
2309 As with providing an @code{AutoOpt}-ed library to a non-@code{AutoOpt}-ed
2310 program, you must write the option description file as if you were writing
2311 all the options for the program, but you should specify the
2312 @code{allow-errors} global option attribute and you will likely want an
2313 alternate @code{usage()} function (see ``Program Information Attributes''
2314 @pxref{information attributes}).  In this case, though, when
2315 @code{optionProcess()} returns, you need to test to see if there might be
2316 library options.  If there might be, then call the library's exported
2317 routine for handling command line options, set the next-option-to-process
2318 with the @code{RESTART_OPT()} macro, and recall @code{optionProcess()}.
2319 Repeat until done.
2320
2321 @node information attributes
2322 @subsection Program Information Attributes
2323 @cindex information attributes
2324
2325 These attributes are used to define how and what information is displayed
2326 to the user of the program.
2327
2328 @table @samp
2329 @item copyright
2330 @vindex copyright
2331 The @code{copyright} is a structured value containing three to five
2332 values.  If @code{copyright} is used, then the first three are required.
2333
2334 @enumerate
2335 @item
2336 @vindex date
2337 @file{date} - the list of applicable dates for the copyright.
2338 @item
2339 @vindex owner
2340 @file{owner} - the name of the copyright holder.
2341 @item
2342 @vindex type
2343 @file{type} - specifies the type of distribution license.
2344 AutoOpts/AutoGen supports the text of the GNU Public License (@file{gpl}),
2345 the GNU Lesser General Public License with Library extensions
2346 (@file{lgpl}), the Modified Free BSD license (@file{mbsd}) and a few others.
2347 Other licenses may be specified, but you must provide your own license file.
2348 The list of license files provided by AutoOpts may be seen by typing:
2349 @example
2350 ls $(autoopts-config pkgdatadir)/*.lic
2351 @end example
2352 @item
2353 @vindex text
2354 @file{text} - the text of the copyright notice.  This must be provided
2355 if @file{type} is set to @file{NOTE}.
2356 @item
2357 @vindex author
2358 @file{author} - in case the author name is to appear in the documentation
2359 and is different from the copyright owner.
2360 @item
2361 @vindex eaddr
2362 @file{eaddr} - email address for receiving praises and complaints.
2363 Typically that of the author or copyright holder.
2364 @end enumerate
2365 @*
2366 An example of this might be:
2367 @example
2368 copyright = @{
2369     date  = "1992-2015";
2370     owner = "Bruce Korb";
2371     eaddr = 'bkorb@@gnu.org';
2372     type  = GPL;
2373 @};
2374 @end example
2375
2376 @item detail
2377 @vindex detail
2378 This string is added to the usage output when the HELP option is
2379 selected.
2380
2381 @item explain
2382 @vindex explain
2383 Gives additional information whenever the usage routine is invoked.
2384
2385 @item package
2386 @vindex package
2387 The name of the package the program belongs to.  This will appear
2388 parenthetically after the program name in the version and usage output,
2389 e.g.:  @code{autogen @i{(GNU autogen)} - The Automated Program Generator}.
2390
2391 @item preserve-case
2392 @vindex preserve-case
2393 This attribute will not change anything except appearance.  Normally, the
2394 option names are all documented in lower case.  However, if you specify this
2395 attribute, then they will display in the case used in their specification.
2396 Command line options will still be matched without case sensitivity.
2397 This is useful for specifying option names in camel-case.
2398
2399 @item prog-desc @strong{and}
2400 @itemx opts-ptr
2401 @vindex prog-desc
2402 @vindex opts-ptr
2403 These define global pointer variables that point to the program
2404 descriptor and the first option descriptor for a library option.  This
2405 is intended for use by certain libraries that need command line and/or
2406 initialization file option processing.  These definitions have no effect
2407 on the option template output, but are used for creating a library
2408 interface file.  Normally, the first "option" for a library will be a
2409 documentation option that cannot be specified on the command line, but
2410 is marked as @code{settable}.  The library client program will invoke the
2411 @code{SET_OPTION} macro which will invoke a handler function that will
2412 finally set these global variables.
2413
2414 @item usage
2415 @vindex usage
2416 Optionally names the usage procedure, if the library routine
2417 @code{optionUsage()} does not work for you.  If you specify
2418 @code{my_usage} as the value of this attribute, for example, you will
2419 use a procedure by that name for displaying usage.  Of course, you will
2420 need to provide that procedure and it must conform to this profile:
2421 @example
2422 void @i{my_usage}( tOptions* pOptions, int exitCode )
2423 @end example
2424
2425 @item gnu-usage
2426 @vindex gnu-usage
2427 Normally, the default format produced by the @code{optionUsage} procedure
2428 is @i{AutoOpts Standard}.  By specifying this attribute, the default format
2429 will be @i{GNU-ish style}.  Either default may be overridden by the user with
2430 the @env{AUTOOPTS_USAGE} environment variable.  If it is set to @code{gnu}
2431 or @code{autoopts}, it will alter the style appropriately.  This attribute
2432 will conflict with the @code{usage} attribute.
2433
2434 @item reorder-args
2435 @vindex reorder-args
2436 Some applications traditionally require that the command operands be
2437 intermixed with the command options.  In order to handle that, the arguments
2438 must be reordered.  If you are writing such an application, specify this
2439 global option.  All of the options (and any associated option arguments)
2440 will be brought to the beginning of the argument list.  New applications
2441 should not use this feature, if at all possible.  This feature is
2442 @i{disabled} if @env{POSIXLY_CORRECT} is defined in the environment.
2443 @end table
2444
2445 @node Generated main
2446 @subsection Generating main procedures
2447 @cindex main procedure
2448
2449 When AutoOpts generates the code to parse the command line options, it has
2450 the ability to produce any of several types of @code{main()} procedures.
2451 This is done by specifying a global structured value for
2452 @vindex main
2453 @code{main}.  The values that it contains are dependent on the value set for
2454 the one value it must have: @code{main-type}.
2455
2456 @vindex main-type
2457 The recognized values for @code{main-type} are @code{guile},
2458 @code{shell-process}, @code{shell-parser}, @code{main}, @code{include},
2459 @code{invoke}, and @code{for-each}.
2460
2461 @menu
2462 * main guile::              guile: main and inner_main procedures
2463 * main shell-process::      shell-process: emit Bourne shell results
2464 * main shell-parser::       shell-parser: emit Bourne shell script
2465 * main main::               main: user supplied main procedure
2466 * main include::            include: code emitted from included template
2467 * main invoke::             invoke: code emitted from AutoGen macro
2468
2469 The @code{for-each} main  procedure has a number of attributes that
2470 must be specified:
2471
2472 * main for-each::           for-each: perform function on each operand
2473 * main-for-each-proc::          procedure to handle each argument
2474 * main-for-each-type::          handler procedure type
2475 * main-for-each-code::          code for handler procedure
2476 * main-for-each-opts::          for-each main procedure options
2477 @end menu
2478
2479 @node main guile
2480 @subsubsection guile: main and inner_main procedures
2481
2482 When the @code{main-type} is specified to be @code{guile},
2483 a @code{main()} procedure is generated that calls @code{gh_enter()}, providing
2484 it with a generated @code{inner_main()} to invoke.  If you must perform
2485 certain tasks before calling @code{gh_enter()}, you may specify such code
2486 in the value for the
2487 @vindex before-guile-boot
2488 @code{before-guile-boot} attribute.
2489
2490 The @code{inner_main()} procedure itself will process the command line
2491 arguments (by calling @code{optionProcess()},
2492 @pxref{libopts-optionProcess}), and then either invoke the code
2493 specified with the
2494 @vindex guile-main
2495 @code{guile-main} attribute, or else export the parsed options to Guile
2496 symbols and invoke the @code{scm_shell()} function from the Guile library.
2497 This latter will render the program nearly identical to the stock
2498 @code{guile(1)} program.
2499
2500 @node main shell-process
2501 @subsubsection shell-process: emit Bourne shell results
2502
2503 This will produce a @code{main()} procedure that parses the command line
2504 options and emits to @file{stdout} Bourne shell commands that puts the
2505 option state into environment variables.  This can be used within a
2506 shell script as follows:
2507
2508 @example
2509 unset OPTION_CT
2510 eval "`opt_parser \"$@@\"`"
2511 test $@{OPTION_CT@} -gt 0 && shift $@{OPTION_CT@}
2512 @end example
2513
2514 If the option parsing code detects an error or a request for usage or version,
2515 it will emit a command to exit with an appropriate exit code to @file{stdout}.
2516 This form of @code{main} will cause all messages, including requested usage
2517 and version information, to be emitted to @file{stderr}.  Otherwise, a numeric
2518 value for @code{OPTION_CT} is guaranteed to be emitted, along with assignments
2519 for all the options parsed, something along the lines of the following will be
2520 written to @file{stdout} for evaluation:
2521
2522 @example
2523 OPTION_CT=4
2524 export OPTION_CT
2525 MYPROG_SECOND='first'
2526 export MYPROG_SECOND
2527 MYPROG_ANOTHER=1 # 0x1
2528 export MYPROG_ANOTHER
2529 @end example
2530
2531 @noindent
2532 If the arguments are to be reordered, however, then the resulting set
2533 of operands will be emitted and @env{OPTION_CT} will be set to zero.
2534 For example, the following would be appended to the above:
2535
2536 @example
2537 set -- 'operand1' 'operand2' 'operand3'
2538 OPTION_CT=0
2539 @end example
2540
2541 @noindent
2542 @env{OPTION_CT} is set to zero since it is not necessary to shift
2543 off any options.
2544
2545 @node main shell-parser
2546 @subsubsection shell-parser: emit Bourne shell script
2547
2548 This will produce a @code{main()} procedure that emits a shell script
2549 that will parse the command line options.  That script can be emitted
2550 to @file{stdout} or inserted or substituted into a pre-existing shell
2551 script file.  Improbable markers are used to identify previously inserted
2552 parsing text:
2553
2554 @example
2555 # # # # # # # # # # -- do not modify this marker --
2556 @end example
2557
2558 @noindent
2559 The program is also pretty insistent upon starting its parsing script
2560 on the second line.
2561
2562 @node main main
2563 @subsubsection main: user supplied main procedure
2564
2565 You must supply a value for the @code{main-text} attribute.
2566 You may also supply a value for
2567 @vindex option-code
2568 @code{option-code}.  If you do, then the @code{optionProcess} invocation
2569 will not be emitted into the code.  AutoOpts will wrap the @code{main-text}
2570 inside of:
2571
2572 @example
2573 int
2574 main( int argc, char** argv )
2575 @{
2576     int res = <<success-exit-code>>;
2577     @{ // replaced by option-code, if that exists
2578         int ct = optionProcess( &<<prog-name>>Options, argc, argv);
2579         argc -= ct;
2580         argv += ct;
2581     @}
2582 <<main-text>>
2583     return res;
2584 @}
2585 @end example
2586
2587 @noindent
2588 so you can most conveniently set the value with a @code{here string}
2589 (@pxref{here-string}):
2590
2591 @example
2592 code = <<- _EndOfMainProc_
2593         <<your text goes here>>
2594         _EndOfMainProc_;
2595 @end example
2596
2597 @node main include
2598 @subsubsection include: code emitted from included template
2599
2600 You must write a template to produce your main procedure.
2601 You specify the name of the template with the @code{tpl} attribute
2602 and it will be incorporated at the point where AutoOpts is ready
2603 to emit the @code{main()} procedure.
2604
2605 This can be very useful if, in your working environment, you have
2606 many programs with highly similar @code{main()} procedures.  All you need
2607 to do is parameterize the variations and specify which variant is needed
2608 within the @code{main} AutoOpts specification.  Since you are coding
2609 the template for this, the attributes needed for this variation would
2610 be dictated by your template.
2611
2612 Here is an example of an @code{include} variation:
2613
2614 @example
2615 main = @{
2616   main-type = include;
2617   tpl       = "main-template.tpl";
2618 @};
2619 @end example
2620
2621 @node main invoke
2622 @subsubsection invoke: code emitted from AutoGen macro
2623
2624 You must write a template to produce your main procedure.  That template
2625 must contain a definition for the function specified with the @code{func}
2626 attribute to this @code{main()} procedure specification.  This
2627 variation operates in much the same way as @code{include}
2628 (@pxref{main include}) method.
2629
2630 @node main for-each
2631 @subsubsection for-each: perform function on each operand
2632
2633 This produces a main procedure that invokes a procedure once for each operand
2634 on the command line (non-option arguments), @strong{OR} once for each
2635 non-blank, non-comment @code{stdin} input line.  Leading and trailing white
2636 space is trimmed from the input line and comment lines are lines that are
2637 empty or begin with a comment character, defaulting to a hash ('#') character.
2638
2639 @strong{NB}:
2640 The @code{argument} program attribute (@pxref{program attributes})
2641 must begin with the @code{[} character, to indicate that there are
2642 command operands, but that they are optional.
2643
2644 @noindent
2645 For an example of the produced main procedure, in the @file{autoopts/test}
2646 build directory, type the following command and look at @file{main.c}:
2647 @example
2648 make verbose TESTS=main.test
2649 @end example
2650
2651 @node main-for-each-proc
2652 @unnumberedsubsubsec procedure to handle each argument
2653
2654 @vindex handler-proc
2655 The @code{handler-proc} attribute is required.  It is used to name the
2656 procedure to call.  That procedure is presumed to be external, but if
2657 you provide the code for it, then the procedure is emitted as a static
2658 procedure in the generated code.
2659
2660 This procedure should return 0 on success, a cumulative error code on warning
2661 and exit without returning on an unrecoverable error.  As the cumulative
2662 warning codes are @i{or}-ed together, the codes should be some sort of bit
2663 mask in order to be ultimately decipherable (if you need to do that).
2664
2665 If the called procedure needs to cause a fail-exit, it is expected to call
2666 @code{exit(3)} directly.  If you want to cause a warning exit code, then this
2667 handler function should return a non-zero status.  That value will be
2668 @strong{OR}-ed into a result integer for computing the final exit code.  E.g.,
2669 here is part of the emitted code:
2670
2671 @example
2672   int res = 0;
2673   if (argc > 0) @{
2674      do  @{
2675          res |= @var{my_handler}( *(argv++) );
2676      @} while (--argc > 0);
2677   @} else @{ ...
2678 @end example
2679
2680 @node main-for-each-type
2681 @unnumberedsubsubsec handler procedure type
2682
2683 @vindex handler-type
2684 If you do not supply the @code{handler-type} attribute, your handler
2685 procedure must be the default type.  The profile of the procedure must be:
2686
2687 @example
2688 int @var{my_handler}(char const * pz_entry);
2689 @end example
2690
2691 @noindent
2692 However, if you do supply this attribute, you may set the value to any of
2693 four alternate flavors:
2694
2695 @table @samp
2696 @item name-of-file
2697 This is essentially the same as the default handler type, except that before
2698 your procedure is invoked, the generated code has verified that the string
2699 names an existing file.  The profile is unchanged.
2700
2701 @item file-X
2702 Before calling your procedure, the file is f-opened according to the @code{X},
2703 where @code{X} may be any of the legal modes for @code{fopen(3C)}.  In this
2704 case, the profile for your procedure must be:
2705
2706 @example
2707 int @var{my_handler}(char const * pz_fname, FILE * entry_fp);
2708 @end example
2709
2710 @noindent
2711 When processing inputs as file pointer stream files, there are several
2712 ways of treating standard input.  It may be an ordinary input file,
2713 or it may contain a list of files to operate on.
2714
2715 If the file handler type is more specifically set to @samp{file-r} and
2716 a command line operand consists of a single hyphen, then @var{my_handler}
2717 will be called with @code{entry_fp} set to @code{stdin} and the @code{pz_fname}
2718 set to the translatable string, "standard input".  Consequently,
2719 in this case, if the input list is being read from @code{stdin}, a line
2720 containing a hyphen by itself will be ignored.
2721
2722 @item  stdin-input
2723 This attribute specifies that standard input is a data input file.
2724 By default, @code{for-each} main procedures will read standard input for
2725 operands if no operands appear on the command line.  If there are operands
2726 after the command line options, then standard input is typically ignored.
2727 It can always be processed as an input data file, however, if a single bare
2728 hyphen is put on the command line.
2729
2730 @item  text-of-file
2731 @itemx some-text-of-file
2732 Before calling your procedure, the contents of the file are read or mapped
2733 into memory.  (Excessively large files may cause problems.)  The
2734 @samp{some-text-of-file} disallows empty files.  Both require regular files.
2735 In this case, the profile for your procedure must be:
2736
2737 @example
2738 program_exit_code_t
2739 @var{my_handler}(char const * fname, char * file_text,
2740            size_t text_size);
2741 @end example
2742
2743 @noindent
2744 Note that though the @code{file_text} is not @code{const}, any changes made to
2745 it are not written back to the original file.  It is merely a memory image of
2746 the file contents.  Also, the memory allocated to hold the text is
2747 @code{text_size + 1} bytes long and the final byte is always @code{NUL}.  The
2748 file contents need not be text, as the data are read with the @code{read(2)}
2749 system call.
2750
2751 @code{file_text} is automatically freed, unless you specify a
2752 @vindex handler-frees
2753 @code{handler-frees} attribute.  Then your code must @code{free(3)} the text.
2754 @end table
2755
2756 If you select one of these file type handlers, then on access or usage errors
2757 the @code{PROGRAM_EXIT_FAILURE} exit code will, by default, be or-ed
2758 into the final exit code.  This can be changed by specifying the
2759 global @code{file-fail-code} attribute and naming a different value.
2760 That is, something other than @code{failure}.  You may choose @code{success},
2761 in which case file access issues will not affect the exit code and the error
2762 message will not be printed.
2763
2764 @node main-for-each-code
2765 @unnumberedsubsubsec code for handler procedure
2766
2767 @vindex MYHANDLER-code
2768 With the @code{MYHANDLER-code} attribute, you provide the code for
2769 your handler procedure in the option definition file.  Note that the
2770 spelling of this attribute depends on the name provided with the
2771 @code{handler-proc} attribute, so we represent it here with
2772 @code{MYHANDLER} as a place holder.  As an example, your @code{main()}
2773 procedure specification might look something like this:
2774
2775 @example
2776 main = @{
2777   main-type    = for-each;
2778   handler-proc = @var{MYHANDLER};
2779   @var{MYHANDLER}-code = <<- EndOfMyCode
2780         /* whatever you want to do */
2781         EndOfMyCode;
2782 @};
2783 @end example
2784
2785 @noindent
2786 and instead of an emitted external reference, a procedure will be emitted
2787 that looks like this:
2788
2789 @example
2790 static int
2791 @var{MYHANDLER}( char const* pz_entry )
2792 @{
2793     int res = 0;
2794     <<@var{MYHANDLER}-code goes here>>
2795     return res;
2796 @}
2797 @end example
2798
2799 @node main-for-each-opts
2800 @unnumberedsubsubsec for-each main procedure options
2801
2802 These attributes affect the main procedure and how it processes
2803 each argument or input line.
2804
2805 @table @samp
2806 @item interleaved
2807 @vindex interleaved
2808 If this attribute is specified, then options and operands may be
2809 interleaved.  Arguments or input lines beginning with a hyphen will
2810 cause it to be passed through to an option processing function and
2811 will take effect for the remainder of the operands (or input lines)
2812 processed.
2813
2814 @item main-init
2815 @vindex main-init
2816 This is code that gets inserted after the options have been processed, but
2817 before the handler procs get invoked.
2818
2819 @item main-fini
2820 @vindex main-fini
2821 This is code that gets inserted after all the entries have been processed,
2822 just before returning from @code{main()}.
2823
2824 @item comment-char
2825 @vindex comment-char
2826 When reading operands from standard input, if you wish comment lines to
2827 start with a character other than a hash (@code{#}) character, then
2828 specify one character with this attribute.  If string value is empty,
2829 then only blank lines will be considered comments.
2830 @end table
2831
2832 @node option attributes
2833 @subsection Option Attributes
2834 @cindex option attributes
2835
2836 For each option you wish to specify, you must have a block macro named
2837 @code{flag} defined.  There are two required attributes: @code{name} and
2838 @code{descrip}.  If any options do not have a @code{value} (traditional flag
2839 character) attribute, then the @code{long-opts} program attribute must also
2840 be defined.  As a special exception, if no options have a @code{value}
2841 @strong{and} @code{long-opts} is not defined @strong{and} @code{argument} is
2842 not defined, then all arguments to the program are named options.  In this
2843 case, the @option{-} and @option{--} command line option markers are optional.
2844
2845 @menu
2846 * Required Attributes::         Required Attributes
2847 * Common Attributes::           Common Option Attributes
2848 * Immediate Action::            Immediate Action Attributes
2849 * Option Conflict Attributes::  Option Conflict Attributes
2850
2851 These option attributes do not fit well with the above categories.
2852
2853 * opt-attr settable::           Program may set option
2854 * opt-attr no-preset::          Option cannot be pre-configured
2855 * opt-attr equivalence::        Option Equivalence Class
2856 * opt-attr aliases::            Option Aliasing
2857 * opt-attr default option::     Default Option
2858 * opt-attr documentation::      Option Sectioning Comment
2859 * opt-attr translators::        Translator Notes
2860 @end menu
2861
2862 @node Required Attributes
2863 @subsubsection Required Attributes
2864 @cindex Required Attributes
2865
2866 Every option must have exactly one copy of both of these attributes.
2867
2868 @table @samp
2869 @item name
2870 @vindex name
2871 Long name for the option.  Even if you are not accepting long options
2872 and are only accepting flags, it must be provided.  AutoOpts generates
2873 private, named storage that requires this name.  This name also causes
2874 a @code{#define}-d name to be emitted.  It must not conflict with any
2875 other names you may be using in your program.
2876
2877 For example, if your option name is, @code{debug} or @code{munged-up},
2878 you must not use the @code{#define} names @code{DEBUG} (or
2879 @code{MUNGED_UP}) in your program for non-AutoOpts related purposes.
2880 They are now used by AutoOpts.
2881
2882 Sometimes (most especially under Windows), you may get a surprise.
2883 For example, @code{INTERFACE} is apparently a user space name that
2884 one should be free to use.  Windows usurps this name.  To solve this,
2885 you must do one of the following:
2886
2887 @enumerate
2888 @item
2889 Change the name of your option
2890 @item
2891 add the program attribute (@pxref{program attributes}):
2892
2893 @example
2894 export = '#undef INTERFACE';
2895 @end example
2896 @item
2897 add the program attribute:
2898
2899 @example
2900 guard-option-names;
2901 @end example
2902 @end enumerate
2903
2904 @item descrip
2905 @vindex descrip
2906 Except for documentation options, a @strong{very} brief description of the
2907 option.  About 40 characters on one line, maximum, not counting any texinfo
2908 markups.  Texinfo markups are stripped before printing in the usage text.  It
2909 appears on the @code{usage()} output next to the option name.
2910
2911 If, however, the option is a documentation option, it will appear on one or
2912 more lines by itself.  It is thus used to visually separate and comment upon
2913 groups of options in the usage text.
2914 @end table
2915
2916 @node Common Attributes
2917 @subsubsection Common Option Attributes
2918 @cindex Common Option Attributes
2919
2920 These option attributes are optional.  Any that do appear in the
2921 definition of a flag, may appear only once.
2922
2923 @table @samp
2924 @item value
2925 @vindex value
2926 The flag character to specify for traditional option flags, e.g., @option{-L}.
2927
2928 @item max
2929 @vindex max
2930 Maximum occurrence count (invalid if @var{disable} present).
2931 The default maximum is 1.  @code{NOLIMIT} can be used for the value,
2932 otherwise it must be a number or a @code{#define} that evaluates to a number.
2933
2934 @item min
2935 @vindex min
2936 Minimum occurrence count.  If present, then the option @strong{must}
2937 appear on the command line.  Do not define it with the value zero (0).
2938
2939 @item must-set
2940 @vindex must-set
2941 If an option must be specified, but it need not be specified on
2942 the command line, then specify this attribute for the option.
2943
2944 @item deprecated
2945 @vindex deprecated
2946 There are two effects to this attribute:  the usage text will not
2947 show the option, and the generated documentation will mark it with:
2948 @emph{NOTE: THIS OPTION IS DEPRECATED}.
2949
2950 @item disable
2951 @vindex disable
2952 Prefix for disabling (inverting sense of) the option.  Only useful
2953 if long option names are being processed.  When an option has this
2954 attribute, the test @code{ENABLED_OPT(OPTNAME)} is false when either
2955 of the following is true:
2956 @itemize @bullet
2957 @item
2958 The option has not been specified and the @code{enable} attribute has
2959 not been specified.
2960 @item
2961 The option has been specified with this disabling prefix.
2962 @end itemize
2963 To detect that the option has been specified with the disabling
2964 prefix, you must use:
2965 @example
2966 HAVE_OPT(OPTNAME) && ! ENABLED_OPT(OPTNAME)
2967 @end example
2968
2969 @item enable
2970 @vindex enable
2971 Long-name prefix for enabling the option (invalid if @var{disable}
2972 @strong{not} present).  Only useful if long option names are being
2973 processed.
2974
2975 @item enabled
2976 @vindex enabled
2977 If default is for option being enabled.  (Otherwise, the OPTST_DISABLED
2978 bit is set at compile time.)  Only useful if the option can be disabled.
2979
2980 @item ifdef
2981 @itemx ifndef
2982 @itemx omitted-usage
2983 @vindex ifdef
2984 @vindex ifndef
2985 @vindex omitted-usage
2986 If an option is relevant on certain platforms or when certain features
2987 are enabled or disabled, you can specify the compile time flag used
2988 to indicate when the option should be compiled in or out.  For example,
2989 if you have a configurable feature, @code{mumble} that is indicated
2990 with the compile time define, @code{WITH_MUMBLING}, then add:
2991
2992 @example
2993 ifdef = WITH_MUMBLING;
2994 @end example
2995
2996 @noindent
2997 Take care when using these.  There are several caveats:
2998
2999 @itemize @bullet
3000 @item
3001 The case and spelling must match whatever is specified.
3002 @item
3003 Do not confuse these attributes with the AutoGen directives of the
3004 same names, @xref{Directives}.  These cause C preprocessing directives
3005 to be inserted into the generated C text.
3006 @item
3007 Only one of @code{ifdef} and @code{ifndef} may apply to any one option.
3008 @item
3009 The @code{VALUE_OPT_} values are @code{#define}-d.  If @code{WITH_MUMBLING}
3010 is not defined, then the associated @code{VALUE_OPT_} value will not be
3011 @code{#define}-d either.  So, if you have an option named, @code{MUMBLING}
3012 that is active only if @code{WITH_MUMBLING} is @code{#define}-d, then
3013 @code{VALUE_OPT_MUMBLING} will be @code{#define}-d iff @code{WITH_MUMBLING}
3014 is @code{#define}-d.  Watch those switch statements.
3015 @item
3016 If you specify @code{omitted-usage}, then the option will be recognized
3017 as disabled when it is configured out of the build, but will yield the
3018 message, ``This option has been disabled.''  You may specify an alternate
3019 message by giving @code{omitted-usage} a string value. e.g.:
3020 @example
3021 omitted-usage = 'you cannot do this';
3022 @end example
3023 @end itemize
3024
3025 @item no-command
3026 @vindex no-command
3027 This option specifies that the option is not allowed on the command line.
3028 Such an option may not take a @code{value} (flag character) attribute.  The
3029 program must have the @code{homerc} (@pxref{program attributes}) option set.
3030 @end table
3031
3032 @node Immediate Action
3033 @subsubsection Immediate Action Attributes
3034 @cindex immediate action
3035
3036 Certain options may need to be processed early.  For example, in order to
3037 suppress the processing of configuration files, it is necessary to process the
3038 command line option @option{--no-load-opts} @strong{before} the config files
3039 are processed.  To accommodate this, certain options may have their enabled or
3040 disabled forms marked for immediate processing.  The consequence of this is
3041 that they are processed ahead of all other options in the reverse of normal
3042 order.
3043
3044 Normally, the first options processed are the options specified in the first
3045 @code{homerc} file, followed by then next @code{homerc} file through to the
3046 end of config file processing.  Next, environment variables are processed and
3047 finally, the command line options.  The later options override settings
3048 processed earlier.  That actually gives them higher priority.  Command line
3049 immediate action options actually have the lowest priority of all.  They would
3050 be used only if they are to have an effect on the processing of subsequent
3051 options.
3052
3053 @table @samp
3054 @item immediate
3055 @vindex immediate
3056 Use this option attribute to specify that the enabled form of the option
3057 is to be processed immediately.  The @code{help} and @code{more-help}
3058 options are so specified.  They will also call @code{exit()} upon
3059 completion, so they @strong{do} have an effect on the processing
3060 of the remaining options :-).
3061
3062 @item immed-disable
3063 @vindex immed-disable
3064 Use this option attribute to specify that the disabled form of the
3065 option is to be processed immediately.  The @code{load-opts} option is
3066 so specified.  The @option{--no-load-opts} command line option will
3067 suppress the processing of config files and environment variables.
3068 Contrariwise, the @option{--load-opts} command line option is
3069 processed normally.  That means that the options specified in that file
3070 will be processed after all the @code{homerc} files and, in fact, after
3071 options that precede it on the command line.
3072
3073 @item also
3074 If either the @code{immediate} or the @code{immed-disable} attributes
3075 are set to the string, @code{also}, then the option will actually be
3076 processed twice:  first at the immediate processing phase and again
3077 at the normal time.
3078 @end table
3079
3080 @node Option Conflict Attributes
3081 @subsubsection Option Conflict Attributes
3082 @cindex Option Conflict Attributes
3083
3084 These attributes may be used as many times as you need.
3085 They are used at the end of the option processing to verify
3086 that the context within which each option is found does not
3087 conflict with the presence or absence of other options.
3088
3089 This is not a complete cover of all possible conflicts and
3090 requirements, but it simple to implement and covers the
3091 more common situations.
3092
3093 @table @samp
3094 @cindex flags-must
3095 @item flags-must
3096 one entry for every option that @strong{must} be present
3097 when this option is present
3098
3099 @cindex flags-cant
3100 @item flags-cant
3101 one entry for every option that @strong{cannot} be present
3102 when this option is present
3103 @end table
3104
3105 @node opt-attr settable
3106 @subsubsection Program may set option
3107 @vindex settable
3108 If the option can be set outside of option processing, specify
3109 @code{settable}.  If this attribute is defined, special macros for setting
3110 this particular option will be inserted into the interface file.  For example,
3111 @code{TEMPL_DIRS} is a settable option for AutoGen, so a macro named
3112 @code{SET_OPT_TEMPL_DIRS(a)} appears in the interface file.  This attribute
3113 interacts with the @var{documentation} attribute.
3114
3115 @node opt-attr no-preset
3116 @subsubsection Option cannot be pre-configured
3117 @vindex no-preset
3118 @cindex configuration file
3119 If presetting this option is not allowed, specify @code{no-preset}.
3120 (Thus, environment variables and values set in configuration files will be
3121 ignored.)
3122
3123 @node opt-attr equivalence
3124 @subsubsection Option Equivalence Class
3125 @vindex equivalence
3126 Generally, when several options are mutually exclusive and basically serve the
3127 purpose of selecting one of several processing modes, specify the
3128 @code{equivalence} attribute.  These options will be considered an
3129 equivalence class.  Sometimes, it is just easier to deal with them as such.
3130 All members of the equivalence class must contain the same equivalenced-to
3131 option, including the equivalenced-to option itself.  Thus, it must be a class
3132 member.
3133
3134 For an option equivalence class, there is a single occurrence counter for
3135 the class.  It can be referenced with the interface macro,
3136 @code{COUNT_OPT(BASE_OPTION)}, where @var{BASE_OPTION} is the equivalenced-to
3137 option name.
3138
3139 Also, please take careful note: since the options are mapped to the
3140 equivalenced-to option descriptor, any option argument values are mapped to
3141 that descriptor also.  Be sure you know which ``equivalent option'' was
3142 selected before getting an option argument value!
3143
3144 During the presetting phase of option processing
3145 (@pxref{Presetting Options}), equivalenced options may be specified.
3146 However, if different equivalenced members are specified, only the last
3147 instance will be recognized and the others will be discarded.  A conflict
3148 error is indicated only when multiple different members appear on the
3149 command line itself.
3150
3151 As an example of where equivalenced options might be useful, @code{cpio(1)}
3152 has three options @option{-o}, @option{-i}, and @option{-p} that define the
3153 operational mode of the program (@code{create}, @code{extract} and
3154 @code{pass-through}, respectively).  They form an equivalence class from
3155 which one and only one member must appear on the command line.  If
3156 @code{cpio} were an AutoOpt-ed program, then each of these option
3157 definitions would contain:
3158
3159 @example
3160 equivalence = create;
3161 @end example
3162
3163 and the program would be able to determine the operating mode
3164 with code that worked something like this:
3165
3166 @example
3167 switch (WHICH_IDX_CREATE) @{
3168 case INDEX_OPT_CREATE:       ...
3169 case INDEX_OPT_EXTRACT:      ...
3170 case INDEX_OPT_PASS_THROUGH: ...
3171 default:    /* cannot happen */
3172 @}
3173 @end example
3174
3175 @node opt-attr aliases
3176 @subsubsection Option Aliasing
3177
3178 Sometimes, for backwards compatibility or tradition or just plain convenience,
3179 it works better to define one option as a pure alias for another option.
3180 For such situations, provide the following pieces of information:
3181 @example
3182 flag = @{
3183    name  = @i{aliasing-option-name};
3184    value = @i{aliasing-flag-char}; // optional !
3185    aliases = @i{aliased-to-option};
3186 @};
3187 @end example
3188 Do not provide anything else.  The usage text for such an option will be:
3189 @example
3190    This is an alias for @i{aliased-to-option}
3191 @end example
3192
3193 @node opt-attr default option
3194 @subsubsection Default Option
3195 @vindex default
3196 If your program processes its arguments in named option mode (See
3197 @code{long-opts} in @ref{program attributes}), then you may select
3198 @strong{one} of your options to be the default option.  Do so by using
3199 attribute @code{default} with one of the options.  The option so specified
3200 must have an @code{arg-type} (@pxref{Option Arguments}) specified, but not the
3201 @code{arg-optional} (@pxref{arg-optional}) attribute.  That is to say, the
3202 option argument must be required.
3203
3204 If you have done this, then any arguments that do not match an option name and
3205 do not contain an equal sign (@code{=}) will be interpreted as an option
3206 argument to the default option.
3207
3208 @node opt-attr documentation
3209 @subsubsection Option Sectioning Comment
3210 This attribute means the option exists for the purpose of separating option
3211 description text in the usage output and texi documentation.  Without this
3212 attribute, every option is a separate node in the texi docs.  With this
3213 attribute, the documentation options become texi doc nodes and the options are
3214 collected under them.  Choose the name attribute carefully because it will
3215 appear in the texi documentation.
3216
3217 Libraries may also choose to make it settable so that the library can
3218 determine which command line option is the first one that pertains to the
3219 library.
3220
3221 @vindex documentation
3222 If the @samp{documentation} attribute is present, then all other
3223 attributes are disabled except @code{settable}, @code{call-proc} and
3224 @code{flag-code}.  @code{settable} must be and is only specified if
3225 @code{call-proc}, @code{extract-code} or @code{flag-code} has been specified.
3226 When present, the @code{descrip} attribute will be displayed only when the
3227 @option{--help} option has been specified.  It will be displayed flush to the
3228 left hand margin and may consist of one or more lines of text, filled to 72
3229 columns.
3230
3231 The name of the option will not be printed in the help text.  It @i{will},
3232 however, be printed as section headers in the texi documentation.  If the
3233 attribute is given a non-empty value, this text will be reproduced in the man
3234 page and texi doc immediately after the @code{descrip} text.
3235
3236 @node opt-attr translators
3237 @subsubsection Translator Notes
3238 @vindex translators
3239 If you need to give the translators a special note about a particular option,
3240 please use the @code{translators} attribute.  The attribute text will be
3241 emitted into the generated @code{.c} text where the option related strings get
3242 defined.  To make a general comment about all of the option code, add comments
3243 to an @code{include} attribute (@pxref{program attributes}).  Do @strong{not}
3244 use this attribute globally, or it will get emitted into every option
3245 definition block.
3246
3247 @node Option Arguments
3248 @subsection Option Argument Specification
3249 @cindex Option Arguments
3250
3251 Command line options come in three flavors:  options that do not
3252 take arguments, those that do and those that may.  Without an
3253 "arg-type" attribute, AutoOpts will not process an argument to an
3254 option.  If "arg-type" is specified and "arg-optional" is also
3255 specified, then the next command line token will be taken to
3256 be an argument, unless it looks like the name of another option.
3257
3258 If the argument type is specified to be anything other than "str[ing]", then
3259 AutoOpts will specify a callback procedure to handle the argument.  Some of
3260 these procedures will be created and inserted into the generated @file{.c}
3261 file, and others are already built into the @file{libopts} library.
3262 Therefore, if you write your own callback procedure
3263 (@pxref{Option Argument Handling}), then you must either not specify an
3264 "arg-type" attribute, or else specify it to be of type "str[ing]".  Your
3265 callback function will be able to place its own restrictions on what that
3266 string may contain or represent.
3267
3268 Option argument handling attributes depend upon the value set for the
3269 @vindex arg-type
3270 @code{arg-type} attribute.  It specifies the type of argument the option
3271 will take.  If not present, the option cannot take an argument.  If present,
3272 it must be an entry in the following table.  The first three letters is
3273 sufficient.
3274
3275 @menu
3276 * arg-type string::         Arg Type String
3277 * arg-type number::         Arg Type Number
3278 * arg-type boolean::        Arg Type Boolean
3279 * arg-type keyword::        Arg Type Keyword
3280 * arg-type set membership:: Arg Type Set Membership
3281 * arg-type hierarchy::      Arg Type Hierarchical
3282 * arg-type file name::      Arg Type File Name
3283 * arg-type time-duration::  Arg Type Time Duration
3284 * arg-type time-date::      Arg Type Time and Date
3285
3286 Supporting attributes for particular argument types:
3287
3288 * arg-keyword::             Keyword list
3289 * arg-optional::            Option Argument Optional
3290 * arg-default::             Default Option Argument Value
3291 @end menu
3292
3293 @node arg-type string
3294 @subsubsection Arg Type String
3295 @code{arg-type = string;}
3296
3297 The argument may be any arbitrary string, though your program or option
3298 callback procedure may place additional constraints upon it.
3299
3300
3301 @node arg-type number
3302 @subsubsection Arg Type Number
3303 @code{arg-type = number;}
3304
3305 The argument must be a correctly formed integer, without any trailing U's or
3306 L's.  AutoOpts contains a library procedure to convert the string to a number.
3307 If you specify range checking with @code{arg-range} (see below), then AutoOpts
3308 produces a special purpose procedure for this option.
3309
3310 @table @samp
3311 @item scaled
3312 @vindex scaled
3313 @code{scaled} marks the option so that suffixes of @samp{k}, @samp{K},
3314 @samp{m}, @samp{M}, @samp{g}, @samp{G}, @samp{t}, and @samp{T} will multiply
3315 the given number by a power of 1000 or 1024.  Lower case letters scale by a
3316 power of 1000 and upper case scale by a power of 1024.
3317
3318 @item arg-range
3319 @vindex arg-range
3320 @code{arg-range} is used to create a callback procedure for validating the
3321 range of the option argument.  It must match one of the range entries.  Each
3322 @code{arg-range} should consist of either an integer by itself or an integer
3323 range.  The integer range is specified by one or two integers separated by the
3324 two character sequence, @code{->}.  Be sure to quote the entire range string.
3325 The definitions parser will not accept the range syntax as a single string
3326 token.
3327
3328 The generated procedure imposes the range constraints as follows:
3329 @itemize @bullet
3330 @item
3331 A number by itself will match that one value.
3332 @item
3333 The high end of the range may not be @code{INT_MIN}, both for obvious
3334 reasons and because that value is used to indicate a single-valued match.
3335 @item
3336 An omitted lower value implies a lower bound of INT_MIN.
3337 @item
3338 An omitted upper value implies a upper bound of INT_MAX.
3339 @item
3340 The argument value is required.  It may not be optional.
3341 @item
3342 The value must match one of the entries.  If it can match more than one,
3343 then you have redundancies, but no harm will come of it.
3344 @end itemize
3345 @end table
3346
3347
3348 @node arg-type boolean
3349 @subsubsection Arg Type Boolean
3350 @code{arg-type = boolean;}
3351
3352 The argument will be interpreted and always yield either AG_TRUE or
3353 AG_FALSE.  False values are@:  the empty string, the number zero, or a
3354 string that starts with @code{f}, @code{F}, @code{n} or @code{N}
3355 (representing False or No).  Anything else will be interpreted as True.
3356
3357
3358 @node arg-type keyword
3359 @subsubsection Arg Type Keyword
3360 @code{arg-type = keyword;}
3361
3362 The argument must match a specified list of strings (@pxref{arg-keyword}).
3363 Assuming you have named the option, @code{optn-name}, the strings will be
3364 converted into an enumeration of type @code{te_Optn_Name} with the values
3365 @code{OPTN_NAME_KEYWORD}.*  If you have @strong{not} specified a default
3366 value, the value @code{OPTN_NAME_UNDEFINED} will be inserted with the value
3367 zero.  The option will be initialized to that value.  You may now use this
3368 in your code as follows:
3369
3370 @example
3371 te_Optn_Name opt = OPT_VALUE_OPTN_NAME;
3372 switch (opt) @{
3373 case OPTN_NAME_UNDEFINED:  /* undefined things */ break;
3374 case OPTN_NAME_KEYWORD:    /* `keyword' things */ break;
3375 default: /* utterly impossible */ ;
3376 @}
3377 @end example
3378
3379 AutoOpts produces a special purpose procedure for this option.
3380 You may not specify an alternate handling procedure.
3381
3382 If you have need for the string name of the selected keyword, you
3383 may obtain this with the macro, @code{OPT_OPTN_NAME_VAL2STR(val)}.
3384 The value you pass would normally be @code{OPT_VALUE_OPTN_NAME},
3385 but anything with numeric value that is legal for @code{te_Optn_Name}
3386 may be passed.  Anything out of range will result in the string,
3387 @samp{"*INVALID*"} being returned.  The strings are read only.
3388 It may be used as in:
3389
3390 @example
3391 te_Optn_Name opt = OPT_VALUE_OPTN_NAME;
3392 printf( "you selected the %s keyword\n",
3393         OPT_OPTN_NAME_VAL2STR(opt) );
3394 @end example
3395
3396 * Note: you may replace the @code{OPTN_NAME} enumeration prefix with
3397 another prefix by specifying a
3398 @vindex prefix-enum
3399 @code{prefix-enum} attribute.
3400
3401 Finally, users may specify the argument either by name or by number.
3402 Since the numeric equivalents change by having new entries inserted
3403 into the keyword list, this would not be a recommended practice.
3404 However, either @code{-1} or @code{~0} will always be equivalent to
3405 specifying the last keyword.
3406
3407 @node arg-type set membership
3408 @subsubsection Arg Type Set Membership
3409 @code{arg-type = set;}
3410
3411 The argument must be a list of names each of which must match the strings
3412 ``@code{all}'', ``@code{none}'' or one of the keywords (@pxref{arg-keyword})
3413 specified for this option.  @code{all} will turn on all membership bits and
3414 @code{none} will turn them all off.  Specifying one of the keywords will set
3415 the corresponding set membership bit on (or off, if negated) .  Literal
3416 numbers may also be used and may, thereby, set or clear more than one bit.
3417
3418 The membership result starts with the previous (or initialized) result.  To
3419 clear previous results, either start the membership string with @samp{none +}
3420 or with the equals character (@samp{=}).  To invert (bit flip) the final
3421 result (regardless of whether the previous result is carried over or not),
3422 start the string with a carat character (@samp{^}).  If you wish to invert the
3423 result and start without a carried over value, use one of the following:
3424 @code{=^} or @code{^none+}.  These are equivalent.
3425
3426 The list of names or numbers must be separated by one of the following
3427 characters: @samp{+-|!,} or whitespace.  The comma is equivalent to
3428 whitespace, except that only one may appear between two entries and it may not
3429 appear in conjunction with the @var{or} bar (@samp{|}).  The @samp{+|} leading
3430 characters or unadorned name signify adding the next named bit to the mask,
3431 and the @samp{-!}  leading characters indicate removing it.
3432
3433 The number of keywords allowed is constrained by the number of bits in a
3434 pointer, as the bit set is kept in a @code{void *} pointer.
3435
3436 If, for example, you specified @code{first} in your list of keywords,
3437 then you can use the following code to test to see if either @code{first}
3438 or @code{all} was specified:
3439
3440 @example
3441 uintptr_t opt = OPT_VALUE_OPTN_NAME;
3442 if (opt & OPTN_NAME_FIRST)
3443     /* OPTN_NAME_FIRST bit was set */ ;
3444 @end example
3445
3446 AutoOpts produces a special purpose procedure for this option.
3447 To set multiple bits as the default (initial) value, you must
3448 specify an initial numeric value (which might become inaccurate over
3449 time), or else specify @code{arg-default} multiple times.  Do not
3450 specify a series of names conjoined with @code{+} symbols as the
3451 value for any of the @code{arg-default} attributes.  That works for
3452 option parsing, but not for the option code generation.
3453
3454 @node arg-type hierarchy
3455 @subsubsection Arg Type Hierarchical
3456 @code{arg-type = hierarchy;}
3457 @*
3458 @code{arg-type = nested;}
3459
3460 This denotes an option with a structure-valued argument, a.k.a.
3461 @code{subopts} in @code{getopts} terminology.  The argument is parsed
3462 and the values made available to the program via the find and
3463 find next calls (@xref{libopts-optionFindValue},
3464 @xref{libopts-optionGetValue}, and
3465 @pxref{libopts-optionFindNextValue}).
3466
3467 @example
3468 tOptionValue * val = optionGetValue(VALUE_OPT_OPTN_NAME, "name");
3469 while (val != NULL) @{
3470   process(val);
3471   val = optionNextValue(VALUE_OPT_OPTN_NAME, val);
3472   if (wrong_name(val, "name"))
3473     break;
3474 @}
3475 @end example
3476
3477
3478 @node arg-type file name
3479 @subsubsection Arg Type File Name
3480 @code{arg-type = file;}
3481
3482 This argument type will have some validations on the argument and,
3483 optionally, actually open the file.  You must specify several additonal
3484 attributes for the option:
3485
3486 @table @samp
3487 @item file-exists
3488 @vindex file-exists
3489 If not specified or empty, then the directory portion of the name is checked.
3490 The directory must exist or the argument is rejected and the usage procedure
3491 is invoked.
3492
3493 Otherwise, both the directory as above and the full name is tested for
3494 existence.  If the value begins with the two letters @code{no}, then the file
3495 must not pre-exist.  Otherwise, the file is expected to exist.
3496
3497 @item open-file
3498 @vindex open-file
3499 If not specified or empty, the file is left alone.
3500 If the value begins with the four letters @code{desc}[@i{riptor}], then
3501 @code{open(2)} is used and @code{optArg.argFd} is set.  Otherwise, the
3502 file is opened with @code{fopen} and @code{optArg.argFp} is set.
3503
3504 @item file-mode
3505 @vindex file-mode
3506 If @code{open-file} is set and not empty, then you must specify the open mode.
3507 Set the value to the flag bits or mode string as appropriate for the open
3508 type.
3509 @end table
3510
3511
3512 @node arg-type time-duration
3513 @subsubsection Arg Type Time Duration
3514 @code{arg-type = time-duration;}
3515
3516 The argument will be converted into a number of seconds.  It may be
3517 a multi-part number with different parts being multiplied into a seconds
3518 value and added into the final result.  Valid forms are in the table
3519 below.  Upper cased letters represent numbers that must be used in the
3520 expressions.
3521
3522 @table @samp
3523 @item [[HH:]MM:]SS
3524 @code{HH} is multiplied by @code{3600} and @code{MM} multiplied by @code{60}
3525 before they are added to @code{SS}.  This time specification may not be
3526 followed by any other time specs.  @code{HH} and @code{MM} are both optional,
3527 though @code{HH} cannot be specified without @code{MM}.
3528
3529 @item DAYS d
3530 @code{DAYS} is multiplied by the number of seconds in a day.  This value may
3531 be followed by (and added to) values specified by @code{HH:MM:SS} or the
3532 suffixed values below.  If present, it must always be first.
3533
3534 @item HRS h
3535 @code{HRS} is multiplied by the number of seconds in an hour.  This value may
3536 be followed by (and added to) values specified by @code{MM:SS} or the
3537 suffixed values below.
3538
3539 @item MINS m
3540 @code{MINS} is multiplied by the number of seconds in a minute.  This value
3541 may be followed by (and added to) a count of seconds.
3542
3543 @item SECS s
3544 This value can only be the last value in a time specification.  The @code{s}
3545 suffix is optional.
3546 @end table
3547
3548 @example
3549    5 d 1:10:05    ==> 5 days + 1 hour 10 minutes and 5 seconds
3550    5 d 1 h 10 m 5 ==> yields: 436205 seconds
3551    5d1h10m5s      ==> same result -- spaces are optional.
3552 @end example
3553
3554 When saved into a config file, the value will be stored as a simple count
3555 of seconds.  There are actually more (many) accepted time duration strings.
3556 The full documentation can be found with ISO-8601 documentation and the
3557 more extedded documentation when @code{parse_duration()} becomes more widely
3558 available.
3559
3560
3561 @node arg-type time-date
3562 @subsubsection Arg Type Time and Date
3563 @code{arg-type = time-date;}
3564
3565 The argument will be converted into the number of seconds since the epoch.
3566 The conversion rules are very complicated, please see the
3567 @file{getdate_r(3GNU)} man page.  There are some additional restrictions:
3568
3569 @enumerate
3570 @item
3571 Your project must be compiled with @code{PKGDATADIR} defined and naming a
3572 valid directory.
3573 @item
3574 The @env{DATEMSK} environment variable will be set to the @file{datemsk} file
3575 within that directory.
3576 @end enumerate
3577
3578 If that file is not accessible for any reason, the string will be
3579 parsed as a time duration (@pxref{arg-type time-duration}) instead of a
3580 specific date and time.
3581
3582 @node arg-keyword
3583 @subsubsection Keyword list
3584 @vindex keyword
3585 If the @code{arg-type} is @code{keyword} (@pxref{arg-type keyword}) or
3586 @code{set-membership} (@pxref{arg-type set membership}), then you must specify
3587 the list of keywords by a series of @code{keyword} entries.  The interface
3588 file will contain values for @env{@i{<OPTN_NAME>}_@i{<KEYWORD>}} for each
3589 keyword entry.  @code{keyword} option types will have an enumeration and
3590 @code{set-membership} option types will have a set of unsigned bits
3591 @code{#define}-d.
3592
3593 If the @code{arg-type} is specifically @code{keyword}, you may also add
3594 special handling code with a
3595 @vindex extra-code
3596 @code{extra-code} attribute.  After @code{optionEnumerationVal} has
3597 converted the input string into an enumeration, you may insert code to
3598 process this enumeration value (@code{pOptDesc->optArg.argEnum}).
3599
3600 @node arg-optional
3601 @subsubsection Option Argument Optional
3602 @vindex arg-optional
3603 The @code{arg-optional} attribute indicates that the argument to the option is
3604 optional (need not be specified on the command line).  This is only valid if
3605 the @var{arg-type} is @code{string} (@pxref{arg-type string}) or
3606 @code{keyword} (@pxref{arg-type keyword}).  If it is @code{keyword}, then this
3607 attribute may also specify the default keyword to assume when the argument is
3608 not supplied.  If left empty, @var{arg-default} (@pxref{arg-default}) or the
3609 zero-valued keyword will be used.
3610
3611 The syntax rules for identifying the option argument are:
3612 @itemize @bullet
3613 @item
3614 If the option is specified with a flag character and there is a character
3615 following the flag character, then string following that flag character is the
3616 option argument.
3617 @item
3618 If the flag character is the last character in an argument, then
3619 the first character of the next argument is examined.  If it is a hyphen,
3620 then the option is presumed to not have an argument.  Otherwise, the entire
3621 next argument is the argument for the option.
3622 @item
3623 If the option is specified with a long option name and that name is ended with
3624 an equal sign character (@code{=}), then everything after that character is the
3625 option argument.
3626 @item
3627 If the long name is ended by the end of the argument, then the first character
3628 of the next argument is examined, just as with the flag character ending an
3629 argument string.
3630 @end itemize
3631
3632 This is overridden and the options are required if the libopts library
3633 gets configured with @option{--disable-optional-args}.
3634
3635 @node arg-default
3636 @subsubsection Default Option Argument Value
3637 @vindex arg-default
3638 This specifies the default option argument value to be used when the option is
3639 not specified or preset.  You may specify multiple @code{arg-default} values
3640 if the argument type is @code{set membership}.
3641
3642 @node Option Argument Handling
3643 @subsection Option Argument Handling
3644 @cindex Option Argument Handling
3645
3646 AutoOpts will either specify or automatically generate callback procedures
3647 for options that take specialized arguments.  The only option argument types
3648 that are not specialized are plain string arguments and no argument at all.
3649 For options that fall into one of those two categories, you may specify your
3650 own callback function, as specified below.  If you do this and if you
3651 specify that options are resettable (@pxref{automatic options}), then your
3652 option handling code @strong{must} look for the @samp{OPTST_RESET} bit in
3653 the @code{fOptState} field of the option descriptor.
3654
3655 If the option takes a string argument, then the @code{stack-arg} attribute can
3656 be used to specify that the option is to be handled by the @code{libopts}
3657 @code{stackOptArg()} and @code{unstackOptArg()} library procedures (see
3658 below).  In this case, you may not provide option handling code.
3659
3660 Finally, @samp{documentation} options (@pxref{opt-attr documentation}) may
3661 also be marked as @option{settable} (@pxref{opt-attr settable}) and have
3662 special callback functions (either @samp{flag-code}, @samp{extract-code},
3663 or @samp{call-proc}).
3664
3665 @table @samp
3666 @item flag-code
3667 @vindex flag-code
3668 statements to execute when the option is encountered.  This may be used in
3669 conjunction with option argument types that cause AutoOpts to emit handler
3670 code.  If you do this, the @samp{flag-code} with index zero (0) is emitted
3671 into the handler code @emph{before} the argument is handled, and the entry
3672 with index one (1) is handled afterward.
3673
3674 The generated procedure will be laid out something like this:
3675
3676 @example
3677 static void
3678 doOpt<name>(tOptions* pOptions, tOptDesc* pOptDesc)
3679 @{
3680 <flag-code[0]>
3681 <AutoOpts defined handler code>
3682 <flag-code[1]>
3683 @}
3684 @end example
3685
3686 Only certain fields within the @code{tOptions} and @code{tOptDesc}
3687 structures may be accessed.  @xref{Option Processing Data}.  When writing
3688 this code, you must be very careful with the @code{pOptions} pointer.  The
3689 handler code is called with this pointer set to special values for handling
3690 special situations.  Your code must handle them.  As an example,
3691 look at @code{optionEnumerationVal} in @file{enum.c}.
3692
3693 @item extract-code
3694 @vindex extract-code
3695 This is effectively identical to @code{flag-code}, except that the
3696 source is kept in the output file instead of the definitions file
3697 and you cannot use this in conjunction with options with arguments,
3698 other than string arguments.
3699
3700 A long comment is used to demarcate the code.  You must not modify
3701 that marker.  @i{Before} regenerating the option code file,
3702 the old file is renamed from MUMBLE.c to MUMBLE.c.save.  The template
3703 will be looking there for the text to copy into the new output file.
3704
3705 @item call-proc
3706 @vindex call-proc
3707 external procedure to call when option is encountered.  The calling
3708 sequence must conform to the sequence defined above for the generated
3709 procedure, @code{doOpt<name>}.  It has the same restrictions
3710 regarding the fields within the structures passed in as arguments.
3711 @xref{Option Processing Data}.
3712
3713 @item flag-proc
3714 @vindex flag-proc
3715 Name of another option whose @code{flag-code} can be executed
3716 when this option is encountered.
3717
3718 @item stack-arg
3719 @vindex stack-arg
3720 Call a special library routine to stack the option's arguments.  Special
3721 macros in the interface file are provided for determining how many of the
3722 options were found (@code{STACKCT_OPT(NAME)}) and to obtain a pointer to a
3723 list of pointers to the argument values (@code{STACKLST_OPT(NAME)}).
3724 Obviously, for a stackable argument, the @code{max} attribute
3725 (@pxref{Common Attributes}) needs to be set higher than @code{1}.
3726
3727 If this stacked argument option has a disablement prefix, then the entire
3728 stack of arguments will be cleared by specifying the option with that
3729 disablement prefix.
3730
3731 @item unstack-arg
3732 @vindex unstack-arg
3733 Call a special library routine to remove (@code{unstack}) strings
3734 from a @code{stack-arg} option stack.  This attribute must name
3735 the option that is to be @code{unstacked}.  Neither this option nor
3736 the stacked argument option it references may be equivalenced to
3737 another option.
3738 @end table
3739
3740 @node Internationalizing Options
3741 @subsection Internationalizing Options
3742 @cindex Internationalizing Options
3743
3744 Normally, AutoOpts produces usage text that is difficult to translate.  It is
3745 pieced together on the fly using words and phrases scattered around here and
3746 there, piecing together toe document.  This does not translate well.
3747
3748 Incorporated into this package are some ways around the problem.  First, you
3749 should specify the @code{full-usage} and @code{short-usage} program attributes
3750 (@pxref{program attributes}).  This will enable your translators to translate
3751 the usage text as a whole.
3752
3753 Your translators will also be able to translate long option names.  The option
3754 name translations will then become the names searched for both on the command
3755 line and in configuration files.  However, it will not affect the names of
3756 environment variable names used to configure your program.
3757
3758 If it is considered desireable to keep configuration files in the @code{C}
3759 locale, then several macros are available to suppress or delay the
3760 translations of option names at run time.  These are all disabled if
3761 @code{ENABLE_NLS} is not defined at compile time or if @code{no-xlate} has
3762 been set to the value @emph{anything}.  These macros @strong{must}
3763 be invoked before the first invocation of @code{optionProcess}.
3764
3765 @table @samp
3766 @item  OPT_NO_XLAT_CFG_NAMES;
3767 @itemx OPT_XLAT_CFG_NAMES;
3768 Disable (or enable) the translations of option names for configuration files.
3769 If you enable translation for config files, then they will be translated for
3770 command line options.
3771
3772 @item  OPT_NO_XLAT_OPT_NAMES;
3773 @itemx OPT_XLAT_OPT_NAMES;
3774 Disable (or enable) the translations of option names for command line
3775 processing.  If you disable the translation for command line processing,
3776 you will also disable it for configuration file processing.  Once translated,
3777 the option names will remain translated.
3778 @end table
3779
3780 @node documentation attributes
3781 @subsection Man and Info doc Attributes
3782 @cindex documentation attributes
3783
3784 AutoOpts includes AutoGen templates for producing abbreviated man pages
3785 and for producing the invoking section of an info document.  To take
3786 advantage of these templates, you must add several attributes to your
3787 option definitions.
3788
3789 @menu
3790 * per option attributes::       Per option documentation attributes
3791 * global option attributes::    Global documentation attributes
3792 @end menu
3793
3794 @node per option attributes
3795 @subsubsection Per option documentation attributes
3796
3797 These attributes are sub-attributes (@i{sub-stanzas}) of the @code{flag} stanzas.
3798
3799 @table @samp
3800 @item arg-name
3801 @vindex arg-name
3802 If an option has an argument, the argument should have a name for
3803 documentation purposes.  It will default to @code{arg-type}, but
3804 it will likely be clearer with something else like, @code{file-name}
3805 instead of @code{string} (the type).
3806
3807 @item doc
3808 @vindex doc
3809 First, every @code{flag} definition @emph{other than} @code{documentation}
3810 definitions, must have a @code{doc} attribute defined.  If the option takes
3811 an argument, then it will need an @code{arg-name} attribute as well.  The
3812 @code{doc} text should be in plain sentences with minimal formatting.  The
3813 Texinfo commands @code{@@code}, and @code{@@var} will have its enclosed text
3814 made into @strong{\fB} entries in the man page, and the @code{@@file} text
3815 will be made into @strong{\fI} entries.  The @code{arg-name} attribute is
3816 used to display the option's argument in the man page.
3817
3818 Options marked with the @code{documentation} attribute are for documenting
3819 the usage text.  All other options should have the @code{doc} attribute in
3820 order to document the usage of the option in the generated man pages.
3821
3822 Since these blocks of text are inserted into all output forms,
3823 any markup text included in these blocks must be massaged for each
3824 output format.  By default, it is presumed to be @file{texi} format.
3825 @end table
3826
3827 @node global option attributes
3828 @subsubsection Global documentation attributes
3829 @table @samp
3830 @item cmd-section
3831 @vindex cmd-section
3832 If your command is a game or a system management command,
3833 specify this attribute with the value @code{5} or @code{8}, respectively.
3834 The default is a user command (section 1).
3835
3836 @item detail
3837 @vindex detail
3838 This attribute is used to add a very short explanation about what
3839 a program is used for when the @code{title} attribute is insufficient.
3840 If there is no @code{doc-section} stanza of type @code{DESCRIPTION}, then
3841 this text is used for the man page DESCRIPTION section, too.
3842
3843 @item addtogroup
3844 @vindex addtogroup
3845 This attribute tells the template that the generated code should be
3846 surrounded with the following doxygen comments:
3847 @example
3848 /** @@file <header-or-code-file-name>
3849  *  @@addtogroup <value-of-addtogroup>
3850  *  @@@{
3851  */
3852 @end example
3853 @noindent
3854 and
3855 @example
3856 /** @@@} */
3857 @end example
3858
3859 @item option-format
3860 @vindex option-format
3861 Specify the default markup style for the @code{doc} stanzas.
3862 By default, it is @code{texi}, but @code{man} and @code{mdoc} may
3863 also be selected.  There are nine converter programs that do a partial
3864 job of converting one form of markup into another.  @command{texi2texi},
3865 @command{man2man} and @command{mdoc2mdoc} work pretty well.
3866
3867 You may also post process the document by using @code{doc-sub} stanzas,
3868 see below.
3869
3870 @item option-info
3871 @vindex option-info
3872 This text will be inserted as a lead-in paragraph in the @code{OPTIONS}
3873 section of the generated man page.
3874
3875 @item doc-section
3876 @vindex doc-section
3877 This is a compound attribute that requires three @i{sub}attributes:
3878
3879 @table @i
3880 @item ds-format
3881 This describes the format of the associated @code{ds-text} section.
3882 @code{man}, @code{mdoc} and @code{texi} formats are supported.
3883 Regardless of the chosen format, the formatting tags in the output
3884 text will be converted to @code{man} macros for @code{man} pages,
3885 @code{mdoc} macros for @code{mdoc} pages, and @code{texi} macros for
3886 @code{texinfo} pages.
3887
3888 @item ds-text
3889 This is the descriptive text, written according to the rules for
3890 @code{ds-format} documents.
3891
3892 @item ds-type
3893 This describes the section type.  Basically, the title of the section
3894 that will be added to all output documentation.  There may be only one
3895 @code{doc-section} for any given @code{ds-type}.  If there are duplicates,
3896 the results are undefined (it might work, it might not).
3897
3898 There are five categories of @code{ds-type} sections.
3899 They are those that the documentation templates would otherwise:
3900 @enumerate
3901 @item
3902 always create itself, ignoring any @code{ds-type}s by this name.
3903 These are marked, below, as @code{ao-only}.
3904 @item
3905 create, if none was provided.
3906 These are marked, @code{alternate}.
3907 @item
3908 create, but augment if the @code{doc-section} was provided.
3909 These are marked, @code{augments}.
3910 @item
3911 do nothing, but inserts them into the output in a prescribed order.
3912 These are marked, @code{known}
3913 @item
3914 knows nothing about them.  They will be alphabetized and inserted
3915 after the list of leading sections and before the list of trailing
3916 sections.  These are not marked because I don't know their names.
3917 @end enumerate
3918
3919 Some of these are emitted by the documentation templates only if
3920 certain conditions are met.  If there are conditions, they are
3921 explained below.  If there are no conditions, then you will always
3922 see the named section in the output.
3923
3924 The output sections will appear in this order:
3925 @table @samp
3926 @item NAME
3927 @code{ao-only}.
3928 @item SYNOPSIS
3929 @code{alternate}.
3930 @item DESCRIPTION
3931 @code{augments}.
3932 @item OPTIONS
3933 @code{ao-only}.
3934 @item OPTION PRESETS
3935 @code{ao-only}, if environment presets or configuration file processing
3936 has been specified.
3937 @item unknown
3938 At this point, the unknown, alphabetized sections are inserted.
3939 @item IMPLEMENTATION NOTES
3940 @code{known}
3941 @item ENVIRONMENT
3942 @code{augments}, if environment presets have been specified.
3943 @item FILES
3944 @code{augments}, if configuration file processing has been specified.
3945 @item EXAMPLES
3946 @code{known}
3947 @item EXIT STATUS
3948 @code{augments}.
3949 @item ERRORS
3950 @code{known}
3951 @item COMPATIBILITY
3952 @code{known}
3953 @item SEE ALSO
3954 @code{known}
3955 @item CONFORMING TO
3956 @code{known}
3957 @item HISTORY
3958 @code{known}
3959 @item AUTHORS
3960 @code{alternate}, if the @code{copyright} stanza has either
3961 an @code{author} or an @code{owner} attribute.
3962 @item COPYRIGHT
3963 @code{alternate}, if there is a @code{copyright} stanza.
3964 @item BUGS
3965 @code{augments}, if the @code{copyright} stanza has an
3966 @code{eaddr} attribute.
3967 @item NOTES
3968 @code{augments}.
3969 @end table
3970 @end table
3971
3972 @noindent
3973 Here is an example of a @code{doc-section} for a @code{SEE ALSO} type.
3974
3975 @example
3976 doc-section = @{
3977   ds-type   = 'SEE ALSO'; // or anything else
3978   ds-format = 'man';      // or texi or mdoc format
3979   ds-text   = <<-_EOText_
3980         text relevant to this section type,
3981         in the chosen format
3982         _EOText_;
3983 @};
3984 @end example
3985
3986 @item doc-sub
3987 @vindex doc-sub
3988 This attribute will cause the resulting documentation to be post-processed.
3989 This is normally with @command{sed}, see @code{doc-sub-cmd} below.
3990 This attribute has several sub-attributes:
3991
3992 @table @samp
3993 @item sub-name
3994 This is the name of an autogen text definition value, like @code{prog-name}
3995 or @code{version}.  In the @code{sub-text} field, occurrences of this
3996 name preceded by two less than characters and followed by two greater
3997 than characters will be replaced by the text value of the definition,
3998 e.g. @samp{<<prog-name>>}.
3999
4000 @item sub-text
4001 The text that gets added to the command file for the post processing
4002 program.
4003
4004 @item sub-type
4005 If this command only applies to certain types of output, specify
4006 this with a regular expression that will match one of the valid
4007 output format types, e.g. @samp{man|mdoc} will match those two kinds,
4008 but not @code{texi} output.  If omitted, it will always apply.
4009 @end table
4010
4011 For example, if you want to reference the program name in the @code{doc}
4012 text for an option common to two programs, put @samp{#PROG#} into the
4013 text.  The following will replace all occrrences of @samp{#PROG#}
4014 with the current value for @code{prog}:
4015 @example
4016 doc-sub = @{
4017   sub-name = prog-name;
4018   sub-text = 's/#PROG#/<<prog-name>>/g';
4019 @};
4020 @end example
4021
4022 @item doc-sub-cmd
4023 @vindex doc-sub-cmd
4024 A formatting string for constructing the post-processing command.
4025 The first parameter is the name of the file with editing commands in it,
4026 and the second is the file containing the unprocessed document.
4027 The default value is:
4028 @example
4029 sed -f %s %s
4030 @end example
4031 @end table
4032
4033 @node automatic options
4034 @subsection Automatically Supported Options
4035 @cindex automatic options
4036
4037 AutoOpts provides automated support for several options.  @code{help} and
4038 @code{more-help} are always provided.  The others are conditional upon
4039 various global program attributes being defined @xref{program attributes}.
4040
4041 Below are the option names and default flag values.  The flags are activated
4042 if and only if at least one user-defined option also uses a flag value.  The
4043 long names are supported as option names if @code{long-opts} has been
4044 specified.  These option flags may be deleted or changed to characters of your
4045 choosing by specifying
4046 @vindex more-help-value
4047 @vindex usage-value
4048 @vindex version-value
4049 @vindex load-opts-value
4050 @vindex reset-value
4051 @code{xxx-value = "y";}, where @code{xxx} is one of the option names below and
4052 @code{y} is either empty or the character of your choice.  For example, to
4053 change the help flag from @code{?} to @code{h}, specify
4054 @vindex help-value
4055 @code{help-value = "h";}; and to require that @code{save-opts} be specified
4056 only with its long option name, specify
4057 @vindex save-opts-value
4058 @code{save-opts-value = "";}.
4059
4060 Additionally, the procedure that prints out the program version may be
4061 replaced by specifying @code{version-proc}.
4062 @vindex version-proc
4063 This procedure must be defined to be of external scope (non-static).
4064 By default, the AutoOpts library provides @code{optionPrintVersion}
4065 and it will be the specified callback function in the option
4066 definition structure.
4067
4068 With the exception of the @code{load-opts} option, none of these automatically
4069 supported options will be recognized in configuration files or environment
4070 variables.
4071
4072 @table @samp
4073 @item help -?
4074 This option will immediately invoke the @code{USAGE()} procedure
4075 and display the usage line, a description of each option with
4076 its description and option usage information.  This is followed
4077 by the contents of the definition of the @code{detail} text macro.
4078
4079 @item more-help -!
4080 This option is identical to the @code{help} option, except that the
4081 output is passed through a pager program.  (@code{more} by default, or
4082 the program identified by the @code{PAGER} environment variable.)
4083
4084 @item usage -u
4085 This option must be requested by specifying, @code{usage-opt} in the option
4086 definition file.  It will produce abbreviated help text to @file{stdout} and
4087 exit with zero status (@code{EXIT_SUCCESS}).
4088
4089 @item version -v
4090
4091 This will print the program name, title and version.  If it is not
4092 followed by anything or is followed by the letter @code{v}, just the
4093 program name and version will be printed. If followed by the letter
4094 @code{c} and a value for @code{copyright} and @code{owner} have been
4095 provided, then the copyright will be printed, too.  If it is followed by
4096 the letter @code{n}, then the full copyright notice (if available) will
4097 be printed.  The @code{version} attribute must be specified in the
4098 option definition file.
4099
4100 Because some target platforms discourage optional arguments to options,
4101 the autoopts library can be compiled with @code{NO_OPTIONAL_OPT_ARGS}
4102 defined. Alternatively, the @code{version-type} attribute can be added
4103 to the option definitions and it can specify which flavor is preferred.
4104 In either case, an argument to the @code{--version} option will then be
4105 disallowed.
4106
4107 @item load-opts -<
4108 @cindex configuration file
4109 This option will load options from the named file.  They will be treated
4110 exactly as if they were loaded from the normally found configuration files,
4111 but will not be loaded until the option is actually processed.  This can also
4112 be used within another configuration file, causing them to nest.  This is the
4113 @strong{only} automatically supported option that can be activated inside of
4114 config files or with environment variables.
4115
4116 Specifying the negated form of the option (@option{--no-load-opts}) will
4117 suppress the processing of configuration files and environment variables.
4118
4119 This option is activated by specifying one or more @code{homerc} attributes.
4120
4121 @item save-opts ->
4122 @cindex configuration file
4123 This option will cause the option state to be printed in the configuration
4124 file format when option processing is done but not yet verified for
4125 consistency.  The program will terminate successfully without running when
4126 this has completed.  Note that for most shells you will have to quote or
4127 escape the flag character to restrict special meanings to the shell.
4128
4129 The output file will be the configuration file name (default or provided by
4130 @code{rcfile}) in the last directory named in a @code{homerc} definition.
4131
4132 This option may be set from within your program by invoking the
4133 "@code{SET_OPT_SAVE_OPTS(@i{filename})}" macro (@pxref{SET_OPT_name}).
4134 Invoking this macro will set the file name for saving the option processing
4135 state, but the state will @strong{not} actually be saved.  You must call
4136 @code{optionSaveFile} to do that (@pxref{libopts-optionSaveFile}).
4137 @strong{CAVEAT:} if, after invoking this macro, you call
4138 @code{optionProcess}, the option processing state will be saved to this file
4139 and @code{optionProcess} will not return.  You may wish to invoke
4140 @code{CLEAR_OPT( SAVE_OPTS )} (@pxref{CLEAR_OPT}) beforehand if you do need
4141 to reinvoke @code{optionProcess}.
4142
4143 This option is activated by specifying one or more @code{homerc} attributes.
4144
4145 The method of saving the state may be altered by specifying flags before
4146 the output file name. ``Flags'' are specified by placing a list of them
4147 before the file name and separating them from the name with one or two
4148 greater-than characters (``>''). There are three flags currently supported:
4149
4150 @table @samp
4151 @item default
4152 If an option has a default value (has not been set), then the default value
4153 is inserted as a comment.
4154
4155 @item usage
4156 Every option that can be processed from the configuration file will have a
4157 comment that contains the usage string that gets printed with the @code{--help} text
4158
4159 @item update
4160 Instead of removing the old file and writing a new one, the output file is kept,
4161 but any pre-existing segment labeled with @code{<?program prog-name>} is removed.
4162 The new program segment is placed at the end of the file. This flag is implied if
4163 the flags are separated from the file name with doubled greater-than characters.
4164 In other words, @code{update,usage > @i{file-name}} and @code{usage >> @i{file-name}}
4165 are identical.
4166 @end table
4167
4168 @item reset-option -R
4169 This option takes the name of an option for the current program and resets its
4170 state such that it is set back to its original, compile-time initialized
4171 value.  If the option state is subsequently stored (via @option{--save-opts}),
4172 the named option will not appear in that file.
4173
4174 This option is activated by specifying the @code{resettable} attribute.
4175
4176 @strong{BEWARE}:  If the @code{resettable} attribute is specified, all
4177 option callbacks @strong{must} look for the @code{OPTST_RESET} bit in the
4178 @code{fOptState} field of the option descriptor.  If set, the @code{optCookie}
4179 and @code{optArg} fields will be unchanged from their last setting.  When the
4180 callback returns, these fields will be set to their original values.  If you
4181 use this feature and you have allocated data hanging off of the cookie, you
4182 need to deallocate it.
4183 @end table
4184
4185 @node standard options
4186 @subsection Library of Standard Options
4187 @cindex standard options
4188
4189 AutoOpts has developed a set of standardized options.
4190 You may incorporate these options in your program simply by @emph{first}
4191 adding a @code{#define} for the options you want, and then the line,
4192
4193 @example
4194 #include stdoptions.def
4195 @end example
4196
4197 @noindent
4198 in your option definitions.  The supported options are specified thus:
4199
4200 @example
4201 #define DEBUG
4202 #define DIRECTORY
4203 #define DRY_RUN
4204 #define INPUT
4205 #define INTERACTIVE
4206 #define OUTPUT
4207 #define WARN
4208
4209 #define SILENT
4210 #define QUIET
4211 #define BRIEF
4212 #define VERBOSE
4213 @end example
4214
4215 By default, only the long form of the option will be available.
4216 To specify the short (flag) form, suffix these names with @code{_FLAG}.
4217 e.g.,
4218
4219 @example
4220 #define DEBUG_FLAG
4221 @end example
4222
4223 @option{--silent}, @option{--quiet}, @option{--brief} and @option{--verbose}
4224 are related in that they all indicate some level of diagnostic output.  These
4225 options are all designed to conflict with each other.  Instead of four
4226 different options, however, several levels can be incorporated by
4227 @code{#define}-ing @code{VERBOSE_ENUM}.  In conjunction with @code{VERBOSE},
4228 it incorporates the notion of @i{5} levels in an enumeration: @code{silent},
4229 @code{quiet}, @code{brief}, @code{informative} and @code{verbose}; with the
4230 default being @code{brief}.
4231
4232 @ignore
4233 END   == AUTOOPTS-MAIN == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
4234 Extraction from autogen.texi
4235 @end ignore
4236
4237 @ignore
4238 START == AUTOOPTS-API == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
4239 Extraction from autogen.texi
4240 @end ignore
4241
4242 @c === SECTION MARKER
4243
4244 @node AutoOpts API
4245 @section Programmatic Interface
4246 @cindex AutoOpts API
4247
4248 The user interface for access to the argument information is completely
4249 defined in the generated header file and in the portions of the
4250 distributed file "options.h" that are marked "public".
4251
4252 In the following macros, text marked @var{<NAME>} or @var{name}
4253 is the name of the option @strong{in upper case} and
4254 @strong{segmented with underscores @code{_}}.  The macros and enumerations
4255 defined in the options header (interface) file are used as follows:
4256
4257 To see how these @code{#define} macros are used in a program,
4258 the reader is referred to the several @file{opts.h} files
4259 included with the AutoGen sources.
4260
4261 @menu
4262 * Option Processing Data::  Data for Option Processing
4263 * CLEAR_OPT::               CLEAR_OPT( <NAME> ) - Clear Option Markings
4264 * COUNT_OPT::               COUNT_OPT( <NAME> ) - Definition Count
4265 * DESC::                    DESC( <NAME> ) - Option Descriptor
4266 * DISABLE_OPT_name::        DISABLE_OPT_name - Disable an option
4267 * ENABLED_OPT::             ENABLED_OPT( <NAME> ) - Is Option Enabled?
4268 * ERRSKIP_OPTERR::          ERRSKIP_OPTERR - Ignore Option Errors
4269 * ERRSTOP_OPTERR::          ERRSTOP_OPTERR - Stop on Errors
4270 * HAVE_OPT::                HAVE_OPT( <NAME> ) - Have this option?
4271 * ISSEL_OPT::               ISSEL_OPT( <NAME> ) - Is Option Selected?
4272 * ISUNUSED_OPT::            ISUNUSED_OPT( <NAME> ) - Never Specified?
4273 * OPTION_CT::               OPTION_CT - Full Count of Options
4274 * OPT_ARG::                 OPT_ARG( <NAME> ) - Option Argument String
4275 * OPT_NO_XLAT_CFG_NAMES::   OPT_NO_XLAT_CFG_NAMES - option name xlation
4276 * OPT_NO_XLAT_OPT_NAMES::   OPT_NO_XLAT_OPT_NAMES - option name xlation
4277 * OPT_VALUE_name::          OPT_VALUE_name - Option Argument Value
4278 * OPT_XLAT_CFG_NAMES::      OPT_XLAT_CFG_NAMES - option name xlation
4279 * OPT_XLAT_OPT_NAMES::      OPT_XLAT_OPT_NAMES - option name xlation
4280 * RESTART_OPT::             RESTART_OPT( n ) - Resume Option Processing
4281 * SET_OPT_name::            SET_OPT_name - Force an option to be set
4282 * STACKCT_OPT::             STACKCT_OPT( <NAME> ) - Stacked Arg Count
4283 * STACKLST_OPT::            STACKLST_OPT( <NAME> ) - Argument Stack
4284 * START_OPT::               START_OPT - Restart Option Processing
4285 * STATE_OPT::               STATE_OPT( <NAME> ) - Option State
4286 * USAGE::                   USAGE( exit-code ) - Usage invocation macro
4287 * VALUE_OPT_name::          VALUE_OPT_name - Option Flag Value
4288 * VERSION::                 VERSION - Version and Full Version
4289 * WHICH_IDX_name::          WHICH_IDX_name - Which Equivalenced Index
4290 * WHICH_OPT_name::          WHICH_OPT_name - Which Equivalenced Option
4291 * teOptIndex::              teOptIndex - Option Index and Enumeration
4292 * OPTIONS_STRUCT_VERSION::  OPTIONS_STRUCT_VERSION - active version
4293 * libopts procedures::      libopts External Procedures
4294 @end menu
4295
4296 @node Option Processing Data
4297 @subsection Data for Option Processing
4298 @cindex Option Processing Data
4299
4300 This section describes the data that may be accessed from within the
4301 option processing callback routines.  The following fields may be used
4302 in the following ways and may be used for read only.  The first set is
4303 addressed from the @code{tOptDesc*} pointer:
4304
4305 @table @samp
4306 @cindex optIndex
4307 @item optIndex
4308 @cindex optValue
4309 @item optValue
4310 These may be used by option procedures to determine which option they
4311 are working on (in case they handle several options).
4312
4313 @cindex optActualIndex
4314 @item optActualIndex
4315 @cindex optActualValue
4316 @item optActualValue
4317 These may be used by option procedures to determine which option was
4318 used to set the current option.  This may be different from the above if
4319 the options are members of an equivalence class.
4320
4321 @cindex optOccCt
4322 @item optOccCt
4323 If AutoOpts is processing command line arguments, then this value will contain
4324 the current occurrence count.  During the option preset phase (reading
4325 configuration files and examining environment variables), the value is zero.
4326
4327 @cindex fOptState
4328 @item fOptState
4329 The field may be tested for the following bit values
4330 (prefix each name with @code{OPTST_}, e.g. @code{OPTST_INIT}):
4331
4332 @table @samp
4333 @item INIT
4334 Initial compiled value.  As a bit test, it will always yield FALSE.
4335
4336 @item SET
4337 The option was set via the @code{SET_OPT()} macro.
4338
4339 @item PRESET
4340 @cindex configuration file
4341 The option was set via a configuration file.
4342
4343 @item DEFINED
4344 The option was set via a command line option.
4345
4346 @item SET_MASK
4347 This is a mask of flags that show the set state, one of the
4348 above four values.
4349
4350 @item EQUIVALENCE
4351 This bit is set when the option was selected by an equivalenced option.
4352
4353 @item DISABLED
4354 This bit is set if the option is to be disabled.
4355 (Meaning it was a long option prefixed by the disablement prefix, or
4356 the option has not been specified yet and initializes as @code{disabled}.)
4357 @end table
4358
4359 As an example of how this might be used, in AutoGen I want to allow
4360 template writers to specify that the template output can be left
4361 in a writable or read-only state.  To support this, there is a Guile
4362 function named @code{set-writable} (@pxref{SCM set-writable}).
4363 Also, I provide for command options @option{--writable} and
4364 @option{--not-writable}.  I give precedence to command line and RC
4365 file options, thus:
4366
4367 @example
4368 switch (STATE_OPT( WRITABLE )) @{
4369 case OPTST_DEFINED:
4370 case OPTST_PRESET:
4371     fprintf(stderr, zOverrideWarn, pCurTemplate->pzFileName,
4372             pCurMacro->lineNo);
4373     break;
4374
4375 default:
4376     if (gh_boolean_p( set ) && (set == SCM_BOOL_F))
4377         CLEAR_OPT( WRITABLE );
4378     else
4379         SET_OPT_WRITABLE;
4380 @}
4381 @end example
4382
4383 @cindex pzLastArg
4384 @item pzLastArg
4385 Pointer to the latest argument string.  BEWARE@: If the argument type
4386 is numeric, an enumeration or a bit mask, then this will be the
4387 argument @strong{value} and not a pointer to a string.
4388 @end table
4389
4390 The following two fields are addressed from the @code{tOptions*} pointer:
4391
4392 @table @samp
4393 @cindex pzProgName
4394 @item pzProgName
4395 Points to a NUL-terminated string containing the current program
4396 name, as retrieved from the argument vector.
4397
4398 @cindex pzProgPath
4399 @item pzProgPath
4400 Points to a NUL-terminated string containing the full path of
4401 the current program, as retrieved from the argument vector.
4402 (If available on your system.)
4403
4404 @end table
4405
4406 Note@:  these fields get filled in during the first call to
4407 @code{optionProcess()}.  All other fields are private, for the exclusive
4408 use of AutoOpts code and are subject to change.
4409
4410 @node CLEAR_OPT
4411 @subsection CLEAR_OPT( <NAME> ) - Clear Option Markings
4412 @findex CLEAR_OPT
4413
4414 Make as if the option had never been specified.
4415 @code{HAVE_OPT(<NAME>)} will yield @code{FALSE}
4416 after invoking this macro.
4417
4418 @node COUNT_OPT
4419 @subsection COUNT_OPT( <NAME> ) - Definition Count
4420 @findex COUNT_OPT
4421
4422 This macro will tell you how many times the option was
4423 specified on the command line.  It does not include counts
4424 of preset options.
4425
4426 @example
4427 if (COUNT_OPT( NAME ) != desired-count) @{
4428     make-an-undesirable-message.
4429 @}
4430 @end example
4431
4432 @node DESC
4433 @subsection DESC( <NAME> ) - Option Descriptor
4434 @findex DESC
4435
4436 This macro is used internally by other AutoOpt macros.
4437 It is not for general use.  It is used to obtain the option description
4438 corresponding to its @strong{UPPER CASED} option name argument.
4439 This is primarily used in other macro definitions.
4440
4441 @node DISABLE_OPT_name
4442 @subsection DISABLE_OPT_name - Disable an option
4443 @findex DISABLE_OPT_name
4444
4445 This macro is emitted if it is both settable
4446 and it can be disabled.  If it cannot be disabled, it may
4447 always be CLEAR-ed (see above).
4448
4449 The form of the macro will actually depend on whether the
4450 option is equivalenced to another, and/or has an assigned
4451 handler procedure.  Unlike the @code{SET_OPT} macro,
4452 this macro does not allow an option argument.
4453
4454 @example
4455 DISABLE_OPT_NAME;
4456 @end example
4457
4458 @node ENABLED_OPT
4459 @subsection ENABLED_OPT( <NAME> ) - Is Option Enabled?
4460 @findex ENABLED_OPT
4461
4462 Yields true if the option defaults to disabled and
4463 @code{ISUNUSED_OPT()} would yield true.  It also yields true if
4464 the option has been specified with a disablement prefix,
4465 disablement value or the @code{DISABLE_OPT_NAME} macro was invoked.
4466
4467 @node ERRSKIP_OPTERR
4468 @subsection ERRSKIP_OPTERR - Ignore Option Errors
4469 @findex ERRSKIP_OPTERR
4470
4471 When it is necessary to continue (return to caller)
4472 on option errors, invoke this option.  It is reversible.
4473 @xref{ERRSTOP_OPTERR}.
4474
4475 @node ERRSTOP_OPTERR
4476 @subsection ERRSTOP_OPTERR - Stop on Errors
4477 @findex ERRSTOP_OPTERR
4478
4479 After invoking this macro, if @code{optionProcess()}
4480 encounters an error, it will call @code{exit(1)} rather than return.
4481 This is the default processing mode.  It can be overridden by
4482 specifying @code{allow-errors} in the definitions file,
4483 or invoking the macro @xref{ERRSKIP_OPTERR}.
4484
4485 @node HAVE_OPT
4486 @subsection HAVE_OPT( <NAME> ) - Have this option?
4487 @findex HAVE_OPT
4488
4489 This macro yields true if the option has been specified
4490 in any fashion at all.  It is used thus:
4491
4492 @example
4493 if (HAVE_OPT( NAME )) @{
4494     <do-things-associated-with-opt-name>;
4495 @}
4496 @end example
4497
4498 @node ISSEL_OPT
4499 @subsection ISSEL_OPT( <NAME> ) - Is Option Selected?
4500 @findex ISSEL_OPT
4501
4502 This macro yields true if the option has been
4503 specified either on the command line or via a SET/DISABLE macro.
4504
4505 @node ISUNUSED_OPT
4506 @subsection ISUNUSED_OPT( <NAME> ) - Never Specified?
4507 @findex ISUNUSED_OPT
4508
4509 This macro yields true if the option has
4510 never been specified, or has been cleared via the
4511 @code{CLEAR_OPT()} macro.
4512
4513 @node OPTION_CT
4514 @subsection OPTION_CT - Full Count of Options
4515 @findex OPTION_CT
4516
4517 The full count of all options, both those defined
4518 and those generated automatically by AutoOpts.  This is primarily
4519 used to initialize the program option descriptor structure.
4520
4521 @node OPT_ARG
4522 @subsection OPT_ARG( <NAME> ) - Option Argument String
4523 @findex OPT_ARG
4524
4525 The option argument value as a pointer to string.  Note that argument
4526 values that have been specified as numbers are stored as numbers or
4527 keywords.  For such options, use instead the @code{OPT_VALUE_name}
4528 define.  It is used thus:
4529
4530 @example
4531 if (HAVE_OPT( NAME )) @{
4532     char* p = OPT_ARG( NAME );
4533     <do-things-with-opt-name-argument-string>;
4534 @}
4535 @end example
4536
4537 @node OPT_NO_XLAT_CFG_NAMES
4538 @subsection OPT_NO_XLAT_CFG_NAMES - option name xlation
4539 @findex OPT_NO_XLAT_CFG_NAMES
4540
4541 Invoking this macro will disable the translation of option names only while
4542 processing configuration files and environment variables.  This must be
4543 invoked before the first call to @code{optionProcess}..  You need not invoke
4544 this if your option definition file contains the attribute assignment,
4545 @code{no-xlate = opt-cfg;}.
4546
4547 @node OPT_NO_XLAT_OPT_NAMES
4548 @subsection OPT_NO_XLAT_OPT_NAMES - option name xlation
4549 @findex OPT_NO_XLAT_OPT_NAMES
4550
4551 Invoking this macro will completely disable the translation of option names.
4552 This must be invoked before the first call to @code{optionProcess}.  You need
4553 not invoke this if your option definition file contains the attribute
4554 assignment, @code{no-xlate = opt;}.
4555
4556 @node OPT_VALUE_name
4557 @subsection OPT_VALUE_name - Option Argument Value
4558 @findex OPT_VALUE_name
4559
4560 This macro gets emitted only for options that take numeric, keyword or set
4561 membership arguments.  The macro yields a word-sized integer containing the
4562 enumeration, bit set or numeric value for the option argument.
4563
4564 @example
4565 int opt_val = OPT_VALUE_name;
4566 @end example
4567
4568 @node OPT_XLAT_CFG_NAMES
4569 @subsection OPT_XLAT_CFG_NAMES - option name xlation
4570 @findex OPT_XLAT_CFG_NAMES
4571
4572 If @code{ENABLE_NLS} is defined and @code{no-xlate} has been not set to the
4573 value @emph{anything}, this macro will cause the translation of option names
4574 to happen before starting the processing of configuration files and
4575 environment variables.  This will change the recognition of options within the
4576 @code{$PROGRAMNAME} environment variable, but will not alter the names used
4577 for setting options via @code{$PROGRAMNAME_name} environment variables.
4578
4579 This must be invoked before the first call to @code{optionProcess}.  You might
4580 need to use this macro if your option definition file contains the attribute
4581 assignment, @code{no-xlate = opt;} or @code{no-xlate = opt-cfg;}, and
4582 you have determined in some way that you wish to override that.
4583
4584 @node OPT_XLAT_OPT_NAMES
4585 @subsection OPT_XLAT_OPT_NAMES - option name xlation
4586 @findex OPT_XLAT_OPT_NAMES
4587
4588 If @code{ENABLE_NLS} is defined and @code{no-xlate} has been not set to the
4589 value @emph{anything}, translate the option names before processing the
4590 command line options.  Long option names may thus be localized.  (If the names
4591 were translated before configuration processing, they will not be
4592 re-translated.)
4593
4594 This must be invoked before the first call to @code{optionProcess}.  You might
4595 need to use this macro if your option definition file contains the attribute
4596 assignment, @code{no-xlate = opt;} and you have determined in some way that
4597 you wish to override that.
4598
4599 @node RESTART_OPT
4600 @subsection RESTART_OPT( n ) - Resume Option Processing
4601 @findex RESTART_OPT
4602
4603 If option processing has stopped (either because of an error
4604 or something was encountered that looked like a program argument),
4605 it can be resumed by providing this macro with the index @code{n}
4606 of the next option to process and calling @code{optionProcess()} again.
4607
4608 @example
4609 int main(int argc, char ** argv) @{
4610   for (int ai = 0; ai < argc ;) @{
4611   restart:
4612     ai = optionProcess(&progOptions, argc, argv);
4613     for (; ai < argc; ai++) @{
4614       char * arg = arg[ai];
4615       if (*arg == '-') @{
4616         RESTART_OPT(ai);
4617         goto restart;
4618       @}
4619       process(arg);
4620     @}
4621   @}
4622 @}
4623 @end example
4624
4625 If you want a program to operate this way, you might consider specifying a
4626 @code{for-each} main function
4627 (@pxref{main for-each, for-each main procedure}) with the @code{interleaved}
4628 attribute.  It will allow you to process interleaved operands and options from
4629 either the command line or when reading them from standard input.
4630
4631 @node SET_OPT_name
4632 @subsection SET_OPT_name - Force an option to be set
4633 @findex SET_OPT_name
4634
4635 This macro gets emitted only when the given
4636 option has the @code{settable} attribute specified.
4637
4638 The form of the macro will actually depend on whether the option is
4639 equivalenced to another, has an option argument and/or has an assigned
4640 handler procedure.  If the option has an argument, then this macro will
4641 too.  Beware that the argument is not reallocated, so the value must not
4642 be on the stack or deallocated in any other way for as long as the value
4643 might get referenced.
4644
4645 If you have supplied at least one @file{homerc} file
4646 (@pxref{program attributes}), this macro will be emitted for the
4647 @option{--save-opts} option.
4648
4649 @example
4650 SET_OPT_SAVE_OPTS( "filename" );
4651 @end example
4652
4653 @noindent
4654 @xref{automatic options}, for a discussion of the implications of using
4655 this particular example.
4656
4657 @node STACKCT_OPT
4658 @subsection STACKCT_OPT( <NAME> ) - Stacked Arg Count
4659 @findex STACKCT_OPT
4660
4661 When the option handling attribute is specified
4662 as @code{stack_arg}, this macro may be used to determine how
4663 many of them actually got stacked.
4664
4665 Do not use this on options that have not been stacked or has not been
4666 specified (the @code{stack_arg} attribute must have been specified,
4667 and @code{HAVE_OPT(<NAME>)} must yield TRUE).
4668 Otherwise, you will likely seg fault.
4669
4670 @example
4671 if (HAVE_OPT( NAME )) @{
4672     int     ct = STACKCT_OPT(  NAME );
4673     char**  pp = STACKLST_OPT( NAME );
4674
4675     do  @{
4676         char* p = *pp++;
4677         do-things-with-p;
4678     @} while (--ct > 0);
4679 @}
4680 @end example
4681
4682 @node STACKLST_OPT
4683 @subsection STACKLST_OPT( <NAME> ) - Argument Stack
4684 @findex STACKLST_OPT
4685
4686 The address of the list of pointers to the
4687 option arguments.  The pointers are ordered by the order in
4688 which they were encountered in the option presets and
4689 command line processing.
4690
4691 Do not use this on options that have not been stacked or has not been
4692 specified (the @code{stack_arg} attribute must have been specified,
4693 and @code{HAVE_OPT(<OPTION>)} must yield TRUE).
4694 Otherwise, you will likely seg fault.
4695
4696 @example
4697 if (HAVE_OPT( NAME )) @{
4698     int     ct = STACKCT_OPT(  NAME );
4699     char**  pp = STACKLST_OPT( NAME );
4700
4701     do  @{
4702         char* p = *pp++;
4703         do-things-with-p;
4704     @} while (--ct > 0);
4705 @}
4706 @end example
4707
4708 @node START_OPT
4709 @subsection START_OPT - Restart Option Processing
4710 @findex START_OPT
4711
4712 This is just a shortcut for RESTART_OPT(1) (@xref{RESTART_OPT}.)
4713
4714 @node STATE_OPT
4715 @subsection STATE_OPT( <NAME> ) - Option State
4716 @findex STATE_OPT
4717
4718 If you need to know if an option was set because of presetting actions
4719 (configuration file processing or environment variables), versus a command
4720 line entry versus one of the SET/DISABLE macros, then use this macro.  It
4721 will yield one of four values: @code{OPTST_INIT}, @code{OPTST_SET},
4722 @code{OPTST_PRESET} or @code{OPTST_DEFINED}.  It is used thus:
4723
4724 @example
4725 switch (STATE_OPT( NAME )) @{
4726     case OPTST_INIT:
4727         not-preset, set or on the command line.  (unless CLEAR-ed)
4728
4729     case OPTST_SET:
4730         option set via the SET_OPT_NAME() macro.
4731
4732     case OPTST_PRESET:
4733         option set via an configuration file or environment variable
4734
4735     case OPTST_DEFINED:
4736         option set via a command line option.
4737
4738     default:
4739         cannot happen :)
4740 @}
4741 @end example
4742
4743 @node USAGE
4744 @subsection USAGE( exit-code ) - Usage invocation macro
4745 @findex USAGE
4746
4747 This macro invokes the procedure registered to display
4748 the usage text.  Normally, this will be @code{optionUsage} from the
4749 AutoOpts library, but you may select another procedure by specifying
4750 @code{usage = "proc_name"} program attribute.  This procedure must
4751 take two arguments@:  first, a pointer to the option descriptor, and
4752 second the exit code.  The macro supplies the option descriptor
4753 automatically.  This routine is expected to call @code{exit(3)} with
4754 the provided exit code.
4755
4756 The @code{optionUsage} routine also behaves differently depending
4757 on the exit code:
4758
4759 @table @code
4760 @item EXIT_SUCCESS (the value zero)
4761 It is assumed that full usage help has been requested.  Consequently, more
4762 information is provided than when displaying usage and exiting with a
4763 non-zero exit code.  Output will be sent to @file{stdout} and the program will
4764 exit with a zero status code.
4765
4766 @item EX_USAGE (64)
4767 The abbreviated usage will be printed to @file{stdout} and the program will
4768 exit with a zero status code.  @code{EX_USAGE} may or may not be 64.  If your
4769 system provides @file{/usr/include/sysexits.h} that has a different value,
4770 then that value will be used.
4771
4772 @item any other value
4773 The abbreviated usage will be printed to stderr and the program will
4774 exit with the provided status code.
4775 @end table
4776
4777 @node VALUE_OPT_name
4778 @subsection VALUE_OPT_name - Option Flag Value
4779 @findex VALUE_OPT_name
4780
4781 This is a #define for the flag character used to
4782 specify an option on the command line.  If @code{value} was not
4783 specified for the option, then it is a unique number associated
4784 with the option.  @code{option value} refers to this value,
4785 @code{option argument} refers to the (optional) argument to the
4786 option.
4787
4788 @example
4789 switch (WHICH_OPT_OTHER_OPT) @{
4790 case VALUE_OPT_NAME:
4791     this-option-was-really-opt-name;
4792 case VALUE_OPT_OTHER_OPT:
4793     this-option-was-really-other-opt;
4794 @}
4795 @end example
4796
4797 @node VERSION
4798 @subsection VERSION - Version and Full Version
4799 @findex VERSION
4800
4801 If the @code{version} attribute is defined for the program,
4802 then a stringified version will be #defined as PROGRAM_VERSION and
4803 PROGRAM_FULL_VERSION.  PROGRAM_FULL_VERSION is used for printing
4804 the program version in response to the version option.  The version
4805 option is automatically supplied in response to this attribute, too.
4806
4807 You may access PROGRAM_VERSION via @code{programOptions.pzFullVersion}.
4808
4809 @node WHICH_IDX_name
4810 @subsection WHICH_IDX_name - Which Equivalenced Index
4811 @findex WHICH_IDX_name
4812
4813 This macro gets emitted only for equivalenced-to options.  It is used to
4814 obtain the index for the one of the several equivalence class members
4815 set the equivalenced-to option.
4816
4817 @example
4818 switch (WHICH_IDX_OTHER_OPT) @{
4819 case INDEX_OPT_NAME:
4820     this-option-was-really-opt-name;
4821 case INDEX_OPT_OTHER_OPT:
4822     this-option-was-really-other-opt;
4823 @}
4824 @end example
4825
4826 @node WHICH_OPT_name
4827 @subsection WHICH_OPT_name - Which Equivalenced Option
4828 @findex WHICH_OPT_name
4829
4830 This macro gets emitted only for equivalenced-to options.  It is used to
4831 obtain the value code for the one of the several equivalence class members
4832 set the equivalenced-to option.
4833
4834 @example
4835 switch (WHICH_OPT_OTHER_OPT) @{
4836 case VALUE_OPT_NAME:
4837     this-option-was-really-opt-name;
4838 case VALUE_OPT_OTHER_OPT:
4839     this-option-was-really-other-opt;
4840 @}
4841 @end example
4842
4843 @node teOptIndex
4844 @subsection teOptIndex - Option Index and Enumeration
4845 @findex teOptIndex
4846
4847 This enum defines the complete set of options, both
4848 user specified and automatically provided.  This can be used,
4849 for example, to distinguish which of the equivalenced options
4850 was actually used.
4851
4852 @example
4853 switch (pOptDesc->optActualIndex) @{
4854 case INDEX_OPT_FIRST:
4855     stuff;
4856 case INDEX_OPT_DIFFERENT:
4857     different-stuff;
4858 default:
4859     unknown-things;
4860 @}
4861 @end example
4862
4863 @node OPTIONS_STRUCT_VERSION
4864 @subsection OPTIONS_STRUCT_VERSION - active version
4865
4866 You will not actually need to reference this value, but you need to be
4867 aware that it is there.  It is the first value in the option descriptor
4868 that you pass to @code{optionProcess}.  It contains a magic number and
4869 version information.  Normally, you should be able to work with a more
4870 recent option library than the one you compiled with.  However, if the
4871 library is changed incompatibly, then the library will detect the out of
4872 date magic marker, explain the difficulty and exit.  You will then need
4873 to rebuild and recompile your option definitions.  This has rarely been
4874 necessary.
4875
4876 @ignore
4877 END   == AUTOOPTS-API == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
4878 Extraction from autogen.texi
4879 @end ignore
4880
4881 @ignore
4882 START == AUTOOPTS-DATA == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
4883 Extraction from autogen.texi
4884 @end ignore
4885
4886 @c === SECTION MARKER
4887
4888 @node Multi-Threading
4889 @section Multi-Threading
4890
4891 AutoOpts was designed to configure a program for running.  This generally
4892 happens before much real work has been started.  Consequently, it is
4893 expected to be run before multi-threaded applications have started multiple
4894 threads.  However, this is not always the case. Some applications may
4895 need to reset and reload their running configuration, and some may use
4896 @code{SET_OPT_xxx()} macros during processing.  If you need to dynamically
4897 change your option configuration in your multi-threaded application, it is
4898 your responsibility to prevent all threads from accessing the option
4899 configuration state, except the one altering the configuration.
4900
4901 The various accessor macros (@code{HAVE_OPT()}, etc.) do not modify state
4902 and are safe to use in a multi-threaded application.  It is safe as long
4903 as no other thread is concurrently modifying state, of course.
4904
4905 @c === SECTION MARKER
4906
4907 @node option descriptor
4908 @section Option Descriptor File
4909 @cindex option descriptor
4910
4911 This is the module that is to be compiled and linked with your program.
4912 It contains internal data and procedures subject to change.  Basically,
4913 it contains a single global data structure containing all the
4914 information provided in the option definitions, plus a number of static
4915 strings and any callout procedures that are specified or required.  You
4916 should never have need for looking at this, except, perhaps, to examine
4917 the code generated for implementing the @code{flag-code} construct.
4918
4919 @c === SECTION MARKER
4920
4921 @node Using AutoOpts
4922 @section Using AutoOpts
4923 @cindex using AutoOpts
4924
4925 There are actually several levels of @code{using} autoopts.
4926 Which you choose depends upon how you plan to distribute
4927 (or not) your application.
4928
4929 @menu
4930 * local use::               local-only use
4931 * binary not installed::    binary distro, AutoOpts not installed
4932 * binary pre-installed::    binary distro, AutoOpts pre-installed
4933 * source pre-installed::    source distro, AutoOpts pre-installed
4934 * source not installed::    source distro, AutoOpts not installed
4935 @end menu
4936
4937 @node local use
4938 @subsection local-only use
4939
4940 To use AutoOpts in your application where you do not have to
4941 worry about distribution issues, your issues are simple and few.
4942
4943 @itemize @bullet
4944 @item
4945 Create a file @samp{myopts.def}, according to the documentation above.
4946 It is probably easiest to start with the example in @ref{Quick Start}
4947 and edit it into the form you need.
4948
4949 @item
4950 Run AutoGen to create the option interface file (@code{myopts.h})
4951 and the option descriptor code (@code{myopts.c}):
4952
4953 @example
4954 autogen myopts.def
4955 @end example
4956
4957 @item
4958 In all your source files where you need to refer to option state,
4959 @code{#include "myopts.h"}.
4960 @item
4961 In your main routine, code something along the lines of:
4962
4963 @example
4964 #define ARGC_MIN some-lower-limit
4965 #define ARGC_MAX some-upper-limit
4966 main( int argc, char** argv )
4967 @{
4968     @{
4969         int arg_ct = optionProcess( &myprogOptions, argc, argv );
4970         argc -= arg_ct;
4971         if ((argc < ARGC_MIN) || (argc > ARGC_MAX)) @{
4972             fprintf( stderr, "%s ERROR:  remaining args (%d) "
4973                      "out of range\n", myprogOptions.pzProgName,
4974                      argc );
4975
4976             USAGE( EXIT_FAILURE );
4977         @}
4978         argv += arg_ct;
4979     @}
4980     if (HAVE_OPT(OPTN_NAME))
4981         respond_to_optn_name();
4982     ...
4983 @}
4984 @end example
4985
4986 @item
4987 Compile @samp{myopts.c} and link your program
4988 with the following additional arguments:
4989
4990 @example
4991 `autoopts-config cflags ldflags` myopts.c
4992 @end example
4993 @end itemize
4994
4995 @node binary not installed
4996 @subsection binary distro, AutoOpts not installed
4997
4998 If you will be distributing (or copying) your project to a system that
4999 does not have AutoOpts installed, you will need to statically link the
5000 AutoOpts library, @code{libopts} into your program.  Get the link information
5001 with @code{static-libs} instead of @code{ldflags}:
5002
5003 @example
5004 `autoopts-config static-libs`
5005 @end example
5006
5007 @node binary pre-installed
5008 @subsection binary distro, AutoOpts pre-installed
5009
5010 If you will be distributing (or copying) your project to a system that does
5011 have AutoOpts (or only @code{libopts}) installed, you will still need to
5012 ensure that the library is findable at program load time, or you will still
5013 have to statically link.  The former can be accomplished by linking your
5014 project with @option{--rpath} or by setting the @env{LD_LIBRARY_PATH}
5015 appropriately.  Otherwise, @xref{binary not installed}.
5016
5017 @node source pre-installed
5018 @subsection source distro, AutoOpts pre-installed
5019
5020 If you will be distributing your project to a system that will build
5021 your product but it may not be pre-installed with AutoOpts, you will
5022 need to do some configuration checking before you start the build.
5023 Assuming you are willing to fail the build if AutoOpts has not been
5024 installed, you will still need to do a little work.
5025
5026 AutoOpts is distributed with a configuration check M4 script,
5027 @file{autoopts.m4}.  It will add an @code{autoconf} macro named,
5028 @code{AG_PATH_AUTOOPTS}.  Add this to your @file{configure.ac} script
5029 and use the following substitution values:
5030
5031 @table @code
5032 @item AUTOGEN
5033 the name of the autogen executable
5034 @item AUTOGEN_TPLIB
5035 the directory where AutoGen template library is stored
5036 @item AUTOOPTS_CFLAGS
5037 the compile time options needed to find the AutoOpts headers
5038 @item AUTOOPTS_LIBS
5039 the link options required to access the @code{libopts} library
5040 @end table
5041
5042 @node source not installed
5043 @subsection source distro, AutoOpts not installed
5044
5045 If you will be distributing your project to a system that will build
5046 your product but it may not be pre-installed with AutoOpts, you may
5047 wish to incorporate the sources for @code{libopts} in your project.
5048 To do this, I recommend reading the tear-off libopts library
5049 @file{README} that you can find in the @file{pkg/libopts} directory.
5050 You can also examine an example package (blocksort) that incorporates
5051 this tear off library in the autogen distribution directory.  There is
5052 also a web page that describes what you need to do:
5053 @example
5054 @url{http://autogen.sourceforge.net/blocksort.html}
5055 @end example
5056
5057 Alternatively, you can pull the @code{libopts} library sources into
5058 a build directory and build it for installation along with your package.
5059 This can be done approximately as follows:
5060 @example
5061 tar -xzvf `autoopts-config libsrc`
5062 cd libopts-*
5063 ./bootstrap
5064 configure
5065 make
5066 make install
5067 @end example
5068 That will install the library, but not the headers or anything else.
5069
5070 @c === SECTION MARKER
5071
5072 @node Presetting Options
5073 @section Configuring your program
5074 @cindex shell options
5075
5076 AutoOpts supports the notion of @code{presetting} the value or state of an
5077 option.  The values may be obtained either from environment variables or from
5078 configuration files (@file{rc} or @file{ini} files).  In order to take
5079 advantage of this, the AutoOpts client program must specify these features in
5080 the option descriptor file (@pxref{program attributes}) with the @code{rcfile}
5081 or @code{environrc} attributes.
5082
5083 @menu
5084 * loading rcfile::      configuration file presets
5085 * saving rcfile::       Saving the presets into a configuration file
5086 * sample rcfile::       Creating a sample configuration file
5087 * environrc::           environment variable presets
5088 * config example::      Config file only example
5089 @end menu
5090
5091 It is also possible to configure your program @i{without} using
5092 the command line option parsing code.  This is done by using
5093 only the following four functions from the @file{libopts} library:
5094
5095 @table @samp
5096 @item configFileLoad
5097 (@pxref{libopts-configFileLoad}) will parse the contents of a config
5098 file and return a pointer to a structure representing the hierarchical
5099 value.  The values are sorted alphabetically by the value name and all
5100 entries with the same name will retain their original order.
5101 Insertion sort is used.
5102
5103 @item optionGetValue
5104 (@pxref{libopts-optionGetValue}) will find the first value within the
5105 hierarchy with a name that matches the name passed in.
5106
5107 @item optionNextValue
5108 (@pxref{libopts-optionNextValue}) will return the next value that
5109 follows the value passed in as an argument.  If you wish to get all
5110 the values for a particular name, you must take note when the name
5111 changes.
5112
5113 @item optionUnloadNested
5114 (@pxref{libopts-optionUnloadNested}).  The pointer passed in must be
5115 of type, @code{OPARG_TYPE_HIERARCHY} (see the autoopts/options.h
5116 header file).  @code{configFileLoad} will return a @code{tOptionValue}
5117 pointer of that type.  This function will release all the associated
5118 memory.  @code{AutoOpts} generated code uses this function for its own
5119 needs.  Client code should only call this function with pointers
5120 gotten from @code{configFileLoad}.
5121 @end table
5122
5123 @node loading rcfile
5124 @subsection configuration file presets
5125 @cindex rcfile
5126
5127 Configuration files are enabled by specifying the program attribute
5128 @code{homerc} (@pxref{program attributes}).  Any option not marked
5129 with the @code{no-preset} attribute may appear in a configuration file.
5130 The files loaded are selected both by the @code{homerc} entries and,
5131 optionally, via a command line option.  The first component of the
5132 @code{homerc} entry may be an environment variable such as @env{$HOME}, or
5133 it may also be @samp{$$} (@strong{two} dollar sign characters) to specify
5134 the directory of the executable.  For example:
5135
5136 @example
5137 homerc = "$$/../share/autogen";
5138 @end example
5139
5140 @noindent
5141 will cause the AutoOpts library to look in the normal autogen datadir
5142 relative to the current installation directory for autogen.
5143
5144 The configuration files are processed in the order they are specified by
5145 the @code{homerc} attribute, so that each new file will normally override
5146 the settings of the previous files.  This may be overridden by marking some
5147 options for @code{immediate action} (@pxref{Immediate Action}).  Any such
5148 options are acted upon in @strong{reverse} order.  The disabled
5149 @code{load-opts} (@option{--no-load-opts}) option, for example, is an
5150 immediate action option.  Its presence in the last @code{homerc} file will
5151 prevent the processing of any prior @code{homerc} files because its effect
5152 is immediate.
5153
5154 Configuration file processing can be completely suppressed by specifying
5155 @option{--no-load-opts} on the command line, or @code{PROGRAM_LOAD_OPTS=no} in
5156 the environment (if @code{environrc} has been specified).
5157
5158 See the @code{Configuration File Format} section (@pxref{Config File Format})
5159 for details on the format of the file.
5160
5161 @node saving rcfile
5162 @subsection Saving the presets into a configuration file
5163
5164 When configuration files are enabled for an application, the user is
5165 also provided with an automatically supplied @option{--save-opts} option.
5166 All of the known option state will be written to either the specified
5167 output file or, if it is not specified, then to the last specified
5168 @code{homerc} file.
5169
5170 @node sample rcfile
5171 @subsection Creating a sample configuration file
5172 @cindex sample rcfile
5173
5174 AutoOpts is shipped with a template named, @file{rc-sample.tpl}.
5175 If your option definition file specifies the @code{homerc} attribute,
5176 then you may invoke @file{autogen} thus:
5177
5178 @example
5179 autogen -Trc-sample <your-option-def-file>
5180 @end example
5181
5182 This will, by default, produce a sample file named,
5183 @file{sample-<prog-name>rc}.  It will be named differently if you specify your
5184 configuration (rc) file name with the @code{rcfile} attribute.  In that case,
5185 the output file will be named, @file{sample-<rcfile-name>}.  It will contain
5186 all of the program options not marked as @code{no-preset}.  It will also
5187 include the text from the @code{doc} attribute.
5188
5189 @ignore
5190 END   == AUTOOPTS-DATA == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5191 Extraction from autogen.texi
5192 @end ignore
5193
5194 @ignore
5195 START == AO-DATA1 == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5196 Extraction from autogen.texi
5197 @end ignore
5198
5199 @node environrc
5200 @subsection environment variable presets
5201 @cindex environrc
5202
5203 If the AutoOpts client program specifies @code{environrc} in its
5204 option descriptor file, then environment variables will be used for
5205 presetting option state.  Variables will be looked for that are named,
5206 @env{PROGRAM_OPTNAME} and @env{PROGRAM}.  @env{PROGRAM} is the
5207 upper cased @code{C-name} of the program, and @var{OPTNAME} is the
5208 upper cased @code{C-name} of a specific option.  (The @code{C-name}s
5209 are the regular names with all special characters converted to
5210 underscores (@code{_}).)
5211
5212 Option specific environment variables are processed after (and thus
5213 take precedence over) the contents of the @env{PROGRAM} environment
5214 variable.  The option argument string for these options takes on the
5215 string value gotten from the environment.  Consequently, you can only
5216 have one instance of the @var{OPTNAME}.
5217
5218 If a particular option may be disabled, then its disabled state is
5219 indicated by setting the @env{PROGRAM_OPTNAME} value to the
5220 disablement prefix.  So, for example, if the disablement prefix were
5221 @code{dont}, then you can disable the @code{optname} option by setting
5222 the @env{PROGRAM_OPTNAME}' environment variable to @code{@i{dont}}.
5223 @xref{Common Attributes}.
5224
5225 The @env{PROGRAM} environment string is tokenized and parsed much
5226 like a command line.  Doubly quoted strings have backslash escapes
5227 processed the same way they are processed in C program constant
5228 strings.  Singly quoted strings are pretty raw in that backslashes are
5229 honored before other backslashes, apostrophes, newlines and cr/newline
5230 pairs.  The options must be introduced with hyphens in the same way as
5231 the command line.
5232
5233 Note that not all options may be preset.  Options that are specified with the
5234 @code{no-preset} attribute and the @option{--help}, @option{--more-help},
5235 and @option{--save-opts} auto-supported options may not be preset.
5236
5237 @node config example
5238 @subsection Config file only example
5239 @cindex rcfile
5240 @cindex Configuration File
5241 @cindex Configuration File example
5242
5243 If for some reason it is difficult or unworkable to integrate configuration
5244 file processing with command line option parsing, the @code{libopts}
5245 (@pxref{libopts procedures}) library can still be used to process
5246 configuration files.  Below is a @t{Hello, World!} greeting program that tries
5247 to load a configuration file @file{hello.conf} to see if it should use an
5248 alternate greeting or to personalize the salutation.
5249 @ignore
5250 END   == AO-DATA1 == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5251 Extraction from autogen.texi
5252 @end ignore
5253
5254 @ignore
5255 START == AO-DATA2 == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5256 Extraction from autogen.texi
5257 @end ignore
5258
5259 @c === SECTION MARKER
5260
5261 @node Config File Format
5262 @section Configuration File Format
5263 @cindex Configuration File
5264
5265 The configuration file is designed to associate names and values, much like
5266 an AutoGen Definition File (@pxref{Definitions File}).  Unfortunately, the
5267 file formats are different.  Specifically, AutoGen Definitions provide for
5268 simpler methods for the precise control of a value string and provides for
5269 dynamically computed content.  Configuration files have some established
5270 traditions in their layout.  So, they are different, even though they do
5271 both allow for a single name to be associated with multiple values and they
5272 both allow for hierarchical values.
5273
5274 @menu
5275 * config name/string-value::    assigning a string value to a configurable
5276 * config integer-values::       integer values
5277 * config nested-values::        hierarchical values
5278 * config directives::           configuration file directives
5279 * config comments::             comments in the configuration file
5280 @end menu
5281
5282 @node config name/string-value
5283 @subsection assigning a string value to a configurable
5284
5285 The basic syntax is a name followed by a value on a single line.  They are
5286 separated from each other by either white space, a colon (@code{:}) or an
5287 equal sign (@code{=}).  The colon or equal sign may optionally be surrounded
5288 by additional white space.  If more than one value line is needed, a
5289 backslash (@code{\}) may be used to continue the value.  The backslash (but
5290 not the newline) will be erased.  Leading and trailing white space is always
5291 stripped from the value.
5292
5293 Fundamentally, it looks like this:
5294
5295 @example
5296 name  value for that name
5297 name = another \
5298      multi-line value \
5299      for that name.
5300 name: a *third* value for @code{name}
5301 @end example
5302
5303 If you need more control over the content of the value, you may enclose the
5304 value in XML style brackets:
5305 @example
5306 <name>value </name>
5307 @end example
5308 @noindent
5309 Within these brackets you need not (must not) continue the value data with
5310 backslashes.  You may also select the string formation rules to use, just
5311 add the attribute after the name, thus: @code{<name keep>}.
5312
5313 @table @samp
5314 @item keep
5315 This mode will keep all text between the brackets and not strip any
5316 white space.
5317 @item uncooked
5318 This mode strips leading and trailing white space, but not do any
5319 quote processing.  This is the default and need not be specified.
5320 @item cooked
5321 The text is trimmed of leading and trailing white space and XML encodings
5322 are processed.  These encodings are slightly expanded over the XML
5323 specification.  They are specified with an ampersand followed by a value
5324 name or numeric value and then a semicolon:
5325
5326 @table @samp
5327 @item  amp
5328 @itemx lt
5329 @itemx gt
5330 @itemx quot
5331 @itemx apos
5332 @itemx #dd
5333 @itemx #xHH
5334
5335 These are all per fairly standad HTML and/or XML encodings.
5336 Additionally:
5337
5338 @item bs
5339 The ASCII back space character.
5340 @item ff
5341 The ASCII form feed character.
5342 @item ht
5343 The ASCII horizontal (normal) tab character.
5344 @item cr
5345 The ASCII carriage return character.
5346 @item vt
5347 The ASCII vertical tab character.
5348 @item bel
5349 The ASCII alarm bell character.
5350 @item nl
5351 The ASCII new line character.
5352 @item space
5353 The ASCII space character.  Normally not necessary, but if you want
5354 to preserve leading or trailing space characters, then use this.
5355 @end table
5356 @end table
5357
5358 And here is an example of an XML-styled value:
5359
5360 @example
5361 <name cooked>
5362     This is&nl;&ht;another multi-line
5363 &ht;string example.
5364 </name>
5365 @end example
5366
5367 The string value associated with @code{name} will be exactly the text enclosed
5368 in quotes with the encoded characters @code{cooked} as you would expect (three
5369 text lines with the last line not ending with a newline, but ending with a
5370 period).
5371
5372 @node config integer-values
5373 @subsection integer values
5374
5375 A name can be specified as having an integer value.  To do this, you
5376 must use the XML-ish format and specify a @code{type} attribute for
5377 the name:
5378
5379 @example
5380 <name type=integer> 1234 </name>
5381 @end example
5382
5383 Boolean, enumeration and set membership types will be added as time
5384 allows.  @code{type=string} is also supported, but also is the default.
5385
5386 @node config nested-values
5387 @subsection hierarchical values
5388
5389 In order to specify a hierarchical value, you *must* use XML-styled
5390 formatting, specifying a type that is shorter and easier to spell:
5391
5392 @example
5393 <structured-name type=nested>
5394     [[....]]
5395 </structured-name>
5396 @end example
5397
5398 @noindent
5399 The ellipsis may be filled with any legal configuration file name/value
5400 assignments.
5401
5402 @node config directives
5403 @subsection configuration file directives
5404 @cindex autoopts directives
5405
5406 The @code{<?} marker indicates an XML directive.
5407 There is only one directive supported:  program sectioning,
5408 though two syntaxes are supported.
5409
5410 If, for example, you have a collection of programs that work closely
5411 together and, likely, have a common set of options, these programs may use a
5412 single, sectioned, configuration file.  The file may be sectioned in either
5413 of two ways.  The two ways may not be intermixed in a single configuration
5414 file.  All text before the first segmentation line is processed, then only
5415 the segment that applies:
5416
5417 @table @samp
5418 @item <?auto-options ...>
5419 The @code{...} ellipsis may contain AutoOpts option processing options.
5420 Currently, that consists of one or both of:
5421
5422 @table @code
5423 @item gnu
5424 @itemx autoopts
5425 to indicate GNU-standard or AutoOpts-standard layout of usage and
5426 version information, and/or
5427
5428 @item misuse-usage
5429 @itemx no-misuse-usage
5430 to indicate whether the available options should be listed when
5431 an invalid option appears on the command line.
5432 @end table
5433 @noindent
5434 Anything else will be silently ignored.
5435
5436 @item <?program prog-name>
5437 The @code{<?} marker indicates an XML directive.
5438 The file is partitioned by these lines and the options are processed
5439 for the @code{prog-name} program only before the first @code{<?program}
5440 directive and the program section with a matching program name.
5441
5442 @item [PROG_NAME]
5443 This is basically an alias for @code{<?program prog-name>}, except that
5444 the program name must be upper cased and segmented only with underscores
5445 and it is @strong{not} recognized as a program segment when updating
5446 configuration files with the @code{--save-opts} option. In other words,
5447 use this only for Windows compatibility.
5448 @end table
5449
5450 @noindent
5451 Segmentation does not apply if the config file is being parsed with
5452 the @code{configFileLoad(3AutoOpts)} function.
5453
5454 @node config comments
5455 @subsection comments in the configuration file
5456
5457 Comments are lines beginning with a hash mark (@code{#}),
5458 XML-style comments (@code{<!-- arbitrary text -->}), and
5459 unrecognized XML directives.
5460
5461 @example
5462 # this is a comment
5463 <!-- this is also
5464      a comment -->
5465 <?this is
5466   a bad comment ;->
5467 @end example
5468
5469 @c === SECTION MARKER
5470
5471 @node shell options
5472 @section AutoOpts for Shell Scripts
5473 @cindex shell options
5474 @cindex configuration file
5475
5476 AutoOpts may be used with shell scripts either by automatically creating a
5477 complete program that will process command line options and pass back
5478 the results to the invoking shell by issuing shell variable assignment
5479 commands, or it may be used to generate portable shell code that can
5480 be inserted into your script.
5481
5482 The functionality of these features, of course, is somewhat constrained
5483 compared with the normal program facilities.  Specifically, you cannot
5484 invoke callout procedures with either of these methods.  Additionally,
5485 if you generate a shell script to do the parsing:
5486
5487 @enumerate
5488 @item
5489 You cannot obtain options from configuration files.
5490 @item
5491 You cannot obtain options from environment variables.
5492 @item
5493 You cannot save the option state to an option file.
5494 @item
5495 Option conflict/requirement verification is disabled.
5496 @end enumerate
5497
5498 Both of these methods are enabled by running AutoGen on
5499 the definitions file with the additional main procedure attribute:
5500
5501 @example
5502 main = @{ main-type = shell-process; @};
5503 @end example
5504 @noindent
5505 or:
5506 @example
5507 main = @{ main-type = shell-parser; @};
5508 @end example
5509
5510 If you do not supply a @code{proc-to-call}, it will default to
5511 @code{optionPutShell}.  That will produce a program that will process the
5512 options and generate shell text for the invoking shell to interpret
5513 (@pxref{binary-parser}).  If you supply the name, @code{optionParseShell},
5514 then you will have a program that will generate a shell script that can parse
5515 the options (@pxref{script-parser}).  If you supply a different procedure
5516 name, you will have to provide that routine and it may do whatever you like.
5517
5518 @menu
5519 * binary-parser::        Parsing with an Executable
5520 * script-parser::        Parsing with a Portable Script
5521 @end menu
5522
5523 @node binary-parser
5524 @subsection Parsing with an Executable
5525
5526 The following commands are approximately all that is needed
5527 to build a shell script command line option parser from
5528 an option definition file:
5529
5530 @example
5531 autogen -L <opt-template-dir> test-errors.def
5532 cc -o test-errors -L <opt-lib-dir> -I <opt-include-dir> \
5533         -DTEST_PROGRAM_OPTS test-errors.c -lopts
5534 @end example
5535
5536 The resulting program can then be used within your shell script as follows:
5537
5538 @example
5539 eval `./test-errors "$@@"`
5540 if [ -z "$@{OPTION_CT@}" ] ; then exit 1 ; fi
5541 test $@{OPTION_CT@} -gt 0 && shift $@{OPTION_CT@}
5542 @end example
5543 @ignore
5544 END   == AO-DATA2 == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5545 Extraction from autogen.texi
5546 @end ignore
5547
5548 @ignore
5549 START == AUTOINFO == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
5550 Extraction from autogen.texi
5551 @end ignore
5552
5553 @c === SECTION MARKER
5554
5555 @node AutoInfo
5556 @section Automated Info Docs
5557 @cindex AutoInfo
5558
5559 AutoOpts provides two templates for producing @file{.texi} documentation.
5560 @file{agtexi-cmd.tpl} for the invoking section, and @file{aginfo3.tpl} for
5561 describing exported library functions and macros.
5562
5563 For both types of documents, the documentation level is selected by
5564 passing a @samp{-DLEVEL=<level-name>} argument to AutoGen when you build
5565 the document.  (See the example invocation below.)
5566
5567 Two files will be produced, a @file{.texi} file and a @file{.menu} file.
5568 You should include the text in the @file{.menu} file in a @file{@@menu}
5569 list, either with @file{@@include}-ing it or just copying text.
5570 The @file{.texi} file should be @file{@@include}-ed where the invoking
5571 section belongs in your document.
5572
5573 The @file{.texi} file will contain an introductory paragraph, a menu
5574 and a subordinate section for the invocation usage and for each
5575 documented option.  The introductory paragraph is normally the boiler
5576 plate text, along the lines of:
5577
5578 @example
5579 This chapter documents the @@file@{AutoOpts@} generated usage text
5580 and option meanings for the @@file@{your-program@} program.
5581 @end example
5582
5583 @noindent
5584 or:
5585
5586 @example
5587 These are the publicly exported procedures from the lib@i{name} library.
5588 Any other functions mentioned in the @i{header} file are for the private use
5589 of the library.
5590 @end example
5591
5592 @menu
5593 * command-info::      @code{invoking} info docs
5594 * library-info::      library info docs
5595 @end menu
5596
5597 @node command-info
5598 @subsection @code{invoking} info docs
5599
5600 Using the option definitions for an AutoOpt client program, the
5601 @file{agtexi-cmd.tpl} template will produce texinfo text that documents the
5602 invocation of your program.  The text emitted is designed to be included
5603 in the full texinfo document for your product.  It is not a stand-alone
5604 document.  The usage text for the @ref{autogen usage},
5605 @ref{getdefs usage} and @ref{columns usage} programs, are included in
5606 this document and are all generated using this template.
5607
5608 If your program's option definitions include a
5609 @samp{prog-info-descrip} section, then that text will replace the
5610 boilerplate introductory paragraph.
5611
5612 @noindent
5613 These files are produced by invoking the following command:
5614
5615 @example
5616 autogen -L $@{prefix@}/share/autogen -Tagtexi-cmd.tpl \
5617         -DLEVEL=section your-opts.def
5618 @end example
5619
5620 @noindent
5621 Where @file{$@{prefix@}} is the AutoGen installation prefix
5622 and @file{your-opts.def} is the name of your product's option
5623 definition file.
5624
5625 @node library-info
5626 @subsection library info docs
5627
5628 The @command{texinfo} doc for libraries is derived from mostly the same
5629 information as is used for producing man pages @xref{man3}.  The main
5630 difference is that there is only one output file and the individual
5631 functions are referenced from a @code{texi} menu.  There is also
5632 a small difference in the global attributes used:
5633
5634 @multitable @columnfractions .02 .23 .65
5635 @item @tab lib_description
5636 @tab A description of the library.  This text appears before the menu.
5637 If not provided, the standard boilerplate version will be inserted.
5638 @item
5639 @item @tab see_also
5640 @tab The @code{SEE ALSO} functionality is not supported for the
5641 @file{texinfo} documentation, so any @code{see_also} attribute will be
5642 ignored.
5643 @end multitable
5644
5645 @noindent
5646 These files are produced by invoking the following commands:
5647
5648 @example
5649 getdefs linenum srcfile template=aginfo3.tpl output=libexport.def \
5650        <source-file-list>
5651
5652 autogen -L $@{prefix@}/share/autogen -DLEVEL=section libexport.def
5653 @end example
5654
5655 @noindent
5656 Where @file{$@{prefix@}} is the AutoGen installation prefix
5657 and @file{libexport.def} is some name that suits you.
5658
5659 An example of this can be seen in this document, @xref{libopts procedures}.
5660
5661 @c === SECTION MARKER
5662
5663 @node AutoMan pages
5664 @section Automated Man Pages
5665 @cindex AutoMan pages
5666
5667 AutoOpts provides two templates for producing man pages.
5668 The command (@file{man1}) pages are derived from the options definition
5669 file, and the library (@file{man3}) pages are derived from
5670 stylized comments (@pxref{getdefs Invocation}).
5671
5672 Man pages include a date in the footer.  By default, this is derived from
5673 the current date.  However, this may be overridden with the @code{MAN_PAGE_DATE}
5674 environment variable.  If set and not empty, its contents will be copied
5675 into where the output of @code{date '+%d %b %Y'} would otherwise go.
5676
5677 Man pages may be formatted as either traditional man pages or using @code{mdoc} formatting.
5678 The format is selected by selecting the appropriate template.
5679
5680 @menu
5681 * man1::      command line man pages
5682 * man3::      library man pages
5683 @end menu
5684
5685 @node man1
5686 @subsection command line man pages
5687
5688 Man pages for commands are documented using the @file{agman-cmd.tpl}
5689 and @file{agmdoc-cmd.tpl} templates.  If the options specify pulling
5690 information from @file{RC}/@file{ini}/@file{cfg} files, then you may use
5691 the @file{rc-sample.tpl} template to produce an example config file for
5692 your program.
5693
5694 Using the option definitions for an AutoOpts client program,
5695 the @samp{agman-cmd.tpl} template will produce an nroff document
5696 suitable for use as a @samp{man(1)} page document for a command
5697 line command.  The description section of the document is either
5698 the @samp{prog-man-descrip} text, if present, or the @samp{detail}
5699 text.
5700
5701 Each option in the option definitions file is fully documented
5702 in its usage.  This includes all the information documented
5703 above for each option (@pxref{option attributes}), plus
5704 the @samp{doc} attribute is appended.  Since the @samp{doc}
5705 text is presumed to be designed for @code{texinfo} documentation,
5706 @code{sed} is used to convert some constructs from @code{texi}
5707 to @code{nroff}-for-@code{man}-pages.  Specifically,
5708
5709 @example
5710 convert @@code, @@var and @@samp into \fB...\fP phrases
5711 convert @@file into \fI...\fP phrases
5712 Remove the '@@' prefix from curly braces
5713 Indent example regions
5714 Delete the example commands
5715 Replace @samp{end example} command with ".br"
5716 Replace the @samp{@@*} command with ".br"
5717 @end example
5718
5719 @noindent
5720 This document is produced by invoking the following command:
5721
5722 @example
5723 autogen -L $@{prefix@}/share/autogen -Tagman-cmd.tpl options.def
5724 @end example
5725
5726 @noindent
5727 Where @file{$@{prefix@}} is the AutoGen installation prefix and
5728 @file{options.def} is the name of your product's option definition file.
5729 I do not use this very much, so any feedback or improvements would be
5730 greatly appreciated.
5731
5732 @node man3
5733 @subsection library man pages
5734
5735 Man pages for libraries are documented using the @file{agman3.tpl} template.
5736
5737 Two global definitions are required, and then
5738 one library man page is produced for each @code{export_func} definition
5739 that is found.  It is generally convenient to place these definitions
5740 as @file{getdefs} comments (@pxref{getdefs Invocation}) near the procedure
5741 definition, but they may also be a separate AutoGen definitions file
5742 (@pxref{Definitions File}).  Each function will be cross referenced
5743 with their sister functions in a @file{SEE ALSO} section.  A global
5744 @code{see_also} definition will be appended to this cross referencing text.
5745
5746 @noindent
5747 The two global definitions required are:
5748
5749 @multitable @columnfractions .02 .15 .77
5750 @item @tab library
5751 @tab This is the name of your library, without the @file{lib} prefix.
5752 The AutoOpts library is named @file{libopts.so...}, so the @code{library}
5753 attribute would have the value @code{opts}.
5754 @item
5755 @item @tab header
5756 @tab Generally, using a library with a compiled program entails
5757 @code{#include}-ing a header file.  Name that header with this attribute.
5758 In the case of AutoOpts, it is generated and will vary based on the
5759 name of the option definition file.  Consequently, @file{your-opts.h} is
5760 specified.
5761 @end multitable
5762
5763 @noindent
5764 The @code{export_func} definition should contain the following attributes:
5765
5766 @multitable @columnfractions .02 .15 .77
5767 @item @tab name
5768 @tab The name of the procedure the library user may call.
5769 @item @tab what
5770 @tab A brief sentence describing what the procedure does.
5771 @item @tab doc
5772 @tab A detailed description of what the procedure does.
5773 It may ramble on for as long as necessary to properly describe it.
5774 @item @tab err
5775 @tab A short description of how errors are handled.
5776 @item @tab ret_type
5777 @tab The data type returned by the procedure.
5778 Omit this for @code{void} procedures.
5779 @item @tab ret_desc
5780 @tab Describe what the returned value is, if needed.
5781 @item @tab private
5782 @tab If specified, the function will @strong{not} be documented.
5783 This is used, for example, to produce external declarations for functions
5784 that are not available for public use, but are used in the generated text.
5785 @item
5786 @item @tab arg
5787 @tab This is a compound attribute that contains:
5788 @end multitable
5789 @multitable @columnfractions .02 .15 .15 .62
5790 @item @tab @tab arg_type
5791 @tab The data type of the argument.
5792 @item @tab @tab arg_name
5793 @tab A short name for it.
5794 @item @tab @tab arg_desc
5795 @tab A brief description.
5796 @end multitable
5797
5798 @noindent
5799 As a @file{getdefs} comment, this would appear something like this:
5800
5801 @example
5802 /*=--subblock=arg=arg_type,arg_name,arg_desc =*/
5803 /*=*
5804  * library: opts
5805  * header:  your-opts.h
5806 =*/
5807 /*=export_func optionProcess
5808  *
5809  * what: this is the main option processing routine
5810  * arg:  + tOptions* + pOpts + program options descriptor +
5811  * arg:  + int       + argc  + program arg count  +
5812  * arg:  + char**    + argv  + program arg vector +
5813  * ret_type:  int
5814  * ret_desc:  the count of the arguments processed
5815  *
5816  * doc:  This is what it does.
5817  * err:  When it can't, it does this.
5818 =*/
5819 @end example
5820
5821 @noindent
5822 Note the @code{subblock} and @code{library} comments.
5823 @code{subblock} is an embedded @file{getdefs}
5824 option (@pxref{getdefs subblock}) that tells it how to parse the
5825 @code{arg} attribute.  The @code{library} and @code{header} entries
5826 are global definitions that apply to all the documented functions.
5827
5828 @c === SECTION MARKER
5829
5830 @node getopt_long
5831 @section Using getopt(3C)
5832 @cindex getopt_long
5833
5834 There is a template named, @file{getopt.tpl} that is distributed with
5835 AutoOpts.  Using that template instead of @file{options.tpl} will produce
5836 completely independent source code that will parse command line options.  It
5837 will utilize either the standard @code{getopt(3C)} or the GNU
5838 @code{getopt_long(3GNU)} function to drive the parsing.  Which is used is
5839 selected by the presence or absence of the @code{long-opts} program attribute.
5840 It will save you from being dependent upon the @code{libopts} library @i{and}
5841 it produces code ready for internationalization.  However, it also carries
5842 with it some limitations on the use of AutoOpts features and some requirements
5843 on the build environment.
5844
5845 @strong{PLEASE NOTE}: in processing the option definitions to produce
5846 the usage text, it is necessary to compile some generated code in a
5847 temporary directory.  That means that all the include directories
5848 needed to compile the code must be full path names and not relative
5849 directory names.  ``.'' is a relative directory name.  To specify
5850 ``-I.'' in the @code{CFLAGS} environment variable, you must expand it.
5851 For example, use:
5852 @example
5853 CFLAGS=-I`pwd`
5854 @end example
5855
5856 @menu
5857 * getopt limitations::  getopt feature limitations
5858 * getopt building::     getopt build requirements
5859 @end menu
5860
5861 @node getopt limitations
5862 @subsection getopt feature limitations
5863
5864 This list of limitations is relative to the full list of AutoOpts
5865 supported features, @xref{Features}.
5866
5867 @enumerate
5868 @item
5869 You cannot automatically take advantage of environment variable options or
5870 automated parsing of configuration files (@code{rc} or @code{ini} files).
5871 Consequently, the resulting code does not support @file{--load-opts} or
5872 @file{--save-opts} options automatically.
5873
5874 @item
5875 You cannot use set membership, enumerated, range checked or stacked
5876 argument type options.  In fact, you cannot use anything that depends
5877 upon the @code{libopts} library.  You are constrained to options that
5878 take @code{@code{string}} arguments, though you may handle the option
5879 argument with a callback procedure.
5880
5881 @item
5882 Special disablement and/or enablement prefixes are not recognized.
5883
5884 @item
5885 Option coordination with external libraries will not work.
5886
5887 @item
5888 Every option must be @code{settable} because the emitted code
5889 depends upon the @code{SET_OPT_XXX} macros having been defined.
5890 Specify this as a global (program) attribute.
5891
5892 @item
5893 You must specify a main procedure attribute (@pxref{Generated main}).
5894 The @file{getopt.tpl} template depends upon being able to compile the
5895 traditional .c file into a program and get it to emit the usage text.
5896
5897 @item
5898 For the same reason, the traditional option parsing table code must be
5899 emitted @b{before} the @file{getopt.tpl} template gets expanded.
5900
5901 @item
5902 The usage text is, therefore, statically defined.
5903 @end enumerate
5904
5905 @node getopt building
5906 @subsection getopt build requirements
5907
5908 You must supply some compile and link options via environment variables.
5909
5910 @table @samp
5911 @item srcdir
5912 In case the option definition file lives in a different directory.
5913 @item CFLAGS
5914 Any special flags required to compile.  The flags from
5915 @code{autoopts-config cflags} will be included automatically.  Since
5916 the creation of the option parsing code includes creating a program
5917 that prints out help text, if it is necessary to include files from
5918 various directories to compile that program, you will need to specify
5919 those directories with @option{-Idirpath} text in the @code{CFLAGS}.
5920 Some experimentation may be necessary in that case.
5921
5922 @strong{NOTE}: the @option{-Idirpath} text is only needed if your option
5923 callback functions include code that require additional @code{#include}
5924 directives.
5925 @item LDFLAGS
5926 Any special flags required to link.  The flags from
5927 @code{autoopts-config ldflags} will be included automatically.  This
5928 is required only if additional link flags for the help text emission
5929 program might be needed.
5930 @item CC
5931 This is needed only if @code{@code{cc}} cannot be found in @env{$PATH}
5932 (or it is not the one you want).
5933 @end table
5934
5935 To use this, set the exported environment variables and specify @code{getopt}
5936 as the default template in your option definitions file
5937 (@pxref{Identification}).  You will have @i{four} new files.  Assuming your
5938 definitions were in a file named @file{myprog-opts.def} and your program name
5939 was specified as @file{progname}, the resulting files would be created:
5940 @file{myprog-opts.h}, @file{myprog-opts.c}, @file{getopt-progname.h} and
5941 @file{getopt-progname.c}.  You must compile and link both @file{.c} files into
5942 your program.  If there are link failures, then you are using AutoOpts
5943 features that require the @file{libopts} library.  You must remove these
5944 features, @xref{getopt limitations}.
5945
5946 These generated files depend upon configure defines to work correctly.
5947 Therefore, you must specify a @code{config-header} attribute
5948 (@pxref{programming attributes}) and ensure it has @code{#defines} for
5949 either @code{HAVE_STDINT_H} or @code{HAVE_INTTYPES_H}; either
5950 @code{HAVE_SYS_LIMITS_H} or @code{HAVE_LIMITS_H}; and
5951 @code{HAVE_SYSEXITS_H}, if the @file{sysexits.h} header is available.
5952 The required header files for these defines are, respectively,
5953 the @file{/usr/include} files named:
5954 @itemize @bullet
5955 @item stdint.h
5956 @item inttypes.h
5957 @item sys/limits.h
5958 @item limits.h
5959 @item sysexits.h
5960 @end itemize
5961
5962 @noindent
5963 The following header files must also exist on the build platform:
5964 @itemize @bullet
5965 @item sys/types.h
5966 @item stdio.h
5967 @item string.h
5968 @item unistd.h -- or, for getopt_long:
5969 @item getopt.h
5970 @end itemize
5971 @c === SECTION MARKER
5972
5973 @node i18n
5974 @section Internationalizing AutoOpts
5975 @cindex Internationalizing AutoOpts
5976
5977 The generated code for AutoOpts will enable and disable the translation of
5978 AutoOpts run time messages.  If @code{ENABLE_NLS} is defined at compile time
5979 and @code{no-xlate} has been not set to the value @emph{anything}, then the
5980 @code{_()} macro may be used to specify a translation function.  If undefined,
5981 it will default to @code{gettext(3GNU)}.  This define will also enable a
5982 callback function that @code{optionProcess} invokes at the beginning of option
5983 processing.  The AutoOpts @code{libopts} library will always check for this
5984 @emph{compiled with NLS} flag, so @code{libopts} does not need to be specially
5985 compiled.  The strings returned by the translation function will be
5986 @code{strdup(3)-ed} and kept.  They will not be re-translated, even if the
5987 locale changes, but they will also not be dependent upon reused or unmappable
5988 memory.
5989
5990 You should also ensure that the @code{ATTRIBUTE_FORMAT_ARG()} gets
5991 @code{#define}-ed to something useful.  There is an autoconf macro
5992 named @code{AG_COMPILE_FORMAT_ARG} in @file{ag_macros.m4} that will
5993 set it appropriately for you.  If you do not do this, then translated
5994 formatting strings may trigger GCC compiler warnings.
5995
5996 To internationalize option processing, you should first internationalize your
5997 program.  Then, the option processing strings can be added to your translation
5998 text by processing the AutoOpts-generated @file{my-opts.c} file and adding the
5999 distributed @file{po/usage-txt.pot} file.  (Also by extracting the strings
6000 yourself from the @file{usage-txt.h} file.)  When you call
6001 @code{optionProcess}, all of the user visible AutoOpts strings will be passed
6002 through the localization procedure established with the @code{_()}
6003 preprocessing macro.
6004
6005 All of this is @emph{dis}-abled if you specify the global attribute
6006 @code{no-xlate} to @emph{anything}.
6007
6008 @c === SECTION MARKER
6009
6010 @node Naming Conflicts
6011 @section Naming Conflicts
6012 @cindex Naming Conflicts
6013
6014 AutoOpts generates a header file that contains many C preprocessing macros and
6015 several external names.  For the most part, they begin with either @code{opt_}
6016 or @code{option}, or else they end with @code{_opt}.  If this happens to
6017 conflict with other macros you are using, or if you are compiling multiple
6018 option sets in the same compilation unit, the conflicts can be avoided.  You
6019 may specify an external name @code{prefix} (@pxref{program attributes}) for
6020 all of the names generated for each set of option definitions.
6021
6022 Among these macros, several take an option name as a macro argument.
6023 Sometimes, this will inconveniently conflict.  For example, if you specify an
6024 option named, @code{debug}, the emitted code will presume that @code{DEBUG} is
6025 not a preprocessing name.  Or also, if you are building on a Windows platform,
6026 you may find that MicroSoft has usurped a number of user space names in its
6027 header files.  Consequently, you will get a preprocessing error if you use,
6028 for example, @code{HAVE_OPT(DEBUG)} or @code{HAVE_OPT(INTERNAL)}
6029 (@pxref{HAVE_OPT}) in your code.  You may trigger an obvious warning for such
6030 conflicts by specifying the @code{guard-option-names} attribute
6031 (@pxref{program attributes}).  That emitted code will also @code{#undef}-ine
6032 the conflicting name.
6033
6034 @node All Attribute Names
6035 @section All Attribute Names
6036
6037 This is the list of all the option attributes used in the various
6038 option processing templates.  There are several flavors of attributes,
6039 and these are not distinguished here.
6040
6041 @itemize @bullet
6042 @item
6043 Valid, current attributes that you are encouraged to use.
6044 @item
6045 Internally generated attributes that you cannot use at all.
6046 I need to prefix these with a distinguished prefix.  e.g.  @code{ao-}
6047 @item
6048 Valid attributes, but are deprecated.  Alternates should be documented.
6049 @end itemize
6050
6051 This list is derived by running many example option definitions through the
6052 option generation and man page templates and noting which attributes are
6053 actually used.  There may be a few that are used but not exercised in my
6054 testing.  If so, I need to ferret those out and test them, too.
6055
6056 @example
6057 addtogroup         aliases          allow_errors  arg_default
6058 arg_name           arg_optional     arg_range     arg_type
6059 argument           author           call_proc     cmd_section
6060 comment_char       concept          config_header copyright
6061 date               default          deprecated    descrip
6062 detail             die_code         disable       disable_load
6063 disable_save       doc              doc_section   doc_sub
6064 doc_sub_cmd        documentation    ds_format     ds_text
6065 ds_type            eaddr            enable        enabled
6066 environrc          equivalence      exit_desc     exit_name
6067 explain            export           extract_code  field
6068 file_fail_code     flag             flag_code     flag_proc
6069 flags_cant         flags_must       full_usage    gnu_usage
6070 guard_option_names handler_proc     handler_type  help_type
6071 help_value         home_rc          homerc        ifdef
6072 ifndef             immed_disable    immediate     include
6073 interleaved        keyword          lib_name      library
6074 load_opts_value    long_opts        main_fini     main_init
6075 main_type          max              min           more_help_value
6076 must_set           name             no_command    no_libopts
6077 no_misuse_usage    no_preset        no_xlate      omit_texi
6078 omitted_usage      open_file        opt_state     option_format
6079 option_info        owner            package       prefix
6080 prefix_enum        preserve_case    prog_descrip  prog_info_descrip
6081 prog_man_descrip   prog_name        prog_title    rcfile
6082 reorder_args       reset_value      resettable    save_opts_value
6083 scaled             set_desc         set_index     settable
6084 short_usage        stack_arg        stdin_input   sub_name
6085 sub_text           sub_type         test_main     translators
6086 type               unshar_file_code unstack_arg   usage
6087 usage_message      usage_opt        usage_value   value
6088 vendor_opt         version          version_proc  version_value
6089 @end example
6090
6091 @node Option Define Names
6092 @section Option Definition Name Index
6093 @printindex vr
6094
6095 @ignore
6096 END   == AUTOINFO == DO NOT CHANGE THIS COMMENT or the surrounding 'ignore's
6097 Extraction from autogen.texi
6098 @end ignore
6099
6100 @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
6101 @c
6102 @c  TRAILER
6103
6104 @c  LocalWords:  AutoGen texinfo Korb tpl bruce Exp texi autogen setfilename AG
6105 @c  LocalWords:  settitle setchapternewpage dne dircategory direntry ifinfo gpl
6106 @c  LocalWords:  AutoOpts snprintfv titlepage vskip pt filll sp dir xref cindex
6107 @c  LocalWords:  AutoGen's noindent rc ini enum IDX const az upcase ENDFOR ESAC
6108 @c  LocalWords:  optargs egcs inclhack sh fixincl autoconf endif var templ dirs
6109 @c  LocalWords:  def txt cd STR str ifdef alist downcase sprintf arg lexer
6110 @c  LocalWords:  srcfile linenum subblock defParse srcdir sed POSIX printf expr
6111 @c  LocalWords:  stdout expr func gfunc tr findex exparg desc desc sep macfunc
6112 @c  LocalWords:  ing getdefs libopts src ksh forcomma csh env Sourced autoopts
6113 @c  LocalWords:  mkmerge builddir ADDON AutoGetopts getopt glibc argp perl awk
6114 @c  LocalWords:  printindex cp fn