summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorEric Andersen2001-02-22 22:47:06 +0000
committerEric Andersen2001-02-22 22:47:06 +0000
commite13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43 (patch)
tree62affbc16948c85f27d2b349f5f7035b9540bedb /docs
parentffc40bf3de05a50a0f58be80fe76202b6b5972f8 (diff)
downloadbusybox-e13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43.zip
busybox-e13bc0bc68363e8e8c413cdf0cb2ba6fd67c8b43.tar.gz
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 0000000..2ce1edd
--- /dev/null
+++ b/docs/autodocifier.pl
@@ -0,0 +1,88 @@
+#!/usr/bin/perl -w
+#
+# autodocufier.pl - extracts usage messages from busybox usage.c and
+# pretty-prints them to stdout.
+
+use strict;
+
+my $line;
+my $applet;
+my $count;
+my $full_usage;
+
+open(USAGE, 'usage.h') or die "usage.h: $!";
+
+while (defined($line = <USAGE>)) {
+ $count=0;
+ if ($line =~ /^#define (\w+)_trivial_usage/) {
+ # grab the applet name
+ $applet = $1;
+ print "\n$applet:\n";
+
+ while (defined($line = <USAGE>)) {
+ if ( $count==0 ) {
+ $count++;
+ print "\t$applet ";
+ } else { print "\t"; }
+ $full_usage = $applet . "_full_usage";
+ last if ( $line =~ /$full_usage/ );
+ # Skip preprocessor stuff
+ next if $line =~ /^\s*#/;
+ # Strip the continuation char
+ $line =~ s/\\$//;
+ # strip quotes off
+ $line =~ s/^\s*"//;
+ $line =~ s/"\s*$//;
+ # substitute escape sequences
+ # (there's probably a better way to do this...)
+ $line =~ s/\\t/ /g;
+ $line =~ s/\\n//g;
+ # fix up preprocessor macros
+ $line =~ s/USAGE_\w+\([\s]*?(".*?").*?\)/$1/sg;
+ # Strip any empty quotes out
+ $line =~ s/"[\s]*"//sg;
+ # strip line end quotes, again
+ $line =~ s/^\s*"//;
+ $line =~ s/"\s*$//;
+
+ # Finally, print it
+ print "$line\n";
+ }
+ printf("\n");
+ while (defined($line = <USAGE>)) {
+ if ( $count==0 ) {
+ $count++;
+ print "\t$applet ";
+ } else { print "\t"; }
+ # we're done if we hit a line lacking a '\' at the end
+ #last if ! $line !~ /\\$/;
+ if ( $line !~ /\\$/ ) {
+ #print "Got one at $line\n";
+ last;
+ }
+ # Skip preprocessor stuff
+ next if $line =~ /^\s*#/;
+ # Strip the continuation char
+ $line =~ s/\\$//;
+ # strip quotes off
+ $line =~ s/^\s*"//;
+ $line =~ s/"\s*$//;
+ # substitute escape sequences
+ # (there's probably a better way to do this...)
+ $line =~ s/\\t/ /g;
+ $line =~ s/\\n//g;
+ # Automagically #define all preprocessor lines
+ #$line =~ s/USAGE_\w+\([\s]*?(".*?")\s,\s".*"\s\)/$1/sg;
+ $line =~ s/USAGE_\w+\(\s*?(".*").*\)/$1/sg;
+ # Strip any empty quotes out
+ $line =~ s/"[\s]*"//sg;
+ # strip line end quotes, again
+ $line =~ s/^\s*"//;
+ $line =~ s/"\s*$//;
+
+ # Finally, print it
+ print "$line\n";
+ }
+ printf("\n\n");
+ }
+}