diff options
Diffstat (limited to 'src/common/plugin-timer.c')
-rw-r--r-- | src/common/plugin-timer.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/common/plugin-timer.c b/src/common/plugin-timer.c index e6944330..d0c82c28 100644 --- a/src/common/plugin-timer.c +++ b/src/common/plugin-timer.c @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "config.h" + #include <stdlib.h> #include <string.h> #include <glib.h> @@ -43,7 +45,7 @@ typedef struct char *command; int ref; int repeat; - float timeout; + int timeout; unsigned int forever:1; } timer; @@ -51,9 +53,9 @@ static void timer_del (timer *tim) { timer_list = g_slist_remove (timer_list, tim); - free (tim->command); + g_free (tim->command); hexchat_unhook (ph, tim->hook); - free (tim); + g_free (tim); } static void @@ -99,7 +101,7 @@ timeout_cb (timer *tim) } static void -timer_add (int ref, float timeout, int repeat, char *command) +timer_add (int ref, int timeout, int repeat, char *command) { timer *tim; GSList *list; @@ -117,18 +119,18 @@ timer_add (int ref, float timeout, int repeat, char *command) } } - tim = malloc (sizeof (timer)); + tim = g_new (timer, 1); tim->ref = ref; tim->repeat = repeat; tim->timeout = timeout; - tim->command = strdup (command); + tim->command = g_strdup (command); tim->context = hexchat_get_context (ph); tim->forever = FALSE; if (repeat == 0) tim->forever = TRUE; - tim->hook = hexchat_hook_timer (ph, timeout * 1000.0, (void *)timeout_cb, tim); + tim->hook = hexchat_hook_timer (ph, timeout, (void *)timeout_cb, tim); timer_list = g_slist_append (timer_list, tim); } @@ -150,7 +152,7 @@ timer_showlist (void) while (list) { tim = list->data; - hexchat_printf (ph, _("%5d %8.1f %7d %s\n"), tim->ref, tim->timeout, + hexchat_printf (ph, _("%5d %8.1f %7d %s\n"), tim->ref, tim->timeout / 1000.0f, tim->repeat, tim->command); list = list->next; } @@ -160,7 +162,7 @@ static int timer_cb (char *word[], char *word_eol[], void *userdata) { int repeat = 1; - float timeout; + double timeout; int offset = 0; int ref = 0; int quiet = FALSE; @@ -199,10 +201,10 @@ timer_cb (char *word[], char *word_eol[], void *userdata) timeout = atof (word[2 + offset]); command = word_eol[3 + offset]; - if (timeout < 0.1 || !command[0]) + if (timeout < 0.1 || timeout * 1000 > INT_MAX || !command[0]) hexchat_print (ph, HELP); else - timer_add (ref, timeout, repeat, command); + timer_add (ref, (int) timeout * 1000, repeat, command); return HEXCHAT_EAT_HEXCHAT; } |