aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>2001-02-23 02:33:28 +0000
committerJohn Beppu <beppu@lbox.org>2001-02-23 02:33:28 +0000
commit4a25d8c9c364e582f3304247ec1115a1269635d6 (patch)
tree88e970ac09f7127fc9208340ba583f1adcf97517 /docs
parent0ed9923887ca0f9bb2986269d6565cd199e13367 (diff)
downloadbusybox-w32-4a25d8c9c364e582f3304247ec1115a1269635d6.tar.gz
busybox-w32-4a25d8c9c364e582f3304247ec1115a1269635d6.tar.bz2
busybox-w32-4a25d8c9c364e582f3304247ec1115a1269635d6.zip
This is the remixed autodocufier.pl.
Diffstat (limited to 'docs')
-rwxr-xr-xdocs/autodocifier.pl255
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
6use strict; 3use strict;
4use Getopt::Long;
5
6# collect lines continued with a '\' into an array
7sub continuation {
8 my $fh = shift;
9 my @line;
7 10
8my $line; 11 while (<$fh>) {
9my $applet; 12 my $s = $_;
10my $count; 13 $s =~ s/\\\s*$//;
11my $full_usage; 14 $s =~ s/#.*$//;
12 15 push @line, $s;
13open(USAGE, 'usage.h') or die "usage.h: $!"; 16 last unless (/\\\s*$/);
14 17 }
15while (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; 22sub 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 42sub 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*$//; 66sub 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# }
79my %docs;
80
81# get command-line options
82my %opt;
83
84GetOptions(
85 \%opt,
86 "help|h",
87 "sgml|s",
88 "pod|p",
89 "verbose|v",
90);
91
92if (defined $opt{help}) {
93 print
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
105foreach (@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
127foreach my $name (sort keys %docs) {
128 print pod_for_usage($name, $docs{$name});
129}
130
131exit 0;
132
133__END__
134
135=head1 NAME
136
137autodocifier.pl - generate docs for busybox based on usage.h
138
139=head1 SYNOPSIS
140
141autodocifier.pl usage.h > something
142
143=head1 DESCRIPTION
144
145The purpose of this script is to automagically generate documentation
146for busybox using its usage.h as the original source for content.
147Currently, the same content has to be duplicated in 3 places in
148slightly different formats -- F<usage.h>, F<docs/busybox.pod>, and
149F<docs/busybox.sgml>. Duplicating the same content in these 3 places
150is tedious, so Perl has come to the rescue.
151
152This script was based on an original work by
153Erik Andersen (andersen@lineo.com).
154
155=head1 OPTIONS
156
157these control my behaviour
158
159=over 8
160
161=item --help
162
163This displays the help message.
164
165=back
166
167=head1 FILES
168
169files that I manipulate
170
171=head1 COPYRIGHT
172
173Copyright (c) 2001 John BEPPU. All rights reserved. This program is
174free software; you can redistribute it and/or modify it under the same
175terms as Perl itself.
176
177=head1 AUTHOR
178
179John BEPPU <beppu@lineo.com>
180
181=cut
182
183# $Id: autodocifier.pl,v 1.2 2001/02/23 02:33:28 beppu Exp $