]> granicus.if.org Git - mutt/commitdiff
Byrial Jensen's unhook command patch.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 15 Feb 2000 08:51:00 +0000 (08:51 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 15 Feb 2000 08:51:00 +0000 (08:51 +0000)
doc/manual.sgml.head
doc/muttrc.man.head
hook.c
init.c
init.h
protos.h

index c588fbf00a2bac2d9c7c2f90be47b402fcd5cf45..82bbb1f0b57724d8a9dcbeb84fba4e6468e4be58 100644 (file)
@@ -1381,6 +1381,15 @@ If the filename ends with a vertical bar (|), then <em/filename/ is
 considered to be an executable program from which to read input (eg.
 <tt/source ~/bin/myscript|/).
 
+<sect1>Removing hooks<label id="unhook">
+<p>
+Usage: <tt/unhook/ [ * | <em/hook-type/ ]
+
+This command permits you to flush hooks you have previously defined.
+You can either remove all hooks by giving the ``*'' character as an
+argument, or you can remove all hooks of a specific type by saying
+something like <tt/unhook send-hook/.
+
 <sect>Advanced Usage
 
 <sect1>Regular Expressions<label id="regexp">
index f8a351489b325d8a9e2722501fbfb99590fadd0b..3a46cc936a42167cdad0071200caf5f37e489ea2 100644 (file)
@@ -271,6 +271,11 @@ variables will reset to their system defaults.
 .TP
 \fBsource\fP \fIfilename\fP
 The given file will be evaluated as a configuration file.
+.TP
+\fBunhook\fP [\fB * \fP | \fIhook-type\fP ]
+This command will remove all hooks of a given type, or all hooks
+when \(lq\fB*\fP\(rq is used as an argument.  \fIhook-type\fP
+can be any of the \fB-hook\fP commands documented above.
 .SH PATTERNS
 .PP
 In various places with mutt, including some of the abovementioned
diff --git a/hook.c b/hook.c
index e9be28507dd557a4d3f0adb58a95ec0a9b4577ea..52b8fbdf2a977418e2cc59b43a4b122343e6455f 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -186,6 +186,68 @@ error:
   return (-1);
 }
 
+static void delete_hook (HOOK *h)
+{
+  FREE (&h->command);
+  FREE (&h->rx.pattern);
+  if (h->rx.rx)
+  {
+    regfree (h->rx.rx);
+  }
+  mutt_pattern_free (&h->pattern);
+  FREE (&h);
+}
+
+/* Deletes all hooks of type ``type'', or all defined hooks if ``type'' is 0 */
+static void delete_hooks (int type)
+{
+  HOOK *h;
+  HOOK *prev;
+
+  while (h = Hooks, h && (type == 0 || type == h->type))
+  {
+    Hooks = h->next;
+    delete_hook (h);
+  }
+
+  prev = h; /* Unused assignment to avoid compiler warnings */
+
+  while (h)
+  {
+    if (type == h->type)
+    {
+      prev->next = h->next;
+      delete_hook (h);
+    }
+    else
+      prev = h;
+    h = prev->next;
+  }
+}
+
+int mutt_parse_unhook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  while (MoreArgs (s))
+  {
+    mutt_extract_token (buf, s, 0);
+    if (mutt_strcmp ("*", buf->data) == 0)
+      delete_hooks (0);
+    else
+    {
+      int type = mutt_get_hook_type (buf->data);
+      if (type)
+       delete_hooks (type);
+      else
+      {
+       snprintf (err->data, err->dsize,
+                _("unhook: unknown hook type: %s"), buf->data);
+       return (-1);
+      }
+    }
+  }
+  return 0;
+}
+
 void mutt_folder_hook (char *path)
 {
   HOOK *tmp = Hooks;
diff --git a/init.c b/init.c
index 8cfc5bc88c4220a298358dc70a552a089b54fcaf..6d0fa3ca2759f4c9cf24d7f364ea3cffb49c1d41 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1873,3 +1873,13 @@ void mutt_init (int skip_sys_rc, LIST *commands)
   set_option (OPTWEED); /* turn weeding on by default */
 #endif
 }
+
+int mutt_get_hook_type (const char *name)
+{
+  struct command_t *c;
+
+  for (c = Commands ; c->name ; c++)
+    if (c->func == mutt_parse_hook && mutt_strcasecmp (c->name, name) == 0)
+      return c->data;
+  return 0;
+}
diff --git a/init.h b/init.h
index ca54bf81a9b1b056ba5eb3c108f01c2f17ee083f..a015f7f04d43bb1a774517fed9c6c19ca55c3b02 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2164,6 +2164,7 @@ struct command_t Commands[] = {
   { "toggle",          parse_set,              M_SET_INV },
   { "unalias",         parse_unalias,          0 },
   { "unhdr_order",     parse_unlist,           UL &HeaderOrderList },
+  { "unhook",          mutt_parse_unhook,      0 },
   { "unignore",                parse_unignore,         0 },
   { "unlists",         parse_unlists,          0 },
   { "unmono",          mutt_parse_unmono,      0 },
index 36c1fdc68143f4f079615a525866ef7d0dea8bf2..5874a189fbad8bf3a2256a2d88021deef1d2b0be 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -240,6 +240,7 @@ int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***,
 int _mutt_enter_string (unsigned char *, size_t, int, int, int, int, char ***, int *);
 #define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
 int _mutt_get_field (char *, char *, size_t, int, int, char ***, int *);
+int mutt_get_hook_type (const char *);
 int mutt_get_password (char *, char *, size_t);
 int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **, char *, size_t);
 int mutt_get_tmp_attachment (BODY *);
@@ -268,6 +269,7 @@ int mutt_parse_push (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_rc_line (/* const */ char *, BUFFER *, BUFFER *);
 int mutt_parse_score (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
+int mutt_parse_unhook (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_pattern_func (int, char *);
 int mutt_pipe_attachment (FILE *, BODY *, const char *, char *); 
 int mutt_pipe_message (HEADER *);