[cvslog] [CVS] Module eggdrop1.8: Change committed

cvs at eggheads.org cvs at eggheads.org
Wed Oct 27 14:47:41 CST 2010


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.8
Commit time: 2010-10-27 20:47:36 UTC
Committer  : Rumen Stoyanov <pseudo at egg6.net>

Modified files:
     doc/Changes1.8 doc/tcl-commands.doc doc/html/tcl-commands.html
     src/chanprog.c src/patch.h src/tclegg.h src/tclmisc.c

Log message:

Added optional count argument to Tcl timer and utimer to allow them run more than once.

---------------------- diff included ----------------------
Index: eggdrop1.8/doc/Changes1.8
diff -u eggdrop1.8/doc/Changes1.8:1.30 eggdrop1.8/doc/Changes1.8:1.31
--- eggdrop1.8/doc/Changes1.8:1.30	Tue Oct 26 03:13:56 2010
+++ eggdrop1.8/doc/Changes1.8	Wed Oct 27 14:47:26 2010
@@ -1,4 +1,4 @@
-$Id: Changes1.8,v 1.30 2010/10/26 09:13:56 pseudo Exp $
+$Id: Changes1.8,v 1.31 2010/10/27 20:47:26 pseudo Exp $
 
 Eggdrop Changes (since version 1.8.0)
 
@@ -6,6 +6,10 @@
 
 1.8.0 (CVS):
 
+  - Added optional count argument to Tcl timer and utimer to allow them run
+    more than once.
+    Patch by: pseudo
+
   - Renamed the vhost Tcl variable to vhost4 as it is in the documentation.
     Patch by: pseudo
 
Index: eggdrop1.8/doc/html/tcl-commands.html
diff -u eggdrop1.8/doc/html/tcl-commands.html:1.7 eggdrop1.8/doc/html/tcl-commands.html:1.8
--- eggdrop1.8/doc/html/tcl-commands.html:1.7	Mon Oct 25 09:56:38 2010
+++ eggdrop1.8/doc/html/tcl-commands.html	Wed Oct 27 14:47:26 2010
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!-- $Id: tcl-commands.html,v 1.7 2010/10/25 15:56:38 pseudo Exp $ -->
+<!-- $Id: tcl-commands.html,v 1.8 2010/10/27 20:47:26 pseudo Exp $ -->
 
 <html>
   <head>
@@ -3138,22 +3138,32 @@
           <p><strong>Module:</strong> core</p>
         </dd>
 
-        <dt><strong><a name="cmd_timer"></a>timer &lt;minutes&gt; &lt;tcl-command&gt;</strong></dt>
+        <dt><strong><a name="cmd_timer"></a>timer &lt;minutes&gt; &lt;tcl-command&gt;
+        [count]</strong></dt>
 
         <dd>
           <p><strong>Description:</strong> executes the given Tcl command
-          after a certain number of minutes have passed</p>
+          after a certain number of minutes have passed. If count is
+          specified, the command will be executed count times with the given
+          interval in between. If you specify a count of 0, the timer will
+          repeat until it's removed with killtimer or until the bot is
+          restarted.</p>
 
           <p><strong>Returns:</strong> a timerID</p>
 
           <p><strong>Module:</strong> core</p>
         </dd>
 
-        <dt><strong><a name="cmd_utimer"></a>utimer &lt;seconds&gt; &lt;tcl-command&gt;</strong></dt>
+        <dt><strong><a name="cmd_utimer"></a>utimer &lt;seconds&gt; &lt;tcl-command&gt;
+        [count]</strong></dt>
 
         <dd>
           <p><strong>Description:</strong> executes the given Tcl command
-          after a certain number of seconds have passed</p>
+          after a certain number of seconds have passed. If count is
+          specified, the command will be executed count times with the given
+          interval in between. If you specify a count of 0, the utimer will
+          repeat until it's removed with killutimer or until the bot is
+          restarted.</p>
 
           <p><strong>Returns:</strong> a timerID</p>
 
@@ -3165,7 +3175,8 @@
         <dd>
           <p><strong>Returns:</strong> a list of active minutely timers.
           Each entry in the list contains the number of minutes left till
-          activation, the command that will be executed, and the timerID.</p>
+          activation, the command that will be executed, the timerID, and
+          the remaining number of repeats.</p>
 
           <p><strong>Module:</strong> core</p>
         </dd>
@@ -3175,7 +3186,8 @@
         <dd>
           <p><strong>Returns:</strong> a list of active secondly timers.
           Each entry in the list contains the number of minutes left till
-          activation, the command that will be executed, and the timerID.</p>
+          activation, the command that will be executed, the timerID, and
+          the remaining number of repeats.</p>
 
           <p><strong>Module:</strong> core</p>
         </dd>
