tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit 2b09bac500bfc2b65467b35520076622d1d67afb
parent 16449e8a72c7d9282647823d1747ae5696619d4f
Author: Louis Burda <quent.burda@gmail.com>
Date:   Tue, 28 Dec 2021 16:41:41 +0100

Added panic and simplified makefile

Diffstat:
MMakefile | 16+++++-----------
Msrc/player.c | 23+++++++++++++++++++++--
Msrc/util.c | 9+++++++++
Msrc/util.h | 3+++
4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,6 @@ -CC = clang CFLAGS = -I src -g LDLIBS = -lcurses -lreadline -lmpdclient -WARNFLAGS = -Wno-pragma-once-outside-header +DEPFLAGS = -MT $@ -MMD -MP -MF build/$*.d SRCS = $(wildcard src/*.c) OBJS = $(SRCS:src/%.c=build/%.o) @@ -12,22 +11,17 @@ DEPS = $(OBJS:%.o=%.d) all: tmus clean: - rm tmus + rm -rf build build: mkdir build build/%.o: src/%.c build/%.d - @echo DEPS: $^ - $(CC) -c -o $@ $< $(CFLAGS) + $(CC) -c -o $@ $(DEPFLAGS) $(CFLAGS) $< -build/main.d: src/main.c | build - $(CC) -c -MT build/main.o -MMD -MP -MF $@ $< +build/%.d: | build; -build/%.d: src/%.c src/%.h | build - $(CC) -c -MT build/$*.o -MMD -MP -MF $@ $^ $(WARNFLAGS) - --include $(DEPS) +include $(DEPS) tmus: $(OBJS) $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) diff --git a/src/player.c b/src/player.c @@ -22,6 +22,25 @@ static struct player player_static; struct player *player; +static void +handle_mpd_status(struct mpd_connection *conn, int status) +{ + switch (status) { + case MPD_ERROR_SYSTEM: + PLAYER_STATUS(PLAYER_MSG_ERR, "%s", + mpd_connection_get_error_message(conn)); + break; + case MPD_ERROR_SERVER: + case MPD_ERROR_ARGUMENT: + if (!mpd_connection_clear_error(conn)) + PANIC("Player failed to recover from error"); + break; + case MPD_ERROR_CLOSED: + PANIC("Player encountered non-recoverable error"); + break; + } +} + void player_init(void) { @@ -92,7 +111,7 @@ player_update(void) ref_free(ref); break; default: - ASSERT(0); + PANIC(); } player->action = PLAYER_ACTION_NONE; } @@ -111,7 +130,7 @@ player_update(void) player->state = PLAYER_STATE_STOPPED; break; default: - ASSERT(0); + PANIC(); } player->volume = mpd_status_get_volume(status); diff --git a/src/util.c b/src/util.c @@ -2,6 +2,7 @@ #include "util.h" +#include "execinfo.h" #include "ncurses.h" #include <stdarg.h> @@ -40,6 +41,14 @@ done: } void +panic(const char *msg, const char *file, int line) +{ + endwin(); + fprintf(stderr, "Panic at %s:%i (%s)\n", file, line, msg); + exit(1); +} + +void assert(int cond, const char *file, int line, const char *condstr) { if (cond) return; diff --git a/src/util.h b/src/util.h @@ -6,9 +6,12 @@ #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define ARRLEN(x) (sizeof(x)/sizeof((x)[0])) +#define PANIC(...) panic("" __VA_ARGS__, __FILE__, __LINE__) #define ASSERT(x) assert((x), __FILE__, __LINE__, #x) int strnwidth(const char *s, int n); + +void panic(const char *msg, const char *file, int line); void assert(int cond, const char *file, int line, const char *condstr); char *aprintf(const char *fmtstr, ...);