home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / bin / ifnames < prev    next >
Text File  |  1994-12-22  |  3KB  |  94 lines

  1. #!/bin/sh
  2. # ifnames - print the identifiers used in C preprocessor conditionals
  3. # Copyright (C) 1994 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.  
  24. usage="\
  25. Usage: ifnames [-h] [--help] [-m dir] [--macrodir=dir] [--version] [file...]"
  26. show_version=no
  27.  
  28. test -z "$AC_MACRODIR" && AC_MACRODIR=/gnu/lib/autoconf
  29.  
  30. while test $# -gt 0; do
  31.   case "$1" in 
  32.   -h | --help | --h* )
  33.     echo "$usage"; exit 0 ;;
  34.   --macrodir=* | --m*=* )
  35.     AC_MACRODIR="`echo \"$1\" | sed -e 's/^[^=]*=//'`"
  36.     shift ;;
  37.   -m | --macrodir | --m* )
  38.     shift
  39.     test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
  40.     AC_MACRODIR="$1"
  41.     shift ;;
  42.   --version | --versio | --versi | --vers)
  43.     show_version=yes; shift ;;
  44.   --)     # Stop option processing.
  45.     shift; break ;;
  46.   -*) echo "$usage" 1>&2; exit 1 ;;
  47.   *) break ;;
  48.   esac
  49. done
  50.  
  51. if test $show_version = yes; then
  52.   version=`sed -n 's/define.AC_ACVERSION.[     ]*\([0-9.]*\).*/\1/p' \
  53.     $AC_MACRODIR/acgeneral.m4`
  54.   echo "Autoconf version $version"
  55.   exit 0
  56. fi
  57.  
  58. if test $# -eq 0; then
  59.     cat > stdin
  60.     set stdin
  61.     trap 'rm -f stdin' 0
  62.     trap 'rm -f stdin; exit 1' 1 3 15
  63. fi
  64.  
  65. for arg
  66. do
  67. # The first two substitutions remove comments.  Not perfect, but close enough.
  68. # The second is for comments that end on a later line.  The others do:
  69. # Enclose identifiers in @ and a space.
  70. # Handle "#if 0" -- there are no @s to trigger removal.
  71. # Remove non-identifiers.
  72. # Remove any spaces at the end.
  73. # Translate any other spaces to newlines.
  74. sed -n '
  75. s%/\*[^/]*\*/%%g
  76. s%/\*[^/]*%%g
  77. /^[     ]*#[     ]*ifn*def[     ][     ]*\([A-Za-z0-9_]*\).*/s//\1/p
  78. /^[     ]*#[     ]*e*l*if[     ]/{
  79.     s///
  80.     s/@//g
  81.     s/\([A-Za-z_][A-Za-z_0-9]*\)/@\1 /g
  82.     s/$/@ /
  83.     s/@defined //g
  84.     s/[^@]*@\([^ ]* \)[^@]*/\1/g
  85.     s/ *$//
  86.     s/ /\
  87. /g
  88.     p
  89. }
  90. ' $arg | sort -u | sed 's%$% '$arg'%'
  91. done | awk '
  92. { files[$1] = files[$1] " " $2 }
  93. END { for (sym in files) print sym files[sym] }' | sort
  94.