prefs.c: consistent indentation

This commit is contained in:
wdlkmpx 2021-01-14 22:52:00 +08:00
parent 08f868a3e0
commit 88feee2703

View File

@ -106,7 +106,7 @@ gchar *pref_get_default_theme_name(void) {
} }
void pref_set_theme_name(gchar *name) { void pref_set_theme_name(gchar *name) {
if(_theme_name) { if (_theme_name) {
g_free(_theme_name); g_free(_theme_name);
} }
_theme_name = g_strdup(name); _theme_name = g_strdup(name);
@ -115,7 +115,7 @@ void pref_set_theme_name(gchar *name) {
gchar *find_rc_file(void) { gchar *find_rc_file(void) {
gchar *rc_file = NULL; gchar *rc_file = NULL;
if(getenv("HOME")) { if (getenv("HOME")) {
rc_file = g_strdup_printf("%s/%s", getenv ("HOME"), CONFIG_FILE_NAME); rc_file = g_strdup_printf("%s/%s", getenv ("HOME"), CONFIG_FILE_NAME);
} else { /* unable to find $HOME, assuming current directory */ } else { /* unable to find $HOME, assuming current directory */
rc_file = g_strdup(CONFIG_FILE_NAME); rc_file = g_strdup(CONFIG_FILE_NAME);
@ -126,7 +126,7 @@ gchar *find_rc_file(void) {
/* converts string to TRUE/FALSE. "true", "yes" or "1" is TRUE, otherwise - FALSE */ /* converts string to TRUE/FALSE. "true", "yes" or "1" is TRUE, otherwise - FALSE */
gboolean pref_str_to_bool(gchar *val) { gboolean pref_str_to_bool(gchar *val) {
if(!g_ascii_strcasecmp(val, "true") || if (!g_ascii_strcasecmp(val, "true") ||
!g_ascii_strcasecmp(val, "yes") || !g_ascii_strcasecmp(val, "yes") ||
!g_ascii_strcasecmp(val, "1")) { !g_ascii_strcasecmp(val, "1")) {
return TRUE; return TRUE;
@ -142,53 +142,57 @@ gchar *pref_bool_to_str(gboolean val) {
/* we use very lame preferences file format: ``property=value\n''. /* we use very lame preferences file format: ``property=value\n''.
so - there must be no whitespaces on begin/end of line =) */ so - there must be no whitespaces on begin/end of line =) */
void load_preferences(void) { void load_preferences(void)
{
FILE *fp; FILE *fp;
gchar *rc_file; gchar *rc_file;
gchar buffer[BUFFER_SIZE]; gchar buffer[BUFFER_SIZE];
gchar **prop_val; gchar **prop_val;
if(!_theme_name) { if (!_theme_name) {
_theme_name = g_strdup(_default_theme_name); _theme_name = g_strdup(_default_theme_name);
} }
rc_file = find_rc_file(); rc_file = find_rc_file();
if((fp = fopen(rc_file, "r"))) { if ((fp = fopen(rc_file, "r")))
while(fgets(buffer, BUFFER_SIZE, fp)) { {
while(fgets(buffer, BUFFER_SIZE, fp))
{
g_strchomp(buffer); g_strchomp(buffer);
prop_val = g_strsplit(buffer, "=", 2); prop_val = g_strsplit(buffer, "=", 2);
if(prop_val[0] && prop_val[0][0] && prop_val[1] && prop_val[1][0]) { if (prop_val[0] && prop_val[0][0] && prop_val[1] && prop_val[1][0])
if(!g_ascii_strcasecmp(prop_val[0], "show_hints")) { {
if (!g_ascii_strcasecmp(prop_val[0], "show_hints")) {
_show_next_colors = pref_str_to_bool(prop_val[1]); _show_next_colors = pref_str_to_bool(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "show_path")) { } else if (!g_ascii_strcasecmp(prop_val[0], "show_path")) {
_show_path = pref_str_to_bool(prop_val[1]); _show_path = pref_str_to_bool(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "show_footprints")) { } else if (!g_ascii_strcasecmp(prop_val[0], "show_footprints")) {
_show_footprints = pref_str_to_bool(prop_val[1]); _show_footprints = pref_str_to_bool(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "show_destroy")) { } else if (!g_ascii_strcasecmp(prop_val[0], "show_destroy")) {
_show_destroy = pref_str_to_bool(prop_val[1]); _show_destroy = pref_str_to_bool(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "show_highlight")) { } else if (!g_ascii_strcasecmp(prop_val[0], "show_highlight")) {
_show_highlight = pref_str_to_bool(prop_val[1]); _show_highlight = pref_str_to_bool(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "theme_name")) { } else if (!g_ascii_strcasecmp(prop_val[0], "theme_name")) {
if(_theme_name) { if (_theme_name) {
g_free(_theme_name); g_free(_theme_name);
} }
_theme_name = g_strdup(prop_val[1]); _theme_name = g_strdup(prop_val[1]);
} else if(!g_ascii_strcasecmp(prop_val[0], "rules_xsize")) { } else if (!g_ascii_strcasecmp(prop_val[0], "rules_xsize")) {
rules_set_width(atoi(prop_val[1])); rules_set_width(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "rules_ysize")) { } else if (!g_ascii_strcasecmp(prop_val[0], "rules_ysize")) {
rules_set_height(atoi(prop_val[1])); rules_set_height(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "rules_colors")) { } else if (!g_ascii_strcasecmp(prop_val[0], "rules_colors")) {
rules_set_colors(atoi(prop_val[1])); rules_set_colors(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "rules_next")) { } else if (!g_ascii_strcasecmp(prop_val[0], "rules_next")) {
rules_set_next(atoi(prop_val[1])); rules_set_next(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "rules_destroy")) { } else if (!g_ascii_strcasecmp(prop_val[0], "rules_destroy")) {
rules_set_destroy(atoi(prop_val[1])); rules_set_destroy(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "time_limit")) { } else if (!g_ascii_strcasecmp(prop_val[0], "time_limit")) {
timer_set_limit(atoi(prop_val[1])); timer_set_limit(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "highlight_dr")) { } else if (!g_ascii_strcasecmp(prop_val[0], "highlight_dr")) {
prefs_set_hl_dr(atoi(prop_val[1])); prefs_set_hl_dr(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "highlight_dg")) { } else if (!g_ascii_strcasecmp(prop_val[0], "highlight_dg")) {
prefs_set_hl_dg(atoi(prop_val[1])); prefs_set_hl_dg(atoi(prop_val[1]));
} else if(!g_ascii_strcasecmp(prop_val[0], "highlight_db")) { } else if (!g_ascii_strcasecmp(prop_val[0], "highlight_db")) {
prefs_set_hl_db(atoi(prop_val[1])); prefs_set_hl_db(atoi(prop_val[1]));
} }
} }
@ -202,20 +206,21 @@ void load_preferences(void) {
/* writes ``property=value\n'' to fp. /* writes ``property=value\n'' to fp.
why i made it separate function? for "feature purposes" =) */ why i made it separate function? for "feature purposes" =) */
void write_pref_string(FILE *fp, gchar *property, gchar *value) { void write_pref_string(FILE *fp, gchar *property, gchar *value) {
fprintf(fp, "%s=%s\n", property, value); fprintf (fp, "%s=%s\n", property, value);
} }
void write_pref_int(FILE *fp, gchar *property, gint value) { void write_pref_int(FILE *fp, gchar *property, gint value) {
fprintf(fp, "%s=%d\n", property, value); fprintf (fp, "%s=%d\n", property, value);
} }
gchar *save_preferences(void) { gchar *save_preferences (void)
{
FILE *fp; FILE *fp;
gchar *rc_file/*, *err*/; gchar *rc_file/*, *err*/;
gchar *ret = NULL; gchar *ret = NULL;
rc_file = find_rc_file(); rc_file = find_rc_file();
if((fp = fopen(rc_file, "w"))) { if ((fp = fopen(rc_file, "w"))) {
write_pref_string(fp, "show_hints", pref_bool_to_str(_show_next_colors)); write_pref_string(fp, "show_hints", pref_bool_to_str(_show_next_colors));
write_pref_string(fp, "show_path", pref_bool_to_str(_show_path)); write_pref_string(fp, "show_path", pref_bool_to_str(_show_path));
write_pref_string(fp, "show_footprints", pref_bool_to_str(_show_footprints)); write_pref_string(fp, "show_footprints", pref_bool_to_str(_show_footprints));