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