summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-01 15:19:47 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-01 15:19:47 -0500
commitb376a87775d10dc7a693c0e1ecbe59e867e4634a (patch)
tree492abc20a91ae41bd089410b7082dc9cea88628a /config.c
parentfe4d14a5bb135a925bb47fe88b1a78df0d03cd49 (diff)
different syntax highlighting depending on the file extension
Diffstat (limited to 'config.c')
-rw-r--r--config.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/config.c b/config.c
index 2ebc094..bf3b284 100644
--- a/config.c
+++ b/config.c
@@ -11,7 +11,8 @@ typedef enum {
SECTION_NONE,
SECTION_CORE,
SECTION_KEYBOARD,
- SECTION_COLORS
+ SECTION_COLORS,
+ SECTION_EXTENSIONS
} Section;
// all worth it for the -Wformat warnings
@@ -227,6 +228,8 @@ void config_read(Ted *ted, char const *filename) {
section = SECTION_COLORS;
} else if (streq(section_name, "core")) {
section = SECTION_CORE;
+ } else if (streq(section_name, "extensions")) {
+ section = SECTION_EXTENSIONS;
} else {
config_err(cfg, "Unrecognized section: [%s].", section_name);
}
@@ -294,6 +297,25 @@ void config_read(Ted *ted, char const *filename) {
config_err(cfg, "Expected ':' for key action. This line should look something like: %s = :command.", key);
}
} break;
+ case SECTION_EXTENSIONS: {
+ Language lang = language_from_str(key);
+ if (lang == LANG_NONE) {
+ config_err(cfg, "Invalid programming language: %s.", key);
+ } else {
+ char *new_str = malloc(strlen(value) + 1);
+ if (!new_str) {
+ config_err(cfg, "Out of memory.");
+ } else {
+ char *dst = new_str;
+ // get rid of whitespace in extension list
+ for (char const *src = value; *src; ++src)
+ if (!isspace(*src))
+ *dst++ = *src;
+ *dst = 0;
+ settings->language_extensions[lang] = new_str;
+ }
+ }
+ } break;
case SECTION_CORE: {
char const *endptr;
long long const integer = strtoll(value, (char **)&endptr, 10);
@@ -380,3 +402,10 @@ void config_read(Ted *ted, char const *filename) {
ted_seterr(ted, "Couldn't open file %s.", filename);
}
}
+
+static void settings_free(Settings *settings) {
+ for (u16 i = 0; i < LANG_COUNT; ++i) {
+ free(settings->language_extensions[i]);
+ settings->language_extensions[i] = NULL;
+ }
+}