Index: eggdrop1.8/doc/tcl-commands.doc
diff -u eggdrop1.8/doc/tcl-commands.doc:1.6 eggdrop1.8/doc/tcl-commands.doc:1.7
--- eggdrop1.8/doc/tcl-commands.doc:1.6	Mon Oct 25 09:56:38 2010
+++ eggdrop1.8/doc/tcl-commands.doc	Wed Oct 27 14:47:26 2010
@@ -1,4 +1,4 @@
-$Id: tcl-commands.doc,v 1.6 2010/10/25 15:56:38 pseudo Exp $
+$Id: tcl-commands.doc,v 1.7 2010/10/27 20:47:26 pseudo Exp $
 
 Eggdrop Tcl Commands
 Last revised: October 24, 2010
@@ -1366,28 +1366,34 @@
       will be used.
     Module: core
 
-  timer <minutes> <tcl-command>
+  timer <minutes> <tcl-command> [count]
     Description: executes the given Tcl command after a certain number of
-      minutes have passed
+      minutes have passed. If count is specified, the command will be executed
+      count times with the given interval in between. If you specify a count
+      of 0, the timer will repeat until it's removed with killtimer or until
+      the bot is restarted.
     Returns: a timerID
     Module: core
 
-  utimer <seconds> <tcl-command>
+  utimer <seconds> <tcl-command> [count]
     Description: executes the given Tcl command after a certain number of
-      seconds have passed
+      seconds have passed. If count is specified, the command will be executed
+      count times with the given interval in between. If you specify a count
+      of 0, the utimer will repeat until it's removed with killutimer or until
+      the bot is restarted.
     Returns: a timerID
     Module: core
 
   timers
     Returns: a list of active minutely timers. Each entry in the list contains
       the number of minutes left till activation, the command that will be
-      executed, and the timerID.
+      executed, the timerID, and the remaining number of repeats.
     Module: core
 
   utimers
     Returns: a list of active secondly timers. Each entry in the list contains
       the number of minutes left till activation, the command that will be
-      executed, and the timerID.
+      executed, the timerID, and the remaining number of repeats.
     Module: core
 
   killtimer <timerID>
Index: eggdrop1.8/src/chanprog.c
diff -u eggdrop1.8/src/chanprog.c:1.5 eggdrop1.8/src/chanprog.c:1.6
--- eggdrop1.8/src/chanprog.c:1.5	Mon Oct 25 09:56:38 2010
+++ eggdrop1.8/src/chanprog.c	Wed Oct 27 14:47:26 2010
@@ -7,7 +7,7 @@
  *   telling the current programmed settings
  *   initializing a lot of stuff and loading the tcl scripts
  *
- * $Id: chanprog.c,v 1.5 2010/10/25 15:56:38 pseudo Exp $
+ * $Id: chanprog.c,v 1.6 2010/10/27 20:47:26 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -579,14 +579,15 @@
 
 /* Add a timer
  */
-unsigned long add_timer(tcl_timer_t ** stack, int elapse, char *cmd,
-                        unsigned long prev_id)
+unsigned long add_timer(tcl_timer_t ** stack, int elapse, int count,
+                        char *cmd, unsigned long prev_id)
 {
   tcl_timer_t *old = (*stack);
 
   *stack = nmalloc(sizeof **stack);
   (*stack)->next = old;
-  (*stack)->mins = elapse;
+  (*stack)->mins = (*stack)->interval = elapse;
+  (*stack)->count = count;
   (*stack)->cmd = nmalloc(strlen(cmd) + 1);
   strcpy((*stack)->cmd, cmd);
   /* If it's just being added back and already had an id,
@@ -639,12 +640,18 @@
     if (!old->mins) {
       egg_snprintf(x, sizeof x, "timer%lu", old->id);
       do_tcl(x, old->cmd);
-      nfree(old->cmd);
-      nfree(old);
-    } else {
-      old->next = *stack;
-      *stack = old;
+      if (old->count == 1) {
+        nfree(old->cmd);
+        nfree(old);
+        continue;
+      } else {
+        old->mins = old->interval;
+        if (old->count > 1)
+          old->count--;
+      }
     }
+    old->next = *stack;
+    *stack = old;
   }
 }
 
@@ -667,17 +674,19 @@
  */
 void list_timers(Tcl_Interp *irp, tcl_timer_t *stack)
 {
-  char mins[10], id[16], *x;
-  EGG_CONST char *argv[3];
+  char mins[10], count[10], id[16], *x;
+  EGG_CONST char *argv[4];
   tcl_timer_t *mark;
 
   for (mark = stack; mark; mark = mark->next) {
     egg_snprintf(mins, sizeof mins, "%u", mark->mins);
     egg_snprintf(id, sizeof id, "timer%lu", mark->id);
+    egg_snprintf(count, sizeof count, "%u", mark->count);
     argv[0] = mins;
     argv[1] = mark->cmd;
     argv[2] = id;
-    x = Tcl_Merge(3, argv);
+    argv[3] = count;
+    x = Tcl_Merge(sizeof *argv, argv);
     Tcl_AppendElement(irp, x);
     Tcl_Free((char *) x);
   }
Index: eggdrop1.8/src/patch.h
diff -u eggdrop1.8/src/patch.h:1.19 eggdrop1.8/src/patch.h:1.20
--- eggdrop1.8/src/patch.h:1.19	Tue Oct 26 03:13:56 2010
+++ eggdrop1.8/src/patch.h	Wed Oct 27 14:47:26 2010
@@ -10,7 +10,7 @@
  * statement, leave the rest of the file alone, this allows better
  * overlapping patches.
  *
- * $Id: patch.h,v 1.19 2010/10/26 09:13:56 pseudo Exp $
+ * $Id: patch.h,v 1.20 2010/10/27 20:47:26 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,12 +41,12 @@
  *
  *
  */
-patch("1288084419");            /* current unixtime */
+patch("1288212413");            /* current unixtime */
 /*
  *
  *
  */
-patch("vhost4");
+patch("timercount");
 /*
  *
  *
Index: eggdrop1.8/src/tclegg.h
diff -u eggdrop1.8/src/tclegg.h:1.1.1.1 eggdrop1.8/src/tclegg.h:1.2
--- eggdrop1.8/src/tclegg.h:1.1.1.1	Mon Jul 26 15:11:06 2010
+++ eggdrop1.8/src/tclegg.h	Wed Oct 27 14:47:26 2010
@@ -2,7 +2,7 @@
  * tclegg.h
  *   stuff used by tcl.c and tclhash.c
  *
- * $Id: tclegg.h,v 1.1.1.1 2010/07/26 21:11:06 simple Exp $
+ * $Id: tclegg.h,v 1.2 2010/10/27 20:47:26 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -101,7 +101,9 @@
  */
 typedef struct timer_str {
   struct timer_str *next;
-  unsigned int mins;            /* Time to elapse                       */
+  unsigned int mins;            /* Time remaining                       */
+  unsigned int count;           /* Number of repeats                    */
+  unsigned int interval;        /* Time to elapse                       */
   char *cmd;                    /* Command linked to                    */
   unsigned long id;             /* Used to remove timers                */
 } tcl_timer_t;
@@ -130,7 +132,7 @@
         }                                                               \
 } while (0)
 
