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));
45 $paramhelp .= " printf(\"-$shortopt$s1, --$longopt $params$s2$doc\\n\");\n";
48 sub add_header_to_manpage
52 my $short_description = shift;
53 my $long_description = shift;
55 my $date = `date +"%B %Y"`;
62 $u =~ s/%s/$progname/g;
63 $newusage .= "$p.B $u\n";
67 print manpage << "EOF"
68 .TH $progname "1" "$date" "$progname" "$package"
70 $progname - $short_description
79 open(fi, "$file") or die "File not found";
81 my $package = "swftools";
83 $progname =~ s|(^/?([^/]+/))*([^/]+).doc|$3|;
86 open(manpage, ">$path$progname.1") or die;
89 my $short_description = "";
90 my $long_description = "";
99 $short_description .= $_;
103 $long_description .= $_;
106 add_header_to_manpage($package, $progname, $short_description, $long_description, $usage);
115 if(/^-([^\s,]+)[\s,]+--([^\s]+)(\s+(.*))?$/) {
130 $longdoc = $doc if(!$longdoc || ($longdoc =~ /^\s*$/));
132 $shortopts[$numopts] = $shortopt;
133 $longopts[$numopts] = $longopt;
136 add_option_to_manpage($shortopt,$longopt,$params,$doc,$longdoc);
137 add_option_to_help($shortopt,$longopt,$params,$doc,$longdoc);
155 my $filename = "$path$progname.c";
157 if(!open($cfile, "<$filename")) {
158 $filename = "$path$progname.cpp";
159 if(!open($cfile, "<$filename")) {
160 $filename = "$path$progname.cc";
161 if(!open($cfile, "<$filename")) {
162 $filename = "$path$progname.c++";
163 open($cfile, "<$filename") or die;
171 if(/void\s*args_callback_usage.*\(.*\*/) {
172 print "substituting usage in $filename\n";
174 $src .= "void args_callback_usage(char *name)\n";
176 $src .= " printf(\"\\n\");\n";
181 my $prefix = "Usage:";
185 $src .= " printf(\"$prefix $u\\n\", name);\n";
187 $src .= " printf(\"$prefix $u\\n\");\n";
191 $src .= " printf(\"\\n\");\n";
193 $src .= "$paramhelp";
195 $src .= " printf(\"\\n\");\n";
200 if(/^\s*(static\s+)?(struct\s+)?options_t.*=/) {
201 print "substituting options_t in $filename\n";
206 $src .= "static struct options_t options[] = {\n";
207 for(my $t=0;$t<$numopts;$t++) {
208 my $s = $shortopts[$t];
209 my $l = $longopts[$t];
210 $src .= "{\"$s\", \"$l\"},\n";
212 $src .= "{0,0}\n};\n";
219 open($cfile, ">$filename") or die;