varnish-cache/bin/varnishstat/varnishstat_help_gen.c
0
/*-
1
 * Copyright (c) 2020 Varnish Software AS
2
 * All rights reserved.
3
 *
4
 * Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
30
#include <stddef.h>
31
#include <string.h>
32
#include <unistd.h>
33
34
#include <vdef.h>
35
#include <vas.h>
36
#include <vsb.h>
37
38
static const char help[] = "\n\n"
39
#define BINDING_KEY(key, name, next) "<" name ">" next
40
#define BINDING(name, desc) "\n\n" desc "\n\n"
41
#include "varnishstat_bindings.h"
42
;
43
44
int
45 40
main(void)
46
{
47
        struct vsb *vsb;
48
        const char *p, *n;
49
        unsigned u;
50
51 40
        vsb = VSB_new_auto();
52 40
        AN(vsb);
53 40
        VSB_cat(vsb,
54
            "/*\n"
55
            " * NB:  This file is machine generated, DO NOT EDIT!\n"
56
            " *\n"
57
            " * Edit varnishstat_bindings.h and run make instead\n"
58
            " */\n"
59
            "\n"
60
            "#include <stddef.h>\n"
61
            "#include \"vdef.h\"\n"
62
            "#include \"varnishstat.h\"\n"
63
            "\n"
64
            "const char *const bindings_help[] = {\n");
65
66 40
        n = help;
67 40
        u = 0;
68 40
        do {
69 2920
                p = n + 1;
70 2920
                n = strchr(p, '\n');
71 2920
                if (n != NULL && n > p) {
72 1560
                        VSB_putc(vsb, '\t');
73 1560
                        VSB_quote(vsb, p, (int)(n - p), VSB_QUOTE_CSTR);
74 1560
                        VSB_cat(vsb, ",\n");
75 1560
                        u++;
76 1560
                }
77 2920
        } while (n != NULL);
78
79 80
        VSB_printf(vsb,
80
            "\tNULL\n"
81
            "};\n"
82
            "\n"
83 40
            "const int bindings_help_len = %u;\n", u);
84 40
        AZ(VSB_finish(vsb));
85 40
        AZ(VSB_tofile(vsb, STDOUT_FILENO));
86 40
        VSB_destroy(&vsb);
87 40
        return (0);
88
}