diff --git a/clite/core.js b/clite/core.js index 53b16e1..d2a0c5c 100644 --- a/clite/core.js +++ b/clite/core.js @@ -2717,7 +2717,20 @@ clite.lib = { return -3; } - if (clite.lib.getFileType(fd) != clite.io.types.FT_BINARY) { + var ft = clite.lib.getFileType(fd); + if (ft == clite.io.types.FT_SCRIPT) { + var fl = clite.io.readLine(io.pid,fd); + clite.io.close(fd); + if (!fl) + return -5; + var e = fl.substring(2); + fd = clite.io.open(io.pid,e,clite.io.flags.O_RDONLY|clite.io.flags.O_EXEC|clite.io.flags.O_SYNC); + if (!fd) + return -6; + args = [args[0],path]; + ft = clite.lib.getFileType(fd); + } + if (ft != clite.io.types.FT_BINARY) { clite.io.close(io.pid,fd); return -4; } diff --git a/clite/libclite.js b/clite/libclite.js index 1d96c4a..6c7f8d9 100644 --- a/clite/libclite.js +++ b/clite/libclite.js @@ -8,9 +8,10 @@ return Object.create({ resolvePath:function(txt,base) { if (txt == '/') return txt; - if (txt[0] == '~') { + if (txt[0] == '~') txt = env.HOME+txt.substring(1); - } + if (txt[0] == '.') + txt = env.PWD+'/'+txt; var path = txt; if (txt[0] != '/') { if (typeof base != 'string') diff --git a/clite/shell.js b/clite/shell.js index 4cda1ed..dab688c 100644 --- a/clite/shell.js +++ b/clite/shell.js @@ -367,16 +367,36 @@ Options: if (r == -1) { stdlib.fprintf(io.stderr,'Shell: unknown command: %s\n',args[0]); io.exit(-1); + return; } if (r == -2) { stdio.fprintf(io.stderr,'Shell: error in command: %s\n',args[0]); io.exit(-1); + return; } if (r == -3 || r == -4) { stdio.fprintf(io.stderr,'Shell: not an executable file: %s\n',args[0]); io.exit(-3); + return; + } + + if (r == -5) { + stdio.fprintf(io.stderr,'Shell: invalid parser for file: %s\n',args[0]); + io.exit(-3); + return; + } + + if (r == -6) { + stdio.fprintf(io.stderr,'Shell: no valid parser for file: %s\n',args[0]); + io.exit(-3); + return; + } + + if (r<0) { + stdio.fprintf(io.stderr,'Shell: could not exec file: %s\n',args[0]); + io.exit(-3); } } var pid = stdlib.fork(env,fio,execFunc); @@ -506,24 +526,16 @@ Options: // run a shell script if one is specified if (f != null) { - var fd = stdio.open(f,stdio.flags.O_RDONLY); - if (!fd) - return 1; - parseScript(fd); - stdio.close(fd); - - stdlib.waitall(function() { + parser.queue(f); + parser.run(function() { io.exit(0); }); // run a shell script from stdin }else if (!stdio.isatty(io.stdin)) { if (!s) return 0; - parseScript(io.stdin); - - stdlib.waitall(function() { - io.exit(0); - }); + // TODO: parser stdin support + return 1; // otherwise we have an interactive shell // so run /etc/shrc and ~/.shrc }else{