aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c4
-rw-r--r--sway/commands/bar.c4
-rw-r--r--sway/commands/bar/colors.c2
-rw-r--r--sway/commands/input.c4
-rw-r--r--sway/commands/mode.c4
-rw-r--r--sway/commands/seat.c4
-rw-r--r--sway/config.c19
7 files changed, 18 insertions, 23 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 825fda8f..3a86ae53 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -376,8 +376,8 @@ cleanup:
return results;
}
-struct cmd_results *subcommand(char **argv, int argc,
- struct cmd_handler *handlers, int handlers_size) {
+struct cmd_results *config_subcommand(char **argv, int argc,
+ struct cmd_handler *handlers, size_t handlers_size) {
char *command = join_args(argv, argc);
wlr_log(L_DEBUG, "Subcommand: %s", command);
free(command);
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index 358b3893..d84ce808 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -52,7 +52,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "bar",
"Can only be used in config file.");
}
- return subcommand(argv, argc, bar_config_handlers,
+ return config_subcommand(argv, argc, bar_config_handlers,
sizeof(bar_config_handlers));
}
@@ -111,5 +111,5 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
wlr_log(L_DEBUG, "Creating bar %s", bar->id);
}
- return subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
+ return config_subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
}
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
index 6d3c09b8..8c862ca9 100644
--- a/sway/commands/bar/colors.c
+++ b/sway/commands/bar/colors.c
@@ -52,7 +52,7 @@ static struct cmd_results *parse_three_colors(char ***colors,
}
struct cmd_results *bar_cmd_colors(int argc, char **argv) {
- return subcommand(argv, argc, bar_colors_handlers,
+ return config_subcommand(argv, argc, bar_colors_handlers,
sizeof(bar_colors_handlers));
}
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 972160e2..22a0bb7c 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -42,8 +42,8 @@ struct cmd_results *cmd_input(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
}
- struct cmd_results *res = subcommand(argv + 1, argc - 1, input_handlers,
- sizeof(input_handlers));
+ struct cmd_results *res = config_subcommand(argv + 1, argc - 1,
+ input_handlers, sizeof(input_handlers));
free_input_config(config->handler_context.input_config);
config->handler_context.input_config = NULL;
diff --git a/sway/commands/mode.c b/sway/commands/mode.c
index 31d0f251..00331ccc 100644
--- a/sway/commands/mode.c
+++ b/sway/commands/mode.c
@@ -65,8 +65,8 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
}
// Create binding
- struct cmd_results *result = subcommand(argv + 1, argc - 1, mode_handlers,
- sizeof(mode_handlers));
+ struct cmd_results *result = config_subcommand(argv + 1, argc - 1,
+ mode_handlers, sizeof(mode_handlers));
config->current_mode = config->modes->items[0];
return result;
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 6080bf64..5e3c0bd0 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -24,8 +24,8 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
"Couldn't allocate config");
}
- struct cmd_results *res = subcommand(argv + 1, argc - 1, seat_handlers,
- sizeof(seat_handlers));
+ struct cmd_results *res = config_subcommand(argv + 1, argc - 1,
+ seat_handlers, sizeof(seat_handlers));
free_seat_config(config->handler_context.seat_config);
config->handler_context.seat_config = NULL;
diff --git a/sway/config.c b/sway/config.c
index edb10bd7..88cc6843 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -518,21 +518,20 @@ static int detect_brace_on_following_line(FILE *file, char *line,
int lines = 0;
if (line[strlen(line) - 1] != '{' && line[strlen(line) - 1] != '}') {
char *peeked = NULL;
+ long position = 0;
do {
wlr_log(L_DEBUG, "Peeking line %d", line_number + lines + 1);
free(peeked);
- peeked = peek_line(file, lines);
+ peeked = peek_line(file, lines, &position);
if (peeked) {
peeked = strip_whitespace(peeked);
}
+ wlr_log(L_DEBUG, "Peeked line: `%s`", peeked);
lines++;
} while (peeked && strlen(peeked) == 0);
if (peeked && strlen(peeked) == 1 && peeked[0] == '{') {
- for (int i = 0; i < lines; i++) {
- free(peeked);
- peeked = read_line(file);
- }
+ fseek(file, position, SEEK_SET);
} else {
lines = 0;
}
@@ -541,7 +540,7 @@ static int detect_brace_on_following_line(FILE *file, char *line,
return lines;
}
-static char *expand_line(char *block, char *line, bool add_brace) {
+static char *expand_line(const char *block, const char *line, bool add_brace) {
int size = (block ? strlen(block) + 1 : 0) + strlen(line)
+ (add_brace ? 2 : 0) + 1;
char *expanded = calloc(1, size);
@@ -549,10 +548,8 @@ static char *expand_line(char *block, char *line, bool add_brace) {
wlr_log(L_ERROR, "Cannot allocate expanded line buffer");
return NULL;
}
- strcat(expanded, block ? block : "");
- strcat(expanded, block ? " " : "");
- strcat(expanded, line);
- strcat(expanded, add_brace ? " {" : "");
+ snprintf(expanded, size, "%s%s%s%s", block ? block : "",
+ block ? " " : "", line, add_brace ? " {" : "");
return expanded;
}
@@ -594,9 +591,7 @@ bool read_config(FILE *file, struct sway_config *config) {
// Special case
res = config_commands_command(expanded);
} else {
- wlr_log(L_DEBUG, "Entering c_c");
res = config_command(expanded);
- wlr_log(L_DEBUG, "Exiting c_c");
}
free(expanded);
switch(res->status) {