Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c31d6d

Browse files
Improve web interface and remove dependency on third-party code
1 parent 5645260 commit 7c31d6d

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

‎pscweb.css‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
body {
2+
font-family: sans-serif;
3+
background-color: rgb(160, 80, 160);
4+
color: rgb(0, 0, 0);
5+
margin: 4px;
6+
}
7+
8+
h2 {
9+
font-family: sans-serif;
10+
color: rgb(225, 225, 225);
11+
font-size: 18pt;
12+
margin: 2pt;
13+
}
14+
15+
h3 {
16+
font-family: sans-serif;
17+
font-weight: bold;
18+
font-style: italic;
19+
font-size: 14pt;
20+
margin: 2pt;
21+
}
22+
23+
pre {
24+
font-size: 12pt;
25+
line-height: 14pt;
26+
}
27+
28+
textarea {
29+
width: 584px;
30+
height: 512px;
31+
background-color: rgba(0, 0, 0, 0);
32+
border: 8px;
33+
padding: 8px;
34+
font-size: 12pt;
35+
resize: none;
36+
}
37+
38+
button {
39+
border: 2px solid rgb(0, 0, 0);
40+
border-radius: 3px;
41+
background-color: rgb(224, 224, 224);
42+
}
43+
44+
input {
45+
border: 2px solid rgb(0, 0, 0);
46+
border-radius: 3px;
47+
background-color: rgb(255, 255, 255);
48+
width: 60%;
49+
float: right;
50+
}
51+
52+
.window {
53+
background-color: rgb(224, 160, 224);
54+
margin: 4px;
55+
padding: 8px;
56+
border-radius: 10px;
57+
width: 600px;
58+
height: 584px;
59+
float: left;
60+
}

‎pscweb.html‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en-GB"><!-- https://github.com/cpp-tutor/pseudocode-compiler/ -->
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Pseudocode to JavaScript Compiler</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link href="pscweb.css" type="text/css" rel="stylesheet" />
8+
</head>
9+
<body>
10+
<script type="text/javascript" src="pscweb.js">
11+
</script>
12+
<span>
13+
<div>
14+
<h2 align="center">Pseudocode to JavaScript Compiler</h2>
15+
</div>
16+
<div class="window">
17+
<form id="input">
18+
<label for="program_source_id"><h3 align="center">Type your program in here</h3>
19+
<textarea name="program_source"></textarea>
20+
</label>
21+
<div>
22+
<button type="button" onClick="run()">Run program</button>
23+
<button type="button" onClick="clear_output()">Clear output</button>
24+
<input type="text" name="user_input" placeholder="Input1,Input2..." maxlength="128"/>
25+
</div>
26+
</form>
27+
</div>
28+
<div class="window">
29+
<h3 align="center">View the output of your program here</h3>
30+
<pre id="program_output"></pre>
31+
</div>
32+
</span>
33+
</body>
34+
</html>

‎pscweb.js‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// pscweb.js : support library for Pseudocode Compiler web interface
2+
3+
var input_index = 0;
4+
5+
function readline() {
6+
let input = document.getElementById('input').elements['user_input'].value;
7+
var input_read = '';
8+
var more = input.indexOf(',', input_index);
9+
if (more != -1) {
10+
let begin = input_index;
11+
input_index = more + 1;
12+
input_read = input.substring(begin, more);
13+
}
14+
else {
15+
input_read = input.substring(input_index);
16+
}
17+
print(input_read);
18+
return input_read;
19+
}
20+
21+
function print(line) {
22+
let max_lines = 28, max_length = 60;
23+
let lines = document.getElementById('program_output').innerHTML.split('\n').length;
24+
if (lines > max_lines) {
25+
alert('Too many lines of output. Please clear the output window!');
26+
throw new Error('Window full');
27+
}
28+
while(line.length > max_length) {
29+
document.getElementById('program_output').innerHTML += line.substring(0, max_length) + '\n';
30+
line = line.substring(max_length);
31+
}
32+
document.getElementById('program_output').innerHTML += line + '\n';
33+
}
34+
35+
function clear_output() {
36+
document.getElementById('program_output').innerHTML = '';
37+
}
38+
39+
function base64enc(rawutf8) {
40+
let encweb = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=';
41+
var enc = '', pos = 0, len = rawutf8.length;
42+
while ((len - pos) > 2) {
43+
enc += encweb[(rawutf8.charCodeAt(pos) >> 2) & 0x3f];
44+
enc += encweb[((rawutf8.charCodeAt(pos) << 4) | (rawutf8.charCodeAt(pos + 1) >> 4)) & 0x3f];
45+
enc += encweb[((rawutf8.charCodeAt(pos + 1) << 2) | (rawutf8.charCodeAt(pos + 2) >> 6)) &0x3f];
46+
enc += encweb[rawutf8.charCodeAt(pos + 2) & 0x3f];
47+
pos += 3;
48+
}
49+
if ((len - pos) == 2) {
50+
enc += encweb[(rawutf8.charCodeAt(pos) >> 2) & 0x3f];
51+
enc += encweb[((rawutf8.charCodeAt(pos) << 4) | (rawutf8.charCodeAt(pos + 1) >> 4)) & 0x3f];
52+
enc += encweb[(rawutf8.charCodeAt(pos + 1) << 2) &0x3f];
53+
enc += encweb[64];
54+
}
55+
if ((len - pos) == 1) {
56+
enc += encweb[(rawutf8.charCodeAt(pos) >> 2) & 0x3f];
57+
enc += encweb[(rawutf8.charCodeAt(pos) << 4) & 0x3f];
58+
enc += encweb[64];
59+
enc += encweb[64];
60+
}
61+
return enc;
62+
}
63+
64+
function run() {
65+
input_index = 0;
66+
let script = document.createElement('script');
67+
let query_string = base64enc(document.getElementById('input').elements['program_source'].value);
68+
script.setAttribute('src', '/cgi-bin/psc?' + query_string);
69+
document.body.appendChild(script);
70+
}
71+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /