[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 #!/usr/bin/perl 2 # 3 # See COPYRIGHT 4 # 5 # Script to generate a pod file from an html source (the same one as for text files too) 6 # and later this pod file it passed through pod2man 7 # 8 # Use: 9 # html2man [ <man-dir> [<version-dir>] ] <file.html 10 # 11 # <Man-dir> is the directory where the man pages will be created 12 # (current directory by default). If a file name is given instead of 13 # directory then the directory of that file is used. 14 # <Version-dir> is the directory containing the ttf2pt1 files version.h 15 # and CHANGES.html which are used to generate the release name and date 16 # for the man page (by default looks in current directory and then in up to 17 # 5 ancestor directories). 18 # If the version files can not be found then the release defaults to 19 # "current" and the date defaults to today. 20 # 21 # Special formatting in the html file is: 22 # All controls are hidden within HTML comments that must occupy a whole separate line 23 # Such a line looks like: 24 # <!-- =<html2man_directive> <arguments> --> 25 # <!-- ==<pod_directive> <arguments> --> 26 # Any sort of directive must be followed by a space. The pod directives are 27 # automatically surrounded by empty lines in the output file. 28 # The html2man directives are: 29 # 30 # <!-- =defdoc <docid> <file> <section> --> 31 # Define a man page. Multiple man pages can be defined in the same HTML 32 # file. <Docid> is a short name by which this man page will be referred in the 33 # other directives. <File> is the name of the man page, and <section> is the 34 # section of the manual (do not confuse with sections within a man page). 35 # 36 # <!-- =section <docid> <page_section_name> --> 37 # All the text following this directive is copied (with translation) 38 # into the specified section of the specified man page. The sections 39 # may appear in arbitrary order, they will be rearranged to the standard 40 # order before output. Only standard section names are permitted (see @stdsect 41 # below). The pod directives which occur outside of man sections are ignored, 42 # just like the common text. The translation of HTML tags is: 43 # 44 # <br> - to paragraph break 45 # <b> - to B<> 46 # <i> - to I<> 47 # <tt> - to C<> 48 # <a href> - to F<> 49 # <ul>, <li>, </ul> - to =over 2, =item *, =back 50 # , &, <, > - to their symbols, appropriately encoded 51 # 52 # The rest of HTML tags is removed 53 # 54 # If the same section is started more than once, the text from the 55 # second appearance will be added to the first, etc. 56 # 57 # <!-- =stop --> 58 # Stop copying text to the man page. 59 # 60 # <!-- =cont --> 61 # Continue copying text to the man page, same section as before. 62 # 63 # <!-- =text <text> --> 64 # Insert this <text> into the man page (works only when copying is enabled). 65 # Characters <, >, & are converted as usual. 66 67 @mons = qw(January February March April May June July August September October November December); 68 69 $dir = $ARGV[0]; 70 $maindir = $ARGV[1]; 71 72 if($dir eq "") { 73 $dir = "."; 74 } elsif( ! -d $dir ) { 75 if( ! ($dir =~ s|\/[^/]*$||) ) { 76 $dir = "."; 77 } 78 } 79 if($maindir eq "") { 80 $maindir = "."; 81 for($i=0; $i<5; $i++) { 82 if(-f "$maindir/version.h") { 83 last; 84 } 85 $maindir = "../$maindir"; 86 } 87 } 88 89 if( open(VERFILE, "<$maindir/version.h") ) { 90 while(<VERFILE>) { 91 if( /^\s*\#define\s+TTF2PT1_VERSION\s+\"(.*)\"/ ) { 92 $release = "version $1"; 93 } 94 } 95 close(VERFILE); 96 if( $release =~ /SNAP-([0-9][0-9])([0-9][0-9])([0-9][0-9])/ ) { 97 $date = sprintf("%s %d, 20%02d", $mons[$2-1], $3, $1); 98 } elsif( open(CFILE, "<$maindir/CHANGES.html") ) { 99 while(<CFILE>) { 100 if( /\<H4\>/) { 101 last; 102 } 103 } 104 $_ = <CFILE>; 105 chomp; 106 if( $_ =~ s/^.*?-- // ) { 107 $date = $_; 108 } 109 close(CFILE); 110 } 111 } 112 113 if($release eq "") { 114 $release = "current"; 115 } 116 if($date eq "") { 117 @lt = localtime(time); 118 $date = sprintf("%s %d, %d", $mons[$lt[4]], $lt[3], 1900+$lt[5]); 119 } 120 121 #printf(STDERR "date=%s release=%s\n", $date, $release); 122 123 $writemode = 0; 124 125 while(<STDIN>) { 126 if( s/^\<\!\-\- \=(\S+)\s+//) { 127 $cmd = $1; 128 s/\s*--\>\s*$//; 129 #printf(STDERR "cmd=%s args=%s\n", $cmd, $_); 130 if($cmd =~ /^=/) { 131 if($writemode) { 132 $text{$tosect} .= "\n\n$cmd $_\n\n"; 133 } 134 } elsif($cmd eq "defdoc") { 135 @sl = split; 136 push(@allids, $sl[0]); 137 $file{$sl[0]} = $sl[1]; 138 $mansect{$sl[0]} = $sl[2]; 139 } elsif($cmd eq "section") { 140 # tosect includes the file id 141 $tosect = $_; 142 $text{$tosect} .= "\n\n"; 143 $writemode = 1; 144 } elsif($cmd eq "stop") { 145 $writemode = 0; 146 $text{$tosect} .= "\n"; 147 } elsif($cmd eq "cont") { 148 $writemode = 1; 149 } elsif($cmd eq "text") { 150 if($writemode) { 151 s/\<\;/</gi; 152 s/\>\;/>/gi; 153 s/\&\;/\&/gi; 154 $text{$tosect} .= "$_\n"; 155 } 156 } 157 } elsif($writemode) { 158 s/^\s+//; 159 160 s/\{/\&lbr;/g; 161 s/\}/\&rbr;/g; 162 163 s/\<br\>/\n\n/gi; 164 #s/\<blockquote\>/\n\n=over 4\n\n/gi; 165 #s/\<\/blockquote\>/\n\n=back\n\n/gi; 166 s/\<ul\>/\n\n=over 4\n\n/gi; 167 s/\<\/ul\>/\n\n=back\n\n/gi; 168 s/\<li\>\s*/\n\n=item \*\n\n/gi; 169 s/\<i\>(.*?)\<\/i\>/I\{\1\}/gi; 170 s/\<b\>(.*?)\<\/b\>/B\{\1\}/gi; 171 s/\<tt\>(.*?)\<\/tt\>/C\{\1\}/gi; 172 s/\<a href\=\.*?\>(.*?)\<\/a\>/F\{\1\}/gi; 173 s/\<.*?\>//g; 174 s/\{/\</g; 175 s/\}/\>/g; 176 177 s/\ \;/S< >/gi; 178 s/\&\;/\&/gi; 179 s/\<\;/E<lt>/gi; 180 s/\>\;/E<gt>/gi; 181 #s/\|/E<verbar>/g; 182 #s/\//E<sol>/g; 183 s/\&lbr\;/\{/g; 184 s/\&rbr\;/\}/g; 185 186 #printf(STDERR "section=%s add=%s", $tosect, $_); 187 $text{$tosect} .= $_; 188 } 189 } 190 191 @stdsect = ( 192 "NAME", 193 "SYNOPSIS", 194 "DESCRIPTION", 195 "OPTIONS", 196 "RETURN VALUE", 197 "ERRORS", 198 "EXAMPLES", 199 "ENVIRONMENT", 200 "FILES", 201 "SEE ALSO", 202 "NOTES", 203 "CAVEATS", 204 "DIAGNOSTICS", 205 "BUGS", 206 "RESTRICTIONS", 207 "AUTHOR", 208 "HISTORY" ); 209 210 #printf(STDERR "allids= @allids\n"); 211 for $id (@allids) { 212 #print(STDERR "creating man page $id $file{$id} $mansect{$id}\n\n"); 213 die "Unable to create pod file $dir/$file{$id}.pod" 214 unless open(PODF, ">$dir/$file{$id}.pod"); 215 print(PODF "=pod\n\n"); 216 for $sect (@stdsect) { 217 $sid = "$id $sect"; 218 #printf(STDERR "trying %s\n", $sid); 219 if(defined $text{$sid}) { 220 print(PODF "=head1 $sect\n\n$text{$sid}\n\n"); 221 } 222 } 223 print(PODF "=cut\n"); 224 close(PODF); 225 die "Unable to generate the man page $dir/$file{$id}.1" 226 if system("pod2man --section=\"$mansect{$id}\" --release=\"$release\" " 227 . "--center=\"TTF2PT1 Font Converter\" --date=\"$date\" " 228 . "$dir/$file{$id}.pod >$dir/$file{$id}.1"); 229 230 unlink("$dir/$file{$id}.pod"); 231 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |