/[weechat]/weechat/src/plugins/scripts/perl/weechat-perl.c
ViewVC logotype

Diff of /weechat/src/plugins/scripts/perl/weechat-perl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by kolter, Mon Oct 24 21:33:48 2005 UTC revision 1.5 by flashcode, Tue Oct 25 17:37:13 2005 UTC
# Line 139  static XS (XS_weechat_register) Line 139  static XS (XS_weechat_register)
139                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
140                                      "\"register\" function");                                      "\"register\" function");
141          XSRETURN (0);          XSRETURN (0);
         return;  
142      }      }
143            
144      name = SvPV (ST (0), integer);      name = SvPV (ST (0), integer);
# Line 156  static XS (XS_weechat_register) Line 155  static XS (XS_weechat_register)
155                                      "already exists with this name)",                                      "already exists with this name)",
156                                      name);                                      name);
157          XSRETURN (0);          XSRETURN (0);
         return;  
158      }      }
159            
160      /* register script */      /* register script */
# Line 179  static XS (XS_weechat_register) Line 177  static XS (XS_weechat_register)
177                                      "\"%s\" (not enough memory)",                                      "\"%s\" (not enough memory)",
178                                      name);                                      name);
179          XSRETURN (0);          XSRETURN (0);
         return;  
180      }      }
181        
182      XSRETURN (1);      XSRETURN (1);
183  }  }
184    
# Line 197  static XS (XS_weechat_print) Line 195  static XS (XS_weechat_print)
195      /* make gcc happy */      /* make gcc happy */
196      (void) cv;      (void) cv;
197            
198        if (!perl_current_script)
199        {
200            perl_plugin->printf_server (perl_plugin,
201                                        "Perl error: unable to print message, "
202                                        "script not initialized");
203            XSRETURN (0);
204        }
205        
206      if ((items < 1) || (items > 3))      if ((items < 1) || (items > 3))
207      {      {
208          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
209                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
210                                      "\"print\" function");                                      "\"print\" function");
211          XSRETURN_NO;          XSRETURN (0);
         return;  
212      }      }
213            
214      channel_name = NULL;      channel_name = NULL;
# Line 220  static XS (XS_weechat_print) Line 225  static XS (XS_weechat_print)
225      perl_plugin->printf (perl_plugin,      perl_plugin->printf (perl_plugin,
226                           server_name, channel_name,                           server_name, channel_name,
227                           "%s", message);                           "%s", message);
228      XSRETURN_YES;      
229        XSRETURN (1);
230  }  }
231    
232  /*  /*
# Line 235  static XS (XS_weechat_print_infobar) Line 241  static XS (XS_weechat_print_infobar)
241      /* make gcc happy */      /* make gcc happy */
242      (void) cv;      (void) cv;
243            
244        if (!perl_current_script)
245        {
246            perl_plugin->printf_server (perl_plugin,
247                                        "Perl error: unable to print infobar message, "
248                                        "script not initialized");
249            XSRETURN (0);
250        }
251        
252      if (items != 2)      if (items != 2)
253      {      {
254          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
255                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
256                                      "\"print_infobar\" function");                                      "\"print_infobar\" function");
257          XSRETURN_NO;          XSRETURN (0);
258      }      }
259            
260      perl_plugin->infobar_printf (perl_plugin,      perl_plugin->infobar_printf (perl_plugin,
261                                   SvIV (ST (0)),                                   SvIV (ST (0)),
262                                   SvPV (ST (1), integer));                                   SvPV (ST (1), integer));
263      XSRETURN_YES;      
264        XSRETURN (1);
265  }  }
266    
267  /*  /*
# Line 262  static XS (XS_weechat_command) Line 277  static XS (XS_weechat_command)
277      /* make gcc happy */      /* make gcc happy */
278      (void) cv;      (void) cv;
279            
280        if (!perl_current_script)
281        {
282            perl_plugin->printf_server (perl_plugin,
283                                        "Perl error: unable to run command, "
284                                        "script not initialized");
285            XSRETURN (0);
286        }
287        
288      if ((items < 1) || (items > 3))      if ((items < 1) || (items > 3))
289      {      {
290          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
291                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
292                                      "\"command\" function");                                      "\"command\" function");
293          XSRETURN_NO;          XSRETURN (0);
         return;  
