Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; die if !(@ARGV); my @codes = qw(61 31 21 1 44 16 21 11 7 9 37 39 33 3 2 1 0 32 51 41 10 +); open TARGET,"$ARGV[0]"; open NEW,">$ARGV[0]\.c"; print NEW "#include <EXTERN.h>\n#include <perl.h>\n\n"; print NEW "extern void xs_init();\n"; print NEW "static PerlInterpreter *perl;\n\nvoid main() {\n"; print NEW " int execute[] = {"; my $total = 0; my $counter = 0; my $beginning = 1; while(<TARGET>) { my @tmp = split //,$_; $total += $#tmp; for(my $i=0;$i<=$#tmp;$i++) { my $check = $tmp[$i]; if($beginning) { $beginning = 0; $tmp[$i] = ord($tmp[$i])+$codes[$counter]; print NEW $tmp[$i]; } else { $tmp[$i] = ord($tmp[$i])+$codes[$counter]; print NEW ",".$tmp[$i]; } $counter++; $counter = 0 if $counter>$#codes; } $total++; } print NEW ",0};\n int i = 0;\n int codes[] = {61,31,21,1,44,16,2 +1,11,7,9,37,39,33,3,2,1,0,32,51,41,10};\n char *embedding[] = +{ \"\",\"-e\",\"0\" };\n"; print NEW " char str[".$total."];\n"; print NEW " int count = 0;\n"; print NEW " while(execute[i]!=0) {\n str[i] = (char) +(execute[i] - codes[count]);\n"; print NEW " i++;\n count++;\n + if(count>40) count=0;\n }\n str[i]='\0';\n"; print NEW " perl = perl_alloc();\n perl_construct(perl);\n + perl_parse(perl,xs_init,3,embedding,NULL);\n perl_run(pe +rl);\n eval_pv(str,TRUE);\n perl_destruct(perl);\n per +l_free(perl);\n}"; close TARGET; close NEW; open MAKE,">make"; my $name = $ARGV[0]; print MAKE "perl -MExtUtils::Embed -e xsinit -- -o perlxsi.c "; while(shift @ARGV) { if($ARGV[0]) { print MAKE $ARGV[0]," "; } } print MAKE "\n"; print MAKE "cc -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`\n"; print MAKE "cc -c $name\.c `perl -MExtUtils::Embed -e ccopts`\n"; print MAKE "cc -o exe perlxsi.o $name\.o `perl -MExtUtils::Embed -e ld +opts -- -std DynaLoader `\n"; `chmod 700 ./make`; close MAKE;

In reply to Transformation by Alex the Serb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found