ajout de Sheebr + support de shutdown + auto install kernel
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//@ts-check
|
||||
const { exec, fork } = require('child_process');
|
||||
/**
|
||||
* @param {string} path
|
||||
* @deprecated
|
||||
*/
|
||||
function hookTo(path) {
|
||||
exec(`node ${path}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
*/
|
||||
async function fHook(path) {
|
||||
const child = fork(path)
|
||||
return new Promise((res, rej) => {
|
||||
child.on('exit', () => {
|
||||
res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function rHook(path) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = { hookTo, fHook }
|
||||
@@ -1,29 +1,53 @@
|
||||
const audio = require('./audio.js')
|
||||
//@ts-check
|
||||
function panic() {
|
||||
console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE")
|
||||
while(1) {}
|
||||
}
|
||||
|
||||
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
|
||||
console.log(`
|
||||
async function main() {
|
||||
try {
|
||||
const audio = require('./audio.js')
|
||||
//@ts-expect-error
|
||||
const { poweroff, halt } = require('./shutdown.js')
|
||||
const input = require('./input.js')
|
||||
const { fHook } = require("./hook.js")
|
||||
|
||||
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
|
||||
console.log(`
|
||||
|
||||
|
||||
_______ _________ ______ _______ _______
|
||||
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /|
|
||||
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / )
|
||||
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) /
|
||||
| | | ___ | | | | __ ( | __)| ___ | ) _ (
|
||||
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\
|
||||
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ )
|
||||
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\|
|
||||
_______ _________ ______ _______ _______
|
||||
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /|
|
||||
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / )
|
||||
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) /
|
||||
| | | ___ | | | | __ ( | __)| ___ | ) _ (
|
||||
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\
|
||||
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ )
|
||||
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\|
|
||||
|
||||
_______ _______
|
||||
( ___ )( ____ \\
|
||||
| ( ) || ( \\/
|
||||
| | | || (_____
|
||||
| | | |(_____ )
|
||||
| | | | ) |
|
||||
| (___) |/\\____) |
|
||||
(_______)\\_______)
|
||||
_______ _______
|
||||
( ___ )( ____ \\
|
||||
| ( ) || ( \\/
|
||||
| | | || (_____
|
||||
| | | |(_____ )
|
||||
| | | | ) |
|
||||
| (___) |/\\____) |
|
||||
(_______)\\_______)
|
||||
|
||||
`)
|
||||
`)
|
||||
|
||||
audio('/chibrax/sheeebr.wav')
|
||||
audio('/chibrax/sheeebr.wav')
|
||||
|
||||
while(1) {}
|
||||
//chainload into sheebr
|
||||
await fHook("/usr/bin/sheebr.js")
|
||||
poweroff()
|
||||
|
||||
/*while(1){}
|
||||
console.log("End of init reached")
|
||||
panic()*/
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
panic()
|
||||
}
|
||||
}
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//@ts-check
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns
|
||||
*/
|
||||
async function input(str) {
|
||||
console.log(str)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
let line = "";
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
});
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = input
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.10"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
syscalls = require('./syscall.node')
|
||||
module.exports = syscalls
|
||||
@@ -0,0 +1,9 @@
|
||||
async function mSleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
async function sleep(s) {
|
||||
return mSleep(s * 1000)
|
||||
}
|
||||
|
||||
module.exports = { mSleep, sleep }
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"include": ["./**/*"],
|
||||
"compilerOptions": {
|
||||
// Tells TypeScript to read JS files, as
|
||||
// normally they are ignored as source files
|
||||
"allowJs": true,
|
||||
// Generate d.ts files
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": false,
|
||||
"noEmit": true,
|
||||
"lib": [ "ES2016" ],
|
||||
"target": "es2016",
|
||||
"moduleResolution":"Node",
|
||||
"noImplicitAny": true,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
if(process.argv.length >= 3){
|
||||
console.log(process.argv[3])
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const fs = require('fs')
|
||||
|
||||
let path = process.argv[3] ?? '.'
|
||||
let optionsArray = process.argv.slice(4) ?? []
|
||||
let options = []
|
||||
for(let option of optionsArray){
|
||||
if(option.startwith("--")) options.push(option.slice)
|
||||
else if(options.startwith("-")) options.push += option.slice(1).split('').map(el => {return '-' + el})
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(path);
|
||||
const nonHiddenFiles = files.filter(file => file[0] != '.')
|
||||
|
||||
console.log(options.includes('-a') ? files.join(' ') : nonHiddenFiles.join(' '))
|
||||
@@ -0,0 +1,6 @@
|
||||
const fs = require('fs')
|
||||
if(process.argv.length >= 3){
|
||||
fs.mkdir(process.argv[3], { recursive: true }, (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
console.log(process.cwd())
|
||||
@@ -0,0 +1,60 @@
|
||||
const { Lexer } = require('../lib/sheebr/lexer')
|
||||
const { getline } = require('../lib/sheebr/utils')
|
||||
const fs = require('fs')
|
||||
const environment = require('../lib/sheebr/environment')
|
||||
const readline = require('readline').createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: false
|
||||
});
|
||||
const readlineSync = require('../lib/sheebr/readLineSync')
|
||||
let execSync = require('child_process').execSync
|
||||
|
||||
|
||||
let current_dir = process.cwd()
|
||||
|
||||
start()
|
||||
|
||||
async function start(){
|
||||
while(true){
|
||||
input = await getline("sheebr> ");
|
||||
if(input == "exit") break;
|
||||
else evaluate(input);
|
||||
}
|
||||
}
|
||||
|
||||
function evaluate(input){
|
||||
let lexer = new Lexer(input)
|
||||
args = lexer.scanTokens()
|
||||
|
||||
if(args[0] == "cd"){
|
||||
if(args.length != 2){
|
||||
console.log("Wrong number of arguments"); return;}
|
||||
if(!fs.existsSync(args[1])){console.log("Folder does not exist"); return;}
|
||||
current_dir = args[1][0] == "/" ? args[1] : current_dir + '/' + args[1];
|
||||
console.log(current_dir)
|
||||
return;
|
||||
}
|
||||
// check for all folders in path
|
||||
|
||||
let found = false;
|
||||
for(let path of environment.path){
|
||||
let tobreak = false;
|
||||
const files = fs.readdirSync(path);
|
||||
if(files.includes(`${args[0]}.js`)){
|
||||
found = true;
|
||||
script = execSync(`node ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir});
|
||||
process.stdout.write(script)
|
||||
tobreak = true;
|
||||
}
|
||||
|
||||
if(tobreak) break;
|
||||
}
|
||||
if(!found){
|
||||
console.log("Program not found")
|
||||
}
|
||||
let program = args[0]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
const fs = require('fs')
|
||||
if(process.argv.length >= 3){
|
||||
fs.openSync(process.argv[3], 'w');
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
let environment = {
|
||||
path: ["/sheebr", "/usr/bin"]
|
||||
}
|
||||
|
||||
module.exports = environment
|
||||
@@ -0,0 +1,57 @@
|
||||
const { isAlpha } = require('./utils')
|
||||
|
||||
|
||||
class Lexer{
|
||||
constructor(source){
|
||||
this.tokens = [];
|
||||
this.current = 0;
|
||||
this.start = 0;
|
||||
this.source = source
|
||||
}
|
||||
|
||||
scanTokens(){
|
||||
while(this.current < this.source.length){
|
||||
this.start = this.current
|
||||
this.scanToken()
|
||||
|
||||
}
|
||||
return this.tokens;
|
||||
}
|
||||
|
||||
scanToken(){
|
||||
|
||||
if(this.source[this.current] == "\""){
|
||||
this.string()
|
||||
}
|
||||
else{
|
||||
let content = ""
|
||||
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
|
||||
content += this.source[this.current];
|
||||
this.current++;
|
||||
|
||||
}
|
||||
this.tokens.push(content)
|
||||
}
|
||||
this.current++;
|
||||
|
||||
}
|
||||
|
||||
string(){
|
||||
this.current++;
|
||||
let content = ""
|
||||
while(this.source[this.current] != "\"" && this.current < this.source.length){
|
||||
content += this.source[this.current];
|
||||
this.current++;
|
||||
}
|
||||
this.tokens.push(content)
|
||||
}
|
||||
|
||||
addToken(tokenType, value=""){
|
||||
this.tokens.push(Token(tokenType, value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
Lexer
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
async function getline(str) {
|
||||
process.stdout.write(str)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8')
|
||||
let line = ""
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
})
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function isAlpha(str){
|
||||
return /^[a-zA-Z]*$/.test(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
isAlpha, getline
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user