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