corrected copyright notices
[gnutls.git] / src / libopts / check.c
blob019a23505aef5efc040ebd6217f24a5ab534abfa
1 /**
2 * @file check.c
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
32 /**
33 * Check for conflicts based on "must" and "cannot" attributes.
35 static bool
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++);
43 if (UNUSED_OPT(p)) {
44 const tOptDesc * pN = pOpts->pOptDesc + pMust[-1];
45 fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name);
46 return true;
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);
59 return true;
64 return false;
67 /**
68 * Check that the option occurs often enough. Too often is already checked.
70 static bool
71 occurs_enough(tOptions * pOpts, tOptDesc * pOD)
73 (void)pOpts;
76 * IF the occurrence counts have been satisfied,
77 * THEN there is no problem.
79 if (pOD->optOccCt >= pOD->optMinCt)
80 return true;
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)) )
88 return true;
90 if (pOD->optMinCt > 1)
91 fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt);
92 else fprintf(stderr, zNeedOne, pOD->pz_Name);
93 return false;
96 /**
97 * Verify option consistency.
99 * Make sure that the argument list passes our consistency tests.
101 LOCAL bool
102 is_consistent(tOptions * pOpts)
104 tOptDesc * pOD = pOpts->pOptDesc;
105 int oCt = pOpts->presetOptCt;
108 * FOR each of "oCt" options, ...
110 for (;;) {
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))
119 return false;
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))
131 return false;
133 if (--oCt <= 0)
134 break;
135 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);
150 return false;
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);
160 return false;
165 return true;