Pārlūkot izejas kodu

feat: 加入了文件检查

SongZihuan 4 gadi atpakaļ
vecāks
revīzija
4e2c5a4bf8
8 mainītis faili ar 28 papildinājumiem un 5 dzēšanām
  1. 2 1
      CMakeLists.txt
  2. 14 0
      file/file.c
  3. 1 0
      include/__virtualmath.h
  4. 6 0
      include/file.h
  5. 2 0
      main.c
  6. 2 3
      src/inter.c
  7. 1 1
      src/runfile.c
  8. 0 0
      src/runoperation.c

+ 2 - 1
CMakeLists.txt

@@ -9,8 +9,9 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/include)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/memory MEM_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/memory MEM_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/parser PASER_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/parser PASER_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/src SRC_LIST)
 AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/src SRC_LIST)
+AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/file FILE_LIST)
 
 
 MESSAGE("project dir is ${PROJECT_SOURCE_DIR}")
 MESSAGE("project dir is ${PROJECT_SOURCE_DIR}")
-ADD_LIBRARY(VirtualMathCore STATIC ${SRC_LIST} ${PASER_LIST} ${MEM_LIST})
+ADD_LIBRARY(VirtualMathCore STATIC ${SRC_LIST} ${PASER_LIST} ${MEM_LIST} ${FILE_LIST})
 ADD_EXECUTABLE(VirtualMath main.c)
 ADD_EXECUTABLE(VirtualMath main.c)
 TARGET_LINK_LIBRARIES(VirtualMath VirtualMathCore)
 TARGET_LINK_LIBRARIES(VirtualMath VirtualMathCore)

+ 14 - 0
file/file.c

@@ -0,0 +1,14 @@
+#include "__virtualmath.h"
+
+int checkFile(char *dir){
+    struct stat my_stat;
+    int status = stat(dir, &my_stat);
+    if (status != 0)
+        return 0;
+    else if (S_ISREG(my_stat.st_mode))
+        return 1;
+    else if (S_ISDIR(my_stat.st_mode))
+        return 2;
+    else
+        return 3;
+}

+ 1 - 0
include/__virtualmath.h

@@ -15,5 +15,6 @@
 #include "grammar.h"
 #include "grammar.h"
 #include "log.h"
 #include "log.h"
 #include "arguement.h"
 #include "arguement.h"
+#include "file.h"
 
 
 #endif //VIRTUALMATH___VIRTUALMATH_H
 #endif //VIRTUALMATH___VIRTUALMATH_H

+ 6 - 0
include/file.h

@@ -0,0 +1,6 @@
+#ifndef VIRTUALMATH_FILE_H
+#define VIRTUALMATH_FILE_H
+
+int checkFile(char *dir);
+
+#endif //VIRTUALMATH_FILE_H

+ 2 - 0
main.c

@@ -20,4 +20,6 @@ int main(int argc, char *argv[]) {
  * TODO-szh import语句
  * TODO-szh import语句
  * TODO-szh 检查文件是否为目录和目录是否为目录
  * TODO-szh 检查文件是否为目录和目录是否为目录
  * TODO-szh 生成语法树
  * TODO-szh 生成语法树
+ * TODO-szh 取反符号 -
+ * TODO-szh 字面量后缀
  */
  */

+ 2 - 3
src/inter.c

@@ -10,12 +10,12 @@ Inter *newInter(char *code_file, char *debug_dir, Result *global_result, int *st
     ParserMessage *pm = NULL;
     ParserMessage *pm = NULL;
     *status = 0;
     *status = 0;
 
 
-    if (access(code_file, R_OK) != 0){
+    if (checkFile(code_file) != 1){
         *status = 1;
         *status = 1;
         return NULL;
         return NULL;
     }
     }
 
 
-    if (access(debug_dir, R_OK) != 0)
+    if (checkFile(debug_dir) != 1)
         debug_dir = NULL;
         debug_dir = NULL;
 
 
     global_inter = makeInter(code_file, debug_dir);
     global_inter = makeInter(code_file, debug_dir);
@@ -23,7 +23,6 @@ Inter *newInter(char *code_file, char *debug_dir, Result *global_result, int *st
 
 
     parserCommandList(pm, global_inter, true, global_inter->statement);
     parserCommandList(pm, global_inter, true, global_inter->statement);
     if (pm->status != success){
     if (pm->status != success){
-        writeLog(pm->paser_debug, ERROR, "Syntax Error: %s\n", pm->status_message);
         writeLog(stderr, ERROR, "Syntax Error: %s\n", pm->status_message);
         writeLog(stderr, ERROR, "Syntax Error: %s\n", pm->status_message);
         goto return_;
         goto return_;
     }
     }

+ 1 - 1
src/runfile.c

@@ -16,7 +16,7 @@ Result includeFile(INTER_FUNCTIONSIG) {
     }
     }
 
 
     file_dir = file.value->value->data.str.str;
     file_dir = file.value->value->data.str.str;
-    if (access(file_dir, R_OK) != 0){
+    if (checkFile(file_dir)){
         setResultError(&result, inter, "IncludeFileException", "File is not readable", st, true);
         setResultError(&result, inter, "IncludeFileException", "File is not readable", st, true);
         goto return_;
         goto return_;
     }
     }

+ 0 - 0
src/operation.c → src/runoperation.c