ref: 116a08245af2ba33ddb84ece7f4e4f0b46262266
parent: df4a8f8abb21c4d88a06c140e57da14a240e42cb
author: cancel <cancel@cancel.fm>
date: Wed Jan 15 13:22:39 EST 2020
Cleanup
--- a/sysmisc.c
+++ b/sysmisc.c
@@ -390,12 +390,11 @@
Confwflag_add_newline = 1 << 0,
};
-void ezconf_write_start(Ezconf_write *ezcw, Confopt_w *opts, size_t optscount) {
- for (size_t i = 0; i < optscount; i++)
- opts[i].written = 0;
+void ezconf_write_start(Ezconf_write *ezcw, Confopt_w *optsbuffer,
+ size_t buffercap) {
*ezcw = (Ezconf_write){0};
- ezcw->opts = opts;
- ezcw->optscount = optscount;
+ ezcw->opts = optsbuffer;
+ ezcw->optscap = buffercap;
Ezconf_write_error error = Ezconf_write_unknown_error;
switch (conf_save_start(&ezcw->save)) {
case Conf_save_start_ok:
@@ -426,7 +425,13 @@
}
ezcw->error = error;
}
-
+void ezconf_write_addopt(Ezconf_write *ezcw, char const *key, intptr_t id) {
+ size_t count = ezcw->optscount, cap = ezcw->optscap;
+ if (count == cap)
+ return;
+ ezcw->opts[count] = (Confopt_w){.name = key, .id = id, .written = 0};
+ ezcw->optscount = count + 1;
+}
bool ezconf_write_step(Ezconf_write *ezcw) {
U32 stateflags = ezcw->stateflags;
FILE *origfile = ezcw->save.origfile, *tempfile = ezcw->save.tempfile;
--- a/sysmisc.h
+++ b/sysmisc.h
@@ -117,7 +117,7 @@
typedef struct {
Conf_save save;
Confopt_w *opts;
- size_t optscount;
+ size_t optscount, optscap;
intptr_t optid;
FILE *file;
Ezconf_write_error error;
@@ -124,5 +124,7 @@
U32 stateflags;
} Ezconf_write;
-void ezconf_write_start(Ezconf_write *ezcw, Confopt_w *opts, size_t optscount);
+void ezconf_write_start(Ezconf_write *ezcw, Confopt_w *optsbuffer,
+ size_t buffercap);
+void ezconf_write_addopt(Ezconf_write *ezcw, char const *key, intptr_t id);
bool ezconf_write_step(Ezconf_write *ezcw);
--- a/tui_main.c
+++ b/tui_main.c
@@ -2398,8 +2398,9 @@
void save_prefs_with_error_message(Midi_mode const *midi_mode, int softmargin_y,
int softmargin_x,
bool softmargins_touched_by_user) {
- Confopt_w wopts[Confoptslen];
- Usz i = 0;
+ Confopt_w optsbuff[Confoptslen];
+ Ezconf_write ez;
+ ezconf_write_start(&ez, optsbuff, ORCA_ARRAY_COUNTOF(optsbuff));
oso *midi_output_device_name = NULL;
switch (midi_mode->any.type) {
case Midi_mode_type_null:
@@ -2416,19 +2417,14 @@
osowipe(&midi_output_device_name);
break;
}
- wopts[i].name = confopts[Confopt_portmidi_output_device];
- wopts[i].id = Confopt_portmidi_output_device;
- i++;
+ ezconf_write_addopt(&ez, confopts[Confopt_portmidi_output_device],
+ Confopt_portmidi_output_device);
} break;
#endif
}
if (softmargins_touched_by_user) {
- wopts[i].name = confopts[Confopt_margins];
- wopts[i].id = Confopt_margins;
- i++;
+ ezconf_write_addopt(&ez, confopts[Confopt_margins], Confopt_margins);
}
- Ezconf_write ez;
- ezconf_write_start(&ez, wopts, i);
while (ezconf_write_step(&ez)) {
switch (ez.optid) {
#ifdef FEAT_PORTMIDI