Browse Source

Cleanup naming

master
cancel 5 years ago
parent
commit
7ac411976b
  1. 62
      sysmisc.c
  2. 40
      sysmisc.h
  3. 2
      tui_main.c

62
sysmisc.c

@ -339,36 +339,36 @@ cleanup:
return err; return err;
} }
char const *prefs_save_error_string(Prefs_save_error error) { char const *ezconf_write_error_string(Ezconf_write_error error) {
switch (error) { switch (error) {
case Prefs_save_ok: case Ezconf_write_ok:
return "No error"; return "No error";
case Prefs_save_oom: case Ezconf_write_oom:
return "Out of memory"; return "Out of memory";
case Prefs_save_no_home: case Ezconf_write_no_home:
return "Unable to resolve $XDG_CONFIG_HOME or $HOME"; return "Unable to resolve $XDG_CONFIG_HOME or $HOME";
case Prefs_save_mkdir_failed: case Ezconf_write_mkdir_failed:
return "Unable to create $XDG_CONFIG_HOME or $HOME/.config directory"; return "Unable to create $XDG_CONFIG_HOME or $HOME/.config directory";
case Prefs_save_conf_dir_not_dir: case Ezconf_write_conf_dir_not_dir:
return "Config directory path is not a directory"; return "Config directory path is not a directory";
case Prefs_save_old_temp_file_stuck: case Ezconf_write_old_temp_file_stuck:
return "Unable to remove old orca.conf.tmp file"; return "Unable to remove old orca.conf.tmp file";
case Prefs_save_temp_file_perm_denied: case Ezconf_write_temp_file_perm_denied:
return "Permission denied for config directory"; return "Permission denied for config directory";
case Prefs_save_temp_open_failed: case Ezconf_write_temp_open_failed:
return "Unable to open orca.conf.tmp for writing"; return "Unable to open orca.conf.tmp for writing";
case Prefs_save_temp_fsync_failed: case Ezconf_write_temp_fsync_failed:
return "fsync() reported an when writing temp file.\n" return "fsync() reported an when writing temp file.\n"
"Refusing to continue."; "Refusing to continue.";
case Prefs_save_temp_close_failed: case Ezconf_write_temp_close_failed:
return "Unable to close temp file"; return "Unable to close temp file";
case Prefs_save_rename_failed: case Ezconf_write_rename_failed:
return "Unable to rename orca.conf.tmp to orca.conf"; return "Unable to rename orca.conf.tmp to orca.conf";
case Prefs_save_line_too_long: case Ezconf_write_line_too_long:
return "Line in file is too long"; return "Line in file is too long";
case Prefs_save_existing_read_error: case Ezconf_write_existing_read_error:
return "Error when reading existing configuration file"; return "Error when reading existing configuration file";
case Prefs_save_unknown_error: case Ezconf_write_unknown_error:
break; break;
} }
return "Unknown"; return "Unknown";
@ -396,31 +396,31 @@ void ezconf_write_start(Ezconf_write *ezcw, Confopt_w *opts, size_t optscount) {
*ezcw = (Ezconf_write){0}; *ezcw = (Ezconf_write){0};
ezcw->opts = opts; ezcw->opts = opts;
ezcw->optscount = optscount; ezcw->optscount = optscount;
Prefs_save_error error = Prefs_save_unknown_error; Ezconf_write_error error = Ezconf_write_unknown_error;
switch (conf_save_start(&ezcw->save)) { switch (conf_save_start(&ezcw->save)) {
case Conf_save_start_ok: case Conf_save_start_ok:
error = Prefs_save_ok; error = Ezconf_write_ok;
break; break;
case Conf_save_start_alloc_failed: case Conf_save_start_alloc_failed:
error = Prefs_save_oom; error = Ezconf_write_oom;
break; break;
case Conf_save_start_no_home: case Conf_save_start_no_home:
error = Prefs_save_no_home; error = Ezconf_write_no_home;
break; break;
case Conf_save_start_mkdir_failed: case Conf_save_start_mkdir_failed:
error = Prefs_save_mkdir_failed; error = Ezconf_write_mkdir_failed;
break; break;
case Conf_save_start_conf_dir_not_dir: case Conf_save_start_conf_dir_not_dir:
error = Prefs_save_conf_dir_not_dir; error = Ezconf_write_conf_dir_not_dir;
break; break;
case Conf_save_start_old_temp_file_stuck: case Conf_save_start_old_temp_file_stuck:
error = Prefs_save_old_temp_file_stuck; error = Ezconf_write_old_temp_file_stuck;
break; break;
case Conf_save_start_temp_file_perm_denied: case Conf_save_start_temp_file_perm_denied:
error = Prefs_save_temp_file_perm_denied; error = Ezconf_write_temp_file_perm_denied;
break; break;
case Conf_save_start_temp_file_open_failed: case Conf_save_start_temp_file_open_failed:
error = Prefs_save_temp_open_failed; error = Ezconf_write_temp_open_failed;
break; break;
} }
ezcw->error = error; ezcw->error = error;
@ -480,10 +480,10 @@ bool ezconf_write_step(Ezconf_write *ezcw) {
case Conf_read_eof: case Conf_read_eof:
goto end_original; goto end_original;
case Conf_read_buffer_too_small: case Conf_read_buffer_too_small:
ezcw->error = Prefs_save_line_too_long; ezcw->error = Ezconf_write_line_too_long;
goto cancel; goto cancel;
case Conf_read_io_error: case Conf_read_io_error:
ezcw->error = Prefs_save_existing_read_error; ezcw->error = Ezconf_write_existing_read_error;
goto cancel; goto cancel;
} }
} }
@ -526,19 +526,19 @@ cancel:
ezcw->stateflags = 0; ezcw->stateflags = 0;
return false; return false;
commit:; commit:;
Prefs_save_error error = Prefs_save_unknown_error; Ezconf_write_error error = Ezconf_write_unknown_error;
switch (conf_save_commit(&ezcw->save)) { switch (conf_save_commit(&ezcw->save)) {
case Conf_save_commit_ok: case Conf_save_commit_ok:
error = Prefs_save_ok; error = Ezconf_write_ok;
break; break;
case Conf_save_commit_temp_fsync_failed: case Conf_save_commit_temp_fsync_failed:
error = Prefs_save_temp_fsync_failed; error = Ezconf_write_temp_fsync_failed;
break; break;
case Conf_save_commit_temp_close_failed: case Conf_save_commit_temp_close_failed:
error = Prefs_save_temp_close_failed; error = Ezconf_write_temp_close_failed;
break; break;
case Conf_save_commit_rename_failed: case Conf_save_commit_rename_failed:
error = Prefs_save_rename_failed; error = Ezconf_write_rename_failed;
break; break;
} }
ezcw->error = error; ezcw->error = error;

