varnish-cache/lib/libvarnishapi/vsl2rst.c
0
/*-
1
 * Copyright (c) 2011-2015 Varnish Software AS
2
 * All rights reserved.
3
 *
4
 * Author: Martin Blix Grydeland <martin@varnish-software.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
31
#ifndef __FLEXELINT__
32
33
#include "config.h"
34
35
#include <stdint.h>
36
#include <stdio.h>
37
#include <stdlib.h>
38
#include <string.h>
39
40
#include "vapi/vsl.h"
41
42
struct SLT {
43
        unsigned        tag;
44
        unsigned        flags;
45
        const char      *name;
46
        const char      *sdesc;
47
        const char      *ldesc;
48
};
49
50
static struct SLT tags[SLT__MAX] = {
51
#define SLTM(name, flags, sdesc, ldesc)                         \
52
        [SLT_##name] = { SLT_##name, flags, #name, sdesc, ldesc },
53
#include "tbl/vsl_tags.h"
54
};
55
56
static int
57 877
ptag_cmp(const void *va, const void *vb)
58
{
59
        const struct SLT *a, *b;
60
61 877
        a = *(const struct SLT * const *)va;
62 877
        b = *(const struct SLT * const *)vb;
63 877
        if (a->name == NULL && b->name != NULL)
64 2
                return (1);
65 875
        else if (a->name != NULL && b->name == NULL)
66 95
                return (-1);
67 780
        else if (a->name == NULL && b->name == NULL)
68 169
                return (0);
69 611
        return (strcmp(a->name, b->name));
70 877
}
71
72
static void
73 78
print_tabbed(const char *string, int tabs)
74
{
75
        int i;
76
        const char *c;
77
78 17300
        for (c = string; *c; c++) {
79 17222
                if (c == string || *(c - 1) == '\n')
80 1316
                        for (i = 0; i < tabs; i++)
81 1316
                                printf("\t");
82 17222
                printf("%c", *c);
83 17222
        }
84 78
}
85
86
int
87 1
main(int argc, char *argv[])
88
{
89
        int i;
90
        struct SLT *ptags[SLT__MAX];
91
92 1
        (void)argc;
93 1
        (void)argv;
94
95 257
        for (i = 0; i < SLT__MAX; i++)
96 256
                ptags[i] = &tags[i];
97
98 1
        qsort(ptags, SLT__MAX, sizeof *ptags, ptag_cmp);
99
100 257
        for (i = 0; i < SLT__MAX; i++) {
101 256
                if (ptags[i]->name == NULL || !strcmp(ptags[i]->name, ""))
102 163
                        continue;
103 93
                if (ptags[i]->flags & SLT_F_UNUSED)
104 15
                        continue;
105 78
                printf("%s", ptags[i]->name);
106 78
                if (ptags[i]->sdesc != NULL && strcmp(ptags[i]->sdesc, ""))
107 78
                        printf(" - %s", ptags[i]->sdesc);
108 78
                printf("\n");
109 78
                if (ptags[i]->ldesc != NULL && strcmp(ptags[i]->ldesc, "")) {
110 78
                        print_tabbed(ptags[i]->ldesc, 1);
111 78
                }
112 78
                printf("\n\n");
113 78
        }
114
115 1
        return (0);
116
}
117
118
#endif // __FLEXELINT__