On Thu, 14 Dec 2006, Joel E. Denny wrote: > 1. If the file name does not contain a `/', it's one of Bison's installed > skeleton files. > > 2. If the file name does contain a `/', it's an absolute or relative file > name. If it's relative, it's relative to where the file name was > specified (current working directory for the command-line, and grammar > file directory for the grammar file).
I committed the following to implement this. Index: ChangeLog =================================================================== RCS file: /sources/bison/bison/ChangeLog,v retrieving revision 1.1667 diff -p -u -r1.1667 ChangeLog --- ChangeLog 17 Jan 2007 18:28:30 -0000 1.1667 +++ ChangeLog 18 Jan 2007 02:05:54 -0000 @@ -1,3 +1,24 @@ +2007-01-17 Joel E. Denny <[EMAIL PROTECTED]> + + Implement support for relative and absolute skeleton file names. + Discussed starting at + <http://lists.gnu.org/archive/html/bison-patches/2006-12/msg00071.html>. + * doc/bison.texinfo (Decl Summary): Document in %skeleton entry. + (Bison Options): Document in --skeleton entry. + * src/output.c (output_skeleton): Use strncpy rather than strcpy since + full_skeleton can't necessarily hold all of pkgdatadir. + If the specified skeleton file name contains a `/', don't prepend + pkgdatadir. + * src/parse-gram.y (prologue_declaration): If the specified skeleton + file name contains a `/', prepend the grammar file directory. + * tests/Makefile.am (TESTSUITE_AT): Add skeletons.at. + * skeletons.at: New file. + (relative skeleton file names): New test case. + (installed skeleton file names): New test case. + * tests/testsuite.at: Include skeletons.at. + + * bootstrap: Update copyright to 2007. + 2007-01-17 Paolo Bonzini <[EMAIL PROTECTED]> * bootstrap: Remove occurrences of .#bootmp from the files. Index: bootstrap =================================================================== RCS file: /sources/bison/bison/bootstrap,v retrieving revision 1.50 diff -p -u -r1.50 bootstrap --- bootstrap 17 Jan 2007 18:28:30 -0000 1.50 +++ bootstrap 18 Jan 2007 02:05:54 -0000 @@ -2,7 +2,7 @@ # Bootstrap this package from CVS. -# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by Index: doc/bison.texinfo =================================================================== RCS file: /sources/bison/bison/doc/bison.texinfo,v retrieving revision 1.221 diff -p -u -r1.221 bison.texinfo --- doc/bison.texinfo 17 Jan 2007 08:44:55 -0000 1.221 +++ doc/bison.texinfo 18 Jan 2007 02:05:57 -0000 @@ -4698,11 +4698,18 @@ Require a Version of Bison}. @end deffn @deffn {Directive} %skeleton "@var{file}" -Specify the skeleton to use. You probably don't need this option unless -you are developing Bison; you should use @code{%language} if you want to -specify the skeleton for a different language, because it is clearer and -because it will always choose the correct skeleton for non-deterministic -or push parsers. +Specify the skeleton to use. + +You probably don't need this option unless you are developing Bison. +You should use @code{%language} if you want to specify the skeleton for a +different language, because it is clearer and because it will always choose the +correct skeleton for non-deterministic or push parsers. + +If @var{file} does not contain a @code{/}, @var{file} is the name of a skeleton +file in the Bison installation directory. +If it does, @var{file} is an absolute file name or a file name relative to the +directory of the grammar file. +This is similar to how most shells resolve commands. @end deffn @deffn {Directive} %token-table @@ -7319,14 +7326,20 @@ Pretend that @code{%no-parser} was speci @item -S @var{file} @itemx [EMAIL PROTECTED] -Specify the skeleton to use, as if @code{%skeleton} was specified +Specify the skeleton to use, similar to @code{%skeleton} (@pxref{Decl Summary, , Bison Declaration Summary}). -You probably don't need this option unless you are developing Bison; -you should use @option{--language} if you want to specify the skeleton for a +You probably don't need this option unless you are developing Bison. +You should use @option{--language} if you want to specify the skeleton for a different language, because it is clearer and because it will always choose the correct skeleton for non-deterministic or push parsers. +If @var{file} does not contain a @code{/}, @var{file} is the name of a skeleton +file in the Bison installation directory. +If it does, @var{file} is an absolute file name or a file name relative to the +current working directory. +This is similar to how most shells resolve commands. + @item -k @itemx --token-table Pretend that @code{%token-table} was specified. @xref{Decl Summary}. Index: src/output.c =================================================================== RCS file: /sources/bison/bison/src/output.c,v retrieving revision 1.266 diff -p -u -r1.266 output.c --- src/output.c 9 Jan 2007 05:24:11 -0000 1.266 +++ src/output.c 18 Jan 2007 02:05:58 -0000 @@ -492,13 +492,16 @@ output_skeleton (void) full_skeleton = xmalloc (pkgdatadirlen + 1 + (skeleton_size < sizeof m4sugar ? sizeof m4sugar : skeleton_size)); - strcpy (full_skeleton, pkgdatadir); + strncpy (full_skeleton, pkgdatadir, pkgdatadirlen); full_skeleton[pkgdatadirlen] = '/'; strcpy (full_skeleton + pkgdatadirlen + 1, m4sugar); full_m4sugar = xstrdup (full_skeleton); strcpy (full_skeleton + pkgdatadirlen + 1, m4bison); full_m4bison = xstrdup (full_skeleton); - strcpy (full_skeleton + pkgdatadirlen + 1, skeleton); + if (strchr (skeleton, '/')) + strcpy (full_skeleton, skeleton); + else + strcpy (full_skeleton + pkgdatadirlen + 1, skeleton); xfclose (xfopen (full_m4sugar, "r")); /* Create an m4 subprocess connected to us via two pipes. */ Index: src/parse-gram.y =================================================================== RCS file: /sources/bison/bison/src/parse-gram.y,v retrieving revision 1.116 diff -p -u -r1.116 parse-gram.y --- src/parse-gram.y 17 Jan 2007 09:00:00 -0000 1.116 +++ src/parse-gram.y 18 Jan 2007 02:05:58 -0000 @@ -286,7 +286,30 @@ prologue_declaration: | "%push-parser" { push_parser = true; pull_parser = false; } | "%push-pull-parser" { push_parser = true; pull_parser = true; } | "%require" STRING { version_check (&@2, $2); } -| "%skeleton" STRING { skeleton_arg ($2, 1, &@1); } +| "%skeleton" STRING + { + char const *skeleton_user = $2; + if (strchr (skeleton_user, '/')) + { + size_t dir_length = strlen (current_file); + char *skeleton_build; + while (dir_length && current_file[dir_length - 1] != '/') + --dir_length; + while (dir_length && current_file[dir_length - 1] == '/') + --dir_length; + skeleton_build = + xmalloc (dir_length + 1 + strlen (skeleton_user) + 1); + if (dir_length > 0) + { + strncpy (skeleton_build, current_file, dir_length); + skeleton_build[dir_length++] = '/'; + } + strcpy (skeleton_build + dir_length, skeleton_user); + skeleton_user = uniqstr_new (skeleton_build); + free (skeleton_build); + } + skeleton_arg (skeleton_user, 1, &@1); + } | "%token-table" { token_table_flag = true; } | "%verbose" { report_flag = report_states; } | "%yacc" { yacc_flag = true; } Index: tests/Makefile.am =================================================================== RCS file: /sources/bison/bison/tests/Makefile.am,v retrieving revision 1.44 diff -p -u -r1.44 Makefile.am --- tests/Makefile.am 2 Jan 2007 02:10:42 -0000 1.44 +++ tests/Makefile.am 18 Jan 2007 02:05:58 -0000 @@ -47,7 +47,7 @@ TESTSUITE_AT = \ local.at \ testsuite.at \ input.at \ - output.at sets.at reduce.at \ + output.at sets.at reduce.at skeletons.at \ synclines.at headers.at actions.at conflicts.at \ calc.at \ torture.at existing.at regression.at \ Index: tests/skeletons.at =================================================================== RCS file: tests/skeletons.at diff -N tests/skeletons.at --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/skeletons.at 18 Jan 2007 02:05:58 -0000 @@ -0,0 +1,143 @@ +# Checking skeleton support. -*- Autotest -*- +# Copyright (C) 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +AT_BANNER([[Skeletons Support.]]) + +## ------------------------------ ## +## relative skeleton file names. ## +## ------------------------------ ## + +AT_SETUP([[relative skeleton file names]]) + +AT_CHECK([[mkdir tmp]]) + +AT_DATA([[tmp/skel.c]], +[[m4@&[EMAIL PROTECTED](0)d@&[EMAIL PROTECTED] [EMAIL PROTECTED](b4_parser_file_name@)d@&[EMAIL PROTECTED] +b4_percent_define_get([[test]]) +m4@&[EMAIL PROTECTED](0) +]]) + +AT_DATA([[skel.c]], +[[m4@&[EMAIL PROTECTED](0)d@&[EMAIL PROTECTED] [EMAIL PROTECTED](b4_parser_file_name@)d@&[EMAIL PROTECTED] +b4_percent_define_get([[test]]) -- Local +m4@&[EMAIL PROTECTED](0) +]]) + +AT_DATA([[tmp/input-gram.y]], +[[%skeleton "./skel.c" +%define test "Hello World" +%% +start: ; +]]) + +AT_DATA([[input-gram.y]], +[[%skeleton "./skel.c" +%define test "Hello World" +%% +start: ; +]]) + +AT_DATA([[tmp/input-cmd-line.y]], +[[%define test "Hello World" +%% +start: ; +]]) + +AT_CHECK([[bison tmp/input-gram.y]]) +AT_CHECK([[cat input-gram.tab.c]], [[0]], +[[Hello World +]]) + +AT_CHECK([[bison input-gram.y]]) +AT_CHECK([[cat input-gram.tab.c]], [[0]], +[[Hello World -- Local +]]) + +AT_CHECK([[bison --skeleton=tmp/skel.c tmp/input-cmd-line.y]]) +AT_CHECK([[cat input-cmd-line.tab.c]], [[0]], +[[Hello World +]]) + +AT_CLEANUP + + +## ------------------------------ ## +## installed skeleton file name. ## +## ------------------------------ ## + +AT_SETUP([[installed skeleton file name]]) + +m4_pushdef([AT_GRAM], +[[%{ + #include <stdio.h> + void yyerror (char const *msg); + int yylex (void); +%} + +%error-verbose +%token 'a' + +%% + +start: ; + +%% + +void +yyerror (char const *msg) +{ + fprintf (stderr, "%s\n", msg); +} + +int +yylex (void) +{ + return 'a'; +} + +int +main (void) +{ + return yyparse (); +} +]]) + +AT_DATA([[input-cmd-line.y]], +[AT_GRAM]) + +AT_DATA([[input-gram.y]], +[[%skeleton "yacc.c"] +AT_GRAM]) + +AT_CHECK([[bison --skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y]]) +AT_COMPILE([[input-cmd-line]]) +AT_PARSER_CHECK([[./input-cmd-line]], [[1]], [], +[[syntax error, unexpected 'a', expecting $end +]]) + +AT_CHECK([[bison -o input-gram.c input-gram.y]]) +AT_COMPILE([[input-gram]]) +AT_PARSER_CHECK([[./input-gram]], [[1]], [], +[[syntax error, unexpected 'a', expecting $end +]]) + +m4_popdef([AT_GRAM]) + +AT_CLEANUP Index: tests/testsuite.at =================================================================== RCS file: /sources/bison/bison/tests/testsuite.at,v retrieving revision 1.32 diff -p -u -r1.32 testsuite.at --- tests/testsuite.at 12 Dec 2006 06:47:39 -0000 1.32 +++ tests/testsuite.at 18 Jan 2007 02:05:58 -0000 @@ -1,6 +1,6 @@ # Test suite for GNU Bison. -*- Autotest -*- -# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Free Software +# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007 Free Software # Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -34,6 +34,9 @@ m4_include([input.at]) # Testing output file names. m4_include([output.at]) +# Testing skeleton support. +m4_include([skeletons.at]) + # Testing the part of the engine that computes FOLLOW etc. m4_include([sets.at])
