Add a version readings args instead of MPD library
This commit is contained in:
parent
3f16114d1b
commit
54cf7074e8
@ -4,7 +4,7 @@ project (MPDBliss C)
|
|||||||
|
|
||||||
add_subdirectory (bliss)
|
add_subdirectory (bliss)
|
||||||
|
|
||||||
file (GLOB MPDBLISS_SRC "src/*.c")
|
file (GLOB COMMON_SRC "src/*.c")
|
||||||
|
|
||||||
# TODO \/
|
# TODO \/
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
@ -23,10 +23,19 @@ add_definitions (-Wall -Wno-long-long -pedantic -std=c99)
|
|||||||
# TODO /\
|
# TODO /\
|
||||||
|
|
||||||
add_executable (mpdbliss
|
add_executable (mpdbliss
|
||||||
${MPDBLISS_SRC})
|
${COMMON_SRC} "main_mpd.c")
|
||||||
|
|
||||||
target_link_libraries (mpdbliss
|
target_link_libraries (mpdbliss
|
||||||
m
|
m
|
||||||
sqlite3
|
sqlite3
|
||||||
mpdclient
|
mpdclient
|
||||||
bliss)
|
bliss)
|
||||||
|
|
||||||
|
|
||||||
|
add_executable (argsbliss
|
||||||
|
${COMMON_SRC} "main_args.c")
|
||||||
|
|
||||||
|
target_link_libraries (argsbliss
|
||||||
|
m
|
||||||
|
sqlite3
|
||||||
|
bliss)
|
||||||
|
51
main_args.c
Normal file
51
main_args.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
#include "analysis.h"
|
||||||
|
#include "utilities.h"
|
||||||
|
|
||||||
|
// TODO: Handle deletions from db
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("Usage: %s basepath [relative_filenames].\n", argv[0]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get data directory, init db file
|
||||||
|
char mpdbliss_data_folder[DEFAULT_STRING_LENGTH] = "";
|
||||||
|
char mpdbliss_data_db[DEFAULT_STRING_LENGTH] = "";
|
||||||
|
if (0 != _init_db(mpdbliss_data_folder, mpdbliss_data_db)) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *base_path = argv[1];
|
||||||
|
|
||||||
|
// Connect to SQLite db
|
||||||
|
sqlite3 *dbh;
|
||||||
|
if (0 != sqlite3_open(mpdbliss_data_db, &dbh)) {
|
||||||
|
fprintf(stderr, "Unable to open SQLite db.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
int dberr = sqlite3_exec(dbh, "PRAGMA foreign_keys = ON", NULL, NULL, NULL);
|
||||||
|
if (SQLITE_OK != dberr) {
|
||||||
|
fprintf(stderr, "Unable to open SQLite db.\n");
|
||||||
|
sqlite3_close(dbh);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 2; i < argc; ++i) {
|
||||||
|
_parse_music_helper(dbh, base_path, argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close SQLite connection
|
||||||
|
sqlite3_close(dbh);
|
||||||
|
|
||||||
|
printf("Done! :)\n");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
@ -76,6 +76,12 @@ long int update_database(
|
|||||||
fprintf(stderr, "Unable to open SQLite db.\n");
|
fprintf(stderr, "Unable to open SQLite db.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
int dberr = sqlite3_exec(dbh, "PRAGMA foreign_keys = ON", NULL, NULL, NULL);
|
||||||
|
if (SQLITE_OK != dberr) {
|
||||||
|
fprintf(stderr, "Unable to open SQLite db.\n");
|
||||||
|
sqlite3_close(dbh);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the received list in memory, to prevent timeout
|
// Retrieve the received list in memory, to prevent timeout
|
||||||
struct mpd_entity **entities = malloc(sizeof(struct mpd_entity *) * n_songs);
|
struct mpd_entity **entities = malloc(sizeof(struct mpd_entity *) * n_songs);
|
BIN
src/.main.c.swp
BIN
src/.main.c.swp
Binary file not shown.
Loading…
Reference in New Issue
Block a user