1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00
Files
mariadb/Docs/Support/docbook-split
unknown 633d54b67e 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.
2002-02-27 04:35:26 -07:00

71 lines
2.1 KiB
Perl
Executable File

#! /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.
# Breaks the MySQL reference manual into chapters, appendices, and indexes.
use strict;
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 = "";
mkdir $directory unless -d $directory;
while (defined $line) {
if ($line =~ /(<chapter.+)/i ) {
$start_text = $1;
$output_name = sprintf("ch%02d%s", $chap_num, $ext);
++$chap_num;
&process_file("chapter");
}
elsif ($line =~ /(<appendix.+)/i ) {
$start_text = $1 ;
$output_name = "app$app_letter$ext";
++$app_letter;
&process_file("appendix");
}
elsif ($line =~ /(<index\s+id=")(.*?)(">.*)/i ) {
$start_text = $1 . $2 . $3;
$output_name = lc($2) . $ext;
&process_file("index");
}
else {
# Skip junk in between chapters, appendices and indexes.
$line = <>;
}
}
sub process_file {
my $marker = shift;
my $path = "$directory/$output_name";
open (OUTPUT_FILE, ">$path") or die "Cannot open $path";
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 (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;
close OUTPUT_FILE;
return;
}
print OUTPUT_FILE $line;
}
}
exit 0;