3 # create-html-usage.pl -- insert usage lines into README
4 # Cpoyright (C) 2015,2017 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 $usage =~ s/[ \t]*\n[ \t]+/ /gs;
28 return split "\n", $usage;
29 } elsif ($name eq "help") {
30 return "tg help [-w] [<command>]";
31 } elsif ($name eq "status") {
32 my $tgsthelp = $ENV{TG_STATUS_HELP_USAGE
} || "status";
33 return "tg $tgsthelp";
43 while (length($s) > $w && $s =~ /^(.{1,$w})(?<=\w)\b[ \t]+(.+)$/s) {
47 $ans .= $s if $s !~ /^\s*$/;
52 $textmode=1, shift if defined($ARGV[0]) && $ARGV[0] eq '--text';
54 while (my $line = <>) {
56 1 while $line =~ s/\t+/" " x (($+[0] - $-[0]) * 8 - $-[0] % 8)/e;
57 $line =~ s
'^``([^``\n].*)``$'wrap
(78, 4, $1)'e if $textmode;
58 $line =~ s'^(\s
*):`(.+?)`_
:'"$1$2 "'e
if $textmode;
59 $line =~ s
'^(\s*):(\w+?)_?:'"$1$2"'e if $textmode;
62 if ($line =~ /^[~]+$/ && $last =~ /^tg ([^\s]+)$/) {
63 my @usage = get_tg_usage($1);
67 printf "%s", join("",map({wrap(78, 12, "$tab$_")."\n"} @usage));
69 printf "%s", join("",map({"$tab| ".'``'.$_.'``'."\n"} @usage));
78 printf "%s\n", $last if defined($last);