If OCSP revocation data are invalid or too old set appropriate verification flags.
[gnutls.git] / src / libopts / numeric.c
blobb709d0708ffacb50f816fe13fdac21facb03c8cb
2 /**
3 * \file numeric.c
5 * Time-stamp: "2012-02-25 12:54:32 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 /*=export_func optionShowRange
29 * private:
31 * what:
32 * arg: + tOptions* + pOpts + program options descriptor +
33 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
34 * arg: + void * + rng_table + the value range tables +
35 * arg: + int + rng_count + the number of entries +
37 * doc:
38 * Show information about a numeric option with range constraints.
39 =*/
40 void
41 optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct)
43 const struct {long const rmin, rmax;} * rng = rng_table;
45 char const * pz_indent = BULLET_STR;
48 * The range is shown only for full usage requests and an error
49 * in this particular option.
51 if (pOpts != OPTPROC_EMIT_USAGE) {
52 if (pOpts <= OPTPROC_EMIT_LIMIT)
53 return;
54 pz_indent = ONE_TAB_STR;
56 fprintf(option_usage_fp, zRangeErr, pOpts->pzProgName,
57 pOD->pz_Name, pOD->optArg.argInt);
58 pz_indent = "";
61 if (pOD->fOptState & OPTST_SCALED_NUM)
62 fprintf(option_usage_fp, zRangeScaled, pz_indent);
64 fprintf(option_usage_fp, (rng_ct > 1) ? zRangeLie : zRangeOnly, pz_indent);
65 pz_indent = (pOpts != OPTPROC_EMIT_USAGE) ? ONE_TAB_STR : DEEP_INDENT_STR;
67 for (;;) {
68 if (rng->rmax == LONG_MIN)
69 fprintf(option_usage_fp, zRangeExact, pz_indent, rng->rmin);
70 else if (rng->rmin == LONG_MIN)
71 fprintf(option_usage_fp, zRangeUpto, pz_indent, rng->rmax);
72 else if (rng->rmax == LONG_MAX)
73 fprintf(option_usage_fp, zRangeAbove, pz_indent, rng->rmin);
74 else
75 fprintf(option_usage_fp, zRange, pz_indent, rng->rmin,
76 rng->rmax);
78 if (--rng_ct <= 0) {
79 fputc(NL, option_usage_fp);
80 break;
82 fputs(zRangeOr, option_usage_fp);
83 rng++;
86 if (pOpts > OPTPROC_EMIT_LIMIT)
87 pOpts->pUsageProc(pOpts, EXIT_FAILURE);
90 /*=export_func optionNumericVal
91 * private:
93 * what: process an option with a numeric value.
94 * arg: + tOptions* + pOpts + program options descriptor +
95 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
97 * doc:
98 * Decipher a numeric value.
99 =*/
100 void
101 optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
103 char* pz;
104 long val;
107 * Numeric options may have a range associated with it.
108 * If it does, the usage procedure requests that it be
109 * emitted by passing a NULL pOD pointer. Also bail out
110 * if there is no option argument or if we are being reset.
112 if ( (pOD == NULL)
113 || (pOD->optArg.argString == NULL)
114 || ((pOD->fOptState & OPTST_RESET) != 0))
115 return;
117 errno = 0;
118 val = strtol(pOD->optArg.argString, &pz, 0);
119 if ((pz == pOD->optArg.argString) || (errno != 0))
120 goto bad_number;
122 if ((pOD->fOptState & OPTST_SCALED_NUM) != 0)
123 switch (*(pz++)) {
124 case NUL: pz--; break;
125 case 't': val *= 1000;
126 case 'g': val *= 1000;
127 case 'm': val *= 1000;
128 case 'k': val *= 1000; break;
130 case 'T': val *= 1024;
131 case 'G': val *= 1024;
132 case 'M': val *= 1024;
133 case 'K': val *= 1024; break;
135 default: goto bad_number;
138 if (*pz != NUL)
139 goto bad_number;
141 if (pOD->fOptState & OPTST_ALLOC_ARG) {
142 AGFREE(pOD->optArg.argString);
143 pOD->fOptState &= ~OPTST_ALLOC_ARG;
146 pOD->optArg.argInt = val;
147 return;
149 bad_number:
151 fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
152 if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
153 (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
155 errno = EINVAL;
156 pOD->optArg.argInt = ~0;
160 * Local Variables:
161 * mode: C
162 * c-file-style: "stroustrup"
163 * indent-tabs-mode: nil
164 * End:
165 * end of autoopts/numeric.c */