summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-23 23:50:27 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-23 23:50:27 +0100
commit9e5725662f944fe437be7ba1b54acbc5fc18dbe1 (patch)
treee5daa605b91dce014582f35fe0330287c1867775 /degesch.c
parent0785a6f417d3a6e43d2d72132e550d517af41bc4 (diff)
downloadxK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.tar.gz
xK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.tar.xz
xK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.zip
Bump liberty
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c333
1 files changed, 167 insertions, 166 deletions
diff --git a/degesch.c b/degesch.c
index b8f7bb1..e7c776e 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1385,7 +1385,7 @@ struct channel
struct str_map param_modes; ///< Parametrized channel modes
struct channel_user *users; ///< Channel users
- struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY
+ struct strv names_buf; ///< Buffer for RPL_NAMREPLY
size_t users_len; ///< User count
bool left_manually; ///< Don't rejoin on reconnect
@@ -1410,7 +1410,7 @@ channel_new (void)
str_init (&self->no_param_modes);
str_map_init (&self->param_modes);
self->param_modes.free = free;
- str_vector_init (&self->names_buf);
+ strv_init (&self->names_buf);
return self;
}
@@ -1423,7 +1423,7 @@ channel_destroy (struct channel *self)
str_map_free (&self->param_modes);
// Owner has to make sure we have no users by now
hard_assert (!self->users && !self->users_len);
- str_vector_free (&self->names_buf);
+ strv_free (&self->names_buf);
free (self);
}
@@ -2004,7 +2004,7 @@ struct completion_hook
/// Tries to add possible completions of "word" to "output"
void (*complete) (struct completion_hook *self,
- struct completion *data, const char *word, struct str_vector *output);
+ struct completion *data, const char *word, struct strv *output);
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2062,7 +2062,7 @@ struct app_context
struct poller_idle prompt_event; ///< Deferred prompt refresh
struct poller_idle input_event; ///< Pending input event
- struct str_vector pending_input; ///< Pending input lines
+ struct strv pending_input; ///< Pending input lines
int *nick_palette; ///< A 256-color palette for nicknames
size_t nick_palette_len; ///< Number of entries in nick_palette
@@ -2156,7 +2156,7 @@ app_context_init (struct app_context *self)
self->input = input_new ();
self->input->user_data = self;
- str_vector_init (&self->pending_input);
+ strv_init (&self->pending_input);
str_init (&self->input_buffer);
self->nick_palette =
@@ -2195,7 +2195,7 @@ app_context_free (struct app_context *self)
iconv_close (self->term_to_utf8);
CALL (self->input, destroy);
- str_vector_free (&self->pending_input);
+ strv_free (&self->pending_input);
str_free (&self->input_buffer);
free (self->editor_filename);
@@ -4991,15 +4991,15 @@ on_irc_autojoin_timeout (void *user_data)
const char *autojoin = get_config_string (s->config, "autojoin");
if (autojoin)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (autojoin, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
irc_send (s, "JOIN %s", v.vector[i]);
str_map_set (&joins_sent, v.vector[i], (void *) 1);
}
- str_vector_free (&v);
+ strv_free (&v);
}
// Then also rejoin any channels from the last disconnect
@@ -5430,7 +5430,7 @@ transport_tls_try_read (struct server *s)
while (true)
{
ERR_clear_error ();
- str_ensure_space (buf, 512);
+ str_reserve (buf, 512);
int n_read = SSL_read (data->ssl, buf->str + buf->len,
buf->alloc - buf->len - 1 /* null byte */);
@@ -5570,8 +5570,8 @@ irc_autofill_user_info (struct server *s, struct error **e)
static char *
irc_fetch_next_nickname (struct server *s)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (get_config_string (s->config, "nicks"), ",", true, &v);
char *result = NULL;
@@ -5581,7 +5581,7 @@ irc_fetch_next_nickname (struct server *s)
// Exhausted all nicknames
s->nick_counter = -1;
- str_vector_free (&v);
+ strv_free (&v);
return result;
}
@@ -5716,7 +5716,7 @@ irc_on_connector_connected (void *user_data, int socket, const char *hostname)
}
static void
-irc_setup_connector (struct server *s, const struct str_vector *addresses)
+irc_setup_connector (struct server *s, const struct strv *addresses)
{
struct connector *connector = xmalloc (sizeof *connector);
connector_init (connector, &s->ctx->poller);
@@ -5752,8 +5752,8 @@ irc_on_socks_connecting (void *user_data,
}
static bool
-irc_setup_connector_socks (struct server *s,
- const struct str_vector *addresses, struct error **e)
+irc_setup_connector_socks (struct server *s, const struct strv *addresses,
+ struct error **e)
{
const char *socks_host = get_config_string (s->config, "socks_host");
int64_t socks_port_int = get_config_integer (s->config, "socks_port");
@@ -5808,15 +5808,15 @@ irc_initiate_connect (struct server *s)
return;
}
- struct str_vector servers;
- str_vector_init (&servers);
+ struct strv servers;
+ strv_init (&servers);
cstr_split (addresses, ",", true, &servers);
struct error *e = NULL;
if (!irc_setup_connector_socks (s, &servers, &e) && !e)
irc_setup_connector (s, &servers);
- str_vector_free (&servers);
+ strv_free (&servers);
if (e)
{
@@ -6413,8 +6413,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
if (msg->params.len < 2)
return;
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
const char *args = "";
if (msg->params.len > 2)
@@ -6450,8 +6450,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
log_server_status (s, s->buffer,
"#s: #S", "Capabilities supported", args);
- struct str_vector chosen; str_vector_init (&chosen);
- struct str_vector use; str_vector_init (&use);
+ struct strv chosen; strv_init (&chosen);
+ struct strv use; strv_init (&use);
cstr_split (get_config_string (s->config, "capabilities"),
",", true, &use);
@@ -6462,18 +6462,18 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
const char *cap = v.vector[i];
for (size_t k = 0; k < use.len; k++)
if (!strcasecmp_ascii (use.vector[k], cap))
- str_vector_add (&chosen, cap);
+ strv_append (&chosen, cap);
}
- char *chosen_str = join_str_vector (&chosen, ' ');
- str_vector_free (&chosen);
- str_vector_free (&use);
+ char *chosen_str = strv_join (&chosen, " ");
+ strv_free (&chosen);
+ strv_free (&use);
irc_send (s, "CAP REQ :%s", chosen_str);
free (chosen_str);
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -6631,11 +6631,11 @@ 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 str_vector copy;
- str_vector_init (&copy);
- str_vector_add_vector (&copy, msg->params.vector + 1);
- char *modes = join_str_vector (&copy, ' ');
- str_vector_free (&copy);
+ struct strv copy;
+ strv_init (&copy);
+ strv_append_vector (&copy, msg->params.vector + 1);
+ char *modes = strv_join (&copy, " ");
+ strv_free (&copy);
if (irc_is_channel (s, context))
{
@@ -7154,13 +7154,13 @@ 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 str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
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]))
break;
- str_vector_free (&v);
+ strv_free (&v);
}
static bool process_input_utf8
@@ -7204,8 +7204,8 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
return;
const char *response = msg->params.vector[1];
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (response, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
@@ -7235,7 +7235,7 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
}
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -7363,7 +7363,7 @@ irc_process_names (struct server *s, struct channel *channel)
str_map_init (&present);
present.key_xfrm = s->irc_strxfrm;
- struct str_vector *updates = &channel->names_buf;
+ struct strv *updates = &channel->names_buf;
for (size_t i = 0; i < updates->len; i++)
{
const char *item = updates->vector[i];
@@ -7384,7 +7384,7 @@ irc_process_names (struct server *s, struct channel *channel)
irc_channel_unlink_user (channel, iter);
str_map_free (&present);
- str_vector_reset (&channel->names_buf);
+ strv_reset (&channel->names_buf);
char *all_users = make_channel_users_list (s, channel);
struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel->name);
@@ -7608,8 +7608,8 @@ irc_handle_isupport_idchan (struct server *s, char *value)
struct str prefixes;
str_init (&prefixes);
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (value, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -7619,7 +7619,7 @@ irc_handle_isupport_idchan (struct server *s, char *value)
if (colon)
str_append_data (&prefixes, pair, colon - pair);
}
- str_vector_free (&v);
+ strv_free (&v);
free (s->irc_idchan_prefixes);
s->irc_idchan_prefixes = str_steal (&prefixes);
@@ -7635,8 +7635,8 @@ irc_handle_isupport_statusmsg (struct server *s, char *value)
static void
irc_handle_isupport_chanmodes (struct server *s, char *value)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (value, ",", true, &v);
if (v.len >= 4)
{
@@ -7649,7 +7649,7 @@ irc_handle_isupport_chanmodes (struct server *s, char *value)
free (s->irc_chanmodes_param_never);
s->irc_chanmodes_param_never = xstrdup (v.vector[3]);
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -7730,9 +7730,9 @@ 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 str_vector copy;
- str_vector_init (&copy);
- str_vector_add_vector (&copy, msg->params.vector + !!msg->params.len);
+ struct strv copy;
+ strv_init (&copy);
+ strv_append_vector (&copy, msg->params.vector + !!msg->params.len);
struct buffer *buffer = s->buffer;
int flags = BUFFER_LINE_STATUS;
@@ -7805,10 +7805,10 @@ irc_process_numeric (struct server *s,
if (buffer)
{
// Join the parameter vector back and send it to the server buffer
- log_server (s, buffer, flags, "#&m", join_str_vector (&copy, ' '));
+ log_server (s, buffer, flags, "#&m", strv_join (&copy, " "));
}
- str_vector_free (&copy);
+ strv_free (&copy);
}
static void
@@ -7882,7 +7882,7 @@ wrap_text_for_single_line (const char *text, size_t text_len,
static bool
wrap_message (const char *message,
- int line_max, struct str_vector *output, struct error **e)
+ int line_max, struct strv *output, struct error **e)
{
if (line_max <= 0)
goto error;
@@ -7901,13 +7901,13 @@ wrap_message (const char *message,
goto error;
}
- str_vector_add_owned (output, str_steal (&m));
+ strv_append_owned (output, str_steal (&m));
message += eaten;
message_left -= eaten;
}
if (message_left)
- str_vector_add (output, message);
+ strv_append (output, message);
return true;
@@ -7923,7 +7923,7 @@ error:
/// so that they don't arrive cut off by the server
static bool
irc_autosplit_message (struct server *s, const char *message,
- int fixed_part, struct str_vector *output, struct error **e)
+ int fixed_part, struct strv *output, struct error **e)
{
// :<nick>!<user>@<host> <fixed-part><message>
int space_in_one_message = 0;
@@ -7935,7 +7935,7 @@ irc_autosplit_message (struct server *s, const char *message,
// However we don't always have the full info for message splitting
if (!space_in_one_message)
- str_vector_add (output, message);
+ strv_append (output, message);
else if (!wrap_message (message, space_in_one_message, output, e))
return false;
return true;
@@ -7953,8 +7953,8 @@ 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 str_vector lines;
- str_vector_init (&lines);
+ struct strv lines;
+ strv_init (&lines);
struct error *e = NULL;
if (!irc_autosplit_message (s, message, fixed_part, &lines, &e))
{
@@ -7967,7 +7967,7 @@ send_autosplit_message (struct server *s,
irc_send (s, "%s %s :%s%s%s", command, target,
prefix, lines.vector[i], suffix);
}
- str_vector_free (&lines);
+ strv_free (&lines);
}
#define SEND_AUTOSPLIT_ACTION(s, target, message) \
@@ -7992,7 +7992,7 @@ struct config_dump_data
{
struct config_dump_level *head; ///< The first level
struct config_dump_level **tail; ///< Where to place further levels
- struct str_vector *output; ///< Where to place new entries
+ struct strv *output; ///< Where to place new entries
};
static void config_dump_item
@@ -8072,11 +8072,11 @@ config_dump_item (struct config_item *item, struct config_dump_data *data)
str_append_printf (&line, " (default: %s)", "null");
str_free (&value);
- str_vector_add_owned (data->output, str_steal (&line));
+ strv_append_owned (data->output, str_steal (&line));
}
static void
-config_dump (struct config_item *root, struct str_vector *output)
+config_dump (struct config_item *root, struct strv *output)
{
struct config_dump_data data;
data.head = NULL;
@@ -8089,23 +8089,23 @@ config_dump (struct config_item *root, struct str_vector *output)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int
-str_vector_sort_cb (const void *a, const void *b)
+strv_sort_cb (const void *a, const void *b)
{
return strcmp (*(const char **) a, *(const char **) b);
}
static void
-str_vector_sort (struct str_vector *self)
+strv_sort (struct strv *self)
{
- qsort (self->vector, self->len, sizeof *self->vector, str_vector_sort_cb);
+ qsort (self->vector, self->len, sizeof *self->vector, strv_sort_cb);
}
static void
dump_matching_options
- (struct config_item *root, const char *mask, struct str_vector *output)
+ (struct config_item *root, const char *mask, struct strv *output)
{
config_dump (root, output);
- str_vector_sort (output);
+ strv_sort (output);
// Filter out results by wildcard matching
for (size_t i = 0; i < output->len; i++)
@@ -8113,7 +8113,7 @@ dump_matching_options
// Yeah, I know
char *key = cstr_cut_until (output->vector[i], " ");
if (fnmatch (mask, key, 0))
- str_vector_remove (output, i--);
+ strv_remove (output, i--);
free (key);
}
}
@@ -8379,8 +8379,8 @@ static bool
lua_plugin_process_error (struct lua_plugin *self, const char *message,
struct error **e)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (message, "\n", true, &v);
if (v.len < 2)
@@ -8394,7 +8394,7 @@ lua_plugin_process_error (struct lua_plugin *self, const char *message,
log_global_debug (self->ctx, " #s", v.vector[i]);
}
- str_vector_free (&v);
+ strv_free (&v);
return false;
}
@@ -8946,7 +8946,7 @@ lua_plugin_push_completion (lua_State *L, struct completion *data)
}
static bool
-lua_completion_hook_process_value (lua_State *L, struct str_vector *output,
+lua_completion_hook_process_value (lua_State *L, struct strv *output,
struct error **e)
{
if (lua_type (L, -1) != LUA_TSTRING)
@@ -8960,12 +8960,12 @@ lua_completion_hook_process_value (lua_State *L, struct str_vector *output,
if (!utf8_validate (value, len))
return error_set (e, "must be valid UTF-8");
- str_vector_add (output, value);
+ strv_append (output, value);
return true;
}
static bool
-lua_completion_hook_process (lua_State *L, struct str_vector *output,
+lua_completion_hook_process (lua_State *L, struct strv *output,
struct error **e)
{
if (lua_isnil (L, -1))
@@ -8983,7 +8983,7 @@ lua_completion_hook_process (lua_State *L, struct str_vector *output,
static void
lua_completion_hook_complete (struct completion_hook *self,
- struct completion *data, const char *word, struct str_vector *output)
+ struct completion *data, const char *word, struct strv *output)
{
struct lua_hook *hook =
CONTAINER_OF (self, struct lua_hook, data.c_hook);
@@ -10403,12 +10403,12 @@ plugin_find (struct app_context *ctx, const char *name)
static char *
plugin_resolve_relative_filename (const char *filename)
{
- struct str_vector paths;
- str_vector_init (&paths);
+ struct strv paths;
+ strv_init (&paths);
get_xdg_data_dirs (&paths);
char *result = resolve_relative_filename_generic
(&paths, PROGRAM_NAME "/plugins/", filename);
- str_vector_free (&paths);
+ strv_free (&paths);
return result;
}
@@ -10482,12 +10482,12 @@ load_plugins (struct app_context *ctx)
(ctx->config.root, "behaviour.plugin_autoload");
if (plugins)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (plugins, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
plugin_load (ctx, v.vector[i]);
- str_vector_free (&v);
+ strv_free (&v);
}
}
@@ -10753,9 +10753,9 @@ handle_command_buffer (struct handler_args *a)
static bool
replace_string_array
- (struct config_item *item, struct str_vector *array, struct error **e)
+ (struct config_item *item, struct strv *array, struct error **e)
{
- char *changed = join_str_vector (array, ',');
+ char *changed = strv_join (array, ",");
struct str tmp = { .str = changed, .len = strlen (changed) };
bool result = config_item_set_from (item,
config_item_string_array (&tmp), e);
@@ -10767,24 +10767,24 @@ static bool
handle_command_set_add
(struct config_item *item, const char *value, struct error **e)
{
- struct str_vector items;
- str_vector_init (&items);
+ struct strv items;
+ strv_init (&items);
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
- str_vector_reset (&items);
+ strv_reset (&items);
// FIXME: handle multiple items properly
bool result = false;
- if (str_vector_find (&items, value) != -1)
+ if (strv_find (&items, value) != -1)
error_set (e, "already present in the array: %s", value);
else
{
- str_vector_add (&items, value);
+ strv_append (&items, value);
result = replace_string_array (item, &items, e);
}
- str_vector_free (&items);
+ strv_free (&items);
return result;
}
@@ -10792,25 +10792,25 @@ static bool
handle_command_set_remove
(struct config_item *item, const char *value, struct error **e)
{
- struct str_vector items;
- str_vector_init (&items);
+ struct strv items;
+ strv_init (&items);
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
- str_vector_reset (&items);
+ strv_reset (&items);
// FIXME: handle multiple items properly
bool result = false;
- ssize_t i = str_vector_find (&items, value);
+ ssize_t i = strv_find (&items, value);
if (i == -1)
error_set (e, "not present in the array: %s", value);
else
{
- str_vector_remove (&items, i);
+ strv_remove (&items, i);
result = replace_string_array (item, &items, e);
}
- str_vector_free (&items);
+ strv_free (&items);
return result;
}
@@ -10842,17 +10842,17 @@ handle_command_set_assign_item (struct app_context *ctx,
}
else
{
- struct str_vector tmp;
- str_vector_init (&tmp);
+ struct strv tmp;
+ strv_init (&tmp);
dump_matching_options (ctx->config.root, key, &tmp);
log_global_status (ctx, "Option changed: #s", tmp.vector[0]);
- str_vector_free (&tmp);
+ strv_free (&tmp);
}
}
static bool
handle_command_set_assign
- (struct app_context *ctx, struct str_vector *all, char *arguments)
+ (struct app_context *ctx, struct strv *all, char *arguments)
{
char *op = cut_word (&arguments);
bool add = false;
@@ -10899,8 +10899,8 @@ handle_command_set (struct handler_args *a)
if (*a->arguments)
option = cut_word (&a->arguments);
- struct str_vector all;
- str_vector_init (&all);
+ struct strv all;
+ strv_init (&all);
dump_matching_options (ctx->config.root, option, &all);
bool result = true;
@@ -10915,7 +10915,7 @@ handle_command_set (struct handler_args *a)
else
result = handle_command_set_assign (ctx, &all, a->arguments);
- str_vector_free (&all);
+ strv_free (&all);
return result;
}
@@ -11161,12 +11161,12 @@ handle_command_part (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
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);
- str_vector_free (&v);
+ strv_free (&v);
}
else if (a->buffer->type != BUFFER_CHANNEL)
log_server_error (a->s, a->buffer, "#s: #s", "Can't part",
@@ -11204,12 +11204,12 @@ handle_command_cycle (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
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);
- str_vector_free (&v);
+ strv_free (&v);
}
else if (a->buffer->type != BUFFER_CHANNEL)
log_server_error (a->s, a->buffer, "#s: #s", "Can't cycle",
@@ -11301,7 +11301,7 @@ handle_command_kickban (struct handler_args *a)
static void
mass_channel_mode (struct server *s, const char *channel_name,
- bool adding, char mode_char, struct str_vector *v)
+ bool adding, char mode_char, struct strv *v)
{
size_t n;
for (size_t i = 0; i < v->len; i += n)
@@ -11328,8 +11328,8 @@ static void
mass_channel_mode_mask_list
(struct handler_args *a, bool adding, char mode_char)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
// XXX: this may be a bit too trivial; we could also map nicknames
@@ -11345,7 +11345,7 @@ mass_channel_mode_mask_list
}
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
- str_vector_free (&v);
+ strv_free (&v);
}
static bool
@@ -11371,15 +11371,15 @@ handle_command_unban (struct handler_args *a)
static bool
handle_command_invite (struct handler_args *a)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
bool result = !!v.len;
for (size_t i = 0; i < v.len; i++)
irc_send (a->s, "INVITE %s %s", v.vector[i], a->channel_name);
- str_vector_free (&v);
+ strv_free (&v);
return result;
}
@@ -11626,11 +11626,11 @@ handle_command_channel_mode
if (!*a->arguments)
return false;
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
- str_vector_free (&v);
+ strv_free (&v);
return true;
}
@@ -11966,8 +11966,8 @@ 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 str_vector words;
- str_vector_init (&words);
+ struct strv words;
+ strv_init (&words);
cstr_split (arguments, " ", true, &words);
// TODO: eventually also add support for argument ranges
@@ -11984,13 +11984,13 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
else
str_append_printf (output, "$%c", *p);
- str_vector_free (&words);
+ strv_free (&words);
return ++p;
}
static void
expand_alias_definition (const char *definition, const char *arguments,
- struct str_vector *commands)
+ struct strv *commands)
{
struct str expanded;
str_init (&expanded);
@@ -12005,7 +12005,7 @@ expand_alias_definition (const char *definition, const char *arguments,
}
else if (*p == ';')
{
- str_vector_add_owned (commands, str_steal (&expanded));
+ strv_append_owned (commands, str_steal (&expanded));
str_init (&expanded);
}
else if (*p == '$' && p[1])
@@ -12013,12 +12013,12 @@ expand_alias_definition (const char *definition, const char *arguments,
else
str_append_c (&expanded, *p);
}
- str_vector_add_owned (commands, str_steal (&expanded));
+ strv_append_owned (commands, str_steal (&expanded));
}
static bool
expand_alias (struct app_context *ctx,
- const char *alias_name, char *input, struct str_vector *commands)
+ const char *alias_name, char *input, struct strv *commands)
{
struct config_item *entry =
str_map_find (get_aliases_config (ctx), alias_name);
@@ -12072,7 +12072,7 @@ send_message_to_buffer (struct app_context *ctx, struct buffer *buffer,
static bool
process_alias (struct app_context *ctx, struct buffer *buffer,
- struct str_vector *commands, int level)
+ struct strv *commands, int level)
{
for (size_t i = 0; i < commands->len; i++)
log_global_debug (ctx, "Alias expanded to: ###d: \"#s\"",
@@ -12097,8 +12097,8 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
if (process_user_command (ctx, buffer, name, input))
return true;
- struct str_vector commands;
- str_vector_init (&commands);
+ struct strv commands;
+ strv_init (&commands);
bool result = false;
if (!expand_alias (ctx, name, input, &commands))
@@ -12108,7 +12108,7 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
else
result = process_alias (ctx, buffer, &commands, alias_level);
- str_vector_free (&commands);
+ strv_free (&commands);
return result;
}
@@ -12155,8 +12155,8 @@ process_input (struct app_context *ctx, char *user_input)
print_error ("character conversion failed for: %s", "user input");
else
{
- struct str_vector lines;
- str_vector_init (&lines);
+ struct strv lines;
+ strv_init (&lines);
// XXX: this interprets commands in pasted text
cstr_split (input, "\r\n", false, &lines);
@@ -12164,7 +12164,7 @@ process_input (struct app_context *ctx, char *user_input)
(void) process_input_utf8 (ctx,
ctx->current_buffer, lines.vector[i], 0);
- str_vector_free (&lines);
+ strv_free (&lines);
}
free (input);
}
@@ -12277,7 +12277,7 @@ utf8_common_prefix (const char **vector, size_t len)
static void
complete_command (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
@@ -12293,7 +12293,7 @@ complete_command (struct app_context *ctx, struct completion *data,
{
struct command_handler *handler = &g_command_handlers[i];
if (!strncasecmp_ascii (word, handler->name, word_len))
- str_vector_add_owned (output,
+ strv_append_owned (output,
xstrdup_printf ("%s%s", prefix, handler->name));
}
@@ -12303,22 +12303,22 @@ complete_command (struct app_context *ctx, struct completion *data,
while ((alias = str_map_iter_next (&iter)))
{
if (!strncasecmp_ascii (word, iter.link->key, word_len))
- str_vector_add_owned (output,
+ strv_append_owned (output,
xstrdup_printf ("%s%s", prefix, iter.link->key));
}
}
static void
complete_option (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
- struct str_vector options;
- str_vector_init (&options);
+ struct strv options;
+ strv_init (&options);
config_dump (ctx->config.root, &options);
- str_vector_sort (&options);
+ strv_sort (&options);
// Wildcard expansion is an interesting side-effect
char *mask = xstrdup_printf ("%s*", word);
@@ -12326,17 +12326,17 @@ complete_option (struct app_context *ctx, struct completion *data,
{
char *key = cstr_cut_until (options.vector[i], " ");
if (!fnmatch (mask, key, 0))
- str_vector_add_owned (output, key);
+ strv_append_owned (output, key);
else
free (key);
}
free (mask);
- str_vector_free (&options);
+ strv_free (&options);
}
static void
complete_topic (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
@@ -12351,7 +12351,7 @@ complete_topic (struct app_context *ctx, struct completion *data,
{
// We must prepend the channel name if the topic itself starts
// with something that could be regarded as a channel name
- str_vector_add_owned (output, irc_is_channel (buffer->server, topic)
+ strv_append_owned (output, irc_is_channel (buffer->server, topic)
? xstrdup_printf ("%s %s", buffer->channel->name, topic)
: xstrdup (topic));
}
@@ -12359,14 +12359,14 @@ complete_topic (struct app_context *ctx, struct completion *data,
static void
complete_nicknames (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
struct buffer *buffer = ctx->current_buffer;
if (buffer->type == BUFFER_SERVER)
{
struct user *self_user = buffer->server->irc_user;
if (self_user)
- str_vector_add (output, self_user->nickname);
+ strv_append (output, self_user->nickname);
}
if (buffer->type != BUFFER_CHANNEL)
return;
@@ -12377,7 +12377,7 @@ complete_nicknames (struct app_context *ctx, struct completion *data,
const char *nickname = iter->user->nickname;
if (irc_server_strncmp (buffer->server, word, nickname, word_len))
continue;
- str_vector_add_owned (output, data->location == 0
+ strv_append_owned (output, data->location == 0
? xstrdup_printf ("%s:", nickname)
: xstrdup (nickname));
}
@@ -12404,11 +12404,11 @@ complete_word (struct app_context *ctx, struct completion *data,
else
try_nicknames = true;
- struct str_vector words;
- str_vector_init (&words);
+ struct strv words;
+ strv_init (&words);
// Add placeholder
- str_vector_add_owned (&words, NULL);
+ strv_append_owned (&words, NULL);
if (try_commands) complete_command (ctx, data, word, &words);
if (try_options) complete_option (ctx, data, word, &words);
@@ -12424,7 +12424,7 @@ complete_word (struct app_context *ctx, struct completion *data,
if (words.len == 1)
{
// Nothing matched
- str_vector_free (&words);
+ strv_free (&words);
return NULL;
}
@@ -13086,7 +13086,7 @@ on_readline_input (char *line)
// readline always erases the input line after returning from here,
// but we don't want that in order to allow correct buffer switching
- str_vector_add_owned (&ctx->pending_input, line);
+ strv_append_owned (&ctx->pending_input, line);
poller_idle_set (&ctx->input_event);
}
else
@@ -13229,7 +13229,7 @@ on_editline_return (EditLine *editline, int key)
// process_input() expects a multibyte string
const LineInfo *info_mb = el_line (editline);
- str_vector_add_owned (&ctx->pending_input,
+ strv_append_owned (&ctx->pending_input,
xstrndup (info_mb->buffer, info_mb->lastchar - info_mb->buffer));
poller_idle_set (&ctx->input_event);
@@ -13574,7 +13574,7 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
// There's no other way with libedit, as both el_getc() in a function
// handler and CC_ARGHACK would block execution
struct str *buf = &ctx->input_buffer;
- str_ensure_space (buf, 1);
+ str_reserve (buf, 1);
if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;
buf->str[++buf->len] = '\0';
@@ -13626,7 +13626,7 @@ static void
process_bracketed_paste (const struct pollfd *fd, struct app_context *ctx)
{
struct str *buf = &ctx->input_buffer;
- str_ensure_space (buf, 1);
+ str_reserve (buf, 1);
if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;
buf->str[++buf->len] = '\0';
@@ -13736,6 +13736,7 @@ rearm_flush_timer (struct app_context *ctx)
static void
on_flush_timer (struct app_context *ctx)
{
+ // TODO: maybe also garbage collect all plugins?
// I guess we don't need to do anything more complicated
fflush (NULL);
rearm_flush_timer (ctx);
@@ -13777,7 +13778,7 @@ on_pending_input (struct app_context *ctx)
poller_idle_reset (&ctx->input_event);
for (size_t i = 0; i < ctx->pending_input.len; i++)
process_input (ctx, ctx->pending_input.vector[i]);
- str_vector_reset (&ctx->pending_input);
+ strv_reset (&ctx->pending_input);
}
static void
@@ -13875,13 +13876,13 @@ test_config (void)
config_load (&config, config_item_parse (s.str, s.len, false, NULL));
str_free (&s);
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
dump_matching_options (config.root, "*foo*", &v);
hard_assert (v.len == 2);
hard_assert (!strcmp (v.vector[0], "top.foo = off"));
hard_assert (!strcmp (v.vector[1], "top.foobar = \"qux\""));
- str_vector_free (&v);
+ strv_free (&v);
config_free (&config);
}
@@ -13891,15 +13892,15 @@ test_config (void)
static void
test_aliases (void)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
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"));
hard_assert (!strcmp (v.vector[1], " /bar foo bar baz $;"));
hard_assert (!strcmp (v.vector[2], ""));
hard_assert (!strcmp (v.vector[3], "foobarbaz"));
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -13909,13 +13910,13 @@ test_wrapping (void)
static const char *split[] =
{ " foo", "bar", "foob", "ar", "fó", "ób", "árb", "áz" };
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
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++)
hard_assert (!strcmp (v.vector[i], split[i]));
- str_vector_free (&v);
+ strv_free (&v);
}
static void