summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-10-17 10:18:25 -0400
committerpommicket <pommicket@gmail.com>2023-10-17 10:18:25 -0400
commit9842cb988343d255db17ed57d486ecc41fc0618e (patch)
treee228c5319c9b1f00f574c8ce505883411f3e4de6
parent13c10a7002fd25efc22d3f07f25f9bf693f83e89 (diff)
switch from ted->strings to cfg->strings
-rw-r--r--config.c24
-rw-r--r--ide-rename-symbol.c2
-rw-r--r--main.c1
-rw-r--r--ted-internal.h7
4 files changed, 12 insertions, 22 deletions
diff --git a/config.c b/config.c
index 34e37b9..811fcc9 100644
--- a/config.c
+++ b/config.c
@@ -267,6 +267,10 @@ void settings_free(Settings *settings) {
}
static void config_free(Config *cfg) {
+ arr_foreach_ptr(cfg->strings, char *, pstr) {
+ free(*pstr);
+ }
+ arr_free(cfg->strings);
settings_free(&cfg->settings);
free(cfg->path);
memset(cfg, 0, sizeof *cfg);
@@ -464,7 +468,7 @@ static void get_config_path(Ted *ted, char *expanded, size_t expanded_sz, const
}
// only reads fp for multi-line strings
-static char *config_read_string(Ted *ted, ConfigReader *reader, const char *first_line, FILE *fp) {
+static char *config_read_string(ConfigReader *reader, Config *cfg, const char *first_line, FILE *fp) {
const char *p;
char line_buf[1024];
u32 start_line = reader->line_number;
@@ -520,12 +524,9 @@ static char *config_read_string(Ted *ted, ConfigReader *reader, const char *firs
arr_add(str, *p);
}
- char *s = NULL;
- if (ted->nstrings < TED_MAX_STRINGS) {
- s = strn_dup(str, arr_len(str));
- ted->strings[ted->nstrings++] = s;
- }
- arr_clear(str);
+ char *s = strn_dup(str, arr_len(str));
+ arr_add(cfg->strings, s);
+ arr_free(str);
return s;
}
@@ -669,7 +670,7 @@ static void config_parse_line(ConfigReader *reader, Config *cfg, char *line, FIL
value = endp;
} else if (*value == '"' || *value == '`') {
// string argument
- argument.string = config_read_string(ted, reader, value, fp);
+ argument.string = config_read_string(reader, cfg, value, fp);
}
while (isspace(*value)) ++value; // skip past space following argument
if (*value == ':') {
@@ -756,7 +757,7 @@ static void config_parse_line(ConfigReader *reader, Config *cfg, char *line, FIL
}
if (value[0] == '"' || value[0] == '`') {
- char *string = config_read_string(ted, reader, value, fp);
+ char *string = config_read_string(reader, cfg, value, fp);
if (string)
value = string;
}
@@ -1020,11 +1021,6 @@ void config_free_all(Ted *ted) {
config_free(cfg);
}
arr_clear(ted->all_configs);
- for (u32 i = 0; i < ted->nstrings; ++i) {
- free(ted->strings[i]);
- ted->strings[i] = NULL;
- }
- ted->nstrings = 0;
settings_free(&ted->default_settings);
}
diff --git a/ide-rename-symbol.c b/ide-rename-symbol.c
index 53a6467..e5e30fb 100644
--- a/ide-rename-symbol.c
+++ b/ide-rename-symbol.c
@@ -128,7 +128,7 @@ void rename_symbol_process_lsp_response(Ted *ted, const LSPResponse *response) {
arr_foreach_ptr(data->changes, const LSPWorkspaceChange, change) {
if (change->type == LSP_CHANGE_DELETE && change->data.delete.recursive) {
- ted_error(ted, "refusing to perform rename because it involves a recurisve deletion\n"
+ ted_error(ted, "refusing to perform rename because it involves a recursive deletion\n"
"I'm too scared to go through with this");
goto cleanup;
}
diff --git a/main.c b/main.c
index a972f66..c9348b8 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
/*
TODO:
-- get rid of ted->strings; do cfg->strings instead.
- switch back to starting file after rename
- .editorconfig? see https://editorconfig.org/
FUTURE FEATURES:
diff --git a/ted-internal.h b/ted-internal.h
index 066c38c..6fa49ae 100644
--- a/ted-internal.h
+++ b/ted-internal.h
@@ -155,6 +155,7 @@ struct Settings {
typedef struct {
Language language;
char *path;
+ char **strings;
Settings settings;
bool settings_set[sizeof (Settings)];
} Config;
@@ -167,8 +168,6 @@ typedef struct EditNotifyInfo {
/// max tabs per node
#define TED_MAX_TABS 100
-/// max strings in all config files
-#define TED_MAX_STRINGS 1000
/// "find" menu result
typedef struct FindResult FindResult;
@@ -400,10 +399,6 @@ struct Ted {
/// `nodes[0]` is always the "root node", if any buffers are open.
Node **nodes;
TextBuffer **buffers;
- /// number of config file strings
- u32 nstrings;
- /// config file strings
- char *strings[TED_MAX_STRINGS];
char window_title[256];
/// little box used to display errors and info.