Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: RE: To ease writing perl pieces from within C/C++ programs

by vkonovalov (Monk)
on Jul 04, 2000 at 18:54 UTC ( [id://21015]=note: print w/replies, xml ) Need Help??


in reply to RE: To ease writing perl pieces from within C/C++ programs
in thread To ease writing perl pieces from within C/C++ programs

use strict; my @manifest; my $recurse=0; for (@ARGV) { if (/^-M(.*)$/) { push @manifest, $1; } elsif (s/^-r$//) {$recurse=1} elsif (s/^-R$//) {$recurse=0} } my @files = (); sub getf { my ($p) = @_; my @res = (); opendir FDIR, $p; for (readdir FDIR) { next if /^\.*$/; if (-f "$p/$_") {push @res,"$p/$_"} elsif (-d "$p/$_") {push @res,getf("$p/$_")} } closedir FDIR; return @res; } if ($recurse) { my @f; for (@ARGV) { s/[\/\\]+$//; if (/^(.*?)[\\\/]([^\\\/]+)$/) { my ($path, $patt) = ($1,$2); push @f, getf($path); $patt =~ s/([.+])/\\$1/g; $patt =~ s/\?/./g; $patt =~ s/\*/(?:.*?)/g; push @files, grep {/[\/\\]$patt$/} @f; } elsif (-f) { push @files, $_; } } } else { push @files, @ARGV; } for (@manifest) { open FIN, "<$_"; push @files, grep {!/^#/ and !/^\s*$/} <FIN>; close FIN; } undef $/; sub retr { my $str = shift; for ($str) { s/(["\\])/\\$1/g; s/(\r?\n)/\\n\\$1/g; } return $str; } for (@files) { next unless -f; my $bb = 0; open FIN, "<$_"; binmode FIN; my $f = <FIN>; my $f0 = $f; close FIN; if ( $f=~s/^(#ifdef PERL_SOURCE((?:_S)?))(\r?\n)(.*?)#else(.*?)#endif/ ((index($4.$5,"#ifdef")>-1) or (index($4.$5,"#else")>-1)) ? $& : "$1$3$4#else${3}PERL_EVAL$2(\"\\$3".retr($4)."\");$3#endif" /megs ) { $bb = 1; } if ( $f=~s/^(#ifdef PERL_SOURCE((?:_S)?))(\r?\n)(.*?)#endif/ ((index($4,"#ifdef")>-1) or (index($4,"#else")>-1)) ? $& : "$1$3$4#else${3}PERL_EVAL$2(\"\\$3".retr($4)."\");$3#endif" /megs ) { $bb = 1; } if ($bb and $f0 ne $f) { print STDERR ">>>$_<<<\n"; open FOUT, ">$_"; binmode FOUT; print FOUT $f; close FOUT; } else { print STDERR " $_\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://21015]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found