varnish-cache/lib/libvarnishapi/vxp_test.c
0
/*-
1
 * Copyright (c) 2014-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
#ifndef __FLEXELINT__
31
32
#include <stdio.h>
33
#include <stdint.h>
34
#include <stdlib.h>
35
#include <string.h>
36
#include <unistd.h>
37
38
#include "miniobj.h"
39
#include "vdef.h"
40
#include "vqueue.h"
41
#include "vre.h"
42
#include "vas.h"
43
44
#include "vsb.h"
45
46
#include "vxp.h"
47
48
static void
49 25
usage(void)
50
{
51 25
        fprintf(stderr, "Usage: vxp_test -q <query-expression>\n");
52 25
        exit(1);
53
}
54
55
int
56 75
main(int argc, char * const *argv)
57
{
58
        struct vsb *vsb;
59
        struct vex *vex;
60 75
        char *q_arg = NULL;
61
        int opt;
62
63 175
        while ((opt = getopt(argc, argv, "q:")) != -1) {
64 100
                switch (opt) {
65
                case 'q':
66 75
                        REPLACE(q_arg, optarg);
67 75
                        break;
68
                default:
69 25
                        usage();
70 25
                }
71
        }
72 75
        if (q_arg == NULL || optind != argc)
73 0
                usage();
74
75 75
        vsb = VSB_new_auto();
76 75
        AN(vsb);
77 75
        vex = vex_New(q_arg, vsb, 0);
78
79 75
        if (vex == NULL) {
80 25
                AZ(VSB_finish(vsb));
81 25
                fprintf(stderr, "Error:\n%s", VSB_data(vsb));
82 25
                VSB_destroy(&vsb);
83 25
                free(q_arg);
84 25
                exit(1);
85
        }
86 50
        VSB_destroy(&vsb);
87
88 50
        vex_Free(&vex);
89 50
        AZ(vex);
90 50
        free(q_arg);
91
92 50
        return (0);
93
}
94
95
#endif // __FLEXELINT__