diff --git a/clite/commands.js b/clite/commands.js index d2b96e4..aee52b7 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -5,7 +5,7 @@ clite.commands.load('help',function(args,env,io) { var stdio = io.include('stdio'); if (args.length > 1) { // TODO: implement command help lookup - stdio.printf('help with arguments is a work in progress'); + stdio.printf('help with arguments is a work in progress\n'); } stdio.printf(` Welcome to CLIte (pronounced like 'site' with an added L). @@ -127,7 +127,7 @@ Options: dirs.forEach(function(dir,index) { if (dirs.length > 1) - stdio.printf(dir+':'); + stdio.printf('%s:\n',dir); var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC); if (!fd) { stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir); @@ -206,7 +206,7 @@ Options: remote = false; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else{ @@ -237,9 +237,9 @@ Options: || st.type == stdio.types.FT_IMAGE ) { if (st) { - stdio.write(io.stderr,'not a normal file: '+st.name); + stdio.fprintf(io.stderr,'not a normal file: %s\n',st.name); }else{ - stdio.write(io.stderr,'not a normal file'); + stdio.write(io.stderr,'not a normal file\n'); } }else{ var d = stdio.readAll(fd); @@ -247,10 +247,11 @@ Options: if (download) { var ld = stdio.open('/dev/local',stdio.flags.O_WRONLY); if (ld) { - stdio.write(ld,{name:st.name,data:d}); + var t = st.name+String.fromCharCode(2)+d; + stdio.write(ld,t); stdio.close(ld); }else{ - stdio.write(io.stderr,'can not write to local device'); + stdio.write(io.stderr,'can not write to local device\n'); } }else{ stdio.printf(d); @@ -274,7 +275,7 @@ Options: || st.type == stdio.types.FT_UNKOWN || st.type == stdio.types.FT_IMAGE ) { - stdio.write(io.stderr,'not a normal file: '+file); + stdio.fprintf(io.stderr,'not a normal file: %s\n',file); pending--; return; } @@ -284,7 +285,7 @@ Options: } var fd = stdio.open(file,stdio.flags.O_RDONLY,fcb); if (!fd) { - stdio.write(io.stderr,'cannot open file: '+file); + stdio.fprintf(io.stderr,'cannot open file: %s\n',file); pending--; return; } @@ -379,13 +380,13 @@ Options: return 0; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else if (file == null) { file = clite.resolvePath(args[i],false); }else{ - stdio.write(io.stderr,'unknown argument: '+args[i]); + stdio.fprintf(io.stderr,'unknown argument: %s\n',args[i]); } } @@ -408,13 +409,13 @@ Options: function prepFile(fd) { if (!fd) { - stdio.write(io.stderr,'could not open file: '+file); + stdio.fprintf(io.stderr,'could not open file: %s\n',file); io.exit(1); return; } var st = stdio.fstatat(fd,0); if ( !st || (st.type != stdio.types.FT_TEXT && st.type != stdio.types.FT_SCRIPT)) { - stdio.write(io.stderr,'can not read files of this type'); + stdio.write(io.stderr,'can not read files of this type\n'); io.exit(1); return; } @@ -440,14 +441,14 @@ Options: if (file == null) { if (stdio.isatty(io.stdin)) { - stdio.write(io.stderr,'no file specified'); + stdio.write(io.stderr,'no file specified\n'); return 1; } fd = io.stdin; }else{ fd = stdio.open(file,stdio.flags.O_RDONLY,prepFile); if (!fd) { - stdio.write(io.stderr,'could not open file: '+file); + stdio.fprintf(io.stderr,'could not open file: %s\n',file); return 1; } } @@ -515,7 +516,7 @@ Options: }); clite.commands.load('view',function(args,env,io) { - stdio.printf('view is under development'); + stdio.printf('view is under development\n'); return 0; }); @@ -565,7 +566,7 @@ Options: } if (file == null) { - stdio.fprintf(io.stderr,'no file specified'); + stdio.fprintf(io.stderr,'no file specified\n'); return 1; } @@ -574,13 +575,13 @@ Options: if (!st) { if (force) return 0; - stdio.fprintf(io.stderr,'no such file or directory: %s',path); + stdio.fprintf(io.stderr,'no such file or directory: %s\n',path); return 1; } var fd = stdio.open(path,stdio.flags.O_RDONLY|stdio.flags.O_NOFOLLOW|stdio.flags.O_SYNC); if (!fd) { - stdio.fprintf(io.stderr,'permission denied: %s',path); + stdio.fprintf(io.stderr,'permission denied: %s\n',path); return 1; } @@ -589,7 +590,7 @@ Options: var i = stdio.read(fd); if (i) { stdio.close(fd); - stdio.fprintf(io.stderr,'cannot remove non-empty directory: %s',path); + stdio.fprintf(io.stderr,'cannot remove non-empty directory: %s\n',path); return 1; } }else{ @@ -606,13 +607,13 @@ Options: stdio.close(fd); if (st.type == stdio.types.FT_DEV) { - stdio.fprintf(io.stderr,'cannot remove device files: %s',path); + stdio.fprintf(io.stderr,'cannot remove device files: %s\n',path); return 1; } if (!stdio.remove(path)) { - stdio.fprintf(io.stderr,'permission denied: %s',path); + stdio.fprintf(io.stderr,'permission denied: %s\n',path); return 1; } @@ -664,7 +665,7 @@ Options: } if (file == null) { - stdio.fprintf(io.stderr,'no path specified'); + stdio.fprintf(io.stderr,'no path specified\n'); return 1; } @@ -687,13 +688,13 @@ Options: st = stdio.stat(path); if (st) { if (st.type != stdio.types.FT_DIR) { - stdio.fprintf(io.stderr,'permission denied: %s',path); + stdio.fprintf(io.stderr,'permission denied: %s\n',path); return 1; } continue; } if (!stdio.mkdir(path)) { - stdio.fprintf(io.stderr,'permission denied: %s',path); + stdio.fprintf(io.stderr,'permission denied: %s\n',path); return 1; } } @@ -1115,11 +1116,11 @@ Options: return 0; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else{ - stdio.write(io.stderr,'unknown argument: '+args[i]); + stdio.fprintf(io.stderr,'unknown argument: %s\n',args[i]); } } @@ -1188,11 +1189,11 @@ Options: version = true; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else{ - stdio.write(io.stderr,'unknown argument: '+args[i]); + stdio.fprintf(io.stderr,'unknown argument: %s\n',args[i]); } } @@ -1213,7 +1214,7 @@ Options: if (machine) txt += ut.machine; - stdio.printf(txt); + stdio.printf('%s\n',txt); return 0; }); @@ -1258,14 +1259,14 @@ Options: utc = true; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else if (args[i][0] == '+') { format = args[i].substring(1); }else{ // TODO: set time - stdio.write(io.stderr,'unknown argument: '+args[i]); + stdio.fprintf(io.stderr,'unknown argument: %s\n',args[i]); } } diff --git a/clite/core.js b/clite/core.js index cec9d60..79fa874 100644 --- a/clite/core.js +++ b/clite/core.js @@ -114,7 +114,14 @@ var clite = { read:null, write:function(obj) { if (typeof obj === 'string') { - clite.core.download('data.txt',obj); + var n = 'data.txt'; + var d = obj; + var ind = obj.indexOf(String.fromCharCode(2)); + if (ind > -1) { + n = obj.substring(0,ind); + d = obj.substring(ind+1); + } + clite.core.download(n,d); }else if (typeof obj.name === 'string' && typeof obj.data === 'string') { clite.core.download(obj.name,obj.data); }else{