6 print "Usage: parsedoc.pl <docfile.doc>\n";
12 sub add_option_to_manpage
21 $shortopt =~ s
|-|\\-|;
22 $params =~ s
|<(.*)>|\\fI\
1\\fR
|;
23 $longdoc =~ s/<([a-zA-Z0-9_-]+)>/\\fI\1\\fR/;
24 #$longdoc =~ s/%/%%$1/g;
25 print manpage
<< "EOF"
27 \\fB
\\-$shortopt\\fR
, \\fB
\\-\\-$longopt\\fR
$params
33 sub add_option_to_help
42 my $s1 = " "x
(2-length($shortopt));
43 my $s2 = " "x
(20-length($longopt." ".$params));
46 $paramhelp .= " printf(\"-$shortopt$s1, --$longopt $params$s2$doc\\n\");\n";
49 sub add_header_to_manpage
53 my $short_description = shift;
54 my $long_description = shift;
56 my $date = `date +"%B %Y"`;
60 $long_description =~ s/([^\\])-/\1\\-/g;
62 my @chunks = split(/\n/,$usage);
64 foreach my $u (@chunks) {
65 $u =~ s/%s/$progname/g;
66 $newusage .= "$p.B $u\n";
69 $newusage =~ s/([^\\])-/\1\\-/g;
70 print manpage
<< "EOF"
71 .TH
$progname "1" "$date" "$progname" "$package"
73 $progname \\- $short_description
82 open(fi
, "$file") or die "File not found";
84 my $package = "swftools";
86 $progname =~ s
|(^/?([^/]+/))*([^/]+).doc
|$3|;
89 open(manpage
, ">$path$progname.1") or die;
92 my $short_description = "";
93 my $long_description = "";
102 $short_description .= $_;
106 $long_description .= $_;
109 add_header_to_manpage
($package, $progname, $short_description, $long_description, $usage);
118 if(/^-([^\s,]+)[\s,]+--([^\s]+)(\s+(.*))?$/) {
133 $longdoc = $doc if(!$longdoc || ($longdoc =~ /^\s*$/));
135 $shortopts[$numopts] = $shortopt;
136 $longopts[$numopts] = $longopt;
139 add_option_to_manpage
($shortopt,$longopt,$params,$doc,$longdoc);
140 add_option_to_help
($shortopt,$longopt,$params,$doc,$longdoc);
153 $tail =~ s/([^\\])-/\1\\-/g;
159 my $filename = "$path$progname.c";
161 if(!open($cfile, "<$filename")) {
162 $filename = "$path$progname.cpp";
163 if(!open($cfile, "<$filename")) {
164 $filename = "$path$progname.cc";
165 if(!open($cfile, "<$filename")) {
166 $filename = "$path$progname.c++";
167 open($cfile, "<$filename") or die;
175 if(/void\s*args_callback_usage.*\(.*\*/) {
176 print "substituting usage in $filename\n";
178 $src .= "void args_callback_usage(char *name)\n";
180 $src .= " printf(\"\\n\");\n";
184 my @chunks = split(/\n/,$usage);
185 my $prefix = "Usage:";
187 foreach $u (@chunks) {
189 $src .= " printf(\"$prefix $u\\n\", name);\n";
192 $src .= " printf(\"$prefix $u\\n\");\n";
196 $src .= " printf(\"\\n\");\n";
198 $src .= "$paramhelp";
200 $src .= " printf(\"\\n\");\n";
205 if(/^\s*(static\s+)?(struct\s+)?options_t.*=/) {
206 print "substituting options_t in $filename\n";
211 $src .= "static struct options_t options[] = {\n";
212 for(my $t=0;$t<$numopts;$t++) {
213 my $s = $shortopts[$t];
214 my $l = $longopts[$t];
215 $src .= "{\"$s\", \"$l\"},\n";
217 $src .= "{0,0}\n};\n";
224 open($cfile, ">$filename") or die;