| 1 |
#!/usr/bin/env perl |
| 2 |
# Written by <[email protected]> |
| 3 |
#%DESC Show shell/Perl script flags |
| 4 |
# |
| 5 |
# Note the ":" for an option that is not to be documented. |
| 6 |
#For example: |
| 7 |
# In Bash scripts: |
| 8 |
# |
| 9 |
# --help) |
| 10 |
# exec sh-flags $0 |
| 11 |
# ;; |
| 12 |
# -n) # Only configure - no compilation |
| 13 |
# no_compilation=1 |
| 14 |
# shift |
| 15 |
# ;; |
| 16 |
# -q) # show configuration parameters |
| 17 |
# qflag=1 |
| 18 |
# shift |
| 19 |
# ;; |
| 20 |
# -old) : # Unused, for backward compatibility |
| 21 |
# shift |
| 22 |
# ;; |
| 23 |
# |
| 24 |
# |
| 25 |
# In Perl scripts: |
| 26 |
# |
| 27 |
#while (defined $ARGV[0] && $ARGV[0] =~ /^-(.*)/) { |
| 28 |
# my $argv = shift; |
| 29 |
# my $flag = $1; |
| 30 |
|
| 31 |
# $flag eq '-help' and do { |
| 32 |
# exec('sh-flags', $0) |
| 33 |
# }; |
| 34 |
# $flag eq 'l' and do { #- -l Use LEN in cost comparisons |
| 35 |
# $lflag = $argv; |
| 36 |
# next; |
| 37 |
# }; |
| 38 |
# (($flag eq 'md5') || ($flag eq 'md5u')) and do { #- -md5 Emit md5 |
| 39 |
# #- -md5u Same but discard dups |
| 40 |
# $md5flag = $argv; |
| 41 |
# next; |
| 42 |
# }; |
| 43 |
#} |
| 44 |
|
| 45 |
use strict; |
| 46 |
use warnings; |
| 47 |
|
| 48 |
(my $prog = $0) =~ s/.*\///; |
| 49 |
die "$prog: Missing argument\n" unless defined $ARGV[0]; |
| 50 |
my $printflags; |
| 51 |
my $infile = $ARGV[0]; |
| 52 |
open(F, $infile) or die "$prog: Cannot open '$infile': $!\n"; |
| 53 |
|
| 54 |
while (<F>) { |
| 55 |
if (/^#%DESC|^#%?Usage/i) |
| 56 |
{ |
| 57 |
print; |
| 58 |
next; |
| 59 |
} |
| 60 |
# Skip all lines unless case label with a comment, or #- |
| 61 |
# But ignore ## comments. |
| 62 |
if (/^\s*([^(]+)\)\s+#[^#](.*)/ || / #-\s+(\S+)\s+(\S+.*)$/) |
| 63 |
{ |
| 64 |
unless ($printflags) |
| 65 |
{ |
| 66 |
print "Flags:\n"; |
| 67 |
$printflags = 1; |
| 68 |
} |
| 69 |
print "$1: $2\n"; |
| 70 |
} |
| 71 |
} |