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;
|
2017-09-15 04:10:21 +02:00
|
|
|
use JSON;
|
2011-01-26 02:59:19 +01:00
|
|
|
|
|
|
|
my $sock = IO::Socket::INET->new(
|
2015-09-04 06:32:44 +02:00
|
|
|
PeerAddr => '127.0.0.1',
|
2019-06-26 18:34:19 +02: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
|
|
|
|
2017-09-15 04:10:21 +02:00
|
|
|
my $json = join ' ', @ARGV;
|
|
|
|
my $h = decode_json $json;
|
|
|
|
my $lang = $h->{lang} // "c11";
|
2011-01-26 02:59:19 +01:00
|
|
|
|
2017-09-15 04:10:21 +02:00
|
|
|
if ($h->{code} =~ s/-lang=([^ ]+)//) {
|
2015-01-17 16:00:47 +01:00
|
|
|
$lang = lc $1;
|
2011-01-26 03:02:21 +01:00
|
|
|
}
|
|
|
|
|
2017-09-15 04:10:21 +02:00
|
|
|
$h->{lang} = $lang;
|
|
|
|
$json = encode_json $h;
|
|
|
|
|
|
|
|
print $sock "$json\n";
|
2011-01-26 02:59:19 +01:00
|
|
|
|
|
|
|
while(my $line = <$sock>) {
|
|
|
|
print "$line";
|
|
|
|
}
|
|
|
|
|
|
|
|
close $sock;
|