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

cvs at eggheads.org cvs at eggheads.org
Mon Mar 8 05:18:17 CST 2010


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.6
Commit time: 2010-03-08 11:18:17 UTC
Committer  : Rumen Stoyanov <pseudo at egg6.net>

Modified files:
     doc/Changes1.6 doc/tcl-commands.doc doc/html/tcl-commands.html
     src/main.c src/match.c src/patch.h src/proto.h src/tclegg.h
     src/tclhash.c src/tclhash.h

Log message:

Added a new bind CRON as a crontab-like alternative to bind TIME.

---------------------- diff included ----------------------
Index: eggdrop1.6/doc/Changes1.6
diff -u eggdrop1.6/doc/Changes1.6:1.68 eggdrop1.6/doc/Changes1.6:1.69
--- eggdrop1.6/doc/Changes1.6:1.68	Sat Feb 20 12:33:51 2010
+++ eggdrop1.6/doc/Changes1.6	Mon Mar  8 05:18:07 2010
@@ -1,4 +1,4 @@
-$Id: Changes1.6,v 1.68 2010/02/20 18:33:51 pseudo Exp $
+$Id: Changes1.6,v 1.69 2010/03/08 11:18:07 pseudo Exp $
 
 Eggdrop Changes (since version 1.6.0)
 
@@ -6,6 +6,10 @@
 
 1.6.20 (CVS):
 
+  - Added a new bind CRON as a crontab-like alternative to bind TIME.
+    Fixes Bugzilla Bug # 477 "bind time enhancement"
+    Patch by: pseudo
+
   - Removed some CYGWIN_HACKS that aren't needed anymore.
     Patch by: FireEgl
 
Index: eggdrop1.6/doc/html/tcl-commands.html
diff -u eggdrop1.6/doc/html/tcl-commands.html:1.65 eggdrop1.6/doc/html/tcl-commands.html:1.66
--- eggdrop1.6/doc/html/tcl-commands.html:1.65	Thu Jan  7 07:48:30 2010
+++ eggdrop1.6/doc/html/tcl-commands.html	Mon Mar  8 05:18:07 2010
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!-- $Id: tcl-commands.html,v 1.65 2010/01/07 13:48:30 pseudo Exp $ -->
+<!-- $Id: tcl-commands.html,v 1.66 2010/03/08 11:18:07 pseudo Exp $ -->
 
 <html>
   <head>
@@ -4811,6 +4811,29 @@
 
               <p><strong>Module:</strong> server</p>
             </li>
+
+            <li>
+              <p><a name="binda_cron"></a><strong>CRON (stackable)</strong></p>*
+
+              <p><strong>bind cron &lt;flags&gt; &lt;mask&gt; &lt;proc&gt;<br>
+              proc-name &lt;minute&gt; &lt;hour&gt; &lt;day&gt; &lt;weekday&gt;
+              &lt;year&gt;</strong></p>
+
+              <p><strong>Description:</strong> similar to bind TIME, but the
+              mask is evaluated as a cron expression, e.g.
+              &quot;16/2 */2 5-15 7,8,9 4&quot;. It can contain up to five
+              fields: minute, hour, day, month, weekday; delimited by
+              whitespace. Week days are represented as 0-6, where 0 is Sunday.
+              Symbolic names are not supported. The bind will be triggered if
+              the mask matches all of the fields, except that if both day and
+              weekday are not '*', only one of them is required to match. If
+              any number of fields are omitted at the end, the match will
+              proceed as if they were '*'. All cron operators are supported.
+              Please refer to the crontab manual for their meanings. Flags are
+              ignored.</p>
+
+              <p><strong>Module:</strong> core</p>
+            </li>
           </ol>
         </li>
 
Index: eggdrop1.6/doc/tcl-commands.doc
diff -u eggdrop1.6/doc/tcl-commands.doc:1.131 eggdrop1.6/doc/tcl-commands.doc:1.132
--- eggdrop1.6/doc/tcl-commands.doc:1.131	Thu Jan  7 07:48:30 2010
+++ eggdrop1.6/doc/tcl-commands.doc	Mon Mar  8 05:18:07 2010
@@ -1,4 +1,4 @@
-$Id: tcl-commands.doc,v 1.131 2010/01/07 13:48:30 pseudo Exp $
+$Id: tcl-commands.doc,v 1.132 2010/03/08 11:18:07 pseudo Exp $
 
 Eggdrop Tcl Commands
 Last revised: November 23, 2009
