varnish-cache/lib/libvarnishapi/vsl2rst.c
1
/*-
2
 * Copyright (c) 2011-2015 Varnish Software AS
3
 * All rights reserved.
4
 *
5
 * Author: Martin Blix Grydeland <martin@varnish-software.com>
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 *
28
 */
29
30
#ifndef __FLEXELINT__
31
32
#include "config.h"
33
34
#include <stdint.h>
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <string.h>
38
39
#include "vapi/vsl.h"
40
41
struct SLT {
42
        unsigned        tag;
43
        unsigned        flags;
44
        const char      *name;
45
        const char      *sdesc;
46
        const char      *ldesc;
47
};
48
49
static struct SLT tags[SLT__MAX] = {
50
#define SLTM(name, flags, sdesc, ldesc)                         \
51
        [SLT_##name] = { SLT_##name, flags, #name, sdesc, ldesc },
52
#include "tbl/vsl_tags.h"
53
};
54
55
static int
56 883
ptag_cmp(const void *va, const void *vb)
57
{
58
        const struct SLT *a, *b;
59
60 883
        a = *(const struct SLT * const *)va;
61 883
        b = *(const struct SLT * const *)vb;
62 883
        if (a->name == NULL && b->name != NULL)
63 2
                return (1);
64 881
        else if (a->name != NULL && b->name == NULL)
65 93
                return (-1);
66 788
        else if (a->name == NULL && b->name == NULL)
67 171
                return (0);
68 617
        return (strcmp(a->name, b->name));
69
}
70
71
static void
72 71
print_tabbed(const char *string, int tabs)
73
{
74
        int i;
75
        const char *c;
76
77 10974
        for (c = string; *c; c++) {
78 10903
                if (c == string || *(c - 1) == '\n')
79 948
                        for (i = 0; i < tabs; i++)
80 474
                                printf("\t");
81 10903
                printf("%c", *c);
82
        }
83 71
}
84
85
int
86 1
main(int argc, char *argv[])
87
{
88
        int i;
89
        struct SLT *ptags[SLT__MAX];
90
91
        (void)argc;
92
        (void)argv;
93
94 257
        for (i = 0; i < SLT__MAX; i++)
95 256
                ptags[i] = &tags[i];
96
97 1
        qsort(ptags, SLT__MAX, sizeof *ptags, ptag_cmp);
98
99 257
        for (i = 0; i < SLT__MAX; i++) {
100 256
                if (ptags[i]->name == NULL || !strcmp(ptags[i]->name, ""))
101 165
                        continue;
102 91
                if (ptags[i]->flags & SLT_F_UNUSED)
103 20
                        continue;
104 71
                printf("%s", ptags[i]->name);
105 71
                if (ptags[i]->sdesc != NULL && strcmp(ptags[i]->sdesc, ""))
106 71
                        printf(" - %s", ptags[i]->sdesc);
107 71
                printf("\n");
108 71
                if (ptags[i]->ldesc != NULL && strcmp(ptags[i]->ldesc, "")) {
109 71
                        print_tabbed(ptags[i]->ldesc, 1);
110
                }
111 71
                printf("\n\n");
112
        }
113
114 1
        return (0);
115
}
116
117
#endif // __FLEXELINT__