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 40
usage(void)
50
{
51 40
        fprintf(stderr, "Usage: vxp_test -q <query-expression>\n");
52 40
        exit(1);
53
}
54
55
int
56 120
main(int argc, char * const *argv)
57
{
58
        struct vsb *vsb;
59
        struct vex *vex;
60 120
        char *q_arg = NULL;
61
        int opt;
62
63 280
        while ((opt = getopt(argc, argv, "q:")) != -1) {
64 160
                switch (opt) {
65
                case 'q':
66 120
                        REPLACE(q_arg, optarg);
67 120
                        break;
68
                default:
69 40
                        usage();
70 40
                }
71
        }
72 120
        if (q_arg == NULL || optind != argc)
73 0
                usage();
74
75 120
        vsb = VSB_new_auto();
76 120
        AN(vsb);
77 120
        vex = vex_New(q_arg, vsb, 0);
78
79 120
        if (vex == NULL) {
80 40
                AZ(VSB_finish(vsb));
81 40
                fprintf(stderr, "Error:\n%s", VSB_data(vsb));
82 40
                VSB_destroy(&vsb);
83 40
                free(q_arg);
84 40
                exit(1);
85
        }
86 80
        VSB_destroy(&vsb);
87
88 80
        vex_Free(&vex);
89 80
        AZ(vex);
90 80
        free(q_arg);
91
92 80
        return (0);
93
}
94
95
#endif // __FLEXELINT__