Add .clang-format. Reformat everything.

This commit is contained in:
Håvard Pettersson 2017-02-10 19:08:26 -08:00
parent 2947cc1562
commit fa579df623
32 changed files with 994 additions and 1126 deletions

View file

@ -17,16 +17,16 @@
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <weechat/weechat-plugin.h>
#include "twc.h"
#include "twc-list.h"
#include "twc-profile.h"
#include "twc.h"
#include "twc-config.h"
@ -38,19 +38,10 @@ struct t_config_section *twc_config_section_profile_default = NULL;
struct t_config_option *twc_config_friend_request_message;
struct t_config_option *twc_config_short_id_size;
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
{
"save_file",
"autoload",
"autojoin",
"max_friend_requests",
"proxy_address",
"proxy_port",
"proxy_type",
"udp",
"ipv6",
"passphrase",
"logging",
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] = {
"save_file", "autoload", "autojoin", "max_friend_requests",
"proxy_address", "proxy_port", "proxy_type", "udp",
"ipv6", "passphrase", "logging",
};
/**
@ -75,8 +66,7 @@ int
twc_config_profile_read_callback(const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value)
const char *option_name, const char *value)
{
int rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
@ -85,12 +75,13 @@ twc_config_profile_read_callback(const void *pointer, void *data,
char *dot_pos = strrchr(option_name, '.');
if (dot_pos)
{
char *profile_name = weechat_strndup(option_name,
dot_pos-option_name);
char *profile_name =
weechat_strndup(option_name, dot_pos - option_name);
char *option_name = dot_pos + 1;
if (profile_name)
{
int option_index = twc_config_profile_option_search(option_name);
int option_index =
twc_config_profile_option_search(option_name);
if (option_index >= 0)
{
struct t_twc_profile *profile =
@ -101,16 +92,15 @@ twc_config_profile_read_callback(const void *pointer, void *data,
if (profile)
{
rc = weechat_config_option_set(profile->options[option_index],
value, 1);
rc = weechat_config_option_set(
profile->options[option_index], value, 1);
}
else
{
weechat_printf(NULL,
"%s%s: error creating profile \"%s\"",
weechat_prefix("error"),
weechat_plugin->name,
profile_name);
weechat_plugin->name, profile_name);
}
}
@ -121,8 +111,7 @@ twc_config_profile_read_callback(const void *pointer, void *data,
if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR)
{
weechat_printf(NULL,
"%s%s: error creating profile option \"%s\"",
weechat_printf(NULL, "%s%s: error creating profile option \"%s\"",
weechat_prefix("error"), weechat_plugin->name,
option_name);
}
@ -140,7 +129,7 @@ twc_config_check_value_callback(const void *pointer, void *data,
{
int int_value = atoi(value);
// must be multiple of two
/* must be multiple of two */
if (option == twc_config_short_id_size && int_value % 2)
return 0;
@ -190,11 +179,10 @@ twc_config_profile_change_callback(const void *pointer, void *data,
/* option changed for default profile, update all profiles */
size_t index;
struct t_twc_list_item *item;
twc_list_foreach(twc_profiles, index, item)
twc_list_foreach (twc_profiles, index, item)
{
bool logging_enabled
= TWC_PROFILE_OPTION_BOOLEAN(item->profile,
TWC_PROFILE_OPTION_LOGGING);
bool logging_enabled = TWC_PROFILE_OPTION_BOOLEAN(
item->profile, TWC_PROFILE_OPTION_LOGGING);
twc_profile_set_logging(item->profile, logging_enabled);
}
}
@ -202,7 +190,6 @@ twc_config_profile_change_callback(const void *pointer, void *data,
default:
break;
}
}
/**
@ -210,9 +197,8 @@ twc_config_profile_change_callback(const void *pointer, void *data,
*/
struct t_config_option *
twc_config_init_option(struct t_twc_profile *profile,
struct t_config_section *section,
int option_index, const char *option_name,
bool is_default_profile)
struct t_config_section *section, int option_index,
const char *option_name, bool is_default_profile)
{
char *type;
char *description;
@ -251,7 +237,8 @@ twc_config_init_option(struct t_twc_profile *profile,
type = "integer";
description = "maximum amount of friend requests to retain before "
"ignoring new ones";
min = 0; max = INT_MAX;
min = 0;
max = INT_MAX;
default_value = "100";
break;
case TWC_PROFILE_OPTION_PASSPHRASE:
@ -267,14 +254,16 @@ twc_config_init_option(struct t_twc_profile *profile,
case TWC_PROFILE_OPTION_PROXY_PORT:
type = "integer";
description = "proxy port";
min = 0; max = UINT16_MAX;
min = 0;
max = UINT16_MAX;
null_allowed = true;
break;
case TWC_PROFILE_OPTION_PROXY_TYPE:
type = "integer";
description = "proxy type; requires profile reload to take effect";
string_values = "none|socks5|http";
min = 0; max = 0;
min = 0;
max = 0;
default_value = "none";
break;
case TWC_PROFILE_OPTION_SAVEFILE:
@ -308,12 +297,11 @@ twc_config_init_option(struct t_twc_profile *profile,
*index_change_pointer = option_index;
return weechat_config_new_option(
twc_config_file, section,
option_name, type, description, string_values, min, max,
default_value, value, null_allowed,
twc_config_file, section, option_name, type, description, string_values,
min, max, default_value, value, null_allowed,
twc_config_profile_check_value_callback, profile, index_check_pointer,
twc_config_profile_change_callback, profile, index_change_pointer,
NULL, NULL, NULL);
twc_config_profile_change_callback, profile, index_change_pointer, NULL,
NULL, NULL);
}
/**
@ -324,57 +312,39 @@ twc_config_init()
{
twc_config_file = weechat_config_new("tox", NULL, NULL, NULL);
twc_config_section_profile =
weechat_config_new_section(twc_config_file, "profile",
0, 0,
twc_config_profile_read_callback,
NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
twc_config_section_profile = weechat_config_new_section(
twc_config_file, "profile", 0, 0, twc_config_profile_read_callback,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
twc_config_section_profile_default =
weechat_config_new_section(twc_config_file, "profile_default",
0, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
twc_config_section_profile_default = weechat_config_new_section(
twc_config_file, "profile_default", 0, 0, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
for (int i = 0; i < TWC_PROFILE_NUM_OPTIONS; ++i)
{
twc_config_profile_default[i] =
twc_config_init_option(NULL, twc_config_section_profile_default,
i, twc_profile_option_names[i], true);
twc_config_init_option(NULL, twc_config_section_profile_default, i,
twc_profile_option_names[i], true);
}
twc_config_section_look =
weechat_config_new_section(twc_config_file, "look",
0, 0,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL,
NULL, NULL, NULL);
twc_config_section_look = weechat_config_new_section(
twc_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
twc_config_friend_request_message = weechat_config_new_option(
twc_config_file, twc_config_section_look,
"friend_request_message", "string",
twc_config_file, twc_config_section_look, "friend_request_message",
"string",
"message sent with friend requests if no other message is specified",
NULL, 0, 0,
"Hi! Please add me on Tox!", NULL, 0,
twc_config_check_value_callback, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
NULL, 0, 0, "Hi! Please add me on Tox!", NULL, 0,
twc_config_check_value_callback, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
twc_config_short_id_size = weechat_config_new_option(
twc_config_file, twc_config_section_look,
"short_id_size", "integer",
twc_config_file, twc_config_section_look, "short_id_size", "integer",
"length of Tox IDs shown in short format; must be a multiple of two",
NULL, 2, TOX_PUBLIC_KEY_SIZE * 2,
"8", NULL, 0,
twc_config_check_value_callback, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
NULL, 2, TOX_PUBLIC_KEY_SIZE * 2, "8", NULL, 0,
twc_config_check_value_callback, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
}
/**
@ -385,19 +355,18 @@ twc_config_init_profile(struct t_twc_profile *profile)
{
for (int i = 0; i < TWC_PROFILE_NUM_OPTIONS; ++i)
{
// length: name + . + option + \0
size_t length = strlen(profile->name) + 1
+ strlen(twc_profile_option_names[i]) + 1;
/* length: name + . + option + \0 */
size_t length =
strlen(profile->name) + 1 + strlen(twc_profile_option_names[i]) + 1;
char *option_name = malloc(sizeof(*option_name) * length);
if (option_name)
{
snprintf(option_name, length, "%s.%s",
profile->name,
snprintf(option_name, length, "%s.%s", profile->name,
twc_profile_option_names[i]);
profile->options[i] = twc_config_init_option(profile,
twc_config_section_profile, i, option_name, false);
profile->options[i] = twc_config_init_option(
profile, twc_config_section_profile, i, option_name, false);
free(option_name);
}
}
@ -420,4 +389,3 @@ twc_config_write()
{
return weechat_config_write(twc_config_file);
}