summaryrefslogtreecommitdiffstats
path: root/tools/sectionize.pl
blob: 64c2701c097f470c7734f051287bd0117e90f54e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl -w
#
# sectionize.pl
# --------------------------------------------------------------
# this script splits one SGML file into several files one per
# section.
# --------------------------------------------------------------
# PROBLEMS:
#	- naming scheme is harcoded
#	- last file has no sections itself (harmless)
# --------------------------------------------------------------
# Any comment to: Ricardo Mones Lastra <mones@aic.uniovi.es>
# 

(@ARGV > 0) or die ("Missing argument. Usage: $0 <filename>\n");

open (FH,"<$ARGV[0]");
my $fn = $ARGV[0];
$fn =~ s/\.sgml//;
my $sc = 1;
my $ofn = join ('.', $fn, sprintf("%.03d",$sc), 'sgml');
open (OF,">$ofn");
while (<FH>) {
  if (m#^</sect>*$#) {
    print OF $_;
    close (OF);
    $sc = $sc + 1;
    $ofn = join ('.', $fn, sprintf("%.03d",$sc), 'sgml');
    open (OF,">$ofn");    
  } 
  else {
    print OF $_;
  }
}
close (OF);
close (FH);
print "Done. $sc sections processed\n";