294      }      }
295            
296      channel_name = NULL;      channel_name = NULL;
# Line 284  static XS (XS_weechat_command) Line 306  static XS (XS_weechat_command)
306      perl_plugin->exec_command (perl_plugin,      perl_plugin->exec_command (perl_plugin,
307                                 server_name, channel_name,                                 server_name, channel_name,
308                                 SvPV (ST (0), integer));                                 SvPV (ST (0), integer));
309      XSRETURN_YES;      
310        XSRETURN (1);
311  }  }
312    
313  /*  /*
# Line 293  static XS (XS_weechat_command) Line 316  static XS (XS_weechat_command)
316    
317  static XS (XS_weechat_add_message_handler)  static XS (XS_weechat_add_message_handler)
318  {  {
319      char *name, *function;      char *irc_command, *function;
320      unsigned int integer;      unsigned int integer;
321      dXSARGS;      dXSARGS;
322            
323      /* make gcc happy */      /* make gcc happy */
324      (void) cv;      (void) cv;
325            
326        if (!perl_current_script)
327        {
328            perl_plugin->printf_server (perl_plugin,
329                                        "Perl error: unable to add message handler, "
330                                        "script not initialized");
331            XSRETURN (0);
332        }
333        
334      if (items != 2)      if (items != 2)
335      {      {
336          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
337                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
338                                      "\"add_message_handler\" function");                                      "\"add_message_handler\" function");
339          XSRETURN_NO;          XSRETURN (0);
340      }      }
341            
342      name = SvPV (ST (0), integer);      irc_command = SvPV (ST (0), integer);
343      function = SvPV (ST (1), integer);      function = SvPV (ST (1), integer);
344            
345      if (perl_current_script)      if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
346          perl_plugin->msg_handler_add (perl_plugin, name,                                        weechat_perl_handler, function,
347                                        weechat_perl_handler, function,                                        (void *)perl_current_script))
348                                        (void *)perl_current_script);          XSRETURN (1);
     else  
     {  
         perl_plugin->printf_server (perl_plugin,  
                                       "Perl error: unable to add message handler, "  
                                       "script not initialized");  
         XSRETURN_NO;  
     }  
349            
350      XSRETURN_YES;      XSRETURN (0);
351  }  }
352    
353  /*  /*
# Line 339  static XS (XS_weechat_add_command_handle Line 363  static XS (XS_weechat_add_command_handle
363      /* make gcc happy */      /* make gcc happy */
364      (void) cv;      (void) cv;
365            
366        if (!perl_current_script)
367        {
368            perl_plugin->printf_server (perl_plugin,
369                                        "Perl error: unable to add command handler, "
370                                        "script not initialized");
371            XSRETURN (0);
372        }
373        
374      if (items < 2)      if (items < 2)
375      {      {
376          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
377                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
378                                      "\"add_command_handler\" function");                                      "\"add_command_handler\" function");
379          XSRETURN_NO;          XSRETURN (0);
380      }      }
381            
382      command = SvPV (ST (0), integer);      command = SvPV (ST (0), integer);
# Line 353  static XS (XS_weechat_add_command_handle Line 385  static XS (XS_weechat_add_command_handle
385      arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;      arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
386      arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;      arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
387            
388      if (perl_current_script)      if (perl_plugin->cmd_handler_add (perl_plugin,
389          perl_plugin->cmd_handler_add (perl_plugin,                                        command,
390                                        command,                                        description,
391                                        description,                                        arguments,
392                                        arguments,                                        arguments_description,
393                                        arguments_description,                                        weechat_perl_handler,
394                                        weechat_perl_handler,                                        function,
395                                        function,                                        (void *)perl_current_script))
396                                        (void *)perl_current_script);          XSRETURN (1);
397      else      
398        XSRETURN (0);
399    }
400    
401    /*
402     * weechat::remove_handler: remove a handler
403     */
404    
405    static XS (XS_weechat_remove_handler)
406    {
407        char *command, *function;
408        unsigned int integer;
409        dXSARGS;
410        
411        /* make gcc happy */
412        (void) cv;
413        
414        if (!perl_current_script)
415      {      {
416          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
417                                        "Perl error: unable to add command handler, "                                      "Perl error: unable to remove handler, "
418                                        "script not initialized");                                      "script not initialized");
419          XSRETURN_NO;          XSRETURN (0);
420      }      }
421        
422      XSRETURN_YES;      if (items != 2)
423        {
424            perl_plugin->printf_server (perl_plugin,
425                                        "Perl error: wrong parameters for "
426                                        "\"remove_handler\" function");
427            XSRETURN (0);
428        }
429        
430        command = SvPV (ST (0), integer);
431        function = SvPV (ST (1), integer);
432        
433        weechat_script_remove_handler (perl_plugin, perl_current_script,
434                                       command, function);
435        
436        XSRETURN (1);
437  }  }
438    
439  /*  /*
# Line 386  static XS (XS_weechat_get_info) Line 449  static XS (XS_weechat_get_info)
449      /* make gcc happy */      /* make gcc happy */
450      (void) cv;      (void) cv;
451            
452        if (!perl_current_script)
453        {
454            perl_plugin->printf_server (perl_plugin,
455                                        "Perl error: unable to get info, "
456                                        "script not initialized");
457            XSRETURN (0);
458        }
459        
460      if ((items < 1) || (items > 3))      if ((items < 1) || (items > 3))
461      {      {
462          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
463                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
464                                      "\"get_info\" function");                                      "\"get_info\" function");
465          XSRETURN_NO;          XSRETURN (0);
466      }      }
467            
468      server_name = NULL;      server_name = NULL;
# Line 411  static XS (XS_weechat_get_info) Line 482  static XS (XS_weechat_get_info)
482          {          {
483              XST_mPV (0, info);              XST_mPV (0, info);
484              free (info);              free (info);
485                return;
486          }          }
         else  
             XST_mPV (0, "");  
