Repository navigation
Expand file tree
/
Copy pathsql.c
More file actions
93 lines (78 loc) · 2.19 KB
/
Copy pathsql.c
File metadata and controls
93 lines (78 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* $Id$ */
/*
* Copyright (c) 2017--2020 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#if HAVE_SYS_QUEUE
# include <sys/queue.h>
#endif
#include <assert.h>
#if HAVE_ERR
# include <err.h>
#endif
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ort.h"
#include "ort-lang-sql.h"
int
main(int argc, char *argv[])
{
FILE **confs = NULL;
struct config *cfg = NULL;
int rc = 0;
size_t i;
#if HAVE_PLEDGE
if (pledge("stdio rpath", NULL) == -1)
err(1, "pledge");
#endif
if (getopt(argc, argv, "") != -1)
goto usage;
argc -= optind;
argv += optind;
if (argc > 0 &&
(confs = calloc((size_t)argc, sizeof(FILE *))) == NULL)
err(1, NULL);
for (i = 0; i < (size_t)argc; i++)
if ((confs[i] = fopen(argv[i], "r")) == NULL)
err(1, "%s", argv[i]);
#if HAVE_PLEDGE
if (pledge("stdio", NULL) == -1)
err(1, "pledge");
#endif
if ((cfg = ort_config_alloc()) == NULL)
err(1, NULL);
for (i = 0; i < (size_t)argc; i++)
if (!ort_parse_file(cfg, confs[i], argv[i]))
goto out;
if (argc == 0 && !ort_parse_file(cfg, stdin, "<stdin>"))
goto out;
if ((rc = ort_parse_close(cfg)))
if (!(rc = ort_lang_sql(NULL, cfg, stdout)))
warn(NULL);
out:
ort_write_msg_file(stderr, &cfg->mq);
ort_config_free(cfg);
for (i = 0; i < (size_t)argc; i++)
fclose(confs[i]);
free(confs);
return rc ? 0 : 1;
usage:
fprintf(stderr, "usage: %s [config...]\n", getprogname());
return 1;
}