mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-27 23:41:42 +00:00
upgrade code format ⚡
This commit is contained in:
parent
d54b84ab58
commit
d6a3151506
@ -2,7 +2,8 @@
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "judger",
|
||||
"sources": [ "judger.cc"]
|
||||
'cflags_cc!': [ '-std=c++11','-O2' ],
|
||||
"sources": [ "judger.cc"],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -26,21 +26,22 @@ namespace demo {
|
||||
using v8::Context;
|
||||
|
||||
/* 转成数字 */
|
||||
void ToNumber(Isolate * isolate,Local<Value> &args,char * key,std::string &str){
|
||||
bool ToNumber(Isolate * isolate,Local<Value> &args,char * key,std::string &str){
|
||||
Local<Context> context= isolate->GetCurrentContext();
|
||||
Local<Value> val = args->ToObject()->Get(context,String::NewFromUtf8(isolate,key)).ToLocalChecked();
|
||||
if(val->IsNullOrUndefined())
|
||||
return ;
|
||||
return true;
|
||||
else if( val->IsNumber()){
|
||||
Local<Integer> num = val->ToInteger(context).ToLocalChecked();
|
||||
str+=" --";
|
||||
str+=std::string(key);
|
||||
str+="=";
|
||||
str+=std::to_string(num->Value());
|
||||
return ;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate,"typeof argument must be Object!")));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ namespace demo {
|
||||
}
|
||||
|
||||
/* 转成字符串 */
|
||||
void ToCStr(Isolate * isolate,Local<Value> &args,char * key,std::string &str){
|
||||
bool ToCStr(Isolate * isolate,Local<Value> &args,char * key,std::string &str){
|
||||
|
||||
char str_content[255]={0};
|
||||
Local<Context> context= isolate->GetCurrentContext();
|
||||
@ -61,19 +62,20 @@ namespace demo {
|
||||
else
|
||||
val = args;
|
||||
if(val->IsNullOrUndefined())
|
||||
return;
|
||||
return true;
|
||||
else if(val->IsString()){
|
||||
_ToCharPTR(val,context,str_content);
|
||||
str+=" --";
|
||||
str+=std::string(key);
|
||||
str+="=";
|
||||
str+=std::string(str_content);
|
||||
return ;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
char ret[100];
|
||||
sprintf(ret,"typeof %s must be String!",key);
|
||||
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate,ret)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,47 +122,23 @@ namespace demo {
|
||||
|
||||
Local<Value> argument = args[0];
|
||||
|
||||
std::string int_vars[] = { "max_cpu_time","max_real_time","max_memory","memory_limit_check_only","max_stack","max_process_number","max_output_size","uid","gid"};
|
||||
std::string str_vars[] = { "input_path","output_path","error_path","exe_path","log_path","seccomp_rule_name"};
|
||||
|
||||
/* max_cpu_time */
|
||||
ToNumber(isolate,argument,(char *)"max_cpu_time",_args);
|
||||
for( auto var :int_vars){
|
||||
if( ! ToNumber(isolate,argument,(char *)var.c_str(),_args))
|
||||
return;
|
||||
}
|
||||
|
||||
/* max_real_time */
|
||||
ToNumber(isolate,argument,(char *)"max_real_time",_args);
|
||||
|
||||
/* max_memory */
|
||||
ToNumber(isolate,argument,(char *)"max_memory",_args);
|
||||
|
||||
/* memory_limit_check_only */
|
||||
ToNumber(isolate,argument,(char *)"memory_limit_check_only",_args);
|
||||
|
||||
|
||||
|
||||
/* max_stack */
|
||||
ToNumber(isolate,argument,(char *)"max_stack",_args); //默认16mb
|
||||
|
||||
/* max_process_number */
|
||||
ToNumber(isolate,argument,(char *)"max_process_number",_args);
|
||||
|
||||
/* max_output_size */
|
||||
ToNumber(isolate,argument,(char *)"max_output_size",_args);
|
||||
|
||||
/* input_path */
|
||||
ToCStr(isolate,argument,(char *)"input_path",_args);
|
||||
|
||||
/* output_path */
|
||||
ToCStr(isolate,argument,(char *)"output_path",_args);
|
||||
|
||||
/* error_path */
|
||||
ToCStr(isolate,argument,(char *)"error_path",_args);
|
||||
|
||||
/* exe_path */
|
||||
ToCStr(isolate,argument,(char *)"exe_path",_args);
|
||||
for( auto var : str_vars){
|
||||
if( !ToCStr(isolate,argument,(char *)var.c_str(),_args))
|
||||
return;
|
||||
}
|
||||
|
||||
/* args */
|
||||
|
||||
Local<Value> margs= argument->ToObject()->Get(context,String::NewFromUtf8(isolate,"args")).ToLocalChecked();
|
||||
if( margs->IsNullOrUndefined()){
|
||||
NULL;
|
||||
;
|
||||
}
|
||||
else if( margs->IsArray()){
|
||||
Local<Array> args = margs.As<Array>();
|
||||
@ -168,16 +146,18 @@ namespace demo {
|
||||
int i;
|
||||
for(i=0;i<len;i++){
|
||||
Local<Value> in = args->Get(i);
|
||||
ToCStr(isolate,in,(char *)"args",_args);
|
||||
if( !ToCStr(isolate,in,(char *)"args",_args))
|
||||
return;
|
||||
}
|
||||
}
|
||||
else { //not array
|
||||
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate,"args must be a list")));
|
||||
return;
|
||||
}
|
||||
|
||||
Local<Value> menv= argument->ToObject()->Get(context,String::NewFromUtf8(isolate,"env")).ToLocalChecked();
|
||||
if( menv->IsNullOrUndefined()){
|
||||
NULL;
|
||||
;
|
||||
}
|
||||
else if( margs->IsArray()){
|
||||
Local<Array> env = menv.As<Array>();
|
||||
@ -185,24 +165,16 @@ namespace demo {
|
||||
int i;
|
||||
for(i=0;i<len;i++){
|
||||
Local<Value> in = env->Get(i);
|
||||
ToCStr(isolate,in,(char *)"env",_args);
|
||||
if(!ToCStr(isolate,in,(char *)"env",_args))
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
else { //not array
|
||||
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate,"env must be a list")));
|
||||
return;
|
||||
}
|
||||
|
||||
/* log_path */
|
||||
ToCStr(isolate,argument,(char *)"log_path",_args);
|
||||
|
||||
/* seccomp_rule_name */
|
||||
char seccomp_rule_name[255];
|
||||
ToCStr(isolate,argument,(char *)"seccomp_rule_name",_args);
|
||||
|
||||
/* uid */
|
||||
ToNumber(isolate,argument,(char *)"uid",_args);
|
||||
/* gid */
|
||||
ToNumber(isolate,argument,(char *)"gid",_args);
|
||||
|
||||
|
||||
char buf[255];
|
||||
@ -222,7 +194,8 @@ namespace demo {
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%*.*s",len,len,pr); //输出 程序的输出
|
||||
if(len)
|
||||
printf("%*.*s",len,len,pr); //输出 程序的输出
|
||||
|
||||
MaybeLocal<Value> mres = JSON::Parse(isolate,String::NewFromUtf8(isolate,pr+len));
|
||||
args.GetReturnValue().Set(mres.ToLocalChecked());
|
||||
|
@ -1,12 +1,16 @@
|
||||
{
|
||||
"name": "judger",
|
||||
"version": "1.0.0",
|
||||
"description": "judger for online system",
|
||||
"main": "./build/Release/judger.node",
|
||||
"scripts": {
|
||||
"build":"node-gyp rebuild",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "virusdefender,rainboy",
|
||||
"license": "GPL"
|
||||
"name": "judger",
|
||||
"version": "1.0.0",
|
||||
"description": "judger for online system",
|
||||
"main": "./build/Release/judger.node",
|
||||
"scripts": {
|
||||
"build": "node-gyp rebuild",
|
||||
"test": "mocha -t 5000 ../../tests/Nodejs_and_core"
|
||||
},
|
||||
"author": "virusdefender,rainboy",
|
||||
"license": "GPL",
|
||||
"devDependencies": {
|
||||
"mocha": "^6.1.4",
|
||||
"node-gyp": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user