File: main.c

package info (click to toggle)
libexplain 0.52.D002-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 34,656 kB
  • sloc: ansic: 138,224; makefile: 36,642; sh: 15,448; yacc: 1,442; awk: 246
file content (318 lines) | stat: -rw-r--r-- 6,140 bytes parent folder | download
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * libexplain - a library of system-call-specific strerror replacements
 * Copyright (C) 2011 Peter Miller
 * Written by Peter Miller <pmiller@opensource.org.au>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <libexplain/ac/fcntl.h>
#include <libexplain/ac/linux/videodev.h>
#include <libexplain/ac/linux/videodev2.h>
#include <libexplain/ac/stdio.h>
#include <libexplain/ac/stdlib.h>
#include <libexplain/ac/string.h>
#include <libexplain/ac/unistd.h>

#include <libexplain/fstrcmp.h>
#include <libexplain/output.h>
#include <libexplain/program_name.h>
#include <libexplain/sizeof.h>
#include <libexplain/version_print.h>


typedef struct table_t table_t;
struct table_t
{
    const char *name;
    int value;
};

static const table_t table[] =
{
#include <test_config/configured.h>

    {
        "__linux__",
#ifdef __linux__
        1
#else
        0
#endif
    },
    {
        "__unix__",
#ifdef __unix__
        1
#else
        0
#endif
    },
    {
        "__GNUC__",
#ifdef __GNUC__
        1
#else
        0
#endif
    },
    {
        "__FreeBSD__",
#ifdef __FreeBSD__
        1
#else
        0
#endif
    },

    /*
     * These are so we can be selective in tests.  We don't want too
     * many, because the various ioctl includes do not play nive with
     * each other.
     */
    {
        "VIDIOC_DQEVENT",
#ifdef VIDIOC_DQEVENT
        1
#else
        0
#endif
    },
    {
        "VIDIOC_SUBSCRIBE_EVENT",
#ifdef VIDIOC_SUBSCRIBE_EVENT
        1
#else
        0
#endif
    },
    {
        "VIDIOC_UNSUBSCRIBE_EVENT",
#ifdef VIDIOC_UNSUBSCRIBE_EVENT
        1
#else
        0
#endif
    },
    {
        "VIDIOC_S_HW_FREQ_SEEK",
#ifdef VIDIOC_S_HW_FREQ_SEEK
        1
#else
        0
#endif
    },
    {
        "VIDIOC_DBG_G_CHIP_IDENT",
#ifdef VIDIOC_DBG_G_CHIP_IDENT
        1
#else
        0
#endif
    },
    {
        "VIDIOC_QUERY_DV_PRESET",
#ifdef VIDIOC_QUERY_DV_PRESET
        1
#else
        0
#endif
    },
    {
        "VIDIOC_G_DV_PRESET",
#ifdef VIDIOC_G_DV_PRESET
        1
#else
        0
#endif
    },
    {
        "VIDIOC_ENUM_DV_PRESETS",
#ifdef VIDIOC_ENUM_DV_PRESETS
        1
#else
        0
#endif
    },
    {
        "VIDIOC_G_DV_TIMINGS",
#ifdef VIDIOC_G_DV_TIMINGS
        1
#else
        0
#endif
    },
    {
        "VIDIOCGCAP",
#ifdef VIDIOCGCAP
        1
#else
        0
#endif
    },
    {
        "O_NOFOLLOW",
#if defined(O_NOFOLLOW) && (O_NOFOLLOW != 0)
        1
#else
        0
#endif
    },
    {
        "O_DIRECTORY",
#if defined(O_DIRECTORY) && (O_DIRECTORY != 0)
        1
#else
        0
#endif
    },
    {
        "O_CLOEXEC",
#if defined(O_CLOEXEC) && (O_CLOEXEC != 0)
        1
#else
        0
#endif
    },
    {
        "O_DIRECT",
#if defined(O_DIRECT) && (O_DIRECT != 0)
        1
#else
        0
#endif
    },
    {
        "O_NOATIME",
#if defined(O_NOATIME) && (O_NOATIME != 0)
        1
#else
        0
#endif
    },
};


static void
usage(void)
{
    const char *prog = explain_program_name_get();
    fprintf(stderr, "Usage: %s <cfg-name>\n", prog);
    fprintf(stderr, "       %s -V\n", prog);
    exit(EXIT_SUCCESS);
}


int
main(int argc, char **argv)
{
    const char      *name;
    const table_t   *tp;
    const table_t   *best;
    double          best_weight;

    explain_option_hanging_indent_set(4);
    for (;;)
    {
        int c = getopt(argc, argv, "lV");
        if (c == EOF)
            break;
        switch (c)
        {
        case 'l':
            for (tp = table; tp < ENDOF(table); ++tp)
            {
                printf("#%s %s\n", (tp->value ? "define" : "undef"), tp->name);
            }
            return EXIT_SUCCESS;

        case 'V':
            explain_version_print();
            return 0;

        default:
            usage();
        }
    }
    if (optind + 1 != argc)
        usage();
    name = argv[optind];
    for (tp = table; tp < ENDOF(table); ++tp)
    {
        if (0 == strcmp(tp->name, name))
        {
            if (tp->value)
                return EXIT_SUCCESS;
            explain_output_error_and_die
            (
                "This system does not %s, therefore this test is declared to "
                    "pass by default.",
                name
            );
            return EXIT_FAILURE;
        }
    }
    if (0 == strcmp(name, "not-root"))
    {
        if (getuid() == 0 || geteuid() == 0)
        {
            explain_output_error_and_die
            (
                "This test only applies when not executed by root, "
                "therefore this test is declared to pass by default."
            );
        }
        return EXIT_SUCCESS;
    }

    /*
     * See of we can find a close match, in case it was a typo.
     */
    best = 0;
    best_weight = 0.6;
    for (tp = table; tp < ENDOF(table); ++tp)
    {
        double          w;

        w = explain_fstrcasecmp(tp->name, name);
        if (w > best_weight)
        {
            best = tp;
            best_weight = w;
        }
    }
    if (best)
    {
        explain_output_error_and_die
        (
            "Configuration item \"%s\" unknown, did you mean \"%s\" instead?  "
                "Proceeding with the test.",
            name,
            best->name
        );
    }

    /*
     * Nothing similar, they will have to work it out for themselves.
     */
    explain_output_error_and_die
    (
        "Configuration item \"%s\" unknown, proceeding with test.",
        name
    );
    return EXIT_SUCCESS;
}


/* vim: set ts=8 sw=4 et : */