diff options
| author | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-02-23 02:33:28 +0000 |
|---|---|---|
| committer | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-02-23 02:33:28 +0000 |
| commit | a3c90f196ebfc9ce3a9bdadc62d86b7f13d090b4 (patch) | |
| tree | 88e970ac09f7127fc9208340ba583f1adcf97517 /docs | |
| parent | 7e94a9be5910b3b2c5d14b398b54391a2accfb93 (diff) | |
| download | busybox-w32-a3c90f196ebfc9ce3a9bdadc62d86b7f13d090b4.tar.gz busybox-w32-a3c90f196ebfc9ce3a9bdadc62d86b7f13d090b4.tar.bz2 busybox-w32-a3c90f196ebfc9ce3a9bdadc62d86b7f13d090b4.zip | |
This is the remixed autodocufier.pl.
git-svn-id: svn://busybox.net/trunk/busybox@1901 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'docs')
| -rwxr-xr-x | docs/autodocifier.pl | 255 |
1 files changed, 175 insertions, 80 deletions
diff --git a/docs/autodocifier.pl b/docs/autodocifier.pl index 2ce1edd75..e5b9767d2 100755 --- a/docs/autodocifier.pl +++ b/docs/autodocifier.pl | |||
| @@ -1,88 +1,183 @@ | |||
| 1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
| 2 | # | ||
| 3 | # autodocufier.pl - extracts usage messages from busybox usage.c and | ||
| 4 | # pretty-prints them to stdout. | ||
| 5 | 2 | ||
| 6 | use strict; | 3 | use strict; |
| 4 | use Getopt::Long; | ||
| 5 | |||
| 6 | # collect lines continued with a '\' into an array | ||
| 7 | sub continuation { | ||
| 8 | my $fh = shift; | ||
| 9 | my @line; | ||
| 7 | 10 | ||
| 8 | my $line; | 11 | while (<$fh>) { |
| 9 | my $applet; | 12 | my $s = $_; |
| 10 | my $count; | 13 | $s =~ s/\\\s*$//; |
| 11 | my $full_usage; | 14 | $s =~ s/#.*$//; |
| 12 | 15 | push @line, $s; | |
| 13 | open(USAGE, 'usage.h') or die "usage.h: $!"; | 16 | last unless (/\\\s*$/); |
| 14 | 17 | } | |
| 15 | while (defined($line = <USAGE>)) { | 18 | return @line; |
| 16 | $count=0; | 19 | } |
| 17 | if ($line =~ /^#define (\w+)_trivial_usage/) { | 20 | |
| 18 | # grab the applet name | 21 | # regex && eval away unwanted strings from documentation |
| 19 | $applet = $1; | 22 | sub beautify { |
| 20 | print "\n$applet:\n"; | 23 | my $text = shift; |
| 21 | 24 | $text =~ s/USAGE_\w+\([\s]*?(".*?").*?\)/$1/sg; | |
| 22 | while (defined($line = <USAGE>)) { | 25 | $text =~ s/"[\s]*"//sg; |
| 23 | if ( $count==0 ) { | 26 | my @line = split("\n", $text); |
| 24 | $count++; | 27 | $text = join('', |
| 25 | print "\t$applet "; | 28 | map { eval } |
| 26 | } else { print "\t"; } | 29 | map { qq[ sprintf(qq#$_#) ] } |
| 27 | $full_usage = $applet . "_full_usage"; | 30 | map { |
| 28 | last if ( $line =~ /$full_usage/ ); | 31 | s/^\s*//; |
| 29 | # Skip preprocessor stuff | 32 | s/"//g; |
| 30 | next if $line =~ /^\s*#/; | 33 | s/% /%% /g; |
| 31 | # Strip the continuation char | 34 | $_ |
| 32 | $line =~ s/\\$//; | ||
| 33 | # strip quotes off | ||
| 34 | $line =~ s/^\s*"//; | ||
| 35 | $line =~ s/"\s*$//; | ||
| 36 | # substitute escape sequences | ||
| 37 | # (there's probably a better way to do this...) | ||
| 38 | $line =~ s/\\t/ /g; | ||
| 39 | $line =~ s/\\n//g; | ||
| 40 | # fix up preprocessor macros | ||
| 41 | $line =~ s/USAGE_\w+\([\s]*?(".*?").*?\)/$1/sg; | ||
| 42 | # Strip any empty quotes out | ||
| 43 | $line =~ s/"[\s]*"//sg; | ||
| 44 | # strip line end quotes, again | ||
| 45 | $line =~ s/^\s*"//; | ||
| 46 | $line =~ s/"\s*$//; | ||
| 47 | |||
| 48 | # Finally, print it | ||
| 49 | print "$line\n"; | ||
| 50 | } | 35 | } |
| 51 | printf("\n"); | 36 | @line |
| 52 | while (defined($line = <USAGE>)) { | 37 | ); |
| 53 | if ( $count==0 ) { | 38 | return $text; |
| 54 | $count++; | 39 | } |
| 55 | print "\t$applet "; | 40 | |
| 56 | } else { print "\t"; } | 41 | # generate POD for an applet |
| 57 | # we're done if we hit a line lacking a '\' at the end | 42 | sub pod_for_usage { |
| 58 | #last if ! $line !~ /\\$/; | 43 | my $name = shift; |
| 59 | if ( $line !~ /\\$/ ) { | 44 | my $usage = shift; |
| 60 | #print "Got one at $line\n"; | 45 | |
| 61 | last; | 46 | my $trivial = $usage->{trivial}; |
| 62 | } | 47 | $trivial !~ /^\s/ && $trivial =~s/(?<!\w)(-\w+)/B<$1>/sxg; |
| 63 | # Skip preprocessor stuff | 48 | |
| 64 | next if $line =~ /^\s*#/; | 49 | my @full = |
| 65 | # Strip the continuation char | 50 | map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ } |
| 66 | $line =~ s/\\$//; | 51 | split("\n", $usage->{full}); |
| 67 | # strip quotes off | 52 | |
| 68 | $line =~ s/^\s*"//; | 53 | return |
| 69 | $line =~ s/"\s*$//; | 54 | "-------------------------------\n". |
| 70 | # substitute escape sequences | 55 | "\n". |
| 71 | # (there's probably a better way to do this...) | 56 | "=item $name". |
| 72 | $line =~ s/\\t/ /g; | 57 | "\n\n". |
| 73 | $line =~ s/\\n//g; | 58 | "$name $trivial". |
| 74 | # Automagically #define all preprocessor lines | 59 | "\n\n". |
| 75 | #$line =~ s/USAGE_\w+\([\s]*?(".*?")\s,\s".*"\s\)/$1/sg; | 60 | join("\n", @full). |
| 76 | $line =~ s/USAGE_\w+\(\s*?(".*").*\)/$1/sg; | 61 | "\n\n" |
| 77 | # Strip any empty quotes out | 62 | ; |
| 78 | $line =~ s/"[\s]*"//sg; | 63 | } |
| 79 | # strip line end quotes, again | 64 | |
| 80 | $line =~ s/^\s*"//; | 65 | # generate SGML for an applet |
| 81 | $line =~ s/"\s*$//; | 66 | sub sgml_for_usage { |
| 82 | 67 | my $name = shift; | |
| 83 | # Finally, print it | 68 | my $usage = shift; |
| 84 | print "$line\n"; | 69 | return |
| 70 | "FIXME"; | ||
| 71 | } | ||
| 72 | |||
| 73 | # the keys are applet names, and the values will contain | ||
| 74 | # hashrefs of the form: | ||
| 75 | # { | ||
| 76 | # trivial => "...", | ||
| 77 | # full => "...", | ||
| 78 | # } | ||
| 79 | my %docs; | ||
| 80 | |||
| 81 | # get command-line options | ||
| 82 | my %opt; | ||
| 83 | |||
| 84 | GetOptions( | ||
| 85 | \%opt, | ||
| 86 | "help|h", | ||
| 87 | "sgml|s", | ||
| 88 | "pod|p", | ||
| 89 | "verbose|v", | ||
| 90 | ); | ||
| 91 | |||
| 92 | if (defined $opt{help}) { | ||
| 93 | |||
| 94 | "$0 [OPTION]... [FILE]...\n", | ||
| 95 | "\t--help\n", | ||
| 96 | "\t--sgml\n", | ||
| 97 | "\t--pod\n", | ||
| 98 | "\t--verbose\n", | ||
| 99 | ; | ||
| 100 | exit 1; | ||
| 101 | } | ||
| 102 | |||
| 103 | # | ||
| 104 | # collect documenation into %docs | ||
| 105 | foreach (@ARGV) { | ||
| 106 | open(USAGE, $_) || die("$0: $!"); | ||
| 107 | my $fh = *USAGE; | ||
| 108 | my ($applet, $type, @line); | ||
| 109 | while (<$fh>) { | ||
| 110 | |||
| 111 | if (/^#define (\w+)_(\w+)_usage/) { | ||
| 112 | $applet = $1; | ||
| 113 | $type = $2; | ||
| 114 | @line = continuation($fh); | ||
| 115 | my $doc = $docs{$applet} ||= { }; | ||
| 116 | |||
| 117 | my $text = join("\n", @line); | ||
| 118 | $doc->{$type} = beautify($text); | ||
| 85 | } | 119 | } |
| 86 | printf("\n\n"); | 120 | |
| 87 | } | 121 | } |
| 88 | } | 122 | } |
| 123 | |||
| 124 | #use Data::Dumper; | ||
| 125 | #print Data::Dumper->Dump([\%docs], [qw(docs)]); | ||
| 126 | |||
| 127 | foreach my $name (sort keys %docs) { | ||
| 128 | print pod_for_usage($name, $docs{$name}); | ||
| 129 | } | ||
| 130 | |||
| 131 | exit 0; | ||
| 132 | |||
| 133 | __END__ | ||
| 134 | |||
| 135 | =head1 NAME | ||
| 136 | |||
| 137 | autodocifier.pl - generate docs for busybox based on usage.h | ||
| 138 | |||
| 139 | =head1 SYNOPSIS | ||
| 140 | |||
| 141 | autodocifier.pl usage.h > something | ||
| 142 | |||
| 143 | =head1 DESCRIPTION | ||
| 144 | |||
| 145 | The purpose of this script is to automagically generate documentation | ||
| 146 | for busybox using its usage.h as the original source for content. | ||
| 147 | Currently, the same content has to be duplicated in 3 places in | ||
| 148 | slightly different formats -- F<usage.h>, F<docs/busybox.pod>, and | ||
| 149 | F<docs/busybox.sgml>. Duplicating the same content in these 3 places | ||
| 150 | is tedious, so Perl has come to the rescue. | ||
| 151 | |||
| 152 | This script was based on an original work by | ||
| 153 | Erik Andersen (andersen@lineo.com). | ||
| 154 | |||
| 155 | =head1 OPTIONS | ||
| 156 | |||
| 157 | these control my behaviour | ||
| 158 | |||
| 159 | =over 8 | ||
| 160 | |||
| 161 | =item --help | ||
| 162 | |||
| 163 | This displays the help message. | ||
| 164 | |||
| 165 | =back | ||
| 166 | |||
| 167 | =head1 FILES | ||
| 168 | |||
| 169 | files that I manipulate | ||
| 170 | |||
| 171 | =head1 COPYRIGHT | ||
| 172 | |||
| 173 | Copyright (c) 2001 John BEPPU. All rights reserved. This program is | ||
| 174 | free software; you can redistribute it and/or modify it under the same | ||
| 175 | terms as Perl itself. | ||
| 176 | |||
| 177 | =head1 AUTHOR | ||
| 178 | |||
| 179 | John BEPPU <beppu@lineo.com> | ||
| 180 | |||
| 181 | =cut | ||
| 182 | |||
| 183 | # $Id: autodocifier.pl,v 1.2 2001/02/23 02:33:28 beppu Exp $ | ||
