Commit fa5d4812 fa5d4812fc4936dd470ded17116c9d966d0d645e by Sergey Poznyakoff

Rewrite Makefile rules for lex and bison

The aim is to get rid of the explicit rules and use the Autmake framework
as much as possible, without hurting the flexibility.  To this effect, the
gylwrap tool is rewritten from scratch (in Perl).  In compatibility
mode it takes the same arguments as the standard ylwrap.  Additional
configuration is supplied in the configuration file gylwrap.conf, located
in the directory where the input file resides.

* mu-aux/gylwrap: Rewrite from scratch.
* configure.ac (MU_YLWRAP): New subst variable.
* libmailutils/base/.gitignore: Update.
* libmailutils/base/Makefile.am: Update.
* libmailutils/base/gylwrap.conf: New file.
* libmailutils/cfg/.gitignore: Update.
* libmailutils/cfg/Makefile.am: Use new YLWRAP
* libmailutils/cfg/cfg.h: Remove.
* libmailutils/cfg/gylwrap.conf: New file.
* libmailutils/cfg/lexer.l: Include mailutils/yyloc.h directly.
* libmailutils/cfg/parser.y: Likewise.
* libmu_sieve/Makefile.am: Use new YLWRAP
* libmu_sieve/gylwrap.conf: New file.
* libmu_sieve/sieve.y: Rename to libmu_sieve/sieve-gram.y
* libmu_sieve/sieve.l: Rename to libmu_sieve/sieve-lex.l
* mail/Makefile.am: Use new YLWRAP
* mh/.gitignore: Update.
* mh/Makefile.am: Use new YLWRAP
* mh/gylwrap.conf: New file.
* mh/mh_alias.y: Rename to mh/mh_alias_gram.y
* mh/mh_alias.l: Rename to mh/mh_alias_lex.l
* mh/pick.y: Rename to mh/pick-gram.y
* mimeview/.gitignore: Update.
* mimeview/Makefile.am: Use new YLWRAP
* mimeview/mimetypes.y: Rename to mimeview/grammar.y
* mimeview/gylwrap.conf: New file.
* mimeview/mimetypes.l: Rename to mimeview/lexer.l
* po/POTFILES.in: Update
1 parent 3a78309a
...@@ -71,6 +71,9 @@ AC_SUBST(MU_LIB_COMMON_INCLUDES,'-I${top_builddir} -I${top_srcdir}/include -I${ ...@@ -71,6 +71,9 @@ AC_SUBST(MU_LIB_COMMON_INCLUDES,'-I${top_builddir} -I${top_srcdir}/include -I${
71 71
72 AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu -I${top_builddir} -I${top_builddir}/include') 72 AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu -I${top_builddir} -I${top_builddir}/include')
73 73
74 # Use our replacement for the ylwrap tool
75 AC_SUBST([MU_YLWRAP],'$(mu_aux_dir)/gylwrap --compatibility --')
76
74 dnl Check for programs 77 dnl Check for programs
75 AC_PROG_CC 78 AC_PROG_CC
76 AM_PROG_CC_C_O 79 AM_PROG_CC_C_O
......
...@@ -54,7 +54,7 @@ libbase_la_SOURCES = \ ...@@ -54,7 +54,7 @@ libbase_la_SOURCES = \
54 observer.c\ 54 observer.c\
55 onexit.c\ 55 onexit.c\
56 opool.c\ 56 opool.c\
57 parsedate.c\ 57 parsedate.y\
58 permstr.c\ 58 permstr.c\
59 registrar.c\ 59 registrar.c\
60 refcount.c\ 60 refcount.c\
...@@ -82,17 +82,10 @@ AM_CPPFLAGS = \ ...@@ -82,17 +82,10 @@ AM_CPPFLAGS = \
82 -DLOCALEDIR=\"$(localedir)\" 82 -DLOCALEDIR=\"$(localedir)\"
83 83
84 84
85 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap 85 YLWRAP = @MU_YLWRAP@
86 AM_YFLAGS=-vt 86 EXTRA_DIST = gylwrap.conf
87 AM_LFLAGS=-dp 87 AM_YFLAGS=
88 AM_LFLAGS=
88 89
89 EXTRA_DIST = parsedate.y
90
91 BUILT_SOURCES = parsedate.c
92
93 parsedate.c: $(srcdir)/parsedate.y
94 $(YLWRAP) "$(YACC) $(AM_YFLAGS)" $< \
95 y.tab.c parsedate.c y.output parsedate.y.output \
96 -- -yy pd_yy
97 90
98 91
......
1 # Configuration settings for gylwrap.
2 # See ../../mu-aux/gylwrap --help, for details.
3 yyrepl = pd_yy
1 lexer.c 1 lexer.c
2 parser.c 2 parser.c
3 parser.h 3 parser.h
4 parser.output
......
...@@ -20,9 +20,8 @@ noinst_LTLIBRARIES = libcfg.la ...@@ -20,9 +20,8 @@ noinst_LTLIBRARIES = libcfg.la
20 libcfg_la_SOURCES = \ 20 libcfg_la_SOURCES = \
21 driver.c\ 21 driver.c\
22 format.c\ 22 format.c\
23 lexer.c\ 23 lexer.l\
24 parser.c\ 24 parser.y
25 cfg.h
26 25
27 localedir = $(datadir)/locale 26 localedir = $(datadir)/locale
28 AM_CPPFLAGS = \ 27 AM_CPPFLAGS = \
...@@ -30,25 +29,15 @@ AM_CPPFLAGS = \ ...@@ -30,25 +29,15 @@ AM_CPPFLAGS = \
30 -DSYSCONFDIR=\"$(sysconfdir)\"\ 29 -DSYSCONFDIR=\"$(sysconfdir)\"\
31 -DLOCALEDIR=\"$(localedir)\" 30 -DLOCALEDIR=\"$(localedir)\"
32 31
33
34 EXTRA_DIST = \ 32 EXTRA_DIST = \
35 lexer.l\ 33 lexer.l\
36 parser.y\ 34 parser.y\
37 parser.h 35 parser.h\
36 gylwrap.conf
38 37
39 BUILT_SOURCES = parser.c parser.h lexer.c 38 BUILT_SOURCES = parser.c parser.h lexer.c
40 39
41 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap 40 YLWRAP = @MU_YLWRAP@
42 AM_YFLAGS=-vt 41 AM_YFLAGS=-vdt
43 AM_LFLAGS=-dp 42 AM_LFLAGS=-dp
44 43
45 parser.c parser.h: $(srcdir)/parser.y
46 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
47 y.tab.c parser.c y.tab.h parser.h \
48 y.output parser.y.output \
49 -- -yy mu_cfg_yy
50
51 lexer.c: $(srcdir)/lexer.l parser.h
52 $(AM_V_GEN)$(YLWRAP) "$(LEX) $(AM_LFLAGS) $(LFLAGS)" \
53 $(srcdir)/lexer.l lex.yy.c lexer.c \
54 -- -yy mu_cfg_yy
......
1 #include <mailutils/yyloc.h>
1 # Configuration settings for gylwrap.
2 # See ../../mu-aux/gylwrap --help, for details.
3
4 yyrepl = mu_cfg_yy
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
41 #include <mailutils/locus.h> 41 #include <mailutils/locus.h>
42 #include <mailutils/stream.h> 42 #include <mailutils/stream.h>
43 #include <mailutils/stdstream.h> 43 #include <mailutils/stdstream.h>
44 #include "cfg.h" 44 #include <mailutils/yyloc.h>
45 #include "parser.h" 45 #include "parser.h"
46 46
47 void _mu_line_begin (void); 47 void _mu_line_begin (void);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
40 #include <mailutils/stream.h> 40 #include <mailutils/stream.h>
41 #include <mailutils/stdstream.h> 41 #include <mailutils/stdstream.h>
42 #include <mailutils/cidr.h> 42 #include <mailutils/cidr.h>
43 #include "cfg.h" 43 #include <mailutils/yyloc.h>
44 44
45 int mu_cfg_parser_verbose; 45 int mu_cfg_parser_verbose;
46 static mu_list_t /* of mu_cfg_node_t */ parse_node_list; 46 static mu_list_t /* of mu_cfg_node_t */ parse_node_list;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. 16 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 17
18 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap 18 YLWRAP = @MU_YLWRAP@
19 AM_YFLAGS = -dtv 19 AM_YFLAGS = -dtv
20 #AM_LEXFLAGS=-dvp 20 #AM_LEXFLAGS=-dvp
21 AM_CPPFLAGS =\ 21 AM_CPPFLAGS =\
...@@ -39,9 +39,8 @@ libmu_sieve_la_SOURCES = \ ...@@ -39,9 +39,8 @@ libmu_sieve_la_SOURCES = \
39 relational.c\ 39 relational.c\
40 require.c\ 40 require.c\
41 runtime.c\ 41 runtime.c\
42 sieve-gram.c\ 42 sieve-gram.y\
43 sieve-gram.h\ 43 sieve-lex.l\
44 sieve-lex.c\
45 strexp.c\ 44 strexp.c\
46 string.c\ 45 string.c\
47 tests.c\ 46 tests.c\
...@@ -50,24 +49,14 @@ libmu_sieve_la_SOURCES = \ ...@@ -50,24 +49,14 @@ libmu_sieve_la_SOURCES = \
50 libmu_sieve_la_LIBADD = ${MU_LIB_MAILUTILS} @LTDL_LIB@ 49 libmu_sieve_la_LIBADD = ${MU_LIB_MAILUTILS} @LTDL_LIB@
51 libmu_sieve_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@ 50 libmu_sieve_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
52 51
53 noinst_HEADERS = sieve-priv.h 52 noinst_HEADERS = sieve-priv.h sieve-gram.h
54 53
55 BUILT_SOURCES = \ 54 BUILT_SOURCES = \
56 sieve-gram.c sieve-gram.h \ 55 sieve-gram.c sieve-gram.h \
57 sieve-lex.c 56 sieve-lex.c
58 57
59 MAINTAINERCLEANFILES=$(BUILT_SOURCES) 58 EXTRA_DIST=gylwrap.conf
60
61 EXTRA_DIST = sieve.y sieve.l
62 59
63 sieve-lex.c: $(srcdir)/sieve.l sieve-gram.h 60 MAINTAINERCLEANFILES=$(BUILT_SOURCES)
64 $(AM_V_GEN)$(YLWRAP) "$(LEX) $(AM_LEXFLAGS) $(LEXFLAGS)" \
65 $(srcdir)/sieve.l lex.yy.c sieve-lex.c \
66 -- -yy mu_sieve_yy
67
68 sieve-gram.c sieve-gram.h: $(srcdir)/sieve.y
69 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS) $(YFLAGS)" $(srcdir)/sieve.y \
70 y.tab.c sieve-gram.c y.tab.h sieve-gram.h y.output y.output \
71 -- -yy mu_sieve_yy
72 61
73 62
......
1 # Configuration settings for gylwrap.
2 # See ../mu-aux/gylwrap --help, for details.
3
4 yyrepl=mu_sieve_yy
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. 16 ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
17 17
18 YLWRAP = @MU_YLWRAP@
18 AM_YFLAGS=-vt 19 AM_YFLAGS=-vt
19 AM_CPPFLAGS = \ 20 AM_CPPFLAGS = \
20 @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@\ 21 @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@\
......
...@@ -14,8 +14,7 @@ forw ...@@ -14,8 +14,7 @@ forw
14 inc 14 inc
15 install-mh 15 install-mh
16 mark 16 mark
17 mh_alias.h 17 mh_alias_gram.[ch]
18 mh_alias_gram.c
19 mh_alias_lex.c 18 mh_alias_lex.c
20 mh_fmtgram.c 19 mh_fmtgram.c
21 mhl 20 mhl
......
...@@ -68,33 +68,33 @@ noinst_LIBRARIES = libmh.a ...@@ -68,33 +68,33 @@ noinst_LIBRARIES = libmh.a
68 libmh_a_SOURCES= \ 68 libmh_a_SOURCES= \
69 compcommon.c\ 69 compcommon.c\
70 mboxprop.c\ 70 mboxprop.c\
71 mh_alias_gram.c\ 71 mh_alias_gram.y\
72 mh_alias_lex.c\ 72 mh_alias_lex.l\
73 mh_getopt.c\ 73 mh_getopt.c\
74 mh_global.c\ 74 mh_global.c\
75 mh_format.c\ 75 mh_format.c\
76 mh_init.c\ 76 mh_init.c\
77 mh_list.c\ 77 mh_list.c\
78 mh_fmtgram.c\ 78 mh_fmtgram.y\
79 mh_msgset.c\ 79 mh_msgset.c\
80 mh_sequence.c\ 80 mh_sequence.c\
81 mh_stream.c\ 81 mh_stream.c\
82 mh_whatnow.c\ 82 mh_whatnow.c\
83 mh_whom.c\ 83 mh_whom.c\
84 whatnowenv.c 84 whatnowenv.c
85 noinst_HEADERS = mh.h mh_alias.h mh_format.h mh_getopt.h 85 noinst_HEADERS = mh.h mh_alias_gram.h mh_format.h mh_getopt.h
86 86
87 BUILT_SOURCES= \ 87 BUILT_SOURCES=\
88 mh_fmtgram.c \ 88 mh_fmtgram.c\
89 pick-gram.c \ 89 pick-gram.c\
90 pick-gram.h \ 90 pick-gram.h\
91 mh_alias_gram.c \ 91 mh_alias_gram.c\
92 mh_alias_lex.c \ 92 mh_alias_gram.h\
93 mh_alias.h 93 mh_alias_lex.c
94 94
95 MAINTAINERCLEANFILES=$(BUILT_SOURCES) 95 MAINTAINERCLEANFILES=$(BUILT_SOURCES)
96 96
97 EXTRA_DIST = mh_fmtgram.y pick.y mh_alias.y mh_alias.l 97 EXTRA_DIST = gylwrap.conf
98 98
99 mhlibdir = $(pkgdatadir)/mh 99 mhlibdir = $(pkgdatadir)/mh
100 100
...@@ -119,9 +119,9 @@ mh_LIBS = \ ...@@ -119,9 +119,9 @@ mh_LIBS = \
119 @MU_COMMON_LIBRARIES@ 119 @MU_COMMON_LIBRARIES@
120 LDADD = $(mh_LIBS) 120 LDADD = $(mh_LIBS)
121 scan_LDADD = $(mh_LIBS) @CURSES_LIBS@ 121 scan_LDADD = $(mh_LIBS) @CURSES_LIBS@
122 pick_SOURCES = pick.c pick.h pick-gram.c pick-gram.h 122 pick_SOURCES = pick.c pick.h pick-gram.y pick-gram.h
123 123
124 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap 124 YLWRAP = @MU_YLWRAP@
125 AM_YFLAGS=-vt 125 AM_YFLAGS=-vt
126 126
127 inc_LDADD = \ 127 inc_LDADD = \
...@@ -144,29 +144,6 @@ inc_LDADD = \ ...@@ -144,29 +144,6 @@ inc_LDADD = \
144 ${MU_LIB_MAILUTILS}\ 144 ${MU_LIB_MAILUTILS}\
145 @MU_COMMON_LIBRARIES@ 145 @MU_COMMON_LIBRARIES@
146 146
147
148 pick-gram.c pick-gram.h: $(srcdir)/pick.y
149 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
150 y.tab.c pick-gram.c y.tab.h pick-gram.h \
151 y.output pick.output \
152 -- -yy pick_yy
153
154 mh_fmtgram.c: $(srcdir)/mh_fmtgram.y
155 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS)" $< \
156 y.tab.c mh_fmtgram.c y.output fmtgram.y.output \
157 -- -yy fmt_yy
158
159 mh_alias_gram.c mh_alias.h: $(srcdir)/mh_alias.y
160 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
161 y.tab.c mh_alias_gram.c y.tab.h mh_alias.h \
162 y.output mh_alias.output \
163 -- -yy ali_yy
164
165 mh_alias_lex.c: $(srcdir)/mh_alias.l mh_alias.h
166 $(AM_V_GEN)$(YLWRAP) "$(LEX) $(AM_LEXFLAGS) $(LEXFLAGS)" \
167 $(srcdir)/mh_alias.l lex.yy.c mh_alias_lex.c \
168 -- -yy ali_yy
169
170 install-exec-hook: 147 install-exec-hook:
171 @here=`pwd`; \ 148 @here=`pwd`; \
172 cd $(DESTDIR)$(bindir); \ 149 cd $(DESTDIR)$(bindir); \
......
1 # Configuration settings for gylwrap.
2 # See ../mu-aux/gylwrap --help, for details.
3
4 [pick-gram.y]
5 yyrepl = pick_yy
6 flags = -d
7 [mh_fmtgram.y]
8 yyrepl = fmt_yy
9 [mh_alias_gram.y]
10 yyrepl = ali_yy
11 flags = -d
12 [mh_alias_lex.l]
13 yyrepl = ali_yy
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
23 23
24 %{ 24 %{
25 #include <mh.h> 25 #include <mh.h>
26 #include <mh_alias.h> 26 #include <mh_alias_gram.h>
27 #include <sys/stat.h> 27 #include <sys/stat.h>
28 #include <mailutils/cctype.h> 28 #include <mailutils/cctype.h>
29 #include <mailutils/io.h> 29 #include <mailutils/io.h>
......
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
3 .libs 3 .libs
4 Makefile 4 Makefile
5 Makefile.in 5 Makefile.in
6 lex.yy.c 6 grammar.c
7 mimetypes-decl.h 7 grammar.h
8 mimetypes-gram.c 8 grammar.output
9 mimetypes-lex.c 9 lexer.c
10 mimetypes.output
11 mimeview 10 mimeview
12 y.output
13 y.tab.c
......
...@@ -25,28 +25,15 @@ AM_CPPFLAGS = \ ...@@ -25,28 +25,15 @@ AM_CPPFLAGS = \
25 bin_PROGRAMS = mimeview 25 bin_PROGRAMS = mimeview
26 mimeview_SOURCES = \ 26 mimeview_SOURCES = \
27 mimeview.c \ 27 mimeview.c \
28 mimetypes-gram.c \ 28 grammar.y \
29 mimetypes-lex.c \ 29 lexer.l \
30 mimetypes-decl.h \ 30 mimeview.h\
31 mimeview.h 31 grammar.h
32 32
33 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap 33 YLWRAP = @MU_YLWRAP@
34 AM_YFLAGS=-vt 34 AM_YFLAGS=-vtd
35 AM_LEXFLAGS=-d 35 AM_LEXFLAGS=-d
36 EXTRA_DIST = mimetypes.y mimetypes.l 36 EXTRA_DIST = gylwrap.conf
37
38 mimetypes-gram.c mimetypes-decl.h: $(srcdir)/mimetypes.y
39 $(AM_V_GEN)$(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
40 y.tab.c mimetypes-gram.c y.tab.h mimetypes-decl.h \
41 y.output mimetypes.output \
42 -- -yy mimetypes_yy
43
44 mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
45 $(AM_V_GEN)$(YLWRAP) "$(LEX) $(AM_LEXFLAGS) $(LEXFLAGS)" \
46 $(srcdir)/mimetypes.l lex.yy.c mimetypes-lex.c \
47 -- -yy mimetypes_yy
48
49 BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
50 37
51 mimeview_LDADD = \ 38 mimeview_LDADD = \
52 ${MU_APP_LIBRARIES}\ 39 ${MU_APP_LIBRARIES}\
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 22
23 #include <mailutils/cctype.h> 23 #include <mailutils/cctype.h>
24 #include <mimeview.h> 24 #include <mimeview.h>
25 #include <mimetypes-decl.h> 25 #include <grammar.h>
26 #include <regex.h> 26 #include <regex.h>
27 27
28 static void 28 static void
......
1 # Configuration settings for gylwrap.
2 # See ../mu-aux/gylwrap --help, for details.
3 yyrepl = mimetypes_yy
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
26 #include <stdio.h> 26 #include <stdio.h>
27 #include <sys/stat.h> 27 #include <sys/stat.h>
28 #include <mimeview.h> 28 #include <mimeview.h>
29 #include <mimetypes-decl.h> 29 #include <grammar.h>
30 #include <mailutils/io.h> 30 #include <mailutils/io.h>
31 31
32 static mu_linetrack_t trk; 32 static mu_linetrack_t trk;
......
1 #! /bin/sh 1 eval '(exit $?0)' && eval 'exec perl -wS "$0" "$@"'
2 # ylwrap - wrapper for lex/yacc invocations. 2 & eval 'exec perl -wS "$0" $argv:q'
3 # Copyright 1996-1999, 2007, 2010-2012, 2014-2017 Free Software 3 if 0;
4 # Foundation, Inc. 4
5 # Written by Tom Tromey <tromey@cygnus.com>. 5 use strict;
6 # 6 use warnings;
7 # This program is free software; you can redistribute it and/or modify 7 use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order auto_version);
8 # it under the terms of the GNU General Public License as published by 8 use File::Basename;
9 # the Free Software Foundation; either version 3, or (at your option) 9 use File::Temp qw(tempdir);
10 # any later version. 10 use Pod::Man;
11 # 11 use Pod::Usage;
12 # This program is distributed in the hope that it will be useful, 12 use Cwd 'abs_path';
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 use List::Regexp;
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14
15 # GNU General Public License for more details. 15 =head1 NAME
16 # 16
17 # You should have received a copy of the GNU General Public License 17 gylwrap - wrapper for yacc, lex and similar programs
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18
19 19 =head1 SYNOPSIS
20 # Usage: 20
21 # ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [-yy repl] [ARGS]... 21 B<gylwrap>
22 # * PROGRAM is program to run; options can follow but must start with `-'. 22 [B<-c?>]
23 # * INPUT is the input file 23 [B<--compatibility>]
24 # * OUTPUT is file PROG generates 24 [B<--yyrepl=>I<PREFIX>]
25 # * DESIRED is file we actually want 25 [B<--yysym=>I<STRING>]
26 # * ARGS are passed to PROG 26 [B<--stdout>]
27 # * Optional -yy introduces the sequence to replace yy prefixes with. 27 [B<--help>]
28 # Any number of OUTPUT,DESIRED pairs may be used. 28 [B<--version>]
29 29 I<COMMAND>
30 # The program to run. 30 I<INPUT>
31 prog="$1" 31 I<OUTPUT> I<DESIRED>...
32 shift 32
33 # Make any relative path in $prog absolute. 33 B<ylwrap>
34 case "$prog" in 34 [B<-?>]
35 /* | [A-Za-z]:*) ;; 35 [B<--yyrepl=>I<PREFIX>]
36 */*) prog="`pwd`/$prog" ;; 36 [B<--yysym=>I<STRING>]
37 esac 37 [B<--stdout>]
38 38 [B<--help>]
39 # We also have to accept options here and append them to the program. 39 [B<--version>]
40 # Why? Suppose YACC is set to `bison -y'. Clearly nobody uses 40 I<INPUT>
41 # ylwrap, or this would have been discovered earlier! 41 [I<OUTPUT> I<DESIRED>]...
42 while :; do 42 B<--> I<PROGRAM> [I<ARGS>]
43 case "$1" in 43
44 -*) 44 =head1 DESCRIPTION
45 prog="$prog $1" 45
46 shift 46 Wraps B<lex> and B<yacc> invocations to rename their output files.
47 ;; 47 It also ensures that multiple I<COMMAND> instances can be invoked
48 *) 48 in a single directory in parallel and allows for renaming global
49 break 49 symbols to avoid clashes when multiple parsers and/or lexers are
50 ;; 50 linked in a single executable.
51 esac 51
52 done 52 To achieve this, B<gylwrap> creates a temporary directory, changes
53 53 to it, and runs I<COMMAND> (which may contain arguments and options)
54 # The input. 54 with I<INPUT> as its last argument. Upon successful exit, it processes
55 input="$1" 55 the I<OUTPUT> I<DESIRED> pairs. Each I<OUTPUT> file is then renamed
56 shift 56 to the file I<DESIRED>, taking care to fix up any eventual B<#line>
57 case "$input" in 57 directives.
58 /* | [A-Za-z]:*) 58
59 # Absolute path; do nothing. 59 If B<--yyrepl=I<PREFIX>> is given, the global symbols that can cause
60 ;; 60 name clashes are renamed by replacing the initial B<yy> with I<PREFIX>.
61 *) 61 For a list of symbols that are subject for replacement, inspect the
62 # Relative path. Make it absolute. 62 B<@sym> variable at the start of the script. Additional names can be
63 input="`pwd`/$input" 63 added to this list using the B<--yysym> option.
64 ;; 64
65 esac 65 If given the B<--compatibility> option or if invoked as B<ylwrap>,
66 66 the tool runs in compatibility mode, mimicking the behavior of the
67 # The directory holding the input. 67 standard B<ylwrap> utility from GNU Automake. Command line arguments
68 input_dir="`echo $input | sed -e 's,/[^/]*$,,'`" 68 consist of two lists, separated by B<-->. The left-hand side list
69 # Quote $INPUT_DIR so we can use it in a regexp. 69 supplies the I<OUTPUT>,I<DESIRED> pairs, and the right-hand side one
70 # FIXME: really we should care about more than `.'. 70 supplies the command and its arguments.
71 input_rx="`echo $input_dir | sed -e 's,\.,\\\.,g'`" 71
72 72 In both modes, prior to running the command, the program looks for file
73 pairlist= 73 B<gylwrap.conf> in the same directory as the I<INPUT> file. If found,
74 defout=$1 74 the file is sourced. Empty lines and comments (introduced by the hash
75 while test "$#" -ne 0; do 75 sign) are ignored. Rest of lines are either option assignements, or
76 if test "$1" = "--"; then 76 section headings.
77 shift 77
78 break 78 Option assignements have the form B<I<OPTION> = I<VALUE>>, and generally,
79 fi 79 have the same meaning as the corresponding command line option without
80 pairlist="$pairlist $1" 80 the leading two dashes:
81 shift 81
82 done 82 =over 4
83 83
84 STDOUT="" 84 =item B<yyrepl => I<PREFIX>
85 if [ $# -ne 0 ]; then 85
86 while test "$#" -ne 0; do 86 Replace the B<yy> prefix with I<PREFIX> in the identifiers.
87 case "x$1" in 87
88 x-yy) 88 =item B<stdout = 1>
89 shift 89
90 if [ $# -eq 0 ]; then 90 Enable the B<--stdout> option.
91 echo "ylwrap: -yy requires an argument" 91
92 exit 1 92 =item B<yysym => I<NAME>
93 fi 93
94 YYREPL=$1 94 Add I<NAME> to the list of symbols suitable for prefix replacement.
95 shift;; 95 This keyword can appear multiple times.
96 x-stdout) 96
97 shift 97 =item B<flags => I<STRING>
98 STDOUT=$defout 98
99 ;; 99 Add I<STRING> to the invocation of I<COMMAND>. This is useful, if you
100 *) 100 have several parsers in the same directory, and some of them require
101 break;; 101 the B<-d> option, while others don't.
102 esac 102
103 done 103 =back
104 fi 104
105 105 Section headers have the form B<[I<FILE>]>. The settings under a
106 # FIXME: add hostname here for parallel makes that run commands on 106 section header have effect only if I<FILE> is the same as the I<INPUT>
107 # other machines. But that might take us over the 14-char limit. 107 command line argument.
108 dirname=ylwrap$$ 108
109 trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 109 =head1 OPTIONS
110 mkdir $dirname || exit 1 110
111 111 =over 4
112 cd $dirname 112
113 113 =item B<-c>, B<--compatibility>
114 if [ -n "$STDOUT" ]; then 114
115 $prog ${1+"$@"} "$input" > $STDOUT 115 Run in compatibility mode.
116 else 116
117 $prog ${1+"$@"} "$input" 117 =item B<--stdout>
118 fi 118
119 status=$? 119 Redirect I<COMMAND>'s standard output to the first I<OUTPUT>.
120 120
121 if test $status -eq 0; then 121 =item B<--yyrepl=>I<PREFIX>
122 set X $pairlist 122
123 shift 123 Replace the B<yy> prefix in global symbols with I<PREFIX>.
124 first=yes 124
125 # Since DOS filename conventions don't allow two dots, 125 =item B<--yysym=>I<SYMBOL>
126 # the DOS version of Bison writes out y_tab.c instead of y.tab.c 126
127 # and y_tab.h instead of y.tab.h. Test to see if this is the case. 127 Add I<SYMBOL> to the list of symbols subject for replacement.
128 y_tab_nodot="no" 128
129 if test -f y_tab.c || test -f y_tab.h; then 129 =item B<-?>, B<--help>
130 y_tab_nodot="yes" 130
131 fi 131 Displays help text and exit
132 132
133 while test "$#" -ne 0; do 133 =item B<--version>
134 from="$1" 134
135 # Handle y_tab.c and y_tab.h output by DOS 135 Displays program version and exits.
136 if test $y_tab_nodot = "yes"; then 136
137 if test $from = "y.tab.c"; then 137 =back
138 from="y_tab.c" 138
139 else 139 =head1 NOTE
140 if test $from = "y.tab.h"; then 140
141 from="y_tab.h" 141 This script is an improved version of the B<ylwrap> script, included
142 fi 142 in the GNU Automake distribution.
143 fi 143
144 fi 144 =cut
145 if test -f "$from"; then 145
146 # If $2 is an absolute path name, then just use that, 146 # List of symbols suitable for prefix replacements. See the
147 # otherwise prepend `../'. 147 # options --yyrepl and --yysym, and similar statements in the configuration
148 case "$2" in 148 # file.
149 /* | [A-Za-z]:*) target="$2";; 149 my @yysym = qw(
150 *) target="../$2";; 150 yymaxdepth
151 esac 151 yyparse
152 152 yylex
153 # Edit out `#line' or `#' directives. We don't want the 153 yyerror
154 # resulting debug information to point at an absolute srcdir; 154 yylval
155 # it is better for it to just mention the .y file with no 155 yychar
156 # path. 156 yydebug
157 T=`basename $target` 157 yypact
158 EXPR="/^#/ s,$input_rx/,,;s,\"$from\",\"$T\"," 158 yyr1
159 if [ ! -z "$YYREPL" ]; then 159 yyr2
160 EXPR="$EXPR;s/yy/$YYREPL/g" 160 yydef
161 fi 161 yychk
162 sed -e "$EXPR" "$from" > "$target" || status=$? 162 yypgo
163 else 163 yyact
164 # A missing file is only an error for the first file. This 164 yyexca
165 # is a blatant hack to let us support using "yacc -d". If -d 165 yyerrflag
166 # is not specified, we don't want an error when the header 166 yynerrs
167 # file is "missing". 167 yyps
168 if test $first = yes; then 168 yypv
169 status=1 169 yys
170 fi 170 yy_yys
171 fi 171 yystate
172 shift 172 yytmp
173 shift 173 yyv
174 first=no 174 yy_yyv
175 done 175 yyval
176 else 176 yylloc
177 status=$? 177 yyreds
178 fi 178 yytoks
179 179 yylhs
180 # Remove the directory. 180 yylen
181 cd .. 181 yydefred
182 rm -rf $dirname 182 yydgoto
183 183 yysindex
184 exit $status 184 yyrindex
185 yygindex
186 yytable
187 yycheck
188 yyname
189 yyrule
190 );
191
192 our $VERSION = '1.00';
193
194 # If prefix replacement is requested, the list above is assembled into
195 # a single regular expression, stored here.
196 my $yyrx;
197
198 # String to replace the "yy" prefix with.
199 my $yyrepl;
200
201 # If set, redirect the stdout from the command to the first output file.
202 my $stdout;
203
204 # Input directory with special characters escaped, for "#line" directive
205 # fixup.
206 my $input_rx;
207
208 # Configuration settings from the "gylwrap.conf" file. Indexed by
209 # input file name. Default entry is ''.
210 my %config;
211
212 # Name of the first output file. This is used in compatibility mode to
213 # avoid bailing out if one of the output files (except the principal one)
214 # does not exist.
215 my $parser;
216
217 # Name this program was invoked as.
218 my $progname = basename($0);
219 my $compat = $progname eq 'ylwrap'; # True if running in compatibility mode
220
221 # List of files created during the run, for cleanup purposes.
222 my @created;
223
224 sub filter {
225 my ($from, $to) = @_;
226 my $target = basename($to);
227 my $ifd;
228 unless (open($ifd, '<', $from)) {
229 if ($compat) {
230 return if $from ne $parser;
231 }
232 die "can't open input file $from: $!";
233 }
234 open(my $ofd, '>', $to)
235 or die "can't open output file $to: $!";
236 push @created, $to;
237 while (<$ifd>) {
238 if (/^#/) {
239 s{$input_rx/}{};
240 s{"$from"}{"$target"};
241 }
242 if ($yyrx) {
243 s{\byy($yyrx)\b}{${yyrepl}$1}g;
244 }
245 print $ofd $_
246 }
247 close $ifd;
248 close $ofd;
249 }
250
251 sub readconf {
252 my $file = shift;
253 open(my $fd, '<', $file)
254 or die "can't open $file: $!";
255 my $key = '';
256 while (<$fd>) {
257 chomp;
258 s/^\s+//;
259 if (/^#/ || /^$/) {
260 next;
261 } elsif (/^\[(.+)\]/) {
262 $key = $1;
263 } elsif (m/(.+?)\s*=\s*(.+)$/) {
264 if ($1 eq 'yysym') {
265 push @{$config{$key}{$1}}, $2;
266 } else {
267 $config{$key}{$1} = $2;
268 }
269 } else {
270 print STDERR "$file:$.: unrecognized line\n";
271 }
272 }
273 close($fd);
274 }
275
276 my ($command, $input, @output);
277
278 GetOptions("yyrepl=s" => \$yyrepl,
279 "yysym=s@" => \@yysym,
280 "stdout" => \$stdout,
281 "compatibility|c" => \$compat,
282 "help|?" => sub {
283 pod2usage(-exitstatus => 0, -verbose => 2);
284 }
285 ) or exit(1);
286
287 if ($compat) {
288 $input = shift @ARGV;
289 while (my $arg = shift @ARGV) {
290 last if ($arg eq '--');
291 push @output, $arg;
292 }
293 $command = join(' ', @ARGV);
294 } else {
295 pod2usage(-exitstatus => 1, -verbose => 0, -output => \*STDERR)
296 unless @ARGV >= 2;
297 ($command, $input, @output) = @ARGV;
298 }
299
300 pod2usage(-exitstatus => 1, -verbose => 0, -output => \*STDERR)
301 unless (@output && (@output % 2) == 0);
302
303 # Make sure input file name is absolute
304 $input = abs_path($input);
305
306 my $input_dir = dirname($input);
307 $input_rx = qr($input_dir);
308
309 my $confile = "$input_dir/gylwrap.conf";
310 readconf($confile) if -r $confile;
311
312 my $input_base = basename($input);
313 unless ($stdout) {
314 $stdout = $config{$input_base}{stdout} || $config{''}{stdout};
315 }
316 unless ($yyrepl) {
317 $yyrepl = $config{$input_base}{yyrepl} || $config{''}{yyrepl};
318 }
319 if ($yyrepl) {
320 push @yysym, @{$config{$input_base}{yysym}}
321 if exists $config{$input_base}{yysym};
322 push @yysym, @{$config{''}{yysym}}
323 if exists $config{''}{yysym};
324 if ($yyrepl) {
325 $yyrx = regexp_opt({ type => 'pcre' }, map { s/^yy//; $_ } @yysym);
326 }
327 }
328
329 my $prog = $command;
330 $prog =~ s/\s.*$//;
331
332 if (my $flags = $config{$input_base}{flags} || $config{''}{flags}) {
333 $command .= ' ' . $flags;
334 }
335
336 $parser = $output[0];
337
338 $command .= ' '.$input;
339 if ($stdout) {
340 $command .= '>'.$parser;
341 }
342
343 # Create working directory
344 my $wd = tempdir("ylXXXXXX", DIR => '.', CLEANUP => 1)
345 or die "cannot create temporary directory";
346 chdir $wd
347 or die "cannot change to the temporary directory";
348 END {
349 if ($?) {
350 unlink @created;
351 }
352 chdir "..";
353 }
354
355 system($command);
356 if ($? == -1) {
357 print STDERR "$prog: $!\n";
358 exit(127);
359 } elsif ($? & 127) {
360 print STDERR "$prog died with signal ".($? & 127)."\n";
361 exit(127);
362 } else {
363 my $code = $? >> 8;
364 exit($code) if $code;
365 }
366
367 while (my $from = shift @output) {
368 my $to = shift @output;
369 $to = '../' . $to unless $to =~ m{^/};
370 filter($from, $to);
371 }
372
373 exit 0;
374
375
376
......
...@@ -43,8 +43,8 @@ libmu_sieve/prog.c ...@@ -43,8 +43,8 @@ libmu_sieve/prog.c
43 libmu_sieve/relational.c 43 libmu_sieve/relational.c
44 libmu_sieve/require.c 44 libmu_sieve/require.c
45 libmu_sieve/runtime.c 45 libmu_sieve/runtime.c
46 libmu_sieve/sieve.l 46 libmu_sieve/sieve-lex.l
47 libmu_sieve/sieve.y 47 libmu_sieve/sieve-gram.y
48 libmu_sieve/tests.c 48 libmu_sieve/tests.c
49 libmu_sieve/util.c 49 libmu_sieve/util.c
50 libmu_sieve/variables.c 50 libmu_sieve/variables.c
...@@ -174,8 +174,8 @@ mh/send.c ...@@ -174,8 +174,8 @@ mh/send.c
174 mh/whatnow.c 174 mh/whatnow.c
175 mh/whom.c 175 mh/whom.c
176 176
177 mimeview/mimetypes.l 177 mimeview/lexer.l
178 mimeview/mimetypes.y 178 mimeview/grammar.y
179 mimeview/mimeview.c 179 mimeview/mimeview.c
180 180
181 movemail/movemail.c 181 movemail/movemail.c
......