#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "distcc.h"
#include "trace.h"
#include "io.h"
#include "util.h"
#include "exitcode.h"
#include "strip.h"
int dcc_strip_local_args(char **from, char ***out_argv)
{
char **to;
int from_i, to_i;
int from_len;
dcc_trace_argv("original arguments", from);
from_len = dcc_argv_len(from);
*out_argv = to = malloc((from_len + 1) * sizeof (char *));
if (!to) {
rs_log_error("failed to allocate space for arguments");
return EXIT_OUT_OF_MEMORY;
}
for (from_i = to_i = 0; from[from_i]; from_i++) {
if (str_equal("-D", from[from_i])
|| str_equal("-I", from[from_i])
|| str_equal("-U", from[from_i])
|| str_equal("-L", from[from_i])
|| str_equal("-l", from[from_i])
|| str_equal("-MF", from[from_i])
|| str_equal("-MT", from[from_i])
|| str_equal("-MQ", from[from_i])
|| str_equal("-include", from[from_i])
|| str_equal("-imacros", from[from_i])
|| str_equal("-iprefix", from[from_i])
|| str_equal("-iwithprefix", from[from_i])
|| str_equal("-isystem", from[from_i])
|| str_equal("-iwithprefixbefore", from[from_i])
|| str_equal("-idirafter", from[from_i])) {
if (from[from_i+1])
from_i++;
}
else if (str_startswith("-Wp,", from[from_i])
|| str_startswith("-Wl,", from[from_i])
|| str_startswith("-D", from[from_i])
#if defined(DARWIN)
|| str_startswith("-F", from[from_i])
#endif // DARWIN
|| str_startswith("-U", from[from_i])
|| str_startswith("-I", from[from_i])
|| str_startswith("-l", from[from_i])
|| str_startswith("-L", from[from_i])) {
;
}
else if (str_equal("-undef", from[from_i])
|| str_equal("-nostdinc", from[from_i])
|| str_equal("-nostdinc++", from[from_i])
|| str_equal("-MD", from[from_i])
|| str_equal("-MMD", from[from_i])
|| str_equal("-MG", from[from_i])
|| str_equal("-MP", from[from_i])) {
;
}
else {
to[to_i++] = from[from_i];
}
}
to[to_i] = NULL;
dcc_trace_argv("result", to);
return 0;
}
int dcc_strip_dasho(char **from, char ***out_argv)
{
char **to;
int from_i, to_i;
int from_len;
from_len = dcc_argv_len(from);
*out_argv = to = malloc((from_len + 1) * sizeof (char *));
if (!to) {
rs_log_error("failed to allocate space for arguments");
return EXIT_OUT_OF_MEMORY;
}
for (from_i = to_i = 0; from[from_i]; ) {
if (!strcmp(from[from_i], "-o")) {
from_i += 2;
}
else if (str_startswith("-o", from[from_i])) {
from_i++;
}
else {
to[to_i++] = from[from_i++];
}
}
to[to_i] = NULL;
dcc_trace_argv("result", to);
return 0;
}