From 004817752fc47c9c4c501d054d6d3dad57abf521 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 29 Jun 2017 08:23:37 +0200 Subject: [PATCH] Code cleanup --- README.md | 18 +++++++++--------- src/cache.c | 8 ++++---- src/cache.h | 6 +++--- src/cmusfm.h | 6 +++--- src/config.c | 18 +++++++++--------- src/config.h | 4 ++-- src/debug.h | 15 +++++++-------- src/libscrobbler2.c | 4 ++-- src/libscrobbler2.h | 4 ++-- src/main.c | 8 ++++---- src/notify.c | 6 +++--- src/notify.h | 6 +++--- src/server.c | 14 +++++++------- src/server.h | 6 +++--- src/utils.c | 12 ++++++------ test/test-cache.c | 12 +++++++++++- test/test-server-notify.c | 18 +++++++++++++----- test/test-server-submit01.c | 12 ++++++++++-- test/test-server-submit02.c | 12 ++++++++++-- test/test-server.inc | 10 ++++++++++ 20 files changed, 121 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index e39e0ba..a022829 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,15 @@ displayed. Exemplary configuration might be as follows: * `notification = "yes"` * `format-coverfile = "^(cover|folder)\.jpg$"` +By default cmusfm scrobbles to the Last.fm service. However, it is possible to change this +behavior by modifying `service-api-url` and `service-auth-url` options in the configuration file. +Afterwards, one should reinitialize cmusfm (`cmusfm init`) in order to authenticate with new +scrobbling service. In order to use [Libre.fm](https://libre.fm/) as a scrobbling service, one +shall use configuration as follows: + +* `service-api-url = "https://libre.fm/2.0/"` +* `service-auth-url = "https://libre.fm/api/auth"` + Installation ------------ @@ -73,15 +82,6 @@ action might be also required when upgrading to the newer version with new featu After that you can safely edit `~/.config/cmus/cmusfm.conf` configuration file. -By default cmusfm scrobbles to the Last.fm service. However, it is possible to change this -behavior by modifying `service-api-url` and `service-auth-url` options in the configuration file. -Afterwards, one should reinitialize cmusfm (`cmusfm init`) in order to authenticate with new -scrobbling service. In order to use [Libre.fm](https://libre.fm/) as a scrobbling service, one -shall use configuration as follows: - -* `service-api-url = "https://libre.fm/2.0/"` -* `service-auth-url = "https://libre.fm/api/auth"` - ~~Note, that for some changes to take place, restart of the cmusfm server process is required. To achieved this, one has to quit cmus player and then kill background instance of cmusfm (e.g. `pkill cmusfm`).~~ Above statement is not valid if one's got diff --git a/src/cache.c b/src/cache.c index 37045af..1938d1b 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1,8 +1,8 @@ /* - * cmusfm - cache.c - * Copyright (c) 2014-2015 Arkadiusz Bokowy + * cache.c + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ */ #if HAVE_CONFIG_H -#include "../config.h" +# include "../config.h" #endif #include "cache.h" diff --git a/src/cache.h b/src/cache.h index e13d0dd..9ed25de 100644 --- a/src/cache.h +++ b/src/cache.h @@ -1,8 +1,8 @@ /* - * cmusfm - cache.h - * Copyright (c) 2014-2015 Arkadiusz Bokowy + * cache.h + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/cmusfm.h b/src/cmusfm.h index cec55c3..7958963 100644 --- a/src/cmusfm.h +++ b/src/cmusfm.h @@ -1,8 +1,8 @@ /* - * cmusfm - cmusfm.h - * Copyright (c) 2010-2016 Arkadiusz Bokowy + * cmusfm.h + * Copyright (c) 2010-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/config.c b/src/config.c index 73c36af..46d76b5 100644 --- a/src/config.c +++ b/src/config.c @@ -1,8 +1,8 @@ /* - * cmusfm - config.c + * config.c * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ #include #include #if HAVE_SYS_INOTIFY_H -#include +# include #endif #include "cmusfm.h" @@ -61,11 +61,11 @@ static char *get_config_value(char *str) { return str; } -static char *encode_config_bool(int value) { +static char *encode_config_bool(bool value) { return value ? "yes" : "no"; } -static int decode_config_bool(const char *value) { +static bool decode_config_bool(const char *value) { return strcmp(value, "yes") == 0; } @@ -86,10 +86,10 @@ int cmusfm_config_read(const char *fname, struct cmusfm_config *conf) { * sailors from the pirate bay */ strcpy(conf->format_coverfile, "^folder\\.jpg$"); #endif - conf->nowplaying_localfile = 1; - conf->nowplaying_shoutcast = 1; - conf->submit_localfile = 1; - conf->submit_shoutcast = 1; + conf->nowplaying_localfile = true; + conf->nowplaying_shoutcast = true; + conf->submit_localfile = true; + conf->submit_shoutcast = true; if ((f = fopen(fname, "r")) == NULL) return -1; diff --git a/src/config.h b/src/config.h index ad1efcb..3a35d93 100644 --- a/src/config.h +++ b/src/config.h @@ -1,8 +1,8 @@ /* - * cmusfm - config.h + * config.h * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/debug.h b/src/debug.h index c50ce06..1316138 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,8 +1,8 @@ /* - * cmusfm - debug.h - * Copyright (c) 2014 Arkadiusz Bokowy + * debug.h + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,16 +22,15 @@ #define CMUSFM_DEBUG_H_ #if HAVE_CONFIG_H -#include "../config.h" +# include "../config.h" #endif #include - #if DEBUG -#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) +# define debug(M, ARGS...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, __LINE__, ## ARGS) #else -#define debug(M, ...) {} +# define debug(M, ARGS...) do {} while (0) #endif -#endif /* CMUSFM_DEBUG_H_ */ +#endif diff --git a/src/libscrobbler2.c b/src/libscrobbler2.c index 40a2d5e..0a71839 100644 --- a/src/libscrobbler2.c +++ b/src/libscrobbler2.c @@ -1,8 +1,8 @@ /* - * cmusfm - libscrobbler2.c + * libscrobbler2.c * Copyright (c) 2011-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libscrobbler2.h b/src/libscrobbler2.h index 1dd84b4..1a065a8 100644 --- a/src/libscrobbler2.h +++ b/src/libscrobbler2.h @@ -1,8 +1,8 @@ /* - * cmusfm - libscrobbler2.h + * libscrobbler2.h * Copyright (c) 2011-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/main.c b/src/main.c index 2106dcb..4e5a9c3 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,8 @@ /* - * cmusfm - main.c - * Copyright (c) 2010-2016 Arkadiusz Bokowy + * main.c + * Copyright (c) 2010-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ */ #if HAVE_CONFIG_H -#include "../config.h" +# include "../config.h" #endif #include "cmusfm.h" diff --git a/src/notify.c b/src/notify.c index f9ef547..0f5e3d6 100644 --- a/src/notify.c +++ b/src/notify.c @@ -1,8 +1,8 @@ /* - * cmusfm - notify.c - * Copyright (c) 2014-2016 Arkadiusz Bokowy + * notify.c + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/notify.h b/src/notify.h index f8d6c41..534cfd8 100644 --- a/src/notify.h +++ b/src/notify.h @@ -1,8 +1,8 @@ /* - * cmusfm - notify.h - * Copyright (c) 2014 Arkadiusz Bokowy + * notify.h + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/server.c b/src/server.c index f46bf97..f7f0801 100644 --- a/src/server.c +++ b/src/server.c @@ -1,8 +1,8 @@ /* - * cmusfm - server.c + * server.c * Copyright (c) 2010-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ */ #if HAVE_CONFIG_H -#include "../config.h" +# include "../config.h" #endif #include "server.h" @@ -35,7 +35,7 @@ #include #include #if HAVE_SYS_INOTIFY_H -#include +# include #endif #include "cache.h" @@ -43,7 +43,7 @@ #include "config.h" #include "debug.h" #if ENABLE_LIBNOTIFY -#include "notify.h" +# include "notify.h" #endif @@ -274,11 +274,11 @@ int cmusfm_server_check(void) { } /* server shutdown stuff */ -static int server_on = 1; +static bool server_on = true; static void cmusfm_server_stop(int sig) { (void)sig; debug("stopping server"); - server_on = 0; + server_on = false; } /* Start server instance. This function hangs until server is stopped. diff --git a/src/server.h b/src/server.h index 9fc2b3d..401c078 100644 --- a/src/server.h +++ b/src/server.h @@ -1,8 +1,8 @@ /* - * cmusfm - server.h - * Copyright (c) 2014-2015 Arkadiusz Bokowy + * server.h + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/utils.c b/src/utils.c index e4e1768..3510934 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,8 @@ /* - * cmusfm - utils.c - * Copyright (c) 2014-2016 Arkadiusz Bokowy + * utils.c + * Copyright (c) 2014-2017 Arkadiusz Bokowy * - * This file is a part of a cmusfm. + * This file is a part of cmusfm. * * cmusfm is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ */ #if HAVE_CONFIG_H -#include "../config.h" +# include "../config.h" #endif #include "cmusfm.h" @@ -29,8 +29,8 @@ #include #include #if ENABLE_LIBNOTIFY -#include -#include +# include +# include #endif #include "debug.h" diff --git a/test/test-cache.c b/test/test-cache.c index 19b0ceb..2e6a44d 100644 --- a/test/test-cache.c +++ b/test/test-cache.c @@ -1,3 +1,11 @@ +/* + * test-cache.c + * Copyright (c) 2015-2017 Arkadiusz Bokowy + * + * This file is a part of cmusfm. + * + */ + #include #include #include @@ -11,6 +19,8 @@ const char *cmusfm_cache_file; /* library function used by the cache code */ int scrobbler_scrobble_count = 0; scrobbler_status_t scrobbler_scrobble(scrobbler_session_t *sbs, scrobbler_trackinfo_t *sbt) { + (void)sbs; + (void)sbt; scrobbler_scrobble_count++; return SCROBBLER_STATUS_OK; } @@ -50,7 +60,7 @@ int main(void) { assert((f = fopen(cmusfm_cache_file, "r")) != NULL); /* make sure the structure of the cache file is not changed */ assert((size = fread(buffer, 1, sizeof(buffer), f)) == 107); - assert(make_data_hash(buffer, size) == 371117); + assert(make_data_hash((unsigned char *)buffer, size) == 371117); fclose(f); cmusfm_cache_submit(NULL); diff --git a/test/test-server-notify.c b/test/test-server-notify.c index 7d9b888..ed6698a 100644 --- a/test/test-server-notify.c +++ b/test/test-server-notify.c @@ -1,3 +1,11 @@ +/* + * test-server-notify.c + * Copyright (c) 2015-2017 Arkadiusz Bokowy + * + * This file is a part of cmusfm. + * + */ + #include #define DEBUG_SKIP_HICCUP @@ -17,8 +25,8 @@ int main(void) { strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); strcpy(((char *)(track + 1)) + 60, ""); - config.nowplaying_localfile = 1; - config.nowplaying_shoutcast = 1; + config.nowplaying_localfile = true; + config.nowplaying_shoutcast = true; track->status = CMSTATUS_PLAYING; cmusfm_server_update_record_checksum(track); @@ -28,13 +36,13 @@ int main(void) { assert(strcmp(scrobbler_update_now_playing_sbt.artist, "The Beatles") == 0); assert(strcmp(scrobbler_update_now_playing_sbt.track, "Yellow Submarine") == 0); - config.nowplaying_localfile = 0; + config.nowplaying_localfile = false; cmusfm_server_process_data(NULL, track); assert(scrobbler_update_now_playing_count == 1); #if ENABLE_LIBNOTIFY - config.notification = 1; + config.notification = true; #endif track->status |= CMSTATUS_SHOUTCASTMASK; @@ -48,7 +56,7 @@ int main(void) { /* reshow now playing notification after a long pause */ - config.nowplaying_localfile = 1; + config.nowplaying_localfile = true; track->status = CMSTATUS_PLAYING; cmusfm_server_update_record_checksum(track); diff --git a/test/test-server-submit01.c b/test/test-server-submit01.c index d7085e4..097a52a 100644 --- a/test/test-server-submit01.c +++ b/test/test-server-submit01.c @@ -1,3 +1,11 @@ +/* + * test-server-submit01.c + * Copyright (c) 2015-2017 Arkadiusz Bokowy + * + * This file is a part of cmusfm. + * + */ + #include #define DEBUG_SKIP_HICCUP @@ -16,8 +24,8 @@ int main(void) { strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); strcpy(((char *)(track + 1)) + 60, ""); - config.submit_localfile = 1; - config.submit_shoutcast = 1; + config.submit_localfile = true; + config.submit_shoutcast = true; track->status = CMSTATUS_PLAYING; track->duration = 35; diff --git a/test/test-server-submit02.c b/test/test-server-submit02.c index edc03cc..dbed873 100644 --- a/test/test-server-submit02.c +++ b/test/test-server-submit02.c @@ -1,3 +1,11 @@ +/* + * test-server-submit02.c + * Copyright (c) 2015-2017 Arkadiusz Bokowy + * + * This file is a part of cmusfm. + * + */ + #include #define DEBUG_SKIP_HICCUP @@ -16,8 +24,8 @@ int main(void) { strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); strcpy(((char *)(track + 1)) + 60, ""); - config.submit_localfile = 1; - config.submit_shoutcast = 1; + config.submit_localfile = true; + config.submit_shoutcast = true; track->status = CMSTATUS_PLAYING; track->duration = 4 * 60 * 5; diff --git a/test/test-server.inc b/test/test-server.inc index a20385b..51fec23 100644 --- a/test/test-server.inc +++ b/test/test-server.inc @@ -1,3 +1,13 @@ +/* + * test-server.inc + * vim: ft=c + * + * Copyright (c) 2015-2017 Arkadiusz Bokowy + * + * This file is a part of cmusfm. + * + */ + #include "../src/cmusfm.h" #include "../src/server.c" #include "../src/utils.c"