Skip to content

Commit 7b6178e

Browse files
committed
vb module added
1 parent e1a655f commit 7b6178e

File tree

3 files changed

+196
-1
lines changed

3 files changed

+196
-1
lines changed

compilex.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var cppModule = require('./cppModule.js');
66
var javaModule = require('./javaModule.js');
77
var pyModule = require('./pyModule.js');
88
var csModule = require('./csModule.js');
9+
var vbModule = require('./vbModule.js');
10+
911

1012
exports.stats = false;
1113

@@ -80,6 +82,17 @@ exports.compileCSWithInput = function ( envData , code , input , fn ) {
8082
csModule.compileCSWithInput(envData , code , input , fn );
8183
}
8284

85+
exports.compileVB = function ( envData , code , fn ){
86+
if(exports.stats)
87+
vbModule.stats = true;
88+
vbModule.compileVB(envData , code , fn );
89+
}
90+
91+
exports.compileVBWithInput = function ( envData , code , input , fn ) {
92+
if(exports.stats)
93+
vbModule.stats = true;
94+
vbModule.compileVBWithInput(envData , code , input , fn );
95+
}
8396

8497
exports.flushSync = function() {
8598
path = ' ./temp/';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "compilex",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "compilex is a node.js library which is used to build online code editor/compiler websites and webservices.",
55
"main": "compilex.js",
66
"dependencies": {

vbModule.js

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
var exec = require('child_process').exec;
2+
var fs = require('fs');
3+
var cuid = require('cuid');
4+
var colors = require('colors');
5+
6+
7+
exports.stats = false ;
8+
9+
10+
exports.compileVB = function ( envData , code , fn ) {
11+
//creating source file
12+
var filename = cuid.slug();
13+
path = './temp/';
14+
15+
16+
//create temp0
17+
fs.writeFile( path + filename +'.vb' , code , function(err ){
18+
if(exports.stats)
19+
{
20+
if(err)
21+
console.log('ERROR: '.red + err);
22+
else
23+
console.log('INFO: '.green + filename +'.vb created');
24+
}
25+
if(envData.OS === 'windows')
26+
{
27+
28+
//compile cs code
29+
commmand = 'cd temp & vbc ' + filename +'.vb' ;
30+
exec(commmand , function ( error , stdout , stderr ){
31+
if(error)
32+
{
33+
if(exports.stats)
34+
{
35+
console.log('INFO: '.green + filename + '.vb contained an error while compiling');
36+
}
37+
var out = { error : stderr };
38+
fn(out);
39+
}
40+
else
41+
{
42+
var tempcommand = "cd temp & "+ filename ;
43+
exec( tempcommand , function ( error , stdout , stderr ){
44+
if(error)
45+
{
46+
47+
if(error.toString().indexOf('Error: stdout maxBuffer exceeded.') != -1)
48+
{
49+
var out = { error : 'Error: stdout maxBuffer exceeded. You might have initialized an infinite loop.' };
50+
fn(out);
51+
}
52+
else
53+
{
54+
if(exports.stats)
55+
{
56+
console.log('INFO: '.green + filename + '.vb contained an error while executing');
57+
}
58+
59+
var out = { error : stderr };
60+
fn(out);
61+
}
62+
}
63+
else
64+
{
65+
if(exports.stats)
66+
{
67+
console.log('INFO: '.green + filename + '.vb successfully compiled and executed !');
68+
}
69+
var out = { output : stdout};
70+
fn(out);
71+
}
72+
});
73+
}
74+
75+
});
76+
}
77+
});
78+
79+
//compiling and exrcuiting source code
80+
81+
} //end of compileCS
82+
83+
exports.compileVBWithInput = function ( envData , code , input , fn ) {
84+
var filename = cuid.slug();
85+
path = './temp/';
86+
87+
//create temp0
88+
fs.writeFile( path + filename +'.vb' , code , function(err ){
89+
if(exports.stats)
90+
{
91+
if(err)
92+
console.log('ERROR: '.red + err);
93+
else
94+
console.log('INFO: '.green + filename +'.vb created');
95+
}
96+
97+
if(envData.OS === 'windows')
98+
{
99+
100+
//compile c code
101+
commmand = 'cd temp & vbc ' + filename +'.vb';
102+
exec(commmand , function ( error , stdout , stderr ){
103+
if(error)
104+
{
105+
if(exports.stats)
106+
{
107+
console.log('INFO: '.green + filename + '.vb contained an error while compiling');
108+
}
109+
var out = { error : stderr };
110+
fn(out);
111+
}
112+
else
113+
{
114+
if(input)
115+
{
116+
var inputfile = filename + 'input.txt';
117+
118+
fs.writeFile( path + inputfile , input , function(err ){
119+
if(exports.stats)
120+
{
121+
if(err)
122+
console.log('ERROR: '.red + err);
123+
else
124+
console.log('INFO: '.green + inputfile +' (inputfile) created');
125+
}
126+
});
127+
var tempcommand = "cd temp & " + filename ;
128+
129+
exec( tempcommand + '<' + inputfile , function( error , stdout , stderr ){
130+
if(error)
131+
{
132+
if(error.toString().indexOf('Error: stdout maxBuffer exceeded.') != -1)
133+
{
134+
var out = { error : 'Error: stdout maxBuffer exceeded. You might have initialized an infinite loop.'};
135+
fn(out);
136+
}
137+
else
138+
{
139+
if(exports.stats)
140+
{
141+
console.log('INFO: '.green + filename + '.vb contained an error while executing');
142+
}
143+
var out = { error : stderr};
144+
fn(out);
145+
}
146+
}
147+
else
148+
{
149+
if(exports.stats)
150+
{
151+
console.log('INFO: '.green + filename + '.vb successfully compiled and executed !');
152+
}
153+
var out = { output : stdout};
154+
fn(out);
155+
}
156+
});
157+
158+
}
159+
else //input not provided
160+
{
161+
if(exports.stats)
162+
{
163+
console.log('INFO: '.green + 'Input mission for '+filename +'.vb');
164+
}
165+
var out = { error : 'Input Missing' };
166+
fn(out);
167+
}
168+
169+
}
170+
171+
172+
}); //end of csc exec
173+
}
174+
175+
176+
177+
});
178+
179+
//end of writeFile
180+
181+
182+
} //end of compileCPPWithInput

0 commit comments

Comments
 (0)