revert previous push
[autoconf.git] / bin / ifnames.in
blobd470744c2c05fa8cb327f980c53e5446f2a14e91
1 #! @PERL@ -w
2 # -*- perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
6     if 0;
8 # ifnames - print the identifiers used in C preprocessor conditionals
10 # Copyright (C) 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
11 # 2007, 2008, 2009 Free Software Foundation, Inc.
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.
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.
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.
28 # Reads from stdin if no files are given.
29 # Writes to stdout.
31 # Written by David MacKenzie <djm@gnu.ai.mit.edu>
32 # and Paul Eggert <eggert@twinsun.com>.
34 BEGIN
36   my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
37   unshift @INC, $pkgdatadir;
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');
46 use Autom4te::General;
47 use Autom4te::XFile;
48 use Autom4te::FileUtils;
50 # $HELP
51 # -----
52 $help = "Usage: $0 [OPTION]... [FILE]...
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.
60   -h, --help      print this help, then exit
61   -V, --version   print version number, then exit
63 Report bugs to <bug-autoconf\@gnu.org>.
64 GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
65 General help using GNU software: <http://www.gnu.org/gethelp/>.
69 # $VERSION
70 # --------
71 $version = "ifnames (@PACKAGE_NAME@) @VERSION@
72 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
73 License GPLv2+: GNU GPL version 2 or later
74 <http://gnu.org/licenses/old-licenses/gpl-2.0.html>
75 This is free software: you are free to change and redistribute it.
76 There is NO WARRANTY, to the extent permitted by law.
78 Written by David J. MacKenzie and Paul Eggert.
82 # &parse_args ()
83 # --------------
84 # Process any command line arguments.
85 sub parse_args ()
87   getopt ();
91 # %OCCURRENCE
92 # -----------
93 my %occurrence;
96 # &scan_file ($FILE-NAME)
97 # -----------------------
98 sub scan_file ($)
100   my ($file_name) = @_;
101   my $file = new Autom4te::XFile ("< " . open_quote ($file_name));
102   while ($_ = $file->getline)
103     {
104       # Continuation lines.
105       $_ .= $file->getline
106         while (s/\\$//);
108       # Preprocessor directives.
109       if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
110         {
111           # Remove comments.  Not perfect, but close enough.
112           s(/\*.*?\*/)();
113           s(/\*.*)();
114           s(//.*)();
115           foreach my $word (split (/\W+/))
116             {
117               next
118                 if $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
119               $occurrence{$word}{$file_name} = 1;
120             }
121         }
122     }
126 ## ------ ##
127 ## Main.  ##
128 ## ------ ##
130 parse_args();
131 foreach (@ARGV)
132   {
133     scan_file ($_);
134   }
135 foreach (sort keys %occurrence)
136   {
137     print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n";
138   }
140 ### Setup "GNU" style for perl-mode and cperl-mode.
141 ## Local Variables:
142 ## perl-indent-level: 2
143 ## perl-continued-statement-offset: 2
144 ## perl-continued-brace-offset: 0
145 ## perl-brace-offset: 0
146 ## perl-brace-imaginary-offset: 0
147 ## perl-label-offset: -2
148 ## cperl-indent-level: 2
149 ## cperl-brace-offset: 0
150 ## cperl-continued-brace-offset: 0
151 ## cperl-label-offset: -2
152 ## cperl-extra-newline-before-brace: t
153 ## cperl-merge-trailing-else: nil
154 ## cperl-continued-statement-offset: 2
155 ## End: