summaryrefslogtreecommitdiff
path: root/autoopts/test/handler.test
blob: ac7d4a4a341b434ea6759d44686128f1af0ae250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# handler.test ---   test option handling
#                    make sure that when it is not specified
#                    then option processing consumes all args.
#
# Time-stamp:        "2012-08-11 08:14:34 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
#
# ----------------------------------------------------------------------

. ./defs

# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #

echo "creating ${testname}.def in `pwd`"
cat > ${testname}.def <<_EOF_
AutoGen Definitions options;
prog-name = ${testname};
prog-title = "Testing ${testname}";

flag = {
    name = first;
    descrip = "first description";
    extract_code;
};

flag = {
    name = second;
    descrip = "second description";
    arg-type = keyword;
    keyword = alpha, beta, gamma, omega;
};

flag = {
    name = third;
    descrip = "third description";
    flag_code = "    SomeCodeOrOther();";
};

flag = {
    name = fourth;
    descrip = "fourth description";
    arg-type = keyword;
    keyword = alpha, beta, gamma, omega;
    arg-default = gamma;
    arg-optional;
};

flag = {
    name = fifth;
    descrip = "fifth description";
    flag_proc = first;
};

flag = {
    name = sixth;
    descrip = "sixth description";
    arg-type = set-member;
    keyword = alpha, beta, gamma, omega;
    arg-default = gamma, beta;
};
_EOF_

echo ${AG_L} ${testname}.def
${AG_L} ${testname}.def || \
  failure AutoGen could not process

${SED} '/START =/a\
SampleCode();\
XXX-REMOVE-XXX' ${testname}.c > ${testname}.tmp
chmod 644 ${testname}.c
${SED} -e '/^XXX-REMOVE-XXX$/d;s/XXX-REMOVE-XXX//' \
    ${testname}.tmp > ${testname}.c

${AG_L} ${testname}.def || \
  failure AutoGen could not process

# We are testing to ensure the procedures are created correctly.
# The template line numbers and time stamps and all that cruft
# vary too much, so sed them away.
#
${SED} -e '1,/Create the static procedure(s) declared above/d' \
    -e '/extracted from.*near line/d' \
    -e '/^#line/d' \
    -e 's@handler_opt_strs+[0-9]*@handler_opt_strs+NNN@g' \
    -e 's@+NNN,  *@+NNN, @g' \
    -e '/^#ifndef *PKGDATADIR/,$d' \
    ${testname}.c > ${testname}.test

# # # # # # # # # # SAMPLE OUTPUT FILE # # # # # # # # #

echo creating ${testname}.sample
cat > ${testname}.sample <<\_EOF_
 */
/**
 * The callout function that invokes the optionUsage function.
 *
 * @param pOptions the AutoOpts option description structure
 * @param pOptDesc the descriptor for the "help" (usage) option.
 * @noreturn
 */
static void
doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
{
    optionUsage(&handlerOptions, HANDLER_EXIT_SUCCESS);
    /* NOTREACHED */
    (void)pOptDesc;
    (void)pOptions;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
 * Code to handle the first option.
 *
 * @param pOptions the handler options data structure
 * @param pOptDesc the option descriptor for this option.
 */
static void
doOptFirst(tOptions* pOptions, tOptDesc* pOptDesc)
{
/*  START =-= First Opt Code =-= DO NOT CHANGE THIS COMMENT */
SampleCode();
/*  END   =-= First Opt Code =-= DO NOT CHANGE THIS COMMENT */
    (void)pOptDesc;
    (void)pOptions;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
 * Code to handle the second option.
 *
 * @param pOptions the handler options data structure
 * @param pOptDesc the option descriptor for this option.
 */
static void
doOptSecond(tOptions* pOptions, tOptDesc* pOptDesc)
{

    static char const zDef[2] = { 0x7F, 0 };
    static char const * const azNames[5] = { zDef,
        handler_opt_strs+NNN, handler_opt_strs+NNN, handler_opt_strs+NNN,
        handler_opt_strs+NNN };

    if (pOptions <= OPTPROC_EMIT_LIMIT) {
        (void) optionEnumerationVal(pOptions, pOptDesc, azNames, 5);
        return; /* protect AutoOpts client code from internal callbacks */
    }

    pOptDesc->optArg.argEnum =
        optionEnumerationVal(pOptions, pOptDesc, azNames, 5);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
 * Code to handle the third option.
 *
 * @param pOptions the handler options data structure
 * @param pOptDesc the option descriptor for this option.
 */
static void
doOptThird(tOptions* pOptions, tOptDesc* pOptDesc)
{
    /* extracted from handler.def, line 21 */
    SomeCodeOrOther();
    (void)pOptDesc;
    (void)pOptions;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
 * Code to handle the fourth option.
 *
 * @param pOptions the handler options data structure
 * @param pOptDesc the option descriptor for this option.
 */
static void
doOptFourth(tOptions* pOptions, tOptDesc* pOptDesc)
{

    static char const * const azNames[4] = {
        handler_opt_strs+NNN, handler_opt_strs+NNN, handler_opt_strs+NNN,
        handler_opt_strs+NNN };

    if (pOptions <= OPTPROC_EMIT_LIMIT) {
        (void) optionEnumerationVal(pOptions, pOptDesc, azNames, 4);
        return; /* protect AutoOpts client code from internal callbacks */
    }

    if (pOptDesc->optArg.argString == NULL)
        pOptDesc->optArg.argEnum = FOURTH_GAMMA;
    else
        pOptDesc->optArg.argEnum =
            optionEnumerationVal(pOptions, pOptDesc, azNames, 4);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
 * Code to handle the sixth option.
 *
 * @param pOptions the handler options data structure
 * @param pOptDesc the option descriptor for this option.
 */
static void
doOptSixth(tOptions* pOptions, tOptDesc* pOptDesc)
{

    static char const * const azNames[4] = {
        "alpha",  "beta",   "gamma",  "omega"
    };
    /*
     * This function handles special invalid values for "pOptions"
     */
    optionSetMembers(pOptions, pOptDesc, azNames, 4);
}

/**
 * The directory containing the data associated with handler.
 */
_EOF_

cmp -s ${testname}.test ${testname}.sample || {
  failure "`diff -c ${testname}.test ${testname}.sample`" ; }

cleanup

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## End:

# end of handler.test