Le 12 juin 2012 à 18:24, Akim Demaille a écrit : > Fourth step. This introduces a weakness in Bison: when > given arguments such as > > --output=sub1/foo.c --defines=sub2/foo.h > > then sub1/foo.c features '#include "sub2/foo.h"'. But we actually > already have this problem in glr.c which already prefers to include > the header instead of duplicating its content. > > So we really need to be able to compute "relative" paths here, to > be addressed in the near future. > > Ok to install?
I have given a try to computing relative paths by stealing some bits from the coreutils (relpath.[ch] and a function from ln.c, as suggested by Eric Blake). I have pushed in gnulib an akim/relpath branch with this. Then I used it in Bison, see below, but I am frighten by the sheer number of dependencies that this simple idea incurs. Am I missing something? Just have a look at the gitignore changes… (this is in the declare-yyparse branch of Bison). Any opinion is *most* welcome. From 424cb4f460a0f4f1f8325a8eb7e1d0686635962b Mon Sep 17 00:00:00 2001 From: Akim Demaille <[email protected]> Date: Wed, 13 Jun 2012 22:22:38 +0200 Subject: [PATCH] compute relative paths from parser.c to parser.h for #include * bootstrap.conf: Request relpath. * gnulib: Update to get it. * src/scan-skel.l (@relative): New. * data/glr.c: Use it. --- bootstrap.conf | 2 ++ data/glr.c | 2 +- gnulib | 2 +- lib/.gitignore | 47 +++++++++++++++++++++++++++++++++++++++++++++++ m4/.gitignore | 25 +++++++++++++++++++++++++ src/scan-skel.l | 14 ++++++++++++++ 6 files changed, 90 insertions(+), 2 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index aa05e34..1b68ef5 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -28,6 +28,7 @@ gnulib_modules=' quote quotearg readme-release realloc-posix + relpath spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp unistd unistd-safer unlocked-io update-copyright unsetenv verify warnings @@ -42,6 +43,7 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ --from-code=UTF-8\\\ --flag=asprintf:2:c-format\\\ --flag=complain:1:c-format --flag=complain_at:2:c-format\\\ + --flag=error:3:c-format --flag=error_at_line:5:c-format\\\ --flag=fatal:1:c-format --flag=fatal_at:2:c-format\\\ --flag=warn:1:c-format --flag=warn_at:2:c-format\\\ --flag=unexpected_end:2:c-format\\\ diff --git a/data/glr.c b/data/glr.c index 7ebc65c..117ccaa 100644 --- a/data/glr.c +++ b/data/glr.c @@ -202,7 +202,7 @@ m4_if(b4_prefix, [yy], [], ]b4_null_define[ -]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], +]b4_defines_if([[#include "@relative(]b4_spec_defines_file[@, ]b4_parser_file_name[@)"]], [b4_shared_declarations])[ /* Enabling traces. */ diff --git a/gnulib b/gnulib index b42157d..2005fbf 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit b42157dd01e3243646f5a8270c09ee125a8aca21 +Subproject commit 2005fbf739536a0f60bf970c24c1ecf3c9cc8a43 diff --git a/lib/.gitignore b/lib/.gitignore index 5eec743..bb516bd 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -268,3 +268,50 @@ /xmemdup0.c /xmemdup0.h /sys_types.in.h +/relpath.c +/relpath.h +/areadlink-with-size.c +/areadlink.h +/at-func.c +/canonicalize.c +/canonicalize.h +/chdir-long.c +/chdir-long.h +/closedir.c +/dirent-private.h +/dirent.in.h +/dirfd.c +/dup.c +/fchdir.c +/fdopendir.c +/file-set.c +/file-set.h +/filename.h +/filenamecat-lgpl.c +/filenamecat.h +/fstatat.c +/getcwd-lgpl.c +/getcwd.c +/hash-pjw.c +/hash-pjw.h +/hash-triple.c +/hash-triple.h +/lstat.c +/mempcpy.c +/memrchr.c +/openat-die.c +/openat-priv.h +/openat-proc.c +/openat.c +/openat.h +/opendir.c +/readdir.c +/readlink.c +/rewinddir.c +/same-inode.h +/same.c +/same.h +/save-cwd.c +/save-cwd.h +/xgetcwd.c +/xgetcwd.h diff --git a/m4/.gitignore b/m4/.gitignore index d47aee0..d505bf8 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -178,3 +178,28 @@ /xstrndup.m4 /off_t.m4 /sys_types_h.m4 +/canonicalize.m4 +/chdir-long.m4 +/closedir.m4 +/d-ino.m4 +/dirent_h.m4 +/dirfd.m4 +/dup.m4 +/fchdir.m4 +/fdopendir.m4 +/filenamecat.m4 +/fstatat.m4 +/getcwd-abort-bug.m4 +/getcwd-path-max.m4 +/getcwd.m4 +/lstat.m4 +/mempcpy.m4 +/memrchr.m4 +/openat.m4 +/opendir.m4 +/readdir.m4 +/readlink.m4 +/rewinddir.m4 +/same.m4 +/save-cwd.m4 +/xgetcwd.m4 diff --git a/src/scan-skel.l b/src/scan-skel.l index 2433905..7e7f68e 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -36,6 +36,7 @@ #include "complain.h" #include "getargs.h" #include "files.h" +#include "relpath.h" #include "scan-skel.h" #define YY_DECL static int skel_lex (void) @@ -265,6 +266,19 @@ at_directive_perform (int at_directive_argc, break; } } + else if (0 == strcmp (at_directive_argv[0], "@relative")) + { + if (at_directive_argc < 3) + fail_for_at_directive_too_few_args (at_directive_argv[0]); + if (at_directive_argc > 3) + fail_for_at_directive_too_many_args (at_directive_argv[0]); + { + char *rel = convert_abs_rel(at_directive_argv[1], + at_directive_argv[2]); + fputs (rel, yyout); + free (rel); + } + } else if (0 == strcmp (at_directive_argv[0], "@output")) { if (at_directive_argc > 2) -- 1.7.10.4
