1# 2# cf_generate.pl 3# 4# cf_generate: Build the files cf_byprog.html, cf_byname.html and 5# attrs.html from the informations found 6# in ../htcommon/defaults.cc. 7# attrs.html : attrs_head.html + generation + attrs_tail.html 8# cf_byprog.html : cf_byprog_head.html + generation + cf_byprog_tail.html 9# cf_byname.html : cf_byname_head.html + generation + cf_byname_tail.html 10# 11# Part of the ht://Dig package <http://www.htdig.org/> 12# Copyright (c) 1999-2004 The ht://Dig Group 13# For copyright details, see the file COPYING in your distribution 14# or the GNU Library General Public License (LGPL) version 2 or later 15# <http://www.gnu.org/copyleft/lgpl.html> 16# 17# $Id: cf_generate.pl,v 1.9 2004/06/05 04:30:47 lha Exp $ 18# 19use strict; 20 21use vars qw(%char2quote); 22 23%char2quote = ( 24 '>' => '>', 25 '<' => '<', 26 '&' => '&', 27 "'" => ''', 28 '"' => '"', 29 ); 30 31sub html_escape { 32 my($toencode) = @_; 33 34 return undef if(!defined($toencode)); 35 36 $toencode =~ s;([&\"<>\']);$char2quote{$1};ge; 37 return $toencode; 38} 39 40# 41# Read and parse attributes descriptions found in defaults.cc 42# 43 44my($dir); 45if (scalar(@ARGV) == 0) { 46 $dir = '..'; 47} 48else { 49 $dir = @ARGV[0]; 50} 51 52local($/) = undef; 53my($file) = $dir . "/htcommon/defaults.cc"; 54my($content); 55open(FILE, "<$file") or die "cannot open $file for reading : $!"; 56$content = <FILE>; 57close(FILE); 58 59# 60# Change curly to square brackets to generate perl arrays instead 61# of hashes. Order is important. 62# 63$content =~ s/.*ConfigDefaults.*?\{(.*)\{0, 0.*/[$1]/s; 64$content =~ s/\s*\\*$//mg; 65$content =~ s/([\@\$])/\\$1/gs; 66$content =~ s/^\{/\[/mg; 67$content =~ s/^\"\s*\},$/\" \],/mg; 68# 69# Transform macro substituted strings by @strings@ (substitued by ../configure) 70# Three step process ( -> \@ string\@ -> \@string\@ -> @string@ ) 71# as perl seems to get confused by @$2. 72# 73$content =~ s|^(\[ \"\w+\", )([A-Z].*?),\n|$1\"\\\@$2\\@\",\n|mg; 74#$content =~ s/^(\[ \"\w+\", )\"(.*?)\"(.*?)\"(.*?)\",\n/$1\"$2\\\"$3\\\"$4\",\n/mg; 75$content =~ s/BIN_DIR/bindir/g; 76my($config); 77eval "\$config = $content"; 78 79if(!$config) { 80 die "could not extract any configuration info from $file"; 81} 82 83# 84# Spit the HTML pages 85# 86 87my($file); 88# 89# Complete list of attributes with descriptions and examples. 90# 91$file = "attrs.html.in"; 92open(ATTR, ">$file") or die "cannot open $file for writing : $!"; 93 94$file = $dir . "/htdoc/attrs_head.html"; 95open(FILE, "<$file") or die "cannot open $file for reading : $!"; 96$content = <FILE>; 97print ATTR $content; 98close(FILE); 99 100# 101# Index by attribute name 102# 103$file = "cf_byname.html"; 104open(BYNAME, ">$file") or die "cannot open $file for writing : $!"; 105 106$file = $dir . "/htdoc/cf_byname_head.html"; 107open(FILE, "<$file") or die "cannot open $file for reading : $!"; 108$content = <FILE>; 109print BYNAME $content; 110close(FILE); 111 112my($letter) = ''; 113my($record); 114foreach $record (@$config) { 115 my($name, $default, $type, $programs, $block, $version, $category, $example, $description) = @$record; 116 117 if($letter ne uc(substr($name, 0, 1))) { 118 print BYNAME "\t</font> <br>\n" if($letter); 119 $letter = uc(substr($name, 0, 1)); 120 print BYNAME "\t<strong>$letter</strong> <font face=\"helvetica,arial\" size=\"2\"><br>\n"; 121 } 122 123 print BYNAME "\t <img src=\"dot.gif\" alt=\"*\" width=9 height=9> <a target=\"body\" href=\"attrs.html#$name\">$name</a><br>\n"; 124 125 my($used_by) = join(",\n\t\t\t", 126 map { 127 my($top) = $_ eq 'htsearch' ? " target=\"_top\"" : ""; 128 "<a href=\"$_.html\"$top>$_</a>"; 129 } 130 split(' ', $programs)); 131 132 if ($block eq '') { 133 $block = "Global"; 134 } 135 136 if($version != 'all') { 137 $version = "$version or later"; 138 } 139 140 if(!($example =~ /^$name:/)) { 141 $example = "\t\t\t <tr> <td valign=\"top\"><em>No example provided</em></td> </tr>\n"; 142 } elsif($example =~ /\A$name:\s*\Z/s) { 143 $example = "\t\t\t <tr> <td valign=\"top\">$name:</td> </tr>\n"; 144 } else { 145 my($one); 146 my($html) = ''; 147 foreach $one (split("$name:", $example)) { 148 next if($one =~ /^\s*$/); 149 $html .= <<EOF; 150 <tr> 151 <td valign="top"> 152 $name: 153 </td> 154 <td nowrap> 155 $one 156 </td> 157 </tr> 158EOF 159 } 160 $example = $html; 161 } 162 163 if($default =~ /^\s*$/) { 164 $default = "<em>No default</em>"; 165 } else { 166 $default =~ s/^([A-Z][A-Z_]*) \" (.*?)\"/$1 $2/; # for PDF_PARSER 167 $default = html_escape($default); 168 # hyperlink default values defined in terms of other attributes 169 $default =~ s/\${([A-Za-z_]*)}/\${<a href=\"#$1\">$1<\/a>}/; 170 171 } 172 print ATTR <<EOF; 173 <dl> 174 <dt> 175 <strong><a name="$name"> 176 $name</a></strong> 177 </dt> 178 <dd> 179 <dl> 180 <dt> 181 <em>type:</em> 182 </dt> 183 <dd> 184 $type 185 </dd> 186 <dt> 187 <em>used by:</em> 188 </dt> 189 <dd> 190 $used_by 191 </dd> 192 <dt> 193 <em>default:</em> 194 </dt> 195 <dd> 196 $default 197 </dd> 198 <dt> 199 <em>block:</em> 200 </dt> 201 <dd> 202 $block 203 </dd> 204 <dt> 205 <em>version:</em> 206 </dt> 207 <dd> 208 $version 209 </dd> 210 <dt> 211 <em>description:</em> 212 </dt> 213 <dd>$description </dd> 214 <dt> 215 <em>example:</em> 216 </dt> 217 <dd> 218 <table border="0"> 219$example </table> 220 </dd> 221 </dl> 222 </dd> 223 </dl> 224 <hr> 225EOF 226 227} 228 229open(FILE, "date |") or die "cannot open pipe to date command for reading : $!"; 230$content = <FILE>; 231close(FILE); 232my($date) = $content; 233 234my($file) = $dir . "/htdoc/attrs_tail.html"; 235open(FILE, "<$file") or die "cannot open $file for reading : $!"; 236$content = <FILE>; 237$content =~ s/Last modified: [^\n]*\n/Last modified: $date/; 238print ATTR $content; 239close(FILE); 240 241my($file) = $dir . "/htdoc/cf_byname_tail.html"; 242open(FILE, "<$file") or die "cannot open $file for reading : $!"; 243$content = <FILE>; 244print BYNAME $content; 245close(FILE); 246 247close(ATTR); 248close(BYNAME); 249 250# 251# Index by program name 252# 253$file = "cf_byprog.html"; 254open(BYPROG, ">$file") or die "cannot open $file for writing : $!"; 255 256$file = $dir . "/htdoc/cf_byprog_head.html"; 257open(FILE, "<$file") or die "cannot open $file for reading : $!"; 258$content = <FILE>; 259print BYPROG $content; 260close(FILE); 261 262my(%prog2attr); 263foreach $record (@$config) { 264 my($name, $default, $type, $programs, $example, $description) = @$record; 265 266 my($prog); 267 foreach $prog (split(' ', $programs)) { 268 push(@{$prog2attr{$prog}}, $record); 269 } 270} 271 272my($prog); 273foreach $prog (sort(keys(%prog2attr))) { 274 my($top) = $prog eq 'htsearch' ? "target=\"_top\"" : "target=\"body\""; 275 print BYPROG "\t<br><strong><a href=\"$prog.html\" $top>$prog</a></strong> <font face=\"helvetica,arial\" size=\"2\"><br>\n"; 276 my($record); 277 foreach $record (@{$prog2attr{$prog}}) { 278 my($name, $default, $type, $programs, $example, $description) = @$record; 279 print BYPROG "\t <img src=\"dot.gif\" alt=\"*\" width=9 height=9> <a target=\"body\" href=\"attrs.html#$name\">$name</a><br>\n"; 280 } 281} 282 283my($file) = $dir . "/htdoc/cf_byprog_tail.html"; 284open(FILE, "<$file") or die "cannot open $file for reading : $!"; 285$content = <FILE>; 286print BYPROG $content; 287close(FILE); 288 289close(BYPROG); 290