[BACK]Return to hooks.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/Attic/hooks.c between version 1.2 and 1.3

version 1.2, 2015/12/11 15:46:57 version 1.3, 2015/12/15 13:43:07
Line 34 
Line 34 
   
 static struct hook      *hooks_find1(struct hooks *, const char *);  static struct hook      *hooks_find1(struct hooks *, const char *);
 static void              hooks_free1(struct hooks *, struct hook *);  static void              hooks_free1(struct hooks *, struct hook *);
   static void              hooks_emptyfn(struct cmd_q *);
   
 static int  static int
 hooks_cmp(struct hook *hook1, struct hook *hook2)  hooks_cmp(struct hook *hook1, struct hook *hook2)
Line 132 
Line 133 
         return (hook);          return (hook);
 }  }
   
 void  static void
 hooks_run(struct hooks *hooks, const char *name, struct client *c)  hooks_emptyfn(struct cmd_q *hooks_cmdq)
 {  {
           struct cmd_q    *cmdq = hooks_cmdq->data;
   
           if (cmdq != NULL) {
                   if (hooks_cmdq->client_exit >= 0)
                           cmdq->client_exit = hooks_cmdq->client_exit;
                   if (!cmdq_free(cmdq))
                           cmdq_continue(cmdq);
           }
           cmdq_free(hooks_cmdq);
   }
   
   int
   hooks_run(struct hooks *hooks, struct client *c, const char *fmt, ...)
   {
         struct hook     *hook;          struct hook     *hook;
         struct cmd_q    *cmdq;          struct cmd_q    *hooks_cmdq;
           va_list          ap;
           char            *name;
   
           va_start(ap, fmt);
           xvasprintf(&name, fmt, ap);
           va_end(ap);
   
         hook = hooks_find(hooks, name);          hook = hooks_find(hooks, name);
         if (hook == NULL)          if (hook == NULL) {
                 return;                  free(name);
                   return (-1);
           }
         log_debug("running hook %s", name);          log_debug("running hook %s", name);
           free(name);
   
         cmdq = cmdq_new(c);          hooks_cmdq = cmdq_new(c);
         cmdq_run(cmdq, hook->cmdlist, NULL);          hooks_cmdq->flags |= CMD_Q_NOHOOKS;
         cmdq_free(cmdq);          hooks_cmdq->parent = NULL;
   
           cmdq_run(hooks_cmdq, hook->cmdlist, NULL);
           cmdq_free(hooks_cmdq);
           return (0);
   }
   
   int
   hooks_wait(struct hooks *hooks, struct cmd_q *cmdq, const char *fmt, ...)
   {
           struct hook     *hook;
           struct cmd_q    *hooks_cmdq;
           va_list          ap;
           char            *name;
   
           va_start(ap, fmt);
           xvasprintf(&name, fmt, ap);
           va_end(ap);
   
           hook = hooks_find(hooks, name);
           if (hook == NULL) {
                   free(name);
                   return (-1);
           }
           log_debug("running hook %s (parent %p)", name, cmdq);
           free(name);
   
           hooks_cmdq = cmdq_new(cmdq->client);
           hooks_cmdq->flags |= CMD_Q_NOHOOKS;
           hooks_cmdq->parent = cmdq;
   
           hooks_cmdq->emptyfn = hooks_emptyfn;
           hooks_cmdq->data = cmdq;
   
           if (cmdq != NULL)
                   cmdq->references++;
           cmdq_run(hooks_cmdq, hook->cmdlist, NULL);
           return (0);
 }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3