From: Geert J. <gj...@us...> - 2002-09-03 19:40:55
|
Update of /cvsroot/woc/woc/src/woc/src/topic In directory usw-pr-cvs1:/tmp/cvs-serv23171/woc/src/topic Added Files: make_associations_index.pl make_shtmlfiles_index.pl make_xmlfiles_index.pl topic2html.pl update.sh Log Message: --- NEW FILE: make_associations_index.pl --- #!/usr/local/bin/perl -w use strict; use diagnostics; if (!-e "associaties.xml") { print "The file associaties.xml does not exist!$/"; exit(0); } open(SOURCE, "<associaties.xml"); my @source = <SOURCE>; close(SOURCE); open(TARGET, ">associations_index"); while (@source) { while (@source && $source[0] !~ /<topic/i) { shift @source; } my $at = ""; $at = $1 if (@source && $source[0] =~ /id="(.*?)"/i); my $name = ""; while (@source && !($source[0] =~ /<\/topic/i || $source[0] =~ /<topic.*?\/>/i)) { $name = $1 if ($source[0] =~ /<basename>(.*?)<\/basename>/i); $name =~ s/<woctm:assocrl\senum="(.*?)"\/>/\$$1\$/g; $name =~ s/<woctm:assocrl\senum="/\$/g; shift @source; } print TARGET "$at $name\n" if ($at && $name); shift @source; } close(TARGET); --- NEW FILE: make_shtmlfiles_index.pl --- #!/usr/local/bin/perl -w use strict; my $wmldir = "/vol/www/woc/web-docs/gui/items"; my @files = `ls -1 $wmldir/*.shtml`;#<$wmldir/*.shtml>; my $filename = ""; my @file = (); my $itemname = ""; open(TARGET, ">shtmlfiles_index"); foreach $filename (@files) { chomp ($filename); open(FILE, "<$filename"); @file = <FILE>; while (@file && $file[0] !~ /<a class="item" name=/i) { shift @file; } $itemname = ""; $itemname = $1 if (@file && $file[0] =~ />([^>]*?)<\/B><\/a>/i); print TARGET "$filename $itemname\n" if ($itemname); } --- NEW FILE: make_xmlfiles_index.pl --- #!/usr/local/bin/perl -w use strict; my $wmldir = "/vol/www/woc/data/wml"; my @files = <$wmldir/*.xml>; my $filename = ""; my @file = (); my $itemname = ""; open(TARGET, ">associations_index"); foreach $filename (@files) { open(FILE, "<$filename"); @file = <FILE>; while (@file && $file[0] !~ /<ITEM/i) { shift @file; } $itemname = ""; $itemname = $1 if (@file && $file[0] =~ /NAME="(.*?)"/i); print "$filename $itemname\n" if ($itemname); } --- NEW FILE: topic2html.pl --- #!/usr/local/bin/perl -w use strict; ## global vars ## my $associations_indexfile = "associations_index"; my $xmlfiles_indexfile = "xmlfiles_index"; my $shtmlfiles_indexfile = "shtmlfiles_index"; my $wmldir = "/vol/www/woc/data/wml"; my $verbose = ""; # False my $debug = ""; # False ### MAIN ### print "Content-type: text/plain\n\n\n"; my $associations_index = {()}; my $xmlfiles_index = {()}; my $shtmlfiles_index = {()}; if (@ARGV) { while ($ARGV[0] =~ /^\-/) { if ($ARGV[0] =~ /^\-d/i) { $debug = "Active"; shift @ARGV; } if ($ARGV[0] =~ /^\-v/i) { $verbose = "Active"; shift @ARGV; } } $associations_index = &get_associations_index ($associations_indexfile); $xmlfiles_index = &get_xmlfiles_index ($xmlfiles_indexfile); $shtmlfiles_index = &get_shtmlfiles_index ($shtmlfiles_indexfile); foreach my $file (@ARGV) { &process_file ("$wmldir/$file", $associations_index, $xmlfiles_index, $shtmlfiles_index); } } else { die "Usage: $0 [-v[erbose]] [-d[ebug]] <xml-files>\n"; } ### END of MAIN ### sub get_associations_index { my %associations_index = (); if (open (INDEXFILE, $_[0])) { my @indexfile = <INDEXFILE>; foreach my $line (@indexfile) { my ($assoc, @line) = split (/\s+/, $line); $associations_index{$assoc} = join (" ", @line); } } else { warn "The associations indexfile $_[0] cannot be read!\n"; } return \%associations_index; } sub get_xmlfiles_index { my %xmlfiles_index = (); if (open (INDEXFILE, $_[0])) { my @indexfile = <INDEXFILE>; foreach my $line (@indexfile) { my ($xmlfile, @name) = split (/\s+/, $line); $xmlfiles_index{join (" ", @name)} = $xmlfile; } } else { warn "The xmlfiles indexfile $_[0] cannot be read!\n"; } return \%xmlfiles_index; } sub get_shtmlfiles_index { my %shtmlfiles_index = (); if (open (INDEXFILE, $_[0])) { my @indexfile = <INDEXFILE>; foreach my $line (@indexfile) { my ($shtmlfile, @name) = split (/\s+/, $line); $shtmlfiles_index{join (" ", @name)} = $shtmlfile; } } else { warn "The shtmlfiles indexfile $_[0] cannot be read!\n"; } return \%shtmlfiles_index; } sub process_file { my ($file, $associations_index, $xmlfiles_index, $shtmlfiles_index) = @_; ## get topicname and associations ## my $topicname = ""; my $associations = []; if (open (XMLFILE, $_[0])) { my @xmlfile = <XMLFILE>; while (@xmlfile && $xmlfile[0] !~ /<ITEM/i) { shift @xmlfile; print "current line=$xmlfile[0]" if $debug; } $topicname = $1 if (@xmlfile && $xmlfile[0] =~ /NAME="(.+?)"/i); while (@xmlfile) { while (@xmlfile && $xmlfile[0] !~ /<tm:assoc\s/i) { shift @xmlfile; print "current line=$xmlfile[0]" if $debug && @xmlfile; } my $assoc = ""; if (@xmlfile && $xmlfile[0] =~ /id="(.+?)"/i) { $assoc = $1; print "Found association=$1\n" if $verbose; } shift @xmlfile if @xmlfile; print "current line=$xmlfile[0]" if $debug && @xmlfile; ## get all associated files! ## my @assocrl = (); while (@xmlfile && $xmlfile[0] !~ /<\/tm:assoc>/i) { while (@xmlfile && $xmlfile[0] !~ /<\/tm:assoc>/i && $xmlfile[0] !~ /<tm:assocrl\s/i) { shift @xmlfile; print "current line=$xmlfile[0]" if $debug; } if (@xmlfile && $xmlfile[0] =~ /xlink:href="(.+?)"/i) { push (@assocrl, $1); print "Found assoclink=$1\n" if $verbose; } else { print "No assoclink??\n" if $verbose && @xmlfile; } if (@xmlfile && $xmlfile[0] !~ /<\/tm:assoc>/i){ shift @xmlfile; print "current line=$xmlfile[0]" if $debug; } } if ($assoc && @assocrl) { push (@$associations, [$assoc, \@assocrl]); print "Pussing assoc=$assoc @assocrl\n" if $verbose; } else { print "Was last association\n" if $verbose && !@xmlfile; } } } else { warn "The xmlfile $_[0] cannot be read!\n"; } ## turn associations into HTML ## my @result = (); foreach my $assoc (@$associations) { my $association = ($$associations_index{$$assoc[0]} || ""); print "Assoc: $association$/" if $debug; if ($association =~ /\$.*?\$/) { my @related_topics = @{$$assoc[1]}; my @related_files = (); foreach my $related_topic (@related_topics) { if (exists $$shtmlfiles_index{$related_topic}) { push (@related_files, $$shtmlfiles_index{$related_topic}); } else { push (@related_files, ""); } } $association =~ s/\$0\$/<I>$topicname<\/I>/g; if ($association =~ /\$\*\$/) { print "Substitute \*...$/" if $verbose; while (@related_files) { my $related_file = shift @related_files; my $related_topic = shift @related_topics; my $delim = ","; $delim = " en" if (scalar @related_files == 1); $delim = "" if (scalar @related_files == 0); if ($related_file) { # add link # $related_file =~ s/\/vol\/www\/woc\/web-docs/\/woc/i; $association =~ s/\$\*\$/ <A HREF=\"\/cgi-bin-woc\/topiclink\/link.pl?$related_file+$$assoc[0]\"><I>$related_topic<\/I><\/A>$delim\$\*\$/g; } else { # don't link # $association =~ s/\$\*\$/ <I>$related_topic<\/I>\$\*\$/g; } } print "New Assoc: $association$/" if $verbose; } $association =~ s/\$\*\$//g; my $i = 1; while ($association =~ /\$$i\$/) { my $related_file = shift @related_files; my $related_topic = shift @related_topics; if ($related_file) { # add link # $related_file =~ s/\/vol\/www\/woc\/web-docs/\/woc/i; $association =~ s/\$$i\$/<A HREF=\"\/cgi-bin-woc\/topiclink\/link.pl?$related_file\+$$assoc[0]\"><I>$related_topic<\/I><\/A>/g; } else { # don't link # $association =~ s/\$$i\$/<I>$related_topic<\/I>/g; } $association =~ s/\$$i\$/<I>$topicname<\I>/g; $i++ } push (@result, "$association<BR />\n"); } elsif ($association) { my @related_topics = @{$$assoc[1]}; my @related_files = (); foreach my $related_topic (@related_topics) { if (exists $$shtmlfiles_index{$related_topic}) { push (@related_files, $$shtmlfiles_index{$related_topic}); } else { push (@related_files, ""); } } push (@result, "<I>$topicname</I> $association"); my $related_file = shift @related_files; my $related_topic = shift @related_topics; if ($related_file) { # add link # $related_file =~ s/\/vol\/www\/woc\/web-docs/\/woc/i; push (@result, " <A HREF=\"/cgi-bin-woc/topiclink/link.pl?$related_file\+$$assoc[0]\"><I>$related_topic</I></A>"); } else { # don't link # push (@result, " <I>$related_topic</I>"); } while (@related_files) { my $related_file = shift @related_files; my $related_topic = shift @related_topics; if (@related_files > 0) { if ($related_file) { # add link # $related_file =~ s/\/vol\/www\/woc\/web-docs/\/woc/i; push (@result, ", <A HREF=\"\/cgi-bin-woc\/topiclink\/link.pl?$related_file\+$$assoc[0]\"><I>$related_topic</I></A>"); } else { # don't link # push (@result, ", <I>$related_topic</I>"); } } elsif (@related_files == 0) { if ($related_file) { # add link # $related_file =~ s/\/vol\/www\/woc\/web-docs/\/woc/i; push (@result, " en <A HREF=\"\/cgi-bin-woc\/topiclink\/link.pl?$related_file\+$$assoc[0]\"><I>$related_topic</I></A>"); } else { # don't link # push (@result, " en <I>$related_topic</I>"); } } } push (@result, "<BR />\n"); } } foreach (@result) { print; } } --- NEW FILE: update.sh --- ./make_xmlfiles_index.pl > xmlfiles_index ./make_shtmlfiles_index.pl ./make_associations_index.pl |