3 # ifnames - print the identifiers used in C preprocessor conditionals
4 # Copyright 1994, 1995, 1999, 2000 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # Reads from stdin if no files are given.
24 # Written by David MacKenzie <djm@gnu.ai.mit.edu>
25 # and Paul Eggert <eggert@twinsun.com>.
27 me=`echo "$0" | sed -e 's,.*/,,'`
30 Usage: $0 [OPTION] ... [FILE] ...
32 Scan all of the C source FILES (or the standard input, if none are
33 given) and write to the standard output a sorted list of all the
34 identifiers that appear in those files in \`#if', \`#elif', \`#ifdef', or
35 \`#ifndef' directives. Print each identifier on a line, followed by a
36 space-separated list of the files in which that identifier occurs.
38 -h, --help print this help, then exit
39 -V, --version print version number, then exit
41 Report bugs to <bug-autoconf@gnu.org>."
44 ifnames (@PACKAGE_NAME@) @VERSION@
45 Written by David J. MacKenzie and Paul Eggert.
47 Copyright 1994, 1995, 1999, 2000 Free Software Foundation, Inc.
48 This is free software; see the source for copying conditions. There is NO
49 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
52 Try \`$me --help' for more information."
54 while test $# -gt 0; do
57 echo "$usage"; exit 0 ;;
59 echo "$version"; exit 0 ;;
60 --) # Stop option processing.
64 echo "$me: invalid option $1"
75 # Record that sym was found in FILENAME.
76 function file_sym(sym, i, fs)
78 if (sym ~ /^[A-Za-z_]/)
80 if (!found[sym,FILENAME])
82 found[sym,FILENAME] = 1
84 # Insert FILENAME into files[sym], keeping the list sorted.
87 while (match(substr(fs, i), /^ [^ ]*/) \
88 && substr(fs, i + 1, RLENGTH - 1) < FILENAME)
92 files[sym] = substr(fs, 1, i - 1) " " FILENAME substr(fs, i)
98 while (sub(/\\$/, "", $0) > 0)
100 if ((getline tmp) > 0)
108 if (sub(/^[\t ]*#[\t ]*ifn?def[\t ]+/, "", $0))
110 sub(/[^A-Za-z_0-9].*/, "", $0)
113 if (sub(/^[\t ]*#[\t ]*(el)?if[\t ]+/, "", $0))
115 # Remove comments. Not perfect, but close enough.
116 gsub(/\/\*[^\/]*(\*\/)?/, "", $0)
118 for (i = split($0, field, /[^A-Za-z_0-9]+/); 1 <= i; i--)
120 if (field[i] != "defined")