mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
make file types human readable-ish, FT_TEXT rather than 1
This commit is contained in:
parent
80543aef12
commit
3dbefb93da
2 changed files with 42 additions and 22 deletions
|
|
@ -50,7 +50,7 @@ Options:
|
|||
|
||||
function writeNodeData(st,fd) {
|
||||
if (long) {
|
||||
if (st.type == 4) {
|
||||
if (st.type == stdio.types.FT_LINK) {
|
||||
var d = stdio.readAll(fd);
|
||||
if (!d)
|
||||
d = '?';
|
||||
|
|
@ -95,7 +95,7 @@ Options:
|
|||
return;
|
||||
}
|
||||
var st = stdio.fstat(fd);
|
||||
if (!st || st.type != 3) {
|
||||
if (!st || st.type != stdio.types.FT_DIR) {
|
||||
writeNodeData(st,fd);
|
||||
stdio.close(fd);
|
||||
return;
|
||||
|
|
@ -167,7 +167,7 @@ Options:
|
|||
function fcb(fd) {
|
||||
var st = stdio.fstat(fd);
|
||||
// check if it's a directory or link
|
||||
if (!st || st.type == 3 || st.type == 4) {
|
||||
if (!st || st.type == stdio.types.FT_DIR || st.type == stdio.types.FT_LINK) {
|
||||
if (st) {
|
||||
io.error('not a normal file: '+st.name);
|
||||
}else{
|
||||
|
|
@ -196,16 +196,16 @@ Options:
|
|||
}
|
||||
|
||||
files.forEach(function(file,index) {
|
||||
var fd = stdio.open(file,fcb);
|
||||
if (!fd) {
|
||||
io.error('cannot open file: '+file);
|
||||
var st = stdio.stat(file);
|
||||
// check if it's a directory or link
|
||||
if (!st || st.type == stdio.types.FT_DIR || st.type == stdio.types.FT_LINK) {
|
||||
io.error('not a normal file: '+file);
|
||||
pending--;
|
||||
return;
|
||||
}
|
||||
var st = stdio.fstat(fd);
|
||||
// check if it's a directory or link
|
||||
if (!st || st.type == 3 || st.type == 4) {
|
||||
io.error('not a normal file: '+file);
|
||||
var fd = stdio.open(file,fcb);
|
||||
if (!fd) {
|
||||
io.error('cannot open file: '+file);
|
||||
pending--;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -714,6 +714,26 @@ clite.io = {
|
|||
return clite.io.fchmod(fd,mode);
|
||||
}
|
||||
},
|
||||
// 0: unknown
|
||||
// 1: text file
|
||||
// 2: executable/binary (function)
|
||||
// 3: directory
|
||||
// 4: link
|
||||
// 5: device
|
||||
// 6: unloaded remote file
|
||||
// 7: shell script
|
||||
// 8: image
|
||||
types:{
|
||||
FT_UNKOWN:0,
|
||||
FT_TEXT:1,
|
||||
FT_BINARY:2,
|
||||
FT_DIR:3,
|
||||
FT_LINK:4,
|
||||
FT_DEV:5,
|
||||
FT_REMOTE:6,
|
||||
FT_SCRIPT:7,
|
||||
FT_IMAGE:8
|
||||
},
|
||||
creat:null,
|
||||
open:null,
|
||||
close:null,
|
||||
|
|
@ -1633,39 +1653,39 @@ clite.lib = {
|
|||
// 8: image
|
||||
if (fd.node.data.content == null) {
|
||||
if (fd.node.data.remote != null)
|
||||
return 6;
|
||||
return 0;
|
||||
return clite.io.types.FT_REMOTE;
|
||||
return clite.io.types.FT_UNKOWN;
|
||||
}
|
||||
if (fd.node.data.islink)
|
||||
return 4;
|
||||
return clite.io.types.FT_LINK;
|
||||
if (fd.node.data.isdir)
|
||||
return 3;
|
||||
return clite.io.types.FT_DIR;
|
||||
if (fd.node.data.isdev)
|
||||
return 5;
|
||||
return clite.io.types.FT_DEV;
|
||||
const type = typeof fd.node.data.content;
|
||||
switch (type) {
|
||||
case 'string': // text file
|
||||
if (fd.node.data.content.substring(0,2) == '#!')
|
||||
return 7;
|
||||
return 1;
|
||||
return clite.io.types.FT_SCRIPT;
|
||||
return clite.io.types.FT_TEXT;
|
||||
break;
|
||||
case 'function': // executable
|
||||
return 2;
|
||||
return clite.io.types.FT_BINARY;
|
||||
break;
|
||||
case 'object':
|
||||
if (Array.isArray(fd.node.data.content)) // directory
|
||||
return 3;
|
||||
return clite.io.types.FT_DIR;
|
||||
if (fd.node.data.content instanceof HTMLImageElement)
|
||||
return 8;
|
||||
return clite.io.types.FT_IMAGE;
|
||||
case 'symbol':
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
case 'bigint':
|
||||
case 'undefined':
|
||||
default:
|
||||
return 0;
|
||||
return clite.io.types.FT_UNKOWN;
|
||||
}
|
||||
return 0;
|
||||
return clite.io.types.FT_UNKOWN;
|
||||
},
|
||||
getBuffer:function() {
|
||||
return Object.create({
|
||||
|
|
|
|||
Loading…
Reference in a new issue