Skip to content

Commit

Permalink
added c code execution
Browse files Browse the repository at this point in the history
  • Loading branch information
tomarviii88 committed Jan 4, 2021
1 parent 939410f commit ee9ca77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/api/services/code.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const ROOT_DIR = `${process.cwd()}`;
const SOURCE_DIR = path.join(ROOT_DIR, 'executor');
const TARGET_DIR = `/app/codes`;
const IMAGE_NAME = 'executor:1.0';
//const VOL_NAME = `my_vol`;
const VOL_NAME = SOURCE_DIR;
const VOL_NAME = `my_vol`;
//const VOL_NAME = SOURCE_DIR;

class CodeService {
async execute(code, input, lang, id) {
Expand Down Expand Up @@ -77,6 +77,10 @@ class CodeService {
fileName += '.java';
break;
}
case 'c': {
fileName += '.c';
break;
}
default: {
throw { message: 'Invalid language' };
}
Expand Down Expand Up @@ -114,6 +118,10 @@ class CodeService {
command = `cd ${TARGET_DIR} && javac ${file} && java Input < ${input}`;
break;
}
case 'c': {
command = `cd ${TARGET_DIR} && gcc -o ${id} ${file} && ./${id} < ${input}`;
break;
}
default: {
throw { message: 'Invalid language' };
}
Expand Down Expand Up @@ -157,9 +165,9 @@ class CodeService {
if (err) throw { message: err };
});
}
if (lang == 'c++') {
if (lang == 'c++' || lang == 'c') {
fs.unlinkSync(path.join(SOURCE_DIR, id), err => {
if (err) throw { message: err };
if (err) throw err;
});
}
if (lang == 'java') {
Expand Down
5 changes: 5 additions & 0 deletions server/api/services/validation.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class ValidationService {
isValid: true
};
}
case 'c': {
return {
isValid: true
};
}
default: {
return {
isValid: false,
Expand Down

0 comments on commit ee9ca77

Please sign in to comment.