about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-07-25 15:10:40 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-07-25 15:10:40 +0200
commita8784eff9f40ca284cb03ae30a93287ea635ba91 (patch)
treec8fdf11d077d76c3a21dd7b5dd49f7baef987e02
parentb26ae5886ddc7d0d84595fb5b94878f50d488d42 (diff)
downloadbox64-a8784eff9f40ca284cb03ae30a93287ea635ba91.tar.gz
box64-a8784eff9f40ca284cb03ae30a93287ea635ba91.zip
[RCFILE] Added support for generic names in RCFiles
-rw-r--r--docs/USAGE.md2
-rw-r--r--src/include/khash.h15
-rw-r--r--src/tools/rcfile.c58
-rw-r--r--system/box64.box64rc13
4 files changed, 69 insertions, 19 deletions
diff --git a/docs/USAGE.md b/docs/USAGE.md
index 50df5539..69c78dc1 100644
--- a/docs/USAGE.md
+++ b/docs/USAGE.md
@@ -7,6 +7,8 @@ Env. var with * can also be put inside box64rc files.
 Box64 look for 2 places for rcfile: `/etc/box64.box64rc` and `~/.box64rc`

 The second takes precedence to the first, on an APP level 

 (that means if an [MYAPP] my appears in both file, only the settings in `~/.box64rc` will be applied)

+There is also some égeneric" name, like [*SETUP*] that will be applied to every program containg "setup" in the name

+(Note that this is not a full regex rules, it's just a name between '[*' and '*]', nothing else)

 

 #### BOX64_LOG *

 Controls the Verbosity level of the logs

diff --git a/src/include/khash.h b/src/include/khash.h
index 9d20a0e6..823757bf 100644
--- a/src/include/khash.h
+++ b/src/include/khash.h
@@ -556,6 +556,21 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
   @abstract     Iterate over the entries in the hash table
   @param  h     Pointer to the hash table [khash_t(name)*]
   @param  kvar  Variable to which key will be assigned
+  @param  vvar  Variable to which value will be assigned
+  @param  code  Block of code to execute
+ */
+#define kh_foreach_ref(h, kvar, rvar, code) { khint_t __i;	\
+	for (__i = kh_begin(h); __i != kh_end(h); ++__i) {		\
+		if (!kh_exist(h,__i)) continue;						\
+		(kvar) = kh_key(h,__i);								\
+		(rvar) = &kh_val(h,__i);							\
+		code;												\
+	} }
+
+/*! @function
+  @abstract     Iterate over the entries in the hash table
+  @param  h     Pointer to the hash table [khash_t(name)*]
+  @param  kvar  Variable to which key will be assigned
   @param  code  Block of code to execute
  */
 #define kh_foreach_key(h, kvar, code) { khint_t __i;           	\
diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c
index 7f3f6a18..b105fa65 100644
--- a/src/tools/rcfile.c
+++ b/src/tools/rcfile.c
@@ -282,6 +282,7 @@ SUPER()
 KHASH_MAP_INIT_STR(params, my_params_t)
 
 static kh_params_t *params = NULL;
+static kh_params_t *params_gen = NULL;
 
 static void clearParam(my_params_t* param)
 {
@@ -306,17 +307,18 @@ static void clearParam(my_params_t* param)
     #undef ENTRYULONG
 }
 
