#!/usr/bin/perl @codebuf = (); @perlbuf = (); @order = (); @INCLUDES = ( "stdio.h", "stdlib.h", "string.h", "unistd.h" ); if ( $#ARGV < 0 ) { while ( defined ( $buf = ) ) { $codebuf[0] .= $buf; } } else { $k = $#ARGV; for ( $i = 0; $i <= $k; $i += 2 ) { $snig = $ARGV[$i]; push ( @order, $snig ); if ( $snig eq "p" ) { push ( @perlbuf, $ARGV[$i+1] ); } elsif ( $snig eq "c" ) { push ( @codebuf, $ARGV[$i+1] ); } # FIXME -- add python here as snig "y" else { die ("unknown code fragment type '$snig'"); } } } for ( $i = 0; $i <= $#codebuf; $i++ ) { $codebuf[$i] =~ tr/\`/\'/; } $name = "/tmp/clip$$"; @names = (); $i = 0; foreach $x ( @codebuf ) { $codename = $name . "_" . $i . ".c"; $execname = $name . "_" . $i . ".x"; push ( @names, $codename ); push ( @names, $execname ); open ( F, ">$codename" ); foreach $str ( @INCLUDES ) { print ( F "#include <$str>\n" ); } print ( F "$x\n" ); close ( F ); $res = `gcc -I. -O0 -o $execname $codename 2>&1`; if ( !-x $execname ) { die ("$codename error:\n$res"); } $i++; } $i = 0; foreach $x ( @perlbuf ) { $perlname = $name . "_" . $i . ".pl"; push ( @names, $perlname ); open ( F, ">$perlname" ); print ( F "#!/usr/bin/perl\n" ); print ( F "$x\n" ); close ( F ); $res = `chmod +x $perlname`; $i++; } $k = $#order; $execution = ""; $cix = 0; $pix = 0; for ( $i = 0; $i <= $k; $i++ ) { if ( $i > 0 ) { $execution .= '|'; } if ( $order[$i] eq "p" ) { $execution .= $name . "_" . $pix . '.pl 2>&1 '; $pix++; } elsif ( $order[$i] eq "c" ) { $execution .= $name . "_" . $cix . '.x 2>&1 '; $cix++; } } $res = `$execution`; print ("$res"); unlink ( @names ); exit ( 0 );