Blame doc/scripts/split-texi.pl

Packit aea12f
#!/usr/bin/perl
Packit aea12f
Packit aea12f
# Copyright (C) 2011-2012 Free Software Foundation, Inc.
Packit aea12f
#
Packit aea12f
# This file is part of GnuTLS.
Packit aea12f
#
Packit aea12f
# This file is free software; you can redistribute it and/or modify it
Packit aea12f
# under the terms of the GNU General Public License as published by
Packit aea12f
# the Free Software Foundation; either version 3 of the License, or
Packit aea12f
# (at your option) any later version.
Packit aea12f
#
Packit aea12f
# This file is distributed in the hope that it will be useful, but
Packit aea12f
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
# General Public License for more details.
Packit aea12f
#
Packit aea12f
# You should have received a copy of the GNU General Public License
Packit aea12f
# along with this file; if not, write to the Free Software Foundation,
Packit aea12f
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit aea12f
Packit aea12f
$dir = shift;
Packit aea12f
$param2 = shift;
Packit aea12f
Packit aea12f
if (defined $param2 && $param2 ne '') {
Packit aea12f
  $enum = 1;
Packit aea12f
} else {
Packit aea12f
  $enum = 0;
Packit aea12f
}
Packit aea12f
Packit aea12f
sub key_of_record {
Packit aea12f
  local($record) = @_;
Packit aea12f
Packit aea12f
  # Split record into lines:
Packit aea12f
  my @lines = split /\n/, $record;
Packit aea12f
Packit aea12f
  my ($i) = 1;
Packit aea12f
  my ($key) = '';
Packit aea12f
  $key = $lines[$i] if (defined $lines[$i]);
Packit aea12f
Packit aea12f
  if ($enum == 1) {
Packit aea12f
    while( !($key =~ m/\@c\s(.*)\n/) && ($i < 5)) { $i=$i+1; $key = $lines[$i]; }
Packit aea12f
  } else {
Packit aea12f
    while( !($key =~ m/\@subheading\s(.*)/) && ($i < 5)) { 
Packit aea12f
      $i=$i+1; 
Packit aea12f
      if (defined $lines[$i]) {
Packit aea12f
        $key = $lines[$i]; 
Packit aea12f
      } else {
Packit aea12f
        $key = '';
Packit aea12f
      }
Packit aea12f
    }
Packit aea12f
  }
Packit aea12f
Packit aea12f
  return $key;
Packit aea12f
}
Packit aea12f
Packit aea12f
if ($enum == 1) {
Packit aea12f
  $/="\@end table";
Packit aea12f
} else {
Packit aea12f
  $/="\@end deftypefun";
Packit aea12f
}
Packit aea12f
@records = <>;  # Read in whole file, one record per array element.
Packit aea12f
Packit aea12f
$/="\n";
Packit aea12f
Packit aea12f
mkdir $dir;
Packit aea12f
Packit aea12f
if ($enum == 0) {
Packit aea12f
  @records = sort { key_of_record($a) cmp key_of_record($b) } @records;
Packit aea12f
}
Packit aea12f
Packit aea12f
foreach (@records) {
Packit aea12f
  $key = $_;
Packit aea12f
  if ($enum == 1) {
Packit aea12f
    $key =~ m/\@c\s(.*)\n/;
Packit aea12f
    $key = $1;
Packit aea12f
  } else {
Packit aea12f
    $key =~ m/\@subheading\s(.*)\n/;
Packit aea12f
    $key = $1;
Packit aea12f
  }
Packit aea12f
Packit aea12f
  if (defined $key && $key ne "") {
Packit aea12f
    open FILE, "> $dir/$key\n" or die $!;
Packit aea12f
    print FILE $_ . "\n";
Packit aea12f
    close FILE;
Packit aea12f
  }
Packit aea12f
} 
Packit aea12f
Packit aea12f
#print @records;