diff --git a/apps/misc.c b/apps/misc.c index d7a64b3..481dc2a 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -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 @@ char* strrsplt(char* str, int c) 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 @@ char* skip_whitespace(char* const str) 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. diff --git a/apps/tagcache.c b/apps/tagcache.c index 2b2881a..15c1218 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -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 @@ static void remove_files(void) } } +#ifdef __PCTOOL__ +void tagcache_remove_database(void) +{ + remove_files(); + remove(TAGCACHE_FILE_TEMP); +} +#endif static bool check_all_headers(void) { @@ -3018,6 +3028,7 @@ static bool modify_numeric_entry(int masterfd, int idx_id, int tag, long data) return write_index(masterfd, idx_id, &idx); } +#endif #if 0 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, @@ -3035,6 +3046,7 @@ bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, } #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 @@ void tagcache_update_numeric(int idx_id, int tag, long data) { queue_command(CMD_UPDATE_NUMERIC, idx_id, tag, data); } -#endif /* !__PCTOOL__ */ long tagcache_get_serial(void) { @@ -3171,6 +3182,7 @@ long tagcache_get_commitid(void) { return current_tcmh.commitid; } +#endif /* !__PCTOOL__ */ static bool write_tag(int fd, const char *tagstr, const char *datastr) { diff --git a/apps/tagcache.h b/apps/tagcache.h index e995784..6d4f634 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -179,6 +179,7 @@ void tagcache_build(const char *path); #ifdef __PCTOOL__ void tagcache_reverse_scan(void); +void tagcache_remove_database(void); #endif const char* tagcache_tag_to_str(int tag); diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c index 61989e5..062576d 100644 --- a/firmware/common/unicode.c +++ b/firmware/common/unicode.c @@ -40,7 +40,7 @@ static int default_codepage = 0; static int loaded_cp_table = 0; -#ifdef HAVE_LCD_BITMAP +#if defined(HAVE_LCD_BITMAP) || defined(__PCTOOL__) #define MAX_CP_TABLE_SIZE 32768 #define NUM_TABLES 5 @@ -194,7 +194,7 @@ unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8, case ISO_8859_9: /* Turkish */ case ISO_8859_2: /* Latin Extended */ case WIN_1250: /* Central European */ -#ifdef HAVE_LCD_BITMAP +#if defined(HAVE_LCD_BITMAP) || defined(__PCTOOL__) case ISO_8859_8: /* Hebrew */ case ISO_8859_11: /* Thai */ case WIN_1256: /* Arabic */ @@ -203,7 +203,7 @@ unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8, ucs = codepage_table[tmp]; break; -#ifdef HAVE_LCD_BITMAP +#if defined(HAVE_LCD_BITMAP) || defined(__PCTOOL__) case SJIS: /* Japanese */ if (*iso > 0xA0 && *iso < 0xE0) { tmp = *iso++ | (0xA100 - 0x8000); diff --git a/firmware/include/rbunicode.h b/firmware/include/rbunicode.h index 39fe253..6322816 100644 --- a/firmware/include/rbunicode.h +++ b/firmware/include/rbunicode.h @@ -35,7 +35,7 @@ #define MASK 0xC0 /* 11000000 */ #define COMP 0x80 /* 10x */ -#ifdef HAVE_LCD_BITMAP +#if defined(HAVE_LCD_BITMAP) || defined(__PCTOOL__) enum codepages { ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251, diff --git a/tools/database/Makefile b/tools/database/Makefile old mode 100644 new mode 100755 index 2c20bb7..9d680e7 --- a/tools/database/Makefile +++ b/tools/database/Makefile @@ -1,20 +1,39 @@ ifndef V SILENT = @ endif -INCLUDE = -I../../firmware/export \ - -I../../apps -I../../uisimulator/sdl -I/usr/include/SDL -FIRMINC = -I../../firmware/include -fno-builtin +CC = gcc +INCLUDE = -I../../firmware/export -I../../apps +FIRMINC = -I../../firmware/include DEFINES = -D__PCTOOL__ -DHAVE_TAGCACHE -DSIMULATOR -DCONFIG_CODEC=1 \ - -DROCKBOX_LITTLE_ENDIAN -DROCKBOX_DIR=\".rockbox\" -DROCKBOX_HAS_LOGF \ + -DROCKBOX_LITTLE_ENDIAN -DROCKBOX_DIR=\".\" -DROCKBOX_HAS_LOGF \ -DCONFIG_CODEC=1 -CFLAGS = -g $(INCLUDE) $(DEFINES) -Wno-pointer-sign +LIBS = +CFLAGS = -g $(INCLUDE) $(DEFINES) + +GCC_VER := $(shell $(CC) -dumpversion | sed -e 's/\..*//') + +ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) + ifneq "$(GCC_VER)" "4" + CFLAGS += -mno-cygwin + endif +else + ifneq ($(findstring MINGW,$(shell uname)),MINGW) + LIBS += -ldl + endif +endif + +# -Wno-pointer-sign supports gcc 4.X.X (not supprt 3.X.X) +ifeq "$(GCC_VER)" "4" + CFLAGS += -Wno-pointer-sign +endif SRC = database.o tagcache.o replaygain.o \ metadata.o metadata_common.o mp3data.o \ a52.o mp3.o adx.o mp4.o aiff.o mpc.o ape.o ogg.o \ asap.o sid.o asf.o spc.o flac.o vorbis.o wave.o \ mod.o wavpack.o monkeys.o \ - logf.o unicode.o ctype.o structec.o crc32.o io.o misc.o + logf.o unicode.o ctype.o structec.o crc32.o io.o misc.o \ + strcasestr.o errno.o OBJ = $(SRC:.c=.o) @@ -36,7 +55,7 @@ all: $(TARGET) database: $(OBJ) @echo LD $@ - $(SILENT)$(CC) -g -ldl -o $@ $+ + $(SILENT)$(CC) $(CFLAGS) $(LIBS) -o $@ $+ clean: - rm -f $(OBJ) $(TARGET) + rm -f $(OBJ) $(TARGET) $(TARGET).exe diff --git a/tools/database/database.c b/tools/database/database.c index a8be48a..a17ee15 100644 --- a/tools/database/database.c +++ b/tools/database/database.c @@ -1,49 +1,236 @@ -/* 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" -int main(int argc, char **argv) +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_APPEND_STR "append" + +enum {DB_MODE_CREATE, DB_MODE_UPDATE, DB_MODE_APPEND}; + +static void show_usage(void) { - tagcache_init(); - tagcache_build("."); - tagcache_reverse_scan(); - - return 0; + printf("Usage: songdb -r|--root-path -m|--mode [-d|--rockbox-directory ] [-s|--song-directory ][-c|--codepage ][-h|--help][-V|--version]\n"); + printf("\n"); + printf("Options\n"); + printf(" -r|--root-path \n"); + printf(" Rockbox root path.\n"); + printf(" -m|--mode \n"); + printf(" create: build database newly.\n"); + printf(" update: update database.\n"); + printf(" append: append non registered files.\n"); + printf(" -d|--rockbox-directory \n"); + printf(" Rockbox directory.\n"); + printf(" -s|--song-directory \n"); + printf(" song storage directory.\n"); + printf(" -c|--codepage \n"); + printf(" metadata codepage\n"); + printf(" -h|--help\n"); + printf(" show this help message and exit.\n"); + printf(" -V|--version\n"); + printf(" show version information and exit.\n"); + return; } -/* stub to avoid including all of apps/misc.c */ -bool file_exists(const char *file) +static void show_version(void) { - if (!stat(file)) - return true; - return false; + printf("songdb version %s\n", "test"); + printf("Copyright (C) 2009 The Rockbox Team., Yoshihisa Uchida\n"); + printf("Released under the GNU General Public License v2+\n"); + return; } -/* stubs to avoid including thread-sdl.c */ -#include "kernel.h" -void mutex_init(struct mutex *m) +static void show_errmsg(const char *msg) { - (void)m; -} + printf("error: %s\n", msg); + return; +} -void mutex_lock(struct mutex *m) +static int get_codepage(const char *cp) { - (void)m; -} + int code; -void mutex_unlock(struct mutex *m) -{ - (void)m; -} + for (code = 0; code < NUM_CODEPAGES; code++) + { + if (strcmp(cp, get_codepage_name(code)) == 0) + return code; + } -void thread_sdl_thread_lock(void *me) -{ - (void)me; -} + return -1; +} -void * thread_sdl_thread_unlock(void) +int main(int argc, char **argv) { - return (void*)1; -} - + 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); + } + 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_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(); + + 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); + } + + return 0; +} diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index d87e331..1e9fa4d 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -50,15 +50,16 @@ #define MAX_OPEN_FILES 11 #include +#ifndef __PCTOOL__ #include #include #include "thread.h" #include "kernel.h" +#include "thread-sdl.h" +#endif #include "debug.h" #include "config.h" #include "ata.h" /* for IF_MV2 et al. */ -#include "thread-sdl.h" - /* Windows (and potentially other OSes) distinguish binary and text files. * Define a dummy for the others. */ @@ -147,6 +148,12 @@ void dircache_rename(const char *oldname, const char *newname); #define SIMULATOR_DEFAULT_ROOT "simdisk" extern const char *sim_root_dir; +#ifdef __PCTOOL__ +#define PCTOOL_DEFAULT_ROOT "./" +#define PCTOOL_DEFAULT_ROCKBOX_DIR "/.rockbox" +extern const char *sim_rockbox_dir; +#endif + static int num_openfiles = 0; struct sim_dirent { @@ -201,7 +208,9 @@ enum struct sim_io { +#ifndef __PCTOOL__ struct mutex sim_mutex; /* Rockbox mutex */ +#endif int cmd; /* The command to perform */ int ready; /* I/O ready flag - 1= ready */ int fd; /* The file to read/write */ @@ -214,22 +223,29 @@ static struct sim_io io; int ata_init(void) { +#ifndef __PCTOOL__ /* Initialize the rockbox kernel objects on a rockbox thread */ mutex_init(&io.sim_mutex); +#endif io.accum = 0; return 1; } +#ifndef __PCTOOL__ int ata_spinup_time(void) { return HZ; } +#endif static ssize_t io_trigger_and_wait(int cmd) { +#ifndef __PCTOOL__ void *mythread = NULL; +#endif ssize_t result; +#ifndef __PCTOOL__ if (io.count > IO_YIELD_THRESHOLD || (io.accum += io.count) >= IO_YIELD_THRESHOLD) { @@ -237,6 +253,7 @@ static ssize_t io_trigger_and_wait(int cmd) io.accum = 0; mythread = thread_sdl_thread_unlock(); } +#endif switch (cmd) { @@ -248,20 +265,22 @@ static ssize_t io_trigger_and_wait(int cmd) break; } +#ifndef __PCTOOL__ /* Regain our status as current */ if (mythread != NULL) { thread_sdl_thread_lock(mythread); } +#endif return result; } -#ifndef __PCTOOL__ static const char *get_sim_pathname(const char *name) { static char buffer[MAX_PATH]; /* sufficiently big */ +#ifndef __PCTOOL__ if(name[0] == '/') { snprintf(buffer, sizeof(buffer), "%s%s", @@ -270,10 +289,22 @@ static const char *get_sim_pathname(const char *name) } fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); return name; -} #else -#define get_sim_pathname(name) name + if(name[0] == '/') + { + snprintf(buffer, sizeof(buffer), "%s%s", + sim_root_dir != NULL ? sim_root_dir : PCTOOL_DEFAULT_ROOT, name); + } + else + { + snprintf(buffer, sizeof(buffer), "%s%s/%s", + sim_root_dir != NULL ? sim_root_dir : PCTOOL_DEFAULT_ROOT, + sim_rockbox_dir != NULL ? sim_rockbox_dir : PCTOOL_DEFAULT_ROCKBOX_DIR, + name); + } + return buffer; #endif +} MYDIR *sim_opendir(const char *name) { @@ -367,7 +398,9 @@ ssize_t sim_read(int fd, void *buf, size_t count) { ssize_t result; +#ifndef __PCTOOL__ mutex_lock(&io.sim_mutex); +#endif /* Setup parameters */ io.fd = fd; @@ -376,7 +409,9 @@ ssize_t sim_read(int fd, void *buf, size_t count) result = io_trigger_and_wait(IO_READ); +#ifndef __PCTOOL__ mutex_unlock(&io.sim_mutex); +#endif return result; } @@ -385,7 +420,9 @@ ssize_t sim_write(int fd, const void *buf, size_t count) { ssize_t result; +#ifndef __PCTOOL__ mutex_lock(&io.sim_mutex); +#endif io.fd = fd; io.buf = (void*)buf; @@ -393,7 +430,9 @@ ssize_t sim_write(int fd, const void *buf, size_t count) result = io_trigger_and_wait(IO_WRITE); +#ifndef __PCTOOL__ mutex_unlock(&io.sim_mutex); +#endif return result; } diff --git a/tools/database/readme.txt b/tools/database/readme.txt new file mode 100755 index 0000000..5e5c5a5 --- /dev/null +++ b/tools/database/readme.txt @@ -0,0 +1,129 @@ + __________ __ ___. + 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. + +========================================================================== +database tool + Create the song database (database_*.tcd) application. + + +================================================= +Usage +================================================= +database -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 database tool 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. + + 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 database tool 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. + + When the database tool is built by using gcc 3.X.X on Cygwin, + to execute the database tool, cygwin1.dll is not needed. + But if it is built by using gcc 4.X.X, cygwin1.dll is needed. + + 2) Linux + + Other OS do not checked. + +When the database tool 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. +2) Fix build warning.