Author: paul
Date: 2005-12-02 18:15:14 +0100 (Fri, 02 Dec 2005)
New Revision: 476
Log:
r4392@frost: paul | 2005-12-02 11:13:54 -0600
Implement "raw" output (one reserved word per line).
Modified:
trunk/
trunk/tools/update-reserved-words.pl
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:4378
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:1346
+ b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:4392
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:1346
Modified: trunk/tools/update-reserved-words.pl
===================================================================
--- trunk/tools/update-reserved-words.pl 2005-12-02 14:18:10 UTC (rev 475)
+++ trunk/tools/update-reserved-words.pl 2005-12-02 17:15:14 UTC (rev 476)
@@ -1,4 +1,5 @@
#!/usr/bin/perl
+# vim:set ts=2 sw=2 expandtab:
# Based on a Emacs macro by david@stripped
# Implemented in Perl by jeremy@stripped
@@ -23,6 +24,12 @@
# - For sql_yacc.yy in 5.0 and up, keyword: definition includes keyword_sp.
# Treat the words in keyword_sp: list the same as those in the keyword:
# list (not reserved).
+# 2005-12-02
+# - Implement --raw option for raw output format (one reserved word per
+# line, no formatting).
+# - Implement --verbose option and print all the extra "noise" output
+# only if that option is specified.
+# - Add GetOpt machinery now that we have more than one option.
# Method of operation:
@@ -56,64 +63,109 @@
# define the set of reserved words.
use strict;
+use Getopt::Long;
+$Getopt::Long::ignorecase = 0; # options are case sensitive
+$Getopt::Long::bundling = 1; # allow short options to be bundled
-my $format = "texi";
+my $usage = <<EOF;
+This script looks through the server Lex/Yacc files to determine
+which keywords are reserved. The required argument indicates the
+root directory of the relevant BitKeeper source tree. For historical
+reasons, the default output format is Texinfo. Normally, you should
+use --xml or --raw to produce XML or raw output.
-if (@ARGV && $ARGV[0] eq "--xml")
+Usage: $0 [options] path_to_bk_source_root
+
+Options:
+--help, -h
+ Print this message
+--debug, -d
+ Enable debug output
+--raw, -R
+ Generate "raw" output (one reserved word per line)
+--verbose
+ Print extra information to STDERR
+--xml, -X
+ Generate XML output
+EOF
+
+# Variables for command line options; most are undefined initially.
+my $help;
+my $debug;
+my $verbose;
+my $raw_format;
+my $xml_format;
+
+GetOptions (
+ # =i means an integer argument is required after the option
+ # =s means a string argument is required after the option
+ # :s means a string argument is optional after the option
+ "help|h" => \$help, # print help message
+ "debug|d" => \$debug, # generate debug output
+ "raw|R" => \$raw_format, # generate raw output
+ "verbose", => \$verbose,
+ "xml|X" => \$xml_format, # generate XML output
+) or die "$usage\n";
+
+if (defined $help)
{
- $format = "xml";
- shift @ARGV;
+ print "$usage\n";
+ exit (0);
}
-my $argc = $#ARGV + 1;
-if ($argc < 1) {
- print "Usage: $0 [--xml] <path_to_source_bk_root>\n";
- exit;
-}
+my $format = "texi";
+die "You cannot specify both --raw and --xml\n" if $raw_format && $xml_format;
+
+$format = "raw" if $raw_format;
+$format = "xml" if $xml_format;
+
+die "$usage\n" unless @ARGV == 1;
+
my $sourcepath = shift(@ARGV)."/";
$sourcepath =~ s/\/\//\//;
my $lexfile = $sourcepath."sql/lex.h";
if (!-e $lexfile) {
- print "$0: Can't find $lexfile\n";
- exit;
+ die "$0: Can't find $lexfile\n";
}
my $yaccfile = $sourcepath."sql/sql_yacc.yy";
if (!-e $yaccfile) {
- print "$0: Can't find $yaccfile\n";
- exit;
+ die "$0: Can't find $yaccfile\n";
}
my $configurefile = $sourcepath."configure.in";
if (!-e $configurefile) {
- print "$0: Can't find $configurefile\n";
- exit;
+ die "$0: Can't find $configurefile\n";
}
my $changesetfile = $sourcepath."ChangeSet";
if (!-e $changesetfile) {
- print "$0: Can't find $changesetfile\n";
- exit;
+ die "$0: Can't find $changesetfile\n";
}
-print STDERR "Fetching MySQL version number from source tree...\n";
+print STDERR "Fetching MySQL version number from source tree...\n"
+ if $verbose;
my $mysqlversion = join "", `grep "AM_INIT_AUTOMAKE(" $configurefile`;
$mysqlversion =~ s/AM_INIT_AUTOMAKE\(mysql, (.+?)\).*/$1/s;
-print STDERR "Using MySQL version $mysqlversion\n";
+print STDERR "Using MySQL version $mysqlversion\n"
+ if $verbose;
-#print STDERR "Fetching BK changeset/date from source tree...\n";
+#print STDERR "Fetching BK changeset/date from source tree...\n"
+# if $verbose;
#my $bkchangeset = `bk -R prs -r+ -h -d'ChangeSet :I: (:D: :T:)' $changesetfile`;
-#print STDERR "BitKeeper reports: $bkchangeset\n";
+#print STDERR "BitKeeper reports: $bkchangeset\n"
+# if $verbose;
-my %words; # hash of keyword token -> keyword string mappings
-my @words; # list of keyword strings
+my %words; # hash of keyword token -> keyword string mappings
+my @words; # list of keyword strings
my $line;
-print STDERR "Scanning $lexfile for symbols..\n";
+print STDERR "Scanning $lexfile for symbols..\n"
+ if $verbose;
open LEX, "<$lexfile" or die "Cannot open $lexfile: $!\n";
while(<LEX>) {
# Identify lines that have keyword string and keyword token.
@@ -131,7 +183,8 @@
# In 5.0 and up, this production also includes the keyword_sp: production,
# so look for them both.
-print STDERR "Scanning $yaccfile for non-reserved words...\n";
+print STDERR "Scanning $yaccfile for non-reserved words...\n"
+ if $verbose;
open YACC, "<$yaccfile" or die "Cannot open $yaccfile: $!\n";
while(defined ($_ = <YACC>) && $_ !~ /^keyword:/) {};
while(<YACC>) {
@@ -146,10 +199,12 @@
close YACC;
-print STDERR "Copying reserved words to an array...\n";
+print STDERR "Copying reserved words to an array...\n"
+ if $verbose;
foreach(keys %words) { push @words, @{$words{$_}}; };
-print STDERR "Sorting array...\n";
+print STDERR "Sorting array...\n"
+ if $verbose;
@words = sort @words;
@@ -157,7 +212,8 @@
my $i;
my $word;
-printf STDERR "There are %i reserved words.\n", scalar @words;
+printf STDERR "There are %i reserved words.\n", scalar @words
+ if $verbose;
if ($format eq "texi")
{
@@ -172,7 +228,7 @@
$list .= sprintf "%s\n", $pre[$i%3];
}
}
-else
+if ($format eq "xml")
{
$list = "<informaltable><tgroup cols='2'>\n";
$list .= "<colspec colwidth='33*'/>\n" x 3;
@@ -192,7 +248,8 @@
}
-print STDERR "Creating new list of reserved words...\n";
+print STDERR "Creating new list of reserved words...\n"
+ if $verbose;
if ($format eq "texi")
@@ -212,7 +269,7 @@
print "\@end multitable\n";
print "\n\@c END_OF_RESERVED_WORDS\n";
}
-else
+if ($format eq "xml")
{
print <<EOF;
<?xml version="1.0" encoding="utf-8"?>
@@ -230,11 +287,19 @@
print $list;
print "<!-- END_OF_RESERVED_WORDS -->\n";
}
+if ($format eq "raw")
+{
+ foreach my $word (@words)
+ {
+ print $word, "\n";
+ }
+}
-print STDERR "Reserved word list updated successfully!\n";
+print STDERR "Reserved word list updated successfully!\n"
+ if $verbose;
-exit;
+exit (0);
sub pretty_date {
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r476 - in trunk: . tools | paul | 2 Dec |