summaryrefslogtreecommitdiff
path: root/jmake/bindex.SH
blob: ee45b2efcbffe12f5fba7317d5fd93f159f44a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
case $CONFIG in
'')
	if test -f config.sh; then TOP=.;
	elif test -f ../config.sh; then TOP=..;
	elif test -f ../../config.sh; then TOP=../..;
	elif test -f ../../../config.sh; then TOP=../../..;
	elif test -f ../../../../config.sh; then TOP=../../../..;
	else
		echo "Can't find config.sh."; exit 1
	fi
	. $TOP/config.sh
	;;
esac
case "$0" in
*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
esac
echo "Extracting bindex (with variable substitutions)"
$spitshell >bindex <<!GROK!THIS!
$startperl
!GROK!THIS!
$spitshell >>bindex <<'!NO!SUBS!'
	eval 'exec perl -S $0 ${1+"$@"}'
		if $running_under_some_shell;

# $Id: bindex.SH 31 2010-03-06 20:15:24Z rmanfredi $
#
#  Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
#  
#  You may redistribute only under the terms of the Artistic Licence,
#  as specified in the README file that comes with the distribution.
#  You may reuse parts of this distribution only within the terms of
#  that same Artistic Licence; a copy of which may be found at the root
#  of the source tree for dist 4.0.
#
# $Log: bindex.SH,v $
# Revision 3.0.1.1  1993/08/19  06:42:12  ram
# patch1: leading config.sh searching was not aborting properly
#
# Revision 3.0  1993/08/18  12:04:13  ram
# Baseline for dist 3.0 netwide release.
#

$file = "files/Jmake.rules";

open(INDEX, ">Index") || die "Cannot create Index.\n";
open(RULES, "$file") || die "Cannot open $file.\n";

print INDEX
"[This Index is automatically generated from Jmake.rules file. Do not
edit this file or your changes will be lost. Edit Jmake.rules instead.]

This file contains a listing of all the macros that can be used in a
Jmakefile. Only a few of these should be used in the Jmakefile (they
are the top-level macros). However, some low-level ones may be useful,
but it is up to you to make that decision. This explains why this file
holds all the available macros for jmake.

In the following listing, the macros are separated by a line of dashes.
The signature of the macro is given, then a small comment of what it
does precedes the actual definition.

Lines preceded by '->' show the set of symbols defined when the macro is
used. Initialization lines are shown as-is, i.e. have the form SYM = val
while concatenation is shown by SYM += val (which means val is added to
the value of SYM).

Conditional lines are preceded by tests like (if SYM). This means the line
is to be kept if and only if the symbol SYM is defined. Other internal
requests are not formatted yet.

";
$inrule = 0;			# Not inside a rule at the beginning
$incomment = 0;			# Not inside a comment
$last_was_text = 0;		# Last line was not a rule text
while (<RULES>) {
	$inrule || next unless /^\s\*\s(\w+)\s*:/;
	if ($inrule) {		# We are already in a rule
		if ($incomment) {
			if (m|^\s*\*/|) {	# End of comment
				$incomment = 0;
				$Comment{$current} .= "\n";
			} else {
				s/^\s*\*\s*//;	# Remove leading comment sign
				$Comment{$current} .= "    $_";
			}
			next;		# Anyway, go to next line
		}
		if (/^\s*$/) {		# Empty line = end of rule
			$inrule = 0;
			next;
		}
		# Here, we have to print the body of the rule, after some cleaning
		s/(@#|@@|@!)\\$//;		# Remove final continuations
		s/^(#define.*)\\/$1/;	# Remove single '\' on first rule line
		s/\|rule:\s*$/\n/;
		s/\|rule:\s+/    /;		# Remove rule markers
		s/\|rule://;
		s/%(\w+):\|skip/#ifdef $1/;		# Deal with ugly skip syntax
		s/\?(\w+):\|skip/#ifndef $1/;	# Deal with ugly skip syntax
		s/\-skip/#endif/;
		s/\?(\w+):/(if $1) /;	# Simple '?' test
		s/%(\w+):/(not $1) /;	# Simple '%' test
		s/\|suffix/.SUFFIXES:/;	# Make suffix command explicit
		s/\t/    /g;			# Expand all tabs to 4 chars
		s/\s*$/\n/;				# Remove any trailing space
		s|\^\^\^|/***/|;		# Change ^^^ to the more visual /***/
		s|\^\^|/**/|;			# Restore ^^ to the more visual /**/
		if (/^$/) {				# If empty line
			$Index{$current} .= "\n" if $last_was_text;
			$last_was_text = 0;
			next;
		}
		if (/^[>+]/) {			# Special commands
			if (s/^>\s*//) {						# Wanted symbol
				chop;
				$Wants{$current} .= " $_";
			} elsif (/^\+\+\s*(\S+)\s*(.*)/) {		# Added symbol
				$Added{$current} .= "\t$1 += $2\n";
			} else {
				s/^\+\s*(.*)//;
				$Init{$current} .= "\t$1\n";
			}
			next;
		}
		if (s/^#define\s+//) {	# Definition of the rule
			chop;
			$Sig{$current} = $_;			# Signature of rule
		} else {
			$Index{$current} .= "    $_";	# Rule's body
			$last_was_text = 1;
		}
	} else {			# We've just entered a rule
		$current = $1;
		next if $current =~ /patch\d/;	# Skip RCS log messages
		$inrule = 1;
		$incomment = 1;	# We're still in the leading comment
		$Seen{$current} = 1;
		$last_was_text = 0;
	}
}
close RULES;

# Now sort the rules in alphabetical order

print INDEX '-' x 72, "\n";
foreach $rule (sort(keys %Seen)) {
	print INDEX "$Sig{$rule}:\n";
	print INDEX $Comment{$rule};
	$line = $Wants{$rule};
	if (length($line)) {
		$line = "->$line.";
		$line = &format($line);
		print INDEX "$line\n";
	}
	$line = $Init{$rule};
	print INDEX "$line\n" if length($line);
	$line = $Added{$rule};
	print INDEX "$line\n" if length($line);
	$line = $Index{$rule};
	print INDEX $line;
	print INDEX "\n" if (length($line));
	print INDEX '-' x 72, "\n";
}

close INDEX;

# Format $_ to fit in 80 columns (70 + size of tabs)
# Long lines are split, and the all but the first are indented
# by two leading spaces. The whole thing is then indented by
# one tab.
sub format {
	local($tmp);
	local($head) = '';
	local($_) = shift(@_);
	while (length($_) > 70) {
		$tmp = substr($_,0,70);
		$tmp =~ s/^(.*) .*/$1/;
		$head .= "\t$tmp\n";
		$_ = ' ' . substr($_,length($tmp),9999);
	}
	$head .= "\t$_\n";
}
!NO!SUBS!
chmod 755 bindex
$eunicefix bindex