From de3a28c6e6a0d81b4b509ee507314a4e16d92286 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 7 Apr 2014 18:16:38 -0400 Subject: [PATCH] create empty config file if none found && make default time 24 hours --- src/friendlist.c | 2 +- src/log.c | 2 +- src/main.c | 4 ++-- src/misc_tools.c | 2 +- src/settings.c | 9 ++++++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/friendlist.c b/src/friendlist.c index 3fa1c0f..8ba8024 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -92,7 +92,7 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp) friends[num].last_online.tm = *localtime(×tamp); /* if the format changes make sure TIME_STR_SIZE is the correct size */ - const char *t = user_settings->time == TIME_24 ? "%H:%M" : "%I:%M %p"; + const char *t = user_settings->time == TIME_12 ? "%I:%M %p" : "%H:%M"; strftime(friends[num].last_online.hour_min_str, TIME_STR_SIZE, t, &friends[num].last_online.tm); } diff --git a/src/log.c b/src/log.c index ed46505..a93ec1f 100644 --- a/src/log.c +++ b/src/log.c @@ -99,7 +99,7 @@ void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool e else snprintf(name_frmt, sizeof(name_frmt), "%s:", name); - const char *t = user_settings->time == TIME_24 ? "%Y/%m/%d [%H:%M:%S]" : "%Y/%m/%d [%I:%M:%S %p]"; + const char *t = user_settings->time == TIME_12 ? "%Y/%m/%d [%I:%M:%S %p]" : "%Y/%m/%d [%H:%M:%S]"; uint8_t s[MAX_STR_SIZE]; strftime(s, MAX_STR_SIZE, t, get_time()); fprintf(log->file,"%s %s %s\n", s, name_frmt, msg); diff --git a/src/main.c b/src/main.c index f193a53..007e30b 100644 --- a/src/main.c +++ b/src/main.c @@ -559,12 +559,12 @@ int main(int argc, char *argv[]) line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); } - /* + if (settings_err == -1) { msg = "Failed to load user settings"; line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); } - */ + sort_friendlist_index(); prompt_init_statusbar(prompt, m); diff --git a/src/misc_tools.c b/src/misc_tools.c index 53c42ce..618cc33 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -59,7 +59,7 @@ struct tm *get_time(void) void get_time_str(uint8_t *buf) { - const char *t = user_settings->time == TIME_24 ? "[%H:%M:%S] " : "[%I:%M:%S %p] "; + const char *t = user_settings->time == TIME_12 ? "[%I:%M:%S %p] " : "[%H:%M:%S] "; strftime(buf, TIME_STR_SIZE, t, get_time()); } diff --git a/src/settings.c b/src/settings.c index c798cae..7833485 100644 --- a/src/settings.c +++ b/src/settings.c @@ -62,19 +62,21 @@ int settings_load(struct user_settings *s, char *path) { char *user_config_dir = get_user_config_dir(); FILE *fp = NULL; + char dflt_path[MAX_STR_SIZE]; if (path) { fp = fopen(path, "r"); } else { - char dflt_path[MAX_STR_SIZE]; snprintf(dflt_path, sizeof(dflt_path), "%s%stoxic.conf", user_config_dir, CONFIGDIR); fp = fopen(dflt_path, "r"); } free(user_config_dir); - if (fp == NULL) - return -1; + if (fp == NULL) { + if ((fp = fopen(dflt_path, "w")) == NULL) + return -1; + } char line[MAX_STR_SIZE]; @@ -99,5 +101,6 @@ int settings_load(struct user_settings *s, char *path) } } + fclose(fp); return 0; }