2015-01-15 06:51:17 +01:00
|
|
|
#!/usr/bin/env perl
|
2011-01-26 02:59:19 +01:00
|
|
|
|
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/.
|
|
|
|
|
2015-01-15 06:51:17 +01:00
|
|
|
use warnings;
|
2011-01-26 02:59:19 +01:00
|
|
|
use strict;
|
|
|
|
|
2015-01-16 06:20:34 +01:00
|
|
|
use File::Basename;
|
2017-09-12 14:50:49 +02:00
|
|
|
use JSON;
|
2015-01-16 06:20:34 +01:00
|
|
|
|
2017-09-12 14:50:49 +02:00
|
|
|
my $json = join ' ', @ARGV;
|
|
|
|
my $h = decode_json $json;
|
|
|
|
|
|
|
|
my $language = lc $h->{lang};
|
2014-07-04 15:04:27 +02:00
|
|
|
|
2015-01-15 06:51:17 +01:00
|
|
|
eval {
|
|
|
|
use lib 'languages';
|
|
|
|
require "$language.pm";
|
|
|
|
} or do {
|
2017-09-12 14:50:49 +02:00
|
|
|
$language =~ s/^cfact_//;
|
|
|
|
|
2015-04-05 11:29:12 +02:00
|
|
|
my @modules = glob 'languages/*.pm';
|
|
|
|
my $found = 0;
|
|
|
|
my ($languages, $comma) = ('', '');
|
|
|
|
|
|
|
|
foreach my $module (sort @modules) {
|
|
|
|
$module = basename $module;
|
|
|
|
$module =~ s/.pm$//;
|
|
|
|
next if $module =~ m/^_/;
|
|
|
|
require "$module.pm";
|
|
|
|
my $mod = $module->new;
|
|
|
|
|
|
|
|
if (exists $mod->{name} and $mod->{name} eq $language) {
|
|
|
|
$language = $module;
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
|
|
|
|
$module = $mod->{name} if exists $mod->{name};
|
|
|
|
$languages .= "$comma$module";
|
|
|
|
$comma = ', ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not $found) {
|
|
|
|
print "Language '$language' is not supported.\nSupported languages are: $languages\n";
|
|
|
|
exit;
|
|
|
|
}
|
2012-09-01 07:20:01 +02:00
|
|
|
};
|
|
|
|
|
2017-09-12 14:50:49 +02:00
|
|
|
if (not length $h->{code}) {
|
|
|
|
if (exists $h->{usage}) {
|
|
|
|
print "$h->{usage}\n";
|
|
|
|
} else {
|
|
|
|
print "Usage: cc [-paste] [-lang=<language>] [-info] [language options] <code> [-input=<stdin input>]\n";
|
|
|
|
}
|
2015-01-17 13:39:19 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-09-12 14:50:49 +02:00
|
|
|
my $lang = $language->new(%$h);
|
2014-04-03 01:48:43 +02:00
|
|
|
|
2015-09-04 06:32:44 +02:00
|
|
|
$lang->{local} = $ENV{CC_LOCAL};
|
|
|
|
|
2015-01-15 06:51:17 +01:00
|
|
|
$lang->process_interactive_edit;
|
|
|
|
$lang->process_standard_options;
|
|
|
|
$lang->process_custom_options;
|
|
|
|
$lang->process_cmdline_options;
|
|
|
|
$lang->preprocess_code;
|
|
|
|
$lang->execute;
|
|
|
|
$lang->postprocess_output;
|
|
|
|
$lang->show_output;
|