aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-02-22 22:47:06 +0000
committerEric Andersen <andersen@codepoet.org>2001-02-22 22:47:06 +0000
commite13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43 (patch)
tree62affbc16948c85f27d2b349f5f7035b9540bedb /docs
parentffc40bf3de05a50a0f58be80fe76202b6b5972f8 (diff)
downloadbusybox-w32-e13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43.tar.gz
busybox-w32-e13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43.tar.bz2
busybox-w32-e13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43.zip
First pass at making up an automagical usage message extractor, which
will be used (when it works) to autogenerate documentation. Based on code written by Mark Whitley.
Diffstat (limited to 'docs')
-rwxr-xr-xdocs/autodocifier.pl88
1 files changed, 88 insertions, 0 deletions
diff --git a/docs/autodocifier.pl b/docs/autodocifier.pl
new file mode 100755
index 000000000..2ce1edd75
--- /dev/null
+++ b/docs/autodocifier.pl
@@ -0,0 +1,88 @@
1#!/usr/bin/perl -w
2#
3# autodocufier.pl - extracts usage messages from busybox usage.c and
4# pretty-prints them to stdout.
5
6use strict;
7
8my $line;
9my $applet;
10my $count;
11my $full_usage;
12
13open(USAGE, 'usage.h') or die "usage.h: $!";
14
15while (defined($line = <USAGE>)) {
16 $count=0;
17 if ($line =~ /^#define (\w+)_trivial_usage/) {
18 # grab the applet name
19 $applet = $1;
20 print "\n$applet:\n";
21
22 while (defined($line = <USAGE>)) {
23 if ( $count==0 ) {
24 $count++;
25 print "\t$applet ";
26 } else { print "\t"; }
27 $full_usage = $applet . "_full_usage";
28 last if ( $line =~ /$full_usage/ );
29 # Skip preprocessor stuff
30 next if $line =~ /^\s*#/;
31 # Strip the continuation char
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 }
51 printf("\n");
52 while (defined($line = <USAGE>)) {
53 if ( $count==0 ) {
54 $count++;
55 print "\t$applet ";
56 } else { print "\t"; }
57 # we're done if we hit a line lacking a '\' at the end
58 #last if ! $line !~ /\\$/;
59 if ( $line !~ /\\$/ ) {
60 #print "Got one at $line\n";
61 last;
62 }
63 # Skip preprocessor stuff
64 next if $line =~ /^\s*#/;
65 # Strip the continuation char
66 $line =~ s/\\$//;
67 # strip quotes off
68 $line =~ s/^\s*"//;
69 $line =~ s/"\s*$//;
70 # substitute escape sequences
71 # (there's probably a better way to do this...)
72 $line =~ s/\\t/ /g;
73 $line =~ s/\\n//g;
74 # Automagically #define all preprocessor lines
75 #$line =~ s/USAGE_\w+\([\s]*?(".*?")\s,\s".*"\s\)/$1/sg;
76 $line =~ s/USAGE_\w+\(\s*?(".*").*\)/$1/sg;
77 # Strip any empty quotes out
78 $line =~ s/"[\s]*"//sg;
79 # strip line end quotes, again
80 $line =~ s/^\s*"//;
81 $line =~ s/"\s*$//;
82
83 # Finally, print it
84 print "$line\n";
85 }
86 printf("\n\n");
87 }
88}