kwsysHeaderDump.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl
  2. #=============================================================================
  3. # KWSys - Kitware System Library
  4. # Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  5. #
  6. # Distributed under the OSI-approved BSD License (the "License");
  7. # see accompanying file Copyright.txt for details.
  8. #
  9. # This software is distributed WITHOUT ANY WARRANTY; without even the
  10. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. # See the License for more information.
  12. #=============================================================================
  13. if ( $#ARGV+1 < 2 )
  14. {
  15. print "Usage: ./kwsysHeaderDump.pl <name> <header>\n";
  16. exit(1);
  17. }
  18. $name = $ARGV[0];
  19. $max = 0;
  20. open(INFILE, $ARGV[1]);
  21. while (chomp ($line = <INFILE>))
  22. {
  23. if (($line !~ /^\#/) &&
  24. ($line =~ s/.*kwsys${name}_([A-Za-z0-9_]*).*/\1/) &&
  25. ($i{$line}++ < 1))
  26. {
  27. push(@lines, "$line");
  28. if (length($line) > $max)
  29. {
  30. $max = length($line);
  31. }
  32. }
  33. }
  34. close(INFILE);
  35. $width = $max + 13;
  36. print sprintf("#define %-${width}s kwsys_ns(${name})\n", "kwsys${name}");
  37. foreach $l (@lines)
  38. {
  39. print sprintf("#define %-${width}s kwsys_ns(${name}_$l)\n",
  40. "kwsys${name}_$l");
  41. }
  42. print "\n";
  43. print sprintf("# undef kwsys${name}\n");
  44. foreach $l (@lines)
  45. {
  46. print sprintf("# undef kwsys${name}_$l\n");
  47. }