summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-22 22:39:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-22 22:39:39 +0200
commit68bc2978099ba0e17045f943081f88fd84eddf92 (patch)
tree9eb77cfa09a64f2f5f913679dc8d3503276f048d /degesch.c
parent933760c2a26732634e86f6695549fb7834b3bb49 (diff)
downloadxK-68bc2978099ba0e17045f943081f88fd84eddf92.tar.gz
xK-68bc2978099ba0e17045f943081f88fd84eddf92.tar.xz
xK-68bc2978099ba0e17045f943081f88fd84eddf92.zip
Bump liberty
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c369
1 files changed, 138 insertions, 231 deletions
diff --git a/degesch.c b/degesch.c
index 81e893c..eb25fd1 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1356,7 +1356,7 @@ static struct channel_user *
channel_user_new (void)
{
struct channel_user *self = xcalloc (1, sizeof *self);
- str_init (&self->prefixes);
+ self->prefixes = str_make ();
return self;
}
@@ -1407,10 +1407,9 @@ channel_new (void)
{
struct channel *self = xcalloc (1, sizeof *self);
self->ref_count = 1;
- str_init (&self->no_param_modes);
- str_map_init (&self->param_modes);
- self->param_modes.free = free;
- strv_init (&self->names_buf);
+ self->no_param_modes = str_make ();
+ self->param_modes = str_map_make (free);
+ self->names_buf = strv_make ();
return self;
}
@@ -1807,34 +1806,34 @@ server_new (struct poller *poller)
self->ref_count = 1;
self->socket = -1;
- str_init (&self->read_buffer);
- str_init (&self->write_buffer);
+ self->read_buffer = str_make ();
+ self->write_buffer = str_make ();
self->state = IRC_DISCONNECTED;
- poller_timer_init (&self->timeout_tmr, poller);
+ self->timeout_tmr = poller_timer_make (poller);
self->timeout_tmr.dispatcher = on_irc_timeout;
self->timeout_tmr.user_data = self;
- poller_timer_init (&self->ping_tmr, poller);
+ self->ping_tmr = poller_timer_make (poller);
self->ping_tmr.dispatcher = on_irc_ping_timeout;
self->ping_tmr.user_data = self;
- poller_timer_init (&self->reconnect_tmr, poller);
+ self->reconnect_tmr = poller_timer_make (poller);
self->reconnect_tmr.dispatcher = (poller_timer_fn) irc_initiate_connect;
self->reconnect_tmr.user_data = self;
- poller_timer_init (&self->autojoin_tmr, poller);
+ self->autojoin_tmr = poller_timer_make (poller);
self->autojoin_tmr.dispatcher = on_irc_autojoin_timeout;
self->autojoin_tmr.user_data = self;
- str_map_init (&self->irc_users);
+ self->irc_users = str_map_make (NULL);
self->irc_users.key_xfrm = irc_strxfrm;
- str_map_init (&self->irc_channels);
+ self->irc_channels = str_map_make (NULL);
self->irc_channels.key_xfrm = irc_strxfrm;
- str_map_init (&self->irc_buffer_map);
+ self->irc_buffer_map = str_map_make (NULL);
self->irc_buffer_map.key_xfrm = irc_strxfrm;
- str_init (&self->irc_user_mode);
+ self->irc_user_mode = str_make ();
server_init_specifics (self);
return self;
@@ -2133,14 +2132,13 @@ app_context_init (struct app_context *self)
{
memset (self, 0, sizeof *self);
- config_init (&self->config);
+ self->config = config_make ();
poller_init (&self->poller);
- str_map_init (&self->servers);
- self->servers.free = (str_map_free_fn) server_unref;
+ self->servers = str_map_make ((str_map_free_fn) server_unref);
self->servers.key_xfrm = tolower_ascii_strxfrm;
- str_map_init (&self->buffers_by_name);
+ self->buffers_by_name = str_map_make (NULL);
self->buffers_by_name.key_xfrm = tolower_ascii_strxfrm;
// So that we don't lose the logo shortly after startup
@@ -2155,8 +2153,8 @@ app_context_init (struct app_context *self)
self->input = input_new ();
self->input->user_data = self;
- strv_init (&self->pending_input);
- str_init (&self->input_buffer);
+ self->pending_input = strv_make ();
+ self->input_buffer = str_make ();
self->nick_palette =
filter_color_cube_for_acceptable_nick_colors (&self->nick_palette_len);
@@ -3020,8 +3018,7 @@ irc_to_utf8 (const char *text)
"\xc5\x93", "\xc2\x9d", "\xc5\xbe", "\xc5\xb8",
};
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
for (const char *p = text; *p; p++)
{
int c = *(unsigned char *) p;
@@ -3159,11 +3156,9 @@ formatter_parse_mirc_color (struct formatter *self, const char *s)
static void
formatter_parse_mirc (struct formatter *self, const char *s)
{
- struct str buf;
- str_init (&buf);
-
FORMATTER_ADD_RESET (self);
+ struct str buf = str_make ();
unsigned char c;
while ((c = *s++))
{
@@ -3341,9 +3336,7 @@ restart:
static void
formatter_addv (struct formatter *self, const char *format, va_list *ap)
{
- struct str buf;
- str_init (&buf);
-
+ struct str buf = str_make ();
while (*format)
{
if (*format != '#' || *++format == '#')
@@ -4010,8 +4003,7 @@ make_log_filename (const char *filename, struct str *output)
static char *
buffer_get_log_path (struct buffer *buffer)
{
- struct str path;
- str_init (&path);
+ struct str path = str_make ();
get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share");
str_append_printf (&path, "/%s/%s", PROGRAM_NAME, "logs");
@@ -4596,9 +4588,9 @@ irc_rehash_and_fix_conflicts (struct server *s)
struct str_map old_channels = s->irc_channels;
struct str_map old_buffer_map = s->irc_buffer_map;
- str_map_init (&s->irc_users);
- str_map_init (&s->irc_channels);
- str_map_init (&s->irc_buffer_map);
+ s->irc_users = str_map_make (NULL);
+ s->irc_channels = str_map_make (NULL);
+ s->irc_buffer_map = str_map_make (NULL);
s->irc_users .key_xfrm = s->irc_strxfrm;
s->irc_channels .key_xfrm = s->irc_strxfrm;
@@ -4620,12 +4612,12 @@ irc_rehash_and_fix_conflicts (struct server *s)
struct user *user;
struct channel *channel;
- str_map_iter_init (&iter, &old_users);
+ iter = str_map_iter_make (&old_users);
while ((user = str_map_iter_next (&iter)))
irc_try_readd_user (s, user,
str_map_find (&old_buffer_map, user->nickname));
- str_map_iter_init (&iter, &old_channels);
+ iter = str_map_iter_make (&old_channels);
while ((channel = str_map_iter_next (&iter)))
irc_try_readd_channel (s, channel,
str_map_find (&old_buffer_map, channel->name));
@@ -4747,8 +4739,7 @@ irc_send (struct server *s, const char *format, ...)
va_list ap;
va_start (ap, format);
- struct str str;
- str_init (&str);
+ struct str str = str_make ();
str_append_vprintf (&str, format, ap);
va_end (ap);
@@ -4822,10 +4813,8 @@ try_finish_quit (struct app_context *ctx)
if (!ctx->quitting)
return;
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
-
bool disconnected_all = true;
+ struct str_map_iter iter = str_map_iter_make (&ctx->servers);
struct server *s;
while ((s = str_map_iter_next (&iter)))
if (irc_is_connected (s))
@@ -4855,8 +4844,7 @@ irc_destroy_transport (struct server *s)
static void
irc_destroy_state (struct server *s)
{
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_channels);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_channels);
struct channel *channel;
while ((channel = str_map_iter_next (&iter)))
irc_left_channel (channel);
@@ -4885,8 +4873,7 @@ irc_disconnect (struct server *s)
{
hard_assert (irc_is_connected (s));
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_buffer_map);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
while ((buffer = str_map_iter_next (&iter)))
log_server (s, buffer, BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT,
@@ -4945,8 +4932,7 @@ initiate_quit (struct app_context *ctx, const char *message)
CALL (ctx->input, hide);
// Initiate a connection close
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
+ struct str_map_iter iter = str_map_iter_make (&ctx->servers);
struct server *s;
while ((s = str_map_iter_next (&iter)))
{
@@ -4990,8 +4976,7 @@ on_irc_autojoin_timeout (void *user_data)
// Since we may not have information from RPL_ISUPPORT yet,
// it's our safest bet to send the channels one at a time
- struct str_map joins_sent;
- str_map_init (&joins_sent);
+ struct str_map joins_sent = str_map_make (NULL);
// We don't know the casemapping yet either, however ASCII should do
joins_sent.key_xfrm = tolower_ascii_strxfrm;
@@ -5000,8 +4985,7 @@ on_irc_autojoin_timeout (void *user_data)
const char *autojoin = get_config_string (s->config, "autojoin");
if (autojoin)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (autojoin, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -5012,13 +4996,11 @@ on_irc_autojoin_timeout (void *user_data)
}
// Then also rejoin any channels from the last disconnect
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_channels);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_channels);
struct channel *channel;
while ((channel = str_map_iter_next (&iter)))
{
- struct str target;
- str_init (&target);
+ struct str target = str_make ();
str_append (&target, channel->name);
const char *key;
@@ -5579,8 +5561,7 @@ irc_autofill_user_info (struct server *s, struct error **e)
static char *
irc_fetch_next_nickname (struct server *s)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (get_config_string (s->config, "nicks"), ",", true, &v);
char *result = NULL;
@@ -5658,7 +5639,7 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
log_server_status (s, s->buffer, "Connection established");
s->state = IRC_CONNECTED;
- poller_fd_init (&s->socket_event, &ctx->poller, s->socket);
+ s->socket_event = poller_fd_make (&ctx->poller, s->socket);
s->socket_event.dispatcher = (poller_fd_fn) on_irc_ready;
s->socket_event.user_data = s;
@@ -5817,8 +5798,7 @@ irc_initiate_connect (struct server *s)
return;
}
- struct strv servers;
- strv_init (&servers);
+ struct strv servers = strv_make ();
cstr_split (addresses, ",", true, &servers);
struct error *e = NULL;
@@ -5866,9 +5846,7 @@ make_chanmode_postfix (struct channel *channel, struct str *modes)
if (channel->no_param_modes.len)
str_append (modes, channel->no_param_modes.str);
- struct str_map_iter iter;
- str_map_iter_init (&iter, &channel->param_modes);
-
+ struct str_map_iter iter = str_map_iter_make (&channel->param_modes);
char *param;
while ((param = str_map_iter_next (&iter)))
str_append_c (modes, iter.link->key[0]);
@@ -5924,8 +5902,7 @@ make_prompt (struct app_context *ctx, struct str *output)
str_append_c (output, '[');
- struct str active_buffers;
- str_init (&active_buffers);
+ struct str active_buffers = str_make ();
make_unseen_prefix (ctx, &active_buffers);
if (active_buffers.len)
str_append_printf (output, "(%s) ", active_buffers.str);
@@ -5937,8 +5914,7 @@ make_prompt (struct app_context *ctx, struct str *output)
if (buffer->type == BUFFER_CHANNEL
&& buffer->channel->users_len)
{
- struct str modes;
- str_init (&modes);
+ struct str modes = str_make ();
make_chanmode_postfix (buffer->channel, &modes);
if (modes.len)
str_append_printf (output, "(+%s)", modes.str);
@@ -5973,8 +5949,7 @@ on_refresh_prompt (struct app_context *ctx)
poller_idle_reset (&ctx->prompt_event);
bool have_attributes = !!get_attribute_printer (stdout);
- struct str prompt;
- str_init (&prompt);
+ struct str prompt = str_make ();
make_prompt (ctx, &prompt);
char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL);
str_free (&prompt);
@@ -6049,8 +6024,7 @@ irc_is_highlight (struct server *s, const char *message)
formatter_init (&f, s->ctx, NULL);
formatter_parse_mirc (&f, message);
- struct str stripped;
- str_init (&stripped);
+ struct str stripped = str_make ();
for (size_t i = 0; i < f.items_len; i++)
{
if (f.items[i].type == FORMATTER_ITEM_TEXT)
@@ -6090,11 +6064,8 @@ irc_is_highlight (struct server *s, const char *message)
static char *
irc_get_privmsg_prefix (struct server *s, struct user *user, const char *target)
{
- struct str prefix;
- str_init (&prefix);
-
- target = irc_skip_statusmsg (s, target);
- if (user && irc_is_channel (s, target))
+ struct str prefix = str_make ();
+ if (user && irc_is_channel (s, (target = irc_skip_statusmsg (s, target))))
{
struct channel *channel;
struct channel_user *channel_user;
@@ -6205,7 +6176,7 @@ mode_processor_do_user (struct mode_processor *self)
{
// Add the new mode prefix while retaining the right order
char *old_prefixes = str_steal (prefixes);
- str_init (prefixes);
+ *prefixes = str_make ();
for (const char *p = all_prefixes; *p; p++)
if (*p == prefix || strchr (old_prefixes, *p))
str_append_c (prefixes, *p);
@@ -6422,9 +6393,7 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
if (msg->params.len < 2)
return;
- struct strv v;
- strv_init (&v);
-
+ struct strv v = strv_make ();
const char *args = "";
if (msg->params.len > 2)
cstr_split ((args = msg->params.vector[2]), " ", true, &v);
@@ -6459,8 +6428,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
log_server_status (s, s->buffer,
"#s: #S", "Capabilities supported", args);
- struct strv chosen; strv_init (&chosen);
- struct strv use; strv_init (&use);
+ struct strv chosen = strv_make ();
+ struct strv use = strv_make ();
cstr_split (get_config_string (s->config, "capabilities"),
",", true, &use);
@@ -6640,8 +6609,7 @@ irc_handle_mode (struct server *s, const struct irc_message *msg)
const char *context = msg->params.vector[0];
// Join the modes back to a single string
- struct strv copy;
- strv_init (&copy);
+ struct strv copy = strv_make ();
strv_append_vector (&copy, msg->params.vector + 1);
char *modes = strv_join (&copy, " ");
strv_free (&copy);
@@ -6761,8 +6729,7 @@ irc_handle_nick (struct server *s, const struct irc_message *msg)
log_nick_self (s, s->buffer, new_nickname);
// Log a message in all open buffers on this server
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_buffer_map);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
while ((buffer = str_map_iter_next (&iter)))
{
@@ -6916,8 +6883,7 @@ static void
irc_send_ctcp_reply (struct server *s,
const char *recipient, const char *format, ...)
{
- struct str m;
- str_init (&m);
+ struct str m = str_make ();
va_list ap;
va_start (ap, format);
@@ -7163,8 +7129,7 @@ irc_try_parse_word_for_userhost (struct server *s, const char *word)
static void
irc_try_parse_welcome_for_userhost (struct server *s, const char *m)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (m, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
if (irc_try_parse_word_for_userhost (s, v.vector[i]))
@@ -7213,8 +7178,7 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
return;
const char *response = msg->params.vector[1];
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (response, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
@@ -7328,8 +7292,7 @@ make_channel_users_list (struct server *s, struct channel *channel)
qsort (entries, n_users, sizeof *entries, channel_user_sort_entry_cmp);
- struct str list;
- str_init (&list);
+ struct str list = str_make ();
for (i = 0; i < n_users; i++)
{
irc_get_channel_user_prefix (s, entries[i].channel_user, &list);
@@ -7368,8 +7331,7 @@ irc_sync_channel_user (struct server *s, struct channel *channel,
static void
irc_process_names (struct server *s, struct channel *channel)
{
- struct str_map present;
- str_map_init (&present);
+ struct str_map present = str_map_make (NULL);
present.key_xfrm = s->irc_strxfrm;
struct strv *updates = &channel->names_buf;
@@ -7418,8 +7380,7 @@ irc_handle_rpl_endofnames (struct server *s, const struct irc_message *msg)
struct channel *channel = str_map_find (&s->irc_channels, channel_name);
if (!strcmp (channel_name, "*"))
{
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_channels);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_channels);
struct channel *channel;
while ((channel = str_map_iter_next (&iter)))
irc_process_names (s, channel);
@@ -7614,11 +7575,8 @@ irc_handle_isupport_chantypes (struct server *s, char *value)
static void
irc_handle_isupport_idchan (struct server *s, char *value)
{
- struct str prefixes;
- str_init (&prefixes);
-
- struct strv v;
- strv_init (&v);
+ struct str prefixes = str_make ();
+ struct strv v = strv_make ();
cstr_split (value, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -7644,8 +7602,7 @@ irc_handle_isupport_statusmsg (struct server *s, char *value)
static void
irc_handle_isupport_chanmodes (struct server *s, char *value)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (value, ",", true, &v);
if (v.len >= 4)
{
@@ -7721,8 +7678,7 @@ irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg)
char *value = param + strcspn (param, "=");
if (*value) *value++ = '\0';
- struct str value_unescaped;
- str_init (&value_unescaped);
+ struct str value_unescaped = str_make ();
unescape_isupport_value (value, &value_unescaped);
dispatch_isupport (s, param, value_unescaped.str);
str_free (&value_unescaped);
@@ -7739,8 +7695,7 @@ irc_process_numeric (struct server *s,
// Get rid of the first parameter, if there's any at all,
// as it contains our nickname and is of no practical use to the user
- struct strv copy;
- strv_init (&copy);
+ struct strv copy = strv_make ();
strv_append_vector (&copy, msg->params.vector + !!msg->params.len);
struct buffer *buffer = s->buffer;
@@ -7782,10 +7737,12 @@ irc_process_numeric (struct server *s,
// Auto-away spams server buffers with activity
case IRC_RPL_NOWAWAY:
flags |= BUFFER_LINE_UNIMPORTANT;
- if (s->irc_user) s->irc_user->away = true; break;
+ if (s->irc_user) s->irc_user->away = true;
+ break;
case IRC_RPL_UNAWAY:
flags |= BUFFER_LINE_UNIMPORTANT;
- if (s->irc_user) s->irc_user->away = false; break;
+ if (s->irc_user) s->irc_user->away = false;
+ break;
case IRC_RPL_LIST:
case IRC_RPL_WHOREPLY:
@@ -7899,8 +7856,7 @@ wrap_message (const char *message,
int message_left = strlen (message);
while (message_left > line_max)
{
- struct str m;
- str_init (&m);
+ struct str m = str_make ();
size_t eaten = wrap_text_for_single_line
(message, message_left, line_max, &m);
@@ -7962,8 +7918,7 @@ send_autosplit_message (struct server *s,
// We might also want to preserve attributes across splits but
// that would make this code a lot more complicated
- struct strv lines;
- strv_init (&lines);
+ struct strv lines = strv_make ();
struct error *e = NULL;
if (!irc_autosplit_message (s, message, fixed_part, &lines, &e))
{
@@ -8020,8 +7975,7 @@ config_dump_children
*data->tail = &level;
data->tail = &level.next;
- struct str_map_iter iter;
- str_map_iter_init (&iter, &object->value.object);
+ struct str_map_iter iter = str_map_iter_make (&object->value.object);
struct config_item *child;
while ((child = str_map_iter_next (&iter)))
{
@@ -8049,9 +8003,7 @@ config_dump_item (struct config_item *item, struct config_dump_data *data)
if (!schema)
return;
- struct str line;
- str_init (&line);
-
+ struct str line = str_make ();
struct config_dump_level *iter = data->head;
if (iter)
{
@@ -8061,8 +8013,7 @@ config_dump_item (struct config_item *item, struct config_dump_data *data)
for (; iter; iter = iter->next)
str_append_printf (&line, ".%s", iter->name);
- struct str value;
- str_init (&value);
+ struct str value = str_make ();
config_item_write (item, false, &value);
// Don't bother writing out null values everywhere
@@ -8132,8 +8083,7 @@ dump_matching_options
static void
save_configuration (struct app_context *ctx)
{
- struct str data;
- str_init (&data);
+ struct str data = str_make ();
serialize_configuration (ctx->config.root, &data);
struct error *e = NULL;
@@ -8234,8 +8184,8 @@ server_remove (struct app_context *ctx, struct server *s)
if (s->buffer)
buffer_remove_safe (ctx, s->buffer);
- struct str_map_unset_iter iter;
- str_map_unset_iter_init (&iter, &s->irc_buffer_map);
+ struct str_map_unset_iter iter =
+ str_map_unset_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
while ((buffer = str_map_unset_iter_next (&iter)))
buffer_remove_safe (ctx, buffer);
@@ -8267,8 +8217,7 @@ server_rename (struct app_context *ctx, struct server *s, const char *new_name)
buffer_rename (ctx, s->buffer, new_name);
- struct str_map_iter iter;
- str_map_iter_init (&iter, &s->irc_buffer_map);
+ struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
while ((buffer = str_map_iter_next (&iter)))
{
@@ -8388,8 +8337,7 @@ static bool
lua_plugin_process_error (struct lua_plugin *self, const char *message,
struct error **e)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (message, "\n", true, &v);
if (v.len < 2)
@@ -8502,8 +8450,7 @@ lua_plugin_push_message (lua_State *L, const struct irc_message *msg)
lua_createtable (L, 0, 4);
lua_createtable (L, msg->tags.len, 0);
- struct str_map_iter iter;
- str_map_iter_init (&iter, &msg->tags);
+ struct str_map_iter iter = str_map_iter_make (&msg->tags);
const char *value;
while ((value = str_map_iter_next (&iter)))
lua_plugin_kv (L, iter.link->key, value);
@@ -9159,8 +9106,7 @@ lua_plugin_push_config_item (lua_State *L, const struct config_item *item)
{
lua_createtable (L, 0, item->value.object.len);
- struct str_map_iter iter;
- str_map_iter_init (&iter, &item->value.object);
+ struct str_map_iter iter = str_map_iter_make (&item->value.object);
struct config_item *child;
while ((child = str_map_iter_next (&iter)))
{
@@ -9591,14 +9537,14 @@ lua_plugin_push_connection (struct lua_plugin *plugin, int socket_fd)
self->plugin = plugin;
set_blocking (socket_fd, false);
- poller_fd_init (&self->socket_event, &plugin->ctx->poller,
- (self->socket_fd = socket_fd));
+ self->socket_event = poller_fd_make
+ (&plugin->ctx->poller, (self->socket_fd = socket_fd));
self->socket_event.dispatcher = (poller_fd_fn) lua_connection_on_ready;
self->socket_event.user_data = self;
poller_fd_set (&self->socket_event, POLLIN);
- str_init (&self->read_buffer);
- str_init (&self->write_buffer);
+ self->read_buffer = str_make ();
+ self->write_buffer = str_make ();
// Make sure the connection doesn't get garbage collected and return it
lua_cache_store (L, self, -1);
@@ -9849,7 +9795,7 @@ lua_plugin_push_wait_timer (struct lua_plugin *plugin, lua_State *L,
self->super.check = lua_wait_timer_check;
self->super.cleanup = lua_wait_timer_cleanup;
- poller_timer_init (&self->timer, &plugin->ctx->poller);
+ self->timer = poller_timer_make (&plugin->ctx->poller);
self->timer.dispatcher = (poller_timer_fn) lua_wait_timer_dispatch;
self->timer.user_data = self;
@@ -10002,7 +9948,7 @@ lua_async_go (lua_State *L)
task->plugin = plugin;
task->thread = thread;
- poller_idle_init (&task->idle, &plugin->ctx->poller);
+ task->idle = poller_idle_make (&plugin->ctx->poller);
task->idle.dispatcher = (poller_idle_fn) lua_task_check;
task->idle.user_data = task;
poller_idle_set (&task->idle);
@@ -10139,8 +10085,7 @@ lua_plugin_push_struct (lua_State *L, struct lua_plugin *self,
}
if (type == ISPECT_STR_MAP)
{
- struct str_map_iter iter;
- str_map_iter_init (&iter, value);
+ struct str_map_iter iter = str_map_iter_make (value);
void *value;
lua_newtable (L);
@@ -10412,8 +10357,7 @@ plugin_find (struct app_context *ctx, const char *name)
static char *
plugin_resolve_relative_filename (const char *filename)
{
- struct strv paths;
- strv_init (&paths);
+ struct strv paths = strv_make ();
get_xdg_data_dirs (&paths);
char *result = resolve_relative_filename_generic
(&paths, PROGRAM_NAME "/plugins/", filename);
@@ -10491,8 +10435,7 @@ load_plugins (struct app_context *ctx)
(ctx->config.root, "behaviour.plugin_autoload");
if (plugins)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (plugins, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
plugin_load (ctx, v.vector[i]);
@@ -10651,9 +10594,7 @@ show_buffers_list (struct app_context *ctx)
int i = 1;
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
{
- struct str s;
- str_init (&s);
-
+ struct str s = str_make ();
int new = iter->new_messages_count - iter->new_unimportant_count;
if (new && iter != ctx->current_buffer)
str_append_printf (&s, " (%d%s)", new, &"!"[!iter->highlighted]);
@@ -10776,8 +10717,7 @@ static bool
handle_command_set_add
(struct config_item *item, const char *value, struct error **e)
{
- struct strv items;
- strv_init (&items);
+ struct strv items = strv_make ();
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
@@ -10801,8 +10741,7 @@ static bool
handle_command_set_remove
(struct config_item *item, const char *value, struct error **e)
{
- struct strv items;
- strv_init (&items);
+ struct strv items = strv_make ();
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
@@ -10851,8 +10790,7 @@ handle_command_set_assign_item (struct app_context *ctx,
}
else
{
- struct strv tmp;
- strv_init (&tmp);
+ struct strv tmp = strv_make ();
dump_matching_options (ctx->config.root, key, &tmp);
log_global_status (ctx, "Option changed: #s", tmp.vector[0]);
strv_free (&tmp);
@@ -10908,8 +10846,7 @@ handle_command_set (struct handler_args *a)
if (*a->arguments)
option = cut_word (&a->arguments);
- struct strv all;
- strv_init (&all);
+ struct strv all = strv_make ();
dump_matching_options (ctx->config.root, option, &all);
bool result = true;
@@ -10985,13 +10922,11 @@ show_aliases_list (struct app_context *ctx)
return true;
}
- struct str_map_iter iter;
- str_map_iter_init (&iter, aliases);
+ struct str_map_iter iter = str_map_iter_make (aliases);
struct config_item *alias;
while ((alias = str_map_iter_next (&iter)))
{
- struct str definition;
- str_init (&definition);
+ struct str definition = str_make ();
if (config_item_type_is_string (alias->type))
config_item_write_string (&definition, &alias->value.string);
else
@@ -11015,8 +10950,7 @@ handle_command_alias (struct handler_args *a)
struct config_item *alias = config_item_string_from_cstr (a->arguments);
- struct str definition;
- str_init (&definition);
+ struct str definition = str_make ();
config_item_write_string (&definition, &alias->value.string);
str_map_set (get_aliases_config (a->ctx), name, alias);
log_global_status (a->ctx, "Created alias /#s: #s", name, definition.str);
@@ -11160,8 +11094,7 @@ handle_command_part (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (cut_word (&a->arguments), ",", true, &v);
for (size_t i = 0; i < v.len; i++)
part_channel (a->s, v.vector[i], a->arguments);
@@ -11203,8 +11136,7 @@ handle_command_cycle (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (cut_word (&a->arguments), ",", true, &v);
for (size_t i = 0; i < v.len; i++)
cycle_channel (a->s, v.vector[i], a->arguments);
@@ -11305,8 +11237,8 @@ mass_channel_mode (struct server *s, const char *channel_name,
size_t n;
for (size_t i = 0; i < v->len; i += n)
{
- struct str modes; str_init (&modes);
- struct str params; str_init (&params);
+ struct str modes = str_make ();
+ struct str params = str_make ();
n = MIN (v->len - i, s->irc_max_modes);
str_append_printf (&modes, "MODE %s %c", channel_name, "-+"[adding]);
@@ -11327,8 +11259,7 @@ static void
mass_channel_mode_mask_list
(struct handler_args *a, bool adding, char mode_char)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (a->arguments, " ", true, &v);
// XXX: this may be a bit too trivial; we could also map nicknames
@@ -11370,8 +11301,7 @@ handle_command_unban (struct handler_args *a)
static bool
handle_command_invite (struct handler_args *a)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (a->arguments, " ", true, &v);
bool result = !!v.len;
@@ -11454,8 +11384,7 @@ show_servers_list (struct app_context *ctx)
log_global_indent (ctx, "");
log_global_indent (ctx, "Servers list:");
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
+ struct str_map_iter iter = str_map_iter_make (&ctx->servers);
struct server *s;
while ((s = str_map_iter_next (&iter)))
log_global_indent (ctx, " #s", s->name);
@@ -11625,8 +11554,7 @@ handle_command_channel_mode
if (!*a->arguments)
return false;
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (a->arguments, " ", true, &v);
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
strv_free (&v);
@@ -11834,8 +11762,7 @@ try_handle_command_help_option (struct app_context *ctx, const char *name)
log_global_indent (ctx, " Default: #s",
schema->default_ ? schema->default_ : "null");
- struct str tmp;
- str_init (&tmp);
+ struct str tmp = str_make ();
config_item_write (item, false, &tmp);
log_global_indent (ctx, " Current value: #s", tmp.str);
str_free (&tmp);
@@ -11901,7 +11828,7 @@ handle_command_help (struct handler_args *a)
static void
init_user_command_map (struct str_map *map)
{
- str_map_init (map);
+ *map = str_map_make (NULL);
map->key_xfrm = tolower_ascii_strxfrm;
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
@@ -11965,8 +11892,7 @@ process_user_command (struct app_context *ctx, struct buffer *buffer,
static const char *
expand_alias_escape (const char *p, const char *arguments, struct str *output)
{
- struct strv words;
- strv_init (&words);
+ struct strv words = strv_make ();
cstr_split (arguments, " ", true, &words);
// TODO: eventually also add support for argument ranges
@@ -11991,9 +11917,7 @@ static void
expand_alias_definition (const char *definition, const char *arguments,
struct strv *commands)
{
- struct str expanded;
- str_init (&expanded);
-
+ struct str expanded = str_make ();
bool escape = false;
for (const char *p = definition; *p; p++)
{
@@ -12005,7 +11929,7 @@ expand_alias_definition (const char *definition, const char *arguments,
else if (*p == ';')
{
strv_append_owned (commands, str_steal (&expanded));
- str_init (&expanded);
+ expanded = str_make ();
}
else if (*p == '$' && p[1])
escape = true;
@@ -12096,9 +12020,7 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
if (process_user_command (ctx, buffer, name, input))
return true;
- struct strv commands;
- strv_init (&commands);
-
+ struct strv commands = strv_make ();
bool result = false;
if (!expand_alias (ctx, name, input, &commands))
log_global_error (ctx, "#s: /#s", "No such command or alias", name);
@@ -12154,8 +12076,7 @@ process_input (struct app_context *ctx, char *user_input)
print_error ("character conversion failed for: %s", "user input");
else
{
- struct strv lines;
- strv_init (&lines);
+ struct strv lines = strv_make ();
// XXX: this interprets commands in pasted text
cstr_split (input, "\r\n", false, &lines);
@@ -12253,7 +12174,7 @@ utf8_common_prefix (const char **vector, size_t len)
struct utf8_iter a[len];
for (size_t i = 0; i < len; i++)
- utf8_iter_init (&a[i], vector[i]);
+ a[i] = utf8_iter_make (vector[i]);
size_t ch_len;
int32_t ch;
@@ -12296,8 +12217,7 @@ complete_command (struct app_context *ctx, struct completion *data,
xstrdup_printf ("%s%s", prefix, handler->name));
}
- struct str_map_iter iter;
- str_map_iter_init (&iter, get_aliases_config (ctx));
+ struct str_map_iter iter = str_map_iter_make (get_aliases_config (ctx));
struct config_item *alias;
while ((alias = str_map_iter_next (&iter)))
{
@@ -12313,9 +12233,7 @@ complete_option (struct app_context *ctx, struct completion *data,
{
(void) data;
- struct strv options;
- strv_init (&options);
-
+ struct strv options = strv_make ();
config_dump (ctx->config.root, &options);
strv_sort (&options);
@@ -12403,8 +12321,7 @@ complete_word (struct app_context *ctx, struct completion *data,
else
try_nicknames = true;
- struct strv words;
- strv_init (&words);
+ struct strv words = strv_make ();
// Add placeholder
strv_append_owned (&words, NULL);
@@ -12453,8 +12370,8 @@ static char *
locale_to_utf8 (struct app_context *ctx, const char *locale,
int *indexes[], size_t n_indexes)
{
- struct str utf8; str_init (&utf8);
- mbstate_t state; memset (&state, 0, sizeof state);
+ mbstate_t state;
+ memset (&state, 0, sizeof state);
size_t remaining = strlen (locale) + 1;
const char *p = locale;
@@ -12465,6 +12382,7 @@ locale_to_utf8 (struct app_context *ctx, const char *locale,
bool fixed[n_indexes];
memset (fixed, 0, sizeof fixed);
+ struct str utf8 = str_make ();
while (true)
{
size_t len = mbrlen (p, remaining, &state);
@@ -12706,9 +12624,7 @@ on_edit_input (int count, int key, void *user_data)
static void
input_editor_process (struct app_context *ctx)
{
- struct str input;
- str_init (&input);
-
+ struct str input = str_make ();
struct error *e = NULL;
if (!read_file (ctx->editor_filename, &input, &e))
{
@@ -13277,8 +13193,7 @@ load_configuration_file (const char *filename, struct error **e)
{
struct config_item *root = NULL;
- struct str data;
- str_init (&data);
+ struct str data = str_make ();
if (!read_file (filename, &data, e))
goto end;
@@ -13387,8 +13302,7 @@ load_configuration (struct app_context *ctx)
static void
load_servers (struct app_context *ctx)
{
- struct str_map_iter iter;
- str_map_iter_init (&iter, get_servers_config (ctx));
+ struct str_map_iter iter = str_map_iter_make (get_servers_config (ctx));
struct config_item *subtree;
while ((subtree = str_map_iter_next (&iter)))
@@ -13658,8 +13572,7 @@ reset_autoaway (struct app_context *ctx)
poller_timer_reset (&ctx->autoaway_tmr);
// Unset any automated statuses that are active right at this moment
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
+ struct str_map_iter iter = str_map_iter_make (&ctx->servers);
struct server *s;
while ((s = str_map_iter_next (&iter)))
{
@@ -13687,8 +13600,7 @@ on_autoaway_timer (struct app_context *ctx)
if (!message || !*message)
return;
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->servers);
+ struct str_map_iter iter = str_map_iter_make (&ctx->servers);
struct server *s;
while ((s = str_map_iter_next (&iter)))
{
@@ -13778,35 +13690,35 @@ on_pending_input (struct app_context *ctx)
static void
init_poller_events (struct app_context *ctx)
{
- poller_fd_init (&ctx->signal_event, &ctx->poller, g_signal_pipe[0]);
+ ctx->signal_event = poller_fd_make (&ctx->poller, g_signal_pipe[0]);
ctx->signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
ctx->signal_event.user_data = ctx;
poller_fd_set (&ctx->signal_event, POLLIN);
- poller_fd_init (&ctx->tty_event, &ctx->poller, STDIN_FILENO);
+ ctx->tty_event = poller_fd_make (&ctx->poller, STDIN_FILENO);
ctx->tty_event.dispatcher = (poller_fd_fn) on_tty_readable;
ctx->tty_event.user_data = ctx;
poller_fd_set (&ctx->tty_event, POLLIN);
- poller_timer_init (&ctx->flush_timer, &ctx->poller);
+ ctx->flush_timer = poller_timer_make (&ctx->poller);
ctx->flush_timer.dispatcher = (poller_timer_fn) on_flush_timer;
ctx->flush_timer.user_data = ctx;
rearm_flush_timer (ctx);
- poller_timer_init (&ctx->date_chg_tmr, &ctx->poller);
+ ctx->date_chg_tmr = poller_timer_make (&ctx->poller);
ctx->date_chg_tmr.dispatcher = (poller_timer_fn) on_date_change_timer;
ctx->date_chg_tmr.user_data = ctx;
rearm_date_change_timer (ctx);
- poller_timer_init (&ctx->autoaway_tmr, &ctx->poller);
+ ctx->autoaway_tmr = poller_timer_make (&ctx->poller);
ctx->autoaway_tmr.dispatcher = (poller_timer_fn) on_autoaway_timer;
ctx->autoaway_tmr.user_data = ctx;
- poller_idle_init (&ctx->prompt_event, &ctx->poller);
+ ctx->prompt_event = poller_idle_make (&ctx->poller);
ctx->prompt_event.dispatcher = (poller_idle_fn) on_refresh_prompt;
ctx->prompt_event.user_data = ctx;
- poller_idle_init (&ctx->input_event, &ctx->poller);
+ ctx->input_event = poller_idle_make (&ctx->poller);
ctx->input_event.dispatcher = (poller_idle_fn) on_pending_input;
ctx->input_event.user_data = ctx;
}
@@ -13850,8 +13762,7 @@ test_config_load (struct config_item *subtree, void *user_data)
static void
test_config (void)
{
- struct config config;
- config_init (&config);
+ struct config config = config_make ();
bool b = true;
config_register_module (&config, "top", test_config_load, &b);
@@ -13864,14 +13775,12 @@ test_config (void)
"top.bar", NULL), invalid, NULL));
config_item_destroy (invalid);
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
serialize_configuration (config.root, &s);
config_load (&config, config_item_parse (s.str, s.len, false, NULL));
str_free (&s);
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
dump_matching_options (config.root, "*foo*", &v);
hard_assert (v.len == 2);
hard_assert (!strcmp (v.vector[0], "top.foo = off"));
@@ -13886,8 +13795,7 @@ test_config (void)
static void
test_aliases (void)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
expand_alias_definition ("/foo; /bar $* $$$;;;$1$2$3$4", "foo bar baz", &v);
hard_assert (v.len == 4);
hard_assert (!strcmp (v.vector[0], "/foo"));
@@ -13904,8 +13812,7 @@ test_wrapping (void)
static const char *split[] =
{ " foo", "bar", "foob", "ar", "fó", "ób", "árb", "áz" };
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
hard_assert (wrap_message (message, 4, &v, NULL));
hard_assert (v.len == N_ELEMENTS (split));
for (size_t i = 0; i < N_ELEMENTS (split); i++)
@@ -13986,8 +13893,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC client.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, NULL, "Experimental IRC client.");
bool format_mode = false;
int c;