diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-04 10:40:32 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-04 10:40:32 -0500 |
commit | 1cbaa8c30f63b854696b9a0761376eda5ea87ecd (patch) | |
tree | c249b7ff2b5311f4d4d6b84ff403687df36cb63d /config.c | |
parent | c8fe98bf37f5364543b365d6d423a785c3c66452 (diff) |
string arguments
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -293,8 +293,35 @@ void config_read(Ted *ted, char const *filename) { char *endp; argument = strtoll(value, &endp, 10); value = endp; - while (isspace(*value)) ++value; // skip past space following number + } else if (*value == '"') { + // string argument + int backslashes = 0; + char const *p; + for (p = value + 1; *p; ++p) { + bool done = false; + switch (*p) { + case '\\': + ++backslashes; + break; + case '"': + if (backslashes % 2 == 0) + done = true; + break; + } + if (done) break; + } + if (!*p) { + config_err(cfg, "String doesn't end."); + break; + } + if (ted->nstrings < TED_MAX_STRINGS) { + char *str = strn_dup(value + 1, (size_t)(p - (value + 1))); + argument = ted->nstrings | ARG_STRING; + ted->strings[ted->nstrings++] = str; + } + value = p + 1; } + while (isspace(*value)) ++value; // skip past space following argument if (*value == ':') { // read the command Command command = command_from_str(value + 1); @@ -428,9 +455,13 @@ void config_read(Ted *ted, char const *filename) { } } -static void settings_free(Settings *settings) { +static void config_free(Ted *ted) { + Settings *settings = &ted->settings; for (u16 i = 0; i < LANG_COUNT; ++i) { free(settings->language_extensions[i]); settings->language_extensions[i] = NULL; } + for (u32 i = 0; i < ted->nstrings; ++i) { + free(ted->strings[i]); + } } |