9 my(%DB,%OWNS,$debugmatch,$D,$key,$owner,$ref,$maxsize,$filename,$doimport,$import_xlate);
44 return "<span class=\"$class\">$_</span>" if defined $class;
50 my( $preinsert,$postinsert,%rec )=@_;
52 my($r)=$preinsert.htmlquote(rec_to_name(%rec),"name").$postinsert;
53 $r.="\n".htmlquote($rec{"Publ. Author"},"author") if (exists($rec{"Publ. Author"}));
54 $r.="<br />\n".htmlquote($rec{"Publication"},"publication") if (exists($rec{"Publication"}));
55 $r.="<br />\n".htmlquote($rec{"Notes"},"notes") if (exists($rec{"Notes"}));
56 if ($doimport && exists($rec{"html"})) {
57 my($import)="import: [".$rec{"id"}."]";
58 $r.="<br />\n<blockquote><!-- BEGIN $import -->\n".$rec{"html"}."\n<!-- END $import --></blockquote>\n";
67 s/\(([0-9]{4}) publ. [0-9]{4}\)/($1)/g;
68 while (/\(([0-9]{4})(-[0-9]+)?\)/) {
69 return $1 if ($1>=1700 && $1<=2010);
80 print("-$file----------------$'--------------\n");
81 warn "Unable to match file \"".getcwd()."/$file\".";
88 if (!open(FI,$file)) {
89 warn("Unable to open file \"$file\" in dir \"".getcwd()."\": $!");
96 my($bigword)='[^<]*(?:<IT>)?[^<]*(?:<RO>)?[^<]*(?:<1000 m)?[^<]*';
99 my($any)='[\x00-\xFF]*';
100 my($ipniservletword)="<a href=\"\\./IpniServlet\\?id=($id)&query_type=by_id\">($word)</a>";
101 my($idquoted)=$id; $idquoted=~s%\W%\\$&%g;
102 my($ipniservletwordthree)=$ipniservletword; $ipniservletwordthree=~s%\($idquoted\)%((?:$idone){3})$&%os or die;
103 my($attrpat)="<p>nomenclatural synonym(\\(Main Record\\))?:$ipniservletword</p>|<p>basionym(\\(\\d+\\))?:$ipniservletword</p>|<p>basionym:($word)|<p>replaced synonym:$ipniservletword</p>|<p>replaced synonym:($word)|<p>Is a replaced synonym of:$ipniservletword</p>|<p>Is a basionym of:$ipniservletword</p>|<p>later publication of(\\(\\d+\\))?:$ipniservletword</p>|<p>Is a later publication of of:$ipniservletword</p>";
108 <title>IPNI Query Results</title>
110 <body bgcolor="#ffffff" text="#000000" link="#006666" vlink="#008080" alink="#008080">
111 <HR><b><i>Orchidaceae</i> ($word)</b> ($word) <br>
112 ((?:<a href="\./PublicationServlet\?id=($id)&query_type=by_id"> ($word)</a> ($word)|$bigword(?:<br>\n$word)*)?<p>($bigword)?</p><p>($word)?</p>(?:
113 remarks: .*)?(<HR><h4>Type</h4>)?(<table $any</table>)?(?:
114 <h4>Linked Records</h2>
115 ((?:$attrpat)*))?(<br>
117 <h4>Original Data</h2>
118 (?:basionym: ($word)<br>
119 )?(?:hybrid parentage: ($word)<br>
120 )?(?:replaced synonym: ($word)<br>
121 )?(?:distribution: ($word)<br>
122 )?(?:Notes: ($word))?)?)(?:<p><a href="\./query_ipni.html">Back to Search Page</a></p>
130 $rec{"Publ. Author"}=$2;
131 $rec{"Publication"}="$5 $6" if defined($5) && defined($6);
132 $rec{"html"}=$3 if defined $3;
134 ($rec{"id"}=$file)=~s#^($id)\.html$#$1#os or failed($file);
135 $rec{"html"}=~s#$ipniservletwordthree#<a href="$1/$1$2.html">$3</a>#osg if $import_xlate && exists $rec{"html"};
136 while (defined($attrsbody) && $attrsbody=~s%^(?:$attrpat)%%os) {
137 # nomenclatural synonym: id=$2
139 # replaced synonym: id=$8
140 # Is a replaced synonym: id=$11
141 # Is a basionym: id=$13
142 # later publication: id=$16
143 # Is a later publication: id=$18
144 my(@refs)=($2,$5,$8,$11,$13,$16,$18);
147 push(@{$rec{"refs"}},$_) if defined ($_=shift @refs);
154 $DB{$rec{"id"}}=\%rec;
164 warn("Unable to change to dir \"$dir\" from dir \"$old\": $!");
167 opendir(DIR,".") or die("Cannot open . in \"".getcwd()."\": $!");
168 foreach (sort readdir(DIR)) {
169 process_entry($_) if ($_!~/^\./);
172 chdir($old) or warn("Unable to retreat to dir \"$old\": $!");
179 process_dir ($entry) if -d $entry;
180 process_file($entry) if -f $entry;
186 { process_entry($_); }
192 for $refid (@{$DB{$id}{"refs"}}) {
193 if (!exists $DB{$refid}) {
194 warn "Undefined ref id \"$refid\" from id \"$id\"" if $D;
197 next if $id eq $refid; # self-ref
198 # push(@refs,$DB{$refid});
201 $DB{$id}{"refs"}=\@refs;
204 print Data::Dumper->Dump([\%DB],["%DB"]) if $D;
206 %OWNS=map { $_=>[] } keys(%DB);
208 for $id (keys %OWNS) {
210 for $refid (@{$DB{$id}{"refs"}}) {
211 next if !exists $OWNS{$refid};
212 push(@{$OWNS{$id}},$refid,@{$OWNS{$refid}});
213 delete $OWNS{$refid};
217 print Data::Dumper->Dump([\%OWNS],["%OWNS"]) if $D;
219 #foreach $key (keys %DB) {
220 # $DB{$key}{"Publication"}=extract_year($DB{$key}{"Publication"})." ::: ".$DB{$key}{"Publication"}
221 # if (exists($DB{$key}{"Publication"}));
224 foreach $key (keys %OWNS) {
225 my(@keys)=@{$OWNS{$key}};
228 @keys=sort { extract_year($DB{$b}{"Publication"}) <=> extract_year($DB{$a}{"Publication"}); } @keys;
229 my($pkey)=shift(@keys);
238 "<?xml version=\"1.0\" encoding=\"utf-8\"?>
239 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
240 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
241 <head><title>Kewensis $header</title>
242 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
243 <base href=\"".($import_xlate ? "data/" : "http://www.ipni.org/ipni/")."\" />
244 <style type=\"text/css\"><!--
245 .name { font-weight: bold; }
246 .author { font-variant: small-caps; }
256 print OUT "</body></html>\n";
260 if (defined $maxsize) {
262 my($filename,$fileid);
263 foreach $owner (sort keys %OWNS) {
266 if ($fileno<0 || tell(OUT)>=$maxsize) {
267 OUT_flush() if ($fileno>=0);
268 $fileid=sprintf("%04d",++$fileno);
269 $filename="kew-$fileid.html";
270 open(OUT,">$filename") or die "Cannot open \"$filename\": $!";
271 print_header("chunk $fileid");
275 print STDERR "($owner):";
276 foreach $child (@{$OWNS{$owner}})
277 { print STDERR " ($child)"; }
280 print OUT format_record("<p><a id=\"".htmlquote($owner)."\">","</a></p>\n",%{$DB{$owner}});
281 if (@{$OWNS{$owner}}) {
282 print OUT "<blockquote>\n";
283 foreach $child (@{$OWNS{$owner}})
284 { print OUT format_record("<p>","</p>\n",%{$DB{$child}}); }
285 print OUT "</blockquote>\n";
288 $DB{$owner}{"_filename"}=$filename;
291 open(OUT,">kew-index.html") or die "Cannot open \"kew-index.html\": $!";
292 print_header("Index");
295 open(OUT,">kewensis.html") or die "Cannot open \"kewensis.html\": $!";
296 print_header("Full");
301 my($preinsert,$postinsert,%rec)=@_;
303 return htmlquote(rec_to_name(%rec));
306 my($printrecref)=(defined $maxsize ? \&format_href : \&format_record );
308 foreach $owner (sort keys %OWNS) {
312 print OUT "<a href=\"".$DB{$owner}{"_filename"}."#$owner\">" if defined $maxsize;
313 print OUT &{$printrecref}("","",%{$DB{$owner}});
314 print OUT "</a>" if defined $maxsize;
316 if (@{$OWNS{$owner}}) {
318 foreach $child (@{$OWNS{$owner}}) {
320 print OUT &{$printrecref}("","",%{$DB{$child}});