| [3092] | 1 | #! @PERL@ -w
|
|---|
| 2 | # -*- perl -*-
|
|---|
| 3 | # @configure_input@
|
|---|
| 4 |
|
|---|
| 5 | eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
|
|---|
| 6 | if 0;
|
|---|
| 7 |
|
|---|
| 8 | # ifnames - print the identifiers used in C preprocessor conditionals
|
|---|
| 9 |
|
|---|
| 10 | # Copyright (C) 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2005, 2006
|
|---|
| 11 | # Free Software Foundation, Inc.
|
|---|
| 12 |
|
|---|
| 13 | # This program is free software; you can redistribute it and/or modify
|
|---|
| 14 | # it under the terms of the GNU General Public License as published by
|
|---|
| 15 | # the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 16 | # any later version.
|
|---|
| 17 |
|
|---|
| 18 | # This program is distributed in the hope that it will be useful,
|
|---|
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 21 | # GNU General Public License for more details.
|
|---|
| 22 |
|
|---|
| 23 | # You should have received a copy of the GNU General Public License
|
|---|
| 24 | # along with this program; if not, write to the Free Software
|
|---|
| 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 26 | # 02110-1301, USA.
|
|---|
| 27 |
|
|---|
| 28 | # Reads from stdin if no files are given.
|
|---|
| 29 | # Writes to stdout.
|
|---|
| 30 |
|
|---|
| 31 | # Written by David MacKenzie <[email protected]>
|
|---|
| 32 | # and Paul Eggert <[email protected]>.
|
|---|
| 33 |
|
|---|
| 34 | BEGIN
|
|---|
| 35 | {
|
|---|
| 36 | my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
|
|---|
| [3095] | 37 | $datadir =~ s/\/\@unixroot/$ENV{'UNIXROOT'}/; # The EMX built perl doesn't know @unixroot.
|
|---|
| [3092] | 38 | unshift @INC, $datadir;
|
|---|
| 39 |
|
|---|
| 40 | # Override SHELL. On DJGPP SHELL may not be set to a shell
|
|---|
| 41 | # that can handle redirection and quote arguments correctly,
|
|---|
| 42 | # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
|
|---|
| 43 | # has detected.
|
|---|
| 44 | $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | use Autom4te::General;
|
|---|
| 48 | use Autom4te::XFile;
|
|---|
| 49 |
|
|---|
| 50 | # $HELP
|
|---|
| 51 | # -----
|
|---|
| 52 | $help = "Usage: $0 [OPTION] ... [FILE] ...
|
|---|
| 53 |
|
|---|
| 54 | Scan all of the C source FILES (or the standard input, if none are
|
|---|
| 55 | given) and write to the standard output a sorted list of all the
|
|---|
| 56 | identifiers that appear in those files in `#if', `#elif', `#ifdef', or
|
|---|
| 57 | `#ifndef' directives. Print each identifier on a line, followed by a
|
|---|
| 58 | space-separated list of the files in which that identifier occurs.
|
|---|
| 59 |
|
|---|
| 60 | -h, --help print this help, then exit
|
|---|
| 61 | -V, --version print version number, then exit
|
|---|
| 62 |
|
|---|
| 63 | Report bugs to <bug-autoconf\@gnu.org>.
|
|---|
| 64 | ";
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | # $VERSION
|
|---|
| 68 | # --------
|
|---|
| 69 | $version = "ifnames (@PACKAGE_NAME@) @VERSION@
|
|---|
| 70 | Copyright (C) 2006 Free Software Foundation, Inc.
|
|---|
| 71 | This is free software. You may redistribute copies of it under the terms of
|
|---|
| 72 | the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
|
|---|
| 73 | There is NO WARRANTY, to the extent permitted by law.
|
|---|
| 74 |
|
|---|
| 75 | Written by David J. MacKenzie and Paul Eggert.
|
|---|
| 76 | ";
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | # &parse_args ()
|
|---|
| 80 | # --------------
|
|---|
| 81 | # Process any command line arguments.
|
|---|
| 82 | sub parse_args ()
|
|---|
| 83 | {
|
|---|
| 84 | getopt ();
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | # %OCCURRENCE
|
|---|
| 89 | # -----------
|
|---|
| 90 | my %occurrence;
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | # &scan_file ($FILE-NAME)
|
|---|
| 94 | # -----------------------
|
|---|
| 95 | sub scan_file ($)
|
|---|
| 96 | {
|
|---|
| 97 | my ($file_name) = @_;
|
|---|
| 98 | my $file = new Autom4te::XFile ($file_name);
|
|---|
| 99 | while ($_ = $file->getline)
|
|---|
| 100 | {
|
|---|
| 101 | # Continuation lines.
|
|---|
| 102 | $_ .= $file->getline
|
|---|
| 103 | while (s/\\$//);
|
|---|
| 104 |
|
|---|
| 105 | # Preprocessor directives.
|
|---|
| 106 | if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
|
|---|
| 107 | {
|
|---|
| 108 | # Remove comments. Not perfect, but close enough.
|
|---|
| 109 | s(/\*.*?\*/)();
|
|---|
| 110 | s(/\*.*)();
|
|---|
| 111 | s(//.*)();
|
|---|
| 112 | foreach my $word (split (/\W+/))
|
|---|
| 113 | {
|
|---|
| 114 | next
|
|---|
| 115 | if $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
|
|---|
| 116 | $occurrence{$word}{$file_name} = 1;
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | ## ------ ##
|
|---|
| 124 | ## Main. ##
|
|---|
| 125 | ## ------ ##
|
|---|
| 126 |
|
|---|
| 127 | parse_args();
|
|---|
| 128 | foreach (@ARGV)
|
|---|
| 129 | {
|
|---|
| 130 | scan_file ($_);
|
|---|
| 131 | }
|
|---|
| 132 | foreach (sort keys %occurrence)
|
|---|
| 133 | {
|
|---|
| 134 | print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n";
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | ### Setup "GNU" style for perl-mode and cperl-mode.
|
|---|
| 138 | ## Local Variables:
|
|---|
| 139 | ## perl-indent-level: 2
|
|---|
| 140 | ## perl-continued-statement-offset: 2
|
|---|
| 141 | ## perl-continued-brace-offset: 0
|
|---|
| 142 | ## perl-brace-offset: 0
|
|---|
| 143 | ## perl-brace-imaginary-offset: 0
|
|---|
| 144 | ## perl-label-offset: -2
|
|---|
| 145 | ## cperl-indent-level: 2
|
|---|
| 146 | ## cperl-brace-offset: 0
|
|---|
| 147 | ## cperl-continued-brace-offset: 0
|
|---|
| 148 | ## cperl-label-offset: -2
|
|---|
| 149 | ## cperl-extra-newline-before-brace: t
|
|---|
| 150 | ## cperl-merge-trailing-else: nil
|
|---|
| 151 | ## cperl-continued-statement-offset: 2
|
|---|
| 152 | ## End:
|
|---|