1#! @PERL@ -w 2# -*- perl -*- 3# @configure_input@ 4 5eval '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-2003, 2005-2012 Free Software 11# 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 3 of the License, or 16# (at your option) 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, see <http://www.gnu.org/licenses/>. 25 26# Reads from stdin if no files are given. 27# Writes to stdout. 28 29# Written by David MacKenzie <djm@gnu.ai.mit.edu> 30# and Paul Eggert <eggert@twinsun.com>. 31 32BEGIN 33{ 34 my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@'; 35 unshift @INC, $pkgdatadir; 36 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'); 42} 43 44use Autom4te::General; 45use Autom4te::XFile; 46use Autom4te::FileUtils; 47 48# $HELP 49# ----- 50$help = "Usage: $0 [OPTION]... [FILE]... 51 52Scan all of the C source FILES (or the standard input, if none are 53given) and write to the standard output a sorted list of all the 54identifiers that appear in those files in `#if', `#elif', `#ifdef', or 55`#ifndef' directives. Print each identifier on a line, followed by a 56space-separated list of the files in which that identifier occurs. 57 58 -h, --help print this help, then exit 59 -V, --version print version number, then exit 60 61Report bugs to <bug-autoconf\@gnu.org>. 62GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>. 63General help using GNU software: <http://www.gnu.org/gethelp/>. 64"; 65 66 67# $VERSION 68# -------- 69$version = "ifnames (@PACKAGE_NAME@) @VERSION@ 70Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc. 71License GPLv3+/Autoconf: GNU GPL version 3 or later 72<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html> 73This is free software: you are free to change and redistribute it. 74There is NO WARRANTY, to the extent permitted by law. 75 76Written by David J. MacKenzie and Paul Eggert. 77"; 78 79 80# &parse_args () 81# -------------- 82# Process any command line arguments. 83sub parse_args () 84{ 85 getopt (); 86} 87 88 89# %OCCURRENCE 90# ----------- 91my %occurrence; 92 93 94# &scan_file ($FILE-NAME) 95# ----------------------- 96sub scan_file ($) 97{ 98 my ($file_name) = @_; 99 my $file = new Autom4te::XFile ("< " . open_quote ($file_name)); 100 while ($_ = $file->getline) 101 { 102 # Continuation lines. 103 $_ .= $file->getline 104 while (s/\\$//); 105 106 # Preprocessor directives. 107 if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//) 108 { 109 # Remove comments. Not perfect, but close enough. 110 s(/\*.*?\*/)(); 111 s(/\*.*)(); 112 s(//.*)(); 113 foreach my $word (split (/\W+/)) 114 { 115 next 116 if $word eq 'defined' || $word !~ /^[a-zA-Z_]/; 117 $occurrence{$word}{$file_name} = 1; 118 } 119 } 120 } 121} 122 123 124## ------ ## 125## Main. ## 126## ------ ## 127 128parse_args(); 129foreach (@ARGV) 130 { 131 scan_file ($_); 132 } 133foreach (sort keys %occurrence) 134 { 135 print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n"; 136 } 137 138### Setup "GNU" style for perl-mode and cperl-mode. 139## Local Variables: 140## perl-indent-level: 2 141## perl-continued-statement-offset: 2 142## perl-continued-brace-offset: 0 143## perl-brace-offset: 0 144## perl-brace-imaginary-offset: 0 145## perl-label-offset: -2 146## cperl-indent-level: 2 147## cperl-brace-offset: 0 148## cperl-continued-brace-offset: 0 149## cperl-label-offset: -2 150## cperl-extra-newline-before-brace: t 151## cperl-merge-trailing-else: nil 152## cperl-continued-statement-offset: 2 153## End: 154