diff options
author | Drew DeVault <[email protected]> | 2015-08-05 22:40:38 -0400 |
---|---|---|
committer | Drew DeVault <[email protected]> | 2015-08-05 22:40:38 -0400 |
commit | 5767dcc86e23ba86e07dde6807b1af3deb3fdcbf (patch) | |
tree | 25aef735d3ed29e87e78d44d9979916762114edf /sway/config.c | |
parent | d0f1fb71d11a709c55b0ed56a9f35920c1282ec8 (diff) |
Mostly implement bindsym command
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sway/config.c b/sway/config.c index 7242be8d..e98246ff 100644 --- a/sway/config.c +++ b/sway/config.c @@ -50,3 +50,31 @@ _continue: return config; } + +char *do_var_replacement(struct sway_config *config, char *str) { + // TODO: Handle escaping $ and using $ in string literals + int i; + for (i = 0; str[i]; ++i) { + if (str[i] == '$') { + // Try for match (note: this could be faster) + int j; + for (j = 0; j < config->symbols->length; ++j) { + struct sway_variable *var = config->symbols->items[j]; + if (strstr(str + i, var->name) == str + i) { + // Match, do replacement + char *new_string = malloc( + strlen(str) - + strlen(var->name) + + strlen(var->value) + 1); + strncpy(new_string, str, i); + new_string[i] = 0; + strcat(new_string, var->value); + strcat(new_string, str + i + strlen(var->name)); + free(str); + str = new_string; + } + } + } + } + return str; +} |