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
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
;
43 optionResetEverything(tOptions
* pOpts
)
45 tOptDesc
* pOD
= pOpts
->pOptDesc
;
46 int ct
= pOpts
->presetOptCt
;
49 optionReset(pOpts
, pOD
);
58 /*=export_func optionResetOpt
61 * what: Reset the value of an option
62 * arg: + tOptions* + pOpts + program options descriptor +
63 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
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.
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
;
81 if ( (! HAS_originalOptArgArray(pOpts
))
82 || (pOpts
->originalOptArgCookie
== NULL
)) {
83 fputs(zResetNotConfig
, stderr
);
87 if ((pzArg
== NULL
) || (*pzArg
== NUL
)) {
88 fputs(zNoResetArg
, stderr
);
89 pOpts
->pUsageProc(pOpts
, EXIT_FAILURE
);
96 if (pzArg
[1] == NUL
) {
98 optionResetEverything(pOpts
);
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
);
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
);
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;
132 * c-file-style: "stroustrup"
133 * indent-tabs-mode: nil
135 * end of autoopts/reset.c */