From 7065b6312ebae611f8bdadd921dcd7aa6d6523c6 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 7 Dec 2015 09:35:58 -0500 Subject: [PATCH] core/collection: Convert file to C Signed-off-by: Anna Schumaker --- core/audio.cpp | 4 +- core/{library.cpp => collection.c} | 24 +++++----- core/core.cpp | 2 +- core/deck.cpp | 5 +- core/playlist.cpp | 4 +- gui/collection.cpp | 4 +- gui/manager.cpp | 5 +- include/core/{library.h => collection.h} | 9 ++-- tests/core/.gitignore | 2 +- tests/core/Sconscript | 2 +- tests/core/audio.cpp | 2 +- tests/core/{library.cpp => collection.c} | 60 ++++++++++++------------ tests/core/deck.cpp | 2 +- tests/core/playlist.cpp | 2 +- 14 files changed, 63 insertions(+), 64 deletions(-) rename core/{library.cpp => collection.c} (91%) rename include/core/{library.h => collection.h} (91%) rename tests/core/{library.cpp => collection.c} (73%) diff --git a/core/audio.cpp b/core/audio.cpp index 6d84e414..2b3eb277 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -2,8 +2,10 @@ * Copyright 2013 (c) Anna Schumaker. */ #include +extern "C" { +#include +} #include -#include #include diff --git a/core/library.cpp b/core/collection.c similarity index 91% rename from core/library.cpp rename to core/collection.c index e26bab14..806e0c2d 100644 --- a/core/library.cpp +++ b/core/collection.c @@ -1,13 +1,11 @@ -/** +/* * Copyright 2013 (c) Anna Schumaker. */ -extern "C" { +#include #include -} -#include -#include #include +#include static struct queue library_q; @@ -23,7 +21,7 @@ static void __scan_dir(void *); static void __scan_dir_later(struct library *library, const gchar *dir) { - struct scan_data *data = new struct scan_data; + struct scan_data *data = g_malloc(sizeof(struct scan_data)); data->sd_lib = library; data->sd_path = g_strdup(dir); @@ -50,10 +48,11 @@ static void __scan_path(struct scan_data *scan, const gchar *name) static void __scan_dir(void *data) { - struct scan_data *scan = (struct scan_data *)data; - GDir *dir = g_dir_open(scan->sd_path, 0, NULL); + struct scan_data *scan = data; const char *name; + GDir *dir; + dir = g_dir_open(scan->sd_path, 0, NULL); if (dir == NULL) goto out; @@ -69,12 +68,12 @@ static void __scan_dir(void *data) out: /* Allocated by __scan_dir_later() */ g_free(scan->sd_path); - delete scan; + g_free(scan); } static void __validate_library(void *data) { - struct library *library = (struct library *)data; + struct library *library = data; struct db_entry *dbe, *next; struct track *track; gchar *path; @@ -118,10 +117,9 @@ void collection_init(struct queue_ops *ops) for (i = 0; i < n; i++) { file_readf(&c_file, "%u %d", &field, &ascending); - queue_sort(&library_q, (compare_t)(field + 1), - (i == 0) ? true : false); + queue_sort(&library_q, field + 1, (i == 0) ? true : false); if (ascending == false) - queue_sort(&library_q, (compare_t)(field + 1), false); + queue_sort(&library_q, field + 1, false); } file_close(&c_file); diff --git a/core/core.cpp b/core/core.cpp index e0d84f20..9d385207 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -5,10 +5,10 @@ #include #include extern "C" { +#include #include #include } -#include #include diff --git a/core/deck.cpp b/core/deck.cpp index 260b4613..0caeb412 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -1,10 +1,11 @@ /** * Copyright 2013 (c) Anna Schumaker. */ +extern "C" { +#include +} #include #include -#include - static std::list queue_deck; static struct queue recent_queue; diff --git a/core/playlist.cpp b/core/playlist.cpp index e0ea228e..f274c806 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -1,7 +1,9 @@ /** * Copyright 2013 (c) Anna Schumaker. */ -#include +extern "C" { +#include +} #include diff --git a/gui/collection.cpp b/gui/collection.cpp index 377c44db..c5571fdc 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -1,7 +1,9 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include +extern "C" { +#include +} #include #include #include diff --git a/gui/manager.cpp b/gui/manager.cpp index 27d57736..25e503cb 100644 --- a/gui/manager.cpp +++ b/gui/manager.cpp @@ -2,11 +2,10 @@ * Copyright 2014 (c) Anna Schumaker. */ extern "C" { -#include +#include +#include #include } -#include -#include #include #include diff --git a/include/core/library.h b/include/core/collection.h similarity index 91% rename from include/core/library.h rename to include/core/collection.h index c1d4b5c5..f3822974 100644 --- a/include/core/library.h +++ b/include/core/collection.h @@ -10,13 +10,10 @@ * * flags sort.length ... sort[N].field sort[N].ascending ... */ -#ifndef OCARINA_CORE_LIBRARY_H -#define OCARINA_CORE_LIBRARY_H +#ifndef OCARINA_CORE_COLLECTION_H +#define OCARINA_CORE_COLLECTION_H -extern "C" { #include -} -#include /* Called to initialize the collection manager. */ @@ -48,4 +45,4 @@ void collection_set_enabled(struct library *, bool); /* Called to access the collection queue. */ struct queue *collection_get_queue(); -#endif /* OCARINA_CORE_LIBRARY_H */ +#endif /* OCARINA_CORE_COLLECTION_H */ diff --git a/tests/core/.gitignore b/tests/core/.gitignore index 06c07df3..57d975db 100644 --- a/tests/core/.gitignore +++ b/tests/core/.gitignore @@ -1,4 +1,5 @@ audio +collection database date deck @@ -7,7 +8,6 @@ file filter idle index -library playlist queue random diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 2dce6d5b..bc70c3b9 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -25,7 +25,7 @@ res += [ CoreTest("idle", "idle.c") ] res += SConscript("tags/Sconscript") res += [ CoreTest("queue", "queue.c") ] -res += [ CoreTest("library", "library.cpp") ] +res += [ CoreTest("collection", "collection.c") ] res += [ CoreTest("playlist", "playlist.cpp") ] res += [ CoreTest("deck", "deck.cpp") ] res += [ CoreTest("audio", "audio.cpp") ] diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index a53f3290..ed103331 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -3,11 +3,11 @@ */ #include extern "C" { +#include #include #include } #include -#include #include "test.h" struct track *TRACK_NULL = NULL; diff --git a/tests/core/library.cpp b/tests/core/collection.c similarity index 73% rename from tests/core/library.cpp rename to tests/core/collection.c index 831be689..b51c1509 100644 --- a/tests/core/library.cpp +++ b/tests/core/collection.c @@ -1,13 +1,11 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -extern "C" { +#include #include #include #include -} -#include -#include "test.h" +#include static void test_init() { @@ -18,12 +16,12 @@ static void test_init() tags_init(); collection_init(NULL); - test_not_equal(q, NULL); - test_equal(queue_has_flag(q, Q_ENABLED), true); - test_equal(queue_has_flag(q, Q_REPEAT), true); - test_equal(queue_has_flag(q, Q_SAVE_SORT), true); - test_equal(queue_has_flag(q, Q_SAVE_FLAGS), true); - test_equal(queue_has_flag(q, Q_ADD_FRONT), false); + test_not_equal((void *)q, NULL); + test_equal(queue_has_flag(q, Q_ENABLED), (bool)true); + test_equal(queue_has_flag(q, Q_REPEAT), (bool)true); + test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)true); + test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)true); + test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)false); test_equal(queue_size(q), 0); list = q->q_sort; @@ -40,19 +38,19 @@ static void test_add() struct queue *q = collection_get_queue(); struct library *lib; - test_equal(collection_add("tests/Invalid"), NULL); + test_equal((void *)collection_add("tests/Invalid"), NULL); lib = collection_add("tests/Music"); - test_not_equal(lib, NULL); + test_not_equal((void *)lib, NULL); test_equal(lib->li_size, 0); - test_equal(lib->li_enabled, true); + test_equal(lib->li_enabled, (bool)true); test_equal(lib->li_path, "tests/Music"); test_equal(queue_size(q), 0); - test_equal(idle_run_task(), true); /* collection validation */ - test_equal(idle_run_task(), true); /* tests/Music/ */ - test_equal(idle_run_task(), true); /* tests/Music/Hyrule Symphony/ */ - test_equal(idle_run_task(), false); /* tests/Music/Ocarina of Time/ */ + test_equal(idle_run_task(), (bool)true); /* collection validation */ + test_equal(idle_run_task(), (bool)true); /* tests/Music/ */ + test_equal(idle_run_task(), (bool)true); /* /Hyrule Symphony/ */ + test_equal(idle_run_task(), (bool)false); /* /Ocarina of Time/ */ test_equal(track_db_get()->db_size, 48); test_equal(lib->li_size, 48); @@ -73,20 +71,20 @@ static void test_update() collection_update(lib); /* Collection validation removes tests/Music/Hyrule Symphony/ */ - test_equal(idle_run_task(), true); + test_equal(idle_run_task(), (bool)true); test_equal(track_db_get()->db_size, 35); test_equal(lib->li_size, 35); test_equal(queue_size(q), 35); /* tests/Music and tests/Music/Ocarina of Time/ have not changed */ - test_equal(idle_run_task(), true); - test_equal(idle_run_task(), true); + test_equal(idle_run_task(), (bool)true); + test_equal(idle_run_task(), (bool)true); test_equal(track_db_get()->db_size, 35); test_equal(lib->li_size, 35); test_equal(queue_size(q), 35); /* Scan tests/Music/symphony/ */ - test_equal(idle_run_task(), false); + test_equal(idle_run_task(), (bool)false); test_equal(track_db_get()->db_size, 48); test_equal(lib->li_size, 48); test_equal(queue_size(q), 48); @@ -98,20 +96,20 @@ static void test_update() * Collection validation removes tests/Music/symphony/, * and tests/Music has not changed */ - test_equal(idle_run_task(), true); - test_equal(idle_run_task(), true); + test_equal(idle_run_task(), (bool)true); + test_equal(idle_run_task(), (bool)true); test_equal(track_db_get()->db_size, 35); test_equal(lib->li_size, 35); test_equal(queue_size(q), 35); /* tests/Music/Hyrule Symphony exists again */ - test_equal(idle_run_task(), true); + test_equal(idle_run_task(), (bool)true); test_equal(track_db_get()->db_size, 48); test_equal(lib->li_size, 48); test_equal(queue_size(q), 48); /* tests/Music/Ocarina of Time/ has not changed */ - test_equal(idle_run_task(), false); + test_equal(idle_run_task(), (bool)false); test_equal(track_db_get()->db_size, 48); test_equal(lib->li_size, 48); test_equal(queue_size(q), 48); @@ -144,14 +142,14 @@ static void test_save_load() GSList *list; collection_save(NULL, Q_ENABLED); - test_equal(test_data_file_exists("library.q"), false); + test_equal(test_data_file_exists("library.q"), (bool)false); - queue_sort(q, COMPARE_TRACK, true); - queue_sort(q, COMPARE_TRACK, false); - queue_sort(q, COMPARE_GENRE, false); + queue_sort(q, COMPARE_TRACK, (bool)true); + queue_sort(q, COMPARE_TRACK, (bool)false); + queue_sort(q, COMPARE_GENRE, (bool)false); collection_save(q, Q_ENABLED); - test_equal(test_data_file_exists("library.q"), true); + test_equal(test_data_file_exists("library.q"), (bool)true); collection_deinit(); test_equal(queue_size(q), 0); @@ -176,7 +174,7 @@ static void test_remove() collection_remove(library_get(0)); test_equal(track_db_get()->db_size, 0); - test_equal(library_get(0), NULL); + test_equal((void *)library_get(0), NULL); test_equal(queue_size(q), 0); collection_deinit(); diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index 07d1fd58..8498a6a1 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -3,10 +3,10 @@ */ #include extern "C" { +#include #include #include } -#include #include "test.h" static queue *Q_NULL = NULL; diff --git a/tests/core/playlist.cpp b/tests/core/playlist.cpp index aaa8c98f..33ae7e88 100644 --- a/tests/core/playlist.cpp +++ b/tests/core/playlist.cpp @@ -2,10 +2,10 @@ * Copyright 2013 (c) Anna Schumaker. */ extern "C" { +#include #include #include } -#include #include #include "test.h"