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
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 +
38 * Show information about a numeric option with range constraints.
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
)
54 pz_indent
= ONE_TAB_STR
;
56 fprintf(option_usage_fp
, zRangeErr
, pOpts
->pzProgName
,
57 pOD
->pz_Name
, pOD
->optArg
.argInt
);
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
;
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
);
75 fprintf(option_usage_fp
, zRange
, pz_indent
, rng
->rmin
,
79 fputc(NL
, option_usage_fp
);
82 fputs(zRangeOr
, option_usage_fp
);
86 if (pOpts
> OPTPROC_EMIT_LIMIT
)
87 pOpts
->pUsageProc(pOpts
, EXIT_FAILURE
);
90 /*=export_func optionNumericVal
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 +
98 * Decipher a numeric value.
101 optionNumericVal(tOptions
* pOpts
, tOptDesc
* pOD
)
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.
113 || (pOD
->optArg
.argString
== NULL
)
114 || ((pOD
->fOptState
& OPTST_RESET
) != 0))
118 val
= strtol(pOD
->optArg
.argString
, &pz
, 0);
119 if ((pz
== pOD
->optArg
.argString
) || (errno
!= 0))
122 if ((pOD
->fOptState
& OPTST_SCALED_NUM
) != 0)
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
;
141 if (pOD
->fOptState
& OPTST_ALLOC_ARG
) {
142 AGFREE(pOD
->optArg
.argString
);
143 pOD
->fOptState
&= ~OPTST_ALLOC_ARG
;
146 pOD
->optArg
.argInt
= val
;
151 fprintf( stderr
, zNotNumber
, pOpts
->pzProgName
, pOD
->optArg
.argString
);
152 if ((pOpts
->fOptSet
& OPTPROC_ERRSTOP
) != 0)
153 (*(pOpts
->pUsageProc
))(pOpts
, EXIT_FAILURE
);
156 pOD
->optArg
.argInt
= ~0;
162 * c-file-style: "stroustrup"
163 * indent-tabs-mode: nil
165 * end of autoopts/numeric.c */