•file.Size, make •file.List decode UTF-8
invalid UTF-8 is a problem for the future
This commit is contained in:
parent
f39784aa10
commit
81e09956d3
@ -15,7 +15,7 @@ See [the BQN specification](https://mlochbaum.github.io/BQN/spec/system.html) fo
|
|||||||
| `•name` | |
|
| `•name` | |
|
||||||
| `•wdpath` | |
|
| `•wdpath` | |
|
||||||
| `•Exit` | |
|
| `•Exit` | |
|
||||||
| `•file` | Fields: `path`, `At`, `List`, `Bytes`, `Chars`, `Lines`, `Type`, `Exists`, `Name`, `Parent`, `MapBytes`, `CreateDir`, `Rename`, `Remove`, `Created`, `Modified`, `Accessed` |
|
| `•file` | Fields: `path`, `At`, `List`, `Bytes`, `Chars`, `Lines`, `Type`, `Exists`, `Name`, `Parent`, `MapBytes`, `CreateDir`, `Rename`, `Remove`, `Created`, `Modified`, `Accessed`, `Size` |
|
||||||
| `•FChars` | |
|
| `•FChars` | |
|
||||||
| `•FBytes` | |
|
| `•FBytes` | |
|
||||||
| `•FLines` | |
|
| `•FLines` | |
|
||||||
|
|||||||
@ -729,6 +729,7 @@ static NFnDesc* fTypeDesc;
|
|||||||
static NFnDesc* fCreatedDesc;
|
static NFnDesc* fCreatedDesc;
|
||||||
static NFnDesc* fAccessedDesc;
|
static NFnDesc* fAccessedDesc;
|
||||||
static NFnDesc* fModifiedDesc;
|
static NFnDesc* fModifiedDesc;
|
||||||
|
static NFnDesc* fSizeDesc;
|
||||||
static NFnDesc* fExistsDesc;
|
static NFnDesc* fExistsDesc;
|
||||||
static NFnDesc* fListDesc;
|
static NFnDesc* fListDesc;
|
||||||
static NFnDesc* fMapBytesDesc;
|
static NFnDesc* fMapBytesDesc;
|
||||||
@ -766,6 +767,7 @@ B ftype_c1(B d, B x) {
|
|||||||
B fcreated_c1 (B d, B x) { return path_info(path_rel(nfn_objU(d), x), 0); }
|
B fcreated_c1 (B d, B x) { return path_info(path_rel(nfn_objU(d), x), 0); }
|
||||||
B faccessed_c1(B d, B x) { return path_info(path_rel(nfn_objU(d), x), 1); }
|
B faccessed_c1(B d, B x) { return path_info(path_rel(nfn_objU(d), x), 1); }
|
||||||
B fmodified_c1(B d, B x) { return path_info(path_rel(nfn_objU(d), x), 2); }
|
B fmodified_c1(B d, B x) { return path_info(path_rel(nfn_objU(d), x), 2); }
|
||||||
|
B fsize_c1 (B d, B x) { return path_info(path_rel(nfn_objU(d), x), 3); }
|
||||||
|
|
||||||
B fexists_c1(B d, B x) {
|
B fexists_c1(B d, B x) {
|
||||||
char ty = path_type(path_rel(nfn_objU(d), x));
|
char ty = path_type(path_rel(nfn_objU(d), x));
|
||||||
@ -1225,7 +1227,7 @@ B sys_c1(B t, B x) {
|
|||||||
if(!fileNS.u) {
|
if(!fileNS.u) {
|
||||||
REQ_PATH;
|
REQ_PATH;
|
||||||
#define F(X) m_nfn(X##Desc, inc(path))
|
#define F(X) m_nfn(X##Desc, inc(path))
|
||||||
fileNS = m_nns(file_nsGen, q_N(path)? m_c32(0) : inc(path), F(fileAt), F(fList), F(fBytes), F(fChars), F(fLines), F(fType), F(fCreated), F(fAccessed), F(fModified), F(fExists), inc(bi_fName), inc(bi_fParent), F(fMapBytes), F(createdir), F(rename), F(remove));
|
fileNS = m_nns(file_nsGen, q_N(path)? m_c32(0) : inc(path), F(fileAt), F(fList), F(fBytes), F(fChars), F(fLines), F(fType), F(fCreated), F(fAccessed), F(fModified), F(fSize), F(fExists), inc(bi_fName), inc(bi_fParent), F(fMapBytes), F(createdir), F(rename), F(remove));
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
cr = incG(fileNS);
|
cr = incG(fileNS);
|
||||||
@ -1299,6 +1301,7 @@ void sysfn_init() {
|
|||||||
fCreatedDesc = registerNFn(m_c8vec_0("(file).Created"), fcreated_c1, c2_bad);
|
fCreatedDesc = registerNFn(m_c8vec_0("(file).Created"), fcreated_c1, c2_bad);
|
||||||
fModifiedDesc= registerNFn(m_c8vec_0("(file).Modified"), fmodified_c1, c2_bad);
|
fModifiedDesc= registerNFn(m_c8vec_0("(file).Modified"), fmodified_c1, c2_bad);
|
||||||
fAccessedDesc= registerNFn(m_c8vec_0("(file).Accessed"), faccessed_c1, c2_bad);
|
fAccessedDesc= registerNFn(m_c8vec_0("(file).Accessed"), faccessed_c1, c2_bad);
|
||||||
|
fSizeDesc = registerNFn(m_c8vec_0("(file).Size"), fsize_c1, c2_bad);
|
||||||
createdirDesc= registerNFn(m_c8vec_0("(file).CreateDir"), createdir_c1, c2_bad);
|
createdirDesc= registerNFn(m_c8vec_0("(file).CreateDir"), createdir_c1, c2_bad);
|
||||||
renameDesc = registerNFn(m_c8vec_0("(file).Rename"), c1_bad, rename_c2);
|
renameDesc = registerNFn(m_c8vec_0("(file).Rename"), c1_bad, rename_c2);
|
||||||
removeDesc = registerNFn(m_c8vec_0("(file).Remove"), remove_c1, c2_bad);
|
removeDesc = registerNFn(m_c8vec_0("(file).Remove"), remove_c1, c2_bad);
|
||||||
@ -1309,6 +1312,6 @@ void sysfn_init() {
|
|||||||
ffiloadDesc = registerNFn(m_c32vec_0(U"•FFI"), c1_bad, ffiload_c2);
|
ffiloadDesc = registerNFn(m_c32vec_0(U"•FFI"), c1_bad, ffiload_c2);
|
||||||
}
|
}
|
||||||
void sysfnPost_init() {
|
void sysfnPost_init() {
|
||||||
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","created","accessed","modified","exists","name","parent","mapbytes","createdir","rename","remove");
|
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","created","accessed","modified","size","exists","name","parent","mapbytes","createdir","rename","remove");
|
||||||
c(BMd1,bi_bitcast)->im = bitcast_im;
|
c(BMd1,bi_bitcast)->im = bitcast_im;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -226,7 +226,7 @@ B path_list(B path) {
|
|||||||
B res = emptySVec();
|
B res = emptySVec();
|
||||||
while ((c = readdir(d)) != NULL) {
|
while ((c = readdir(d)) != NULL) {
|
||||||
char* name = c->d_name;
|
char* name = c->d_name;
|
||||||
if (name[0]=='.'? !(name[1]==0 || (name[1]=='.'&&name[2]==0)) : true) res = vec_addN(res, m_c8vec_0(name));
|
if (name[0]=='.'? !(name[1]==0 || (name[1]=='.'&&name[2]==0)) : true) res = vec_addN(res, utf8Decode(name, strlen(name)));
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
dec(path);
|
dec(path);
|
||||||
@ -370,6 +370,7 @@ B path_info(B path, i32 mode) {
|
|||||||
if (mode==0) return get_timespec(s.st_ctim);
|
if (mode==0) return get_timespec(s.st_ctim);
|
||||||
if (mode==1) return get_timespec(s.st_atim);
|
if (mode==1) return get_timespec(s.st_atim);
|
||||||
if (mode==2) return get_timespec(s.st_mtim);
|
if (mode==2) return get_timespec(s.st_mtim);
|
||||||
|
if (mode==3) return m_f64(s.st_size);
|
||||||
thrM("Unknown path_info mode");
|
thrM("Unknown path_info mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,5 +28,5 @@ void file_wBytes(FILE* file, B name, B x); // doesn't consume
|
|||||||
|
|
||||||
B path_list(B path); // consumes
|
B path_list(B path); // consumes
|
||||||
char path_type(B path); // consumes; errors only if path isn't a string
|
char path_type(B path); // consumes; errors only if path isn't a string
|
||||||
B path_info(B path, i32 mode); // consumes; mode: 0:created 1:accessed 2:modified
|
B path_info(B path, i32 mode); // consumes; mode: 0:created 1:accessed 2:modified 3:size
|
||||||
void cbqn_heapDump(void);
|
void cbqn_heapDump(void);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user