[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: autoscan-2
From: |
Akim Demaille |
Subject: |
FYI: autoscan-2 |
Date: |
02 Jul 2001 09:10:22 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Academic Rigor) |
Index: ChangeLog
from Akim Demaille <address@hidden>
* autoscan.in ($initfile): Remove.
(&find_file): Rename as...
(&scan_file): this.
Immediately scan the current file, instead of gathering them, and
later having them handled by &scan_files.
(&scan_files): Merely invoke Find::File.
Adjust.
Index: autoscan.in
--- autoscan.in Sun, 01 Jul 2001 19:17:23 +0200 akim (ace/13_autoscan.p 1.40
644)
+++ autoscan.in Sun, 01 Jul 2001 19:47:02 +0200 akim (ace/13_autoscan.p 1.40
644)
@@ -26,8 +26,7 @@
use Getopt::Long;
use strict;
-use vars qw($initfile
- @cfiles @makefiles @shfiles %c_keywords %printed);
+use vars qw(@cfiles @makefiles @shfiles %c_keywords %printed);
my $me = basename ($0);
my $verbose = 0;
@@ -79,6 +78,11 @@ sub END
}
+## ------------------------ ##
+## Command line interface. ##
+## ------------------------ ##
+
+
# print_usage ()
# --------------
# Display usage (--help).
@@ -248,82 +252,10 @@ sub init_tables ()
}
-# find_files ()
-# -------------
-# Collect names of various kinds of files in the package.
-# Called by &find on each file.
-sub find_files ()
-{
- # Strip a useless leading `./'.
- $File::Find::name =~ s,^\./,,;
-
- if (/^.*\.[chlymC]$/ || /^.*\.cc$/)
- {
- push (@cfiles, $File::Find::name);
- }
- elsif (/^[Mm]akefile$/ || /^GNUmakefile$/)
- {
- # Wanted only if there is no corresponding Makefile.in.
- # Using Find, $_ contains the current filename with the current
- # directory of the walk through.
- push (@makefiles, $File::Find::name)
- if ! -f "$_.in";
- }
- elsif (/^[Mm]akefile\.in$/)
- {
- push (@makefiles, $File::Find::name);
- }
- elsif (/^.*\.sh$/)
- {
- push (@shfiles, $File::Find::name);
- }
-}
-
-
-# scan_files ()
-# -------------
-# Read through the files and collect lists of tokens in them
-# that might create nonportabilities.
-sub scan_files ()
-{
- my $file;
- if (defined $cfiles[0])
- {
- $initfile = $cfiles[0]; # Pick one at random.
- }
-
- foreach $file (@cfiles)
- {
- push (@{$used{'programs'}{"cc"}}, $file);
- scan_c_file ($file);
- }
-
- foreach $file (@makefiles)
- {
- scan_makefile ($file);
- }
- foreach $file (@shfiles)
- {
- scan_sh_file ($file);
- }
-
- if ($verbose)
- {
- print "cfiles:", join(" ", @cfiles), "\n";
- print "makefiles:", join(" ", @makefiles), "\n";
- print "shfiles:", join(" ", @shfiles), "\n";
-
- foreach my $kind (@kinds)
- {
- print "\n$kind:\n";
- foreach my $word (sort keys %{$used{$kind}})
- {
- print "$word: @{$used{$kind}{$word}}\n";
- }
- }
- }
-}
+## ----------------------- ##
+## Scanning source files. ##
+## ----------------------- ##
# scan_c_file(FILE)
@@ -331,7 +263,12 @@ sub scan_files ()
sub scan_c_file ($)
{
my ($file) = @_;
- my ($in_comment) = 0; # Nonzero if in a multiline comment.
+
+ push (@cfiles, $File::Find::name);
+ push (@{$used{'programs'}{"cc"}}, $File::Find::name);
+
+ # Nonzero if in a multiline comment.
+ my $in_comment = 0;
open(CFILE, "<$file") || die "$me: cannot open $file: $!\n";
while (<CFILE>)
@@ -356,7 +293,7 @@ sub scan_c_file ($)
# Preprocessor directives.
if (/^\s*\#\s*include\s*<([^>]*)>/)
{
- push (@{$used{'headers'}{$1}}, "$file:$.");
+ push (@{$used{'headers'}{$1}}, "$File::Find::name:$.");
}
# Ignore other preprocessor directives.
next if /^\s*\#/;
@@ -369,12 +306,12 @@ sub scan_c_file ($)
# Maybe we should ignore function definitions (in column 0)?
while (s/\b([a-zA-Z_]\w*)\s*\(/ /)
{
- push (@{$used{'functions'}{$1}}, "$file:$.")
+ push (@{$used{'functions'}{$1}}, "$File::Find::name:$.")
if !defined $c_keywords{$1};
}
while (s/\b([a-zA-Z_]\w*)\b/ /)
{
- push (@{$used{'identifiers'}{$1}}, "$file:$.")
+ push (@{$used{'identifiers'}{$1}}, "$File::Find::name:$.")
if !defined $c_keywords{$1};
}
}
@@ -387,6 +324,7 @@ sub scan_c_file ($)
sub scan_makefile ($)
{
my ($file) = @_;
+ push (@makefiles, $File::Find::name);
open(MFILE, "<$file") || die "$me: cannot open $file: $!\n";
while (<MFILE>)
@@ -400,17 +338,17 @@ sub scan_makefile ($)
# Variable assignments.
while (s/\b([a-zA-Z_]\w*)\s*=/ /)
{
- push (@{$used{'makevars'}{$1}}, "$file:$.");
+ push (@{$used{'makevars'}{$1}}, "$File::Find::name:$.");
}
# Libraries.
while (s/\B-l([a-zA-Z_]\w*)\b/ /)
{
- push (@{$used{'libraries'}{$1}}, "$file:$.");
+ push (@{$used{'libraries'}{$1}}, "$File::Find::name:$.");
}
# Tokens in the code.
while (s/\b([a-zA-Z_]\w*)\b/ /)
{
- push (@{$used{'programs'}{$1}}, "$file:$.");
+ push (@{$used{'programs'}{$1}}, "$File::Find::name:$.");
}
}
close(MFILE);
@@ -422,6 +360,7 @@ sub scan_makefile ($)
sub scan_sh_file ($)
{
my ($file) = @_;
+ push (@shfiles, $File::Find::name);
open(MFILE, "<$file") || die "$me: cannot open $file: $!\n";
while (<MFILE>)
@@ -434,13 +373,79 @@ sub scan_sh_file ($)
# Tokens in the code.
while (s/\b([a-zA-Z_]\w*)\b/ /)
{
- push (@{$used{'programs'}{$1}}, "$file:$.");
+ push (@{$used{'programs'}{$1}}, "$File::Find::name:$.");
}
}
close(MFILE);
}
+# scan_file ()
+# ------------
+# Called by &find on each file. $_ contains the current filename with
+# the current directory of the walk through.
+sub scan_file ()
+{
+ # Save $_ as Find::File requires it to be preserved.
+ my $underscore = $_;
+
+ # Strip a useless leading `./'.
+ $File::Find::name =~ s,^\./,,;
+
+ if (/^.*\.[chlymC]$/ || /^.*\.cc$/)
+ {
+ scan_c_file ($_);
+ }
+ elsif (/^[Mm]akefile$/ || /^GNUmakefile$/)
+ {
+ # Wanted only if there is no corresponding Makefile.in.
+ scan_makefile ($_)
+ if ! -f "$_.in";
+ }
+ elsif (/^[Mm]akefile\.in$/)
+ {
+ scan_makefile ($_);
+ }
+ elsif (/^.*\.sh$/)
+ {
+ scan_sh_file ($_);
+ }
+
+ $_ = $underscore;
+}
+
+
+# scan_files ()
+# -------------
+# Read through the files and collect lists of tokens in them
+# that might create nonportabilities.
+sub scan_files ()
+{
+ find (\&scan_file, '.');
+
+ if ($verbose)
+ {
+ print "cfiles:", join(" ", @cfiles), "\n";
+ print "makefiles:", join(" ", @makefiles), "\n";
+ print "shfiles:", join(" ", @shfiles), "\n";
+
+ foreach my $kind (@kinds)
+ {
+ print "\n$kind:\n";
+ foreach my $word (sort keys %{$used{$kind}})
+ {
+ print "$word: @{$used{$kind}{$word}}\n";
+ }
+ }
+ }
+}
+
+
+## ----------------------- ##
+## Output configure.scan. ##
+## ----------------------- ##
+
+
# output_kind ($KIND)
# -------------------
sub output_kind ($)
@@ -512,12 +517,9 @@ sub output ($)
print CONF "# Process this file with autoconf to produce a configure
script.\n";
print CONF "AC_INIT\n";
- if (defined $initfile)
- {
- print CONF "AC_CONFIG_SRCDIR([$initfile])\n";
- }
if (defined $cfiles[0])
{
+ print CONF "AC_CONFIG_SRCDIR([$cfiles[0]])\n";
print CONF "AC_CONFIG_HEADER([config.h])\n";
}
@@ -543,6 +545,12 @@ sub output ($)
}
+
+## --------------------------------------- ##
+## Checking the accuracy of configure.ac. ##
+## --------------------------------------- ##
+
+
# check_configure_ac (CONFIGURE_AC)
# ---------------------------------
# Use autoconf to check if all the suggested macros are included
@@ -609,7 +617,6 @@ sub check_configure_ac ($)
find_autoconf;
my $configure_ac = find_configure_ac;
init_tables;
-find (\&find_files, '.');
scan_files;
output ('configure.scan');
if ($configure_ac)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: autoscan-2,
Akim Demaille <=