2 # ifnames - print the identifiers used in C preprocessor conditionals
3 # Copyright (C) 1994, 95, 99, 2000 Free Software Foundation, Inc.
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)
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.
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
20 # Reads from stdin if no files are given.
23 # Written by David MacKenzie <djm@gnu.ai.mit.edu>
24 # and Paul Eggert <eggert@twinsun.com>.
26 me=`echo "$0" | sed -e 's,.*/,,'`
29 Usage: $0 [OPTION] ... [FILE] ...
31 Scan all of the C source FILES (or the standard input, if none are
32 given) and write to the standard output a sorted list of all the
33 identifiers that appear in those files in \`#if', \`#elif', \`#ifdef', or
34 \`#ifndef' directives. Print each identifier on a line, followed by a
35 space-separated list of the files in which that identifier occurs.
37 -h, --help print this help, then exit
38 -V, --version print version number, then exit
39 -v, --verbose verbosely report processing
41 Report bugs to <bug-autoconf@gnu.org>."
44 ifnames (GNU @PACKAGE@) @VERSION@
45 Written by David J. MacKenzie and Paul Eggert.
47 Copyright (C) 1994, 95, 99, 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) {
77 if (sym ~ /^[A-Za-z_]/) {
78 if (!found[sym,FILENAME]) {
79 found[sym,FILENAME] = 1
81 # Insert FILENAME into files[sym], keeping the list sorted.
84 while (match(substr(fs, i), /^ [^ ]*/) \
85 && substr(fs, i + 1, RLENGTH - 1) < FILENAME) {
88 files[sym] = substr(fs, 1, i - 1) " " FILENAME substr(fs, i)
94 while (sub(/\\$/, "", $0) > 0) {
95 if ((getline tmp) > 0)
103 if (sub(/^[\t ]*#[\t ]*ifn?def[\t ]+/, "", $0)) {
104 sub(/[^A-Za-z_0-9].*/, "", $0)
107 if (sub(/^[\t ]*#[\t ]*(el)?if[\t ]+/, "", $0)) {
108 # Remove comments. Not perfect, but close enough.
109 gsub(/\/\*[^\/]*(\*\/)?/, "", $0)
111 for (i = split($0, field, /[^A-Za-z_0-9]+/); 1 <= i; i--) {
112 if (field[i] != "defined") {