preproc.c: BISONFLAGS += -d
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
- $(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
- $(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
+ $(PERL) $(srcdir)/parse.pl --srcdir $(srcdir) --parser $< --output $@
+ $(PERL) $(srcdir)/check_rules.pl --srcdir $(srcdir) --parser $<
# generate keyword headers
c_kwlist_d.h: c_kwlist.h $(GEN_KEYWORDLIST_DEPS)
use strict;
use warnings;
no warnings 'uninitialized';
+use Getopt::Long;
+my $srcdir = '.';
+my $parser = '../../../backend/parser/gram.y';
+my $stamp = '';
my $verbose = 0;
-if ($ARGV[0] eq '-v')
-{
- $verbose = shift;
-}
-my $path = shift || '.';
-my $parser = shift || '../../../backend/parser/gram.y';
-my $filename = $path . "/ecpg.addons";
+GetOptions(
+ 'srcdir=s' => \$srcdir,
+ 'parser=s' => \$parser,
+ 'stamp=s' => \$stamp,
+ 'verbose' => \$verbose,) or die "wrong arguments";
+
+my $filename = "$srcdir/ecpg.addons";
if ($verbose)
{
print "parser: $parser\n";
print "$cc rules checked\n";
}
+if ($stamp)
+{
+ open my $stampfh, '>', $stamp or die $!;
+ close $stampfh;
+}
+
exit $ret;
use strict;
use warnings;
no warnings 'uninitialized';
+use Getopt::Long;
-my $path = shift @ARGV;
-$path = "." unless $path;
+my $srcdir = '.';
+my $outfile = '';
+my $parser = '';
+
+GetOptions(
+ 'srcdir=s' => \$srcdir,
+ 'output=s' => \$outfile,
+ 'parser=s' => \$parser,) or die "wrong arguments";
+
+# open parser / output file early, to raise errors early
+open(our $parserfh, '<', $parser) or die "could not open parser file $parser";
+open(our $outfh, '>', $outfile) or die "could not open output file $outfile";
my $copymode = 0;
my $brace_indent = 0;
dump_buffer('types');
dump_buffer('ecpgtype');
dump_buffer('orig_tokens');
-print '%%', "\n";
-print 'prog: statements;', "\n";
+print $outfh '%%', "\n";
+print $outfh 'prog: statements;', "\n";
dump_buffer('rules');
include_file('trailer', 'ecpg.trailer');
dump_buffer('trailer');
+close($parserfh);
+
sub main
{
- line: while (<>)
+ line: while (<$parserfh>)
{
if (/ERRCODE_FEATURE_NOT_SUPPORTED/)
{
sub include_file
{
my ($buffer, $filename) = @_;
- my $full = "$path/$filename";
+ my $full = "$srcdir/$filename";
open(my $fh, '<', $full) or die;
while (<$fh>)
{
sub dump_buffer
{
my ($buffer) = @_;
- print '/* ', $buffer, ' */', "\n";
+ print $outfh '/* ', $buffer, ' */', "\n";
my $ref = $buff{$buffer};
- print @$ref;
+ print $outfh @$ref;
return;
}
sub preload_addons
{
- my $filename = $path . "/ecpg.addons";
+ my $filename = $srcdir . "/ecpg.addons";
open(my $fh, '<', $filename) or die;
# there may be multiple lines starting ECPG: and then multiple lines of code.
'src/backend/parser/gram.y'))
{
print "Generating preproc.y...\n";
- chdir('src/interfaces/ecpg/preproc');
- system('perl parse.pl < ../../../backend/parser/gram.y > preproc.y');
- chdir('../../../..');
+ my $ecpg = 'src/interfaces/ecpg';
+ system("perl $ecpg/preproc/parse.pl --srcdir $ecpg/preproc --parser src/backend/parser/gram.y --output $ecpg/preproc/preproc.y");
}
unless (-f "src/port/pg_config_paths.h")