Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sfcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush
sfcode
Commits
cfd96b52
Commit
cfd96b52
authored
Dec 06, 2020
by
Ayush
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compilation functioning
parent
b19ad184
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
104 additions
and
69 deletions
+104
-69
backend/compile.php
backend/compile.php
+15
-10
backend/execute.php
backend/execute.php
+14
-10
backend/filesave.php
backend/filesave.php
+21
-21
src/app/arena/arena.component.html
src/app/arena/arena.component.html
+2
-2
src/app/arena/arena.component.ts
src/app/arena/arena.component.ts
+5
-1
src/app/ide-compile/ide-compile.component.html
src/app/ide-compile/ide-compile.component.html
+1
-1
src/app/ide-compile/ide-compile.component.ts
src/app/ide-compile/ide-compile.component.ts
+0
-1
src/app/ide/ide.component.html
src/app/ide/ide.component.html
+2
-2
src/app/ide/ide.component.ts
src/app/ide/ide.component.ts
+31
-0
src/app/run-code.service.ts
src/app/run-code.service.ts
+13
-21
No files found.
backend/compile.php
View file @
cfd96b52
<?php
<?php
header
(
"Access-Control-Allow-Origin: *"
);
header
(
'Access-Control-Allow-Credentials: true'
);
header
(
"Access-Control-Allow-Methods: PUT, GET, POST, DELETE"
);
header
(
"Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"
);
header
(
"Content-Type: application/json; charset=UTF-8"
);
$postData
=
file_get_contents
(
"php://input"
);
$postData
=
file_get_contents
(
"php://input"
);
$postData
=
json_decode
(
$postData
,
true
);
$postData
=
json_decode
(
$postData
,
true
);
...
@@ -9,25 +15,24 @@ $language = $postData['language'];
...
@@ -9,25 +15,24 @@ $language = $postData['language'];
$ret_stat
=
0
;
$ret_stat
=
0
;
if
(
strcmp
(
$language
,
"cpp"
)
==
0
)
if
(
strcmp
(
$language
,
"
.
cpp"
)
==
0
)
{
{
$base
=
basename
(
$filename
,
".cpp"
);
system
(
"g++ ../users/"
.
$uname
.
"/"
.
$filename
.
".cpp -o ../users/"
.
$uname
.
"/"
.
$filename
,
$ret_stat
);
system
(
"g++ ../users/"
.
$uname
.
"/"
.
$filename
.
" -o ../users/"
.
$uname
.
"/"
.
$base
,
$ret_stat
);
if
(
$ret_stat
!=
0
)
if
(
$ret_stat
!=
0
)
{
{
unlink
(
"../users/"
.
$uname
.
"/"
.
$base
);
unlink
(
"../users/"
.
$uname
.
"/"
.
$filename
);
throw
new
Exception
(
"Compilation Error!"
);
}
}
}
}
else
if
(
strcmp
(
$language
,
"java"
)
==
0
)
else
if
(
strcmp
(
$language
,
"
.
java"
)
==
0
)
{
{
$base
=
basename
(
$filename
,
".java"
);
system
(
"javac ../users/"
.
$uname
.
"/"
.
$filename
.
'.java'
,
$ret_stat
);
system
(
"javac ../users/"
.
$uname
.
"/"
.
$filename
,
$ret_stat
);
if
(
$ret_stat
!=
0
)
if
(
$ret_stat
!=
0
)
{
{
unlink
(
"../users/"
.
$uname
.
"/"
.
$base
.
".class"
);
unlink
(
"../users/"
.
$uname
.
"/"
.
$filename
.
".class"
);
throw
new
Exception
(
"Compilation Error!"
);
}
}
}
}
...
...
backend/execute.php
View file @
cfd96b52
<?php
<?php
header
(
"Access-Control-Allow-Origin: *"
);
header
(
'Access-Control-Allow-Credentials: true'
);
header
(
"Access-Control-Allow-Methods: PUT, GET, POST, DELETE"
);
header
(
"Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"
);
header
(
"Content-Type: application/json; charset=UTF-8"
);
$postData
=
file_get_contents
(
"php://input"
);
$postData
=
file_get_contents
(
"php://input"
);
$postData
=
json_decode
(
$postData
,
true
);
$postData
=
json_decode
(
$postData
,
true
);
$uname
=
$postData
[
'username'
];
$uname
=
$postData
[
'
file'
][
'
username'
];
$filename
=
$postData
[
'filename'
];
$filename
=
$postData
[
'file
'
][
'file
name'
];
$language
=
$postData
[
'language'
];
$language
=
$postData
[
'
file'
][
'
language'
];
$input_data
=
$postData
[
'input_data'
];
$input_data
=
$postData
[
'input_data'
];
$ret_stat
=
0
;
$ret_stat
=
0
;
...
@@ -19,16 +25,14 @@ fclose($file);
...
@@ -19,16 +25,14 @@ fclose($file);
$out_fname
=
"../users/"
.
$uname
.
"/"
.
"temp_out"
.
$template
;
$out_fname
=
"../users/"
.
$uname
.
"/"
.
"temp_out"
.
$template
;
if
(
strcmp
(
$language
,
"cpp"
)
==
0
)
if
(
strcmp
(
$language
,
"
.
cpp"
)
==
0
)
{
{
$base
=
basename
(
$filename
,
".cpp"
);
system
(
"./../users/"
.
$uname
.
"/"
.
$filename
.
" < "
.
$in_fname
.
" > "
.
$out_fname
,
$ret_stat
);
system
(
"./../users/"
.
$uname
.
"/"
.
$base
.
" < "
.
$in_fname
.
" > "
.
$out_fname
,
$ret_stat
);
}
}
else
if
(
strcmp
(
$language
,
"java"
)
==
0
)
else
if
(
strcmp
(
$language
,
"java"
)
==
0
)
{
{
$base
=
basename
(
$filename
,
".java"
);
system
(
"java -cp ../users/"
.
$uname
.
"/ "
.
$filename
.
" < "
.
$in_fname
.
" > "
.
$out_fname
,
$ret_stat
);
system
(
"java -cp ../users/"
.
$uname
.
"/ "
.
$base
.
" < "
.
$in_fname
.
" > "
.
$out_fname
,
$ret_stat
);
}
}
else
if
(
strcmp
(
$language
,
"python"
)
==
0
)
else
if
(
strcmp
(
$language
,
"python"
)
==
0
)
...
@@ -38,13 +42,13 @@ else if(strcmp($language, "python") == 0)
...
@@ -38,13 +42,13 @@ else if(strcmp($language, "python") == 0)
if
(
$ret_stat
!=
0
)
if
(
$ret_stat
!=
0
)
{
{
echo
"Runtime Error!!"
;
throw
new
Exception
(
"Runtime Error!"
)
;
}
}
else
else
{
{
$file
=
fopen
(
$out_fname
,
'r'
);
$file
=
fopen
(
$out_fname
,
'r'
);
echo
fread
(
$file
,
filesize
(
$out_fname
));
echo
json_encode
(
fread
(
$file
,
filesize
(
$out_fname
)
));
fclose
(
$file
);
fclose
(
$file
);
}
}
...
...
backend/filesave.php
View file @
cfd96b52
...
@@ -11,21 +11,21 @@ if (isset($postData) && !empty($postData)) {
...
@@ -11,21 +11,21 @@ if (isset($postData) && !empty($postData)) {
$lang
=
trim
(
$request
->
language
);
$lang
=
trim
(
$request
->
language
);
$path
=
'../users/'
.
$username
.
'/'
.
trim
(
$request
->
path
)
.
'/'
.
$filename
.
$lang
;
$path
=
'../users/'
.
$username
.
'/'
.
trim
(
$request
->
path
)
.
'/'
.
$filename
.
$lang
;
if
(
file_exists
(
$path
))
{
//
if (file_exists($path)) {
$msg
=
"file already exists"
;
//
$msg = "file already exists";
clearstatcache
();
//
clearstatcache();
echo
json_encode
(
$msg
);
//
echo json_encode($msg);
}
// }
else
{
//
else {
$sql1
=
"SELECT n_files from userdata where username =
$username
"
;
//
$sql1 = "SELECT n_files from userdata where username = $username";
$sql2
=
"UPDATE userdata SET n_files = n_files+1 WHERE username =
$username
"
;
//
$sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
$result
=
mysqli_query
(
$mysqli
,
$sql1
);
//
$result = mysqli_query($mysqli, $sql1);
if
(
$result
==
10
){
//
if($result == 10){
$msg
=
"maximum limit(10) reached"
;
//
$msg = "maximum limit(10) reached";
echo
json_encode
(
$msg
);
//
echo json_encode($msg);
}
//
}
else
{
//
else{
if
(
$result
=
mysqli_query
(
$mysqli
,
$sql2
))
{
//
if($result = mysqli_query($mysqli, $sql2)) {
$myfile
=
fopen
(
$path
,
"w"
);
$myfile
=
fopen
(
$path
,
"w"
);
fwrite
(
$myfile
,
$data
);
fwrite
(
$myfile
,
$data
);
fclose
(
$myfile
);
fclose
(
$myfile
);
...
@@ -33,12 +33,12 @@ if (isset($postData) && !empty($postData)) {
...
@@ -33,12 +33,12 @@ if (isset($postData) && !empty($postData)) {
$msg
=
"file successfully uploaded"
;
$msg
=
"file successfully uploaded"
;
clearstatcache
();
clearstatcache
();
echo
json_encode
(
$msg
);
echo
json_encode
(
$msg
);
}
//
}
else
{
//
else{
http_response_code
(
404
);
//
http_response_code(404);
}
//
}
}
//
}
}
//
}
}
}
...
...
src/app/arena/arena.component.html
View file @
cfd96b52
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
<div
id=
"toggle-lang"
>
C++
</div>
<div
id=
"toggle-lang"
>
C++
</div>
<div
id=
"attempt"
>
<div
id=
"attempt"
>
<button
id=
"input"
(click)=
"inputField.setState(true)"
>
Custom Input
</button>
<button
id=
"input"
(click)=
"inputField.setState(true)"
>
Custom Input
</button>
<button
id=
"try"
(click)=
"tryCode(0)"
[class.disabled]=
"compilationError
"
>
{{compilationError ? 'Error' : 'Try Code'
}}
</button>
<button
id=
"try"
(click)=
"tryCode(0)"
[class.disabled]=
"compilationError
|| isCompiling"
>
{{compilationError ? 'Error' : (isCompiling ? 'Compiling...' : 'Try Code')
}}
</button>
<button
id=
"submit"
(click)=
"tryCode(1)"
[class.disabled]=
"compilationError
"
>
{{compilationError ? 'Encountered' : 'Submit Code'
}}
</button>
<button
id=
"submit"
(click)=
"tryCode(1)"
[class.disabled]=
"compilationError
|| isCompiling"
>
{{compilationError ? 'Error' : (isCompiling ? 'Compiling...' : 'Try Code')
}}
</button>
</div>
</div>
<label
for=
"editor"
></label>
<label
for=
"editor"
></label>
<textarea
id=
"editor"
name=
"editor"
></textarea>
<textarea
id=
"editor"
name=
"editor"
></textarea>
...
...
src/app/arena/arena.component.ts
View file @
cfd96b52
...
@@ -20,6 +20,7 @@ export class ArenaComponent implements OnInit {
...
@@ -20,6 +20,7 @@ export class ArenaComponent implements OnInit {
problem
:
Problem
;
problem
:
Problem
;
customInput
=
''
;
customInput
=
''
;
compilationError
=
false
;
compilationError
=
false
;
isCompiling
=
false
;
@
ViewChild
(
InputComponent
)
inputField
:
InputComponent
;
@
ViewChild
(
InputComponent
)
inputField
:
InputComponent
;
@
ViewChild
(
SubmitTryCodeComponent
)
submitField
:
SubmitTryCodeComponent
;
@
ViewChild
(
SubmitTryCodeComponent
)
submitField
:
SubmitTryCodeComponent
;
...
@@ -76,13 +77,16 @@ export class ArenaComponent implements OnInit {
...
@@ -76,13 +77,16 @@ export class ArenaComponent implements OnInit {
}
}
tryCode
(
c
):
void
{
tryCode
(
c
):
void
{
if
(
document
.
getElementById
(
'
try
'
).
classList
.
contains
(
'
disabled
'
))
{
return
;
}
this
.
isCompiling
=
true
;
this
.
runCodeService
.
compileProblemFile
(
this
.
problem
)
this
.
runCodeService
.
compileProblemFile
(
this
.
problem
)
.
subscribe
(
data
=>
{
.
subscribe
(
data
=>
{
if
(
document
.
getElementById
(
'
try
'
).
classList
.
contains
(
'
disabled
'
))
{
return
;
}
this
.
submitField
.
submitting
=
c
;
this
.
submitField
.
submitting
=
c
;
this
.
submitField
.
reset
();
this
.
submitField
.
reset
();
this
.
submitField
.
isActive
=
true
;
this
.
submitField
.
isActive
=
true
;
this
.
isCompiling
=
false
;
},
error
=>
{
},
error
=>
{
this
.
isCompiling
=
false
;
this
.
compilationError
=
true
;
this
.
compilationError
=
true
;
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
compilationError
=
false
;
this
.
compilationError
=
false
;
...
...
src/app/ide-compile/ide-compile.component.html
View file @
cfd96b52
...
@@ -2,6 +2,6 @@
...
@@ -2,6 +2,6 @@
<div
[class.open]=
"isActive"
id=
"compile-popup"
>
<div
[class.open]=
"isActive"
id=
"compile-popup"
>
<p
[innerHTML]=
"statusVal"
id=
"compile-status"
></p>
<p
[innerHTML]=
"statusVal"
id=
"compile-status"
></p>
<button
(click)=
"
resultVal !== 0 && setState(false)"
[class.disabled]=
"resultVal === 0
"
id=
"compile-done"
>
Done
<button
(click)=
"
setState(false)
"
id=
"compile-done"
>
Done
</button>
</button>
</div>
</div>
src/app/ide-compile/ide-compile.component.ts
View file @
cfd96b52
...
@@ -7,7 +7,6 @@ import {Component, Input, OnInit} from '@angular/core';
...
@@ -7,7 +7,6 @@ import {Component, Input, OnInit} from '@angular/core';
})
})
export
class
IdeCompileComponent
implements
OnInit
{
export
class
IdeCompileComponent
implements
OnInit
{
@
Input
()
statusVal
:
string
;
@
Input
()
statusVal
:
string
;
@
Input
()
resultVal
:
number
;
isActive
=
false
;
isActive
=
false
;
constructor
()
{
constructor
()
{
...
...
src/app/ide/ide.component.html
View file @
cfd96b52
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<span
*ngIf=
"!isUpToDate"
>
•
</span>
<span
*ngIf=
"!isUpToDate"
>
•
</span>
<span
id=
"ideFileName"
>
{{file.filename + file.language}}
</span>
<span
id=
"ideFileName"
>
{{file.filename + file.language}}
</span>
<button
(click)=
"inputField.setState(true);"
id=
"inputBtn"
>
Input
</button>
<button
(click)=
"inputField.setState(true);"
id=
"inputBtn"
>
Input
</button>
<button
(click)=
"
this.runField.isActive = true; this.runCodeService.run()"
id=
"runBtn"
>
Run Code
</button>
<button
(click)=
"
runFile()"
id=
"runBtn"
[class.disabled]=
"isCompiling || isError"
>
{{isError ? 'Error' : (isCompiling ? 'Compiling...' : 'Run File')}}
</button>
<button
(click)=
"!isSaved ? this.saveField.setState(true) : updateFile();"
<button
(click)=
"!isSaved ? this.saveField.setState(true) : updateFile();"
[class.disabled]=
"isUploading || isUpToDate"
[class.disabled]=
"isUploading || isUpToDate"
id=
"saveBtn"
>
{{isUploading ? "Saving File..." : "Save File"}}
</button>
id=
"saveBtn"
>
{{isUploading ? "Saving File..." : "Save File"}}
</button>
...
@@ -13,5 +13,5 @@
...
@@ -13,5 +13,5 @@
<textarea
id=
"editor"
name=
"editor"
value=
"{{inp}}"
></textarea>
<textarea
id=
"editor"
name=
"editor"
value=
"{{inp}}"
></textarea>
</div>
</div>
<app-input
(valueEmit)=
"updateInput($event)"
></app-input>
<app-input
(valueEmit)=
"updateInput($event)"
></app-input>
<app-ide-compile
[
resultVal]=
"runCodeService.result"
[
statusVal]=
"runCodeService.runStatus"
></app-ide-compile>
<app-ide-compile
[statusVal]=
"runCodeService.runStatus"
></app-ide-compile>
<app-save-file
(savedFile)=
"isSaved = isUpToDate = true;"
[file]=
"file"
></app-save-file>
<app-save-file
(savedFile)=
"isSaved = isUpToDate = true;"
[file]=
"file"
></app-save-file>
src/app/ide/ide.component.ts
View file @
cfd96b52
...
@@ -21,6 +21,8 @@ export class IdeComponent implements OnInit {
...
@@ -21,6 +21,8 @@ export class IdeComponent implements OnInit {
extensions
=
[
'
.cpp
'
,
'
.py
'
,
'
.java
'
];
extensions
=
[
'
.cpp
'
,
'
.py
'
,
'
.java
'
];
isSaved
=
false
;
isSaved
=
false
;
isUploading
=
false
;
isUploading
=
false
;
isCompiling
=
false
;
isError
=
false
;
isUpToDate
=
false
;
isUpToDate
=
false
;
file
:
File
=
{
file
:
File
=
{
filename
:
'
Untitled
'
,
filename
:
'
Untitled
'
,
...
@@ -113,4 +115,33 @@ int main() {
...
@@ -113,4 +115,33 @@ int main() {
btn
.
innerHTML
=
'
Save File
'
;
btn
.
innerHTML
=
'
Save File
'
;
});
});
}
}
runFile
():
void
{
const
btn
=
document
.
getElementById
(
'
runBtn
'
);
if
(
btn
.
classList
.
contains
(
'
disabled
'
))
{
return
;
}
this
.
isCompiling
=
true
;
this
.
runCodeService
.
compileFile
(
this
.
file
)
.
subscribe
(
data
=>
{
this
.
runCodeService
.
executeFile
(
this
.
file
,
this
.
inp
)
.
subscribe
(
d
=>
{
this
.
runField
.
status
=
'
<div class="code">
'
+
d
+
'
</div>
'
;
this
.
runField
.
setState
(
true
);
this
.
isCompiling
=
false
;
},
err
=>
{
console
.
log
(
err
);
this
.
isCompiling
=
false
;
this
.
isError
=
true
;
this
.
runField
.
status
=
'
<div class="error">Runtime Error!</div>
'
;
this
.
runField
.
setState
(
true
);
setTimeout
(()
=>
{
this
.
isError
=
false
;
},
3000
);
});
},
error
=>
{
console
.
log
(
error
);
this
.
isCompiling
=
false
;
this
.
isError
=
true
;
this
.
runField
.
status
=
'
<div class="error">Compilation Error!</div>
'
;
this
.
runField
.
setState
(
true
);
setTimeout
(()
=>
{
this
.
isError
=
false
;
},
3000
);
});
}
}
}
src/app/run-code.service.ts
View file @
cfd96b52
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Problem
}
from
'
./problem
'
;
import
{
Problem
}
from
'
./problem
'
;
import
{
File
}
from
'
./file
'
;
import
{
Observable
,
of
,
throwError
}
from
'
rxjs
'
;
import
{
Observable
,
of
,
throwError
}
from
'
rxjs
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'
root
'
providedIn
:
'
root
'
...
@@ -9,33 +11,23 @@ export class RunCodeService {
...
@@ -9,33 +11,23 @@ export class RunCodeService {
runStatus
=
'
Compiling...
'
;
runStatus
=
'
Compiling...
'
;
result
=
0
;
result
=
0
;
private
baseUrl
=
'
http://localhost/sfcode/backend/
'
;
constructor
()
{
constructor
(
private
httpClient
:
HttpClient
)
{
}
}
run
():
void
{
compileFile
(
file
:
File
):
Observable
<
any
>
{
const
output
=
`25
return
this
.
httpClient
.
post
(
this
.
baseUrl
+
'
compile.php
'
,
file
);
abcd
150`
;
const
statusArray
=
[
'
Uploading...
'
,
'
Compiling...
'
,
'
Running...
'
,
`Done!
<div class="code">
${
output
}
</div>`
];
this
.
result
=
0
;
let
time
=
0
;
for
(
const
status
of
statusArray
)
{
setTimeout
(()
=>
{
this
.
runStatus
=
status
;
},
time
);
time
+=
2000
;
}
}
setTimeout
(()
=>
{
executeFile
(
file
:
File
,
input
:
string
):
Observable
<
any
>
{
this
.
result
=
1
;
return
this
.
httpClient
.
post
(
this
.
baseUrl
+
'
execute.php
'
,
{
},
6000
);
file
,
input_data
:
input
});
}
}
compileProblemFile
(
prob
:
Problem
):
Observable
<
string
>
{
compileProblemFile
(
prob
:
Problem
):
Observable
<
any
>
{
if
(
Math
.
floor
(
Math
.
random
()
*
2
)
===
1
)
{
return
of
(
'
done
'
);
}
if
(
Math
.
floor
(
Math
.
random
()
*
2
)
===
1
)
{
return
of
(
'
done
'
);
}
else
{
return
throwError
(
'
error
'
);
}
else
{
return
throwError
(
'
error
'
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment