move all score things to lua.
authorPierre Habouzit <madcoder@debian.org>
Sat, 19 May 2007 13:23:08 +0000 (15:23 +0200)
committerPierre Habouzit <madcoder@debian.org>
Sat, 19 May 2007 13:23:08 +0000 (15:23 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
init.h
score.cpkg
score.h

diff --git a/init.h b/init.h
index 49b87d2..ae59a4f 100644 (file)
--- a/init.h
+++ b/init.h
@@ -13,7 +13,6 @@
 
 #include "sort.h"
 #include "mutt.h"
 
 #include "sort.h"
 #include "mutt.h"
-#include "score.h"
 
 #ifndef _MAKEDOC
 #define DT_MASK         0x0f
 
 #ifndef _MAKEDOC
 #define DT_MASK         0x0f
@@ -2606,11 +2605,9 @@ struct command_t Commands[] = {
     {"macro",               mutt_parse_macro,      0},
     {"mono",                mutt_parse_mono,       0},
     {"push",                mutt_parse_push,       0},
     {"macro",               mutt_parse_macro,      0},
     {"mono",                mutt_parse_mono,       0},
     {"push",                mutt_parse_push,       0},
-    {"score",               mutt_parse_score,      0},
     {"uncolor",             mutt_parse_uncolor,    0},
     {"unhook",              mutt_parse_unhook,     0},
     {"unmono",              mutt_parse_unmono,     0},
     {"uncolor",             mutt_parse_uncolor,    0},
     {"unhook",              mutt_parse_unhook,     0},
     {"unmono",              mutt_parse_unmono,     0},
-    {"unscore",             mutt_parse_unscore,    0},
     {"alias",               parse_alias,           0},
     {"attachments",         parse_attachments,     0 },
     {"my_hdr",              parse_my_hdr,          0},
     {"alias",               parse_alias,           0},
     {"attachments",         parse_attachments,     0 },
     {"my_hdr",              parse_my_hdr,          0},
index 40adf78..2b53377 100644 (file)
 #include "score.h"
 @import  "lib-lua/base.cpkg"
 
 #include "score.h"
 @import  "lib-lua/base.cpkg"
 
+typedef struct score_t {
+  char *str;
+  pattern_t *pat;
+  int val;
+  int exact;                    /* if this rule matches, don't evaluate any more */
+  struct score_t *next;
+} score_t;
+DO_INIT(score_t, score);
+static void score_wipe(score_t *sc)
+{
+    pattern_list_wipe(&sc->pat);
+    p_delete(&sc->str);
+}
+DO_NEW(score_t, score);
+DO_DELETE(score_t, score);
+DO_SLIST(score_t, score, score_delete);
+
+static score_t *Score = NULL;
+
 @package mod_score {
     bool enable = 1;
     /*
 @package mod_score {
     bool enable = 1;
     /*
      ** Madmutt scores are always greater than or equal to zero, the default setting
      ** of this variable will never mark a message read.
      */
      ** Madmutt scores are always greater than or equal to zero, the default setting
      ** of this variable will never mark a message read.
      */
-};
 
 
-typedef struct score_t {
-  char *str;
-  pattern_t *pat;
-  int val;
-  int exact;                    /* if this rule matches, don't evaluate any more */
-  struct score_t *next;
-} score_t;
-DO_INIT(score_t, score);
-static void score_wipe(score_t *sc)
-{
-    pattern_list_wipe(&sc->pat);
-    p_delete(&sc->str);
-}
-DO_NEW(score_t, score);
-DO_DELETE(score_t, score);
-DO_SLIST(score_t, score, score_delete);
+    void score(string_t pattern, int value) {
+        const char *pc;
+        score_t **last;
 
 
-static score_t *Score = NULL;
+        for (last = &Score; *last; last = &(*last)->next) {
+            if (!m_strcmp(pattern, (*last)->str))
+                break;
+        }
+        if (!*last) {
+            /* FIXME need a buffer for error */
+            struct pattern_t *pat = mutt_pattern_comp(pattern, 0, NULL);
+
+            if (!pat) {
+                p_delete(&pattern);
+                RETURN();
+            }
+            *last = score_new();
+            (*last)->pat = pat;
+            (*last)->str = pattern;
+        }
+        pc  = pattern;
+        pc += (*last)->exact = (*pc == '=');
+        (*last)->val = value;
+        set_option(OPTNEEDRESCORE);
+        RETURN();
+    };
+
+    void unscore(const string_t pattern) {
+        if (!m_strcmp(pattern, "*")) {
+            score_list_wipe(&Score);
+            set_option(OPTNEEDRESCORE);
+            RETURN();
+        }
+        for (score_t **last = &Score; *last; last = &(*last)->next) {
+            if (!m_strcmp(pattern, (*last)->str)) {
+                score_t *tmp = score_list_pop(last);
+                score_delete(&tmp);
+                set_option(OPTNEEDRESCORE);
+                break;
+            }
+        }
+        RETURN();
+    };
+};
 
 void mutt_check_rescore (CONTEXT * ctx)
 {
 
 void mutt_check_rescore (CONTEXT * ctx)
 {
@@ -91,50 +135,6 @@ void mutt_check_rescore (CONTEXT * ctx)
   unset_option (OPTNEEDRESCORE);
 }
 
   unset_option (OPTNEEDRESCORE);
 }
 
-int mutt_parse_score (BUFFER * buf, BUFFER * s,
-                      unsigned long data __attribute__ ((unused)),
-                      BUFFER * err)
-{
-  char *pattern, *pc;
-  struct pattern_t *pat;
-  score_t **last;
-
-  mutt_extract_token (buf, s, 0);
-  if (!MoreArgs (s)) {
-    m_strcpy(err->data, err->dsize, _("score: too few arguments"));
-    return (-1);
-  }
-  pattern = buf->data;
-  p_clear(buf, 1);
-  mutt_extract_token (buf, s, 0);
-  if (MoreArgs (s)) {
-    p_delete(&pattern);
-    m_strcpy(err->data, err->dsize, _("score: too many arguments"));
-    return (-1);
-  }
-
-  /* look for an existing entry and update the value, else add it to the end
-     of the list */
-  for (last = &Score; *last; last = &(*last)->next) {
-    if (m_strcmp(pattern, (*last)->str) == 0)
-      break;
-  }
-  if (!*last) {
-    if (!(pat = mutt_pattern_comp(pattern, 0, err))) {
-      p_delete(&pattern);
-      return (-1);
-    }
-    *last = score_new();
-    (*last)->pat = pat;
-    (*last)->str = pattern;
-  }
-  pc = buf->data;
-  pc += (*last)->exact = (*pc == '=');
-  (*last)->val = atoi(pc);
-  set_option(OPTNEEDRESCORE);
-  return 0;
-}
-
 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
 {
   score_t *tmp;
 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
 {
   score_t *tmp;
@@ -160,28 +160,4 @@ void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
     _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
 }
 
     _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
 }
 
-int mutt_parse_unscore(BUFFER * buf, BUFFER * s,
-                       unsigned long data __attribute__ ((unused)),
-                       BUFFER * err __attribute__ ((unused)))
-{
-    while (MoreArgs(s)) {
-        mutt_extract_token(buf, s, 0);
-        if (!m_strcmp("*", buf->data)) {
-            score_list_wipe(&Score);
-        } else {
-            score_t **last;
-
-            for (last = &Score; *last; last = &(*last)->next) {
-                if (!m_strcmp(buf->data, (*last)->str)) {
-                    score_t *tmp = score_list_pop(last);
-                    score_delete(&tmp);
-                    break;
-                }
-            }
-        }
-    }
-    set_option (OPTNEEDRESCORE);
-    return 0;
-}
-
 /* vim:set ft=c: */
 /* vim:set ft=c: */
diff --git a/score.h b/score.h
index 5af0405..ddcbb33 100644 (file)
--- a/score.h
+++ b/score.h
@@ -11,9 +11,7 @@
 #define MUTT_SCORE_H
 
 void mutt_check_rescore (CONTEXT *);
 #define MUTT_SCORE_H
 
 void mutt_check_rescore (CONTEXT *);
-int mutt_parse_score (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 void mutt_score_message (CONTEXT *, HEADER *, int);
 void mutt_score_message (CONTEXT *, HEADER *, int);
-int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 
 #include "score.li"
 #endif
 
 #include "score.li"
 #endif