summaryrefslogtreecommitdiff
path: root/regress/doc/listup_recipe.pl
blob: 7759b23a2f612e35de62755f84edf80ae65adfb1 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env perl
#-*- perl -*-
#
# $FML$
#

use strict;
use Carp;
use vars qw($total $current_chapter_title $is_title_print);

if (@ARGV) {
    for my $file (@ARGV) {
	read_file($file);
    }
}
else {
    read_file("/dev/stdin");
}

exit 0;

sub read_file
{
    my ($file) = @_;

    use FileHandle;
    my $rh = new FileHandle $file;
    if (defined $rh) {
	my $in_q  = 0;
	my $in_t  = 0;
	my $first = 0;
	my $num_r = 0; 
	my $buf;

	while ($buf = <$rh>) {
	    next if $buf =~ /<para>/;
	    next if $buf =~ /<\/para>/;

	    # chapter title reset
	    if ($buf =~ /<chapter.*>/) { 
		$current_chapter_title = '';
		$is_title_print = 0;
		next;
	    }
	    unless ($current_chapter_title) {
		if ($buf =~ /<title>/i)   { $in_t = 1; next; }
		if ($buf =~ /<\/title>/i) { $in_t = 0; next; }
		if ($in_t) { 
		    $buf =~ s/^\s*//;
		    $buf =~ s/\s*$//;
		    $current_chapter_title .= $buf; 
		    next;
		}
	    }

	    if ($buf =~ /<question>/)   { 
		$in_q = 1;
		$num_r++;
		$total++;

		unless ($is_title_print) {
		    print_chapter_title();
		    $is_title_print = 1;
		}

		unless ($first) { 
		    print "\n-- $file\n" unless $file =~ /\/dev\//;
		    $first = 1;
		}
		print "\n($num_r)\n";
		next;
	    }
	    if ($buf =~ /<\/question>/) { 
		$in_q = 0;
		next;
	    }

	    if ($in_q) { 
		print $buf;
	    }	    
	}
	$rh->close();
    }
}


sub print_chapter_title
{
    print "\n*** ", $current_chapter_title, " ***\n";
}