home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / autoconf-2.10-src.tgz / tar.out / fsf / autoconf / ifnames.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1996-09-24  |  3KB  |  101 lines

  1. #! /bin/sh
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. # Reads from stdin if no files are given.
  20. # Writes to stdout.
  21.  
  22. # Written by David MacKenzie <djm@gnu.ai.mit.edu>
  23. # and Paul Eggert <eggert@twinsun.com>.
  24.  
  25. usage="\
  26. Usage: ifnames [-h] [--help] [-m dir] [--macrodir=dir] [--version] [file...]"
  27. show_version=no
  28.  
  29. : ${AC_MACRODIR=@datadir@}
  30.  
  31. while test $# -gt 0; do
  32.   case "$1" in 
  33.   -h | --help | --h* )
  34.     echo "$usage"; exit 0 ;;
  35.   --macrodir=* | --m*=* )
  36.     AC_MACRODIR="`echo \"$1\" | sed -e 's/^[^=]*=//'`"
  37.     shift ;;
  38.   -m | --macrodir | --m* )
  39.     shift
  40.     test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
  41.     AC_MACRODIR="$1"
  42.     shift ;;
  43.   --version | --versio | --versi | --vers)
  44.     show_version=yes; shift ;;
  45.   --)     # Stop option processing.
  46.     shift; break ;;
  47.   -*) echo "$usage" 1>&2; exit 1 ;;
  48.   *) break ;;
  49.   esac
  50. done
  51.  
  52. if test $show_version = yes; then
  53.   version=`sed -n 's/define.AC_ACVERSION.[     ]*\([0-9.]*\).*/\1/p' \
  54.     $AC_MACRODIR/acgeneral.m4`
  55.   echo "Autoconf version $version"
  56.   exit 0
  57. fi
  58.  
  59. @AWK@ '
  60.   # Record that sym was found in FILENAME.
  61.   function file_sym(sym,  i, fs) {
  62.     if (sym ~ /^[A-Za-z_]/) {
  63.       if (!found[sym,FILENAME]) {
  64.     found[sym,FILENAME] = 1
  65.  
  66.     # Insert FILENAME into files[sym], keeping the list sorted.
  67.     i = 1
  68.     fs = files[sym]
  69.      while (match(substr(fs, i), /^ [^ ]*/) \
  70.             && substr(fs, i + 1, RLENGTH - 1) < FILENAME) {
  71.        i += RLENGTH
  72.     }
  73.     files[sym] = substr(fs, 1, i - 1) " " FILENAME substr(fs, i)
  74.       }
  75.     }
  76.   }
  77.  
  78.   /^[\t ]*#/ {
  79.     if (sub(/^[\t ]*#[\t ]*ifn?def[\t ]+/, "", $0)) {
  80.       sub(/[^A-Za-z_0-9].*/, "", $0)
  81.       file_sym($0)
  82.     }
  83.     if (sub(/^[\t ]*#[\t ]*(el)?if[\t ]+/, "", $0)) {
  84.       # Remove comments.  Not perfect, but close enough.
  85.       gsub(/\/\*[^\/]*(\*\/)?/, "", $0)
  86.  
  87.       for (i = split($0, field, /[^A-Za-z_0-9]+/);  1 <= i;  i--) {
  88.     if (field[i] != "defined") {
  89.       file_sym(field[i])
  90.     }
  91.       }
  92.     }
  93.   }
  94.  
  95.   END {
  96.     for (sym in files) {
  97.       print sym files[sym]
  98.     }
  99.   }
  100. ' ${1+"$@"} | sort
  101.