From 1b4eb470a73e2988e8688ab676fb6836f2890342 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 12 Nov 2015 08:13:53 -0500 Subject: [PATCH] core/tags/library: Convert file to C Signed-off-by: Anna Schumaker --- core/tags/{library.cpp => library.c} | 6 +++--- core/tags/tags.cpp | 2 +- include/core/tags/library.h | 25 +++++++++------------- include/core/tags/track.h | 4 +++- tests/core/tags/Sconscript | 2 +- tests/core/tags/{library.cpp => library.c} | 22 +++++++++---------- 6 files changed, 29 insertions(+), 32 deletions(-) rename core/tags/{library.cpp => library.c} (95%) rename tests/core/tags/{library.cpp => library.c} (85%) diff --git a/core/tags/library.cpp b/core/tags/library.c similarity index 95% rename from core/tags/library.cpp rename to core/tags/library.c index 525a2b5a..d0a74224 100644 --- a/core/tags/library.cpp +++ b/core/tags/library.c @@ -1,4 +1,4 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker. */ #include @@ -8,7 +8,7 @@ static struct database library_db; static struct library *__library_alloc(gchar *path, bool enabled) { - struct library *library = new struct library; + struct library *library = g_malloc(sizeof(struct library)); dbe_init(&library->li_dbe, library); library->li_size = 0; @@ -25,7 +25,7 @@ static struct db_entry *library_alloc(const gchar *path) static void library_free(struct db_entry *dbe) { - delete LIBRARY(dbe); + g_free(LIBRARY(dbe)); } static gchar *library_key(struct db_entry *dbe) diff --git a/core/tags/tags.cpp b/core/tags/tags.cpp index 1d5c1264..fa1e24c4 100644 --- a/core/tags/tags.cpp +++ b/core/tags/tags.cpp @@ -5,8 +5,8 @@ extern "C" { #include #include #include -} #include +} #include #include diff --git a/include/core/tags/library.h b/include/core/tags/library.h index 376f4d35..e9e1a242 100644 --- a/include/core/tags/library.h +++ b/include/core/tags/library.h @@ -1,25 +1,20 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker. + * + * The Library tag is used to store a single directory added + * to Ocarina by the user. + * + * When writing a Library tag to disk, write out the library_enabled + * and library_path fields for each tag. + * + * ... true /home/Zelda/Music + * ... false /home/Link/Music */ #ifndef OCARINA_CORE_TAGS_LIBRARY_H #define OCARINA_CORE_TAGS_LIBRARY_H -extern "C" { #include -} -#include -/** - * The Library tag is used to store a single directory added - * to Ocarina by the user. - * - * When writing a Library tag to disk, write out the _enabled - * and _path fields for each tag. - * - * ... << enabled1 << path1 - * ... << enabled2 << path2 - * ... << enabled3 << path3 - */ struct library { unsigned int li_size; /* This library's track count. */ bool li_enabled;/* True if this library is enabled. */ diff --git a/include/core/tags/track.h b/include/core/tags/track.h index c011bb3e..3e1a5151 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -10,8 +10,10 @@ extern "C" { #include #include #include -} #include +} + +#include /** diff --git a/tests/core/tags/Sconscript b/tests/core/tags/Sconscript index a6c49736..e4ff5169 100644 --- a/tests/core/tags/Sconscript +++ b/tests/core/tags/Sconscript @@ -14,7 +14,7 @@ def TagTest(name, source): res = [ TagTest("album", "album.c") ] res += [ TagTest("artist", "artist.c") ] res += [ TagTest("genre", "genre.c") ] -res += [ TagTest("library", "library.cpp") ] +res += [ TagTest("library", "library.c") ] env.UsePackage("taglib_c") core_objs += [ env.Object("../../../core/tags/tags.cpp") ] diff --git a/tests/core/tags/library.cpp b/tests/core/tags/library.c similarity index 85% rename from tests/core/tags/library.cpp rename to tests/core/tags/library.c index 3dee318c..2329b035 100644 --- a/tests/core/tags/library.cpp +++ b/tests/core/tags/library.c @@ -1,13 +1,13 @@ -/** +/* * Copyright 2014 (c) Anna Schumaker. */ #include -#include "../test.h" +#include static void test_verify_zelda(struct library *library) { const struct db_ops *library_ops = test_library_ops(); - test_equal(library->li_enabled, true); + test_equal(library->li_enabled, (bool)true); test_equal(library->li_size, 0); test_equal(library_ops->dbe_key(&library->li_dbe), "/home/Zelda/Music"); } @@ -15,7 +15,7 @@ static void test_verify_zelda(struct library *library) static void test_verify_link(struct library *library) { const struct db_ops *library_ops = test_library_ops(); - test_equal(library->li_enabled, false); + test_equal(library->li_enabled, (bool)false); test_equal(library->li_size, 0); test_equal(library_ops->dbe_key(&library->li_dbe), "/home/Link/Music"); } @@ -24,7 +24,7 @@ static void test_library() { const struct db_ops *library_ops = test_library_ops(); struct library *link, *zelda, *library; - file f; + struct file f; link = LIBRARY(library_ops->dbe_alloc("/home/Link/Music")); zelda = LIBRARY(library_ops->dbe_alloc("/home/Zelda/Music")); @@ -71,7 +71,7 @@ static void test_library_db() struct library *library, *library2; struct database library_db; - test_not_equal(library_db_get(), NULL); + test_not_equal((void *)library_db_get(), NULL); test_equal(library_db_get()->db_size, 0); library_db_init(); @@ -79,9 +79,9 @@ static void test_library_db() test_verify_zelda(library); test_equal(library_db_get()->db_size, 1); - test_equal(library_find("/home/Zelda/Music"), library); - test_equal(library_get(0), library); - test_equal(library_get(1), (struct library *)NULL); + test_equal((void *)library_find("/home/Zelda/Music"), (void *)library); + test_equal((void *)library_get(0), (void *)library); + test_equal((void *)library_get(1), NULL); db_init(&library_db, "library.db", false, library_ops); db_load(&library_db); @@ -89,11 +89,11 @@ static void test_library_db() test_equal(db_actual_size(&library_db), 1); library2 = LIBRARY(db_at(&library_db, 0)); - test_not_equal(library2, NULL); + test_not_equal((void *)library2, NULL); test_verify_zelda(library2); library_remove(library); - test_equal(library_get(0), (struct library *)NULL); + test_equal((void *)library_get(0), (void *)NULL); test_equal(library_db_get()->db_size, 0); library_db_deinit();