ref: d7488790ab1621e9e01d4c28bf1fa2ef5ceffc46
parent: 27100081c8ccea41a64273cf7d821adab03ed9b3
author: cancel <cancel@cancel.fm>
date: Tue Jan 14 10:00:11 EST 2020
Move some prefs/conf save stuff out of tui_main to sysmisc
--- a/sysmisc.c
+++ b/sysmisc.c
@@ -307,3 +307,38 @@
conf_save_cancel(p);
return err;
}
+
+char const *prefs_save_error_string(Prefs_save_error error) {
+ switch (error) {
+ case Prefs_save_ok:
+ return "No error";
+ case Prefs_save_oom:
+ return "Out of memory";
+ case Prefs_save_no_home:
+ return "Unable to resolve $XDG_CONFIG_HOME or $HOME";
+ case Prefs_save_mkdir_failed:
+ return "Unable to create $XDG_CONFIG_HOME or $HOME/.config directory";
+ case Prefs_save_conf_dir_not_dir:
+ return "Config directory path is not a directory";
+ case Prefs_save_old_temp_file_stuck:
+ return "Unable to remove old orca.conf.tmp file";
+ case Prefs_save_temp_file_perm_denied:
+ return "Permission denied for config directory";
+ case Prefs_save_temp_open_failed:
+ return "Unable to open orca.conf.tmp for writing";
+ case Prefs_save_temp_fsync_failed:
+ return "fsync() reported an when writing temp file.\n"
+ "Refusing to continue.";
+ case Prefs_save_temp_close_failed:
+ return "Unable to close temp file";
+ case Prefs_save_rename_failed:
+ return "Unable to rename orca.conf.tmp to orca.conf";
+ case Prefs_save_line_too_long:
+ return "Line in file is too long";
+ case Prefs_save_existing_read_error:
+ return "Error when reading existing configuration file";
+ case Prefs_save_unknown_error:
+ break;
+ }
+ return "Unknown";
+}
--- a/sysmisc.h
+++ b/sysmisc.h
@@ -73,3 +73,22 @@
Conf_save_commit_error conf_save_commit(Conf_save *p);
// Finishes. Do not call this with a zeroed `*p`. Afterwards, `*p` will be
// zeroed.
+
+typedef enum {
+ Prefs_save_ok = 0,
+ Prefs_save_oom,
+ Prefs_save_no_home,
+ Prefs_save_mkdir_failed,
+ Prefs_save_conf_dir_not_dir,
+ Prefs_save_old_temp_file_stuck,
+ Prefs_save_temp_file_perm_denied,
+ Prefs_save_temp_open_failed,
+ Prefs_save_temp_fsync_failed,
+ Prefs_save_temp_close_failed,
+ Prefs_save_rename_failed,
+ Prefs_save_line_too_long,
+ Prefs_save_existing_read_error,
+ Prefs_save_unknown_error,
+} Prefs_save_error;
+
+char const* prefs_save_error_string(Prefs_save_error error);
--- a/tui_main.c
+++ b/tui_main.c
@@ -2417,23 +2417,6 @@
fputs("\n", file);
}
-typedef enum {
- Prefs_save_ok = 0,
- Prefs_save_oom,
- Prefs_save_no_home,
- Prefs_save_mkdir_failed,
- Prefs_save_conf_dir_not_dir,
- Prefs_save_old_temp_file_stuck,
- Prefs_save_temp_file_perm_denied,
- Prefs_save_temp_open_failed,
- Prefs_save_temp_fsync_failed,
- Prefs_save_temp_close_failed,
- Prefs_save_rename_failed,
- Prefs_save_line_too_long,
- Prefs_save_existing_read_error,
- Prefs_save_unknown_error,
-} Prefs_save_error;
-
Prefs_save_error save_prefs_to_disk(Midi_mode const *midi_mode,
int softmargin_y, int softmargin_x,
bool softmargins_touched_by_user) {
@@ -2578,52 +2561,11 @@
bool softmargins_touched_by_user) {
Prefs_save_error err = save_prefs_to_disk(
midi_mode, softmargin_y, softmargin_x, softmargins_touched_by_user);
- char const *msg = "Unknown";
- switch (err) {
- case Prefs_save_ok:
- return;
- case Prefs_save_oom:
- msg = "Out of memory";
- break;
- case Prefs_save_no_home:
- msg = "Unable to resolve $XDG_CONFIG_HOME or $HOME";
- break;
- case Prefs_save_mkdir_failed:
- msg = "Unable to create $XDG_CONFIG_HOME or $HOME/.config directory";
- break;
- case Prefs_save_conf_dir_not_dir:
- msg = "Config directory path is not a directory";
- break;
- case Prefs_save_old_temp_file_stuck:
- msg = "Unable to remove old orca.conf.tmp file";
- break;
- case Prefs_save_temp_file_perm_denied:
- msg = "Permission denied for config directory";
- break;
- case Prefs_save_temp_open_failed:
- msg = "Unable to open orca.conf.tmp for writing";
- break;
- case Prefs_save_temp_fsync_failed:
- msg = "fsync() reported an when writing temp file.\n"
- "Refusing to continue.";
- break;
- case Prefs_save_temp_close_failed:
- msg = "Unable to close temp file";
- break;
- case Prefs_save_rename_failed:
- msg = "Unable to rename orca.conf.tmp to orca.conf";
- break;
- case Prefs_save_line_too_long:
- msg = "Line in file is too long";
- break;
- case Prefs_save_existing_read_error:
- msg = "Error when reading existing configuration file";
- break;
- case Prefs_save_unknown_error:
- break;
+ if (err) {
+ char const *msg = prefs_save_error_string(err);
+ qmsg_printf_push("Config Error",
+ "Error when writing configuration file:\n%s", msg);
}
- qmsg_printf_push("Config Error", "Error when writing configuration file:\n%s",
- msg);
}
void print_loading_message(char const *s) {