summaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorAbhinav <abhinav.prsai@gmail.com>2025-06-06 23:41:37 +0100
committerAbhinav <abhinav.prsai@gmail.com>2025-06-06 23:41:37 +0100
commitb0bf3e6250b767f2786f340b577df5f445f9d6aa (patch)
tree6acc7e511c4983fb8e4ad72b08d9c3b57e081f69 /src/parser.c
parentb5c4d85ba3e716387fc83c87e8026faddd32f733 (diff)
clean up exec command
sxwm.c: before, some of the parsing logic of the exec command was located in setup, but i have relocated it to a seperate function called startup_exec. i have also replaced the manual spawning of windows with the spawn function parser.c: added the missing parsing logic of exec and simplified it
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/parser.c b/src/parser.c
index 6b3185a..d6d35c2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -378,38 +378,31 @@ found:
}
}
else if (!strcmp(key, "exec")) {
- char *comment = strchr(rest, '#');
- size_t len = comment ? (size_t)(comment - rest) : strlen(rest);
- char win[len + 1];
- strncpy(win, rest, len);
- win[len] = '\0';
-
- char *final = strip(win);
- char *cmd = strip(final);
- if (*cmd == '"') {
- cmd++;
- }
- else {
- fprintf(stderr, "sxwmrc:%d: exec not enclosed in quotes", lineno);
+ if (torun >= 256) {
+ fprintf(stderr, "sxwmrc:%d: too many exec commands\n", lineno);
+ continue;
}
- char *end = cmd + strlen(cmd) - 1;
- if (*end == '"') {
- *end = '\0';
- }
- else {
- fprintf(stderr, "sxwmrc:%d: exec not enclosed in quotes", lineno);
+ char *comment = strchr(rest, '#');
+ if (comment) {
+ *comment = '\0';
}
- printf("DEBUG: exec command '%s'\n", cmd);
- cfg->torun[torun] = strdup(cmd);
+ char *cmd = strip(rest);
+ cmd = strip_quotes(cmd);
- if (torun > 254) {
- fprintf(stderr, "sxwmrc:%d: too many execs", lineno);
+ if (!*cmd) {
+ fprintf(stderr, "sxwmrc:%d: empty exec command\n", lineno);
+ continue;
}
- else {
- torun++;
+
+ cfg->torun[torun] = strdup(cmd);
+ if (!cfg->torun[torun]) {
+ fprintf(stderr, "sxwmrc:%d: failed to allocate memory for exec command\n", lineno);
+ continue;
}
+
+ torun++;
}
else {
fprintf(stderr, "sxwmrc:%d: unknown option '%s'\n", lineno, key);