/[weechat]/weechat/src/plugins/plugins.c
ViewVC logotype

Diff of /weechat/src/plugins/plugins.c

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

revision 1.27 by flashcode, Mon Oct 17 11:53:46 2005 UTC revision 1.28 by flashcode, Mon Oct 17 14:30:04 2005 UTC
# Line 644  plugin_load (char *filename) Line 644  plugin_load (char *filename)
644          new_plugin->version = strdup (version);          new_plugin->version = strdup (version);
645                    
646          /* functions */          /* functions */
647            new_plugin->ascii_strcasecmp = &weechat_ascii_strcasecmp;
648            new_plugin->explode_string = &weechat_explode_string;
649            new_plugin->free_exploded_string = &weechat_free_exploded_string;
650          new_plugin->mkdir_home = &weechat_plugin_mkdir_home;          new_plugin->mkdir_home = &weechat_plugin_mkdir_home;
651          new_plugin->exec_on_files = &weechat_plugin_exec_on_files;          new_plugin->exec_on_files = &weechat_plugin_exec_on_files;
652          new_plugin->msg_handler_add = &weechat_plugin_msg_handler_add;          new_plugin->msg_handler_add = &weechat_plugin_msg_handler_add;
# Line 659  plugin_load (char *filename) Line 662  plugin_load (char *filename)
662          new_plugin->get_info = &weechat_plugin_get_info;          new_plugin->get_info = &weechat_plugin_get_info;
663          new_plugin->get_dcc_info = &weechat_plugin_get_dcc_info;          new_plugin->get_dcc_info = &weechat_plugin_get_dcc_info;
664          new_plugin->free_dcc_info = &weechat_plugin_free_dcc_info;          new_plugin->free_dcc_info = &weechat_plugin_free_dcc_info;
665          new_plugin->explode_string = &weechat_explode_string;          new_plugin->get_config = &weechat_plugin_get_config;
         new_plugin->free_exploded_string = &weechat_free_exploded_string;  
         new_plugin->ascii_strcasecmp = &weechat_ascii_strcasecmp;  
666                    
667          /* handlers */          /* handlers */
668          new_plugin->msg_handlers = NULL;          new_plugin->msg_handlers = NULL;
# Line 919  plugin_end () Line 920  plugin_end ()
920  /*************************** Public plugin interface **************************/  /*************************** Public plugin interface **************************/
921    
922  /*  /*
923     * weechat_ascii_strcasecmp: locale and case independent string comparison
924     */
925    
926    int
927    weechat_ascii_strcasecmp (t_weechat_plugin *plugin,
928                              char *string1, char *string2)
929    {
930        /* make gcc happy */
931        (void) plugin;
932        
933        return ascii_strcasecmp (string1, string2);
934    }
935    
936    /*
937     * weechat_explode_string: explode a string
938     */
939    
940    char **
941    weechat_explode_string (t_weechat_plugin *plugin, char *string,
942                            char *separators, int num_items_max,
943                            int *num_items)
944    {
945        /* make gcc happy */
946        (void) plugin;
947        
948        if (!plugin || !string || !separators || !num_items)
949            return NULL;
950        
951        return explode_string (string, separators, num_items_max, num_items);
952    }
953    
954    /*
955     * weechat_free_exploded_string: free exploded string
956     */
957    
958    void
959    weechat_free_exploded_string (t_weechat_plugin *plugin, char **exploded_string)
960    {
961        /* make gcc happy */
962        (void) plugin;
963        
964        free_exploded_string (exploded_string);
965    }
966    
967    /*
968   * weechat_plugin_mkdir_home: create a directory for script in WeeChat home   * weechat_plugin_mkdir_home: create a directory for script in WeeChat home
969   */   */
970    
# Line 1151  weechat_plugin_get_info (t_weechat_plugi Line 1197  weechat_plugin_get_info (t_weechat_plugi
1197            
1198      if (ascii_strcasecmp (info, "version") == 0)      if (ascii_strcasecmp (info, "version") == 0)
1199      {      {
1200          return strdup (PACKAGE_STRING);          return strdup (PACKAGE_VERSION);
1201      }      }
1202      else if (ascii_strcasecmp (info, "nick") == 0)      else if (ascii_strcasecmp (info, "nick") == 0)
1203      {      {
# Line 1291  weechat_plugin_free_dcc_info (t_weechat_ Line 1337  weechat_plugin_free_dcc_info (t_weechat_
1337  }  }
1338    
1339  /*  /*
1340   * weechat_explode_string: explode a string   * weechat_plugin_get_config_str_value: return string value for any option
1341     *                                      This function should never be called directly
1342     *                                      (only used by weechat_get_config)
1343   */   */
1344    
1345  char **  char *
1346  weechat_explode_string (t_weechat_plugin *plugin, char *string,  weechat_plugin_get_config_str_value (t_config_option *option, void *value)
                         char *separators, int num_items_max,  
                         int *num_items)  
