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 / mcon / makegloss.SH
1 case $CONFIG in
2 '')
3         if test -f config.sh; then TOP=.;
4         elif test -f ../config.sh; then TOP=..;
5         elif test -f ../../config.sh; then TOP=../..;
6         elif test -f ../../../config.sh; then TOP=../../..;
7         elif test -f ../../../../config.sh; then TOP=../../../..;
8         else
9                 echo "Can't find config.sh."; exit 1
10         fi
11         . $TOP/config.sh
12         ;;
13 esac
14 case "$0" in
15 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
16 esac
17 echo "Extracting mcon/makegloss (with variable substitutions)"
18 $spitshell >makegloss <<!GROK!THIS!
19 $startperl
20         eval "exec perl -S \$0 \$*"
21                 if \$running_under_some_shell;
22
23 !GROK!THIS!
24 $spitshell >>makegloss <<'!NO!SUBS!'
25 # $Id: makegloss.SH,v 3.0.1.3 1994/01/24 14:17:49 ram Exp $
26 #
27 #  Copyright (c) 1991-1993, Raphael Manfredi
28 #  
29 #  You may redistribute only under the terms of the Artistic Licence,
30 #  as specified in the README file that comes with the distribution.
31 #  You may reuse parts of this distribution only within the terms of
32 #  that same Artistic Licence; a copy of which may be found at the root
33 #  of the source tree for dist 3.0.
34 #
35 # Original Author: Larry Wall <lwall@netlabs.com>
36 #
37 # $Log: makegloss.SH,v $
38 # Revision 3.0.1.3  1994/01/24  14:17:49  ram
39 # patch16: now understands internal-use only defined variables
40 #
41 # Revision 3.0.1.2  1993/10/16  13:50:39  ram
42 # patch12: updated to support new ?M: lines
43 #
44 # Revision 3.0.1.1  1993/08/19  06:42:21  ram
45 # patch1: leading config.sh searching was not aborting properly
46 #
47 # Revision 3.0  1993/08/18  12:10:12  ram
48 # Baseline for dist 3.0 netwide release.
49 #
50
51 open(G,">Glossary") || die "Can't create Glossary.\n";
52 print G
53 '[This Glossary is automatically generated from the Unit files.  Do not edit
54 this file or your changes will be lost.  Edit the appropriate Unit instead.]
55
56 This file contains a listing of all the C preprocessor symbols and shell
57 variables whose value can be determined by a Configure script.  For the
58 most part, any symbol in UPPERCASE is a C preprocessor symbol, and
59 will be defined in config.h.  Symbols in lowercase are shell variables,
60 and are defined in config.sh.
61
62 If you write your shell scripts and C programs in terms of these symbols,
63 metaconfig can automatically build you a Configure script that will determine
64 the value of those symbols.  See the README file for a description of how
65 to use metaconfig.
66
67 In the following listing, the Unit: line indicates the name of the unit
68 where this symbol is defined, and the Wants: line indicates what other
69 symbols must be determined in order to figure out the value of this one.
70 If there is an "(Also defines ...)" entry, it indicates what other symbols
71 are defined by the Unit other than the one corresponding to the unit name.
72
73 Variable of the form d_* either have the value "define" or "/*define", and
74 control whether some C preprocessor symbol gets defined or not.
75
76 ';
77
78 @ARGV = <U/*.U>;
79 while (<>) {
80         if (/^\?[\w\-]+:/) {    # We may have found a control line
81                 # Long lines may be escaped with a final backslash
82                 $_ .= &complete_line if s/\\\s*$//;
83         }
84         if (/^\?MAKE:.*:/) {
85                 ($also, $wants) = /^\?MAKE:\s*(.*):\s*(.*)/;
86                 ($unit = $ARGV) =~ s|.*/(.*)\.U$|$1|;
87                 @Also = split(/ /, $also);
88                 $also = '';
89                 $internal = '';
90                 foreach (@Also) {
91                         if (s/^\+//) {
92                                 $internal .= "$_ ";
93                         } else {
94                                 $also .= "$_ ";
95                         }
96                 }
97                 $also =~ s/$unit\s//;
98                 chop($also);
99                 chop($internal);
100                 @Wants = split(/ /, $wants);
101                 $wants = '';
102                 $option = '';
103                 foreach (@Wants) {
104                         if (s/^\+//) {
105                                 $option .= "$_ ";
106                         } else {
107                                 $wants .= "$_ ";
108                         }
109                 }
110                 chop($option);
111                 chop($wants);
112                 $head = '';
113                 $_ = "Unit: $unit";
114                 $_ .= " (Also defines $also)" if $also;
115                 $_ .= " (With private $internal)" if $internal;
116                 $head .= do format($_);
117                 if ($wants) {
118                         $_ = "Wants: $wants";
119                         $head .= do format($_);
120                 }
121                 if ($option) {
122                         $_ = "Optional: $option";
123                         $head .= do format($_);
124                 }
125                 $head .= "\n";
126         }
127
128         # Example of expression matched by the following pattern:
129         #   ?C:symbol ~ alias (obsolete list):
130         # The main symbol (optionally aliased) can be followed by a list of
131         # obsolete symbols (the list is space separated).
132
133         if (/^\?[CS]:(\w+)(\s*~\s*\S+)?\s*(\(.*\))?:\s*$/) {
134                 $sym = $1;
135                 $obsoleted = $3;
136                 push(@syms, $sym);
137                 $header{$sym} .= $head;
138                 if ($obsoleted =~ s/^\((.*)\)$/$1/) {
139                         @obsoleted = split(' ', $obsoleted);
140                         foreach $obs (@obsoleted) {
141                                 push(@syms, $obs);
142                                 $header{$obs} = "\tObsoleted by $sym.\n\n";
143                         }
144                 }
145         }
146         elsif (s/^\?[CS]://) {          # Must be inside definition
147                 if (/^\.$/) {                   # Closing line
148                         $def{$sym} .= "\n";
149                         $sym = '';
150                 }
151                 else {
152                         s/^(\t|  ? ? ? ? ? ? ?)//;
153                         $def{$sym} .= "\t" . $_;
154                 }
155         }
156         elsif (/^\?M:(\w+):\s*([\w\s]*)\n$/) {  # Magic mapping introduction
157                 $sym = $1;
158                 $cdep = $2;
159                 push(@syms, $sym);
160                 $cdep =~ s/^\s*//;
161                 $cdep = ", needs: $cdep" if $cdep ne '';
162                 $header{$sym} = "\tMagic symbol$cdep\n" . $head;
163         }
164         elsif (s/^\?M://) {                     # Must be a magic mapping definition
165                 if (/^\.$/) {                   # Closing line
166                         $def{$sym} .= "\n";
167                         $sym = '';
168                 } else {
169                         $def{$sym} .= "\t" . $_;
170                 }
171         }
172 }
173
174 foreach $sym (sort @syms) {
175         print G "$sym:\n";
176         print G $header{$sym};
177         print G $def{$sym};
178 }
179 close G;
180
181 # Format $_ to fit in 80 columns (70 + size of tabs)
182 # Long lines are split, and the all but the first are indented
183 # by two leading spaces. The whole thing is then indented by
184 # one tab.
185 sub format {
186         local($tmp);
187         local($head) = '';
188         local($_) = shift(@_);
189         while (length($_) > 70) {
190                 $tmp = substr($_,0,70);
191                 $tmp =~ s/^(.*) .*/$1/;
192                 $head .= "\t$tmp\n";
193                 $_ = ' ' . substr($_,length($tmp),9999);
194         }
195         $head .= "\t$_\n";
196 }
197
198 # The first line was escaped with a final \ character. Every following line
199 # is to be appended to it (until we found a real \n not escaped). Note that
200 # the leading spaces of the continuation line are removed, so any space should
201 # be added before the former \ if needed.
202 sub complete_line {
203         local($_);
204         local($read) = '';              # Concatenation of all the continuation lines found
205         while (<>) {
206                 s/^\s+//;                               # Remove leading spaces
207                 if (s/\\\s*$//) {               # Still followed by a continuation line
208                         $read .= $_;    
209                 } else {                                # We've reached the end of the continuation
210                         return $read . $_;
211                 }
212         }
213 }
214
215 !NO!SUBS!
216 chmod 755 makegloss
217 $eunicefix makegloss