Skip to content

Commit dc9c0fc

Browse files
committed
cswrap-core: port to new cswrap-util API
... to deduplicate code of cswrap and cscppc
1 parent 21d9ff6 commit dc9c0fc

2 files changed

Lines changed: 7 additions & 48 deletions

File tree

cswrap

src/cswrap-core.c

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int handle_args(const int argc, char *argv[])
8787
return usage(argv);
8888
}
8989

90-
void signal_forwarder(int signum)
90+
static void signal_forwarder(int signum)
9191
{
9292
const int saved_errno = errno;
9393

@@ -100,29 +100,16 @@ void signal_forwarder(int signum)
100100
errno = saved_errno;
101101
}
102102

103-
bool install_signal_forwarder(void)
103+
static bool install_signal_forwarder(void)
104104
{
105105
static int forwarded_signals[] = {
106106
SIGINT,
107107
SIGQUIT,
108-
SIGTERM
108+
SIGTERM,
109+
/* list terminator */ 0
109110
};
110111

111-
static int forwarded_signals_cnt =
112-
sizeof(forwarded_signals)/
113-
sizeof(forwarded_signals[0]);
114-
115-
static const struct sigaction sa = {
116-
.sa_handler = signal_forwarder
117-
};
118-
119-
/* install the handler for all forwarded signals */
120-
int i;
121-
for (i = 0; i < forwarded_signals_cnt; ++i)
122-
if (0 != sigaction(forwarded_signals[i], &sa, NULL))
123-
return false;
124-
125-
return true;
112+
return install_signal_handler(signal_forwarder, forwarded_signals);
126113
}
127114

128115
static void apply_del_arg(char **argv, const char *del_arg)
@@ -230,34 +217,6 @@ bool is_bare_def_inc(const char *arg)
230217
|| STREQ(arg, "-isystem")));
231218
}
232219

233-
bool is_input_file_suffix(const char *suffix)
234-
{
235-
if (STREQ(suffix, "c"))
236-
return true;
237-
238-
if (!analyzer_is_cxx_ready)
239-
return false;
240-
241-
return STREQ(suffix, "C")
242-
|| STREQ(suffix, "cc")
243-
|| STREQ(suffix, "cpp")
244-
|| STREQ(suffix, "cxx");
245-
}
246-
247-
bool is_input_file(const char *arg)
248-
{
249-
const char *suffix = strrchr(arg, '.');
250-
if (!suffix)
251-
/* we require the file name to contain at least one dot */
252-
return false;
253-
254-
/* skip behind the dot */
255-
++suffix;
256-
257-
/* check for a known input file suffix */
258-
return is_input_file_suffix(suffix);
259-
}
260-
261220
int /* args remain */ drop_arg(int *pargc, char **argv, const int i)
262221
{
263222
const int argc = --(*pargc);
@@ -287,7 +246,7 @@ int translate_args_for_analyzer(int argc, char **argv)
287246
continue;
288247
}
289248

290-
if (is_input_file(arg)) {
249+
if (is_input_file(arg, analyzer_is_cxx_ready)) {
291250
if (is_ignored_file(arg))
292251
/* ignored input file --> do not start analyzer */
293252
return -1;

0 commit comments

Comments
 (0)