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