1#! @SHELL@ 2# ifnames - print the identifiers used in C preprocessor conditionals 3# Copyright (C) 1994, 1995 Free Software Foundation, Inc. 4 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2, or (at your option) 8# any later version. 9 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18# 02111-1307, USA. 19 20# Reads from stdin if no files are given. 21# Writes to stdout. 22 23# Written by David MacKenzie <djm@gnu.ai.mit.edu> 24# and Paul Eggert <eggert@twinsun.com>. 25 26usage="\ 27Usage: ifnames [-h] [--help] [-m dir] [--macrodir=dir] [--version] [file...]" 28show_version=no 29 30: ${AC_MACRODIR=@datadir@} 31 32while test $# -gt 0; do 33 case "$1" in 34 -h | --help | --h* ) 35 echo "$usage"; exit 0 ;; 36 --macrodir=* | --m*=* ) 37 AC_MACRODIR="`echo \"$1\" | sed -e 's/^[^=]*=//'`" 38 shift ;; 39 -m | --macrodir | --m* ) 40 shift 41 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 42 AC_MACRODIR="$1" 43 shift ;; 44 --version | --versio | --versi | --vers) 45 show_version=yes; shift ;; 46 --) # Stop option processing. 47 shift; break ;; 48 -*) echo "$usage" 1>&2; exit 1 ;; 49 *) break ;; 50 esac 51done 52 53if test $show_version = yes; then 54 version=`sed -n 's/define.AC_ACVERSION.[ ]*\([0-9.]*\).*/\1/p' \ 55 $AC_MACRODIR/acgeneral.m4` 56 echo "Autoconf version $version" 57 exit 0 58fi 59 60@AWK@ ' 61 # Record that sym was found in FILENAME. 62 function file_sym(sym, i, fs) { 63 if (sym ~ /^[A-Za-z_]/) { 64 if (!found[sym,FILENAME]) { 65 found[sym,FILENAME] = 1 66 67 # Insert FILENAME into files[sym], keeping the list sorted. 68 i = 1 69 fs = files[sym] 70 while (match(substr(fs, i), /^ [^ ]*/) \ 71 && substr(fs, i + 1, RLENGTH - 1) < FILENAME) { 72 i += RLENGTH 73 } 74 files[sym] = substr(fs, 1, i - 1) " " FILENAME substr(fs, i) 75 } 76 } 77 } 78 79 /^[\t ]*#/ { 80 if (sub(/^[\t ]*#[\t ]*ifn?def[\t ]+/, "", $0)) { 81 sub(/[^A-Za-z_0-9].*/, "", $0) 82 file_sym($0) 83 } 84 if (sub(/^[\t ]*#[\t ]*(el)?if[\t ]+/, "", $0)) { 85 # Remove comments. Not perfect, but close enough. 86 gsub(/\/\*[^\/]*(\*\/)?/, "", $0) 87 88 for (i = split($0, field, /[^A-Za-z_0-9]+/); 1 <= i; i--) { 89 if (field[i] != "defined") { 90 file_sym(field[i]) 91 } 92 } 93 } 94 } 95 96 END { 97 for (sym in files) { 98 print sym files[sym] 99 } 100 } 101' ${1+"$@"} | sort 102