This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / dist-3.0at70b / jmake / bindex
1 #!/usr/bin/perl
2         eval 'exec perl -S $0 "$@"'
3                 if $runnning_under_some_shell;
4
5 # $Id: bindex.SH,v 3.0.1.1 1993/08/19 06:42:12 ram Exp $
6 #
7 #  Copyright (c) 1991-1993, Raphael Manfredi
8 #  
9 #  You may redistribute only under the terms of the Artistic Licence,
10 #  as specified in the README file that comes with the distribution.
11 #  You may reuse parts of this distribution only within the terms of
12 #  that same Artistic Licence; a copy of which may be found at the root
13 #  of the source tree for dist 3.0.
14 #
15 # $Log: bindex.SH,v $
16 # Revision 3.0.1.1  1993/08/19  06:42:12  ram
17 # patch1: leading config.sh searching was not aborting properly
18 #
19 # Revision 3.0  1993/08/18  12:04:13  ram
20 # Baseline for dist 3.0 netwide release.
21 #
22
23 $file = "files/Jmake.rules";
24
25 open(INDEX, ">Index") || die "Cannot create Index.\n";
26 open(RULES, "$file") || die "Cannot open $file.\n";
27
28 print INDEX
29 "[This Index is automatically generated from Jmake.rules file. Do not
30 edit this file or your changes will be lost. Edit Jmake.rules instead.]
31
32 This file contains a listing of all the macros that can be used in a
33 Jmakefile. Only a few of these should be used in the Jmakefile (they
34 are the top-level macros). However, some low-level ones may be useful,
35 but it is up to you to make that decision. This explains why this file
36 holds all the available macros for jmake.
37
38 In the following listing, the macros are separated by a line of dashes.
39 The signature of the macro is given, then a small comment of what it
40 does precedes the actual definition.
41
42 Lines preceded by '->' show the set of symbols defined when the macro is
43 used. Initialization lines are shown as-is, i.e. have the form SYM = val
44 while concatenation is shown by SYM += val (which means val is added to
45 the value of SYM).
46
47 Conditional lines are preceded by tests like (if SYM). This means the line
48 is to be kept if and only if the symbol SYM is defined. Other internal
49 requests are not formatted yet.
50
51 ";
52 $inrule = 0;                    # Not inside a rule at the beginning
53 $incomment = 0;                 # Not inside a comment
54 $last_was_text = 0;             # Last line was not a rule text
55 while (<RULES>) {
56         $inrule || next unless /^\s\*\s(\w+)\s*:/;
57         if ($inrule) {          # We are already in a rule
58                 if ($incomment) {
59                         if (m|^\s*\*/|) {       # End of comment
60                                 $incomment = 0;
61                                 $Comment{$current} .= "\n";
62                         } else {
63                                 s/^\s*\*\s*//;  # Remove leading comment sign
64                                 $Comment{$current} .= "    $_";
65                         }
66                         next;           # Anyway, go to next line
67                 }
68                 if (/^\s*$/) {          # Empty line = end of rule
69                         $inrule = 0;
70                         next;
71                 }
72                 # Here, we have to print the body of the rule, after some cleaning
73                 s/(@#|@@|@!)\\$//;              # Remove final continuations
74                 s/^(#define.*)\\/$1/;   # Remove single '\' on first rule line
75                 s/\|rule:\s*$/\n/;
76                 s/\|rule:\s+/    /;             # Remove rule markers
77                 s/\|rule://;
78                 s/%(\w+):\|skip/#ifdef $1/;             # Deal with ugly skip syntax
79                 s/\?(\w+):\|skip/#ifndef $1/;   # Deal with ugly skip syntax
80                 s/\-skip/#endif/;
81                 s/\?(\w+):/(if $1) /;   # Simple '?' test
82                 s/%(\w+):/(not $1) /;   # Simple '%' test
83                 s/\|suffix/.SUFFIXES:/; # Make suffix command explicit
84                 s/\t/    /g;                    # Expand all tabs to 4 chars
85                 s/\s*$/\n/;                             # Remove any trailing space
86                 s|\^\^|/**/|;                   # Restore ^^ to the more visual /**/
87                 if (/^$/) {                             # If empty line
88                         $Index{$current} .= "\n" if $last_was_text;
89                         $last_was_text = 0;
90                         next;
91                 }
92                 if (/^[>+]/) {                  # Special commands
93                         if (s/^>\s*//) {                                                # Wanted symbol
94                                 chop;
95                                 $Wants{$current} .= " $_";
96                         } elsif (/^\+\+\s*(\S+)\s*(.*)/) {              # Added symbol
97                                 $Added{$current} .= "\t$1 += $2\n";
98                         } else {
99                                 s/^\+\s*(.*)//;
100                                 $Init{$current} .= "\t$1\n";
101                         }
102                         next;
103                 }
104                 if (s/^#define\s+//) {  # Definition of the rule
105                         chop;
106                         $Sig{$current} = $_;                    # Signature of rule
107                 } else {
108                         $Index{$current} .= "    $_";   # Rule's body
109                         $last_was_text = 1;
110                 }
111         } else {                        # We've just entered a rule
112                 $current = $1;
113                 next if $current =~ /patch\d/;  # Skip RCS log messages
114                 $inrule = 1;
115                 $incomment = 1; # We're still in the leading comment
116                 $Seen{$current} = 1;
117                 $last_was_text = 0;
118         }
119 }
120 close RULES;
121
122 # Now sort the rules in alphabetical order
123
124 print INDEX '-' x 72, "\n";
125 foreach $rule (sort(keys %Seen)) {
126         print INDEX "$Sig{$rule}:\n";
127         print INDEX $Comment{$rule};
128         $line = $Wants{$rule};
129         if (length($line)) {
130                 $line = "->$line.";
131                 $line = do format($line);
132                 print INDEX "$line\n";
133         }
134         $line = $Init{$rule};
135         print INDEX "$line\n" if length($line);
136         $line = $Added{$rule};
137         print INDEX "$line\n" if length($line);
138         $line = $Index{$rule};
139         print INDEX $line;
140         print INDEX "\n" if (length($line));
141         print INDEX '-' x 72, "\n";
142 }
143
144 close INDEX;
145
146 # Format $_ to fit in 80 columns (70 + size of tabs)
147 # Long lines are split, and the all but the first are indented
148 # by two leading spaces. The whole thing is then indented by
149 # one tab.
150 sub format {
151         local($tmp);
152         local($head) = '';
153         local($_) = shift(@_);
154         while (length($_) > 70) {
155                 $tmp = substr($_,0,70);
156                 $tmp =~ s/^(.*) .*/$1/;
157                 $head .= "\t$tmp\n";
158                 $_ = ' ' . substr($_,length($tmp),9999);
159         }
160         $head .= "\t$_\n";
161 }