This commit is contained in:
QkoSad
2025-07-16 13:00:37 +03:00
commit 7894b48931
806 changed files with 162532 additions and 0 deletions
+132
View File
@@ -0,0 +1,132 @@
class Main{
static Array mem;
/** Initializes the screen, and locates the cursor at the screen's top-left. */
function void test_init() {
let mem = 0;
return;
}
function void main(){
var String s;
var int i;
let s = String.new(10);
do Main.test_init();
let s = Main.readLine("String: ");
let i = Main.readInt("INT: ");
do Output.printString(s);
do Output.printInt(i);
return;
}
function char keyPressed(){
return mem[24576];
}
function int readInt_stolen(String message){
var starting a;
var int b;
let a = Main.readLine_stolen(message);
let b = String.intValue(a);
do String.dispose(a);
return b;
}
function string readLine_stolen(String message){
var char a, b ,c;
var String d;
var bool e;
let d = String.new(80);
do Output.printString(message);
let b = String.newLine();
let c = String.backSpace();
while (~e){
let a = Main.readChar();
let e = a = b;
if (~e){
if (a = c){
do d.eraseLastChar();
}
else{
do d.appendChar(a);
}
}
}
return d;
}
/**
* Displays the message on the screen, reads from the keyboard the entered
* text until a newline character is detected, echoes the text to the screen,
* and returns its value. Also handles user backspaces.
*/
function String readLine(String message){
var String s, b;
var char c;
let s = String.new(100);
do Output.printString(message);
while (true){
let c = Main.readChar();
if (c = 128){
return s;
}
else{
if (c = 129){
do s.eraseLastChar();
}
else{
do s.appendChar(c);
}
}
}
}
/**
* Waits until a key is pressed on the keyboard and released,
* then echoes the key to the screen, and returns the character
* of the pressed key.
*/
function char readChar(){
var char a, b;
do Output.printChar(0);
while ((b = 0) | (a > 0)){
let a = Main.keyPressed();
if (a > 0){
let b = a;
}
}
do Output.printChar(String.backSpace());
do Output.printChar(b);
return b;
}
/**
* Displays the message on the screen, reads from the keyboard the entered
* text until a newline character is detected, echoes the text to the screen,
* and returns its integer value (until the first non-digit character in the
* entered text is detected). Also handles user backspaces.
*/
function int readInt(String message) {
var String s;
var char c;
let s = String.new(100);
do Output.printString(message);
while (true){
let c = Main.readChar(c);
if (c = 128){
return s.intValue();
}
else{
if (c = 129){
let s = s.eraseLastChar();
}
else{
if ((c > 47) & (c < 57)){
let s = s.appendChar(c);
}
}
}
}
}
}