Bump liberty

This commit is contained in:
Přemysl Eric Janouch 2017-06-22 23:17:25 +02:00
parent 99f35a509c
commit 3ff7867e30
Signed by: p
GPG Key ID: B715679E3A361BE6
3 changed files with 46 additions and 79 deletions

View File

@ -3,9 +3,8 @@ cmake_minimum_required (VERSION 2.8.5)
# Moar warnings # Moar warnings
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC) if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") set (wdisabled "-Wno-unused-function -Wno-implicit-fallthrough")
set (CMAKE_C_FLAGS_DEBUG set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra ${wdisabled}")
"${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wno-unused-function")
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC) endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
# Version # Version

@ -1 +1 @@
Subproject commit 1dcd259d0506b9e2de3715bdf07144b22f57903a Subproject commit 3835b6e49975039a9f72b8920238f3141e7becea

118
nncmpp.c
View File

@ -133,8 +133,7 @@ xbasename (const char *path)
static char * static char *
latin1_to_utf8 (const char *latin1) latin1_to_utf8 (const char *latin1)
{ {
struct str converted; struct str converted = str_make ();
str_init (&converted);
while (*latin1) while (*latin1)
{ {
uint8_t c = *latin1++; uint8_t c = *latin1++;
@ -273,7 +272,7 @@ poller_curl_on_socket_action (CURL *easy, curl_socket_t s, int what,
fd = xmalloc (sizeof *fd); fd = xmalloc (sizeof *fd);
LIST_PREPEND (self->fds, fd); LIST_PREPEND (self->fds, fd);
poller_fd_init (&fd->fd, self->poller, s); fd->fd = poller_fd_make (self->poller, s);
fd->fd.dispatcher = poller_curl_on_socket; fd->fd.dispatcher = poller_curl_on_socket;
fd->fd.user_data = self; fd->fd.user_data = self;
curl_multi_assign (self->multi, s, fd); curl_multi_assign (self->multi, s, fd);
@ -337,7 +336,7 @@ poller_curl_init (struct poller_curl *self, struct poller *poller,
"cURL setup failed", curl_multi_strerror (mres)); "cURL setup failed", curl_multi_strerror (mres));
} }
poller_timer_init (&self->timer, (self->poller = poller)); self->timer = poller_timer_make ((self->poller = poller));
self->timer.dispatcher = poller_curl_on_timer; self->timer.dispatcher = poller_curl_on_timer;
self->timer.user_data = self; self->timer.user_data = self;
return true; return true;
@ -418,10 +417,8 @@ typedef uint8_t *compact_map_t; ///< Compacted (string -> string) map
static compact_map_t static compact_map_t
compact_map (struct str_map *map) compact_map (struct str_map *map)
{ {
struct str s; struct str s = str_make ();
str_init (&s); struct str_map_iter iter = str_map_iter_make (map);
struct str_map_iter iter;
str_map_iter_init (&iter, map);
char *value; char *value;
static const size_t zero = 0, alignment = sizeof zero; static const size_t zero = 0, alignment = sizeof zero;
@ -755,8 +752,7 @@ load_config_streams (struct config_item *subtree, void *user_data)
// XXX: we can't use the tab in load_config_streams() because it hasn't // XXX: we can't use the tab in load_config_streams() because it hasn't
// been initialized yet, and we cannot initialize it before the // been initialized yet, and we cannot initialize it before the
// configuration has been loaded. Thus we load it into the app_context. // configuration has been loaded. Thus we load it into the app_context.
struct str_map_iter iter; struct str_map_iter iter = str_map_iter_make (&subtree->value.object);
str_map_iter_init (&iter, &subtree->value.object);
struct config_item *item; struct config_item *item;
while ((item = str_map_iter_next (&iter))) while ((item = str_map_iter_next (&iter)))
if (!config_item_type_is_string (item->type)) if (!config_item_type_is_string (item->type))
@ -820,14 +816,13 @@ static void
app_init_context (void) app_init_context (void)
{ {
poller_init (&g.poller); poller_init (&g.poller);
mpd_client_init (&g.client, &g.poller); g.client = mpd_client_make (&g.poller);
config_init (&g.config); g.config = config_make ();
strv_init (&g.streams); g.streams = strv_make ();
item_list_init (&g.playlist); item_list_init (&g.playlist);
str_map_init (&g.playback_info); g.playback_info = str_map_make (free);
g.playback_info.key_xfrm = tolower_ascii_strxfrm; g.playback_info.key_xfrm = tolower_ascii_strxfrm;
g.playback_info.free = free;
// This is also approximately what libunistring does internally, // This is also approximately what libunistring does internally,
// since the locale name is canonicalized by locale_charset(). // since the locale name is canonicalized by locale_charset().
@ -940,8 +935,7 @@ app_flush_buffer (struct row_buffer *buf, int width, chtype attrs)
static void static void
app_write_line (const char *str, chtype attrs) app_write_line (const char *str, chtype attrs)
{ {
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
row_buffer_append (&buf, str, attrs); row_buffer_append (&buf, str, attrs);
app_flush_buffer (&buf, COLS, attrs); app_flush_buffer (&buf, COLS, attrs);
} }
@ -970,8 +964,7 @@ app_draw_song_info (void)
|| (title = compact_map_find (map, "name")) || (title = compact_map_find (map, "name"))
|| (title = compact_map_find (map, "file"))) || (title = compact_map_find (map, "file")))
{ {
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
row_buffer_append (&buf, title, attr_highlight); row_buffer_append (&buf, title, attr_highlight);
app_flush_header (&buf, attr_normal); app_flush_header (&buf, attr_normal);
} }
@ -981,9 +974,7 @@ app_draw_song_info (void)
if (!artist && !album) if (!artist && !album)
return; return;
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
if (artist) if (artist)
row_buffer_append_args (&buf, " by " + !buf.total_width, attr_normal, row_buffer_append_args (&buf, " by " + !buf.total_width, attr_normal,
artist, attr_highlight, NULL); artist, attr_highlight, NULL);
@ -999,9 +990,7 @@ app_time_string (int seconds)
int minutes = seconds / 60; seconds %= 60; int minutes = seconds / 60; seconds %= 60;
int hours = minutes / 60; minutes %= 60; int hours = minutes / 60; minutes %= 60;
struct str s; struct str s = str_make ();
str_init (&s);
if (hours) if (hours)
str_append_printf (&s, "%d:%02d:", hours, minutes); str_append_printf (&s, "%d:%02d:", hours, minutes);
else else
@ -1055,9 +1044,7 @@ app_draw_status (void)
chtype attr_normal = APP_ATTR (NORMAL); chtype attr_normal = APP_ATTR (NORMAL);
chtype attr_highlight = APP_ATTR (HIGHLIGHT); chtype attr_highlight = APP_ATTR (HIGHLIGHT);
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
bool stopped = g.state == PLAYER_STOPPED; bool stopped = g.state == PLAYER_STOPPED;
chtype attr_song_action = stopped ? attr_normal : attr_highlight; chtype attr_song_action = stopped ? attr_normal : attr_highlight;
@ -1142,10 +1129,8 @@ app_draw_header (void)
chtype attrs[2] = { APP_ATTR (TAB_BAR), APP_ATTR (TAB_ACTIVE) }; chtype attrs[2] = { APP_ATTR (TAB_BAR), APP_ATTR (TAB_ACTIVE) };
struct row_buffer buf;
row_buffer_init (&buf);
// The help tab is disguised so that it's not too intruding // The help tab is disguised so that it's not too intruding
struct row_buffer buf = row_buffer_make ();
row_buffer_append (&buf, APP_TITLE, attrs[g.active_tab == g.help_tab]); row_buffer_append (&buf, APP_TITLE, attrs[g.active_tab == g.help_tab]);
row_buffer_append (&buf, " ", attrs[false]); row_buffer_append (&buf, " ", attrs[false]);
@ -1157,7 +1142,7 @@ app_draw_header (void)
const char *header = g.active_tab->header; const char *header = g.active_tab->header;
if (header) if (header)
{ {
row_buffer_init (&buf); buf = row_buffer_make ();
row_buffer_append (&buf, header, APP_ATTR (HEADER)); row_buffer_append (&buf, header, APP_ATTR (HEADER));
app_flush_header (&buf, APP_ATTR (HEADER)); app_flush_header (&buf, APP_ATTR (HEADER));
} }
@ -1236,8 +1221,7 @@ app_draw_scrollbar (void)
move (g.header_height + row, COLS - 1); move (g.header_height + row, COLS - 1);
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
row_buffer_append (&buf, c, attrs); row_buffer_append (&buf, c, attrs);
row_buffer_flush (&buf); row_buffer_flush (&buf);
row_buffer_free (&buf); row_buffer_free (&buf);
@ -1263,8 +1247,7 @@ app_draw_view (void)
if (item_index == tab->item_selected) if (item_index == tab->item_selected)
row_attrs = APP_ATTR (SELECTION); row_attrs = APP_ATTR (SELECTION);
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
tab->on_item_draw (item_index, &buf, view_width); tab->on_item_draw (item_index, &buf, view_width);
// Combine attributes used by the handler with the defaults. // Combine attributes used by the handler with the defaults.
@ -1291,9 +1274,7 @@ app_draw_view (void)
static void static void
app_write_mpd_status_playlist (struct row_buffer *buf) app_write_mpd_status_playlist (struct row_buffer *buf)
{ {
struct str stats; struct str stats = str_make ();
str_init (&stats);
if (g.playlist.len == 1) if (g.playlist.len == 1)
str_append_printf (&stats, "1 song "); str_append_printf (&stats, "1 song ");
else else
@ -1328,9 +1309,6 @@ app_write_mpd_status (struct row_buffer *buf)
else else
app_write_mpd_status_playlist (buf); app_write_mpd_status_playlist (buf);
struct row_buffer right;
row_buffer_init (&right);
const char *s; const char *s;
bool repeat = (s = str_map_find (map, "repeat")) && strcmp (s, "0"); bool repeat = (s = str_map_find (map, "repeat")) && strcmp (s, "0");
bool random = (s = str_map_find (map, "random")) && strcmp (s, "0"); bool random = (s = str_map_find (map, "random")) && strcmp (s, "0");
@ -1338,6 +1316,7 @@ app_write_mpd_status (struct row_buffer *buf)
bool consume = (s = str_map_find (map, "consume")) && strcmp (s, "0"); bool consume = (s = str_map_find (map, "consume")) && strcmp (s, "0");
// TODO: remove the conditionals once we make them clickable // TODO: remove the conditionals once we make them clickable
struct row_buffer right = row_buffer_make ();
chtype a[2] = { APP_ATTR (NORMAL), APP_ATTR (HIGHLIGHT) }; chtype a[2] = { APP_ATTR (NORMAL), APP_ATTR (HIGHLIGHT) };
if (repeat) row_buffer_append_args (&right, if (repeat) row_buffer_append_args (&right,
" ", APP_ATTR (NORMAL), "repeat", a[repeat], NULL); " ", APP_ATTR (NORMAL), "repeat", a[repeat], NULL);
@ -1358,9 +1337,7 @@ app_write_mpd_status (struct row_buffer *buf)
static void static void
app_draw_statusbar (void) app_draw_statusbar (void)
{ {
struct row_buffer buf; struct row_buffer buf = row_buffer_make ();
row_buffer_init (&buf);
if (g.message) if (g.message)
row_buffer_append (&buf, g.message, APP_ATTR (HIGHLIGHT)); row_buffer_append (&buf, g.message, APP_ATTR (HIGHLIGHT));
else if (g.client.state == MPD_CONNECTED) else if (g.client.state == MPD_CONNECTED)
@ -1555,9 +1532,7 @@ g_actions[] =
static void static void
mpd_client_vsend_command (struct mpd_client *self, va_list ap) mpd_client_vsend_command (struct mpd_client *self, va_list ap)
{ {
struct strv v; struct strv v = strv_make ();
strv_init (&v);
const char *command; const char *command;
while ((command = va_arg (ap, const char *))) while ((command = va_arg (ap, const char *)))
strv_append (&v, command); strv_append (&v, command);
@ -2182,8 +2157,7 @@ library_tab_on_data (const struct mpd_response *response,
free (parent); free (parent);
} }
struct str_map map; struct str_map map = str_map_make (NULL);
str_map_init (&map);
map.key_xfrm = tolower_ascii_strxfrm; map.key_xfrm = tolower_ascii_strxfrm;
char *key, *value, type; char *key, *value, type;
@ -2289,8 +2263,8 @@ library_tab_on_action (enum action action)
static struct tab * static struct tab *
library_tab_init (void) library_tab_init (void)
{ {
str_init (&g_library_tab.path); g_library_tab.path = str_make ();
strv_init (&g_library_tab.items); g_library_tab.items = strv_make ();
struct tab *super = &g_library_tab.super; struct tab *super = &g_library_tab.super;
tab_init (super, "Library"); tab_init (super, "Library");
@ -2355,8 +2329,7 @@ streams_tab_parse_playlist (const char *playlist, const char *content_type,
struct strv *out) struct strv *out)
{ {
// We accept a lot of very broken stuff because this is the real world // We accept a lot of very broken stuff because this is the real world
struct strv lines; struct strv lines = strv_make ();
strv_init (&lines);
cstr_split (playlist, "\r\n", true, &lines); cstr_split (playlist, "\r\n", true, &lines);
// Since this excludes '"', it should even work for XMLs (w/o entities) // Since this excludes '"', it should even work for XMLs (w/o entities)
@ -2436,9 +2409,7 @@ streams_tab_on_downloaded (CURLMsg *msg, struct poller_curl_task *task)
if (self->replace) if (self->replace)
mpd_client_send_command (c, "clear", NULL); mpd_client_send_command (c, "clear", NULL);
struct strv links; struct strv links = strv_make ();
strv_init (&links);
if (!streams_tab_extract_links (&self->data, type, &links)) if (!streams_tab_extract_links (&self->data, type, &links))
strv_append (&links, uri); strv_append (&links, uri);
for (size_t i = 0; i < links.len; i++) for (size_t i = 0; i < links.len; i++)
@ -2477,7 +2448,7 @@ streams_tab_process (const char *uri, bool replace, struct error **e)
hard_assert (poller_curl_spawn (&task.curl, NULL)); hard_assert (poller_curl_spawn (&task.curl, NULL));
CURL *easy = task.curl.easy; CURL *easy = task.curl.easy;
str_init (&task.data); task.data = str_make ();
task.replace = replace; task.replace = replace;
bool result = false; bool result = false;
@ -2633,8 +2604,8 @@ info_tab_update (void)
static struct tab * static struct tab *
info_tab_init (void) info_tab_init (void)
{ {
strv_init (&g_info_tab.keys); g_info_tab.keys = strv_make ();
strv_init (&g_info_tab.values); g_info_tab.values = strv_make ();
struct tab *super = &g_info_tab.super; struct tab *super = &g_info_tab.super;
tab_init (super, "Info"); tab_init (super, "Info");
@ -2793,8 +2764,7 @@ mpd_update_playback_state (void)
const char *elapsed = str_map_find (map, "elapsed"); const char *elapsed = str_map_find (map, "elapsed");
const char *duration = str_map_find (map, "duration"); const char *duration = str_map_find (map, "duration");
struct strv fields; struct strv fields = strv_make ();
strv_init (&fields);
if (time) if (time)
{ {
cstr_split (time, ":", false, &fields); cstr_split (time, ":", false, &fields);
@ -2848,8 +2818,7 @@ mpd_process_info (const struct strv *data)
} }
// It's much better to process the playlist from the back // It's much better to process the playlist from the back
struct str_map item; struct str_map item = str_map_make (NULL);
str_map_init (&item);
item.key_xfrm = tolower_ascii_strxfrm; item.key_xfrm = tolower_ascii_strxfrm;
for (size_t i = data->len - 1; i-- && data->vector[i]; ) for (size_t i = data->len - 1; i-- && data->vector[i]; )
{ {
@ -3225,8 +3194,7 @@ app_log_handler (void *user_data, const char *quote, const char *fmt,
in_processing = true; in_processing = true;
struct str message; struct str message = str_make ();
str_init (&message);
str_append (&message, quote); str_append (&message, quote);
str_append_vprintf (&message, fmt, ap); str_append_vprintf (&message, fmt, ap);
@ -3252,28 +3220,28 @@ app_log_handler (void *user_data, const char *quote, const char *fmt,
static void static void
app_init_poller_events (void) app_init_poller_events (void)
{ {
poller_fd_init (&g.signal_event, &g.poller, g_signal_pipe[0]); g.signal_event = poller_fd_make (&g.poller, g_signal_pipe[0]);
g.signal_event.dispatcher = app_on_signal_pipe_readable; g.signal_event.dispatcher = app_on_signal_pipe_readable;
poller_fd_set (&g.signal_event, POLLIN); poller_fd_set (&g.signal_event, POLLIN);
poller_fd_init (&g.tty_event, &g.poller, STDIN_FILENO); g.tty_event = poller_fd_make (&g.poller, STDIN_FILENO);
g.tty_event.dispatcher = app_on_tty_readable; g.tty_event.dispatcher = app_on_tty_readable;
poller_fd_set (&g.tty_event, POLLIN); poller_fd_set (&g.tty_event, POLLIN);
poller_timer_init (&g.message_timer, &g.poller); g.message_timer = poller_timer_make (&g.poller);
g.message_timer.dispatcher = app_on_message_timer; g.message_timer.dispatcher = app_on_message_timer;
poller_timer_init (&g.tk_timer, &g.poller); g.tk_timer = poller_timer_make (&g.poller);
g.tk_timer.dispatcher = app_on_key_timer; g.tk_timer.dispatcher = app_on_key_timer;
poller_timer_init (&g.connect_event, &g.poller); g.connect_event = poller_timer_make (&g.poller);
g.connect_event.dispatcher = app_on_reconnect; g.connect_event.dispatcher = app_on_reconnect;
poller_timer_set (&g.connect_event, 0); poller_timer_set (&g.connect_event, 0);
poller_timer_init (&g.elapsed_event, &g.poller); g.elapsed_event = poller_timer_make (&g.poller);
g.elapsed_event.dispatcher = mpd_on_tick; g.elapsed_event.dispatcher = mpd_on_tick;
poller_idle_init (&g.refresh_event, &g.poller); g.refresh_event = poller_idle_make (&g.poller);
g.refresh_event.dispatcher = app_on_refresh; g.refresh_event.dispatcher = app_on_refresh;
} }
@ -3288,8 +3256,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL } { 0, NULL, NULL, 0, NULL }
}; };
struct opt_handler oh; struct opt_handler oh =
opt_handler_init (&oh, argc, argv, opts, NULL, "MPD client."); opt_handler_make (argc, argv, opts, NULL, "MPD client.");
int c; int c;
while ((c = opt_handler_get (&oh)) != -1) while ((c = opt_handler_get (&oh)) != -1)