Advertisement
Guest User

50 kb php

a guest
Dec 1st, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 51.86 KB | None | 0 0
  1. <?php
  2.  
  3. if( !function_exists('str_split') )
  4. {
  5.     function str_split($string, $split_length=1)
  6.     {
  7.         $array = array();
  8.         $len = strlen($string);
  9.         do
  10.         {
  11.             $part = '';
  12.             for ($j = 0; $j < $split_length; $j++)
  13.             {
  14.                 $part .= $string{$i};
  15.                 $i++;
  16.             }
  17.             $array[] = $part;
  18.         }
  19.         while ($i < $len);
  20.         return $array;
  21.     }
  22. }
  23.  
  24. class flogback {
  25.   var $code;
  26.   function flogback($x) {
  27.     $this->code=$x;
  28.   }
  29.   function call($x) {
  30.     global $thestack;
  31.     $thestack[]=unserialize(serialize($x)); //if you don't do this it crashes
  32.     execcode($this->code);
  33.     return array_pop($thestack);
  34.   }
  35. }
  36.  
  37. function array_repeat($a,$c) {
  38.   $o=array();
  39.   while($c--) $o=array_merge($o,$a);
  40.   return $o;
  41. }
  42.  
  43. function array_implode($glue,$pieces) {
  44.   $o=array();
  45.   foreach($pieces as $k=>$v) {
  46.     $o=array_merge($o,(array)$v);
  47.     if($k!=count($pieces)-1) $o=array_merge($o,(array)$glue);
  48.   }
  49.   return $o;
  50. }
  51.  
  52. function array_zip($a) {
  53.   $o=array();
  54.   if(count($a)==0) return $o;
  55.   foreach($a[0] as $k=>$v) {
  56.     $o[$k]=array();
  57.     foreach($a as $K=>$V) {
  58.       $o[$k][$K]=$V[$k];
  59.     }
  60.   }
  61.   return $o;
  62. }
  63.  
  64. function array_tuples($a) {
  65.   $o=array();
  66.   $x=array_fill(0,count($a),0);
  67.   while(1) {
  68.     $o1=array();
  69.     foreach($a as $k=>$v) $o1[$k]=$v[$x[$k]];
  70.     $o[]=$o1;
  71.     for($k=0;$k<=count($x);$k++) {
  72.       if($k==count($x)) return $o;
  73.       if(count($a[$k])==++$x[$k]) $x[$k]=0; else break;
  74.     }
  75.   }
  76. }
  77.  
  78. function array_tuples_callback($a,$f) {
  79.   global $thestack;
  80.   $x=array_fill(0,count($a),0);
  81.   while(1) {
  82.     $o1=array();
  83.     foreach($a as $k=>$v) $o1[$k]=$v[$x[$k]];
  84.     $thestack[]=$o1;
  85.     execcode($f);
  86.     for($k=0;$k<=count($x);$k++) {
  87.       if($k==count($x)) return 0;
  88.       if(count($a[$k])==++$x[$k]) $x[$k]=0; else break;
  89.     }
  90.   }
  91. }
  92.  
  93. function mark_stack() {
  94.   global $thestack;
  95.   global $stackmark;
  96.   $stackmark[]=count($thestack);
  97. }
  98.  
  99. function end_mark_stack() {
  100.   global $thestack;
  101.   global $stackmark;
  102.   $thestack[]=array_splice($thestack,array_pop($stackmark));
  103. }
  104.  
  105. function almost_execute($f) {
  106.   global $thestack;
  107.   global $stackmark;
  108.   global $vars;
  109.   $my_thestack=$thestack;
  110.   $my_stackmark=$stackmark;
  111.   $my_vars=$vars;
  112.   execcode($f);
  113.   $out=array_pop($thestack);
  114.   $thestack=$my_thestack;
  115.   $stackmark=$my_stackmark;
  116.   $vars=$my_vars;
  117.   return $out;
  118. }
  119.  
  120. function maybe_execute($f) {
  121.   global $thestack;
  122.   global $stackmark;
  123.   global $vars;
  124.   $my_thestack=$thestack;
  125.   $my_stackmark=$stackmark;
  126.   $my_vars=$vars;
  127.   if(execcode($f)) {
  128.     $thestack=$my_thestack;
  129.     $stackmark=$my_stackmark;
  130.     $vars=$my_vars;
  131.     return 1;
  132.   } else {
  133.     return 0;
  134.   }
  135. }
  136.  
  137. function str_expand_special($s) {
  138.   global $thestack;
  139.   global $vars;
  140.   $out="";
  141.   for($i=0;$i<strlen($s);$i++) {
  142.     $c=$s[$i];
  143.     if($c=='\\') $c.=$s[++$i];
  144.     switch($c) {
  145.       case '\\n': $out.="\n"; break;
  146.       case '\\r': $out.="\r"; break;
  147.       case '\\t': $out.="\t"; break;
  148.       case '\\v': $out.="\v"; break;
  149.       case '\\f': $out.="\f"; break;
  150.       case '\\C': $out.="{"; break;
  151.       case '\\D': $out.="}"; break;
  152.       case '\\0': $out.=chr(0); break;
  153.       case ':':
  154.         $c=ord($s[++$i]); $d=ord($out[strlen($out)-1]);
  155.         if($c>$d) {
  156.           for($d++;$d<=$c;$d++) $out.=chr($d);
  157.         } else {
  158.           for($d--;$d>=$c;$d--) $out.=chr($d);
  159.         }
  160.         break;
  161.       case '<':
  162.         $d=strpos($c=substr($s,++$i),'>');
  163.         if(!$d) {$c='_';$d++;}
  164.         $i+=$d;
  165.         $out.=$vars[substr($c,0,$d)];
  166.         break;
  167.       case '|': $out.=array_pop($thestack); break;
  168.       case '?':
  169.         if(array_pop($thestack)) $i++;
  170.         break;
  171.       case '!':
  172.         if(!array_pop($thestack)) $i++;
  173.         break;
  174.       case '$':
  175.         $d=hexdec(substr($s,++$i,2));
  176.         $i++;
  177.         $out.=chr($d);
  178.         break;
  179.       case '*':
  180.         $d=hexdec(substr($s,++$i,2));
  181.         $i++;
  182.         $out.=str_repeat($out[strlen($out)-1],$d);
  183.         break;
  184.       case '[':
  185.         $d=hexdec(substr($s,++$i,2));
  186.         $i++;
  187.         $out.=substr($out,0,$d);
  188.         break;
  189.       case ']':
  190.         $d=hexdec(substr($s,++$i,2));
  191.         $i++;
  192.         $out.=substr($out,strlen($out)-$d);
  193.         break;
  194.       case '{': //reserved
  195.       case '}': //reserved
  196.       case '^': //reserved
  197.         break;
  198.       default:
  199.         if($c[0]=='\\') $out.=$c[1]; else $out.=$c;
  200.     }
  201.   }
  202.   return $out;
  203. }
  204.  
  205. function brainfuck($c,$s) {
  206.   global $thestack,$stdinput;
  207.   $p=0; $reg=0;
  208.   for($i=0;$i<strlen($c);$i++) {
  209.     if(ctype_digit($c{$i})) $s[$p]=chr((ord($s[$p])*16+$c{$i})&255);
  210.     if(ctype_xdigit($c{$i}) && ctype_upper($c{$i})) $s[$p]=chr((ord($s[$p])*16+ord($c{$i})-55)&255);
  211.     if($c{$i}=='+') $s[$p]=chr((ord($s[$p])+1)%256);
  212.     if($c{$i}=='-') $s[$p]=chr((ord($s[$p])+255)%256);
  213.     if($c{$i}=='<') $p--;
  214.     if($c{$i}=='>') $p++;
  215.     if($c{$i}==',') $s[$p]=fgetc($stdinput);
  216.     if($c{$i}=='.') echo $s[$p];
  217.     if($c{$i}=='[') if(!ord($s[$p])) {
  218.       $j=1;
  219.       while($j>0) {
  220.         $i++;
  221.         if($c{$i}=='[') $j++;
  222.         if($c{$i}==']') $j--;
  223.       }
  224.     }
  225.     if($c{$i}==']') if(ord($s[$p])) {
  226.       $j=1;
  227.       while($j>0) {
  228.         $i--;
  229.         if($c{$i}==']') $j++;
  230.         if($c{$i}=='[') $j--;
  231.       }
  232.     }
  233.     if($c{$i}=='i') $s=substr($s,0,$p).chr(0).substr($s,$p);
  234.     if($c{$i}=='d') $s=substr($s,0,$p).substr($s,$p+1);
  235.     if($c{$i}=='!') $s[$p]=chr($reg);
  236.     if($c{$i}=='?') $reg=ord($s[$p]);
  237.     if($c{$i}==';') $s[$p]=chr(array_pop($thestack));
  238.     if($c{$i}==':') $thestack[]=ord($s[$p]);
  239.     if($c{$i}=='a') $s[$p]=chr((ord($s[$p])+$reg)%256);
  240.     if($c{$i}=='s') $s[$p]=chr((ord($s[$p])+256-$reg)%256);
  241.     if($c{$i}=='#') $thestack[]=0;
  242.     if($c{$i}=='p') $thestack[]=$p;
  243.     if($c{$i}=='P') $p=array_pop($thestack);
  244.     if($c{$i}=='l') $thestack[]=substr($s,0,$p);
  245.     if($c{$i}=='r') $thestack[]=substr($s,$p);
  246.     if($c{$i}=='L') $s=substr($s,0,$p);
  247.     if($c{$i}=='R') {$s=substr($s,$p); $p=0;}
  248.     if($c{$i}=='~') execcode(array_pop($thestack));
  249.     if($c{$i}=='`') $s[$p]=$c{++$i};
  250.     if($c{$i}=='"') {
  251.       while($c{++$i}!='"') $s[$p++]=$c{$i};
  252.     }
  253.     if($c{$i}=="'") {
  254.       while($c{++$i}!='"') {$s=substr($s,0,$p).$c{$i}.substr($s,$p); $p++;}
  255.     }
  256.     if($p==-1) {
  257.       $p=0;
  258.       $s=chr(0).$s;
  259.     }
  260.   }
  261.   return array($s,$p);
  262. }
  263.  
  264. function matrix_add($x,$y) {
  265.   global $thestack;
  266.   if(is_array($x) && is_array($y)) {
  267.     $o=array();
  268.     foreach($x as $k=>$v) $o[]=matrix_add($v,$y[$k]);
  269.     return $o;
  270.   } else if(is_int($x) && is_int($y)) {
  271.     return $x+$y;
  272.   } else if(is_int($x) && is_array($y)) {
  273.     $o=array();
  274.     foreach($y as $v) $o[]=$v+$x;
  275.     return $o;
  276.   } else if(is_array($x) && is_int($y)) {
  277.     $o=array();
  278.     foreach($x as $v) $o[]=$v+$y;
  279.     return $o;
  280.   } else if(is_string($x)) {
  281.     $thestack[]=$y;
  282.     execcode($x);
  283.     return array_pop($thestack);
  284.   } else if(is_string($y)) {
  285.     $thestack[]=$x;
  286.     execcode($y);
  287.     return array_pop($thestack);
  288.   } else {
  289.     return array();
  290.   }
  291. }
  292.  
  293. $opsmap =
  294.   array(
  295.         '`' => function(){ //reverse-eval;
  296.           global $thestack;
  297.           $v=array_pop($thestack);
  298.           if(is_int($v)) {
  299.             if($v>=0) $thestack[]=''.$v; else $thestack[]='_'.-$v;
  300.           } else if(is_string($v)) {
  301.             $thestack[]='{'.$v.'}';
  302.           }
  303.         },
  304.         '!' => function(){ //logical-not
  305.           global $thestack;
  306.           $v=array_pop($thestack);
  307.           if($v===0 || $v==="" || $v===array()) $thestack[]=1;
  308.           else $thestack[]=0;
  309.         },
  310.         '@' => function(){ //rotate
  311.           global $thestack;
  312.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  313.           array_push($thestack,$v2,$v1,$v3);
  314.         },
  315.         '$' => function() { //copy/sort
  316.           global $thestack;
  317.           $v=array_pop($thestack);
  318.           if(is_int($v)) {
  319.             $thestack[]=$thestack[count($thestack)-1-$v];
  320.           } else if(is_string($v)) {
  321.             $v=str_split($v);
  322.             sort($v);
  323.             $thestack[]=implode('',$v);
  324.           } else if(is_array($v)) {
  325.             sort($v);
  326.             $thestack[]=$v;
  327.           }
  328.         },
  329.         '+' => function() { //add/concatenate
  330.           global $thestack;
  331.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  332.           if(is_array($v2) && !is_array($v1)) {
  333.             $thestack[]=array_merge($v2,array($v1));
  334.           } else if(is_int($v1)) {
  335.             $thestack[]=$v2+$v1;
  336.           } else if(is_string($v1)) {
  337.             $thestack[]=$v2.$v1;
  338.           } else if(is_array($v1)) {
  339.             $thestack[]=array_merge((array)$v2,$v1);
  340.           }
  341.         },
  342.         '-' => function() { //subtract/set-subtract
  343.           global $thestack;
  344.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  345.           if(is_array($v1) || is_array($v2)) {
  346.             $thestack[]=array_values(array_diff($v2,(array)$v1));
  347.           } else if(is_int($v1)) {
  348.             $thestack[]=$v2-$v1;
  349.           } else if(is_string($v1)) {
  350.             $thestack[]=str_replace($v1,'',$v2);
  351.           }
  352.         },
  353.         '*' => function() { //multiply/repeat/join/fold
  354.           global $thestack;
  355.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  356.           if(is_int($v1) && is_int($v2)) {
  357.             $thestack[]=$v2*$v1;
  358.           } else if(is_int($v1) && is_string($v2)) {
  359.             $thestack[]=str_repeat($v2,$v1);
  360.           } else if(is_int($v1) && is_array($v2)) {
  361.             $thestack[]=array_repeat($v2,$v1);
  362.           } else if(is_string($v1) && is_string($v2)) {
  363.             $thestack[]=implode($v1,str_split($v2));
  364.           } else if(is_array($v1) && is_array($v2)) {
  365.             $thestack[]=array_implode($v1,$v2);
  366.           } else if(is_string($v1) && is_array($v2)) {
  367.             $thestack[]=array_shift($v2);
  368.             foreach($v2 as $v) {
  369.               $thestack[]=$v;
  370.               execcode($v1);
  371.             }
  372.           }
  373.         },
  374.         '/' => function() { //divide/explode/chunk/each
  375.           global $thestack;
  376.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  377.           if(is_int($v1) && is_int($v2)) {
  378.             $thestack[]=(int)($v2/$v1);
  379.           } else if(is_int($v1) && is_string($v2)) {
  380.             $thestack[]=str_split($v2,$v1);
  381.           } else if(is_int($v1) && is_array($v2)) {
  382.             $thestack[]=array_chunk($v2,$v1);
  383.           } else if(is_string($v1) && is_string($v2)) {
  384.             $thestack[]=explode($v1,$v2);
  385.           } else if(is_array($v1) && is_array($v2)) {
  386.             // It's supposed to do something?
  387.           } else if(is_string($v1) && is_array($v2)) {
  388.             foreach($v2 as $v) {
  389.               $thestack[]=$v;
  390.               execcode($v1);
  391.             }
  392.           }
  393.         },
  394.         '%' => function() { //modulo/skip-elements/while
  395.           global $thestack;
  396.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  397.           if(is_int($v1) && is_int($v2)) {
  398.             while($v2<0) $v2+=$v1;
  399.             $thestack[]=$v2%$v1;
  400.           } else if(is_int($v1) && is_array($v2)) {
  401.             $out=array();
  402.             if($v1) for($v=($v1>0?0:count($v2)-1);isset($v2[$v]);$v+=$v1) $out[]=$v2[$v];
  403.             $thestack[]=$out;
  404.           } else if(is_string($v1) && is_string($v2)) {
  405.             execcode($v2);
  406.             while(array_pop($thestack)) execcode($v1."\n".$v2);
  407.           } else if(is_string($v1) && is_array($v2)) {
  408.             mark_stack();
  409.             foreach($v2 as $v) {
  410.               $thestack[]=$v;
  411.               execcode($v1);
  412.             }
  413.             end_mark_stack();
  414.           }
  415.         },
  416.         '|' => function() { //or/set-or
  417.           global $thestack;
  418.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  419.           if(is_int($v1) && is_int($v2)) {
  420.             $thestack[]=$v2|$v1;
  421.           } else if(is_array($v1) && is_array($v2)) {
  422.             $thestack[]=array_values(array_unique(array_merge($v2,$v1)));
  423.           } else if(is_string($v1)) {
  424.             if($v2) $thestack[]=$v2; else execcode($v1);
  425.           }
  426.         },
  427.         '&' => function() { //and/set-and
  428.           global $thestack;
  429.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  430.           if(is_int($v1) && is_int($v2)) {
  431.             $thestack[]=$v2&$v1;
  432.           } else if(is_array($v1) && is_array($v2)) {
  433.             $thestack[]=array_values(array_intersect($v2,$v1));
  434.           } else if(is_string($v1)) {
  435.             if($v2) execcode($v1); else $thestack[]=$v2;
  436.           }
  437.         },
  438.         '^' => function() { //xor/set-xor/filter
  439.           global $thestack;
  440.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  441.           if(is_int($v1) && is_int($v2)) {
  442.             $thestack[]=$v2^$v1;
  443.           } else if(is_array($v1) && is_array($v2)) {
  444.             $thestack[]=array_merge(array_diff($v2,$v1),array_diff($v1,$v2));
  445.           } else if(is_string($v1) && is_array($v2)) {
  446.             $out=array();
  447.             foreach($v2 as $v) {
  448.               $thestack[]=$v;
  449.               execcode($v1);
  450.               if(array_pop($thestack)) $out[]=$v;
  451.             }
  452.             $thestack[]=$out;
  453.           }
  454.         },
  455.         '[' => function() { //mark
  456.           global $thestack;
  457.           mark_stack();
  458.         },
  459.         ']' => function() { //end-mark/quick-echo-string
  460.           global $thestack;
  461.           global $stackmark;
  462.           if(count($stackmark)) {
  463.             end_mark_stack();
  464.           } else {
  465.             $v=array_pop($thestack);
  466.             if(is_array($v)) $v=implode('',$v);
  467.             echo $v;
  468.           }
  469.         },
  470.         '\\' => function() { //swap
  471.           global $thestack;
  472.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  473.           array_push($thestack,$v1,$v2);
  474.         },
  475.         ';' => function() { //discard
  476.           global $thestack;
  477.           array_pop($thestack);
  478.         },
  479.         '<' => function() { //less
  480.           global $thestack;
  481.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  482.           if((is_int($v1) && is_int($v2)) || (is_string($v1) && is_string($v2))) {
  483.             $thestack[]=(int)($v2<$v1);
  484.           } else if(is_int($v1) && is_array($v2)) {
  485.             $thestack[]=array_splice($v2,0,$v1);
  486.           }
  487.         },
  488.         '>' => function() { //greater
  489.           global $thestack;
  490.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  491.           if((is_int($v1) && is_int($v2)) || (is_string($v1) && is_string($v2))) {
  492.             $thestack[]=(int)($v2>$v1);
  493.           } else if(is_int($v1) && is_array($v2)) {
  494.             $thestack[]=array_splice($v2,$v1);
  495.           }
  496.         },
  497.         '=' => function() { //equal/array-element
  498.           global $thestack;
  499.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  500.           if((is_int($v1) && is_int($v2)) || (is_string($v1) && is_string($v2))) {
  501.             $thestack[]=(int)($v2==$v1);
  502.           } else if(is_int($v1) && is_array($v2)) {
  503.             if($v1<0) $v1=count($v2)+$v1;
  504.             $thestack[]=$v2[$v1];
  505.           }
  506.         },
  507.         ',' => function() { //range/count
  508.           global $thestack;
  509.           $v1=array_pop($thestack);
  510.           if(is_int($v1)) {
  511.             if($v1>0) $thestack[]=range(0,$v1-1);
  512.             if($v1==0) $thestack[]=array();
  513.             if($v1<0) $thestack[]=range(-1,$v1);
  514.           } else if(is_array($v1)) {
  515.             $thestack[]=count($v1);
  516.           } else if(is_string($v1)) {
  517.             $thestack[]=strlen($v1);
  518.           }
  519.         },
  520.         '.' => function() { //duplicate
  521.           global $thestack;
  522.           $v=array_pop($thestack);
  523.           array_push($thestack,$v,$v);
  524.         },
  525.         '?' => function() { //power/find/if
  526.           global $thestack;
  527.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  528.           if(is_int($v1) && is_int($v2)) {
  529.             $thestack[]=(int)pow($v2,$v1);
  530.           } else if(is_array($v1)) {
  531.             $v=array_search($v2,$v1);
  532.             if(is_int($v)) $thestack[]=$v; else $thestack[]=-1;
  533.           } else if(is_string($v1) && is_array($v2)) {
  534.             $out=-1;
  535.             foreach($v2 as $k=>$v) {
  536.               $thestack[]=$v;
  537.               execcode($v1);
  538.               if(array_pop($thestack)) {$out=$k;break;}
  539.             }
  540.             $thestack[]=$out;
  541.           } else if(is_string($v1) && is_int($v2)) {
  542.             if($v2) execcode($v1);
  543.           } else if(is_string($v1) && is_string($v2)) {
  544.             $v=strpos($v2,$v1);
  545.             if($v===false) $v=-1;
  546.             $thestack[]=$v;
  547.           }
  548.         },
  549.         '(' => function() { //decrement/uncons-first
  550.           global $thestack;
  551.           $v=array_pop($thestack);
  552.           if(is_int($v)) {
  553.             $thestack[]=$v-1;
  554.           } else if(is_array($v)) {
  555.             $v2=array_shift($v);
  556.             array_push($thestack,$v,$v2);
  557.           } else if(is_string($v)) {
  558.             $v=str_split($v,1);
  559.             $v2=array_shift($v);
  560.             array_push($thestack,implode("",$v),$v2);
  561.           }
  562.         },
  563.         'A+' => function() { //array-sum
  564.           global $thestack;
  565.           $v=array_pop($thestack);
  566.           if(is_string($v)) {
  567.             $v2=array_pop($thestack);
  568.             mark_stack();
  569.             foreach($v2 as $v1) {
  570.               $thestack[]=$v;
  571.               execcode($v);
  572.             }
  573.             end_mark_stack();
  574.           }
  575.           $thestack[]=array_sum($v);
  576.         },
  577.         'A.' => function() { //array-implode
  578.           global $thestack;
  579.           $v=array_pop($thestack);
  580.           $thestack[]=implode('',$v);
  581.         },
  582.         'A,' => function() { //array-implode-delimiter
  583.           global $thestack;
  584.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  585.           $thestack[]=implode($v1,$v2);
  586.         },
  587.         'A_' => function() { //array-implode-newline
  588.           global $thestack;
  589.           $v=array_pop($thestack);
  590.           if(is_array($v)) $thestack[]=implode("\n",$v);
  591.           else $thestack[]=''.$v;
  592.         },
  593.         'A#' => function() { //array-implode-space
  594.           global $thestack;
  595.           $v=array_pop($thestack);
  596.           if(is_array($v)) $thestack[]=implode(" ",$v);
  597.           else $thestack[]=''.$v;
  598.         },
  599.         'A*' => function() { //array-product
  600.           global $thestack;
  601.           $v=array_pop($thestack);
  602.           if(is_string($v)) {
  603.             $v2=array_pop($thestack);
  604.             mark_stack();
  605.             foreach($v2 as $v1) {
  606.               $thestack[]=$v;
  607.               execcode($v);
  608.             }
  609.             end_mark_stack();
  610.           }
  611.           $out=1;
  612.           foreach($v as $v1) $out*=$v1;
  613.           $thestack[]=$out;
  614.         },
  615.         'Az' => function() { //array-zip
  616.           global $thestack;
  617.           $v=array_pop($thestack);
  618.           if(!count($v)) {
  619.             $thestack[]=array();
  620.           } else if(is_array($v[0])) {
  621.             $thestack[]=array_zip($v);
  622.           } else if(is_string($v[0])) {
  623.             $v=array_map(str_split,$v);
  624.             $thestack[]=array_map(implode,array(),array_zip($v));
  625.           } else if(is_int($v[0])) {
  626.             $v2=array_fill(0,32,(int)0);
  627.             for($v1=0;$v1<count($v);$v1++) {
  628.               for($v3=0;$v3<32;$v3++) {
  629.                 $v2[$v3]|=(($v[$v1]>>$v3)&1)<<$v1;
  630.               }
  631.             }
  632.             $thestack[]=$v2;
  633.           }
  634.         },
  635.         'Ar' => function() { //array-reverse/string-reverse
  636.           global $thestack;
  637.           $v=array_pop($thestack);
  638.           if(is_array($v)) $thestack[]=array_reverse($v);
  639.           if(is_string($v)) $thestack[]=strrev($v);
  640.           if(is_int($v)) $thestack[]=(int)(0+strrev(''.$v));
  641.         },
  642.         'A$' => function() { //array-multisort
  643.           global $thestack;
  644.           $v=array_pop($thestack);
  645.           call_user_func_array(array_multisort,&$v);
  646.           $thestack[]=$v;
  647.         },
  648.         'A=' => function() { //array-set-element
  649.           global $thestack;
  650.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  651.           if(is_array($v2) && is_int($v1)) {
  652.             if($v1>=0 && $v1<=count($v2)) $v2[$v1]=$v3;
  653.             $thestack[]=$v2;
  654.           }
  655.         },
  656.         'Af' => function() { //array-flatten
  657.           global $thestack;
  658.           $v=array_pop($thestack);
  659.           foreach($v as $v1=>$v2) $v[$v1]=(array)$v2;
  660.           $thestack[]=call_user_func_array(array_merge,$v);
  661.         },
  662.         'A\\' => function() { //array-diagonal-bs
  663.           global $thestack;
  664.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  665.           $out=array();
  666.           foreach($v2 as $k=>$v) if(isset($v[$v1+$k])) $out[]=$v[$v1+$k];
  667.           $thestack[]=$out;
  668.         },
  669.         'A/' => function() { //array-diagonal-fs
  670.           global $thestack;
  671.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  672.           $out=array();
  673.           foreach($v2 as $k=>$v) if(isset($v[$v1-$k])) $out[]=$v[$v1-$k];
  674.           $thestack[]=$out;
  675.         },
  676.         'At' => function() { //array-tuples
  677.           global $thestack;
  678.           $v=array_pop($thestack);
  679.           if(count($v) && !is_array($v[0])) $v=array(array_pop($thestack),$v);
  680.           $thestack[]=array_tuples($v);
  681.         },
  682.         'Ax' => function() { //array-cross
  683.           global $thestack;
  684.           $v1=(array)array_pop($thestack); $v2=(array)array_pop($thestack);
  685.           $v3=array_pop($thestack);
  686.           mark_stack();
  687.           foreach(array_tuples(array($v1,$v2)) as $v) {
  688.             $thestack[]=$v;
  689.             execcode($v3);
  690.           }
  691.           end_mark_stack();
  692.         },
  693.         'Ag' => function() { //array-get-consecutive
  694.           global $thestack;
  695.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  696.           $out=array();
  697.           for($k=0;$k<=count($v2)-$v1;$k++) $out[]=array_slice($v2,$k,$v1);
  698.           $thestack[]=$out;
  699.         },
  700.         'A-' => function() { //array-remove-element
  701.           global $thestack;
  702.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  703.           while($v1<0) $v1+=count($v2);
  704.           $v1=$v1%count($v2);
  705.           $v1=array_splice($v2,$v1,1);
  706.           $thestack[]=$v2;
  707.           $thestack[]=$v1;
  708.         },
  709.         'Au' => function() { //array-u-turn
  710.           global $thestack;
  711.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  712.           while($v1<0) $v1+=count($v2);
  713.           $thestack[]=array_merge(array_slice($v2,$v1),array_slice($v2,0,$v1));
  714.         },
  715.         'A?' => function() { //array-test-unique
  716.           global $thestack;
  717.           $v=array_pop($thestack);
  718.           if(count($v)==count(array_unique($v))) $thestack[]=1;
  719.           else $thestack[]=0;
  720.         },
  721.         'AP[' => function() { //array-pad-left
  722.           global $thestack;
  723.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  724.           $thestack[]=array_slice(array_merge(array_fill(0,$v2,$v1),$v3),-$v2);
  725.         },
  726.         'AP]' => function() { //array-pad-right
  727.           global $thestack;
  728.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  729.           $thestack[]=array_slice(array_merge($v3,array_fill(0,$v2,$v1)),0,$v2);
  730.         },
  731.         'AZt' => function() { //array-tuples-callback
  732.           global $thestack;
  733.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  734.           $thestack[]=array_tuples_callback($v2,$v1);
  735.         },
  736.         'B+' => function() { //bcmath-add
  737.           global $thestack;
  738.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  739.           $thestack[]=bcadd($v2,$v1);
  740.         },
  741.         'B-' => function() { //bcmath-subtract
  742.           global $thestack;
  743.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  744.           $thestack[]=bcsub($v2,$v1);
  745.         },
  746.         'B*' => function() { //bcmath-multiply
  747.           global $thestack;
  748.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  749.           $thestack[]=bcmul($v2,$v1);
  750.         },
  751.         'B/' => function() { //bcmath-divide
  752.           global $thestack;
  753.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  754.           $thestack[]=bcdiv($v2,$v1);
  755.         },
  756.         'B%' => function() { //bcmath-modulo
  757.           global $thestack;
  758.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  759.           $thestack[]=bcmod($v2,$v1);
  760.         },
  761.         'B?' => function() { //bcmath-power
  762.           global $thestack;
  763.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  764.           $thestack[]=bcpow($v2,$v1);
  765.         },
  766.         'B=' => function() { //bcmath-compare
  767.           global $thestack;
  768.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  769.           $thestack[]=bccomp($v2,$v1);
  770.         },
  771.         'Bs' => function() { //bcmath-scale
  772.           global $thestack;
  773.           $v=array_pop($thestack);
  774.           $thestack[]=bcscale($v);
  775.         },
  776.         'Ia' => function() { //input-all
  777.           global $thestack;
  778.           global $stdinput;
  779.           //$v=file_get_contents("php://stdin");
  780.           $v='';
  781.           while(!feof($stdinput)) $v.=fread($stdinput,8192);
  782.           $thestack[]=str_replace("\r","",$v);
  783.         },
  784.         'Il' => function() { //input-line
  785.           global $thestack;
  786.           global $stdinput;
  787.           $v=fgets($stdinput);
  788.           while(strlen($v) >= 1 && ($v[strlen($v)-1]=="\r" || $v[strlen($v)-1]=="\n" ) )
  789.             $v=substr($v,0,-1);
  790.           $thestack[]=$v;
  791.         },
  792.         'I1' => function() { //input-line-or-eof
  793.           global $thestack;
  794.           global $stdinput;
  795.           $v=fgets($stdinput);
  796.           if(feof($stdinput)) return 0;
  797.           while(strlen($v) >= 1 && ($v[strlen($v)-1]=="\r" || $v[strlen($v)-1]=="\n") )
  798.             $v=substr($v,0,-1);
  799.           $thestack[]=$v;
  800.         },
  801.         'I0' => function() { //input-until
  802.           global $thestack;
  803.           global $stdinput;
  804.           $v1=array_pop($thestack);
  805.           $o=""; $v3=0;
  806.           while(($v=fgetc($stdinput))!==false) {
  807.             if($v==$v1[0] && $v3==0) break;
  808.             if(strlen($v1)>2) {
  809.               if($v==$v1[1]) $v3++;
  810.               if($v==$v1[2]) $v3--;
  811.             }
  812.             $o.=$v;
  813.           }
  814.           $thestack[]=$o;
  815.         },
  816.         'M2' => function() { //math-dec-to-bin
  817.           global $thestack;
  818.           $v=array_pop($thestack);
  819.           $thestack[]=decbin($v);
  820.         },
  821.         'Ma' => function() { //math-absolute
  822.           global $thestack;
  823.           $v=array_pop($thestack);
  824.           $thestack[]=abs($v);
  825.         },
  826.         'Ms' => function() { //math-sign
  827.           global $thestack;
  828.           $v=array_pop($thestack);
  829.           $thestack[]=($v?($v>0?1:-1):0);
  830.         },
  831.         'M$' => function() { //math-interleave
  832.           global $thestack;
  833.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  834.           $v1=($v1|($v1<<8))&0x00FF00FF;
  835.           $v1=($v1|($v1<<4))&0x0F0F0F0F;
  836.           $v1=($v1|($v1<<2))&0x33333333;
  837.           $v1=($v1|($v1<<1))&0x55555555;
  838.           $v2=($v2|($v2<<8))&0x00FF00FF;
  839.           $v2=($v2|($v2<<4))&0x0F0F0F0F;
  840.           $v2=($v2|($v2<<2))&0x33333333;
  841.           $v2=($v2|($v2<<1))&0x55555555;
  842.           $thestack[]=$v1|($v2<<1);
  843.         },
  844.         'Mb' => function() { //math-base-convert
  845.           global $thestack;
  846.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  847.           $thestack[]=base_convert((string)$v1,$v2,$v3);
  848.         },
  849.         'Md' => function() { //math-decimal
  850.           global $thestack;
  851.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  852.           $thestack[]=(int)base_convert($v2,$v1,10);
  853.         },
  854.         'P.' => function() { //print-value
  855.           global $thestack;
  856.           $v=array_pop($thestack);
  857.           if(is_array($v)) echo $v[0];
  858.           else echo $v;
  859.         },
  860.         'P,' => function() { //print-value-newline
  861.           global $thestack;
  862.           echo array_pop($thestack)."\n";
  863.         },
  864.         'P_' => function() { //print-newline
  865.           global $thestack;
  866.           echo "\n";
  867.         },
  868.         'Pr' => function() { //print-r
  869.           global $thestack;
  870.           print_r(array_pop($thestack));
  871.         },
  872.         'Ps' => function() { //print-stack
  873.           global $thestack;
  874.           var_dump($thestack);
  875.         },
  876.         'Pc' => function() { //print-character
  877.           global $thestack;
  878.           $v=array_pop($thestack);
  879.           if(is_int($v)) echo chr($v);
  880.           if(is_string($v)) echo $v[0];
  881.           if(is_array($v)) foreach($v as $v1) echo chr($v1);
  882.         },
  883.         'Pf' => function() { //print-format
  884.           global $thestack;
  885.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  886.           call_user_func_array(printf,array_merge((array)$v1,(array)$v2));
  887.         },
  888.         'Pa' => function() { //print-all-list
  889.           global $thestack;
  890.           $v=array_pop($thestack);
  891.           if(is_array($v)) echo implode("\n",$v);
  892.           else echo $v;
  893.         },
  894.         'Sc' => function() { //string-contains
  895.           global $thestack;
  896.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  897.           $thestack[]=(strcspn($v2,$v1)==strlen($v2)?0:1);
  898.         },
  899.         'Sn' => function() { //string-append-newline
  900.           global $thestack;
  901.           $v=array_pop($thestack);
  902.           $thestack[]=$v."\n";
  903.         },
  904.         'St' => function() { //string-translate
  905.           global $thestack;
  906.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  907.           $thestack[]=strtr($v3,$v2,$v1);
  908.         },
  909.         'Sl' => function() { //string-lowercase
  910.           global $thestack;
  911.           $v=array_pop($thestack);
  912.           $thestack[]=strtolower($v);
  913.         },
  914.         'Su' => function() { //string-uppercase
  915.           global $thestack;
  916.           $v=array_pop($thestack);
  917.           $thestack[]=strtoupper($v);
  918.         },
  919.         'Sf' => function() { //string-format
  920.           global $thestack;
  921.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  922.           $thestack[]=call_user_func_array(sprintf,array_merge((array)$v1,(array)$v2));
  923.         },
  924.         'Sb' => function() { //string-brainfuck
  925.           global $thestack;
  926.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  927.           $thestack=array_merge($thestack,brainfuck($v1,$v2));
  928.         },
  929.         'Sx' => function() { //string-expand
  930.           global $thestack;
  931.           $v=array_pop($thestack);
  932.           $thestack[]=str_expand_special($v);
  933.         },
  934.         'S|' => function() { //string-trim
  935.           global $thestack;
  936.           $v=array_pop($thestack);
  937.           if(is_array($v)) $v=implode("\n",$v);
  938.           $thestack[]=trim($v);
  939.         },
  940.         'S[' => function() { //string-ltrim
  941.           global $thestack;
  942.           $v=array_pop($thestack);
  943.           if(is_array($v)) $v=implode("\n",$v);
  944.           $thestack[]=ltrim($v);
  945.         },
  946.         'S]' => function() { //string-rtrim
  947.           global $thestack;
  948.           $v=array_pop($thestack);
  949.           if(is_array($v)) $v=implode("\n",$v);
  950.           $thestack[]=rtrim($v);
  951.         },
  952.         'S(' => function() { //string-cspn
  953.           global $thestack;
  954.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  955.           $thestack[]=strcspn($v2,$v1);
  956.         },
  957.         'S)' => function() { //string-spn
  958.           global $thestack;
  959.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  960.           $thestack[]=strspn($v2,$v1);
  961.         },
  962.         'S0' => function() { //string-upto-first
  963.           global $thestack;
  964.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  965.           if(strlen($v1)==1) {
  966.             $v=strpos($v2,$v1);
  967.             if($v===false) array_push($thestack,"",$v2);
  968.             else array_push($thestack,substr($v2,$v+1),substr($v2,0,$v));
  969.           } else if(strlen($v1)==3) {
  970.             $v3=0;
  971.             for($k=0;$k<strlen($v2);$k++) {
  972.               if($v3==0 && $v2[$k]==$v1[0]) break;
  973.               if($v2[$k]==$v1[1]) $v3++;
  974.               if($v2[$k]==$v1[2]) $v3--;
  975.             }
  976.             array_push($thestack,substr($v2,$k+1),substr($v2,0,$k));
  977.           }
  978.         },
  979.         'S5' => function() { //string-remove-disallowed
  980.           global $thestack;
  981.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  982.           if(is_array($v2)) $v2=implode("\n",$v2);
  983.           $thestack[]=preg_replace('|[^'.preg_quote($v1,'-').']|',"",$v2);
  984.         },
  985.         'S!' => function() { //string-regex-match-offset
  986.           global $thestack;
  987.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  988.           preg_match_all($v1,$v2,$out,PREG_OFFSET_CAPTURE);
  989.           $v=array();
  990.           foreach($out[0] as $v3) $v[]=$v3[1];
  991.           $thestack[]=$v;
  992.         },
  993.         'S?' => function() { //string-regex-match
  994.           global $thestack;
  995.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  996.           preg_match_all($v1,$v2,$out,PREG_SET_ORDER);
  997.           $thestack[]=$out;
  998.         },
  999.         'S"' => function() { //string-regex-quote
  1000.           global $thestack;
  1001.           $v=array_pop($thestack);
  1002.           $thestack[]=preg_quote($v,'/');
  1003.         },
  1004.         'S~' => function() { //string-regex-replace-call
  1005.           global $thestack;
  1006.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  1007.           $v4=substr($v2,strrpos($v2,$v2[0])+1);
  1008.           $v2=substr($v2,0,strrpos($v2,$v2[0])+1).strtr($v4,"[1-","   ");
  1009.           if(strpos($v4,"-")!==false) $v1="0= ".$v1;
  1010.           if(strpos($v4,"[")!==false) {
  1011.             mark_stack();
  1012.             $v1.=" {}";
  1013.           }
  1014.           if(strpos($v4,"1")!==false) {
  1015.             $thestack[]=preg_replace_callback($v2,array(new flogback($v1),'call'),$v3,1);
  1016.           } else {
  1017.             $thestack[]=preg_replace_callback($v2,array(new flogback($v1),'call'),$v3);
  1018.           }
  1019.           if(strpos($v4,"[")!==false) {
  1020.             array_pop($thestack);
  1021.             end_mark_stack();
  1022.           }
  1023.         },
  1024.         'V<' => function() { //variable-stash
  1025.           global $thestack;
  1026.           global $vars, $vars_stash;
  1027.           $v=array_pop($thestack);
  1028.           if(is_string($v)) $v=explode("|",$v);
  1029.           foreach($v as $v1) $vars_stash[$v1][]=$vars[$v1];
  1030.         },
  1031.         'V>' => function() { //variable-retrieve
  1032.           global $thestack;
  1033.           global $vars, $vars_stash;
  1034.           $v=array_pop($thestack);
  1035.           if(is_string($v)) $v=explode("|",$v);
  1036.           foreach($v as $v1) $vars[$v1]=array_pop($vars_stash[$v1]);
  1037.         },
  1038.         'V!' => function() { //variable-overload
  1039.           global $thestack;
  1040.           global $vars_overload;
  1041.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  1042.           $vars_overload[$v2]=$v1;
  1043.         },
  1044.         'V=' => function() { //variable-not-overload
  1045.           global $thestack;
  1046.           global $vars_overload;
  1047.           $v=array_pop($thestack);
  1048.           unset($vars_overload[$v]);
  1049.         },
  1050.         'V?' => function() { //variable-which-overload
  1051.           global $thestack;
  1052.           global $vars_overload;
  1053.           $v=array_pop($thestack);
  1054.           if(isset($vars_overload[$v])) $thestack[]=$vars_overload[$v];
  1055.           else $thestack[]=$v;
  1056.         },
  1057.         'Vx' => function() { //variable-delete
  1058.           global $thestack;
  1059.           global $vars,$vars_stash,$vars_overload;
  1060.           $v=array_pop($thestack);
  1061.           if(is_string($v)) $v=explode("|",$v);
  1062.           foreach($v as $v1) {
  1063.             unset($vars[$v1]);
  1064.             unset($vars_stash[$v1]);
  1065.             unset($vars_overload[$v1]);
  1066.           }
  1067.         },
  1068.         'V(' => function() { //variable-select-prev
  1069.           global $thestack;
  1070.           global $vars_overload;
  1071.           $v=array_pop($thestack);
  1072.           $vars_overload[$v][count($vars_overload[$v])-1]--;
  1073.         },
  1074.         'V)' => function() { //variable-select-next
  1075.           global $thestack;
  1076.           global $vars_overload;
  1077.           $v=array_pop($thestack);
  1078.           $vars_overload[$v][count($vars_overload[$v])-1]++;
  1079.         },
  1080.         'Vi' => function() { //variable-select-inner
  1081.           global $thestack;
  1082.           global $vars_overload;
  1083.           $v=array_pop($thestack);
  1084.           $vars_overload[$v][]=0;
  1085.         },
  1086.         'Vo' => function() { //variable-select-outer
  1087.           global $thestack;
  1088.           global $vars_overload;
  1089.           $v=array_pop($thestack);
  1090.           array_pop($vars_overload[$v]);
  1091.         },
  1092.         'X+' => function() { //matrix-add
  1093.           global $thestack;
  1094.           $v2=array_pop($thestack); $v1=array_pop($thestack);
  1095.           $thestack[]=matrix_add($v1,$v2);
  1096.         },
  1097.         'Z^' => function() { //misc-inline-filter
  1098.           global $thestack;
  1099.           $v=array_pop($thestack);
  1100.           if($v===0 || $v==="" || $v===array()) array_pop($thestack);
  1101.         },
  1102.         'Z2' => function() { //misc-2dup
  1103.           global $thestack;
  1104.           $v2=array_pop($thestack); $v1=array_pop($thestack);
  1105.           array_push($thestack,$v1,$v2,$v1,$v2);
  1106.         },
  1107.         'Z3' => function() { //misc-3dup
  1108.           global $thestack;
  1109.           $v3=array_pop($thestack); $v2=array_pop($thestack); $v1=array_pop($thestack);
  1110.           array_push($thestack,$v1,$v2,$v3,$v1,$v2,$v3);
  1111.         },
  1112.         'Zo' => function() { //misc-over
  1113.           global $thestack;
  1114.           $v2=array_pop($thestack); $v1=array_pop($thestack);
  1115.           array_push($thestack,$v1,$v2,$v1);
  1116.         }
  1117.  
  1118. );
  1119.  
  1120. function execcode($f) {
  1121.   global $thestack;
  1122.   global $stackmark;
  1123.   global $thename;
  1124.   global $vars,$vars_stash,$vars_overload;
  1125.   global $thrown;
  1126.   global $extensions;
  1127.   global $stdinput;
  1128.   global $opsmap;
  1129.   $catch=array();
  1130.   $m=0; $a=""; $f.="\n";
  1131.   for($i=0;$i<strlen($f);$i++) {
  1132.     $c=$f{$i};
  1133.     if($thrown) {
  1134.       $v3=null;
  1135.       if(isset($catch[$thrown[0]])) {
  1136.         $v3=$thrown[0];
  1137.       } else if(is_int($thrown[0])) {
  1138.         if($thrown[0]>0) {
  1139.           foreach($catch as $k=>$v) if(is_int($k)) if($k>0 && ($thrown[0]&$k)==$thrown[0]) $v3=$k;
  1140.         } else {
  1141.           foreach($catch as $k=>$v) if(is_int($k)) if($k<=0 && ((-$thrown[0])&-$k)==-$k) $v3=$k;
  1142.         }
  1143.       } else if(isset($catch[''])) {
  1144.         $v3='';
  1145.       }
  1146.       if($v3!==null) {
  1147.         array_push($thestack,$i,$thrown);
  1148.         $v=$catch[$v3];
  1149.         $v2=preg_match('/(^|\r|\n)\s*'.preg_quote($v,'/').'(\s)/',$f,$v1,PREG_OFFSET_CAPTURE);
  1150.         if($v2) $i=$v1[2][1]; else return 1;
  1151.         $thrown=false;
  1152.       } else return 1;
  1153.     }
  1154.     if($m>0) {
  1155.       if($c=='{') $m++;
  1156.       if($c=='}') $m--;
  1157.       if($m==0) $thestack[]=$a;
  1158.       else $a=$a.$c;
  1159.     } else {
  1160.       if(ctype_alpha($c) || ctype_digit($c) || $c=="_") {
  1161.         if($c=="_" && isset($vars_overload[$thename])) $thename=$vars_overload[$thename];
  1162.         $thename=$thename.$c;
  1163.         if(!ctype_upper($c) && ctype_upper($thename[0]) && $thename!="") {$c=$thename;$thename="";}
  1164.       } else if($c==":") {
  1165.         if($thename=="") $thename="_";
  1166.         if(isset($vars_overload[$thename])) $thename=$vars_overload[$thename];
  1167.         if(is_array($thename)) {
  1168.           $v1=&$vars[$thename[0]];
  1169.           foreach($thename as $k=>$v) if($k) $v1=&$v1[$v];
  1170.           $v2=array_pop($thestack);
  1171.           foreach($v2 as $v) $v1=&$v1[$v];
  1172.           $v1=array_pop($thestack);
  1173.           unset($v1);
  1174.         } else {
  1175.           $vars[$thename]=array_pop($thestack);
  1176.         }
  1177.         $thename="";
  1178.       } else if($c==";" && $thename!="") {
  1179.         $c="";
  1180.         if(isset($extensions[$thename])) call_user_func($extensions[$thename],&$c,&$f,&$i);
  1181.         $thename="";
  1182.       } else if($c=="'" && $thename!="") {
  1183.         if(isset($vars_overload[$thename])) $thename=$vars_overload[$thename];
  1184.         if(is_array($thename)) $thename=implode(' ',$thename).' ';
  1185.         $thestack[]=$thename;
  1186.         $thename="";
  1187.         $c="";
  1188.       } else if($thename!="" && (ctype_lower($thename[0]) || ctype_digit($thename[0]) || $thename[0]=="_")) {
  1189.         if(isset($vars_overload[$thename])) $thename=$vars_overload[$thename];
  1190.         if(is_array($thename)) {
  1191.           $v1=&$vars[$thename[0]];
  1192.           foreach($thename as $k=>$v) if($k) $v1=&$v1[$v];
  1193.           $v2=array_pop($thestack);
  1194.           foreach($v2 as $v) $v1=&$v1[$v];
  1195.           $thestack[]=$v1;
  1196.           unset($v1);
  1197.         } else if(ctype_digit($thename)) {
  1198.           $thestack[]=0+$thename;
  1199.         } else if(substr($thename,0,2)=='0x' && ctype_xdigit(substr($thename,2))) {
  1200.           $thestack[]=hexdec(substr($thename,2));
  1201.         } else if($thename[0]=="_" && ctype_digit(substr($thename,1)) && $thename!="_") {
  1202.           $thestack[]=0-substr($thename,1);
  1203.         } else if(isset($vars[$thename])) {
  1204.           $thestack[]=$vars[$thename];
  1205.         }
  1206.         $thename="";
  1207.       } else if($thename!="") {
  1208.         $c=$thename.$c;
  1209.         if(!ctype_upper($c)) $thename="";
  1210.       }
  1211.       if($c=='{') { //string
  1212.         $a="";
  1213.         $m=1;
  1214.       }
  1215.       if(count($thestack) >= 1){
  1216.         $v=$thestack[count($thestack)-1];
  1217.       }else{
  1218.         $v = null;
  1219.       }
  1220.       //if(is_int($v) && isset($extensions['__number'])) call_user_func($extensions['__number'],&$c,&$f,&$i);
  1221.       //if(is_object($v)) $v->next_command(&$c,&$f,&$i);
  1222.  
  1223.       if(isset($opsmap[$c])){
  1224.         //Simple function.
  1225.         $opsmap[$c]();
  1226.       }else{
  1227.         //Complex function.
  1228.         //Edits $f or $i or $a or $m or returns.
  1229.         //Can't split out easily.
  1230.         if($c=='~') { //not/eval/dump/--in-out-listnum
  1231.           $v=array_pop($thestack);
  1232.           if(is_int($v)) {
  1233.             $thestack[]=~$v;
  1234.           } else if(is_string($v)) {
  1235.             execcode($v);
  1236.           } else if(is_array($v)) {
  1237.             $thestack=array_merge($thestack,$v);
  1238.           } else if(is_object($v)) {
  1239.             $v->cmd_eval();
  1240.           } else if(is_null($v)) {
  1241.             $v='';
  1242.             while(!feof($stdinput)) $v.=fread($stdinput,8192);
  1243.             mark_stack();
  1244.             execcode($v);
  1245.             if(!isset($vars['y'])) $vars['y']=$thestack[0];
  1246.             end_mark_stack();
  1247.             $f.="\nPa";
  1248.           }
  1249.         }
  1250.         if($c=='}') { //right-brace
  1251.           $v=array_pop($thestack);
  1252.           if(is_string($v)) {
  1253.             $thestack[]=str_split($v);
  1254.           } else if(is_int($v)) {
  1255.             $thestack[]=(int)abs($v);
  1256.             if($v>0) $thestack[]=range($v,1);
  1257.             else $thestack[]=array();
  1258.           } else if(is_array($v)) {
  1259.             $thestack[]=$v;
  1260.             $vars['_']=$v;
  1261.           }
  1262.         }
  1263.         if($c==')') { //increment/uncons-last/--in-out-line-array
  1264.           $v=array_pop($thestack);
  1265.           if(is_int($v)) {
  1266.             $thestack[]=$v+1;
  1267.           } else if(is_array($v)) {
  1268.             $v2=array_pop($v);
  1269.             array_push($thestack,$v,$v2);
  1270.           } else if(is_string($v)) {
  1271.             $v=str_split($v,1);
  1272.             $v2=array_pop($v);
  1273.             array_push($thestack,implode("",$v),$v2);
  1274.           } else if(is_null($v)) {
  1275.             $f='Ia10"/'.substr($f,$i+1).' A_P.';
  1276.             $i=-1;
  1277.           }
  1278.         }
  1279.         if($c=='"') { //chr/ord-list/reverse-array/--in-out-per-line
  1280.           $v=array_pop($thestack);
  1281.           if(is_int($v)) {
  1282.             $thestack[]=chr($v);
  1283.           } else if(is_string($v)) {
  1284.             $out=array();
  1285.             for($v1=0;$v1<strlen($v);$v1++) $out[]=ord($v[$v1]);
  1286.             $thestack[]=$out;
  1287.           } else if(is_array($v)) {
  1288.             $thestack[]=array_reverse($v);
  1289.           } else if(is_null($v)) {
  1290.             $f='{0 I1\;'.substr($f,$i+1).' P,1}Fd';
  1291.             $i=-1;
  1292.           }
  1293.         }
  1294.         if($c=='#') { //replace-execution/adjust-stack-mark/almost-execute/--in-out
  1295.           $v=array_pop($thestack);
  1296.           if(is_string($v)) {
  1297.             $f=$v.substr($f,$i+1);
  1298.             $i=-1;
  1299.           } else if(is_int($v)) {
  1300.             $v1=array_pop($stackmark);
  1301.             $stackmark[]=$v1-$v;
  1302.           } else if(is_array($v)) {
  1303.             foreach($v as $v1=>$v2) {
  1304.               $v[$v1]=almost_execute($v2);
  1305.             }
  1306.             $thestack[]=$v;
  1307.           } else if(is_null($v)) {
  1308.             $f=' Ia '.substr($f,$i+1).' P. ';
  1309.             $i=-1;
  1310.           }
  1311.         }
  1312.         //if($c=='As') { //array-shuffle/string-shuffle
  1313.         //  $v=array_pop($thestack);
  1314.         //  if(is_array($v)) {
  1315.         //    shuffle($v);
  1316.         //    $thestack[]=$v;
  1317.         //  } else if(is_string($v)) {
  1318.         //    $v=str_split($v,1);
  1319.         //    shuffle($v);
  1320.         //    $thestack[]=implode("",$v);
  1321.         //  }
  1322.         //}
  1323.         if($c=='F<') { //flow-control-restart
  1324.           $i=-1;
  1325.         }
  1326.         if($c=='F>') { //flow-control-exit
  1327.           return 0;
  1328.         }
  1329.         if($c=='F[') { //flow-control-conditional-restart
  1330.           if(array_pop($thestack)) $i=-1;
  1331.         }
  1332.         if($c=='F]') { //flow-control-conditional-exit
  1333.           if(array_pop($thestack)) return 0;
  1334.         }
  1335.         if($c=='Fd') { //flow-control-do
  1336.           $v=array_pop($thestack);
  1337.           do{execcode($v);} while(array_pop($thestack));
  1338.         }
  1339.         if($c=='Fi') { //flow-control-if-else
  1340.           $v1=array_pop($thestack); $v2=array_pop($thestack); $v3=array_pop($thestack);
  1341.           if($v3) execcode($v2); else execcode($v1);
  1342.         }
  1343.         if($c=='F%') { //flow-control-recursive-map
  1344.           $v=array_pop($thestack);
  1345.           if(is_array($v)) {
  1346.             mark_stack();
  1347.             foreach($v as $v1) {
  1348.               $thestack[]=$v1;
  1349.               execcode($f);
  1350.             }
  1351.             end_mark_stack();
  1352.             return 0;
  1353.           } else {
  1354.             $thestack[]=$v;
  1355.           }
  1356.         }
  1357.         if($c=='F/') { //flow-control-recursive-each
  1358.           $v=array_pop($thestack);
  1359.           if(is_array($v)) {
  1360.             foreach($v as $v1) {
  1361.               $thestack[]=$v1;
  1362.               execcode($f);
  1363.             }
  1364.             return 0;
  1365.           } else {
  1366.             $thestack[]=$v;
  1367.           }
  1368.         }
  1369.         if($c=='F.') { //flow-control-goto
  1370.           $v=array_pop($thestack);
  1371.           $v2=preg_match('/(^|\r|\n)\s*'.preg_quote($v,'/').'(\s)/',$f,$v1,PREG_OFFSET_CAPTURE);
  1372.           if($v2) $i=$v1[2][1];
  1373.         }
  1374.         if($c=='F?') { //flow-control-conditional-goto
  1375.           $v=array_pop($thestack); $v2=array_pop($thestack);
  1376.           $v2=$v2&&preg_match('/(^|\r|\n)\s*'.preg_quote($v,'/').'(\s)/',$f,$v1,PREG_OFFSET_CAPTURE);
  1377.           if($v2) $i=$v1[2][1];
  1378.         }
  1379.         if($c=='Fg') { //flow-control-gosub
  1380.           $v=array_pop($thestack);
  1381.           $v2=preg_match('/(^|\r|\n)\s*'.preg_quote($v,'/').'(\s)/',$f,$v1,PREG_OFFSET_CAPTURE);
  1382.           if($v2) {
  1383.             $thestack[]=$i;
  1384.             $i=$v1[2][1];
  1385.           }
  1386.         }
  1387.         if($c=='Fc') { //flow-control-conditional-gosub
  1388.           $v=array_pop($thestack); $v2=array_pop($thestack);
  1389.           $v2=$v2&&preg_match('/(^|\r|\n)\s*'.preg_quote($v,'/').'(\s)/',$f,$v1,PREG_OFFSET_CAPTURE);
  1390.           if($v2) {
  1391.             $thestack[]=$i;
  1392.             $i=$v1[2][1];
  1393.           }
  1394.         }
  1395.         if($c=='Fr') { //flow-control-return
  1396.           $i=array_pop($thestack);
  1397.         }
  1398.         if($c=='F~') { //flow-control-alt-exec
  1399.           $v=array_pop($thestack);
  1400.           if(execcode($v)) return 1;
  1401.         }
  1402.         if($c=='F1') { //flow-control-reconsider
  1403.           return 1;
  1404.         }
  1405.         if($c=='F2') { //flow-control-conditional-reconsider
  1406.           if(array_pop($thestack)) return 1;
  1407.         }
  1408.         if($c=='Fm') { //flow-control-maybe
  1409.           $v=array_pop($thestack)."\n".substr($f,$i+1);
  1410.           if(!maybe_execute($v)) return 0;
  1411.         }
  1412.         if($c=='Fw') { //flow-control-maybe-not
  1413.           $v=array_pop($thestack);
  1414.           if(!maybe_execute(substr($f,$i+1))) return 0;
  1415.           execcode($v);
  1416.         }
  1417.         if($c=='Fy') { //flow-control-yield
  1418.           $v=array_pop($thestack);
  1419.           $thestack[]=array($i,$f);
  1420.           if(is_string($v)) $v=array(-1,$v);
  1421.           $i=$v[0];
  1422.           $f=$v[1];
  1423.         }
  1424.         if($c=='Ft') { //flow-control-throw
  1425.           $thrown=array_pop($thestack);
  1426.           if(is_object($thrown[0])) $thrown[0]=$thrown[0]->convert();
  1427.         }
  1428.         if($c=='F(') { //flow-control-catch
  1429.           $v1=array_pop($thestack); $v2=array_pop($thestack);
  1430.           if(is_object($v2)) $v2=$v2->convert();
  1431.           $catch[$v2]=$v1;
  1432.         }
  1433.         if($c=='F)') { //flow-control-fumble
  1434.           $v2=array_pop($thestack);
  1435.           if(is_object($v2)) $v2=$v2->convert();
  1436.           unset($catch[$v2]);
  1437.         }
  1438.         if($c=='Fp') { //flow-control-fixed-point
  1439.           $v1=array_pop($thestack); execcode($v1);
  1440.           $v2=array_pop($thestack);
  1441.           do {
  1442.             $v=$v2; $thestack[]=$v;
  1443.             execcode($v1); $v2=array_pop($thestack);
  1444.           } while($v!=$v2);
  1445.           $thestack[]=$v;
  1446.         }
  1447.         if($c=='Fo') { //flow-control-forever
  1448.           $f=substr($f,$i+1)."\nF<";
  1449.           $i=-1;
  1450.         }
  1451.         if($c=='F|') { //flow-control-conditional-drop-exit
  1452.           if(!array_pop($thestack)) {
  1453.             array_pop($thestack);
  1454.             return 0;
  1455.           }
  1456.         }
  1457.         if($c=='F9') { //flow-control-alt-point
  1458.           $v1=array_pop($thestack); execcode($v1);
  1459.           $v2=array_pop($thestack); $v=array();
  1460.           do {
  1461.             $v[]=$v2; $thestack[]=$v2;
  1462.             execcode($v1); $v2=array_pop($thestack);
  1463.           } while(array_search($v2,$v,true)===false);
  1464.           $thestack[]=$v2;
  1465.         }
  1466.         //if($c=='Mr') { //math-random
  1467.         //  $v=array_pop($thestack);
  1468.         //  $thestack[]=mt_rand(0,$v-1);
  1469.         //}
  1470.         if($c=='S`') { //string-heredoc
  1471.           $f=substr($f,$i+1);
  1472.           $i=-1;
  1473.           $v1=substr($f,0,strpos($f,"\n"));
  1474.           $f=substr($f,strpos($f,"\n")+1);
  1475.           $v2=strpos($f,"\n".$v1."\n");
  1476.           $thestack[]=substr($f,0,$v2);
  1477.           $f=substr($f,$v2+2+strlen($v1));
  1478.         }
  1479.         if($c=='Vl') { //variable-local
  1480.           $v=array_pop($thestack);
  1481.           if(is_string($v)) $v=explode("|",$v);
  1482.           foreach($v as $v1) $vars_stash[$v1][]=$vars[$v1];
  1483.           $out=execcode(substr($f,$i+1));
  1484.           foreach($v as $v1) $vars[$v1]=array_pop($vars_stash[$v1]);
  1485.           return $out;
  1486.         }        
  1487.       }
  1488.     }
  1489.   }
  1490.   if($m) {
  1491.     if(is_array($thestack[count($thestack)-1])) {
  1492.       $v2=array_pop($thestack);
  1493.       mark_stack();
  1494.       foreach($v2 as $v) {
  1495.         $thestack[]=$v;
  1496.         execcode($a);
  1497.       }
  1498.       end_mark_stack();
  1499.     } else {
  1500.       execcode($a);
  1501.     }
  1502.   }
  1503. }
  1504.  
  1505. $vars=array(
  1506.   'a'=>'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  1507.   'aa'=>'abcdefghijklmnopqrstuvwxyz',
  1508.   'as'=>'*',
  1509.   'c'=>'}',
  1510.   'd'=>'.',
  1511.   'e'=>'',
  1512.   'f'=>'{}',
  1513.   'g'=>'{',
  1514.   'i'=>')',
  1515.   'j'=>'(',
  1516.   'n'=>"\n",
  1517.   'o'=>';_',
  1518.   'p'=>'.+',
  1519.   'pp'=>' _+',
  1520.   'q'=>"_\\:",
  1521.   'r'=>' Ar',
  1522.   's'=>' ',
  1523.   'sp'=>' 1/',
  1524.   'sq'=>' 0+.*',
  1525.   'th'=>1000,
  1526.   'z'=>array(0),
  1527.   'zz'=>array(0,0),
  1528. );
  1529.  
  1530. $extchars=array(
  1531.   '€'=>'[1#',
  1532.   '¡'=>' Ar ',
  1533.   '¢'=>' 1/ ',
  1534.   '«'=>' Ia ',
  1535.   '¬'=>' Az ',
  1536.   '°'=>' _# ',
  1537.   '²'=>'.*',
  1538.   '³'=>'..**',
  1539.   'µ'=>'}%',
  1540.   '¶'=>' P_ ',
  1541.   '¸'=>' ,i% ',
  1542.   '¹'=>' A= ',
  1543.   '»'=>' Pa ',
  1544.   'Æ'=>' A',
  1545.   'Ê'=>' F',
  1546.   'Ð'=>' S',
  1547.   'Ø'=>'[]',
  1548.   'Ù'=>'(\;',
  1549.   'Ú'=>')\;',
  1550.   'à'=>' a ',
  1551.   'è'=>' e ',
  1552.   'ì'=>' i ',
  1553.   'í'=>' j ',
  1554.   'ò'=>' o ',
  1555.   'ù'=>' u ',
  1556. );
  1557.  
  1558. $stdinput=STDIN;
  1559. $thestack=array();
  1560. $stackmark=array();
  1561. $thename="";
  1562. $vars_stash=array();
  1563. $vars_overload=array();
  1564. $thrown=false;
  1565. $extensions=array();
  1566. for($i=1;$i<count($argv);$i++) {
  1567.   switch($argv[$i]) {
  1568.     case '-c':
  1569.       $thestack=array();
  1570.       $thename="";
  1571.       $vars=array();
  1572.       break;
  1573.     case '-e':
  1574.       require $argv[++$i];
  1575.       break;
  1576.     case '-p':
  1577.       $thestack[]=$argv[++$i];
  1578.       break;
  1579.     case '-t':
  1580.       set_time_limit($argv[++$i]);
  1581.       break;
  1582.     case '-x':
  1583.       execcode(strtr(implode('',file($argv[++$i])),$extchars));
  1584.       break;
  1585.     default:
  1586.       execcode(str_replace("\r","",implode('',file($argv[$i]))));
  1587.       break;
  1588.   }
  1589. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement