فهرست منبع

support load module_list.txt to voerride default one

Lyon 2 سال پیش
والد
کامیت
98f052e5b5

+ 1 - 1
port/linux/package/pikascript/main.py

@@ -4,7 +4,7 @@ import random, re, modbus, socket, unittest, binascii, ctypes, requests, mqtt
 import pika_lua, pika_cjson, cjson_test
 import GTestTask, TempDevTest
 import cb_test
-import configparser, network, math, struct
+import configparser, network
 import test_module1, test_cmodule, test_module4, import_test, testcase
 import test_module5
 import hashlib, hmac, aes, base64, time, os, zlib

+ 4 - 0
port/linux/package/pikascript/module_list.txt

@@ -0,0 +1,4 @@
+main
+json
+math
+struct

+ 12 - 3
src/PikaCompiler.c

@@ -1095,9 +1095,17 @@ PIKA_RES pikaMaker_compileModuleWithList(PikaMaker* self, char* list_content) {
     char* module_name = NULL;
     char* module_name_start = list_content;
     char* module_name_end = NULL;
-    pika_platform_printf("=====module list=====\r\n");
-    pika_platform_printf("%s", list_content);
-    pika_platform_printf("====================\r\n");
+    pika_platform_printf("  <module list>\n");
+    while (1) {
+        module_name_end = strFind(module_name_start, '\n');
+        if (NULL == module_name_end) {
+            break;
+        }
+        module_name = strsSubStr(&buffs, module_name_start, module_name_end);
+        pika_platform_printf("  - %s\r\n", module_name);
+        module_name_start = module_name_end + 1;
+    }
+    module_name_start = list_content;
     while (1) {
         module_name_end = strFind(module_name_start, '\n');
         if (NULL == module_name_end) {
@@ -1132,6 +1140,7 @@ PIKA_RES pikaMaker_compileModuleWithListFile(PikaMaker* self,
         goto __exit;
     }
     char* list_file_content = (char*)arg_getBytes(list_file_arg);
+    list_file_content = strsFilePreProcess_ex(&buffs, list_file_content, "\n");
     res = pikaMaker_compileModuleWithList(self, list_file_content);
     goto __exit;
 __exit:

+ 1 - 1
src/PikaVersion.h

@@ -2,4 +2,4 @@
 #define PIKA_VERSION_MINOR 12
 #define PIKA_VERSION_MICRO 6
 
-#define PIKA_EDIT_TIME "2023/10/03 03:00:00"
+#define PIKA_EDIT_TIME "2023/10/03 12:47:49"

+ 6 - 2
src/dataStrs.c

@@ -287,19 +287,23 @@ char* strsTransfer(Args* buffs, char* str, size_t* iout_p) {
     return transfered_str;
 }
 
-char* strsFilePreProcess(Args* outbuffs, char* lines) {
+char* strsFilePreProcess_ex(Args* outbuffs, char* lines, char* endwith) {
     Args buffs = {0};
     /* replace the "\r\n" to "\n" */
     lines = strsReplace(&buffs, lines, "\r\n", "\n");
     /* clear the void line */
     lines = strsReplace(&buffs, lines, "\n\n", "\n");
     /* add '\n' at the end */
-    lines = strsAppend(&buffs, lines, "\n\n");
+    lines = strsAppend(&buffs, lines, endwith);
     char* result = strsCopy(outbuffs, lines);
     strsDeinit(&buffs);
     return result;
 }
 
+char* strsFilePreProcess(Args* outbuffs, char* lines) {
+    return strsFilePreProcess_ex(outbuffs, lines, "\n\n");
+}
+
 char* strsSubStr(Args* buffs_p, char* name_start, char* name_end) {
     int32_t size = name_end - name_start;
     char* buff = args_getBuff(buffs_p, size + 1);

+ 1 - 0
src/dataStrs.h

@@ -55,6 +55,7 @@ char* strsPathJoin(Args* buffs_p, char* input1, char* input2);
 char* strsPathFormat(Args* buffs_p, char* input);
 char* strsTransfer(Args* buffs, char* str, size_t* iout_p);
 char* strsFilePreProcess(Args* outbuffs, char* lines);
+char* strsFilePreProcess_ex(Args* outbuffs, char* lines, char* endwith);
 char* strsSubStr(Args* buffs_p, char* name_start, char* name_end);
 
 #endif

+ 18 - 1
tools/pikaByteCodeGen/main.c

@@ -67,6 +67,19 @@ static int handle_breakpoint_option(int argc, char **argv, int i) {
   return -1;
 }
 
+int isFileExists(const char *filename) {
+  FILE *file = fopen(filename, "r");
+
+  if (file == NULL) {
+    // Failed to open the file, it may not exist or other error occurred
+    return 0; // File does not exist or error
+  }
+
+  // File successfully opened, close it and return true
+  fclose(file);
+  return 1; // File exists
+}
+
 static int _do_main(int argc, char **argv) {
   int parc = argc - 1;
   PikaMaker *maker = New_PikaMaker();
@@ -110,7 +123,11 @@ static int _do_main(int argc, char **argv) {
     /* no input, default to main.py */
     /* run pika_binder to bind C modules */
     pika_binder();
-    pikaMaker_compileModuleWithListFile(maker, "module_list_default.txt");
+    if (isFileExists("module_list.txt")) {
+      pikaMaker_compileModuleWithListFile(maker, "../module_list.txt");
+    } else {
+      pikaMaker_compileModuleWithListFile(maker, "module_list_default.txt");
+    }
     PIKA_RES res = pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
     pikaMaker_deinit(maker);
     return res;

BIN
tools/pikaCompiler/rust-msc-latest-win10.exe