Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / libopts / reset.c
blobbf6f07bf8d3584345a6d700e0f4cb4198d740477
1 /* $NetBSD$ */
4 /*
5 * Id: 808e536555f06924b450ab6b5a72c03b67c5b99a
6 * Time-stamp: "2009-11-01 11:45:57 bkorb"
8 * This file is part of AutoOpts, a companion to AutoGen.
9 * AutoOpts is free software.
10 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
12 * AutoOpts is available under any one of two licenses. The license
13 * in use must be one of these two and the choice is under the control
14 * of the user of the license.
16 * The GNU Lesser General Public License, version 3 or later
17 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
19 * The Modified Berkeley Software Distribution License
20 * See the file "COPYING.mbsd"
22 * These files have the following md5sums:
24 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
25 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
26 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
29 static void
30 optionReset( tOptions* pOpts, tOptDesc* pOD )
32 pOD->fOptState &= OPTST_PERSISTENT_MASK;
33 pOD->fOptState |= OPTST_RESET;
34 if (pOD->pOptProc != NULL)
35 pOD->pOptProc(pOpts, pOD);
36 pOD->optArg.argString =
37 pOpts->originalOptArgArray[ pOD->optIndex ].argString;
38 pOD->optCookie = pOpts->originalOptArgCookie[ pOD->optIndex ];
39 pOD->fOptState &= OPTST_PERSISTENT_MASK;
43 static void
44 optionResetEverything(tOptions * pOpts)
46 tOptDesc * pOD = pOpts->pOptDesc;
47 int ct = pOpts->presetOptCt;
49 for (;;) {
50 optionReset(pOpts, pOD);
52 if (--ct <= 0)
53 break;
54 pOD++;
59 /*=export_func optionResetOpt
60 * private:
62 * what: Reset the value of an option
63 * arg: + tOptions* + pOpts + program options descriptor +
64 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
66 * doc:
67 * This code will cause another option to be reset to its initial state.
68 * For example, --reset=foo will cause the --foo option to be reset.
69 =*/
70 void
71 optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
73 static ag_bool reset_active = AG_FALSE;
75 tOptState opt_state = OPTSTATE_INITIALIZER(DEFINED);
76 char const * pzArg = pOD->optArg.argString;
77 tSuccess succ;
79 if (reset_active)
80 return;
82 if ( (! HAS_originalOptArgArray(pOpts))
83 || (pOpts->originalOptArgCookie == NULL)) {
84 fputs(zResetNotConfig, stderr);
85 _exit(EX_SOFTWARE);
88 if ((pzArg == NULL) || (*pzArg == NUL)) {
89 fputs(zNoResetArg, stderr);
90 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
91 /* NOTREACHED */
92 assert(0 == 1);
95 reset_active = AG_TRUE;
97 if (pzArg[1] == NUL) {
98 if (*pzArg == '*') {
99 optionResetEverything(pOpts);
100 reset_active = AG_FALSE;
101 return;
104 succ = shortOptionFind(pOpts, (tAoUC)*pzArg, &opt_state);
105 if (! SUCCESSFUL(succ)) {
106 fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
107 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
108 /* NOTREACHED */
109 assert(0 == 1);
111 } else {
112 succ = longOptionFind(pOpts, (char *)pzArg, &opt_state);
113 if (! SUCCESSFUL(succ)) {
114 fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
115 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
116 /* NOTREACHED */
117 assert(0 == 1);
122 * We've found the indicated option. Turn off all non-persistent
123 * flags because we're forcing the option back to its initialized state.
124 * Call any callout procedure to handle whatever it needs to.
125 * Finally, clear the reset flag, too.
127 optionReset(pOpts, opt_state.pOD);
128 reset_active = AG_FALSE;
131 * Local Variables:
132 * mode: C
133 * c-file-style: "stroustrup"
134 * indent-tabs-mode: nil
135 * End:
136 * end of autoopts/reset.c */