Coverage Report

Created: 2023-05-19 06:16

/src/ntp-dev/sntp/libopts/alias.c
Line
Count
Source (jump to first uncovered line)
1
2
/**
3
 * \file alias.c
4
 *
5
 * Handle options that are aliases for another option.
6
 *
7
 * @addtogroup autoopts
8
 * @{
9
 */
10
/*
11
 *  This routine will forward an option alias to the correct option code.
12
 *
13
 *  This file is part of AutoOpts, a companion to AutoGen.
14
 *  AutoOpts is free software.
15
 *  AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved
16
 *
17
 *  AutoOpts is available under any one of two licenses.  The license
18
 *  in use must be one of these two and the choice is under the control
19
 *  of the user of the license.
20
 *
21
 *   The GNU Lesser General Public License, version 3 or later
22
 *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
23
 *
24
 *   The Modified Berkeley Software Distribution License
25
 *      See the file "COPYING.mbsd"
26
 *
27
 *  These files have the following sha256 sums:
28
 *
29
 *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
30
 *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
31
 *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
32
 */
33
34
LOCAL tSuccess
35
too_many_occurrences(tOptions * opts, tOptDesc * od)
36
0
{
37
0
    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
38
0
        char const * eqv = (od->optEquivIndex != NO_EQUIVALENT) ? zequiv : zNil;
39
40
0
        fprintf(stderr, ztoo_often_fmt, opts->pzProgName);
41
42
0
        if (od->optMaxCt > 1)
43
0
            fprintf(stderr, zat_most, od->optMaxCt, od->pz_Name, eqv);
44
0
        else
45
0
            fprintf(stderr, zonly_one, od->pz_Name, eqv);
46
0
        (*opts->pUsageProc)(opts, EXIT_FAILURE);
47
        /* NOTREACHED */
48
0
    }
49
50
0
    return FAILURE;
51
0
}
52
53
/*=export_func  optionAlias
54
 * private:
55
 *
56
 * what:  relay an option to its alias
57
 * arg:   + tOptions *   + opts   + program options descriptor  +
58
 * arg:   + tOptDesc *   + old_od + the descriptor for this arg +
59
 * arg:   + unsigned int + alias  + the aliased-to option index +
60
 * ret-type: int
61
 *
62
 * doc:
63
 *  Handle one option as if it had been specified as another.  Exactly.
64
 *  Returns "-1" if the aliased-to option has appeared too many times.
65
=*/
66
int
67
optionAlias(tOptions * opts, tOptDesc * old_od, unsigned int alias)
68
0
{
69
0
    tOptDesc * new_od;
70
71
0
    if (opts <= OPTPROC_EMIT_LIMIT)
72
0
        return 0;
73
74
0
    new_od = opts->pOptDesc + alias;
75
0
    if ((unsigned)opts->optCt <= alias) {
76
0
        fputs(zbad_alias_id, stderr);
77
0
        option_exits(EXIT_FAILURE);
78
0
    }
79
80
    /*
81
     *  Copy over the option instance flags
82
     */
83
0
    new_od->fOptState &= OPTST_PERSISTENT_MASK;
84
0
    new_od->fOptState |= (old_od->fOptState & ~OPTST_PERSISTENT_MASK);
85
0
    new_od->optArg.argString = old_od->optArg.argString;
86
87
    /*
88
     *  Keep track of count only for DEFINED (command line) options.
89
     *  IF we have too many, build up an error message and bail.
90
     */
91
0
    if (  (new_od->fOptState & OPTST_DEFINED)
92
0
       && (++new_od->optOccCt > new_od->optMaxCt)  )
93
0
        return too_many_occurrences(opts, new_od);
94
95
    /*
96
     *  Clear the state bits and counters
97
     */
98
0
    old_od->fOptState &= OPTST_PERSISTENT_MASK;
99
0
    old_od->optOccCt   = 0;
100
101
    /*
102
     *  If there is a procedure to call, call it
103
     */
104
0
    if (new_od->pOptProc != NULL)
105
0
        (*new_od->pOptProc)(opts, new_od);
106
0
    return 0;
107
0
}
108
109
/** @}
110
 *
111
 * Local Variables:
112
 * mode: C
113
 * c-file-style: "stroustrup"
114
 * indent-tabs-mode: nil
115
 * End:
116
 * end of autoopts/alias.c */