1347  {  {
1348      /* make gcc happy */      char buf_temp[1024], *color_name;
     (void) plugin;  
1349            
1350      if (!plugin || !string || !separators || !num_items)      if (!value)
1351          return NULL;      {
1352            if (option->option_type == OPTION_TYPE_STRING)
1353                value = option->ptr_string;
1354            else
1355                value = option->ptr_int;
1356        }
1357            
1358      return explode_string (string, separators, num_items_max, num_items);      switch (option->option_type)
1359  }      {
1360            case OPTION_TYPE_BOOLEAN:
1361  /*              return (*((int *)value)) ?
1362   * weechat_free_exploded_string: free exploded string                  strdup ("on") : strdup ("off");
1363   */              break;
1364            case OPTION_TYPE_INT:
1365  void              snprintf (buf_temp, sizeof (buf_temp), "%d",
1366  weechat_free_exploded_string (t_weechat_plugin *plugin, char **exploded_string)                        *((int *)value));
1367  {              return strdup (buf_temp);
1368      /* make gcc happy */              break;
1369      (void) plugin;          case OPTION_TYPE_INT_WITH_STRING:
1370                return option->array_values[*((int *)value)];
1371                break;
1372            case OPTION_TYPE_COLOR:
1373                color_name = gui_get_color_by_value (*((int *)value));
1374                return (color_name) ? strdup (color_name) : strdup ("");
1375                break;
1376            case OPTION_TYPE_STRING:
1377                return (*((char **)value)) ? strdup (*((char **)value)) : strdup ("");
1378                break;
1379        }
1380            
1381      free_exploded_string (exploded_string);      /* should never be executed! */
1382        return NULL;
1383  }  }
1384    
1385  /*  /*
1386   * weechat_ascii_strcasecmp: locale and case independent string comparison   * weechat_get_config: get value of a config option
1387   */   */
1388    
1389  int  char *
1390  weechat_ascii_strcasecmp (t_weechat_plugin *plugin,  weechat_plugin_get_config (t_weechat_plugin *plugin, char *option)
                           char *string1, char *string2)  
1391  {  {
1392        int i, j;
1393        t_irc_server *ptr_server;
1394        char option_name[256];
1395        void *ptr_option_value;
1396        
1397      /* make gcc happy */      /* make gcc happy */
1398      (void) plugin;      (void) plugin;
1399            
1400      return ascii_strcasecmp (string1, string2);      for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
1401        {
1402            if ((i != CONFIG_SECTION_KEYS) && (i != CONFIG_SECTION_ALIAS)
1403                && (i != CONFIG_SECTION_IGNORE) && (i != CONFIG_SECTION_SERVER))
1404            {
1405                for (j = 0; weechat_options[i][j].option_name; j++)
1406                {
1407                    if ((!option) ||
1408                        ((option) && (option[0])
1409                         && (strstr (weechat_options[i][j].option_name, option) != NULL)))
1410                    {
1411                        return weechat_plugin_get_config_str_value (&weechat_options[i][j], NULL);
1412                    }
1413                }
1414            }
1415        }
1416        for (ptr_server = irc_servers; ptr_server;
1417             ptr_server = ptr_server->next_server)
1418        {
1419            for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++)
1420            {
1421                snprintf (option_name, sizeof (option_name), "%s.%s",
1422                          ptr_server->name,
1423                          weechat_options[CONFIG_SECTION_SERVER][i].option_name);
1424                if ((!option) ||
1425                    ((option) && (option[0])
1426                     && (strstr (option_name, option) != NULL)))
1427                {
1428                    ptr_option_value = config_get_server_option_ptr (ptr_server,
1429                                                                     weechat_options[CONFIG_SECTION_SERVER][i].option_name);
1430                    if (ptr_option_value)
1431                    {
1432                        return weechat_plugin_get_config_str_value (&weechat_options[CONFIG_SECTION_SERVER][i],
1433                                                                    ptr_option_value);
1434                    }
1435                }
1436            }
1437        }
1438        
1439        /* option not found */
1440        return NULL;
1441  }  }

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

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