/[weechat]/weechat/src/common/weeconfig.c
ViewVC logotype

Diff of /weechat/src/common/weeconfig.c

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

revision 1.98 by flashcode, Tue Dec 6 18:21:01 2005 UTC revision 1.99 by flashcode, Sun Dec 11 00:52:33 2005 UTC
# Line 937  t_config_option weechat_options_server[] Line 937  t_config_option weechat_options_server[]
937      N_("comma separated list of notify levels for channels of this server (format: #channel:1,..)"),      N_("comma separated list of notify levels for channels of this server (format: #channel:1,..)"),
938      OPTION_TYPE_STRING, 0, 0, 0,      OPTION_TYPE_STRING, 0, 0, 0,
939      "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels },      "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels },
940      { "server_charset_decode_iso", N_("charset for decoding ISO on server and channels"),
941        N_("comma separated list of charsets for server and channels, "
942           "to decode ISO (format: server:charset,#channel:charset,..)"),
943        OPTION_TYPE_STRING, 0, 0, 0,
944        "", NULL, NULL, &(cfg_server.charset_decode_iso), config_change_noop },
945      { "server_charset_decode_utf", N_("charset for decoding UTF on server and channels"),
946        N_("comma separated list of charsets for server and channels, "
947           "to decode UTF (format: server:charset,#channel:charset,..)"),
948        OPTION_TYPE_STRING, 0, 0, 0,
949        "", NULL, NULL, &(cfg_server.charset_decode_utf), config_change_noop },
950      { "server_charset_encode", N_("charset for encoding messages on server and channels"),
951        N_("comma separated list of charsets for server and channels, "
952           "to encode messages (format: server:charset,#channel:charset,..)"),
953        OPTION_TYPE_STRING, 0, 0, 0,
954        "", NULL, NULL, &(cfg_server.charset_encode), config_change_noop },
955    { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }    { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
956  };  };
957    
# Line 951  t_config_option *weechat_options[CONFIG_ Line 966  t_config_option *weechat_options[CONFIG_
966    
967    
968  /*  /*
969   * get_pos_array_values: returns position of a string in an array of values   * config_get_pos_array_values: return position of a string in an array of values
970   *                       returns -1 if not found, otherwise position   *                              return -1 if not found, otherwise position
971   */   */
972    
973  int  int
974  get_pos_array_values (char **array, char *string)  config_get_pos_array_values (char **array, char *string)
975  {  {
976      int i;      int i;
977            
# Line 1240  config_option_set_value (t_config_option Line 1255  config_option_set_value (t_config_option
1255              *(option->ptr_int) = int_value;              *(option->ptr_int) = int_value;
1256              break;              break;
1257          case OPTION_TYPE_INT_WITH_STRING:          case OPTION_TYPE_INT_WITH_STRING:
1258              int_value = get_pos_array_values (option->array_values, value);              int_value = config_get_pos_array_values (option->array_values,
1259                                                         value);
1260              if (int_value < 0)              if (int_value < 0)
1261                  return -1;                  return -1;
1262              *(option->ptr_int) = int_value;              *(option->ptr_int) = int_value;
# Line 1259  config_option_set_value (t_config_option Line 1275  config_option_set_value (t_config_option
1275  }  }
1276    
1277  /*  /*
1278     * config_option_list_remove: remove an item from a list for an option
1279     *                            (for options with value like: "abc:1,def:blabla")
1280     */
1281    
1282    void
1283    config_option_list_remove (char **string, char *item)
1284    {
1285        char *name, *pos, *pos2;
1286        
1287        if (!string || !(*string))
1288            return;
1289        
1290        name = (char *) malloc (strlen (item) + 2);
1291        strcpy (name, item);
1292        strcat (name, ":");
1293        pos = strstr (*string, name);
1294        free (name);
1295        if (pos)
1296        {
1297            pos2 = pos + strlen (item);
1298            if (pos2[0] == ':')
1299            {
1300                pos2++;
1301                if (pos2[0])
1302                {
1303                    while (pos2[0] && (pos2[0] != ','))
1304                        pos2++;
1305                    if (pos2[0] == ',')
1306                        pos2++;
1307                    if (!pos2[0] && (pos != (*string)))
1308                        pos--;
1309                    strcpy (pos, pos2);
1310                    if (!(*string)[0])
1311                    {
1312                        free (*string);
1313                        *string = NULL;
1314                    }
1315                    else
1316                        (*string) = (char *) realloc (*string, strlen (*string) + 1);
1317                }
1318            }
1319        }
1320    }
1321    
1322    /*
1323     * config_option_list_set: set an item from a list for an option
1324     *                         (for options with value like: "abc:1,def:blabla")
1325     */
1326    
1327    void
1328    config_option_list_set (char **string, char *item, char *value)
1329    {
1330        config_option_list_remove (string, item);
1331        
1332        if (!(*string))
1333        {
1334            (*string) = (char *) malloc (strlen (item) + 1 + strlen (value) + 1);
1335            (*string)[0] = '\0';
1336        }
1337        else
1338            (*string) = (char *) realloc (*string,
1339                                          strlen (*string) + 1 +
1340                                          strlen (item) + 1 + strlen (value) + 1);
1341        
1342        if ((*string)[0])
1343            strcat (*string, ",");
1344        strcat (*string, item);
1345        strcat (*string, ":");
1346        strcat (*string, value);
1347    }
1348    
1349    /*
1350     * config_option_list_get_value: return position of item value in the list
1351     *                               (for options with value like: "abc:1,def:blabla")
1352     */
1353    
1354    void
1355    config_option_list_get_value (char **string, char *item,
1356                                  char **pos_found, int *length)
1357    {
1358        char *name, *pos, *pos2, *pos_comma;
1359        
1360        *pos_found = NULL;
1361        *length = 0;
1362        
1363        if (!string || !(*string))
1364            return;
1365        
1366        name = (char *) malloc (strlen (item) + 2);
1367        strcpy (name, item);
1368        strcat (name, ":");
1369        pos = strstr (*string, name);
1370        free (name);
1371        if (pos)
1372        {
1373            pos2 = pos + strlen (item);
1374            if (pos2[0] == ':')
1375            {
1376                pos2++;
1377                *pos_found = pos2;
1378                pos_comma = strchr (pos2, ',');
1379                if (pos_comma)
1380                    *length = pos_comma - pos2;
1381                else
1382                    *length = strlen (pos2);
1383            }
1384        }
1385    }
1386    
1387    /*
1388   * config_get_server_option_ptr: get a pointer to a server config option   * config_get_server_option_ptr: get a pointer to a server config option
1389   */   */
1390    
# Line 1303  config_get_server_option_ptr (t_irc_serv Line 1429  config_get_server_option_ptr (t_irc_serv
1429          return (void *)(&server->autorejoin);          return (void *)(&server->autorejoin);
1430      if (ascii_strcasecmp (option_name, "server_notify_levels") == 0)      if (ascii_strcasecmp (option_name, "server_notify_levels") == 0)
1431          return (void *)(&server->notify_levels);          return (void *)(&server->notify_levels);
1432        if (ascii_strcasecmp (option_name, "server_charset_decode_iso") == 0)
1433            return (void *)(&server->charset_decode_iso);
1434        if (ascii_strcasecmp (option_name, "server_charset_decode_utf") == 0)
1435            return (void *)(&server->charset_decode_utf);
1436        if (ascii_strcasecmp (option_name, "server_charset_encode") == 0)
1437            return (void *)(&server->charset_encode);
1438      /* option not found */      /* option not found */
1439      return NULL;      return NULL;
1440  }  }
# Line 1357  config_set_server_value (t_irc_server *s Line 1489  config_set_server_value (t_irc_server *s
1489              *((int *)(ptr_data)) = int_value;              *((int *)(ptr_data)) = int_value;
1490              break;              break;
1491          case OPTION_TYPE_INT_WITH_STRING:          case OPTION_TYPE_INT_WITH_STRING:
1492              int_value = get_pos_array_values (ptr_option->array_values, value);              int_value = config_get_pos_array_values (ptr_option->array_values,
1493                                                         value);
1494              if (int_value < 0)              if (int_value < 0)
1495                  return -2;                  return -2;
1496              *((int *)(ptr_data)) = int_value;              *((int *)(ptr_data)) = int_value;
# Line 1527  config_allocate_server (char *filename, Line 1660  config_allocate_server (char *filename,
1660                       cfg_server.password, cfg_server.nick1, cfg_server.nick2,                       cfg_server.password, cfg_server.nick1, cfg_server.nick2,
1661                       cfg_server.nick3, cfg_server.username, cfg_server.realname,                       cfg_server.nick3, cfg_server.username, cfg_server.realname,
1662                       cfg_server.command, cfg_server.command_delay, cfg_server.autojoin,                       cfg_server.command, cfg_server.command_delay, cfg_server.autojoin,
1663                       cfg_server.autorejoin, cfg_server.notify_levels))                       cfg_server.autorejoin, cfg_server.notify_levels,
1664                         cfg_server.charset_decode_iso, cfg_server.charset_decode_utf,
1665                         cfg_server.charset_encode))
1666      {      {
1667          server_free_all ();          server_free_all ();
1668          gui_printf (NULL,          gui_printf (NULL,
# Line 1566  config_default_values () Line 1701  config_default_values ()
1701                              weechat_options[i][j].default_int;                              weechat_options[i][j].default_int;
1702                          break;                          break;
1703                      case OPTION_TYPE_INT_WITH_STRING:                      case OPTION_TYPE_INT_WITH_STRING:
1704                          int_value = get_pos_array_values (                          int_value = config_get_pos_array_values (
1705                              weechat_options[i][j].array_values,                              weechat_options[i][j].array_values,
1706                              weechat_options[i][j].default_string);                              weechat_options[i][j].default_string);
1707                          if (int_value < 0)                          if (int_value < 0)
# Line 2064  config_create_default () Line 2199  config_create_default ()
2199      fprintf (file, "server_command_delay = 0\n");      fprintf (file, "server_command_delay = 0\n");
2200      fprintf (file, "server_autojoin = \"\"\n");      fprintf (file, "server_autojoin = \"\"\n");
2201      fprintf (file, "server_autorejoin = on\n");      fprintf (file, "server_autorejoin = on\n");
2202        fprintf (file, "server_notify_levels = \"\"\n");
2203        fprintf (file, "server_charset_decode_iso = \"\"\n");
2204        fprintf (file, "server_charset_decode_utf = \"\"\n");
2205        fprintf (file, "server_charset_encode = \"\"\n");
2206            
2207      fclose (file);      fclose (file);
2208      chmod (filename, 0600);      chmod (filename, 0600);
# Line 2251  config_write (char *config_name) Line 2390  config_write (char *config_name)
2390                       (ptr_server->autorejoin) ? "on" : "off");                       (ptr_server->autorejoin) ? "on" : "off");
2391              fprintf (file, "server_notify_levels = \"%s\"\n",              fprintf (file, "server_notify_levels = \"%s\"\n",
2392                       (ptr_server->notify_levels) ? ptr_server->notify_levels : "");                       (ptr_server->notify_levels) ? ptr_server->notify_levels : "");
2393                fprintf (file, "server_charset_decode_iso = \"%s\"\n",
2394                         (ptr_server->charset_decode_iso) ? ptr_server->charset_decode_iso : "");
2395                fprintf (file, "server_charset_decode_utf = \"%s\"\n",
2396                         (ptr_server->charset_decode_utf) ? ptr_server->charset_decode_utf : "");
2397                fprintf (file, "server_charset_encode = \"%s\"\n",
2398                         (ptr_server->charset_encode) ? ptr_server->charset_encode : "");
2399          }          }
2400      }      }
2401            

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.99

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