487      }      }
488            
489      XSRETURN (1);      XST_mPV (0, "");
490  }  }
491    
492  /*  /*
# Line 433  static XS (XS_weechat_get_dcc_info) Line 503  static XS (XS_weechat_get_dcc_info)
503      (void) cv;      (void) cv;
504      (void) items;      (void) items;
505            
506        if (!perl_current_script)
507        {
508            perl_plugin->printf_server (perl_plugin,
509                                        "Perl error: unable to get DCC info, "
510                                        "script not initialized");
511            XSRETURN (0);
512        }
513        
514      dcc_info = perl_plugin->get_dcc_info (perl_plugin);      dcc_info = perl_plugin->get_dcc_info (perl_plugin);
515      dcc_count = 0;      dcc_count = 0;
516            
517      if (!dcc_info)      if (!dcc_info)
     {  
518          XSRETURN (0);          XSRETURN (0);
         return;  
     }  
519            
520      for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)      for (ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
521      {      {
# Line 473  static XS (XS_weechat_get_dcc_info) Line 548  static XS (XS_weechat_get_dcc_info)
548  }  }
549    
550  /*  /*
551   * weechat::get_config: get value of a config option   * weechat::get_config: get value of a WeeChat config option
552   */   */
553    
554  static XS (XS_weechat_get_config)  static XS (XS_weechat_get_config)
555  {  {
556      char *option, *value;      char *option, *return_value;
557      unsigned int integer;      unsigned int integer;
558      dXSARGS;      dXSARGS;
559            
560      /* make gcc happy */      /* make gcc happy */
561      (void) cv;      (void) cv;
562            
563        if (!perl_current_script)
564        {
565            perl_plugin->printf_server (perl_plugin,
566                                        "Perl error: unable to get config option, "
567                                        "script not initialized");
568            XSRETURN (0);
569        }
570        
571      if (items != 1)      if (items != 1)
572      {      {
573          perl_plugin->printf_server (perl_plugin,          perl_plugin->printf_server (perl_plugin,
574                                      "Perl error: wrong parameters for "                                      "Perl error: wrong parameters for "
575                                      "\"get_config\" function");                                      "\"get_config\" function");
576          XSRETURN_NO;          XSRETURN (0);
577      }      }
578            
579      option = SvPV (ST (0), integer);      option = SvPV (ST (0), integer);
580        
581      if (option)      if (option)
582      {      {
583          value = perl_plugin->get_config (perl_plugin, option);          return_value = perl_plugin->get_config (perl_plugin, option);
584                    
585          if (value)          if (return_value)
586          {          {
587              XST_mPV (0, value);              XST_mPV (0, return_value);
588              free (value);              free (return_value);
589                return;
590          }          }
         else  
             XST_mPV (0, "");  
591      }      }
592            
593      XSRETURN (1);      XST_mPV (0, "");
594    }
595    
596    /*
597     * weechat::set_config: set value of a WeeChat config option
598     */
599    
600    static XS (XS_weechat_set_config)
601    {
602        char *option, *value;
603        unsigned int integer;
604        dXSARGS;
605        
606        /* make gcc happy */
607        (void) cv;
608        
609        if (!perl_current_script)
610        {
611            perl_plugin->printf_server (perl_plugin,
612                                        "Perl error: unable to set config option, "
613                                        "script not initialized");
614            XSRETURN (0);
615        }
616        
617        if (items != 2)
618        {
619            perl_plugin->printf_server (perl_plugin,
620                                        "Perl error: wrong parameters for "
621                                        "\"set_config\" function");
622            XSRETURN (0);
623        }
624        
625        option = SvPV (ST (0), integer);
626        value = SvPV (ST (1), integer);
627        
628        if (option && value)
629        {
630            if (perl_plugin->set_config (perl_plugin, option, value))
631                XSRETURN (1);
632        }
633        
634        XSRETURN (0);
635    }
636    
637    /*
638     * weechat::get_plugin_config: get value of a plugin config option
639     */
640    
641    static XS (XS_weechat_get_plugin_config)
642    {
643        char *option, *return_value;
644        unsigned int integer;
645        dXSARGS;
646        
647        /* make gcc happy */
648        (void) cv;
649        
650        if (!perl_current_script)
651        {
652            perl_plugin->printf_server (perl_plugin,
653                                        "Perl error: unable to get plugin config option, "
654                                        "script not initialized");
655            XSRETURN (0);
656        }
657        
658        if (items != 1)
659        {
660            perl_plugin->printf_server (perl_plugin,
661                                        "Perl error: wrong parameters for "
662                                        "\"get_plugin_config\" function");
663            XSRETURN (0);
664        }
665        
666        option = SvPV (ST (0), integer);
667        
668        if (option)
669        {
670            return_value = weechat_script_get_plugin_config (perl_plugin,
671                                                             perl_current_script,
672                                                             option);
673            
674            if (return_value)
675            {
676                XST_mPV (0, return_value);
677                free (return_value);
678                return;
679            }
680        }    
681        
682        XST_mPV (0, "");
683    }
684    
685    /*
686     * weechat::set_plugin_config: set value of a WeeChat config option
687     */
688    
689    static XS (XS_weechat_set_plugin_config)
690    {
691        char *option, *value;
692        unsigned int integer;
693        dXSARGS;
694        
695        /* make gcc happy */
696        (void) cv;
697        
698        if (!perl_current_script)
699        {
700            perl_plugin->printf_server (perl_plugin,
701                                        "Perl error: unable to set plugin config option, "
702                                        "script not initialized");
703            XSRETURN (0);
704        }
705        
706        if (items != 2)
707        {
708            perl_plugin->printf_server (perl_plugin,
709                                        "Perl error: wrong parameters for "
710                                        "\"set_plugin_config\" function");
711            XSRETURN (0);
712        }
713        
714        option = SvPV (ST (0), integer);
715        value = SvPV (ST (1), integer);
716        
717        if (option && value)
718        {
719            if (weechat_script_set_plugin_config (perl_plugin,
720                                                  perl_current_script,
721                                                  option, value))
722                XSRETURN (1);
723        }
724        
725        XSRETURN (0);
726  }  }
727    
728  /*  /*
# Line 525  weechat_perl_xs_init (pTHX) Line 740  weechat_perl_xs_init (pTHX)
740      newXS ("weechat::command", XS_weechat_command, "weechat");      newXS ("weechat::command", XS_weechat_command, "weechat");
741      newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");      newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
742      newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");      newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
743        newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat");
744      newXS ("weechat::get_info", XS_weechat_get_info, "weechat");      newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
745      newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");      newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
746      newXS ("weechat::get_config", XS_weechat_get_config, "weechat");      newXS ("weechat::get_config", XS_weechat_get_config, "weechat");
747        newXS ("weechat::set_config", XS_weechat_set_config, "weechat");
748        newXS ("weechat::get_plugin_config", XS_weechat_get_plugin_config, "weechat");
749        newXS ("weechat::set_plugin_config", XS_weechat_set_plugin_config, "weechat");
750  }  }
751    
752  /*  /*
753   * wee_perl_load: load a Perl script   * weechat_perl_load: load a Perl script
754   */   */
755    
756  int  int
# Line 689  weechat_perl_cmd (t_weechat_plugin *plug Line 908  weechat_perl_cmd (t_weechat_plugin *plug
908  {  {
909      int argc, path_length, handler_found;      int argc, path_length, handler_found;
910      char **argv, *path_script, *dir_home;      char **argv, *path_script, *dir_home;
911      t_plugin_script *ptr_plugin_script;      t_plugin_script *ptr_script;
912      t_plugin_msg_handler *ptr_msg_handler;      t_plugin_handler *ptr_handler;
     t_plugin_cmd_handler *ptr_cmd_handler;  
913            
914      /* make gcc happy */      /* make gcc happy */
915      (void) server;      (void) server;
# Line 715  weechat_perl_cmd (t_weechat_plugin *plug Line 933  weechat_perl_cmd (t_weechat_plugin *plug
933              plugin->printf_server (plugin, "Registered Perl scripts:");              plugin->printf_server (plugin, "Registered Perl scripts:");
934              if (perl_scripts)              if (perl_scripts)
935              {              {
936                  for (ptr_plugin_script = perl_scripts; ptr_plugin_script;                  for (ptr_script = perl_scripts;
937                       ptr_plugin_script = ptr_plugin_script->next_script)                       ptr_script; ptr_script = ptr_script->next_script)
938                  {                  {
939                      plugin->printf_server (plugin, "  %s v%s%s%s",                      plugin->printf_server (plugin, "  %s v%s%s%s",
940                                             ptr_plugin_script->name,                                             ptr_script->name,
941                                             ptr_plugin_script->version,                                             ptr_script->version,
942                                             (ptr_plugin_script->description[0]) ? " - " : "",                                             (ptr_script->description[0]) ? " - " : "",
943                                             ptr_plugin_script->description);                                             ptr_script->description);
944                  }                  }
945              }              }
946              else              else
# Line 732  weechat_perl_cmd (t_weechat_plugin *plug Line 950  weechat_perl_cmd (t_weechat_plugin *plug
950              plugin->printf_server (plugin, "");              plugin->printf_server (plugin, "");
951              plugin->printf_server (plugin, "Perl message handlers:");              plugin->printf_server (plugin, "Perl message handlers:");
952              handler_found = 0;              handler_found = 0;
953              for (ptr_msg_handler = plugin->msg_handlers; ptr_msg_handler;              for (ptr_handler = plugin->handlers;
954                   ptr_msg_handler = ptr_msg_handler->next_handler)                   ptr_handler; ptr_handler = ptr_handler->next_handler)
955              {              {
956                  if (ptr_msg_handler->msg_handler_args)                  if ((ptr_handler->type == HANDLER_MESSAGE)
957                        && (ptr_handler->handler_args))
958                  {                  {
959                      handler_found = 1;                      handler_found = 1;
960                      plugin->printf_server (plugin, "  IRC(%s) => Perl(%s)",                      plugin->printf_server (plugin, "  IRC(%s) => Perl(%s)",
961                                             ptr_msg_handler->irc_command,                                             ptr_handler->irc_command,
962                                             ptr_msg_handler->msg_handler_args);                                             ptr_handler->handler_args);
963                  }                  }
964              }              }
965              if (!handler_found)              if (!handler_found)
# Line 750  weechat_perl_cmd (t_weechat_plugin *plug Line 969  weechat_perl_cmd (t_weechat_plugin *plug
969              plugin->printf_server (plugin, "");              plugin->printf_server (plugin, "");
970              plugin->printf_server (plugin, "Perl command handlers:");              plugin->printf_server (plugin, "Perl command handlers:");
971              handler_found = 0;              handler_found = 0;
972              for (ptr_cmd_handler = plugin->cmd_handlers; ptr_cmd_handler;              for (ptr_handler = plugin->handlers;
973                   ptr_cmd_handler = ptr_cmd_handler->next_handler)                   ptr_handler; ptr_handler = ptr_handler->next_handler)
974              {              {
975                  if (ptr_cmd_handler->cmd_handler_args)                  if ((ptr_handler->type == HANDLER_COMMAND)
976                        && (ptr_handler->handler_args))
977                  {                  {
978                      handler_found = 1;                      handler_found = 1;
979                      plugin->printf_server (plugin, "  /%s => Perl(%s)",                      plugin->printf_server (plugin, "  /%s => Perl(%s)",
980                                             ptr_cmd_handler->command,                                             ptr_handler->command,
981                                             ptr_cmd_handler->cmd_handler_args);                                             ptr_handler->handler_args);
982                  }                  }
983              }              }
984              if (!handler_found)              if (!handler_found)

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26