From 4df856f3dcecd6520ea3cdbe0196ad1f1a5fc58f Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 20 Mar 2022 20:32:00 -0400 Subject: [PATCH 1/3] skip spaces at the start of lines in config files --- common/lib/config.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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; } } From 66e3c5ef5ca1aafa11ba07f6e69f90dd9152a032 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 20 Mar 2022 20:38:37 -0400 Subject: [PATCH 2/3] also do it on the first line --- common/lib/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/lib/config.c b/common/lib/config.c index 46397996..d3087ccc 100644 --- a/common/lib/config.c +++ b/common/lib/config.c @@ -151,7 +151,8 @@ int init_config(size_t config_size) { for (size_t i = 0; i < config_size; i++) { size_t skip = 0; while ((config_addr[i + skip] == '\r') - || (i && config_addr[i - 1] == '\n' && config_addr[i + skip] == ' ')) { + || ((!i || config_addr[i - 1] == '\n') + && config_addr[i + skip] == ' ')) { skip++; } if (skip) { From 1dd3885bb62b88f62d26b779216b57570b0084a8 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 20 Mar 2022 21:38:50 -0400 Subject: [PATCH 3/3] and for tabs --- common/lib/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/config.c b/common/lib/config.c index d3087ccc..10d1fcb8 100644 --- a/common/lib/config.c +++ b/common/lib/config.c @@ -152,7 +152,7 @@ int init_config(size_t config_size) { size_t skip = 0; while ((config_addr[i + skip] == '\r') || ((!i || config_addr[i - 1] == '\n') - && config_addr[i + skip] == ' ')) { + && (config_addr[i + skip] == ' ' || config_addr[i + skip] == '\t'))) { skip++; } if (skip) {