ifnames.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #! @PERL@ -w
  2. # -*- perl -*-
  3. # @configure_input@
  4. eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
  5. if 0;
  6. # ifnames - print the identifiers used in C preprocessor conditionals
  7. # Copyright (C) 1994-1995, 1999-2003, 2005-2012 Free Software
  8. # Foundation, Inc.
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Reads from stdin if no files are given.
  20. # Writes to stdout.
  21. # Written by David MacKenzie <djm@gnu.ai.mit.edu>
  22. # and Paul Eggert <eggert@twinsun.com>.
  23. BEGIN
  24. {
  25. my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
  26. unshift @INC, $pkgdatadir;
  27. # Override SHELL. On DJGPP SHELL may not be set to a shell
  28. # that can handle redirection and quote arguments correctly,
  29. # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
  30. # has detected.
  31. $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
  32. }
  33. use Autom4te::General;
  34. use Autom4te::XFile;
  35. use Autom4te::FileUtils;
  36. # $HELP
  37. # -----
  38. $help = "Usage: $0 [OPTION]... [FILE]...
  39. Scan all of the C source FILES (or the standard input, if none are
  40. given) and write to the standard output a sorted list of all the
  41. identifiers that appear in those files in `#if', `#elif', `#ifdef', or
  42. `#ifndef' directives. Print each identifier on a line, followed by a
  43. space-separated list of the files in which that identifier occurs.
  44. -h, --help print this help, then exit
  45. -V, --version print version number, then exit
  46. Report bugs to <bug-autoconf\@gnu.org>.
  47. GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
  48. General help using GNU software: <http://www.gnu.org/gethelp/>.
  49. ";
  50. # $VERSION
  51. # --------
  52. $version = "ifnames (@PACKAGE_NAME@) @VERSION@
  53. Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
  54. License GPLv3+/Autoconf: GNU GPL version 3 or later
  55. <http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
  56. This is free software: you are free to change and redistribute it.
  57. There is NO WARRANTY, to the extent permitted by law.
  58. Written by David J. MacKenzie and Paul Eggert.
  59. ";
  60. # &parse_args ()
  61. # --------------
  62. # Process any command line arguments.
  63. sub parse_args ()
  64. {
  65. getopt ();
  66. }
  67. # %OCCURRENCE
  68. # -----------
  69. my %occurrence;
  70. # &scan_file ($FILE-NAME)
  71. # -----------------------
  72. sub scan_file ($)
  73. {
  74. my ($file_name) = @_;
  75. my $file = new Autom4te::XFile ("< " . open_quote ($file_name));
  76. while ($_ = $file->getline)
  77. {
  78. # Continuation lines.
  79. $_ .= $file->getline
  80. while (s/\\$//);
  81. # Preprocessor directives.
  82. if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
  83. {
  84. # Remove comments. Not perfect, but close enough.
  85. s(/\*.*?\*/)();
  86. s(/\*.*)();
  87. s(//.*)();
  88. foreach my $word (split (/\W+/))
  89. {
  90. next
  91. if $word eq 'defined' || $word !~ /^[a-zA-Z_]/;
  92. $occurrence{$word}{$file_name} = 1;
  93. }
  94. }
  95. }
  96. }
  97. ## ------ ##
  98. ## Main. ##
  99. ## ------ ##
  100. parse_args();
  101. foreach (@ARGV)
  102. {
  103. scan_file ($_);
  104. }
  105. foreach (sort keys %occurrence)
  106. {
  107. print "$_ ", join (' ', sort keys %{$occurrence{$_}}), "\n";
  108. }
  109. ### Setup "GNU" style for perl-mode and cperl-mode.
  110. ## Local Variables:
  111. ## perl-indent-level: 2
  112. ## perl-continued-statement-offset: 2
  113. ## perl-continued-brace-offset: 0
  114. ## perl-brace-offset: 0
  115. ## perl-brace-imaginary-offset: 0
  116. ## perl-label-offset: -2
  117. ## cperl-indent-level: 2
  118. ## cperl-brace-offset: 0
  119. ## cperl-continued-brace-offset: 0
  120. ## cperl-label-offset: -2
  121. ## cperl-extra-newline-before-brace: t
  122. ## cperl-merge-trailing-else: nil
  123. ## cperl-continued-statement-offset: 2
  124. ## End: