1 ;# $Id: xwant.pl,v 3.0 1993/08/18 12:10:32 ram Exp $
3 ;# Copyright (c) 1991-1993, Raphael Manfredi
5 ;# You may redistribute only under the terms of the Artistic Licence,
6 ;# as specified in the README file that comes with the distribution.
7 ;# You may reuse parts of this distribution only within the terms of
8 ;# that same Artistic Licence; a copy of which may be found at the root
9 ;# of the source tree for dist 3.0.
12 ;# Revision 3.0 1993/08/18 12:10:32 ram
13 ;# Baseline for dist 3.0 netwide release.
16 ;# These two arrays record the file names of the files which may (or may not)
17 ;# contain shell or C symbols known by metaconfig.
18 ;# @SHlist records the .SH files
19 ;# @clist records the C-like files (i.e. .[chyl])
21 # Parse files and build cross references
23 print "Building cross-reference files...\n" unless $opt_s;
24 unless (-f $NEWMANI) {
26 die "No $NEWMANI--don't know who to scan.\n" unless -f $NEWMANI;
29 open(FUI, "|sort | uniq >I.fui") || die "Can't create I.fui.\n";
30 open(UIF, "|sort | uniq >I.uif") || die "Can't create I.uif.\n";
32 local($search); # Where to-be-evaled script is held
33 local($_) = ' ' x 50000 if $opt_m; # Pre-extend pattern search space
34 local(%visited); # Records visited files
35 local(%lastfound); # Where last occurence of key was
37 # Map shell symbol names to units by reverse engineering the @Master array
38 # which records all the known shell symbols and the units where they
40 foreach $init (@Master) {
41 $init =~ /^\?(.*):(.*)=''/ && ($shwanted{"\$$2"} = $1);
44 # Now we are a little clever, and build a loop to eval so that we don't
45 # have to recompile our patterns on every file. We also use "study" since
46 # we are searching the same string for many different things. Hauls!
49 print " Scanning .[chyl] files for symbols...\n" unless $opt_s;
50 $search = ' ' x (40 * (@cmaster + @ocmaster)); # Pre-extend
51 $search = "while (<>) {study;\n"; # Init loop over ARGV
52 foreach $key (keys(cmaster)) {
53 $search .= "\$cmaster{'$key'} .= \"\$ARGV#\" if /\\b$key\\b/;\n";
55 foreach $key (grep(!/^\$/, keys %Obsolete)) {
56 $search .= "&ofound('$key') if /\\b$key\\b/;\n";
58 $search .= "}\n"; # terminate loop
59 print $search if $opt_d;
61 # Swallow each file as a whole, if memory is available
66 while (($key,$value) = each(cmaster)) {
68 foreach $file (sort(split(/#/, $value))) {
70 # %cwanted may contain value separated by \n -- take last one
71 @sym = split(/\n/, $cwanted{$key});
76 pack("A20", "$shwanted{$shell}.U"),
79 pack("A20", "$shwanted{$shell}.U"),
88 undef %cmaster; # We're not building Configure, we may delete this
93 print " Scanning .SH files for symbols...\n" unless $opt_s;
94 $search = ' ' x (40 * (@shmaster + @oshmaster)); # Pre-extend
95 $search = "while (<>) {study;\n";
96 # All the keys already have a leading '$'
97 foreach $key (keys(shmaster)) {
98 $search .= "\$shmaster{'$key'} .= \"\$ARGV#\" if /\\$key\\b/;\n";
100 foreach $key (grep (/^\$/, keys %Obsolete)) {
101 $search .= "&ofound('$key') if /\\$key\\b/;\n";
104 print $search if $opt_d;
106 # Swallow each file as a whole, if memory is available
111 while (($key,$value) = each(shmaster)) {
112 next if $value eq '';
113 foreach $file (sort(split(/#/, $value))) {
117 pack("A20", "$shwanted{$key}.U"),
120 pack("A20", "$shwanted{$key}.U"),
130 # If obsolete symbols where found, write an Obsolete file which lists where
131 # each of them appear and the new symbol to be used. Also write Obsol_h.U
132 # and Obsol_sh.U in .MT for later perusal.
134 &dump_obsolete; # Dump obsolete symbols if any
136 # Clean-up memory by freeing useless data structures
141 # This routine records matches of obsolete keys (C or shell)
144 local($_) = $Obsolete{$key}; # Value of new symbol
145 $ofound{"$ARGV $key $_"}++; # Record obsolete match
146 $cmaster{$_} .= "$ARGV#" unless /^\$/; # A C hit
147 $shmaster{$_} .= "$ARGV#" if /^\$/; # Or a shell one