Index: tools/database/database.c =================================================================== --- tools/database/database.c (Revision 20627) +++ tools/database/database.c (Arbeitskopie) @@ -1,25 +1,249 @@ -/* A _very_ skeleton file to demonstrate building tagcache db on host. */ - +/**************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Yoshihisa Uchida + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ #include +#include +#include +#include +#include "rbunicode.h" #include "tagcache.h" +const char *sim_root_dir = NULL; +const char *sim_rockbox_dir = NULL; + +#define DEFAULT_ROCKBOX_DIRECTORY "/.rockbox" + +#define DB_MODE_CREATE_STR "create" +#define DB_MODE_UPDATE_STR "update" +#define DB_MODE_COMMIT_STR "commit" +#define DB_MODE_APPEND_STR "append" + +enum {DB_MODE_CREATE, DB_MODE_UPDATE, DB_MODE_COMMIT, DB_MODE_APPEND}; + +static void show_usage(void) +{ + fprintf(stdout, "Usage: songdb -r|--root-path -m|--mode [-d|--rockbox-directory ] [-s|--song-directory ][-c|--codepage ][-h|--help][-V|--version]\n"); + fprintf(stdout, "\n"); + fprintf(stdout, "Options\n"); + fprintf(stdout, " -r|--root-path \n"); + fprintf(stdout, " Rockbox root path.\n"); + fprintf(stdout, " -m|--mode \n"); + fprintf(stdout, " create: build database newly.\n"); + fprintf(stdout, " update: update database.\n"); + fprintf(stdout, " commit: commit database.\n"); + fprintf(stdout, " append: append non registered files.\n"); + fprintf(stdout, " -d|--rockbox-directory \n"); + fprintf(stdout, " Rockbox directory.\n"); + fprintf(stdout, " -s|--song-directory \n"); + fprintf(stdout, " song storage directory.\n"); + fprintf(stdout, " -c|--codepage \n"); + fprintf(stdout, " metadata codepage\n"); + fprintf(stdout, " -h|--help\n"); + fprintf(stdout, " show this help message and exit.\n"); + fprintf(stdout, " -V|--version\n"); + fprintf(stdout, " show version information and exit.\n"); + return; +} + +static void show_version(void) +{ + fprintf(stdout, "songdb version %s\n", "test"); + fprintf(stdout, "Copyright (C) 2009 The Rockbox Team., Yoshihisa Uchida\n"); + fprintf(stdout, "Released under the GNU General Public License v2+\n"); + return; +} + +static void show_errmsg(const char *msg) +{ + fprintf(stderr, "error: %s\n", msg); + return; +} + +static int get_codepage(const char *cp) +{ + int code; + + for (code = 0; code < NUM_CODEPAGES; code++) + { + if (strcmp(cp, get_codepage_name(code)) == 0) + return code; + } + + return -1; +} + int main(int argc, char **argv) { + int idx = 0; + int mode = -1; + char rootdir[MAX_PATH] = "\0"; + char rockboxdir[MAX_PATH] = DEFAULT_ROCKBOX_DIRECTORY; + char songdir[MAX_PATH] = "/"; + int cp = UTF_8; + + for (idx = 1; idx < argc; idx++) + { + if ((strcmp(argv[idx],"-h")==0) || (strcmp(argv[idx],"--help")==0)) + { + show_usage(); + return 0; + } + else if ((strcmp(argv[idx],"-V")==0) || (strcmp(argv[idx],"--version")==0)) + { + show_version(); + return 0; + } + else if ((strcmp(argv[idx],"-r")==0) || (strcmp(argv[idx],"--root-path")==0)) + { + if ((idx == argc-1) || (argv[idx+1][0] == '-')) + { + show_usage(); + return 1; + } + idx++; + + if (strlen(argv[idx]) >= MAX_PATH) + { + show_errmsg("root path is too long."); + return 1; + } + strcpy(rootdir, argv[idx]); + } + else if ((strcmp(argv[idx],"-d")==0) || (strcmp(argv[idx],"--rockbox-directory")==0)) + { + if ((idx == argc-1) || (argv[idx+1][0] == '-')) + { + show_usage(); + return 1; + } + idx++; + + if (strlen(argv[idx]) >= MAX_PATH) + { + show_errmsg("Rockbox directory is too long."); + return 1; + } + if (argv[idx][0] != '/') + { + strcpy(rockboxdir, "/"); + strcat(rockboxdir, argv[idx]); + } + else + strncpy(rockboxdir, argv[idx], MAX_PATH); + show_errmsg(rockboxdir); + } + else if ((strcmp(argv[idx],"-s")==0) || (strcmp(argv[idx],"--song-directory")==0)) + { + if ((idx == argc-1) || (argv[idx+1][0] == '-')) + { + show_usage(); + return 1; + } + idx++; + + if (strlen(argv[idx]) >= MAX_PATH) + { + show_errmsg("song store directory is too long."); + return 1; + } + strcpy(songdir, argv[idx]); + } + else if ((strcmp(argv[idx],"-m")==0) || (strcmp(argv[idx],"--mode")==0)) + { + if (idx == argc-1) + { + show_usage(); + return 1; + } + idx++; + if (strcmp(argv[idx],DB_MODE_CREATE_STR)==0) + mode = DB_MODE_CREATE; + else if (strcmp(argv[idx],DB_MODE_UPDATE_STR)==0) + mode = DB_MODE_UPDATE; + else if (strcmp(argv[idx],DB_MODE_COMMIT_STR)==0) + mode = DB_MODE_COMMIT; + else if (strcmp(argv[idx],DB_MODE_APPEND_STR)==0) + mode = DB_MODE_APPEND; + else + { + show_errmsg("--mode is invalid."); + return 1; + } + } + else if ((strcmp(argv[idx], "-c")==0) || (strcmp(argv[idx], "--codepage")==0)) + { + if (idx == argc-1) + { + show_usage(); + return 1; + } + idx++; + cp = get_codepage(argv[idx]); + if (cp < 0) + { + show_errmsg("codepage is invalid."); + return 1; + } + } + else + { + show_usage(); + return 1; + } + } + + if (rootdir[0] == '\0' || mode < 0) + { + show_usage(); + return 1; + } + + sim_root_dir = rootdir; + sim_rockbox_dir = rockboxdir; + + set_codepage(cp); + tagcache_init(); - tagcache_build("."); - tagcache_reverse_scan(); - + + if (mode == DB_MODE_CREATE) + { + tagcache_remove_database(); + tagcache_build(songdir); + } + else if (mode == DB_MODE_UPDATE) + { + tagcache_build(songdir); + tagcache_reverse_scan(); + } + else if (mode == DB_MODE_APPEND) + { + tagcache_build(songdir); + } + else if (mode == DB_MODE_COMMIT) + { + show_errmsg("TODO"); + } + return 0; } -/* stub to avoid including all of apps/misc.c */ -bool file_exists(const char *file) -{ - if (!stat(file)) - return true; - return false; -} - /* stubs to avoid including thread-sdl.c */ #include "kernel.h" void mutex_init(struct mutex *m) Index: tools/database/readme.txt =================================================================== --- tools/database/readme.txt (Revision 0) +++ tools/database/readme.txt (Revision 0) @@ -0,0 +1,126 @@ + __________ __ ___. + Open \______ \ ____ ____ | | _\_ |__ _______ ___ + Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + \/ \/ \/ \/ \/ +$Id$ + +Copyright (C) 2009 Yoshihisa Uchida + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + KIND, either express or implied. + +========================================================================== +songdb + Create the song database (database_*.tcd) application. + + +================================================= +Usage +================================================= +songdb -r|--root-path + -m|--mode + [-d|--rockbox-directory ] + [-s|--song-directory ] + [-c|--codepage ] + [-h|--help] + [-V|--version] + +-r|--root-path + Rockbox root directory. + + / + and //codepages/*.cp + should exist. + + When the songdb is used on Windows, the drive letter is written + Windows style (such as "C:/path/of/root"). + + Song database (database_*.tcd) are build for + / directory. + +-m|--mode + create: build database newly. + + update: Files not registered in the database are added to the database. + And deleted files are deleted from the database. + + commit: The database_tmp.tcd file is changed into database_0.tcd, ..., + database_8.tcd, and database_idx.tcd files. + + append: Files not registered in the database are added to the database. + But deleted files are not deleted from the database. + +-d|--rockbox-directory + Rockbox directory. + If this option is not given, then Rockbox directory is ".rockbox". + +-s|--song-directory + song storage directory. + If begins with a "/", then it looks for the song file + from /. + If does not begin with a "/", then it looks for the song + file from //. + + If this option is not given, then = "/". + + When using songdb on MinGW+MSYS shell, it should be set not /hoge but //hoge. + +-c|--codepage + metadata codepage. + If this option is not given, then metadata codepage is "UTF-8". + + codepage list + option value codepage + ----------------------------------------------- + ISO-8859-1 Latin1 (ISO-8859-1) + ISO-8859-2 Latin Extended (ISO-8859-2) + ISO-8859-7 Greek (ISO-8859-7) + ISO-8859-8 Hebrew (ISO-8859-8) + ISO-8859-9 Turkish (ISO-8859-9) + ISO-8859-11 Thai (ISO-8859-11) + CP1250 Central European (CP1250) + CP1251 Cyrillic (CP1251) + CP1256 Arabic (CP1256) + SJIS Japanese (SJIS) + GB-2312 Simple Chinese (GB2312) + KSX-1001 Korean (KSX1001) + BIG-5 Traditional Chinese (BIG5) + UTF-8 Unicode (UTF-8) + +-h|--help + show help message and exit. + +-V|--version + show version information and exit. + +================================================= +Requirement +================================================= +OS + 1) Windows + - Cygwin or MinGW (with MSYS) must be installed. + + 2) Linux + + Other OS do not checked. + +When the songdb does not use the SDL library, then the SDL library +may not be installed. + +================================================= +Build +================================================= +1) edit Makefile (gcc options) +2) make + +================================================= +TODO +================================================= +1) The folder of song database can be freely set. Index: tools/database/Makefile =================================================================== --- tools/database/Makefile (Revision 20627) +++ tools/database/Makefile (Arbeitskopie) @@ -3,7 +3,7 @@ endif INCLUDE = -I../../firmware/export \ -I../../apps -I../../uisimulator/sdl -I/usr/include/SDL -FIRMINC = -I../../firmware/include -fno-builtin +FIRMINC = -I../../firmware/include DEFINES = -D__PCTOOL__ -DHAVE_TAGCACHE -DSIMULATOR -DCONFIG_CODEC=1 \ -DROCKBOX_LITTLE_ENDIAN -DROCKBOX_DIR=\".rockbox\" -DROCKBOX_HAS_LOGF \ -DCONFIG_CODEC=1 Index: apps/tagcache.c =================================================================== --- apps/tagcache.c (Revision 20627) +++ apps/tagcache.c (Arbeitskopie) @@ -60,13 +60,13 @@ #include #include #include +#include #include "config.h" #include "ata_idle_notify.h" #include "thread.h" #include "kernel.h" #include "system.h" #include "logf.h" -#include "string.h" #include "usb.h" #include "metadata.h" #include "metadata.h" @@ -86,7 +86,10 @@ #ifdef __PCTOOL__ #define yield() do { } while(0) -#define sim_sleep(timeout) do { } while(0) +#ifdef sleep +#undef sleep +#endif +#define sleep(timeout) do { } while(0) #define do_timed_yield() do { } while(0) #endif @@ -1164,6 +1167,13 @@ } } +#ifdef __PCTOOL__ +void tagcache_remove_database(void) +{ + remove_files(); + remove(TAGCACHE_FILE_TEMP); +} +#endif static bool check_all_headers(void) { @@ -3018,6 +3028,7 @@ return write_index(masterfd, idx_id, &idx); } +#endif #if 0 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, @@ -3035,6 +3046,7 @@ } #endif +#ifndef __PCTOOL__ #define COMMAND_QUEUE_IS_EMPTY (command_queue_ridx == command_queue_widx) static bool command_queue_is_full(void) @@ -3160,7 +3172,6 @@ { queue_command(CMD_UPDATE_NUMERIC, idx_id, tag, data); } -#endif /* !__PCTOOL__ */ long tagcache_get_serial(void) { @@ -3171,6 +3182,7 @@ { return current_tcmh.commitid; } +#endif /* !__PCTOOL__ */ static bool write_tag(int fd, const char *tagstr, const char *datastr) { Index: apps/tagcache.h =================================================================== --- apps/tagcache.h (Revision 20627) +++ apps/tagcache.h (Arbeitskopie) @@ -179,6 +179,7 @@ #ifdef __PCTOOL__ void tagcache_reverse_scan(void); +void tagcache_remove_database(void); #endif const char* tagcache_tag_to_str(int tag); Index: apps/misc.c =================================================================== --- apps/misc.c (Revision 20627) +++ apps/misc.c (Arbeitskopie) @@ -27,9 +27,7 @@ #ifdef __PCTOOL__ #include #include -#ifdef WPSEDITOR -#include "string.h" -#endif +#include #else #include "sprintf.h" #include "appevents.h" @@ -765,26 +763,6 @@ return s; } -/* Test file existence, using dircache of possible */ -bool file_exists(const char *file) -{ - int fd; - - if (!file || strlen(file) <= 0) - return false; - -#ifdef HAVE_DIRCACHE - if (dircache_is_enabled()) - return (dircache_get_entry_ptr(file) != NULL); -#endif - - fd = open(file, O_RDONLY); - if (fd < 0) - return false; - close(fd); - return true; -} - bool dir_exists(const char *path) { DIR* d = opendir(path); @@ -838,6 +816,26 @@ return s; } +/* Test file existence, using dircache of possible */ +bool file_exists(const char *file) +{ + int fd; + + if (!file || strlen(file) <= 0) + return false; + +#ifdef HAVE_DIRCACHE + if (dircache_is_enabled()) + return (dircache_get_entry_ptr(file) != NULL); +#endif + + fd = open(file, O_RDONLY); + if (fd < 0) + return false; + close(fd); + return true; +} + /* Format time into buf. * * buf - buffer to format to. Index: firmware/include/stdio.h =================================================================== --- firmware/include/stdio.h (Revision 20627) +++ firmware/include/stdio.h (Arbeitskopie) @@ -1,3 +1,4 @@ + #ifndef _STDIO_H_ #define _STDIO_H_ @@ -34,7 +35,7 @@ #endif int snprintf (char *buf, size_t size, const char *fmt, ...); -int vsnprintf (char *buf, int size, const char *fmt, __VALIST ap); +int vsnprintf (char *buf, size_t size, const char *fmt, __VALIST ap); #ifdef SIMULATOR typedef void FILE; @@ -45,4 +46,17 @@ #endif #endif +#if defined(__PCTOOL__) +int printf(const char* fmt, ...); +int fprintf(FILE *stream, const char *format, ...); + +/* Standard streams (based off linux' stdio.h. */ +extern FILE *stdin; +extern FILE *stdout; +extern FILE *stderr; +/* C89/C99 say they're macros. Make them happy. */ +#define stdin stdin +#define stdout stdout +#define stderr stderr +#endif #endif /* _STDIO_H_ */