2011-01-26 02:59:19 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2011-01-26 03:02:21 +01:00
|
|
|
# compiler_client.pl connects to compiler_server.pl hosted at PeerAddr/PeerPort below
|
|
|
|
# and sends a nick, language and code, then retreives and prints the compilation/execution output.
|
|
|
|
#
|
|
|
|
# this way we can run the compiler virtual machine on any remote server.
|
|
|
|
|
2011-01-26 02:59:19 +01:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use IO::Socket;
|
|
|
|
|
|
|
|
my $sock = IO::Socket::INET->new(
|
2015-09-04 06:32:44 +02:00
|
|
|
PeerAddr => '127.0.0.1',
|
2011-01-26 02:59:19 +01:00
|
|
|
PeerPort => 9000,
|
2011-01-26 03:02:21 +01:00
|
|
|
Proto => 'tcp');
|
|
|
|
|
|
|
|
if(not defined $sock) {
|
2015-09-04 06:32:44 +02:00
|
|
|
print "Fatal error compiling: $!; try again later\n";
|
2011-01-26 03:02:21 +01:00
|
|
|
die $!;
|
|
|
|
}
|
2011-01-26 02:59:19 +01:00
|
|
|
|
|
|
|
my $nick = shift @ARGV;
|
2015-09-04 06:32:44 +02:00
|
|
|
my $channel = shift @ARGV;
|
2011-01-26 02:59:19 +01:00
|
|
|
my $code = join ' ', @ARGV;
|
|
|
|
|
2015-01-17 16:00:47 +01:00
|
|
|
my $lang = "c11";
|
2011-01-26 03:02:21 +01:00
|
|
|
|
|
|
|
if($code =~ s/-lang=([^ ]+)//) {
|
2015-01-17 16:00:47 +01:00
|
|
|
$lang = lc $1;
|
2011-01-26 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
2015-09-04 06:32:44 +02:00
|
|
|
print $sock "compile:$nick:$channel:$lang\n";
|
2011-01-26 02:59:19 +01:00
|
|
|
print $sock "$code\n";
|
|
|
|
print $sock "compile:end\n";
|
|
|
|
|
|
|
|
while(my $line = <$sock>) {
|
|
|
|
print "$line";
|
|
|
|
}
|
|
|
|
|
|
|
|
close $sock;
|