•file.Parent
This commit is contained in:
parent
aa95b6add4
commit
eb9550aa29
@ -11,7 +11,7 @@
|
|||||||
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•GroupOrd") \
|
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•GroupOrd") \
|
||||||
/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(currentError,"•CurrentError") \
|
/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(currentError,"•CurrentError") \
|
||||||
/* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime") M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \
|
/* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime") M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \
|
||||||
/* sysfn.c*/M(fName,"•file.Name") \
|
/* sysfn.c*/M(fName,"•file.Name") M(fParent,"•file.Parent") \
|
||||||
/* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \
|
/* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \
|
||||||
/* inverse.c*/M(setInvReg, "(SetInvReg)") M(setInvSwap, "(SetInvSwap)") M(nativeInvReg, "(NativeInvReg)") M(nativeInvSwap, "(NativeInvSwap)") \
|
/* inverse.c*/M(setInvReg, "(SetInvReg)") M(setInvSwap, "(SetInvSwap)") M(nativeInvReg, "(NativeInvReg)") M(nativeInvSwap, "(NativeInvSwap)") \
|
||||||
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \
|
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \
|
||||||
|
|||||||
@ -768,6 +768,10 @@ B fName_c1(B t, B x) {
|
|||||||
if (!isArr(x) || RNK(x)!=1) thrM("•file.Name: Argument must be a character vector");
|
if (!isArr(x) || RNK(x)!=1) thrM("•file.Name: Argument must be a character vector");
|
||||||
return path_name(x);
|
return path_name(x);
|
||||||
}
|
}
|
||||||
|
B fParent_c1(B t, B x) {
|
||||||
|
if (!isArr(x) || RNK(x)!=1) thrM("•file.Parent: Argument must be a character vector");
|
||||||
|
return path_parent(x);
|
||||||
|
}
|
||||||
|
|
||||||
B mapBytes_c1(B d, B x) {
|
B mapBytes_c1(B d, B x) {
|
||||||
return mmap_file(path_rel(nfn_objU(d), x));
|
return mmap_file(path_rel(nfn_objU(d), x));
|
||||||
@ -1169,7 +1173,7 @@ B sys_c1(B t, B x) {
|
|||||||
B path = m_f64(0);
|
B path = m_f64(0);
|
||||||
B name = m_f64(0);
|
B name = m_f64(0);
|
||||||
B wdpath = m_f64(0);
|
B wdpath = m_f64(0);
|
||||||
#define REQ_PATH ({ if(!path.u) path = q_N(comp_currPath)? bi_N : path_abs(path_dir(inc(comp_currPath))); path; })
|
#define REQ_PATH ({ if(!path.u) path = q_N(comp_currPath)? bi_N : path_abs(path_parent(inc(comp_currPath))); path; })
|
||||||
#define REQ_NAME ({ if(!name.u) name = path_name(inc(comp_currPath)); name; })
|
#define REQ_NAME ({ if(!name.u) name = path_name(inc(comp_currPath)); name; })
|
||||||
for (usz i = 0; i < IA(x); i++) {
|
for (usz i = 0; i < IA(x); i++) {
|
||||||
B c = GetU(x,i);
|
B c = GetU(x,i);
|
||||||
@ -1182,7 +1186,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(fExists), inc(bi_fName), 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(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);
|
||||||
@ -1263,6 +1267,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","exists","name","mapbytes","createdir","rename","remove");
|
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","exists","name","parent","mapbytes","createdir","rename","remove");
|
||||||
c(BMd1,bi_bitcast)->im = bitcast_im;
|
c(BMd1,bi_bitcast)->im = bitcast_im;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -204,7 +204,7 @@ static i32 compare(B w, B x) { // doesn't consume; -1 if w<x, 1 if w>x, 0 if w
|
|||||||
#undef CMP
|
#undef CMP
|
||||||
|
|
||||||
NOINLINE bool atomEqualF(B w, B x);
|
NOINLINE bool atomEqualF(B w, B x);
|
||||||
static bool atomEqual(B w, B x) { // doesn't consume (not that that matters really currently)
|
static bool atomEqual(B w, B x) { // doesn't consume
|
||||||
if(isF64(w)&isF64(x)) return w.f==x.f;
|
if(isF64(w)&isF64(x)) return w.f==x.f;
|
||||||
if (w.u==x.u) return true;
|
if (w.u==x.u) return true;
|
||||||
if (!isVal(w) | !isVal(x)) return false;
|
if (!isVal(w) | !isVal(x)) return false;
|
||||||
|
|||||||
@ -117,15 +117,16 @@ B path_rel(B base, B rel) { // consumes rel; assumes base is a char vector or bi
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
B path_dir(B path) {
|
B path_parent(B path) {
|
||||||
assert(isArr(path));
|
assert(isArr(path));
|
||||||
SGetU(path)
|
SGetU(path)
|
||||||
usz pia = IA(path);
|
usz pia = IA(path);
|
||||||
if (pia==0) thrM("Empty file path");
|
if (pia==0) thrM("Empty file path");
|
||||||
guaranteeStr(path);
|
guaranteeStr(path);
|
||||||
for (i64 i = (i64)pia-1; i >= 0; i--) {
|
for (i64 i = (i64)pia-2; i >= 0; i--) {
|
||||||
if (o2cu(GetU(path, i))=='/') return taga(arr_shVec(TI(path,slice)(path, 0, i+1)));
|
if (o2cu(GetU(path, i))=='/') return taga(arr_shVec(TI(path,slice)(path, 0, i+1)));
|
||||||
}
|
}
|
||||||
|
if (o2cu(GetU(path, 0))=='/') return path;
|
||||||
dec(path);
|
dec(path);
|
||||||
u32* rp; B r = m_c32arrv(&rp, 2); rp[0] = '.'; rp[1] = '/';
|
u32* rp; B r = m_c32arrv(&rp, 2); rp[0] = '.'; rp[1] = '/';
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include "utf.h"
|
#include "utf.h"
|
||||||
|
|
||||||
B path_rel(B base, B rel); // consumes rel; assumes base is a char vector or bi_N
|
B path_rel(B base, B rel); // consumes rel; assumes base is a char vector or bi_N
|
||||||
B path_dir(B path); // consumes; returns directory part of file path, with trailing slash
|
B path_parent(B path); // consumes; returns the containing directory, with trailing slash
|
||||||
B path_name(B path); // consumes; returns filename from a path
|
B path_name(B path); // consumes; returns filename from a path
|
||||||
B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N
|
B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user