From a4a078bf43f95d45aa1aefb09a77e731d4b7ad91 Mon Sep 17 00:00:00 2001 From: rbccwstmctt Date: Fri, 7 Feb 2025 16:39:44 +0000 Subject: [PATCH] Config file ignores whitespace Config file loading now ignored whitespace placed either side of the equals. It doesn't ignore all whitespace, since whitespace may be desirable for some arguments (such as background image). --- main.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index c0d72264..af902e5d 100644 --- a/main.c +++ b/main.c @@ -1013,7 +1013,38 @@ static int load_config(char *path, struct swaylock_state *state, swaylock_log(LOG_ERROR, "Failed to allocate memory"); return 0; } - sprintf(flag, "--%s", line); + + sprintf(flag, "--"); + int search_state = 0; + int flag_index = 2; + for (int i = 0; i < nread; i++) { + + switch(search_state) { + case 0: + if (line[i] != ' ') { + flag[flag_index++] = line[i]; + } + if (line[i] == '=') { + search_state++; + } + break; + + case 1: + if (line[i] != ' ') { + flag[flag_index++] = line[i]; + search_state++; + } + break; + + case 2: + flag[flag_index++] = line[i]; + break; + + } + } + flag[flag_index] = '\0'; + + swaylock_log(LOG_DEBUG, "Read Flag: %s", flag); char *argv[] = {"swaylock", flag}; result = parse_options(2, argv, state, line_mode, NULL); free(flag);