From 60e51e4493bce6006fff87b0d6c1a878e69a9a41 Mon Sep 17 00:00:00 2001 From: otya128 Date: Sun, 25 Dec 2016 13:24:53 +0900 Subject: [PATCH] Implement CHKFILE --- SMILEBASIC/builtinfunctions.d | 4 ++++ SMILEBASIC/project.d | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index e126e8d..90e215c 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -2375,6 +2375,10 @@ class BuiltinFunction array[cast(int)i] = Value(j); } } + static int CHKFILE(PetitComputer p, wstring file) + { + return p.project.chkfile(file); + } static void ACLS(PetitComputer p) { p.console.cls; diff --git a/SMILEBASIC/project.d b/SMILEBASIC/project.d index 2ff812d..01231a5 100644 --- a/SMILEBASIC/project.d +++ b/SMILEBASIC/project.d @@ -168,6 +168,36 @@ class Projects return true; } + wstring convertProjectName(wstring proj) + { + if (proj.empty) + { + return "[DEFAULT]";//TODO:current project!! + } + return proj; + } + + bool chkfile(wstring path) + { + auto file = parseFileName(path); + if (!Projects.isValidFileName(file.name)) + { + throw new IllegalFunctionCall("CHKFILE", 1); + } + if (!Projects.isValidProjectName(file.project)) + { + throw new IllegalFunctionCall("CHKFILE", 1); + } + if (file.resource == Resource.illegal) + { + throw new IllegalFunctionCall("CHKFILE", 1); + } + bool isText = file.resource == Resource.none || file.resource == Resource.program || file.resource == Resource.text; + auto proj = convertProjectName(file.project); + auto p = buildPath(projectPath, proj, isText ? "TXT"w : "DAT"w, file.name).to!string; + return p.exists; + } + static Resource getResource(wstring resname) { switch (std.uni.toUpper(resname)) @@ -181,7 +211,7 @@ class Projects case "TXT": return Resource.text; default: - assert(false); + return Resource.illegal; } } @@ -226,6 +256,7 @@ enum Resource graphic, data, text, + illegal, } struct FileName