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 my $tgsthelp = $ENV{TG_STATUS_HELP_USAGE
} || "status";
31 return "tg $tgsthelp";
41 while (length($s) > $w && $s =~ /^(.{1,$w})(?<=\w)\b[ \t]+(.+)$/s) {
45 $ans .= $s if $s !~ /^\s*$/;
50 $textmode=1, shift if defined($ARGV[0]) && $ARGV[0] eq '--text';
52 while (my $line = <>) {
54 1 while $line =~ s/\t+/" " x (($+[0] - $-[0]) * 8 - $-[0] % 8)/e;
55 $line =~ s
'^``(.*)``$'wrap
(78, 4, $1)'e if $textmode;
56 $line =~ s'^(\s
*):`(.+?)`_
:'"$1$2 "'e
if $textmode;
59 if ($line =~ /^[~]+$/ && $last =~ /^tg ([^\s]+)$/) {
60 my @usage = get_tg_usage
($1);
64 printf "%s", join("",map({wrap
(78, 12, "$tab$_")."\n"} @usage));
66 printf "%s", join("",map({"$tab| ".'``'.$_.'``'."\n"} @usage));
75 printf "%s\n", $last if defined($last);