:: commit 4df856f3dcecd6520ea3cdbe0196ad1f1a5fc58f

Benji Dial <benji3.141@gmail.com> — 2022-03-21 00:32

parents: 65b5a7f66f

skip spaces at the start of lines in config files

diff --git a/common/lib/config.c b/common/lib/config.c
index 65e30409..46397996 100644
--- a/common/lib/config.c
+++ b/common/lib/config.c
@@ -147,12 +147,17 @@ struct macro {
 static struct macro *macros = NULL;
 
 int init_config(size_t config_size) {
-    // remove windows carriage returns, if any
+    // remove windows carriage returns and spaces at the start of lines, if any
     for (size_t i = 0; i < config_size; i++) {
-        if (config_addr[i] == '\r') {
-            for (size_t j = i; j < config_size - 1; j++)
-                config_addr[j] = config_addr[j+1];
-            config_size--;
+        size_t skip = 0;
+        while ((config_addr[i + skip] == '\r')
+            || (i && config_addr[i - 1] == '\n' && config_addr[i + skip] == ' ')) {
+            skip++;
+        }
+        if (skip) {
+            for (size_t j = i; j < config_size - skip; j++)
+                config_addr[j] = config_addr[j + skip];
+            config_size -= skip;
         }
     }
 
tab: 248 wrap: offon