This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor File::DosGlob to avoid an unescaped { in a regex.
[perl5.git] / utils / h2ph.PL
index 87f3c7d..a2d737b 100644 (file)
@@ -96,7 +96,7 @@ while (defined (my $file = next_file())) {
     $t = '';
     $tab = 0;
 
-    # $eval_index goes into ``#line'' directives, to help locate syntax errors:
+    # $eval_index goes into '#line' directives, to help locate syntax errors:
     $eval_index = 1;
 
     if ($file eq '-') {
@@ -151,24 +151,22 @@ while (defined (my $file = next_file())) {
                } else {
                    s/^\s+//;
                    expr();
+
                    $new = 1 if $new eq '';
+
+                   # Shunt around such directives as '#define FOO FOO':
+                   next if $new =~ /^\s*&\Q$name\E\s*\z/;
+
                    $new = reindent($new);
                    $args = reindent($args);
-                   if ($t ne '') {
-                       $new =~ s/(['\\])/\\$1/g;        #']);
-
-                       if ($opt_h) {
-                           print OUT $t,"eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name () {",$new,";}' unless defined(\&$name);\n";
-                           $eval_index++;
-                       } else {
-                           print OUT $t,"eval 'sub $name () {",$new,";}' unless defined(\&$name);\n";
-                       }
-                   } else {
-                       # Shunt around such directives as `#define FOO FOO':
-                       next if " \&$name" eq $new;
+                   $new =~ s/(['\\])/\\$1/g;        #']);
 
-                      print OUT $t,"unless(defined(\&$name)) {\n    sub $name () {\t",$new,";}\n}\n";
+                   print OUT $t, 'eval ';
+                   if ($opt_h) {
+                       print OUT "\"\\n#line $eval_index $outfile\\n\" . ";
+                       $eval_index++;
                    }
+                   print OUT "'sub $name () {$new;}' unless defined(&$name);\n";
                }
            } elsif (/^(include|import|include_next)\s*([<\"])(.*)[>\"]/) {
                 $incl_type = $1;
@@ -660,12 +658,12 @@ sub next_file
             if ($opt_r) {
                 expand_glob($file);
             } else {
-                print STDERR "Skipping directory `$file'\n";
+                print STDERR "Skipping directory '$file'\n";
             }
         } elsif ($opt_a) {
             return $file;
         } else {
-            print STDERR "Skipping `$file':  not a file or directory\n";
+            print STDERR "Skipping '$file':  not a file or directory\n";
         }
     }
 
@@ -761,16 +759,8 @@ sub queue_includes_from
 # non-GCC?) C compilers, but gcc uses additional include directories.
 sub inc_dirs
 {
-    my $from_gcc    = `LC_ALL=C $Config{cc} -v 2>&1`;
-    if( !( $from_gcc =~ s:^Reading specs from (.*?)/specs\b.*:$1/include:s ) )
-    { # gcc-4+ :
-       $from_gcc   = `LC_ALL=C $Config{cc} -print-search-dirs 2>&1`;
-       if ( !($from_gcc =~ s/^install:\s*([^\s]+[^\s\/])([\s\/]*).*$/$1\/include/s) )
-       {
-           $from_gcc = '';
-       };
-    };
-    length($from_gcc) ? ($from_gcc, $from_gcc . "-fixed", $Config{usrinc}) : ($Config{usrinc});
+    my $from_gcc   = `LC_ALL=C $Config{cc} -v -E - < /dev/null 2>&1 | awk '/^#include/, /^End of search list/' | grep '^ '`;
+    length($from_gcc) ? (split(' ', $from_gcc), $Config{usrinc}) : ($Config{usrinc});
 }
 
 
@@ -853,7 +843,7 @@ sub _extract_cc_defines
     my $allsymbols  = join " ",
        @Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};
 
-    # Split compiler pre-definitions into `key=value' pairs:
+    # Split compiler pre-definitions into 'key=value' pairs:
     while ($allsymbols =~ /([^\s]+)=((\\\s|[^\s])+)/g) {
        $define{$1} = $2;
        if ($opt_D) {
@@ -930,7 +920,7 @@ is not specified, then links are skipped over.
 
 =item -h
 
-Put ``hints'' in the .ph files which will help in locating problems with
+Put 'hints' in the .ph files which will help in locating problems with
 I<h2ph>.  In those cases when you B<require> a B<.ph> file containing syntax
 errors, instead of the cryptic
 
@@ -949,7 +939,7 @@ This is primarily used for debugging I<h2ph>.
 
 =item -Q
 
-``Quiet'' mode; don't print out the names of the files being converted.
+'Quiet' mode; don't print out the names of the files being converted.
 
 =back