$c/4) { $indent--; return $temp; } $arr[$i] = preg_replace('/^( )*/', '', $arr[$i]); $i++; if (preg_match('/(def|while|for|if|else|elif)(.*?):/', $arr[$i-1],$match)) { $indent++; if ($match[1] == 'while' || $match[1] == 'if' || $match[1] == 'for' || $match[1] == 'def') { $temp[] = array($match[1], $match[2], rec(), array()); //$ifcount++; } else if ($match[1] == 'else') { //$ifcount++; $temp[count($temp)-1][3] = rec(); } else if ($match[1] == 'elif') { $loop = array('if', $match[2], rec(), array()); $loopref =& $loop; while (preg_match('/(elif|else)(.*?):/', $arr[$i], $match)) { $i++; $indent++; $ifcount++; $loopref =& $loopref[3]; if ($match[1] == 'elif') { $loopref = array('if', $match[2], rec(), array()); } else { $loopref[3] = rec(); } } $temp[count($temp)-1][3] = $loop; } } else { $temp[] = $arr[$i-1]; } } return $temp; } $op = rec(); $ifcount+=2; if ($ifcount <= 2) $ifcount = 2; header ("Content-type: image/png"); $x = 500+$ifcount*70; $y = 500; $cx = $cy = 0; $sx = 0; $sy = 0; $im = @imagecreatetruecolor ($x+1, 5000); imageantialias($im, true); $c = imagecolorallocate ($im, 0, 0, 0); $cc = imagecolorallocate ($im, 0, 255, 0); $bgc = imagecolorallocate ($im, 255, 255, 255); imagefill($im, 0, 0, $bgc); function disp($ip, $cx, $cy, $sx) { global $im, $x, $y, $c, $cc, $bgc, $ifcount; if (is_array($ip) && count($ip) > 0 && ($ip[0] == 'while' || $ip[0] == 'for' || $ip[0] == 'def')) { imagefilledrectangle($im, $cx, $cy, $x-$sx, $cy+30, $bgc); imagestring ($im, 5, $cx+5, $cy+5, strtoupper($ip[0]).$ip[1], $c); $cx+=30; $cy+=30; $tempcy = disp($ip[2], $cx, $cy, $sx); imagefilledrectangle($im, $cx, $cy-30, $cx, $tempcy, $bgc); imagerectangle($im, $cx-30, $cy-30, $x-$sx, $tempcy, $c); imagerectangle($im, $cx, $cy, $x-$sx, $tempcy, $c); $cy = $tempcy; } else if (is_array($ip) && count($ip) > 0 && $ip[0] == 'if') { if ($ifcount > 2) $ifcount--; imagefilledrectangle($im, $cx, $cy, $x-$sx, $cy+40, $bgc); imagerectangle($im, $cx, $cy, $x-$sx, $cy+40, $c); imageline($im, $cx, $cy, ($x-$cx-$sx)/$ifcount+$cx, $cy+40, $c); imageline($im, ($x-$cx-$sx)/$ifcount+$cx, $cy+40, $x-$sx, $cy, $c); imagestring ($im, 5, ($x-$cx-$sx)/4+$cx,$cy+2, $ip[1], $c); imagestring ($im, 5, $cx+5, $cy+20, 't', $c); imagestring ($im, 5, $x-$sx-12, $cy+20, 'f', $c); $cy+=40; $cytemp = $cy; $cy1 = disp($ip[2], $cx, $cy, $sx+($x-$cx-$sx)/$ifcount*($ifcount-1)); $cy2 = disp($ip[3], $cx+($x-$cx-$sx)/$ifcount, $cy, $sx); $cy = $cy1; if ($cy2 > $cy) $cy = $cy2; imagerectangle($im, $cx, $cytemp, $x-$sx, $cy, $c); } else if (!is_array($ip)){ imagefilledrectangle($im, $cx, $cy, $x-$sx, $cy+20, $bgc); imagestring ($im, 4, $cx+5, $cy+2, $ip, $c); imageline($im, $cx, $cy, $x-$sx, $cy, $c); imageline($im, $cx, $cy, $cx, $cy+20, $c); imageline($im, $x-$sx, $cy, $x-$sx, $cy+20, $c); $cy += 20; } else { foreach ($ip as $entry) { if (is_array($entry)) $cy = disp($entry, $cx, $cy, $sx); else { imagefilledrectangle($im, $cx, $cy, $x-$sx, $cy+20, $bgc); imagestring ($im, 4, $cx+5, $cy+2, $entry, $c); imageline($im, $cx, $cy, $x-$sx, $cy, $c); imageline($im, $cx, $cy, $cx, $cy+20, $c); imageline($im, $x-$sx, $cy, $x-$sx, $cy+20, $c); $cy += 20; } } } return $cy; } $cy = disp($op, $cx, $cy, $sx); imageline($im, 0, $cy, $x, $cy, $c); $dst = imagecreatetruecolor($x+1, $cy+50); imagecopy($dst, $im, 0, 0, 0, 0, $x+1, $cy+50); ImagePNG ($dst); } else if (isset($_GET['code'])) { header('Content-type:text/plain'); readfile('index.php'); } else { echo' Struktograf

Struktogramm aus Python-Code erstellen


Quellcode einsehen
'; } ?>