kwsysHeaderDump.pl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl
  2. #
  3. # Program: KWSys - Kitware System Library
  4. # Module: $RCSfile$
  5. #
  6. # Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
  7. # See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  8. #
  9. # This software is distributed WITHOUT ANY WARRANTY; without even
  10. # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. # PURPOSE. See the above copyright notices 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. }