#!/usr/local/bin/perl -w
use File::Basename;
@perl_units = glob('../U/*.U');
@std_units = glob('/usr/local/lib/dist/U/*.U');
push(@perl_units, @std_units);

# Get the list of Wanted symbols generated by metaconfig.
# XXX -- BUG -- we should use config.sh instead!  Some things, such
# as usemymalloc, never show up in Wanted.
open(WANTED, "<../Wanted") || die 'Open ../Wanted';

print <<'EOM';
This file contains a description of all the shell variables whose value is
determined by the Configure script.  Variables intended for use in C
programs (e.g. I_UNISTD) are already described in config_h.SH.

EOM

symbol:  while ($var = <WANTED>) {
    chomp $var;
    next symbol if $var =~ /^!>/;  # Skip Obsolete Symbols
    next symbol if $var =~ /^>/;   # Skip C symbols -- they are in config_h.SH
    next symbol if $var =~ /^$/;
    $gotit = 0;
    foreach $file (@perl_units) {
	open(FH, "<$file") || die "Open $file";
	$base = basename($file);
	while (<FH>) {
	    if (/^\?S:$var:$/ .. /^\?S:.$/) {
		if ($gotit == 0) {
		    print "$var ($base):\n";
		    $gotit = 1;
		}
		else {
		    s/^\?S:.$//;  # Delete trailing line
		    s/^\?S://;    # Remove leading ?S: markers.
		    s/^ /\t/;	  # Ensure all lines begin with tabs.
		    print;
		}
	    }
	}
	close(FH) || die "Closing $file";
	next symbol if ($gotit == 1);
    }
}
