Changeset 5ebff60 for irc_util.c
- Timestamp:
- 2015-02-20T22:50:54Z (8 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
irc_util.c
raf359b4 r5ebff60 1 1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 26 26 #include "bitlbee.h" 27 27 28 char *set_eval_timezone( set_t *set, char *value)28 char *set_eval_timezone(set_t *set, char *value) 29 29 { 30 30 char *s; 31 32 if ( strcmp( value, "local") == 0 ||33 strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )31 32 if (strcmp(value, "local") == 0 || 33 strcmp(value, "gmt") == 0 || strcmp(value, "utc") == 0) { 34 34 return value; 35 35 } 36 36 37 /* Otherwise: +/- at the beginning optional, then one or more numbers, 37 38 possibly followed by a colon and more numbers. Don't bother bound- 38 39 checking them since users are free to shoot themselves in the foot. */ 39 40 s = value; 40 if( *s == '+' || *s == '-' ) 41 s ++; 42 41 if (*s == '+' || *s == '-') { 42 s++; 43 } 44 43 45 /* \d+ */ 44 if ( !g_ascii_isdigit( *s ) )46 if (!g_ascii_isdigit(*s)) { 45 47 return SET_INVALID; 46 while( *s && g_ascii_isdigit( *s ) ) s ++; 47 48 } 49 while (*s && g_ascii_isdigit(*s)) { 50 s++; 51 } 52 48 53 /* EOS? */ 49 if ( *s == '\0' )54 if (*s == '\0') { 50 55 return value; 51 56 } 57 52 58 /* Otherwise, colon */ 53 if ( *s != ':' )59 if (*s != ':') { 54 60 return SET_INVALID; 55 s ++; 56 61 } 62 s++; 63 57 64 /* \d+ */ 58 if ( !g_ascii_isdigit( *s ) )65 if (!g_ascii_isdigit(*s)) { 59 66 return SET_INVALID; 60 while( *s && g_ascii_isdigit( *s ) ) s ++; 61 67 } 68 while (*s && g_ascii_isdigit(*s)) { 69 s++; 70 } 71 62 72 /* EOS */ 63 73 return *s == '\0' ? value : SET_INVALID; 64 74 } 65 75 66 char *irc_format_timestamp( irc_t *irc, time_t msg_ts)76 char *irc_format_timestamp(irc_t *irc, time_t msg_ts) 67 77 { 68 time_t now_ts = time( NULL);78 time_t now_ts = time(NULL); 69 79 struct tm now, msg; 70 80 char *set; 71 81 72 82 /* If the timestamp is <= 0 or less than a minute ago, discard it as 73 83 it doesn't seem to add to much useful info and/or might be noise. */ 74 if ( msg_ts <= 0 || msg_ts > now_ts - 60 )84 if (msg_ts <= 0 || msg_ts > now_ts - 60) { 75 85 return NULL; 76 77 set = set_getstr( &irc->b->set, "timezone" );78 if( strcmp( set, "local" ) == 0 )79 {80 localtime_r( &now_ts, &now );81 localtime_r( &msg_ts, &msg );82 86 } 83 else 84 { 87 88 set = set_getstr(&irc->b->set, "timezone"); 89 if (strcmp(set, "local") == 0) { 90 localtime_r(&now_ts, &now); 91 localtime_r(&msg_ts, &msg); 92 } else { 85 93 int hr, min = 0, sign = 60; 86 87 if( set[0] == '-' ) 88 { 94 95 if (set[0] == '-') { 89 96 sign *= -1; 90 set ++; 97 set++; 98 } else if (set[0] == '+') { 99 set++; 91 100 } 92 else if( set[0] == '+' ) 93 { 94 set ++; 101 102 if (sscanf(set, "%d:%d", &hr, &min) >= 1) { 103 msg_ts += sign * (hr * 60 + min); 104 now_ts += sign * (hr * 60 + min); 95 105 } 96 97 if( sscanf( set, "%d:%d", &hr, &min ) >= 1 ) 98 { 99 msg_ts += sign * ( hr * 60 + min ); 100 now_ts += sign * ( hr * 60 + min ); 101 } 102 103 gmtime_r( &now_ts, &now ); 104 gmtime_r( &msg_ts, &msg ); 106 107 gmtime_r(&now_ts, &now); 108 gmtime_r(&msg_ts, &msg); 105 109 } 106 107 if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday ) 108 return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ", 109 msg.tm_hour, msg.tm_min, msg.tm_sec ); 110 else 111 return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d " 112 "%02d:%02d:%02d\x02]\x02 ", 113 msg.tm_year + 1900, msg.tm_mon + 1, msg.tm_mday, 114 msg.tm_hour, msg.tm_min, msg.tm_sec ); 110 111 if (msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday) { 112 return g_strdup_printf("\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ", 113 msg.tm_hour, msg.tm_min, msg.tm_sec); 114 } else { 115 return g_strdup_printf("\x02[\x02\x02\x02%04d-%02d-%02d " 116 "%02d:%02d:%02d\x02]\x02 ", 117 msg.tm_year + 1900, msg.tm_mon + 1, msg.tm_mday, 118 msg.tm_hour, msg.tm_min, msg.tm_sec); 119 } 115 120 }
Note: See TracChangeset
for help on using the changeset viewer.