texinfo documentation is similar to the printed manual.
[gnutls.git] / doc / scripts / split-texi.pl
blobedb99fedc970c27fade86a30a191d4f8f4f7dfde
1 eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
2 & eval 'exec perl -wS "$0" $argv:q'
3 if 0;
5 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
7 # This file is part of GnuTLS.
9 # This file is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This file is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this file; if not, write to the Free Software Foundation,
21 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 $dir = shift;
24 $param2 = shift;
26 if (defined $param2 && $param2 ne '') {
27 $enum = 1;
28 } else {
29 $enum = 0;
32 sub key_of_record {
33 local($record) = @_;
35 # Split record into lines:
36 my @lines = split /\n/, $record;
38 my ($i) = 1;
39 my ($key) = '';
40 $key = $lines[$i] if (defined $lines[$i]);
42 if ($enum == 1) {
43 while( !($key =~ m/\@c\s(.*)\n/) && ($i < 5)) { $i=$i+1; $key = $lines[$i]; }
44 } else {
45 while( !($key =~ m/\@subheading\s(.*)/) && ($i < 5)) {
46 $i=$i+1;
47 if (defined $lines[$i]) {
48 $key = $lines[$i];
49 } else {
50 $key = '';
55 return $key;
58 if ($enum == 1) {
59 $/="\@end table";
60 } else {
61 $/="\@end deftypefun";
63 @records = <>; # Read in whole file, one record per array element.
65 $/="\n";
67 mkdir $dir;
69 if ($enum == 0) {
70 @records = sort { key_of_record($a) cmp key_of_record($b) } @records;
73 foreach (@records) {
74 $key = $_;
75 if ($enum == 1) {
76 $key =~ m/\@c\s(.*)\n/;
77 $key = $1;
78 } else {
79 $key =~ m/\@subheading\s(.*)\n/;
80 $key = $1;
83 if (defined $key && $key ne "") {
84 open FILE, "> $dir/$key\n" or die $!;
85 print FILE $_ . "\n";
86 close FILE;
90 #print @records;