#!/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>) { # 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 =~ //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 "\n"; $in_itemizedlist = 0; } print "\n\n"; } print "\n"; print "\n"; print "$buf\n"; print "\n"; print "\n"; print "\n"; $found_chapter = $found_title = 0; $in_sect2 = 1; } if ($on_table) { if ($buf =~ //) { $in_question = 1; return; } if ($buf =~ /<\/question>/) { $in_question = 0; return; } } return if $buf =~ //; return if $buf =~ /<\/para>/; if ($in_question) { unless ($in_itemizedlist) { print "\n"; $in_itemizedlist = 1; } print "\n"; print "\n"; print "\n"; # print "\n"; print $buf; print "\n"; print "\n\n"; print "\n"; } } sub header { print "\n"; print "\n"; if ($ENV{ LANG_HINT } eq 'ja') { print "レシピ一覧"; } else { print "List of Recipes\n"; } print "\n"; } sub footer { if ($in_sect2) { print "\n\n"; } print "\n"; }