home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / perl / perlkit / doscpp.pl next >
Text File  |  1990-10-09  |  2KB  |  75 lines

  1.  
  2. # This is run by MS-DOS perl.exe to handle the -P option.
  3. # The Unix version uses /bin/sed, but MS-DOS doesn't because:
  4. #    1) The system may not have a sed clone.
  5. #    2) Some DOS compilers can't be run as a pure filter.
  6. #    3) A user can alter this script to work with his compiler
  7. #       and not have to touch the source code for perl.
  8.  
  9. # This version is Microsoft C 6.0 specific: change as required for
  10. # your compiler.
  11.  
  12. # Invoked by perl as
  13. #    perl -s this_script [input_file] [-x]
  14.  
  15. # Input file is STDIN if not listed explicitly.
  16. # Output is to STDOUT.
  17. # -x is given if the perl script was started by -x.
  18.  
  19. if (!defined($perllib = $ENV{'PERLLIB'})) {
  20.     $perllib = "/usr/local/lib/perl";
  21. }
  22.  
  23. # Create a temp file name.  It must be in the same directory as the
  24. # script so that #includes work properly.
  25.  
  26. $tdir = $ARGV[0];
  27.  
  28. $tdir = "" unless ( $tdir =~ s,(.*[\\/:]).*,$1, );
  29.  
  30. srand;
  31. do {
  32.     $cppinput = sprintf("${tdir}pcpp%04d.c", rand 10000);
  33. } until ( ! -e $cppinput );
  34.  
  35. $SIG{'SIGINT'} = 'handler';
  36. open(CPPINPUT, ">$cppinput") || die "Could not open temp file $cppinput";
  37.  
  38. while (<>) {
  39.     next unless /^#/;
  40.     $x = 0;
  41.     next if/^#\s*include\s/;
  42.     next if/^#\s*define\s/;
  43.     next if/^#\s*undef\s/;
  44.     next if/^#\s*if\s/;
  45.     next if/^#\s*ifdef\s/;
  46.     next if/^#\s*ifndef\s/;
  47.     next if/^#\s*else\s/;
  48.     next if/^#\s*elif\s/;
  49.     next if/^#\s*endif\s/;
  50.     next if/^#\s*pragma\s/;
  51.     next if/^#\s*error\s/;
  52.     $_ = "\n";
  53. }
  54. continue {
  55.     # Work around MSC 6.0's desire to truncate lines at //
  56.     # Won't work for // that are #included, though.
  57.     while ( s,//,/FIX_MSC_SLASH_BUG/,g ) {}
  58.     s,//.*,,;
  59.     print CPPINPUT unless $x;
  60. }
  61.  
  62. close(CPPINPUT);
  63.  
  64. $result = system "cl -EP -I$perllib -DFIX_MSC_SLASH_BUG= $cppinput";
  65.  
  66. unlink $cppinput;
  67.  
  68. exit $result/256;
  69.  
  70. sub handler
  71. {
  72.     close(CPPINPUT);
  73.     unlink $cppinput;
  74. }
  75.