@@ -2212,6 +2212,22 @@
 |          noqueue is only used by the putnow tcl command.
 |        Module: server
 
+|   (46) CRON (stackable)
+|        bind cron <flags> <mask> <proc>
+|        proc-name <minute> <hour> <day> <month> <weekday>
+|
+|        Description: similar to bind TIME, but the mask is evaluated as a cron
+|          expression, e.g. "16/2 */2 5-15 7,8,9 4". It can contain up to five
+|          fields: minute, hour, day, month, weekday; delimited by whitespace.
+|          Week days are represented as 0-6, where 0 is Sunday. Symbolic names
+|          are not supported. The bind will be triggered if the mask matches all
+|          of the fields, except that if both day and weekday are not '*', only
+|          one of them is required to match. If any number of fields are omitted
+|          at the end, the match will proceed as if they were '*'. All cron
+|          operators are supported. Please refer to the crontab manual for their
+|          meanings. Flags are ignored.
+|        Module: core
+
   (B) RETURN VALUES
 
     Several bindings pay attention to the value you return from the proc
Index: eggdrop1.6/src/main.c
diff -u eggdrop1.6/src/main.c:1.131 eggdrop1.6/src/main.c:1.132
--- eggdrop1.6/src/main.c:1.131	Sat Feb 20 12:33:52 2010
+++ eggdrop1.6/src/main.c	Mon Mar  8 05:18:07 2010
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.131 2010/02/20 18:33:52 pseudo Exp $
+ * $Id: main.c,v 1.132 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -607,6 +607,7 @@
 static void core_minutely()
 {
   check_tcl_time(&nowtm);
+  check_tcl_cron(&nowtm);
   do_check_timers(&timer);
   if (quick_logs != 0) {
     flushlogs();
Index: eggdrop1.6/src/match.c
diff -u eggdrop1.6/src/match.c:1.15 eggdrop1.6/src/match.c:1.16
--- eggdrop1.6/src/match.c:1.15	Wed Feb  3 02:58:24 2010
+++ eggdrop1.6/src/match.c	Mon Mar  8 05:18:07 2010
@@ -4,7 +4,7 @@
  *   hostmask matching
  *   cidr matching
  *
- * $Id: match.c,v 1.15 2010/02/03 08:58:24 pseudo Exp $
+ * $Id: match.c,v 1.16 2010/03/08 11:18:07 pseudo Exp $
  *
  * Once this code was working, I added support for % so that I could
  * use the same code both in Eggdrop and in my IrcII client.
@@ -363,3 +363,82 @@
   return ((block >> count) == (addr >> count));
 #endif
 }
+
+/* Inline for cron_match (obviously).
+ * Matches a single field of a crontab expression.
+ */
+inline int cron_matchfld(char *mask, int match)
+{
+  int skip = 0, f, t;
+  char *p, *q;
+
+  for (p = mask; mask && *mask; mask = p) {
+    /* loop through a list of values, if such is given */
+    if ((p = strchr(mask, ',')))
+      *p++ = 0;
+    /* check for the step operator */
+    if ((q = strchr(mask, '/'))) {
+      if (q == mask)
+        continue;
+      *q++ = 0;
+      skip = atoi(q);
+    }
+    if (!strcmp(mask, "*") && (!skip || !(match % skip)))
+      return 1;
+    /* ranges, e.g 10-20 */
+    if (strchr(mask, '-')) {
+      if (sscanf(mask, "%d-%d", &f, &t) != 2)
+        continue;
+      if (t < f) {
+        if (match <= t)
+          match += 60;
+        t += 60;
+      }
+      if ((match >= f && match <= t) &&
+          (!skip || !((match - f) % skip)))
+        return 1;
+    }
+    /* no operator found, should be exact match */
+    f = strtol(mask, &q, 10);
+    if ((q > mask) &&
+        (skip ? !((match - f) % skip) : (match == f)))
+      return 1;
+  }
+  return 0;
+}
+
+/* Check if the current time matches a crontab-like specification.
+ *
+ * mask contains a cron-style series of time fields. The following
+ * crontab operators are supported: ranges '-', asterisks '*',
+ * lists ',' and steps '/'.
+ * match must have 5 space separated integers representing in order
+ * the current minute, hour, day of month, month and year.
+ * It should look like this: "53 17 01 03 2010", which means
+ * 01 March 2010, 17:53.
+ */
+int cron_match(const char *mask, const char *match)
+{
+  int d = 0, i, m = 1, t[5];
+  char *p, *q, *buf;
+
+  if (!mask[0])
+    return 0;
+  if (sscanf(match, "%d %d %d %d %d",
+             &t[0], &t[1], &t[2], &t[3], &t[4]) < 5)
+    return 0;
+  buf = nmalloc(strlen(mask) + 1);
+  strcpy(buf, mask);
+  for (p = buf, i = 0; *p && i < 5; i++) {
+    q = newsplit(&p);
+    if (!strcmp(q, "*"))
+      continue;
+    m = cron_matchfld(q, t[i]);
+    if (i == 2)
+      d = m;
+    else if (!m || (i == 3 && d))
+      break;
+  }
+  nfree(buf);
+  return m;
+}
Index: eggdrop1.6/src/patch.h
diff -u eggdrop1.6/src/patch.h:1.1238 eggdrop1.6/src/patch.h:1.1239
--- eggdrop1.6/src/patch.h:1.1238	Sat Feb 20 12:33:52 2010
+++ eggdrop1.6/src/patch.h	Mon Mar  8 05:18:07 2010
@@ -10,7 +10,7 @@
  * statement, leave the rest of the file alone, this allows better
  * overlapping patches.
  *
- * $Id: patch.h,v 1.1238 2010/02/20 18:33:52 pseudo Exp $
+ * $Id: patch.h,v 1.1239 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,12 +41,12 @@
  *
  *
  */
-patch("1266690792");            /* current unixtime */
+patch("1268046715");            /* current unixtime */
 /*
  *
  *
  */
-patch("lesscygwinhacks");
+patch("bindcron");
 /*
  *
  *
Index: eggdrop1.6/src/proto.h
diff -u eggdrop1.6/src/proto.h:1.79 eggdrop1.6/src/proto.h:1.80
--- eggdrop1.6/src/proto.h:1.79	Thu Jan  7 07:48:31 2010
+++ eggdrop1.6/src/proto.h	Mon Mar  8 05:18:07 2010
@@ -7,7 +7,7 @@
  * because they use structures in those
  * (saves including those .h files EVERY time) - Beldin
  *
- * $Id: proto.h,v 1.79 2010/01/07 13:48:31 pseudo Exp $
+ * $Id: proto.h,v 1.80 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -192,6 +192,7 @@
 int addr_match(char *, char *, int, int);
 int mask_match(char *, char *);
 int cidr_match(char *, char *, int);
+int cron_match(const char *, const char *);
 
 #define wild_match(a,b) _wild_match((unsigned char *)(a),(unsigned char *)(b))
 #define wild_match_per(a,b) _wild_match_per((unsigned char *)(a),              \
Index: eggdrop1.6/src/tclegg.h
diff -u eggdrop1.6/src/tclegg.h:1.38 eggdrop1.6/src/tclegg.h:1.39
--- eggdrop1.6/src/tclegg.h:1.38	Thu Feb 18 03:52:29 2010
+++ eggdrop1.6/src/tclegg.h	Mon Mar  8 05:18:07 2010
@@ -2,7 +2,7 @@
  * tclegg.h
  *   stuff used by tcl.c and tclhash.c
  *
- * $Id: tclegg.h,v 1.38 2010/02/18 09:52:29 pseudo Exp $
+ * $Id: tclegg.h,v 1.39 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -46,6 +46,7 @@
 #define MATCH_MASK      2
 #define MATCH_CASE      3
 #define MATCH_MODE      4
+#define MATCH_CRON      5
 
 /*
  * Bitwise 'or' these:
Index: eggdrop1.6/src/tclhash.c
diff -u eggdrop1.6/src/tclhash.c:1.66 eggdrop1.6/src/tclhash.c:1.67
--- eggdrop1.6/src/tclhash.c:1.66	Thu Feb 18 03:52:29 2010
+++ eggdrop1.6/src/tclhash.c	Mon Mar  8 05:18:07 2010
@@ -7,7 +7,7 @@
  *   (non-Tcl) procedure lookups for msg/dcc/file commands
  *   (Tcl) binding internal procedures to msg/dcc/file commands
  *
- * $Id: tclhash.c,v 1.66 2010/02/18 09:52:29 pseudo Exp $
+ * $Id: tclhash.c,v 1.67 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,11 +41,12 @@
 p_tcl_bind_list bind_table_list;
 p_tcl_bind_list H_chat, H_act, H_bcst, H_chon, H_chof, H_load, H_unld, H_link,
                 H_disc, H_dcc, H_chjn, H_chpt, H_bot, H_time, H_nkch, H_away,
-                H_note, H_filt, H_event;
+                H_note, H_filt, H_event, H_cron;
 
 static int builtin_2char();
 static int builtin_3char();
 static int builtin_5int();
+static int builtin_cron();
 static int builtin_char();
 static int builtin_chpt();
 static int builtin_chjn();
@@ -217,6 +218,7 @@
   add_cd_tcl_cmds(cd_cmd_table);
   H_unld = add_bind_table("unld", HT_STACKABLE, builtin_char);
   H_time = add_bind_table("time", HT_STACKABLE, builtin_5int);
+  H_cron = add_bind_table("cron", HT_STACKABLE, builtin_cron);
   H_note = add_bind_table("note", 0, builtin_3char);
   H_nkch = add_bind_table("nkch", HT_STACKABLE, builtin_2char);
   H_load = add_bind_table("load", HT_STACKABLE, builtin_char);
@@ -540,6 +542,17 @@
   return TCL_OK;
 }
 
+static int builtin_cron STDVAR
+{
+  Function F = (Function) cd;
+
+  BADARGS(6, 6, " min hrs dom mon weekday");
+
+  CHECKVALIDITY(builtin_cron);
+  F(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]));
+  return TCL_OK;
+}
+
 static int builtin_char STDVAR
 {
   Function F = (Function) cd;
@@ -735,6 +748,9 @@
   case MATCH_MODE:
     return (wild_match_partial_case(mask, match));
     break;
+  case MATCH_CRON:
+    return (cron_match(mask, match));
+    break;
   default:
     /* Do nothing */
     break;
@@ -1110,6 +1126,27 @@
                  MATCH_MASK | BIND_STACKABLE);
 }
 
