#!/usr/local/bin/perl
#
# $Header: /e/u/j/local-repository/htdocs/www/software/emacs-20/prom-mew/mew-func-var-const,v 1.1.1.1 2008/03/12 10:53:31 makoto Exp $
  $rcsid = q$Id: mew-func-var-const,v 1.1.1.1 2008/03/12 10:53:31 makoto Exp $;
  $rcsid =~ s/Id://;

#------------ my_name for appropriate help message ----
# my name, strip all before '/' inclusively
# /home/fujiwara/perl/my_name -> my_name
$my_name = $0;
$my_name =~ s#(.*)/##;
#------------ my_path for getting right @INC path -----
# my location, strip rightmost '/' and right of it.
# /home/fujiwara/perl/my_path -> /home/fujiwara/perl
$my_path = $0;
$my_path =~ s|/[^/]+$||;
#---------------------
push(@INC,"$my_path");
require 'getopts.pl';

&Getopts('dhf');  
# ----------------- help -------------
if ( $opt_h ) {  &usage ; }
# -----------------------------------
$dir = $ARGV[0];
$new = $ARGV[1];

print $dir, "\n";
if ( -d $dir ) { chdir $dir }
else           { die "$dir should be existing directory.\n"};

foreach $EL ( sort <*.el> ) {
##    print $EL,"\n";
    open (EL) || print "problem opening el file($EL)\n";
    while(<EL>) {
	if ( /^\s*;/ ) { next }
	if ( /defconst (\S+)\s+/ ||
	     /defvar (\S+)\s+/   ||
	     /defun (\S+)\s+/          ) {
	    $symbol = $1 ;
##	    printf "%-20s: %s\n", $EL, $symbol;
	    $WHODEFINES{$symbol} .= $EL.' ';

	}}
    close($EL);}

# $BI8=`F~NO$+$iFI$s$G!"$=$NCf$K$I$N$h$&$J(B mew- $B$H$$$&J8;zNs$,$"$k(B
# $B$+$@$1$r(B @mew-$BJ8;zNsL>$KF~$l$F$*$/(B

while (<STDIN>) { 
    $count++;
    if ( /mew-/ ) { 
        s/\(/ /g;
        s/\)/ /g;
        s/\,/ /g;
        @primitives = split;
        foreach (@primitives) {
            if ( /^(mew-\S+)/ ) { 
                $symbol = $1 ; 
                $list{$symbol}++;
                eval  " push(\@$symbol,$count)\n";
	    }}}}

# $BDj5A$7$F$$$k(B *.el $B$rI=<($9$k!#(B
foreach $sym (sort keys %list ) {
    $ELrelated{$WHODEFINES{$sym}}++;  # sym $B$rDj5A$7$F$$$k4X?t$K2?$,$"$k$+$N0lMw$r:n$C$F$*$/(B
    if ( $opt_f ) {
	printf("%-40s -> %s\n", $sym,$WHODEFINES{$sym});}
    $func = $WHODEFINES{$sym}; $func =~ s/ //g;
    $INCLUDES{$func} .= $sym. ' ';
#             $B4X?tL>(B                           
}

# lstat $B$7$F;~9o>pJs$rD4$Y$k(B
###  print scalar(localtime(time())),"\n";
if ( -d $dir & -d $new ) {
    foreach $el ( sort keys %ELrelated ) {    
	$el =~ s/ //g;

	$file_dir = $
	$file_new = $new . '/'. $el ;
	$mtime_dir = (lstat($dir . '/'. $el ))[9]; $m_dir  = localtime($mtime_dir);
	$mtime_new = (lstat($new . '/'. $el ))[9]; $m_new  = localtime($mtime_new);
	if ( $mtime_dir == $mtime_new ) { next }
	printf("%-20s %s -> %s\n", $el,$m_dir,$m_new);
	print "   ", $INCLUDES{$el},"\n";
    }}

# ----------------
sub usage {
    print <<HELPHELP;
$my_name: 
Synonyms:
  $my_name [-d] [-h] 
Where:
   -d : debug
   -h : get help
   -f : print variable -> *.el file table
Note:

version: $rcsid
HELPHELP
    exit;
}
__END__
# $Log: mew-func-var-const,v $
# Revision 1.1.1.1  2008/03/12 10:53:31  makoto
# initial
#
# Revision 1.2  1999/12/13 02:51:08  makoto
# now showing  the name of primitive for each *.el file
#
# Revision 1.1  1999/12/13 02:37:56  makoto
# Initial revision
#
makoto@fujiwara$B"#(B10:46:43/991213(~)> perl/practice/mew-func-var-const $SITELISP/{.mew-1.95b3,mew-1.95b9} < $SITELISP/a-first-files/prom-mew.el
