so many shell bugs - builtins freeze the shell

This commit is contained in:
Lisa Milne 2023-12-12 20:09:17 +10:00
parent 0597769c61
commit d8604b3e3b
4 changed files with 39 additions and 37 deletions

View file

@ -18,9 +18,7 @@ touch - create a new file
less - simple text file viewer
file - determines the file type
Under Development:
view - file viewer
edit - text file editor
And many more.
Running any command with the argument -? will give you help for that program.
Or you can run help <command> to get the same info.
@ -28,8 +26,7 @@ Or you can run help <command> to get the same info.
As a basic guide for guests:
Use ls to see what content is available, eg: ls web
Use view or less to view the content, eg: view web/about
`);
`);
return 0;
});
@ -117,7 +114,7 @@ Options:
one = true;
break;
default:
stdio.write(io.stderr,'unknown argument: -'+args[i][j]);
stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]);
}
}
}else{
@ -133,12 +130,12 @@ Options:
stdio.printf(dir+':');
var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC);
if (!fd) {
stdio.write(io.stderr,'cannot open directory: '+dir);
stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir);
return;
}
var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW);
if (!st) {
stdio.write(io.stderr,'cannot read file: '+dir);
stdio.fprintf(io.stderr,'cannot read file: %s\n',dir);
stdio.close(fd);
return;
}
@ -153,13 +150,13 @@ Options:
continue;
var efd = stdio.open(dir+'/'+e,stdio.flags.O_RDONLY|stdio.flags.O_NOFOLLOW|stdio.flags.O_SYNC);
if (!efd) {
stdio.write(io.stderr,'cannot read contents: '+dir);
stdio.fprintf(io.stderr,'cannot read contents: %s\n',dir);
break;
}
var est = stdio.fstatat(efd,stdio.flags.AT_SYMLINK_NOFOLLOW);
if (!est) {
stdio.close(efd);
stdio.write(io.stderr,'cannot read content: '+dir);
stdio.fprintf(io.stderr,'cannot read content: %s\n',dir);
break;
}
writeNodeData(est,efd);
@ -1047,7 +1044,7 @@ Options:
}
if (file == null) {
stdio.write(io.stderr,'no file specified');
stdio.write(io.stderr,'no file specified\n');
return 1;
}
@ -1055,7 +1052,7 @@ Options:
var txt = short+': ';
if (!st) {
stdio.fprintf(io.stderr,'cannot open file: %s',file);
stdio.fprintf(io.stderr,'cannot open file: %s\n',file);
return 1;
}else{
switch (st.type) {
@ -1092,7 +1089,7 @@ Options:
}
}
stdio.printf(txt);
stdio.printf('%s\n',txt);
return 0;
});

View file

@ -2298,8 +2298,21 @@ clite.tty = {
if (!l)
return;
t.rcb(l);
var f = t.rcb;
t.rcb = null;
f(l);
},
fake:function(str) {
for (var i=0; i<str.length; i++) {
let k = {
down:false,
code:str.charCodeAt(i),
char:str[i],
lchar:str[i].toLowerCase()
};
clite.tty.input(k);
}
},
read:function(id,cb) {
if (id<0 || id>=clite.tty.data.ttys.length)

View file

@ -6,11 +6,13 @@ return Object.create({
// clears the terminal
clear:function() {
clite.term.clear();
var ctty = 0;
clite.tty.clear(ctty);
},
ttyctrl:function(fn,v) {
return clite.term.ttyctrl(fn,v);
return false;
//return clite.term.ttyctrl(fn,v);
}
});

View file

@ -14,28 +14,22 @@ clite.commands.load('sh',function(args,env,io) {
},
cd:function(args,io) {
var dir = env.HOME;
if (args.length > 1) {
if (args.length > 1)
dir = clite.resolvePath(args[1]);
}
var fd = stdio.open(dir,stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY);
if (!fd) {
stdio.write(io.stderr,'invalid directory: '+dir);
return;
}
// shouldn't need this now
if (!fd.node.data.isdir) {
stdio.write(io.stderr,'invalid directory: '+dir);
stdio.fprintf(io.stderr,'invalid directory: %s\n',dir);
return;
}
stdio.close(fd);
env.PWD = dir;
},
pwd:function(args,io) {
stdio.write(io.stdout,env.PWD);
stdio.fprintf(io.stdout,'%s\n',env.PWD);
},
echo:function(args,io) {
args.shift();
var txt = args.join(' ');
var txt = args.join(' ')+'\n';
stdio.write(io.stdout,txt);
},
which:function(args,io) {
@ -47,31 +41,31 @@ clite.commands.load('sh',function(args,env,io) {
var path = resolvePATH(args[1]);
if (!path)
return;
stdio.write(io.stdout,args[1]+' is '+path);
stdio.fprintf(io.stdout,'%s is %s\n',args[1],path);
}
},
type:function(args,io) {
if (args.length <2)
return;
if (typeof macro[args[1]] != 'undefined') {
stdio.write(io.stdout,args[1]+' is a shell builtin');
stdio.fprintf(io.stdout,'%s is a shell builtin\n',args[1]);
}else{
var path = resolvePATH(args[1]);
if (!path)
return;
stdio.write(io.stdout,args[1]+' is '+path);
stdio.fprintf(io.stdout,'%s is %s\n',args[1],path);
}
},
whoami:function(args,io) {
stdio.write(io.stdout,env.USER);
stdio.fprintf(io.stdout,'%s\n',env.USER);
},
alias:function(args,io) {
stdio.write(io.stdout,'unimplemented');
stdio.fprintf(io.stdout,'unimplemented\n');
},
export:function(args,io) {
if (args.length == 1) {
Object.keys(env).forEach(function(key) {
stdio.write(io.stdout,key+'='+env[key]);
stdio.fprintf(io.stdout,'%s=%s\n',key,env[key]);
});
return;
}
@ -203,7 +197,7 @@ clite.commands.load('sh',function(args,env,io) {
}
function tabfill() {
var c = term.ttyctrl('iget');
var c = '';//term.ttyctrl('iget');
var parts = clite.strToArgs(c);
var ai = parts.length-1;
if (ai < 0)
@ -370,10 +364,6 @@ clite.commands.load('sh',function(args,env,io) {
if (has_exited)
return;
writePrompt();
// ensure input is enabled
term.ttyctrl('show');
// and that we're on the main framebuffer
term.ttyctrl('alt',false);
// then read from stdin
stdio.read(io.stdin,input);
}