-unsigned long add_timer(tcl_timer_t **, int, char *, unsigned long);
+unsigned long add_timer(tcl_timer_t **, int, int, char *, unsigned long);
 int remove_timer(tcl_timer_t **, unsigned long);
 void list_timers(Tcl_Interp *, tcl_timer_t *);
 void wipe_timers(Tcl_Interp *, tcl_timer_t **);
Index: eggdrop1.8/src/tclmisc.c
diff -u eggdrop1.8/src/tclmisc.c:1.4 eggdrop1.8/src/tclmisc.c:1.5
--- eggdrop1.8/src/tclmisc.c:1.4	Tue Oct 19 08:20:56 2010
+++ eggdrop1.8/src/tclmisc.c	Wed Oct 27 14:47:26 2010
@@ -2,7 +2,7 @@
  * tclmisc.c -- handles:
  *   Tcl stubs for everything else
  *
- * $Id: tclmisc.c,v 1.4 2010/10/19 14:20:56 pseudo Exp $
+ * $Id: tclmisc.c,v 1.5 2010/10/27 20:47:26 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -256,14 +256,19 @@
   unsigned long x;
   char s[16];
 
-  BADARGS(3, 3, " minutes command");
+  BADARGS(3, 4, " minutes command ?count?");
 
   if (atoi(argv[1]) < 0) {
     Tcl_AppendResult(irp, "time value must be positive", NULL);
     return TCL_ERROR;
   }
+  if (argc == 4 && atoi(argv[3]) < 0) {
+    Tcl_AppendResult(irp, "count value must be >= 0", NULL);
+    return TCL_ERROR;
+  }
   if (argv[2][0] != '#') {
-    x = add_timer(&timer, atoi(argv[1]), argv[2], 0L);
+    x = add_timer(&timer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
+                  argv[2], 0L);
     egg_snprintf(s, sizeof s, "timer%lu", x);
     Tcl_AppendResult(irp, s, NULL);
   }
@@ -275,14 +280,19 @@
   unsigned long x;
   char s[16];
 
-  BADARGS(3, 3, " seconds command");
+  BADARGS(3, 4, " seconds command ?count?");
 
   if (atoi(argv[1]) < 0) {
     Tcl_AppendResult(irp, "time value must be positive", NULL);
     return TCL_ERROR;
   }
+  if (argc == 4 && atoi(argv[3]) < 0) {
+    Tcl_AppendResult(irp, "count value must be >= 0", NULL);
+    return TCL_ERROR;
+  }
   if (argv[2][0] != '#') {
-    x = add_timer(&utimer, atoi(argv[1]), argv[2], 0L);
+    x = add_timer(&utimer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
+                  argv[2], 0L);
     egg_snprintf(s, sizeof s, "timer%lu", x);
     Tcl_AppendResult(irp, s, NULL);
   }
----------------------- End of diff -----------------------


More information about the Changes mailing list