aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/sway/config.c b/sway/config.c
index 6c8fe8c1..daaedeed 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -230,19 +230,17 @@ bool read_config(FILE *file, bool is_active) {
230 char *line; 230 char *line;
231 while (!feof(file)) { 231 while (!feof(file)) {
232 line = read_line(file); 232 line = read_line(file);
233 line = strip_whitespace(line);
234 line = strip_comments(line); 233 line = strip_comments(line);
235 if (line[0] == '\0') { 234 list_t *args = split_string(line, whitespace);
236 goto _continue; 235 if (!args->length) {
236 goto cleanup;
237 } 237 }
238 if (line[0] == '}') { 238 //TODO make this better, it only handles modes right now, and very
239 //simply at that
240 if (strncmp(args->items[0], "}", 1) == 0) {
239 config->current_mode = default_mode; 241 config->current_mode = default_mode;
240 goto _continue; 242 goto cleanup;
241 } 243 }
242
243 // Any command which would require wlc to be initialized
244 // should be queued for later execution
245 list_t *args = split_string(line, whitespace);
246 struct cmd_handler *handler; 244 struct cmd_handler *handler;
247 if ((handler = find_handler(args->items[0]))) { 245 if ((handler = find_handler(args->items[0]))) {
248 if (handler->config_type == CMD_KEYBIND) { 246 if (handler->config_type == CMD_KEYBIND) {
@@ -259,9 +257,8 @@ bool read_config(FILE *file, bool is_active) {
259 } else { 257 } else {
260 sway_log(L_ERROR, "Invalid command ``%s''", line); 258 sway_log(L_ERROR, "Invalid command ``%s''", line);
261 } 259 }
260 cleanup:
262 free_flat_list(args); 261 free_flat_list(args);
263
264_continue:
265 free(line); 262 free(line);
266 } 263 }
267 264
@@ -277,27 +274,33 @@ _continue:
277} 274}
278 275
279char *do_var_replacement(char *str) { 276char *do_var_replacement(char *str) {
280 // TODO: Handle escaping $ and using $ in string literals
281 int i; 277 int i;
282 for (i = 0; str[i]; ++i) { 278 char *find = str;
283 if (str[i] == '$') { 279 while ((find = strchr(find, '$'))) {
284 // Try for match (note: this could be faster) 280 // Skip if escaped.
285 int j; 281 if (find > str + 1 && find[-1] == '\\') {
286 for (j = 0; j < config->symbols->length; ++j) { 282 if (!(find > str + 2 && find[-2] == '\\')) {
287 struct sway_variable *var = config->symbols->items[j]; 283 continue;
288 if (strstr(str + i, var->name) == str + i) { 284 }
289 // Match, do replacement 285 }
290 char *new_string = malloc( 286 // Find matching variable
291 strlen(str) - 287 for (i = 0; i < config->symbols->length; ++i) {
292 strlen(var->name) + 288 struct sway_variable *var = config->symbols->items[i];
293 strlen(var->value) + 1); 289 int vnlen = strlen(var->name);
294 strncpy(new_string, str, i); 290 if (strncmp(find, var->name, vnlen) == 0) {
295 new_string[i] = 0; 291 int vvlen = strlen(var->value);
296 strcat(new_string, var->value); 292 char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
297 strcat(new_string, str + i + strlen(var->name)); 293 char *newptr = newstr;
298 free(str); 294 int offset = find - str;
299 str = new_string; 295 strncpy(newptr, str, offset);
300 } 296 newptr += offset;
297 strncpy(newptr, var->value, vvlen);
298 newptr += vvlen;
299 strcpy(newptr, find + vnlen);
300 free(str);
301 str = newstr;
302 find = str + offset + vvlen;
303 break;
301 } 304 }
302 } 305 }
303 } 306 }