| 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@';
|
|---|
| 37 | unshift @INC, $datadir;
|
|---|
| 38 |
|
|---|
| 39 | # Override SHELL. On DJGPP SHELL may not be set to a shell
|
|---|
| 40 | # that can handle redirection and quote arguments correctly,
|
|---|
| 41 | # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
|
|---|
| 42 | # has detected.
|
|---|
| 43 | $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | use Autom4te::General;
|
|---|
| 47 | use Autom4te::XFile;
|
|---|
| 48 |
|
|---|
| 49 | # $HELP
|
|---|
| 50 | # -----
|
|---|
| 51 | $help = "Usage: $0 [OPTION] ... [FILE] ...
|
|---|
| 52 |
|
|---|
| 53 | Scan all of the C source FILES (or the standard input, if none are
|
|---|
| 54 | given) and write to the standard output a sorted list of all the
|
|---|
| 55 | identifiers that appear in those files in `#if', `#elif', `#ifdef', or
|
|---|
| 56 | `#ifndef' directives. Print each identifier on a line, followed by a
|
|---|
| 57 | space-separated list of the files in which that identifier occurs.
|
|---|
| 58 |
|
|---|
| 59 | -h, --help print this help, then exit
|
|---|
| 60 | -V, --version print version number, then exit
|
|---|
| 61 |
|
|---|
| 62 | Report bugs to <bug-autoconf\@gnu.org>.
|
|---|
| 63 | ";
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | # $VERSION
|
|---|
| 67 | # --------
|
|---|
| 68 | $version = "ifnames (@PACKAGE_NAME@) @VERSION@
|
|---|
| 69 | Copyright (C) 2006 Free Software Foundation, Inc.
|
|---|
| 70 | This is free software. You may redistribute copies of it under the terms of
|
|---|
| 71 | the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
|
|---|
| 72 | There is NO WARRANTY, to the extent permitted by law.
|
|---|
| 73 |
|
|---|
| 74 | Written by David J. MacKenzie and Paul Eggert.
|
|---|
| 75 | ";
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | # &parse_args ()
|
|---|
| 79 | # --------------
|
|---|
| 80 | # Process any command line arguments.
|
|---|
| 81 | sub parse_args ()
|
|---|
| 82 | {
|
|---|
| 83 | getopt ();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | # %OCCURRENCE
|
|---|
| 88 | # -----------
|
|---|
| 89 | my %occurrence;
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | # &scan_file ($FILE-NAME)
|
|---|
| 93 | # -----------------------
|
|---|
| 94 | sub scan_file ($)
|
|---|
| 95 | {
|
|---|
| 96 | my ($file_name) = @_;
|
|---|
| 97 | my $file = new Autom4te::XFile ($file_name);
|
|---|
| 98 | while ($_ = $file->getline)
|
|---|
| 99 | {
|
|---|
| 100 | # Continuation lines.
|
|---|
| 101 | $_ .= $file->getline
|
|---|
| 102 | while (s/\\$//);
|
|---|
| 103 |
|
|---|
| 104 | # Preprocessor directives.
|
|---|
| 105 | if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
|
|---|
| 106 | {
|
|---|
| 107 | # Remove comments. Not perfect, but close enough.
|
|---|
| 108 | s(/\*.*?\*/)();
|
|---|
| 109 | s(/\*.*)();
|
|---|
| 110 | s(//.*)();
|
|---|
| 111 | foreach my $word (split (/\W+/))
|
|---|
| 112 | {
|
|---|
| 113 | next
|
|---|
| 114 | if $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
|
|---|
| 115 | $occurrence{$word}{$file_name} = 1;
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | ## ------ ##
|
|---|
| 123 | ## Main. ##
|
|---|
| 124 | ## ------ ##
|
|---|
| 125 |
|
|---|
| 126 | parse_args();
|
|---|
| 127 | foreach (@ARGV)
|
|---|
| 128 | {
|
|---|
| 129 | scan_file ($_);
|
|---|
| 130 | }
|
|---|
| 131 | foreach (sort keys %occurrence)
|
|---|
| 132 | {
|
|---|
| 133 | print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n";
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | ### Setup "GNU" style for perl-mode and cperl-mode.
|
|---|
| 137 | ## Local Variables:
|
|---|
| 138 | ## perl-indent-level: 2
|
|---|
| 139 | ## perl-continued-statement-offset: 2
|
|---|
| 140 | ## perl-continued-brace-offset: 0
|
|---|
| 141 | ## perl-brace-offset: 0
|
|---|
| 142 | ## perl-brace-imaginary-offset: 0
|
|---|
| 143 | ## perl-label-offset: -2
|
|---|
| 144 | ## cperl-indent-level: 2
|
|---|
| 145 | ## cperl-brace-offset: 0
|
|---|
| 146 | ## cperl-continued-brace-offset: 0
|
|---|
| 147 | ## cperl-label-offset: -2
|
|---|
| 148 | ## cperl-extra-newline-before-brace: t
|
|---|
| 149 | ## cperl-merge-trailing-else: nil
|
|---|
| 150 | ## cperl-continued-statement-offset: 2
|
|---|
| 151 | ## End:
|
|---|