3 # create-html-usage.pl -- insert usage lines into README
4 # Cpoyright (C) 2015 Kyle J. McKay. All rights reserved.
5 # License GPLv2 or, at your option, any later version.
12 my $mydir = dirname
($0);
19 for ("$mydir/tg-$name", "$mydir/tg--$name") {
20 -x
$_ and $xname=$_, last;
23 my $usage = `"$xname" -h 2>&1`;
25 $usage =~ s/^(Usage|\s+Or):\s*//mig;
26 return split "\n", $usage;
27 } elsif ($name eq "help") {
28 return "tg help [-w] [<command>]";
29 } elsif ($name eq "status") {
30 return "tg status [-v] [--exit-code]";
40 while (length($s) > $w && $s =~ /^(.{1,$w})(?<=\w)\b[ \t]+(.+)$/s) {
44 $ans .= $s if $s !~ /^\s*$/;
49 $textmode=1, shift if defined($ARGV[0]) && $ARGV[0] eq '--text';
51 while (my $line = <>) {
53 1 while $line =~ s/\t+/" " x (($+[0] - $-[0]) * 8 - $-[0] % 8)/e;
54 $line =~ s
'^``(.*)``$'wrap
(78, 4, $1)'e if $textmode;
55 $line =~ s'^(\s
*):`(.+?)`_
:'"$1$2 "'e
if $textmode;
58 if ($line =~ /^[~]+$/ && $last =~ /^tg ([^\s]+)$/) {
59 my @usage = get_tg_usage
($1);
63 printf "%s", join("",map({wrap
(78, 12, "$tab$_")."\n"} @usage));
65 printf "%s", join("",map({"$tab| ".'``'.$_.'``'."\n"} @usage));
74 printf "%s\n", $last if defined($last);