From 7b031a2aa028282d3a2bc361af2191f1c40e0f65 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 15 Mar 2022 21:37:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=A2file.Exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 309bc43b..fba90dd1 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -670,6 +670,7 @@ static void sys_gcFn() { static NFnDesc* fTypeDesc; +static NFnDesc* fExistsDesc; static NFnDesc* fListDesc; B list_c1(B d, B x) { return path_list(path_rel(nfn_objU(d), x)); @@ -680,6 +681,10 @@ B ftype_c1(B d, B x) { if (ty==0) thrM("•file.Type: Error while accessing file"); return m_c32(ty); } +B fexists_c1(B d, B x) { + char ty = path_type(path_rel(nfn_objU(d), x)); + return m_f64(ty!=0); +} B fName_c1(B t, B x) { if (!isArr(x) || rnk(x)!=1) thrM("•file.Name: Argument must be a character vector"); @@ -1072,7 +1077,7 @@ B sys_c1(B t, B x) { if(!fileNS.u) { REQ_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), inc(bi_fName)); + 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)); #undef F } cr = inc(fileNS); @@ -1141,10 +1146,11 @@ void sysfn_init() { fBytesDesc = registerNFn(m_str8l("(file).Bytes"), fbytes_c1, fbytes_c2); fListDesc = registerNFn(m_str8l("(file).List"), list_c1, c2_bad); fTypeDesc = registerNFn(m_str8l("(file).Type"), ftype_c1, c2_bad); + fExistsDesc = registerNFn(m_str8l("(file).Exists"), fexists_c1, c2_bad); importDesc = registerNFn(m_str32(U"•Import"), import_c1, import_c2); reBQNDesc = registerNFn(m_str8l("(REPL)"), repl_c1, repl_c2); } void sysfnPost_init() { - file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","name"); + file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","exists","name"); c(BMd1,bi_bitcast)->im = bitcast_im; }