summaryrefslogtreecommitdiff
path: root/fml/utils/bin/listup_recipes.pl
blob: 31a57dc9a94b770748745db8841f2daac0f80bf9 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env perl
#-*- perl -*-
#
# $FML: listup_recipes.pl,v 1.1 2005/11/19 03:50:51 fukachan Exp $
#

#
# *** CAUTION: THIS FILE CODE IS JAPANESE EUC. ***
#

use strict;
use Carp;
use vars qw(%entity %file %used %file_in_dir
	    $cur_id $on_table $in_question $in_sect2 $in_itemizedlist
	    $found_chapter $found_title);

my $entity = "include/chapters.ent";
parse($entity);

header();
parse("book.sgml");
footer();

exit 0;


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

    use FileHandle;
    my $rh = new FileHandle $file;
    if (defined $rh) {
	my $buf;
	while ($buf = <$rh>) {
	    # <!entity chapter.download SYSTEM "install/download.sgml">
	    if ($buf =~ /<\!entity\s+(\S+)\s+SYSTEM\s+"(\S+)">/) {
		$entity{ $1 } = $2;
		$file{ $2 }   = $1;
	    }

	    # usual file
	    if ($buf =~ /\&(\S+);/) {
		$used{ $1 } = 1;
		my $_file = $entity{ $1 } || '';
		if ($_file && -f $_file) {
		    parse($_file);
		}
	    }

	    scan($buf);
	}
	$rh->close();
    }
    else {
	croak("cannot open \"$file\"\n");
    }
}


sub scan
{
    my ($buf) = @_;

    if ($buf =~ /id=\"(\S+)\"/) {
	if ($buf =~ /<chapter\s+/i) { 
	    $found_chapter = 1;
	}
	$cur_id = $1;
	return;
    }

    if ($buf =~ /<title>/i) { 
	$found_title = 1;
	return;
    }

    if ($buf =~ /TABLE_OF_RECIPES/) {
	$on_table = 1;
	return;
    }

    if ($found_chapter && $found_title) {
	if ($in_sect2) {
	    if ($in_itemizedlist) {
		print "</itemizedlist>\n";
		$in_itemizedlist = 0;
	    }
	    print "</sect2>\n\n";
	}

	print "<sect2>\n";
	print "<title>\n";
	print "$buf\n";
	print "</title>\n";
	print "<para></para>\n";
	print "\n";
	$found_chapter = $found_title = 0;
	$in_sect2 = 1;
    }

    if ($on_table) {
	if ($buf =~ /<question>/) {
	    $in_question = 1;
	    return;
	}
	if ($buf =~ /<\/question>/) {
	    $in_question = 0;
	    return;
	}
    }

    return if $buf =~ /<para>/;
    return if $buf =~ /<\/para>/;

    if ($in_question) {
	unless ($in_itemizedlist) {
	    print "<itemizedlist>\n";
	    $in_itemizedlist = 1;
	}

	print "<listitem>\n";
	print "<para>\n";
	print "<link linkend=\"$cur_id\">\n";
	# print "<xref linkend=\"$cur_id\">\n";
	print $buf;
	print "</link>\n";
	print "</para>\n\n";
	print "</listitem>\n";
    }
}


sub header
{
    print "<sect1 id=\"recipes\">\n";
    print "<title>\n";
    if ($ENV{ LANG_HINT } eq 'ja') {
	print "�쥷�԰���";
    }
    else {
	print "List of Recipes\n";
    }
    print "</title>\n";
}


sub footer
{
    if ($in_sect2) {
	print "</sect2>\n\n";
    }

    print "</sect1>\n";
}