+void check_tcl_cron(struct tm *tm)
+{
+  char y[15];
+
+  egg_snprintf(y, sizeof y, "%02d", tm->tm_min);
+  Tcl_SetVar(interp, "_cron1", (char *) y, 0);
+  egg_snprintf(y, sizeof y, "%02d", tm->tm_hour);
+  Tcl_SetVar(interp, "_cron2", (char *) y, 0);
+  egg_snprintf(y, sizeof y, "%02d", tm->tm_mday);
+  Tcl_SetVar(interp, "_cron3", (char *) y, 0);
+  egg_snprintf(y, sizeof y, "%02d", tm->tm_mon + 1);
+  Tcl_SetVar(interp, "_cron4", (char *) y, 0);
+  egg_snprintf(y, sizeof y, "%02d", tm->tm_wday);
+  Tcl_SetVar(interp, "_cron5", (char *) y, 0);
+  egg_snprintf(y, sizeof y, "%02d %02d %02d %02d %02d", tm->tm_min, tm->tm_hour,
+               tm->tm_mday, tm->tm_mon + 1, tm->tm_wday);
+  check_tcl_bind(H_cron, y, 0,
+                 " $_cron1 $_cron2 $_cron3 $_cron4 $_cron5",
+                 MATCH_CRON | BIND_STACKABLE);
+}
+
 void check_tcl_event(const char *event)
 {
   Tcl_SetVar(interp, "_event1", (char *) event, 0);
Index: eggdrop1.6/src/tclhash.h
diff -u eggdrop1.6/src/tclhash.h:1.21 eggdrop1.6/src/tclhash.h:1.22
--- eggdrop1.6/src/tclhash.h:1.21	Thu Feb 18 03:52:29 2010
+++ eggdrop1.6/src/tclhash.h	Mon Mar  8 05:18:07 2010
@@ -1,7 +1,7 @@
 /*
  * tclhash.h
  *
- * $Id: tclhash.h,v 1.21 2010/02/18 09:52:29 pseudo Exp $
+ * $Id: tclhash.h,v 1.22 2010/03/08 11:18:07 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -90,6 +90,7 @@
 int check_tcl_note(const char *, const char *, const char *);
 void check_tcl_listen(const char *, int);
 void check_tcl_time(struct tm *);
+void check_tcl_cron(struct tm *);
 void tell_binds(int, char *);
 void check_tcl_nkch(const char *, const char *);
 void check_tcl_away(const char *, int, const char *);
----------------------- End of diff -----------------------


More information about the Changes mailing list