diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_defines.h | 4 | ||||
-rw-r--r-- | src/c_mpdview.c | 51 | ||||
-rw-r--r-- | src/c_mpdview.h | 4 |
3 files changed, 41 insertions, 18 deletions
diff --git a/src/c_defines.h b/src/c_defines.h index 923cbb5..47d03b6 100644 --- a/src/c_defines.h +++ b/src/c_defines.h @@ -55,7 +55,7 @@ typedef char i8_t; typedef short i16_t; typedef int i32_t; typedef long i64_t; -typedef void* ptr_t; +typedef char* ptr_t; enum bool_e { FALSE, @@ -70,4 +70,6 @@ enum ret_e { #define BUFF_SIZE 262144 #define PROGNAME "mpdview" +#define DEF_MUSIC_DIR "/home/jozan/mu" + #endif /* __C_DEFINES_H__ */ 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); diff --git a/src/c_mpdview.h b/src/c_mpdview.h index 25527ab..a96df4a 100644 --- a/src/c_mpdview.h +++ b/src/c_mpdview.h @@ -46,6 +46,8 @@ #ifndef __C_MPDVIEW_H__ #define __C_MPDVIEW_H__ +#include <sys/param.h> + #include <mpd/connection.h> #include <mpd/song.h> #include <mpd/status.h> @@ -55,6 +57,8 @@ struct mpdview_s { struct mpd_status* status; struct mpd_song* song; enum mpd_state state; + char music_dir[PATH_MAX]; + char current_dir[PATH_MAX]; }; #endif /* __C_MPDVIEW_H__ */ |