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 1734
ptag_cmp(const void *va, const void *vb)
57
{
58
        const struct SLT *a, *b;
59
60 1734
        a = *(const struct SLT * const *)va;
61 1734
        b = *(const struct SLT * const *)vb;
62 1734
        if (a->name == NULL && b->name != NULL)
63 4
                return (1);
64 1730
        else if (a->name != NULL && b->name == NULL)
65 190
                return (-1);
66 1540
        else if (a->name == NULL && b->name == NULL)
67 338
                return (0);
68 1202
        return (strcmp(a->name, b->name));
69
}
70
71
static void
72 146
print_tabbed(const char *string, int tabs)
73
{
74
        int i;
75
        const char *c;
76
77 25428
        for (c = string; *c; c++) {
78 25282
                if (c == string || *(c - 1) == '\n')
79 2072
                        for (i = 0; i < tabs; i++)
80 1036
                                printf("\t");
81 25282
                printf("%c", *c);
82
        }
83 146
}
84
85
int
86 2
main(int argc, char *argv[])
87
{
88
        int i;
89
        struct SLT *ptags[SLT__MAX];
90
91
        (void)argc;
92
        (void)argv;
93
94 514
        for (i = 0; i < SLT__MAX; i++)
95 512
                ptags[i] = &tags[i];
96
97 2
        qsort(ptags, SLT__MAX, sizeof *ptags, ptag_cmp);
98
99 514
        for (i = 0; i < SLT__MAX; i++) {
100 512
                if (ptags[i]->name == NULL || !strcmp(ptags[i]->name, ""))
101 326
                        continue;
102 186
                if (ptags[i]->flags & SLT_F_UNUSED)
103 40
                        continue;
104 146
                printf("%s", ptags[i]->name);
105 146
                if (ptags[i]->sdesc != NULL && strcmp(ptags[i]->sdesc, ""))
106 146
                        printf(" - %s", ptags[i]->sdesc);
107 146
                printf("\n");
108 146
                if (ptags[i]->ldesc != NULL && strcmp(ptags[i]->ldesc, "")) {
109 146
                        print_tabbed(ptags[i]->ldesc, 1);
110
                }
111 146
                printf("\n\n");
112
        }
113
114 2
        return (0);
115
}
116
117
#endif // __FLEXELINT__