Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jun 29, 2017
1 parent 0bff93b commit 0048177
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 78 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/cache.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +19,7 @@
*/

#if HAVE_CONFIG_H
#include "../config.h"
# include "../config.h"
#endif

#include "cache.h"
Expand Down
6 changes: 3 additions & 3 deletions src/cache.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/cmusfm.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/config.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,7 +26,7 @@
#include <string.h>
#include <sys/stat.h>
#if HAVE_SYS_INOTIFY_H
#include <sys/inotify.h>
# include <sys/inotify.h>
#endif

#include "cmusfm.h"
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/debug.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,16 +22,15 @@
#define CMUSFM_DEBUG_H_

#if HAVE_CONFIG_H
#include "../config.h"
# include "../config.h"
#endif

#include <stdio.h>


#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
4 changes: 2 additions & 2 deletions src/libscrobbler2.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libscrobbler2.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +19,7 @@
*/

#if HAVE_CONFIG_H
#include "../config.h"
# include "../config.h"
#endif

#include "cmusfm.h"
Expand Down
6 changes: 3 additions & 3 deletions src/notify.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/notify.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/server.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +19,7 @@
*/

#if HAVE_CONFIG_H
#include "../config.h"
# include "../config.h"
#endif

#include "server.h"
Expand All @@ -35,15 +35,15 @@
#include <sys/socket.h>
#include <sys/un.h>
#if HAVE_SYS_INOTIFY_H
#include <sys/inotify.h>
# include <sys/inotify.h>
#endif

#include "cache.h"
#include "cmusfm.h"
#include "config.h"
#include "debug.h"
#if ENABLE_LIBNOTIFY
#include "notify.h"
# include "notify.h"
#endif


Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/server.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +19,7 @@
*/

#if HAVE_CONFIG_H
#include "../config.h"
# include "../config.h"
#endif

#include "cmusfm.h"
Expand All @@ -29,8 +29,8 @@
#include <stdlib.h>
#include <string.h>
#if ENABLE_LIBNOTIFY
#include <dirent.h>
#include <libgen.h>
# include <dirent.h>
# include <libgen.h>
#endif

#include "debug.h"
Expand Down
12 changes: 11 additions & 1 deletion test/test-cache.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* test-cache.c
* Copyright (c) 2015-2017 Arkadiusz Bokowy
*
* This file is a part of cmusfm.
*
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 0048177

Please sign in to comment.