[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
/floppy/ac-patches/90-fyi-ifnames-perl.patch
From: |
Akim Demaille |
Subject: |
/floppy/ac-patches/90-fyi-ifnames-perl.patch |
Date: |
Thu, 13 Sep 2001 08:55:43 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* bin/ifnames.in: Rewrite in Perl.
* configure.ac: Don't look for AWK.
* tests/tools.at (AWK portability): Remove.
(Syntax of the shell scripts): Don't check ifnames.
(AT_CHECK_PERL_SYNTAX): New.
(Syntax of the Perl scripts): Check ifnames.
* tests/ifnames: New.
Index: TODO
--- TODO Mon, 20 Aug 2001 09:04:59 +0200 akim
+++ TODO Wed, 12 Sep 2001 16:58:41 +0200 akim
@@ -20,10 +20,6 @@
** AC_CHECK_TOOL...
Write a test that checks that it honors the values set by the user.
-** ifnames
-Rewrite in Perl. Drop the AWK dependency. Remove the AWK portability
-tests. Add ifnames to the Perl sanity checks.
-
** autom4te and warnings.
Decide what must be done.
Index: configure.ac
--- configure.ac Wed, 05 Sep 2001 15:50:08 +0200 akim
+++ configure.ac Wed, 12 Sep 2001 16:58:53 +0200 akim
@@ -45,9 +45,6 @@
# a AC-SUBST inside AC-PROG-GNU-M4. Grmph!
AC_SUBST(M4)
-# `ifnames' uses AWK.
-AC_PROG_AWK
-
# Generating man pages.
AM_MISSING_PROG(HELP2MAN, help2man)
Index: bin/autom4te.in
--- bin/autom4te.in Sun, 09 Sep 2001 20:38:28 +0200 akim
+++ bin/autom4te.in Wed, 12 Sep 2001 16:26:43 +0200 akim
@@ -26,9 +26,7 @@
BEGIN
{
- my $datadir = ($ENV{'autom4te_perllibdir'}
- || $ENV{'AC_MACRODIR'}
- || '@datadir@');
+ my $datadir = ($ENV{'autom4te_perllibdir'} || '@datadir@');
unshift @INC, "$datadir";
}
Index: bin/ifnames.in
--- bin/ifnames.in Mon, 04 Jun 2001 18:29:01 +0200 akim
+++ bin/ifnames.in Wed, 12 Sep 2001 16:55:10 +0200 akim
@@ -1,7 +1,12 @@
-#! @SHELL@
-# -*- shell-script -*-
+#! @PERL@ -w
+# -*- perl -*-
+# @configure_input@
+
+eval 'exec @PERL@ -S $0 ${1+"$@"}'
+ if 0;
+
# ifnames - print the identifiers used in C preprocessor conditionals
-# Copyright 1994, 1995, 1999, 2000 Free Software Foundation, Inc.
+# Copyright 1994, 1995, 1999, 2000, 2001 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -24,111 +29,95 @@
# Written by David MacKenzie <address@hidden>
# and Paul Eggert <address@hidden>.
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION] ... [FILE] ...
+BEGIN
+{
+ my $datadir = ($ENV{'autom4te_perllibdir'} || '@datadir@');
+ unshift @INC, "$datadir";
+}
+
+use Autom4te::General;
+use Autom4te::XFile;
+
+# $HELP
+# -----
+$help = "Usage: $0 [OPTION] ... [FILE] ...
Scan all of the C source FILES (or the standard input, if none are
given) and write to the standard output a sorted list of all the
-identifiers that appear in those files in \`#if', \`#elif', \`#ifdef', or
-\`#ifndef' directives. Print each identifier on a line, followed by a
+identifiers that appear in those files in `#if', `#elif', `#ifdef', or
+`#ifndef' directives. Print each identifier on a line, followed by a
space-separated list of the files in which that identifier occurs.
-h, --help print this help, then exit
-V, --version print version number, then exit
-Report bugs to <address@hidden>."
+Report bugs to <address@hidden>.";
-version="\
+
+# $VERSION
+# --------
+$version = "\
ifnames (@PACKAGE_NAME@) @VERSION@
Written by David J. MacKenzie and Paul Eggert.
-Copyright 1994, 1995, 1999, 2000 Free Software Foundation, Inc.
+Copyright 1994, 1995, 1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.";
-help="\
-Try \`$me --help' for more information."
-while test $# -gt 0; do
- case "$1" in
- --help | -h )
- echo "$usage"; exit 0 ;;
- --version | -V )
- echo "$version"; exit 0 ;;
- --) # Stop option processing.
- shift; break ;;
- -*)
- exec >&2
- echo "$me: invalid option $1"
- echo "$help"
- exit 1 ;;
- *) break ;;
- esac
-done
-
-# Variables.
-: address@hidden@}
-
-$AWK '
- # Record that sym was found in FILENAME.
- function file_sym(sym, i, fs)
- {
- if (sym ~ /^[A-Za-z_]/)
+# &parse_args ()
+# --------------
+# Process any command line arguments.
+sub parse_args ()
+{
+ getopt ();
+}
+
+
+# %OCCURRENCE
+# -----------
+my %occurrence;
+
+
+# &scan_file ($FILENAME)
+# ----------------------
+sub scan_file ($)
+{
+ my ($filename) = @_;
+ my $file = new Autom4te::XFile ($filename);
+ while ($_ = $file->getline)
{
- if (!found[sym,FILENAME])
- {
- found[sym,FILENAME] = 1
-
- # Insert FILENAME into files[sym], keeping the list sorted.
- i = 1
- fs = files[sym]
- while (match(substr(fs, i), /^ [^ ]*/) \
- && substr(fs, i + 1, RLENGTH - 1) < FILENAME)
- {
- i += RLENGTH
+ # Continuation lines.
+ $_ .= $file->getline
+ while (s/\\$//);
+
+ # Preprocessor directives.
+ if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
+ {
+ # Remove comments. Not perfect, but close enough.
+ s(/\*.*?\*/)();
+ s(/\*.*)();
+ foreach my $word (split (/\W+/))
+ {
+ next
+ if $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
+ $occurrence{$word}{$filename} = 1;
+ }
}
- files[sym] = substr(fs, 1, i - 1) " " FILENAME substr(fs, i)
- }
}
- }
+}
- {
- while (sub(/\\$/, "", $0) > 0)
- {
- if ((getline tmp) > 0)
- $0 = $0 tmp
- else
- break
- }
- }
- /^[\t ]*#/ {
- if (sub(/^[\t ]*#[\t ]*ifn?def[\t ]+/, "", $0))
- {
- sub(/[^A-Za-z_0-9].*/, "", $0)
- file_sym($0)
- }
- if (sub(/^[\t ]*#[\t ]*(el)?if[\t ]+/, "", $0))
- {
- # Remove comments. Not perfect, but close enough.
- gsub(/\/\*[^\/]*(\*\/)?/, "", $0)
+## ------ ##
+## Main. ##
+## ------ ##
- for (i = split($0, field, /[^A-Za-z_0-9]+/); 1 <= i; i--)
- {
- if (field[i] != "defined")
- {
- file_sym(field[i])
- }
- }
- }
+parse_args();
+foreach (@ARGV)
+ {
+ scan_file ($_);
}
-
- END {
- for (sym in files)
- {
- print sym files[sym]
- }
+foreach (sort keys %occurrence)
+ {
+ print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n";
}
-' ${1+"$@"} | sort
Index: tests/Makefile.am
--- tests/Makefile.am Thu, 30 Aug 2001 20:46:39 +0200 akim
+++ tests/Makefile.am Wed, 12 Sep 2001 17:11:59 +0200 akim
@@ -24,7 +24,7 @@
atlocal.in
# Running the uninstalled scripts.
-WRAPPERS = autoconf autoheader autoreconf autom4te autoupdate
+WRAPPERS = autoconf autoheader autoreconf autom4te autoupdate ifnames
DISTCLEANFILES = atconfig atlocal $(TESTSUITE)
Index: tests/tools.at
--- tests/tools.at Wed, 12 Sep 2001 16:03:50 +0200 akim
+++ tests/tools.at Wed, 12 Sep 2001 16:58:08 +0200 akim
@@ -75,7 +75,6 @@
AT_CHECK([/bin/sh -n ../bin/autoconf], 0)
AT_CHECK([/bin/sh -n ../bin/autoreconf], 0)
-AT_CHECK([/bin/sh -n ../bin/ifnames], 0)
# These are not built, they are in the src tree.
AT_CHECK([/bin/sh -n $at_top_srcdir/config/install-sh], 0)
@@ -97,33 +96,17 @@
# | % perl -c ./autom4te
# | ./autom4te syntax OK
# Ignore it, it might change between releases.
-AT_CHECK([autom4te_perllibdir=$top_srcdir/lib $PERL -c ../bin/autom4te],
- 0, [], [ignore])
-AT_CHECK([autom4te_perllibdir=$top_srcdir/lib $PERL -c ../bin/autoheader],
- 0, [], [ignore])
-AT_CHECK([autom4te_perllibdir=$top_srcdir/lib $PERL -c ../bin/autoscan],
- 0, [], [ignore])
-AT_CHECK([autom4te_perllibdir=$top_srcdir/lib $PERL -c ../bin/autoupdate],
- 0, [], [ignore])
+m4_define([AT_CHECK_PERL_SYNTAX],
+[AT_CHECK([autom4te_perllibdir=$top_srcdir/lib $PERL -c ../bin/$1],
+ 0, [], [ignore])])
+
+AT_CHECK_PERL_SYNTAX([autoheader])
+AT_CHECK_PERL_SYNTAX([autom4te])
+AT_CHECK_PERL_SYNTAX([autoscan])
+AT_CHECK_PERL_SYNTAX([autoupdate])
+AT_CHECK_PERL_SYNTAX([ifnames])
AT_CLEANUP
-
-
-
-## ----------------- ##
-## AWK portability. ##
-## ----------------- ##
-
-AT_SETUP([AWK portability])
-
-# Skip if we don't have GNU Awk.
-AT_CHECK([gawk --version || exit 77], 0, ignore, ignore)
-
-# Syntax correctness of ifnames.
-AT_CHECK([AWK='gawk --posix' ifnames /dev/null])
-
-AT_CLEANUP
-
Index: tests/ifnames
--- tests/ifnames Wed, 12 Sep 2001 17:13:39 +0200 akim
+++ tests/ifnames Wed, 12 Sep 2001 17:03:30 +0200 akim
@@ -0,0 +1,14 @@
+#! /bin/sh
+# Running `ifnames' as if it were installed.
+
+. ./atconfig
+
+# Be sure to use the non installed Perl modules.
+# We need no special protection for the subtools (e.g., autoheader runs
+# autoconf which runs autom4te) because by themselves, they try to use
+# subtools from the same directory (i.e., foo/autoheader will run
+# foo/autoconf etc.).
+autom4te_perllibdir=$top_srcdir/lib
+export autom4te_perllibdir
+
+exec ../bin/ifnames ${1+"$@"}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- /floppy/ac-patches/90-fyi-ifnames-perl.patch,
Akim Demaille <=