diff options
Diffstat (limited to 'gcc/cp/repo.c')
-rw-r--r-- | gcc/cp/repo.c | 93 |
1 files changed, 65 insertions, 28 deletions
diff --git a/gcc/cp/repo.c b/gcc/cp/repo.c index 47a111b..d9b4486 100644 --- a/gcc/cp/repo.c +++ b/gcc/cp/repo.c @@ -41,6 +41,8 @@ static tree original_repo; static char *repo_name; static FILE *repo_file; +static char *old_args, *old_dir, *old_main; + extern int flag_use_repository; extern int errorcount, sorrycount; extern struct obstack temporary_obstack; @@ -198,35 +200,55 @@ save_string (s, len) return obstack_copy0 (&temporary_obstack, s, len); } +/* Parse a reasonable subset of shell quoting syntax. */ + +static char * +extract_string (pp) + char **pp; +{ + char *p = *pp; + int backquote = 0; + int inside = 0; + + for (;;) + { + char c = *p; + if (c == '\0') + break; + ++p; + if (backquote) + obstack_1grow (&temporary_obstack, c); + else if (! inside && c == ' ') + break; + else if (! inside && c == '\\') + backquote = 1; + else if (c == '\'') + inside = !inside; + else + obstack_1grow (&temporary_obstack, c); + } + + obstack_1grow (&temporary_obstack, '\0'); + *pp = p; + return obstack_finish (&temporary_obstack); +} + static char * get_base_filename (filename) char *filename; { char *p = getenv ("COLLECT_GCC_OPTIONS"); - char *output = 0; + char *output = NULL; int compiling = 0; - if (p) - while (*p) - { - char *q = p; - while (*q && *q != ' ') q++; - if (*p == '-' && p[1] == 'o') - { - p += 2; - if (p == q) - { - p++; q++; - if (*q) - while (*q && *q != ' ') q++; - } + while (p && *p) + { + char *q = extract_string (&p); - output = save_string (p, q - p); - } - else if (*p == '-' && p[1] == 'c') - compiling = 1; - if (*q) q++; - p = q; + if (strcmp (q, "-o") == 0) + output = extract_string (&p); + else if (strcmp (q, "-c") == 0) + compiling = 1; } if (compiling && output) @@ -301,8 +323,16 @@ init_repo (filename) switch (buf[0]) { case 'A': + old_args = obstack_copy0 (&permanent_obstack, buf + 2, + strlen (buf + 2)); + break; case 'D': + old_dir = obstack_copy0 (&permanent_obstack, buf + 2, + strlen (buf + 2)); + break; case 'M': + old_main = obstack_copy0 (&permanent_obstack, buf + 2, + strlen (buf + 2)); break; case 'C': case 'O': @@ -350,6 +380,7 @@ finish_repo () tree t; char *p; int repo_changed = 0; + char *dir, *args; if (! flag_use_repository) return; @@ -382,6 +413,16 @@ finish_repo () } } + dir = getpwd (); + args = getenv ("COLLECT_GCC_OPTIONS"); + + if (! repo_changed && pending_repo) + if (strcmp (old_main, main_input_filename) != 0 + || strcmp (old_dir, dir) != 0 + || (args == NULL) != (old_args == NULL) + || strcmp (old_args, args) != 0) + repo_changed = 1; + if (! repo_changed || errorcount || sorrycount) goto out; @@ -391,13 +432,9 @@ finish_repo () goto out; fprintf (repo_file, "M %s\n", main_input_filename); - - p = getpwd (); - fprintf (repo_file, "D %s\n", p); - - p = getenv ("COLLECT_GCC_OPTIONS"); - if (p != 0) - fprintf (repo_file, "A %s\n", p); + fprintf (repo_file, "D %s\n", dir); + if (args) + fprintf (repo_file, "A %s\n", args); for (t = pending_repo; t; t = TREE_CHAIN (t)) { |