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 21925
ptag_cmp(const void *va, const void *vb)
58
{
59
        const struct SLT *a, *b;
60
61 21925
        a = *(const struct SLT * const *)va;
62 21925
        b = *(const struct SLT * const *)vb;
63 21925
        if (a->name == NULL && b->name != NULL)
64 50
                return (1);
65 21875
        else if (a->name != NULL && b->name == NULL)
66 2375
                return (-1);
67 19500
        else if (a->name == NULL && b->name == NULL)
68 4225
                return (0);
69 15275
        return (strcmp(a->name, b->name));
70 21925
}
71
72
static void
73 1950
print_tabbed(const char *string, int tabs)
74
{
75
        int i;
76
        const char *c;
77
78 428825
        for (c = string; *c; c++) {
79 426875
                if (c == string || *(c - 1) == '\n')
80 32650
                        for (i = 0; i < tabs; i++)
81 32650
                                printf("\t");
82 426875
                printf("%c", *c);
83 426875
        }
84 1950
}
85
86
int
87 25
main(int argc, char *argv[])
88
{
89
        int i;
90
        struct SLT *ptags[SLT__MAX];
91
92 25
        (void)argc;
93 25
        (void)argv;
94
95 6425
        for (i = 0; i < SLT__MAX; i++)
96 6400
                ptags[i] = &tags[i];
97
98 25
        qsort(ptags, SLT__MAX, sizeof *ptags, ptag_cmp);
99
100 6425
        for (i = 0; i < SLT__MAX; i++) {
101 6400
                if (ptags[i]->name == NULL || !strcmp(ptags[i]->name, ""))
102 4075
                        continue;
103 2325
                if (ptags[i]->flags & SLT_F_UNUSED)
104 375
                        continue;
105 1950
                printf("%s", ptags[i]->name);
106 1950
                if (ptags[i]->sdesc != NULL && strcmp(ptags[i]->sdesc, ""))
107 1950
                        printf(" - %s", ptags[i]->sdesc);
108 1950
                printf("\n");
109 1950
                if (ptags[i]->ldesc != NULL && strcmp(ptags[i]->ldesc, "")) {
110 1950
                        print_tabbed(ptags[i]->ldesc, 1);
111 1950
                }
112 1950
                printf("\n\n");
113 1950
        }
114
115 25
        return (0);
116
}
117
118
#endif // __FLEXELINT__