1 #!/usr/local/bin/perl -- -*-perl-*-
3 # helpfiles: make help files for Z-shell builtins from the manual entries.
5 # Create help files for zsh commands in the current directory;
6 # assumes no other files are present.
7 # No overwriting check; `.' becomes `dot', `:' becomes `colon'.
9 # Any command claiming to be `same as <foo>' or `equivalent to <foo>'
10 # has its help file appended to the end of <foo>'s and replaced by a
11 # link to <foo>. (Arguably the help file should be put at the start
14 # Takes one filename argument, or stdin: the zsh manual page as a plain
15 # ascii file: `man zshbuiltins | colcrt -' (remember the -) should do
18 # If you don't have colcrt, try 'col -bx'. The x is necessary so that
19 # spaces don't turn into tabs, which messes up the calculations of
20 # indentation on machines which randomly wrap lines round to the
21 # previous line (so you see what we're up against).
24 # cd ~/zsh-4.0.1 # or wherever
27 # man zshbuiltins | colcrt - | helpfiles
29 # typeset zhelp=~/zsh-4.0.1/Help # or wherever
30 # [[ $1 = . ]] && 1=dot
31 # [[ $1 = : ]] && 1=colon
32 # if [[ $1 = compctl ]]; then
34 # elif [[ -f $zhelp/$1 ]]; then
35 # ${=PAGER:-more} $zhelp/$1
40 # now <Esc>-h works for shell builtins.
43 last if /^\s*SHELL BUILTIN COMMANDS/;
44 /zshbuiltins/ && $zb++;
45 last if ($zb && /^\s*DESCRIPTIONS/);
52 if ($cmd =~ /^\w+$/) {
54 } elsif ($cmd eq '.') {
56 } elsif ($cmd eq ':') {
65 if (/same\s*as\s*(\S+)/i || /equivalent\s*to\s*(\S+)/i) {
67 ($name =~ /[.,]$/) && chop($name);
78 if (defined($cmd = &namesub
($_))) {
79 # in case there's something nasty here like a link..
92 s/^$indentstr//o; # won't work if too many tabs
96 while (<>) { last unless /^\s*$/; }
100 $indent = length($1);
104 BUILTINS
: while (<>) {
108 if (/^\s*$/ || ($undented = (/^(\s*)/ && length($1) < $indent))) {
109 $undented && &doprint
($_);
110 while (defined($_ = <>) && /(^\w)|(^\s*$)/) {
111 # NAME is the start of the next section when in zshall.
112 # (Historical note: we used to exit on the page header,
113 # but text from the old section can continue to the
115 last BUILTINS
if /^\s*NAME\s*$/;
116 last BUILTINS
if /^STARTUP\/SHUTDOWN FILES
/;
117 last if /^zsh.*\s\d$/; # GNU nroff -man end-of-page marker
119 if (/^\s*Page/ || /^zsh.*\s\d$/) {
122 } while (defined($_) && /^\s*$/);
123 if (/^\s*ZSHBUILTINS/) {
126 } while (defined($_) && /^\s*$/);
129 if (/^(\s*)/ && length($1) < $indent) {
130 # This may be just a bug on the SGI, or maybe something
131 # more sinister (don\'t laugh, this is nroff).
136 } while (defined($_) && /^\s*$/);
137 last unless defined($_);
139 if (/^(\s+)(\S+)/ && length($1) == $indent) {
145 if (defined($defer)) {
147 &doprint
("$_$defer");
154 &doprint
($_) if $print;
161 foreach $file (<*>) {
163 if ($sameas = (&getsame
($_ = <IN
>) || &getsame
($_ = <IN
>))) {
164 defined($sameas = &namesub
($sameas)) || next;
165 # print "$file is the same as $sameas\n";
168 # Copy this to base builtin.
169 open (OUT
, ">>$sameas");
172 while (<IN
>) { print; }
177 # Make this a link to that.
179 symlink ($sameas, $file);