summaryrefslogtreecommitdiffstats
path: root/src/c_mpdview.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c_mpdview.c')
-rw-r--r--src/c_mpdview.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/c_mpdview.c b/src/c_mpdview.c
index aa0c008..26af420 100644
--- a/src/c_mpdview.c
+++ b/src/c_mpdview.c
@@ -39,12 +39,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* mpdview: src/c_mpdview.c
- * Sun, 03 Jul 2022 02:19:55 +0200
+ * Sun, 03 Jul 2022 16:06:29 +0200
* Joe
*
* This is the entrypoint of the program.
*/
+#include <sys/param.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -75,6 +77,12 @@ c_create_view(void)
return (view);
}
+static void
+c_get_music_dir(struct mpdview_s* v)
+{
+ strlcpy(v->music_dir, DEF_MUSIC_DIR, PATH_MAX);
+}
+
static u8_t
c_connect_mpd(struct mpdview_s* v)
{
@@ -146,6 +154,28 @@ c_get_mpd_song(struct mpdview_s* v)
return (RET_OK);
}
+static void
+c_get_current_dir(struct mpdview_s* v)
+{
+ ptr_t ptr;
+
+ snprintf(
+ v->current_dir,
+ PATH_MAX,
+ "%s/%s",
+ v->music_dir,
+ mpd_song_get_uri(v->song)
+ );
+ ptr = v->current_dir;
+ while (*ptr != 0x00) {
+ ptr++;
+ }
+ while (*ptr != '/' && ptr > v->music_dir) {
+ ptr--;
+ }
+ *ptr = 0x00;
+}
+
int
main
(int argc,
@@ -153,8 +183,6 @@ main
const char* envp[])
{
struct mpdview_s* view;
- i32_t read_size;
- char buff[BUFF_SIZE];
(void)argc;
(void)argv;
@@ -163,6 +191,7 @@ main
if (view == NULL) {
return (EXIT_FAILURE);
}
+ c_get_music_dir(view);
if (c_connect_mpd(view) != RET_OK) {
c_destroy_mpdview(&view);
return (EXIT_FAILURE);
@@ -176,20 +205,8 @@ main
c_destroy_mpdview(&view);
return (EXIT_FAILURE);
}
- dprintf(STDOUT_FILENO, "%s\n", mpd_song_get_uri(view->song));
- c_destroy_mpdview(&view);
- return (EXIT_SUCCESS);
- mpd_response_finish(view->conn);
- bzero(buff, BUFF_SIZE);
- read_size = mpd_run_albumart(view->conn, mpd_song_get_uri(view->song), 0, buff, BUFF_SIZE);
- if (read_size > -1) {
- write(STDOUT_FILENO, buff, read_size);
- }
- else {
- dprintf(STDOUT_FILENO, "Exit\n");
- }
- mpd_song_free(view->song);
- view->song = NULL;
+ c_get_current_dir(view);
+ dprintf(STDOUT_FILENO, "%s\n", view->current_dir);
}
c_destroy_mpdview(&view);
return (EXIT_SUCCESS);