-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnodejs.c
113 lines (96 loc) · 2.66 KB
/
nodejs.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* $Id$ */
/*
* Copyright (c) 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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ort.h"
#include "ort-lang-nodejs.h"
int
main(int argc, char *argv[])
{
struct ort_lang_nodejs args;
struct config *cfg = NULL;
int c, rc = 0;
FILE **confs = NULL;
size_t i;
memset(&args, 0, sizeof(struct ort_lang_nodejs));
args.flags = ORT_LANG_NODEJS_DB | ORT_LANG_NODEJS_CORE;
#if HAVE_PLEDGE
if (pledge("stdio rpath", NULL) == -1)
err(1, "pledge");
#endif
while ((c = getopt(argc, argv, "eN:v")) != -1)
switch (c) {
case 'e':
args.flags |= ORT_LANG_NODEJS_NOMODULE;
break;
case 'N':
if (strchr(optarg, 'b') != NULL)
args.flags &= ~ORT_LANG_NODEJS_CORE;
if (strchr(optarg, 'd') != NULL)
args.flags &= ~ORT_LANG_NODEJS_DB;
break;
case 'v':
args.flags |= ORT_LANG_NODEJS_VALID;
break;
default:
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_nodejs(&args, 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;
usage:
fprintf(stderr, "usage: %s [-ev] [-N[b|d] [config...]\n",
getprogname());
return 1;
}