-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > When an include file is found not in the current directory, but in > one of the -I directories (or through an env var), the #line > directives must include the full path (like cpp does).
Agreed. It also affects the __file__ macro. Here's a patch that will make it in 1.4.6 that does just that: 2006-07-29 Eric Blake <[EMAIL PROTECTED]> * src/path.c (path_search): Add result parameter, so that -I can be accounted for. Debian bug 53685. * src/m4.h (path_search): Update prototype. * src/m4.c (main): Adjust callers. * src/freeze.c (reload_frozen_state): Likewise. * src/builtin.c (include, m4_undivert): Likewise. * NEWS: Document this change. - -- Life is short - so eat dessert first! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEzCTH84KuGfSFAYARAn1HAJwJw3zlxiCUyH7xIfYjJMVU3QqOcwCeNTeW mTgjRWLhu7xEzAe7P91cfFI= =qg0L -----END PGP SIGNATURE-----
Index: NEWS =================================================================== RCS file: /sources/m4/m4/NEWS,v retrieving revision 1.1.1.1.2.44 diff -u -p -r1.1.1.1.2.44 NEWS --- NEWS 26 Jul 2006 23:21:29 -0000 1.1.1.1.2.44 +++ NEWS 30 Jul 2006 03:15:36 -0000 @@ -17,6 +17,9 @@ Version 1.4.6 - ?? 2006, by ?? (CVS ver collection. * The dnl macro now warns if end of file is encountered instead of a newline. +* The __file__ macro, and the -s/--synclines option, now show what + directory a file was found in when the -I/--include option or M4PATH + variable had an effect. Version 1.4.5 - 15 July 2006, by Eric Blake (CVS version 1.4.4c) Index: src/builtin.c =================================================================== RCS file: /sources/m4/m4/src/Attic/builtin.c,v retrieving revision 1.1.1.1.2.28 diff -u -p -r1.1.1.1.2.28 builtin.c --- src/builtin.c 27 Jul 2006 21:41:12 -0000 1.1.1.1.2.28 +++ src/builtin.c 30 Jul 2006 03:15:37 -0000 @@ -1049,7 +1049,7 @@ m4_undivert (struct obstack *obs, int ar "non-numeric argument to builtin `%s'", ARG (0))); else { - fp = path_search (ARG (i)); + fp = path_search (ARG (i), NULL); if (fp != NULL) { insert_file (fp); @@ -1154,11 +1154,12 @@ static void include (int argc, token_data **argv, boolean silent) { FILE *fp; + const char *name; if (bad_argc (argv[0], argc, 2, 2)) return; - fp = path_search (ARG (1)); + fp = path_search (ARG (1), &name); if (fp == NULL) { if (!silent) @@ -1167,7 +1168,8 @@ include (int argc, token_data **argv, bo return; } - push_file (fp, ARG (1)); + push_file (fp, name); + free ((char *) name); } /*------------------------------------------------. Index: src/freeze.c =================================================================== RCS file: /sources/m4/m4/src/freeze.c,v retrieving revision 1.1.1.1.2.11 diff -u -p -r1.1.1.1.2.11 freeze.c --- src/freeze.c 24 Jul 2006 20:02:16 -0000 1.1.1.1.2.11 +++ src/freeze.c 30 Jul 2006 03:15:37 -0000 @@ -222,7 +222,7 @@ reload_frozen_state (const char *name) } \ while (character == '\n') - file = path_search (name); + file = path_search (name, NULL); if (file == NULL) M4ERROR ((EXIT_FAILURE, errno, "cannot open %s", name)); Index: src/m4.c =================================================================== RCS file: /sources/m4/m4/src/Attic/m4.c,v retrieving revision 1.1.1.1.2.22 diff -u -p -r1.1.1.1.2.22 m4.c --- src/m4.c 27 Jul 2006 18:12:08 -0000 1.1.1.1.2.22 +++ src/m4.c 30 Jul 2006 03:15:37 -0000 @@ -503,7 +503,8 @@ Written by Rene' Seindal.\n\ push_file (stdin, "stdin"); else { - fp = path_search (argv[optind]); + const char *name; + fp = path_search (argv[optind], &name); if (fp == NULL) { error (0, errno, "%s", argv[optind]); @@ -512,8 +513,8 @@ Written by Rene' Seindal.\n\ retcode = EXIT_FAILURE; continue; } - else - push_file (fp, argv[optind]); + push_file (fp, name); + free ((char *) name); } expand_input (); } Index: src/m4.h =================================================================== RCS file: /sources/m4/m4/src/m4.h,v retrieving revision 1.1.1.1.2.21 diff -u -p -r1.1.1.1.2.21 m4.h --- src/m4.h 28 Jul 2006 20:39:37 -0000 1.1.1.1.2.21 +++ src/m4.h 30 Jul 2006 03:15:37 -0000 @@ -398,7 +398,7 @@ const builtin *find_builtin_by_name (con void include_init (void); void include_env_init (void); void add_include_directory (const char *); -FILE *path_search (const char *); +FILE *path_search (const char *, const char **); /* File: eval.c --- expression evaluation. */ Index: src/path.c =================================================================== RCS file: /sources/m4/m4/src/Attic/path.c,v retrieving revision 1.1.1.1.2.5 diff -u -p -r1.1.1.1.2.5 path.c --- src/path.c 10 Jul 2006 01:44:10 -0000 1.1.1.1.2.5 +++ src/path.c 30 Jul 2006 03:15:37 -0000 @@ -100,14 +100,22 @@ add_include_directory (const char *dir) #endif } +/* Search for FILE, first in `.', then according to -I options. If + successful, return the open file, and if RESULT is not NULL, set + *RESULT to a malloc'd string that represents the file found with + respect to the current working directory. */ + FILE * -path_search (const char *file) +path_search (const char *file, const char **result) { FILE *fp; includes *incl; char *name; /* buffer for constructed name */ int e; + if (result) + *result = NULL; + /* Reject empty file. */ if (!*file) { @@ -118,7 +126,11 @@ path_search (const char *file) /* Look in current working directory first. */ fp = fopen (file, "r"); if (fp != NULL) - return fp; + { + if (result) + *result = strdup (file); + return fp; + } /* If file not found, and filename absolute, fail. */ if (*file == '/' || no_gnu_extensions) @@ -142,7 +154,12 @@ path_search (const char *file) { if (debug_level & DEBUG_TRACE_PATH) DEBUG_MESSAGE2 ("path search for `%s' found `%s'", file, name); - break; + if (result) + *result = name; + else + free (name); + errno = e; + return fp; } } xfree (name);