ソースを参照

feat: 添加了SEP和SEP_CH宏

SEP和SEP_CH宏中包含了当前系统下的目录分隔符
SEP是字符串,SEP_CH是字符
SongZihuan 4 年 前
コミット
f83baf45d3
4 ファイル変更18 行追加41 行削除
  1. 1 5
      src/virtualmath.c
  2. 4 14
      vmcore/file/file.c
  3. 8 2
      vmcore/include/__macro.h
  4. 5 20
      vmcore/src/runfile.c

+ 1 - 5
src/virtualmath.c

@@ -10,11 +10,7 @@ void runCodeFile(Inter *inter, char *file[]) {
         if ((status = checkFileReadble((*file))) == 3)
             continue;
         else if (status == 2) {
-#if __linux__
-            *file = memStrcat(*file, (*file)[memStrlen(*file) - 1] != '/' ? "/__main__.vm" : "__main__.vm", false, false);
-#else
-            *file = memStrcat(*file, ((*file)[memStrlen(*file) - 1] != '\\' ? "\\__main__.vm" : "__main__.vm"), false, false);
-#endif
+            *file = memStrcat(*file, ((*file)[memStrlen(*file) - 1] != SEP_CH ? SEP"__main__.vm" : "__main__.vm"), false, false);
             if (checkFileReadble(*file) != 1)
                 continue;
         }

+ 4 - 14
vmcore/file/file.c

@@ -25,21 +25,11 @@ char *splitDir(char * dir){
     char *point = NULL;
     char *return_char = NULL;
 
-#ifdef __unix__
-    if (dir[memStrlen(dir) - 1] == '/')
-#else
-    if (dir[memStrlen(dir) - 1] == '\\')  // TODO-szh 设置 sep
-#endif  // __unix__
-    { dir[memStrlen(dir) - 1] = NUL; }
+    if (dir[memStrlen(dir) - 1] == SEP_CH)
+        dir[memStrlen(dir) - 1] = NUL;
 
-    if (
-#ifdef __unix__
-    (slash = strrchr(dir, '/'))  == NULL
-#else
-    (slash = strchr(dir, '\\'))  == NULL
-#endif  // __unix__
-    )
-    { slash = dir; }
+    if ((slash = strrchr(dir, SEP_CH))  == NULL)
+        slash = dir;
     else
         slash ++;
 

+ 8 - 2
vmcore/include/__macro.h

@@ -27,6 +27,14 @@
 
 #define LINEFILE __LINE__, __FILE__
 
+#ifdef __linux__
+#define SEP "/"
+#define SEP_CH '/'
+#else
+#define SEP "\\"
+#define SEP_CH '\\'
+#endif
+
 #define MD5_SIZE (16)
 #define MD5_STR_LEN (MD5_SIZE * 2)
 #define MD5_STRING (MD5_STR_LEN + 1)
@@ -36,6 +44,4 @@ typedef long double vdou;
 typedef unsigned long long vhashn;
 typedef unsigned long long fline;
 
-//#define again___
-
 #endif //VIRTUALMATH___MACRO_H

+ 5 - 20
vmcore/src/runfile.c

@@ -35,15 +35,9 @@ static bool isExist(char **path, bool is_ab, char *file) {
         if (status == 2) {
             if (file == NULL)
                 return false;
-#if __linux__
-            if ((*path)[memStrlen(*path) - 1] != '/')
-                *path = memStrcat(*path, "/", true, false);
+            if ((*path)[memStrlen(*path) - 1] != SEP_CH)
+                *path = memStrcat(*path, SEP, true, false);
             *path = memStrcat(*path, file, true, false);
-#else
-            if ((*path)[memStrlen(*path) - 1] != '\\')
-                *path = memStrcat(*path, "\\", true, false);
-            *path = memStrcat(*path, file, true, false);
-#endif
             return isExist(path, false, NULL);
         } else
             return true;
@@ -74,11 +68,7 @@ int checkFileDir(char **file_dir, FUNC) {
         char arr_cwd[200];
         char *p_cwd = NULL;
         getcwd(arr_cwd, 200);
-#ifdef __linux__
-        p_cwd = memStrcatIter(arr_cwd, false, "/", *file_dir, NULL);
-#else
-        p_cwd = memStrcatIter(arr_cwd, false, "\\", *file_dir);
-#endif
+        p_cwd = memStrcatIter(arr_cwd, false, SEP, *file_dir);
         if (isExist(&p_cwd, false, "__init__.vm")) {
             memFree(*file_dir);
             *file_dir = p_cwd;
@@ -90,13 +80,8 @@ int checkFileDir(char **file_dir, FUNC) {
     path: {
     char *path = memStrcpy(getenv("VIRTUALMATHPATH"));
     for (char *tmp = strtok(path, ";"), *new_dir; tmp != NULL; tmp = strtok(NULL, ";")) {
-#ifdef __linux__
-        if (*(tmp + (memStrlen(tmp) - 1)) != '/')
-            new_dir = memStrcatIter(tmp, false, "/", *file_dir, NULL);
-#else
-            if (*(tmp + (memStrlen(tmp) - 1)) != '\\')
-                new_dir = memStrcatIter(tmp, false, "\\", *file_dir);
-#endif
+        if (*(tmp + (memStrlen(tmp) - 1)) != SEP_CH)
+            new_dir = memStrcatIter(tmp, false, SEP, *file_dir);
         else
             new_dir = memStrcat(tmp, *file_dir, false, false);