5 * Time-stamp: "2012-02-12 09:41:42 bkorb"
7 * Automated Options Paged Usage module.
9 * This routine will forward an option alias to the correct option code.
11 * This file is part of AutoOpts, a companion to AutoGen.
12 * AutoOpts is free software.
13 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
15 * AutoOpts is available under any one of two licenses. The license
16 * in use must be one of these two and the choice is under the control
17 * of the user of the license.
19 * The GNU Lesser General Public License, version 3 or later
20 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
22 * The Modified Berkeley Software Distribution License
23 * See the file "COPYING.mbsd"
25 * These files have the following md5sums:
27 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
28 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
29 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
32 /*=export_func optionAlias
35 * what: relay an option to its alias
36 * arg: + tOptions* + pOpts + program options descriptor +
37 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
38 * arg: + unsigned int + alias + the aliased-to option index +
42 * Handle one option as if it had been specified as another. Exactly.
43 * Returns "-1" if the aliased-to option has appeared too many times.
46 optionAlias(tOptions
* pOpts
, tOptDesc
* pOldOD
, unsigned int alias
)
50 if (pOpts
== OPTPROC_EMIT_USAGE
)
53 pOD
= pOpts
->pOptDesc
+ alias
;
54 if ((unsigned)pOpts
->optCt
<= alias
) {
55 fwrite(zAliasRange
, strlen (zAliasRange
), 1, stderr
);
60 * Copy over the option instance flags
62 pOD
->fOptState
&= OPTST_PERSISTENT_MASK
;
63 pOD
->fOptState
|= (pOldOD
->fOptState
& ~OPTST_PERSISTENT_MASK
);
64 pOD
->optArg
.argString
= pOldOD
->optArg
.argString
;
67 * Keep track of count only for DEFINED (command line) options.
68 * IF we have too many, build up an error message and bail.
70 if ( (pOD
->fOptState
& OPTST_DEFINED
)
71 && (++pOD
->optOccCt
> pOD
->optMaxCt
) ) {
73 if ((pOpts
->fOptSet
& OPTPROC_ERRSTOP
) != 0) {
75 (pOD
->optEquivIndex
!= NO_EQUIVALENT
) ? zEquiv
: zNil
;
77 fputs(zErrOnly
, stderr
);
79 if (pOD
->optMaxCt
> 1)
80 fprintf(stderr
, zAtMost
, pOD
->optMaxCt
, pOD
->pz_Name
, pzEqv
);
82 fprintf(stderr
, zOnlyOne
, pOD
->pz_Name
, pzEqv
);
89 * Clear the state bits and counters
91 pOldOD
->fOptState
&= OPTST_PERSISTENT_MASK
;
95 * If there is a procedure to call, call it
97 if (pOD
->pOptProc
!= NULL
)
98 (*pOD
->pOptProc
)(pOpts
, pOD
);
105 * c-file-style: "stroustrup"
106 * indent-tabs-mode: nil
108 * end of autoopts/alias.c */