40
sysmisc.h

@ -77,25 +77,6 @@ Conf_save_commit_error conf_save_commit(Conf_save *p);
// Finishes. Do not call this with a zeroed `*p`. Afterwards, `*p` will be // Finishes. Do not call this with a zeroed `*p`. Afterwards, `*p` will be
// zeroed. // 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);
// Just playing around with this design // Just playing around with this design
typedef struct { typedef struct {
FILE *file; FILE *file;
@ -108,6 +89,25 @@ void ezconf_read_start(Ezconf_read *ezcr);
bool ezconf_read_step(Ezconf_read *ezcr, char const *const *names, bool ezconf_read_step(Ezconf_read *ezcr, char const *const *names,
Usz nameslen); Usz nameslen);
typedef enum {
Ezconf_write_ok = 0,
Ezconf_write_oom,
Ezconf_write_no_home,
Ezconf_write_mkdir_failed,
Ezconf_write_conf_dir_not_dir,
Ezconf_write_old_temp_file_stuck,
Ezconf_write_temp_file_perm_denied,
Ezconf_write_temp_open_failed,
Ezconf_write_temp_fsync_failed,
Ezconf_write_temp_close_failed,
Ezconf_write_rename_failed,
Ezconf_write_line_too_long,
Ezconf_write_existing_read_error,
Ezconf_write_unknown_error,
} Ezconf_write_error;
char const *ezconf_write_error_string(Ezconf_write_error error);
typedef struct { typedef struct {
char const *name; char const *name;
intptr_t id; intptr_t id;
@ -119,7 +119,7 @@ typedef struct {
Confopt_w *opts; Confopt_w *opts;
size_t optscount; size_t optscount;
intptr_t optid; intptr_t optid;
Prefs_save_error error; Ezconf_write_error error;
U32 stateflags; U32 stateflags;
} Ezconf_write; } Ezconf_write;

2
tui_main.c

@ -2443,7 +2443,7 @@ void save_prefs_with_error_message(Midi_mode const *midi_mode, int softmargin_y,
} }
osofree(midi_output_device_name); osofree(midi_output_device_name);
if (ez.error) { if (ez.error) {
char const *msg = prefs_save_error_string(ez.error); char const *msg = ezconf_write_error_string(ez.error);
qmsg_printf_push("Config Error", qmsg_printf_push("Config Error",
"Error when writing configuration file:\n%s", msg); "Error when writing configuration file:\n%s", msg);
} }

Loading…
Cancel
Save