lang/gcc45
This commit is contained in:
106
lang/gcc45/patches/patch-libcpp_macro.c
Normal file
106
lang/gcc45/patches/patch-libcpp_macro.c
Normal file
@@ -0,0 +1,106 @@
|
||||
$NetBSD$
|
||||
|
||||
--- libcpp/macro.c.orig Fri Nov 20 08:18:16 2009
|
||||
+++ libcpp/macro.c
|
||||
@@ -111,6 +111,61 @@ static const char * const monthnames[] =
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
+static size_t remap_pairs;
|
||||
+static char **remap_src;
|
||||
+static char **remap_dst;
|
||||
+
|
||||
+void
|
||||
+add_cpp_remap_path (const char *arg)
|
||||
+{
|
||||
+ const char *arg_dst;
|
||||
+ size_t len;
|
||||
+
|
||||
+ arg_dst = strchr(arg, ':');
|
||||
+ if (arg_dst == NULL) {
|
||||
+ fprintf(stderr, "Invalid argument for -iremap");
|
||||
+ exit(1);
|
||||
+ }
|
||||
+ len = arg_dst - arg;
|
||||
+ ++arg_dst;
|
||||
+
|
||||
+ remap_src = (char **) xrealloc(remap_src, sizeof(char *) * (remap_pairs + 1));
|
||||
+ remap_dst = (char **) xrealloc(remap_dst, sizeof(char *) * (remap_pairs + 1));
|
||||
+
|
||||
+ remap_src[remap_pairs] = (char *) xmalloc(len + 1);
|
||||
+ memcpy(remap_src[remap_pairs], arg, len);
|
||||
+ remap_src[remap_pairs][len] = '\0';
|
||||
+ remap_dst[remap_pairs] = xstrdup(arg_dst);
|
||||
+ ++remap_pairs;
|
||||
+}
|
||||
+
|
||||
+static const char *
|
||||
+cpp_remap_file (const char *arg, char **tmp_name)
|
||||
+{
|
||||
+ char *result;
|
||||
+ size_t i, len;
|
||||
+
|
||||
+ for (i = 0; i < remap_pairs; ++i) {
|
||||
+ len = strlen (remap_src[i]);
|
||||
+ if (strncmp (remap_src[i], arg, len))
|
||||
+ continue;
|
||||
+ if (arg[len] == '\0')
|
||||
+ return xstrdup (remap_dst[i]);
|
||||
+ if (arg[len] != '/')
|
||||
+ continue;
|
||||
+ arg += len;
|
||||
+ len = strlen (remap_dst[i]);
|
||||
+ result = (char *) xmalloc (len + strlen (arg) + 1);
|
||||
+ memcpy(result, remap_dst[i], len);
|
||||
+ strcpy(result + len, arg);
|
||||
+ *tmp_name = result;
|
||||
+
|
||||
+ return result;
|
||||
+ }
|
||||
+
|
||||
+ return arg;
|
||||
+}
|
||||
+
|
||||
/* Helper function for builtin_macro. Returns the text generated by
|
||||
a builtin macro. */
|
||||
const uchar *
|
||||
@@ -170,6 +225,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashno
|
||||
{
|
||||
unsigned int len;
|
||||
const char *name;
|
||||
+ char *tmp_name;
|
||||
uchar *buf;
|
||||
map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
|
||||
|
||||
@@ -177,12 +233,14 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashno
|
||||
while (! MAIN_FILE_P (map))
|
||||
map = INCLUDED_FROM (pfile->line_table, map);
|
||||
|
||||
- name = map->to_file;
|
||||
+ tmp_name = NULL;
|
||||
+ name = cpp_remap_file (map->to_file, &tmp_name);
|
||||
len = strlen (name);
|
||||
buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
|
||||
result = buf;
|
||||
*buf = '"';
|
||||
buf = cpp_quote_string (buf + 1, (const unsigned char *) name, len);
|
||||
+ free (tmp_name);
|
||||
*buf++ = '"';
|
||||
*buf = '\0';
|
||||
}
|
||||
@@ -607,6 +665,7 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *n
|
||||
memset (args, 0, argc * sizeof (macro_arg));
|
||||
buff->cur = (unsigned char *) &args[argc];
|
||||
arg = args, argc = 0;
|
||||
+ pfile->state.collecting_args = 1;
|
||||
|
||||
/* Collect the tokens making up each argument. We don't yet know
|
||||
how many arguments have been supplied, whether too many or too
|
||||
@@ -721,6 +780,7 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *n
|
||||
}
|
||||
}
|
||||
while (token->type != CPP_CLOSE_PAREN && token->type != CPP_EOF);
|
||||
+ pfile->state.collecting_args = 0;
|
||||
|
||||
if (token->type == CPP_EOF)
|
||||
{
|
||||
Reference in New Issue
Block a user