diff options
| author | werdl <werdl_is_cool@outlook.com> | 2025-05-19 19:08:30 +0100 |
|---|---|---|
| committer | werdl <werdl_is_cool@outlook.com> | 2025-05-19 19:08:30 +0100 |
| commit | 176380fd65d0233ea6a5608bfb24d437deccbb0b (patch) | |
| tree | 82c6514b95d5c113788168e9fb1d4f0ead3e005f /src/parser.c | |
| parent | fcd92be19f262aa309fd39a8ad3d57c1e4dc3765 (diff) | |
add multiple should_float options
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/parser.c b/src/parser.c index e5f7944..6ee0d6e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -236,32 +236,46 @@ found: } char *win = strip(rest); - - int count = 0; - for (char *p = win; *p; p++) { - if (*p == ',') { - count++; - } - } - cfg->should_float[should_floatn] = malloc((count + 2) * sizeof(char *)); - - // split by commas - char *comma = strtok(win, ","); + cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); - int i = 0; + char *comma_ptr, *space_ptr; + char *comma = strtok_r(win, ",", &comma_ptr); while (comma) { if (should_floatn < 256) { - cfg->should_float[should_floatn][i] = strdup(comma); - i++; + // if comma starts and ends with quotes, remove them + if (*comma == '"') { + comma++; + } + char *end = comma + strlen(comma) - 1; + if (*end == '"') { + *end = '\0'; + } + + printf("comma: %s\n", comma); + char *argv = strtok_r(comma, " ", &space_ptr); + int i = 0; + + + while (argv) { + printf("argv: %s\n", argv); + cfg->should_float[should_floatn][i] = strdup(argv); + argv = strtok_r(NULL, " ", &space_ptr); + i++; + } + + should_floatn++; + cfg->should_float[should_floatn] = malloc(256 * sizeof(char *)); + } else { fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno); break; } - comma = strtok(NULL, ","); + comma = strtok_r(NULL, ",", &comma_ptr); } + should_floatn++; } else if (!strcmp(key, "call") || !strcmp(key, "bind")) { @@ -345,6 +359,15 @@ found: } } + // print should_float + for (int i = 0; i < should_floatn; i++) { + fprintf(stderr, "sxwmrc: should_float[%d]: ", i); + for (int j = 0; cfg->should_float[i][j]; j++) { + fprintf(stderr, "%s ", cfg->should_float[i][j]); + } + fprintf(stderr, "\n"); + } + fclose(f); remap_and_dedupe_binds(cfg); return 0; |