-static void addParam(const char* name, my_params_t* param)
+static void addParam(const char* name, my_params_t* param, int gen)
 {
     khint_t k;
-    k = kh_get(params, params, name);
-    if(k==kh_end(params)) {
+    kh_params_t* khp = gen?params_gen:params;
+    k = kh_get(params, khp, name);
+    if(k==kh_end(khp)) {
         int ret;
-        k = kh_put(params, params, box_strdup(name), &ret);
+        k = kh_put(params, khp, box_strdup(name), &ret);
     } else {
-        clearParam(&kh_value(params, k));
+        clearParam(&kh_value(khp, k));
     }
-    my_params_t *p = &kh_value(params, k);
+    my_params_t *p = &kh_value(khp, k);
     memcpy(p, param, sizeof(my_params_t));
 }
 
@@ -364,6 +366,8 @@ void LoadRCFile(const char* filename)
     // init the hash table if needed
     if(!params)
         params = kh_init(params);
+    if(!params_gen)
+        params_gen = kh_init(params);
     // prepare to parse the file
     char* line = NULL;
     size_t lsize = 0;
@@ -372,6 +376,7 @@ void LoadRCFile(const char* filename)
     int dummy;
     size_t len;
     char* p;
+    int decor = 1;
     // parsing
     while ((dummy = getline(&line, &lsize, f)) != -1) {
         // remove comments
@@ -383,12 +388,16 @@ void LoadRCFile(const char* filename)
         if(line[0]=='[' && strchr(line, ']')) {
             // new entry, will need to add current one
             if(current_name)
-                addParam(current_name, &current_param);
+                addParam(current_name, &current_param, (decor==2));
+            if(line[1]=='*' && line[(intptr_t)(strchr(line, ']')-line)-1]=='*')
+                decor = 2;
+            else
+                decor = 1;
             // prepare a new entry
             memset(&current_param, 0, sizeof(current_param));
             free(current_name);
-            current_name = LowerCase(line+1);
-            *strchr(current_name, ']') = '\0';
+            current_name = LowerCase(line+decor);
+            *(strchr(current_name, ']')+1-decor) = '\0';
             trimString(current_name);
         } else if(strchr(line, '=')) {
             // actual parameters
@@ -463,7 +472,7 @@ void LoadRCFile(const char* filename)
     }
     // last entry to be pushed too
     if(current_name) {
-        addParam(current_name, &current_param);
+        addParam(current_name, &current_param, (decor==2));
         free(current_name);
     }
     free(line);
@@ -507,28 +516,39 @@ const char* GetLastApplyName()
 {
     return old_name;
 }
+void internal_ApplyParams(const char* name, const my_params_t* param);
 void ApplyParams(const char* name)
 {
     if(!name || !params)
         return;
-    int new_cycle_log = cycle_log;
-    int new_maxcpu = box64_maxcpu;
-    int new_avx = box64_avx2?2:box64_avx;
-    int box64_dynarec_jvm = box64_jvm;
-    int new_reserve_high = 0;
     if(!strcmp(name, old_name)) {
         return;
     }
     strncpy(old_name, name, 255);
-    khint_t k;
+    khint_t k1;
     {
         char* lname = LowerCase(name);
-        k = kh_get(params, params, lname);
+        k1 = kh_get(params, params, lname);
+        my_params_t* param;
+        const char* k2;
+        kh_foreach_ref(params_gen, k2, param, 
+            if(strstr(lname, k2))
+                internal_ApplyParams(name, param);
+        )
         free(lname);
     }
-    if(k == kh_end(params))
+    if(k1 == kh_end(params))
         return;
-    my_params_t* param = &kh_value(params, k);
+    my_params_t* param = &kh_value(params, k1);
+    internal_ApplyParams(name, param);
+}
+
+void internal_ApplyParams(const char* name, const my_params_t* param) {
+    int new_cycle_log = cycle_log;
+    int new_maxcpu = box64_maxcpu;
+    int new_avx = box64_avx2?2:box64_avx;
+    int box64_dynarec_jvm = box64_jvm;
+    int new_reserve_high = 0;
     int want_exit = 0;
     #ifdef DYNAREC
     int olddynarec = box64_dynarec;
diff --git a/system/box64.box64rc b/system/box64.box64rc
index 19ffdbbb..ddf43bfc 100644
--- a/system/box64.box64rc
+++ b/system/box64.box64rc
@@ -3,6 +3,19 @@
 # Note that process name are case insensitive!
 
 #
+# Generic names
+#
+[*setup*]
+BOX64_DYNAREC_SAFEFLAGS=2
+BOX64_DYNAREC_BIGBLOCK=0
+BOX64_DYNAREC_CALLRET=0
+
+[*install*]
+BOX64_DYNAREC_SAFEFLAGS=2
+BOX64_DYNAREC_BIGBLOCK=0
+BOX64_DYNAREC_CALLRET=0
+
+#
 # Linux process
 # 
 [3dSen.x86_64]