4 * @brief consistency checks.
6 * Time-stamp: "2012-03-31 13:46:35 bkorb"
8 * This file contains the routines that deal with processing quoted strings
9 * into an internal format.
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
33 * Check for conflicts based on "must" and "cannot" attributes.
36 has_conflict(tOptions
* pOpts
, tOptDesc
* pOD
)
38 if (pOD
->pOptMust
!= NULL
) {
39 int const * pMust
= pOD
->pOptMust
;
41 while (*pMust
!= NO_EQUIVALENT
) {
42 tOptDesc
* p
= pOpts
->pOptDesc
+ *(pMust
++);
44 const tOptDesc
* pN
= pOpts
->pOptDesc
+ pMust
[-1];
45 fprintf(stderr
, zReqFmt
, pOD
->pz_Name
, pN
->pz_Name
);
51 if (pOD
->pOptCant
!= NULL
) {
52 int const * pCant
= pOD
->pOptCant
;
54 while (*pCant
!= NO_EQUIVALENT
) {
55 tOptDesc
* p
= pOpts
->pOptDesc
+ *(pCant
++);
56 if (SELECTED_OPT(p
)) {
57 const tOptDesc
* pN
= pOpts
->pOptDesc
+ pCant
[-1];
58 fprintf(stderr
, zCantFmt
, pOD
->pz_Name
, pN
->pz_Name
);
68 * Check that the option occurs often enough. Too often is already checked.
71 occurs_enough(tOptions
* pOpts
, tOptDesc
* pOD
)
76 * IF the occurrence counts have been satisfied,
77 * THEN there is no problem.
79 if (pOD
->optOccCt
>= pOD
->optMinCt
)
83 * IF MUST_SET means SET and PRESET are okay,
84 * so min occurrence count doesn't count
86 if ( (pOD
->fOptState
& OPTST_MUST_SET
)
87 && (pOD
->fOptState
& (OPTST_PRESET
| OPTST_SET
)) )
90 if (pOD
->optMinCt
> 1)
91 fprintf(stderr
, zNotEnough
, pOD
->pz_Name
, pOD
->optMinCt
);
92 else fprintf(stderr
, zNeedOne
, pOD
->pz_Name
);
97 * Verify option consistency.
99 * Make sure that the argument list passes our consistency tests.
102 is_consistent(tOptions
* pOpts
)
104 tOptDesc
* pOD
= pOpts
->pOptDesc
;
105 int oCt
= pOpts
->presetOptCt
;
108 * FOR each of "oCt" options, ...
112 * IF the current option was provided on the command line
113 * THEN ensure that any "MUST" requirements are not
114 * "DEFAULT" (unspecified) *AND* ensure that any
115 * "CANT" options have not been SET or DEFINED.
117 if (SELECTED_OPT(pOD
)) {
118 if (has_conflict(pOpts
, pOD
))
123 * IF this option is not equivalenced to another,
124 * OR it is equivalenced to itself (is the equiv. root)
125 * THEN we need to make sure it occurs often enough.
127 if ( (pOD
->optEquivIndex
== NO_EQUIVALENT
)
128 || (pOD
->optEquivIndex
== pOD
->optIndex
) )
130 if (! occurs_enough(pOpts
, pOD
))
139 * IF we are stopping on errors, check to see if any remaining
140 * arguments are required to be there or prohibited from being there.
142 if ((pOpts
->fOptSet
& OPTPROC_ERRSTOP
) != 0) {
145 * Check for prohibition
147 if ((pOpts
->fOptSet
& OPTPROC_NO_ARGS
) != 0) {
148 if (pOpts
->origArgCt
> pOpts
->curOptIdx
) {
149 fprintf(stderr
, zNoArgs
, pOpts
->pzProgName
);
155 * ELSE not prohibited, check for being required
157 else if ((pOpts
->fOptSet
& OPTPROC_ARGS_REQ
) != 0) {
158 if (pOpts
->origArgCt
<= pOpts
->curOptIdx
) {
159 fprintf(stderr
, zArgsMust
, pOpts
->pzProgName
);