Mercurial > pidgin
changeset 20909:feca1fd51b57
Use functions and loops and all those fancy things.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 12 Oct 2007 22:12:29 +0000 |
parents | 9ec0382e6c8d |
children | 54d232b52607 |
files | libpurple/plugins/log_reader.c |
diffstat | 1 files changed, 16 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/log_reader.c Fri Oct 12 21:39:31 2007 +0000 +++ b/libpurple/plugins/log_reader.c Fri Oct 12 22:12:29 2007 +0000 @@ -28,6 +28,19 @@ NAME_GUESS_THEM }; +/* Some common functions. */ +static int get_month(const char *month) +{ + int iter; + const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}; + for (iter = 0; months[iter]; iter++) { + if (strcmp(month, months[iter]) == 0) + break; + } + return iter; +} + /***************************************************************************** * Adium Logger * @@ -1348,36 +1361,7 @@ * daylight savings time. */ tm.tm_isdst = -1; - - /* Ugly hack, in case current locale - * is not English. This code is taken - * from log.c. - */ - if (strcmp(month, "Jan") == 0) { - tm.tm_mon= 0; - } else if (strcmp(month, "Feb") == 0) { - tm.tm_mon = 1; - } else if (strcmp(month, "Mar") == 0) { - tm.tm_mon = 2; - } else if (strcmp(month, "Apr") == 0) { - tm.tm_mon = 3; - } else if (strcmp(month, "May") == 0) { - tm.tm_mon = 4; - } else if (strcmp(month, "Jun") == 0) { - tm.tm_mon = 5; - } else if (strcmp(month, "Jul") == 0) { - tm.tm_mon = 6; - } else if (strcmp(month, "Aug") == 0) { - tm.tm_mon = 7; - } else if (strcmp(month, "Sep") == 0) { - tm.tm_mon = 8; - } else if (strcmp(month, "Oct") == 0) { - tm.tm_mon = 9; - } else if (strcmp(month, "Nov") == 0) { - tm.tm_mon = 10; - } else if (strcmp(month, "Dec") == 0) { - tm.tm_mon = 11; - } + tm.tm_mon = get_month(month); data = g_new0( struct trillian_logger_data, 1); @@ -2226,23 +2210,14 @@ "Error parsing start date for %s\n", filename); } else { - const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}; tm.tm_year -= 1900; /* Let the C library deal with * daylight savings time. */ tm.tm_isdst = -1; - - /* Ugly hack, in case current locale - * is not English. This code is taken - * from log.c. - */ - for (tm.tm_mon = 0; months[tm.tm_mon]; tm.tm_mon++) { - if (strcmp(month, months[tm.tm_mon]) == 0) - break; - } + tm.tm_mon = get_month(month); + found_start = TRUE; offset = c - contents; start_log = c;