gnutls_x509_crt_get_policy() allows for a list of zero policy qualifiers.
[gnutls.git] / src / libopts / reset.c
blobb8c5b9e274b74ff354f6779c1062b1c9983d951e
2 /**
3 * \file reset.c
5 * Time-stamp: "2011-05-24 18:07:16 bkorb"
7 * This file is part of AutoOpts, a companion to AutoGen.
8 * AutoOpts is free software.
9 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
11 * AutoOpts is available under any one of two licenses. The license
12 * in use must be one of these two and the choice is under the control
13 * of the user of the license.
15 * The GNU Lesser General Public License, version 3 or later
16 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
18 * The Modified Berkeley Software Distribution License
19 * See the file "COPYING.mbsd"
21 * These files have the following md5sums:
23 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
24 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
25 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
28 static void
29 optionReset( tOptions* pOpts, tOptDesc* pOD )
31 pOD->fOptState &= OPTST_PERSISTENT_MASK;
32 pOD->fOptState |= OPTST_RESET;
33 if (pOD->pOptProc != NULL)
34 pOD->pOptProc(pOpts, pOD);
35 pOD->optArg.argString =
36 pOpts->originalOptArgArray[ pOD->optIndex ].argString;
37 pOD->optCookie = pOpts->originalOptArgCookie[ pOD->optIndex ];
38 pOD->fOptState &= OPTST_PERSISTENT_MASK;
42 static void
43 optionResetEverything(tOptions * pOpts)
45 tOptDesc * pOD = pOpts->pOptDesc;
46 int ct = pOpts->presetOptCt;
48 for (;;) {
49 optionReset(pOpts, pOD);
51 if (--ct <= 0)
52 break;
53 pOD++;
58 /*=export_func optionResetOpt
59 * private:
61 * what: Reset the value of an option
62 * arg: + tOptions* + pOpts + program options descriptor +
63 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
65 * doc:
66 * This code will cause another option to be reset to its initial state.
67 * For example, --reset=foo will cause the --foo option to be reset.
68 =*/
69 void
70 optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
72 static bool reset_active = false;
74 tOptState opt_state = OPTSTATE_INITIALIZER(DEFINED);
75 char const * pzArg = pOD->optArg.argString;
76 tSuccess succ;
78 if (reset_active)
79 return;
81 if ( (! HAS_originalOptArgArray(pOpts))
82 || (pOpts->originalOptArgCookie == NULL)) {
83 fputs(zResetNotConfig, stderr);
84 _exit(EX_SOFTWARE);
87 if ((pzArg == NULL) || (*pzArg == NUL)) {
88 fputs(zNoResetArg, stderr);
89 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
90 /* NOTREACHED */
91 assert(0 == 1);
94 reset_active = true;
96 if (pzArg[1] == NUL) {
97 if (*pzArg == '*') {
98 optionResetEverything(pOpts);
99 reset_active = false;
100 return;
103 succ = opt_find_short(pOpts, (tAoUC)*pzArg, &opt_state);
104 if (! SUCCESSFUL(succ)) {
105 fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
106 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
107 /* NOTREACHED */
108 assert(0 == 1);
110 } else {
111 succ = opt_find_long(pOpts, (char *)pzArg, &opt_state);
112 if (! SUCCESSFUL(succ)) {
113 fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
114 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
115 /* NOTREACHED */
116 assert(0 == 1);
121 * We've found the indicated option. Turn off all non-persistent
122 * flags because we're forcing the option back to its initialized state.
123 * Call any callout procedure to handle whatever it needs to.
124 * Finally, clear the reset flag, too.
126 optionReset(pOpts, opt_state.pOD);
127 reset_active = false;
130 * Local Variables:
131 * mode: C
132 * c-file-style: "stroustrup"
133 * indent-tabs-mode: nil
134 * End:
135 * end of autoopts/reset.c */