diff options
author | unknown <zak@linux.local> | 2002-02-27 04:35:26 -0700 |
---|---|---|
committer | unknown <zak@linux.local> | 2002-02-27 04:35:26 -0700 |
commit | 633d54b67e577ea1ac1cf845f1367c2d9e7f06d1 (patch) | |
tree | 64eef9cf277016757225b20889b9c63fc31bf6fb /Docs/Support/docbook-split | |
parent | e82914796d6ae684a89a377e8a42f651b6c0e4d7 (diff) | |
download | mariadb-git-633d54b67e577ea1ac1cf845f1367c2d9e7f06d1.tar.gz |
Nice, relaxing Perl munging. :) Have another change to put into this
changeset - afaik, I can edit changesets with bk. So, rather than wait, I will
commit this now, finish up the other code, try to alter the changeset and then
push all the changes up.
Docs/Support/docbook-fixup.pl:
Rewrote to use a more native Perl style.
Increase strictness of error checking.
Simplified and optimized regular expressions.
Fixed several problems with conversion. Still have some minor issues to sort out.
Rewrote to accept input from stdin or from filename arg(s) on the command line.
Improved speed ~6x.
Docs/Support/docbook-split:
Rewrote to use a more native Perl style.
Increase strictness of error checking.
Simplified and optimized.
Rewrote to accept input from stdin or from filename arg(s) on the command line.
Diffstat (limited to 'Docs/Support/docbook-split')
-rwxr-xr-x | Docs/Support/docbook-split | 98 |
1 files changed, 36 insertions, 62 deletions
diff --git a/Docs/Support/docbook-split b/Docs/Support/docbook-split index 62fcc866e04..b116769f86e 100755 --- a/Docs/Support/docbook-split +++ b/Docs/Support/docbook-split @@ -1,91 +1,65 @@ -#! /usr/local/bin/perl +#! /usr/bin/perl -w # O'Reilly's Perl script to chop mysql.xml into separate ch/apps/index files. # The indexes are actually not used, they're created straight from the xrefs. - -use strict; - # Breaks the MySQL reference manual into chapters, appendices, and indexes. -my $input_file; -my $directory; -my $chap_num; -my $app_letter; -my $start_text; -my $line; -my $input_file; -my $output_name; - -$input_file = "mysql.xml"; -$directory="chaps_apps_index"; -$chap_num=1; # Start chapter numbers at one (there is no preface) -$app_letter="a"; # Start appendix letters at "a" -$start_text=""; -$line=""; - -open (INPUT_FILE, '<' . $input_file) or die "Cannot open $input_file"; - -if (-d $directory) { - my $unlinked = unlink <$directory/*>; - printf(Removed "%d files\n", $unlinked); -} -else { - mkdir $directory or die "Cannot make $directory subdirectory"; -} +use strict; -while (1) { +my $app_letter = "a"; # Start appendix letters at "a" +my $chap_num = 1; # Start chapter numbers at one (there is no preface) +my $directory = "chaps_apps_index"; +my $ext = ".xml"; +my $line = ""; +my $output_name = ""; +my $start_text = ""; - # Terminating statement for loop. - exit if not defined $line; +mkdir $directory unless -d $directory; - if ($line =~ /(?:.*)(<chapter.*)/i ) { +while (defined $line) { + if ($line =~ /(<chapter.+)/i ) { $start_text = $1; - $output_name = &make_chapter_name($chap_num); - $chap_num++; + $output_name = sprintf("ch%02d%s", $chap_num, $ext); + ++$chap_num; &process_file("chapter"); } - elsif ($line =~ /(?:.*)(<appendix.*)/i ) { + elsif ($line =~ /(<appendix.+)/i ) { $start_text = $1 ; - $output_name = &make_appendix_name($app_letter); - $app_letter++; + $output_name = "app$app_letter$ext"; + ++$app_letter; &process_file("appendix"); } - elsif ($line =~ /(?:.*)(<index\s+id=")(.*?)(">.*)/i ) { + elsif ($line =~ /(<index\s+id=")(.*?)(">.*)/i ) { $start_text = $1 . $2 . $3; - $output_name = lc($2) . ".xml"; + $output_name = lc($2) . $ext; &process_file("index"); } else { - # Automatically skips junk in between chapters, appendices, - # and indexes. - $line = <INPUT_FILE>; + # Skip junk in between chapters, appendices and indexes. + $line = <>; } } -sub make_chapter_name { - my $num = shift; - my $name = "ch" . sprintf("%02d", $num) . ".xml"; - return $name; -} +sub process_file { + my $marker = shift; + my $path = "$directory/$output_name"; -sub make_appendix_name { - my $letter = shift; - my $name = "app" . sprintf("%s", $letter) . ".xml"; - return $name; -} + open (OUTPUT_FILE, ">$path") or die "Cannot open $path"; -sub process_file { - my $marker=shift; - open (OUTPUT_FILE, '>' . $directory . "/" . $output_name) or - die "Cannot open $output_name"; + print STDERR "Creating $path\n"; + + # Print out XML PI + print OUTPUT_FILE "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; + # Print whatever happened to appear at the end of the previous chapter. - print OUTPUT_FILE $start_text . "\n" if $start_text; - while (1) { - $line = <INPUT_FILE>; - exit if not defined $line; + print OUTPUT_FILE "$start_text\n" if $start_text; + + while (defined $line) { + $line = <>; + # Note: Anything after the terminating marker is lost, just like # lines in between chapters. if ($line =~ /(.*<\/\s*$marker\s*>)/i ) { - print OUTPUT_FILE $1 . "\n" if $1; + print OUTPUT_FILE "$1\n" if $1; close OUTPUT_FILE; return; } |