Index: utils/songdb/readme.txt =================================================================== --- utils/songdb/readme.txt (revision 0) +++ utils/songdb/readme.txt (revision 0) @@ -0,0 +1,108 @@ + __________ __ ___. + Open \______ \ ____ ____ | | _\_ |__ _______ ___ + Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + \/ \/ \/ \/ \/ +$Id$ + +Copyright (C) 2008 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 + [-s|--song-directory ] + [-c|--codepage ] + [-h|--help] + +-r|--root-path + Rockbox root directory. + + /.rockbox directory + and /.rockbox/codepages/*.cp + should exist. + + When songdb is used on Windows, the drive letter is written + Windows style(such as "C:/path/of/root"). + +-m|--mode + create: build database newly. + update: update database. + commit: commit database. + +-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 = "/". + +-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. + +Song database (database_*.tcd) is build for +/.rockbox directory. + +================================================= +Requirement +================================================= +OS + 1) Windows + - Cygwin installed. + 2) Linux + + Other OS do not checked. + + When songdb does not use SDL library, +SDL library may not be installed. + +================================================= +Build +================================================= +1) edit Makefile +2) make + +================================================= +TODO +================================================= +1) The folder of song database can be freely set. +2) Fix build warning. Property changes on: utils/songdb/readme.txt ___________________________________________________________________ Added: svn:executable + * Index: utils/songdb/Makefile =================================================================== --- utils/songdb/Makefile (revision 0) +++ utils/songdb/Makefile (revision 0) @@ -0,0 +1,93 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id$ +# +# 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. +# +SILENT:=@ +CC:=gcc +MAKE:=make +RM:=rm + +# -I- option check. If gcc version >= 4 then -I- option obsolete. +# gcc version >= 4 +# -iquotedir1 -iquotedir2 ... +# gcc version <= 3 +# -Idir1 -Idir2 ... -I- +ifeq "$(shell $(CC) -dumpversion | sed -e 's/\..*//')" "4" + INC_OPT := -iquote + SYS_INC_OPT := +else + INC_OPT := -I + SYS_INC_OPT := -I- +endif + +GCCOPTS := -std=c99 -O -W -Wall -pedantic -fno-builtin +DEBUG := -g +DEFINES := -D__PCTOOL__ -DHAVE_TAGCACHE -DCONFIG_CODEC=1 -DROCKBOX_LITTLE_ENDIAN +INCLUDES := $(INC_OPT)../../apps $(INC_OPT)../../apps/metadata $(INC_OPT)../../firmware/export $(INC_OPT)../../firmware/include $(SYS_INC_OPT) +LIBS := -ldl + +EXTRA_DEFINES := -DROCKBOX_HAS_LOGF + +ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) + GCCOPTS += -mno-cygwin +endif + +CFLAGS = $(GCCOPTS) $(DEBUG) $(DEFINES) $(EXTRA_DEFINES) $(INCLUDES) + +.PHONY: all clean +all: songdb + +SRCS:=../../uisimulator/common/io.c \ +../../firmware/common/crc32.c \ +../../firmware/common/errno.c \ +../../firmware/common/strcasestr.c \ +../../firmware/common/structec.c \ +../../firmware/common/unicode.c \ +../../firmware/replaygain.c \ +../../firmware/id3.c \ +../../firmware/mp3data.c \ +../../apps/tagcache.c \ +../../apps/misc.c \ +../../apps/metadata.c + +# append metadata files +SRCS += $(wildcard ../../apps/metadata/*.c) + +ifneq "$(filter -DROCKBOX_HAS_LOGF,$(EXTRA_DEFINES))" "" + SRCS += ../../firmware/logf.c +endif + +OBJS=$(patsubst %.c,%.o, $(notdir $(SRCS))) + +DEPFILE = songdb.d + +$(DEPFILE): $(SRCS) + $(SILENT)(for each in $(SRCS); do \ + obj=`echo $$each | sed -e 's/\.c/.o/' -e 's/^.*\///'`; \ + $(CC) -MG -MM -MT "$$obj" $(CFLAGS) $$each 2>/dev/null; \ + done) >> $(DEPFILE) + +songdb: songdb.c $(OBJS) + $(SILENT)$(CC) $(CFLAGS) songdb.c -o $@ $(OBJS) $(LIBS) + +$(OBJS):%.o: $(shell grep %.c $(SRCS)) + $(SILENT)$(CC) $(CFLAGS) -c $< -o $@ + +clean: + $(SILENT)$(RM) -f *.o songdb.exe songdb *.d + +#ifneq "$(MAKECMDGOALS)" "clean" + -include $(DEPFILE) +#endif Property changes on: utils/songdb/Makefile ___________________________________________________________________ Added: svn:executable + * Index: utils/songdb/songdb.c =================================================================== --- utils/songdb/songdb.c (revision 0) +++ utils/songdb/songdb.c (revision 0) @@ -0,0 +1,186 @@ +/**************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 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 "dir.h" +#include "rbunicode.h" +#include "tagcache.h" + +const char *sim_root_dir = NULL; + +#define ROCKBOX_DIRECTORY ".rockbox" + +#define DB_MODE_CREATE_STR "create" +#define DB_MODE_UPDATE_STR "update" +#define DB_MODE_COMMIT_STR "commit" + +enum {DB_MODE_CREATE, DB_MODE_UPDATE, DB_MODE_COMMIT}; + +static void show_usage(void) +{ + fprintf(stderr, "Usage: songdb -r|--root-path -m|--mode [-s|--song-directory ][-c|--codepage ][-h|--help]\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Options\n"); + fprintf(stderr, " -r|--root-path \n"); + fprintf(stderr, " Rockbox root path.\n"); + fprintf(stderr, " -m|--mode \n"); + fprintf(stderr, " create: build database newly.\n"); + fprintf(stderr, " update: update database.\n"); + fprintf(stderr, " commit: commit database.\n"); + fprintf(stderr, " -s|--song-directory \n"); + fprintf(stderr, " song storage directory.\n"); + fprintf(stderr, " -c|--codepage \n"); + fprintf(stderr, " metadata codepage\n"); + fprintf(stderr, " -h|--help\n"); + fprintf(stderr, " show this message.\n"); + return; +} + +int get_codepage(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+1] = {'\0'}; + char songdir[MAX_PATH+1] = {'\0'}; + int cp = UTF_8; + + if (argc < 4) + { + show_usage(); + return 1; + } + + 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],"-r")==0) || (strcmp(argv[idx],"--root-path")==0)) + { + if ((idx == argc-1) || (argv[idx+1][0] == '-')) + { + show_usage(); + return 1; + } + idx++; + strncpy(rootdir, 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++; + strncpy(songdir, argv[idx], MAX_PATH); + } + 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 + { + show_usage(); + 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_usage(); + return 1; + } + } + else + { + show_usage(); + return 1; + } + } + + if (rootdir[0] == '\0') + { + show_usage(); + return 1; + } + + if (mode < 0) + { + show_usage(); + return 1; + } + + if (songdir[0] == '\0') + strcpy(songdir, "/"); + + sim_root_dir = rootdir; + 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(); + } + + return 0; +} Property changes on: utils/songdb/songdb.c ___________________________________________________________________ Added: svn:executable + * Index: apps/metadata/asf.c =================================================================== --- apps/metadata/asf.c (revision 18432) +++ apps/metadata/asf.c (working copy) @@ -32,7 +32,7 @@ #include "metadata_common.h" #include "metadata_parsers.h" #include "system.h" -#include +#include "codecs/libwma/asf.h" /* TODO: Just read the GUIDs into a 16-byte array, and use memcmp to compare */ struct guid_s { Index: apps/metadata/metadata_common.c =================================================================== --- apps/metadata/metadata_common.c (revision 18432) +++ apps/metadata/metadata_common.c (working copy) @@ -174,7 +174,7 @@ static char* skip_space(char* str) { - while (isspace(*str)) + while (isspace((unsigned char)*str)) { str++; } @@ -192,7 +192,7 @@ { value = skip_space(value); - while (*value && !isspace(*value)) + while (*value && !isspace((unsigned char)*value)) { value++; } Index: apps/settings.h =================================================================== --- apps/settings.h (revision 18432) +++ apps/settings.h (working copy) @@ -23,7 +23,7 @@ #define __SETTINGS_H__ #include -#include "inttypes.h" +#include #include "config.h" #include "file.h" #include "dircache.h" @@ -51,6 +51,7 @@ /* name of directory where configuration, fonts and other data * files are stored */ #ifdef __PCTOOL__ +#ifdef WPSEDITOR #undef ROCKBOX_DIR #undef ROCKBOX_DIR_LEN #undef WPS_DIR @@ -60,6 +61,10 @@ #define ROCKBOX_DIR "/.rockbox" #define ROCKBOX_DIR_LEN 9 #endif +#else +#define ROCKBOX_DIR "/.rockbox" +#define ROCKBOX_DIR_LEN 9 +#endif #define FONT_DIR ROCKBOX_DIR "/fonts" #define LANG_DIR ROCKBOX_DIR "/langs" Index: apps/metadata.c =================================================================== --- apps/metadata.c (revision 18432) +++ apps/metadata.c (working copy) @@ -28,13 +28,17 @@ #include "playback.h" #include "debug.h" #include "logf.h" +#ifndef __PCTOOL__ #include "cuesheet.h" +#endif #include "metadata.h" #if CONFIG_CODEC == SWCODEC +#ifndef __PCTOOL__ /* For trailing tag stripping */ #include "buffering.h" +#endif /* !__PCTOOL__ */ #include "metadata/metadata_common.h" #include "metadata/metadata_parsers.h" @@ -278,6 +282,7 @@ } #if CONFIG_CODEC == SWCODEC +#ifndef __PCTOOL__ void strip_tags(int handle_id) { static const unsigned char tag[] = "TAG"; @@ -313,4 +318,5 @@ logf("Cutting off APE tag (%ldB)", len); bufcuttail(handle_id, len); } +#endif /* !__PCTOOL__ */ #endif /* CONFIG_CODEC == SWCODEC */ Index: apps/tagcache.c =================================================================== --- apps/tagcache.c (revision 18432) +++ apps/tagcache.c (working copy) @@ -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 "id3.h" @@ -87,7 +87,7 @@ #ifdef __PCTOOL__ #define yield() do { } while(0) -#define sim_sleep(timeout) do { } while(0) +#define sleep(timeout) do { } while(0) #define do_timed_yield() do { } while(0) #endif @@ -155,10 +155,12 @@ int32_t data; }; +#ifndef __PCTOOL__ static struct tagcache_command_entry command_queue[TAGCACHE_COMMAND_QUEUE_LENGTH]; static volatile int command_queue_widx = 0; static volatile int command_queue_ridx = 0; static struct mutex command_queue_mutex; +#endif /* Tag database structures. */ @@ -633,6 +635,7 @@ return true; } +#ifndef __PCTOOL__ static bool write_index(int masterfd, int idxid, struct index_entry *idx) { /* We need to exclude all memory only flags & tags when writing to disk. */ @@ -677,7 +680,7 @@ return true; } - +#endif /* !__PCTOOL__ */ static bool open_files(struct tagcache_search *tcs, int tag) { if (tcs->idxfd[tag] < 0) @@ -1159,7 +1162,15 @@ } } +#ifdef __PCTOOL__ +void tagcache_remove_database(void) +{ + remove_files(); + remove(TAGCACHE_FILE_TEMP); +} +#endif + static bool check_all_headers(void) { struct master_header myhdr; @@ -2993,6 +3004,7 @@ tempbuf_size = 0; } +#ifndef __PCTOOL__ static bool modify_numeric_entry(int masterfd, int idx_id, int tag, long data) { struct index_entry idx; @@ -3011,7 +3023,7 @@ return write_index(masterfd, idx_id, &idx); } - +#endif #if 0 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, int tag, long data) @@ -3028,6 +3040,7 @@ } #endif +#ifndef __PCTOOL__ #define COMMAND_QUEUE_IS_EMPTY (command_queue_ridx == command_queue_widx) static bool command_queue_is_full(void) @@ -3040,6 +3053,7 @@ return (next == command_queue_ridx); } + static bool command_queue_sync_callback(void) { @@ -3162,6 +3176,7 @@ { return current_tcmh.commitid; } +#endif /* !__PCTOOL__ */ static bool write_tag(int fd, const char *tagstr, const char *datastr) { @@ -3187,6 +3202,7 @@ return true; } +#ifndef __PCTOOL__ static bool read_tag(char *dest, long size, const char *src, const char *tagstr) { @@ -3326,7 +3342,6 @@ return write_index(masterfd, idx_id, &idx) ? 0 : -5; } -#ifndef __PCTOOL__ bool tagcache_import_changelog(void) { struct master_header myhdr; @@ -3373,7 +3388,7 @@ return true; } -#endif +#endif /* !__PCTOOL__ */ bool tagcache_create_changelog(struct tagcache_search *tcs) { @@ -4199,7 +4214,9 @@ filenametag_fd = open_tag_fd(&header, tag_filename, false); +#ifndef __PCTOOL__ cpu_boost(true); +#endif logf("Scanning files..."); /* Scan for new files. */ @@ -4227,7 +4244,9 @@ if (!ret) { logf("Aborted."); +#ifndef __PCTOOL__ cpu_boost(false); +#endif return ; } @@ -4252,8 +4271,10 @@ queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); } #endif - + +#ifndef __PCTOOL__ cpu_boost(false); +#endif } #ifdef HAVE_TC_RAMCACHE @@ -4261,8 +4282,10 @@ { if (!hdr) return ; - + +#ifndef __PCTOOL__ cpu_boost(true); +#endif /* At first we should load the cache (if exists). */ tc_stat.ramcache = load_tagcache(); @@ -4274,8 +4297,10 @@ tc_stat.ready = false; hdr = NULL; } - + +#ifndef __PCTOOL__ cpu_boost(false); +#endif } void tagcache_unload_ramcache(void) Index: apps/tagcache.h =================================================================== --- apps/tagcache.h (revision 18432) +++ apps/tagcache.h (working copy) @@ -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 18432) +++ apps/misc.c (working copy) @@ -28,9 +28,7 @@ #include #include #include -#ifdef WPSEDITOR -#include "string.h" -#endif +#include #else #include "sprintf.h" #include "lang.h" @@ -1099,26 +1097,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); @@ -1162,6 +1140,26 @@ } #endif /* !defined(__PCTOOL__) */ +/* 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/export/logf.h =================================================================== --- firmware/export/logf.h (revision 18432) +++ firmware/export/logf.h (working copy) @@ -20,8 +20,8 @@ ****************************************************************************/ #ifndef LOGF_H #define LOGF_H -#include #include +#include "config.h" #include "../include/_ansi.h" #include "debug.h" Index: firmware/export/system.h =================================================================== --- firmware/export/system.h (revision 18432) +++ firmware/export/system.h (working copy) @@ -193,9 +193,9 @@ MAXMEMGUARD }; -#ifndef SIMULATOR +#if !defined(SIMULATOR) && !defined(__PCTOOL__) #include "system-target.h" -#else /* SIMULATOR */ +#else /* SIMULATOR and __PCTOOL__ */ static inline uint16_t swap16(uint16_t value) /* @@ -229,7 +229,7 @@ return (t >> 8) | ((t ^ value) << 8); } -#endif /* !SIMULATOR */ +#endif /* !SIMULATOR and __PCTOOL__ */ /* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */ #ifndef DISABLE_INTERRUPTS Index: firmware/export/thread.h =================================================================== --- firmware/export/thread.h (revision 18432) +++ firmware/export/thread.h (working copy) @@ -81,7 +81,7 @@ #define DEFAULT_STACK_SIZE 0x400 /* Bytes */ -#ifndef SIMULATOR +#if !defined(SIMULATOR) && !defined(__PCTOOL__) /* Need to keep structures inside the header file because debug_menu * needs them. */ #ifdef CPU_COLDFIRE @@ -125,7 +125,7 @@ void *s; /* Semaphore for blocking and wakeup */ void (*start)(void); /* Start function */ }; -#endif /* !SIMULATOR */ +#endif /* !SIMULATOR and __PCTOOL__ */ /* NOTE: The use of the word "queue" may also refer to a linked list of threads being maintained that are normally dealt with in FIFO order Index: firmware/id3.c =================================================================== --- firmware/id3.c (revision 18432) +++ firmware/id3.c (working copy) @@ -424,7 +424,7 @@ int start_pos = tag - entry->id3v2buf; int end_pos = start_pos + desc_len + 5; int value_len = 0; - unsigned char* value = tag + desc_len + 1; + unsigned char* value = (unsigned char *)tag + desc_len + 1; /* Only parse RVA2 replaygain tags if tag version == 2.4 and channel * type is master volume. @@ -987,7 +987,7 @@ tag[j] = utf8buf[j]; /* remove trailing spaces */ - while ( bytesread > 0 && isspace(tag[bytesread-1])) + while ( bytesread > 0 && isspace((unsigned char)tag[bytesread-1])) bytesread--; } Index: firmware/replaygain.c =================================================================== --- firmware/replaygain.c (revision 18432) +++ firmware/replaygain.c (working copy) @@ -26,7 +26,7 @@ #include #include #include -#include +#include "system.h" #include "id3.h" #include "debug.h" #include "replaygain.h" @@ -224,7 +224,7 @@ long sign = 1; bool point = false; - while ((*s != '\0') && isspace(*s)) + while ((*s != '\0') && isspace((unsigned char)*s)) { s++; } Index: firmware/include/dir_uncached.h =================================================================== --- firmware/include/dir_uncached.h (revision 18432) +++ firmware/include/dir_uncached.h (working copy) @@ -32,7 +32,7 @@ #define ATTR_ARCHIVE 0x20 #define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ -#ifdef SIMULATOR +#if defined(SIMULATOR) || defined(__PCTOOL__) #define dirent_uncached sim_dirent #define DIR_UNCACHED SIM_DIR #define opendir_uncached sim_opendir @@ -57,7 +57,7 @@ #include "fat.h" typedef struct { -#ifndef SIMULATOR +#if !defined(SIMULATOR) && !defined(__PCTOOL__) bool busy; long startcluster; struct fat_dir fatdir; Index: firmware/include/file.h =================================================================== --- firmware/include/file.h (revision 18432) +++ firmware/include/file.h (working copy) @@ -22,7 +22,12 @@ #ifndef _FILE_H_ #define _FILE_H_ +#ifdef __PCTOOL__ +#include +#include +#else #include +#endif #undef MAX_PATH /* this avoids problems when building simulator */ #define MAX_PATH 260 @@ -48,18 +53,18 @@ #define O_TRUNC 0x10 #endif -#ifdef SIMULATOR -#define open(x,y) sim_open(x,y) -#define creat(x) sim_creat(x) -#define remove(x) sim_remove(x) -#define rename(x,y) sim_rename(x,y) -#define filesize(x) sim_filesize(x) -#define fsync(x) sim_fsync(x) -#define ftruncate(x,y) sim_ftruncate(x,y) -#define lseek(x,y,z) sim_lseek(x,y,z) -#define read(x,y,z) sim_read(x,y,z) -#define write(x,y,z) sim_write(x,y,z) -#define close(x) sim_close(x) +#if defined(SIMULATOR) || defined(__PCTOOL__) +#define open sim_open +#define creat sim_creat +#define remove sim_remove +#define rename sim_rename +#define filesize sim_filesize +#define fsync sim_fsync +#define ftruncate sim_ftruncate +#define lseek sim_lseek +#define read sim_read +#define write sim_write +#define close sim_close #endif typedef int (*open_func)(const char* pathname, int flags); @@ -73,13 +78,19 @@ extern int close(int fd); extern int fsync(int fd); extern ssize_t read(int fd, void *buf, size_t count); -extern off_t lseek(int fildes, off_t offset, int whence); extern int creat(const char *pathname); extern ssize_t write(int fd, const void *buf, size_t count); extern int remove(const char* pathname); extern int rename(const char* path, const char* newname); extern int ftruncate(int fd, off_t length); +#if !defined(__PCTOOL__) && !defined(SIMULATOR) +extern off_t lseek(int fildes, off_t offset, int whence); extern off_t filesize(int fd); +#else +extern long lseek(int fildes, long offset, int whence); +extern long filesize(int fd); +#endif +#ifdef HAVE_HOTSWAP extern int release_files(int volume); - #endif +#endif Index: uisimulator/common/io.c =================================================================== --- uisimulator/common/io.c (revision 18432) +++ uisimulator/common/io.c (working copy) @@ -50,16 +50,17 @@ #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. */ #ifndef O_BINARY @@ -99,8 +100,8 @@ return buffer; } -#define UTF8_TO_OS(a) utf8_to_ucs2(a,convbuf1) -#define OS_TO_UTF8(a) ucs2_to_utf8(a,convbuf1) +#define UTF8_TO_OS(a) utf8_to_ucs2((const unsigned char *)(a),convbuf1) +#define OS_TO_UTF8(a) ucs2_to_utf8((const wchar_t *)(a),convbuf1) #define DIR_T _WDIR #define DIRENT_T struct _wdirent #define STAT_T struct _stat @@ -115,7 +116,7 @@ #define OPEN(a,b,c) (_wopen)(UTF8_TO_OS(a),b,c) #define CLOSE(a) (close)(a) #define REMOVE(a) (_wremove)(UTF8_TO_OS(a)) -#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2(b,convbuf2)) +#define RENAME(a,b) (_wrename)(UTF8_TO_OS(a),utf8_to_ucs2((const unsigned char *)(b),convbuf2)) #else /* !__MINGW32__ */ @@ -170,7 +171,7 @@ typedef struct mydir MYDIR; -#if 1 /* maybe this needs disabling for MSVC... */ +#ifndef __PCTOOL__ /* maybe this needs disabling for MSVC... */ static unsigned int rockbox2sim(int opt) { int newopt = O_BINARY; @@ -201,7 +202,9 @@ 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,17 +217,22 @@ 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; } static ssize_t io_trigger_and_wait(int cmd) { +#ifndef __PCTOOL__ void *mythread = NULL; - ssize_t result; +#endif + ssize_t result = 0; +#ifndef __PCTOOL__ if (io.count > IO_YIELD_THRESHOLD || (io.accum += io.count) >= IO_YIELD_THRESHOLD) { @@ -232,6 +240,7 @@ io.accum = 0; mythread = thread_sdl_thread_unlock(); } +#endif switch (cmd) { @@ -242,13 +251,13 @@ result = write(io.fd, io.buf, io.count); break; } - +#ifndef __PCTOOL__ /* Regain our status as current */ if (mythread != NULL) { thread_sdl_thread_lock(mythread); } - +#endif return result; } @@ -264,14 +273,12 @@ char buffer[MAX_PATH]; /* sufficiently big */ DIR_T *dir; -#ifndef __PCTOOL__ if(name[0] == '/') { snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); dir=(DIR_T *)OPENDIR(buffer); } else -#endif dir=(DIR_T *)OPENDIR(name); if(dir) { @@ -296,15 +303,15 @@ if(!x11) return (struct sim_dirent *)0; - strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name)); + strcpy((char *)secret.d_name, (char *)OS_TO_UTF8(x11->d_name)); /* build file name */ -#ifdef __PCTOOL__ - snprintf(buffer, sizeof(buffer), "%s/%s", dir->name, secret.d_name); -#else - snprintf(buffer, sizeof(buffer), "%s/%s/%s", + if (dir->name[0] != '/') + snprintf(buffer, sizeof(buffer), "%s/%s", dir->name, secret.d_name); + else + snprintf(buffer, sizeof(buffer), "%s%s/%s", get_sim_rootdir(), dir->name, secret.d_name); -#endif + STAT(buffer, &s); /* get info */ #define ATTR_DIRECTORY 0x10 @@ -333,37 +340,33 @@ int sim_open(const char *name, int o) { char buffer[MAX_PATH]; /* sufficiently big */ +#ifdef __PCTOOL__ + int opts = o | O_BINARY; +#else int opts = rockbox2sim(o); +#endif int ret; - if (num_openfiles >= MAX_OPEN_FILES) return -2; -#ifndef __PCTOOL__ if(name[0] == '/') { snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); - - /* debugf("We open the real file '%s'\n", buffer); */ - if (num_openfiles < MAX_OPEN_FILES) - { - ret = OPEN(buffer, opts, 0666); - if (ret >= 0) num_openfiles++; - return ret; - } + ret = OPEN(buffer, opts, 0666); } - - fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", - name); - return -1; +#ifdef __PCTOOL__ + else + ret = OPEN(name, opts, 0666); #else - if (num_openfiles < MAX_OPEN_FILES) - { - ret = OPEN(buffer, opts, 0666); - if (ret >= 0) num_openfiles++; - return ret; - } + else + { + fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); + return -1; + } #endif + + if (ret >= 0) num_openfiles++; + return ret; } int sim_close(int fd) @@ -376,7 +379,6 @@ int sim_creat(const char *name) { -#ifndef __PCTOOL__ char buffer[MAX_PATH]; /* sufficiently big */ if(name[0] == '/') { @@ -385,67 +387,65 @@ /* debugf("We create the real file '%s'\n", buffer); */ return OPEN(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); } +#ifdef __PCTOOL__ + else + return OPEN(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); +#endif fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); return -1; -#else - return OPEN(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); -#endif } 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; io.buf = buf; io.count = count; result = io_trigger_and_wait(IO_READ); - +#ifndef __PCTOOL__ mutex_unlock(&io.sim_mutex); - +#endif return result; } 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; io.count = count; result = io_trigger_and_wait(IO_WRITE); - +#ifndef __PCTOOL__ mutex_unlock(&io.sim_mutex); - +#endif return result; } int sim_mkdir(const char *name) { -#ifdef __PCTOOL__ - return MKDIR(name, 0777); -#else char buffer[MAX_PATH]; /* sufficiently big */ - snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); + if (name[0] == '/') + { + snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); - /* debugf("We create the real directory '%s'\n", buffer); */ - return MKDIR(buffer, 0777); -#endif + /* debugf("We create the real directory '%s'\n", buffer); */ + return MKDIR(buffer, 0777); + } + return MKDIR(name, 0777); } int sim_rmdir(const char *name) { -#ifdef __PCTOOL__ - return RMDIR(name); -#else char buffer[MAX_PATH]; /* sufficiently big */ if(name[0] == '/') { @@ -455,14 +455,10 @@ return RMDIR(buffer); } return RMDIR(name); -#endif } int sim_remove(const char *name) { -#ifdef __PCTOOL__ - return REMOVE(name); -#else char buffer[MAX_PATH]; /* sufficiently big */ #ifdef HAVE_DIRCACHE @@ -476,14 +472,10 @@ return REMOVE(buffer); } return REMOVE(name); -#endif } int sim_rename(const char *oldpath, const char* newpath) { -#ifdef __PCTOOL__ - return RENAME(oldpath, newpath); -#else char buffer1[MAX_PATH]; char buffer2[MAX_PATH]; @@ -491,17 +483,25 @@ dircache_rename(oldpath, newpath); #endif - if(oldpath[0] == '/') { +#ifndef __PCTOOL__ + if (oldpath[0] != '/' || newpath[0] != '/') + return -1; +#endif + + if(oldpath[0] == '/') snprintf(buffer1, sizeof(buffer1), "%s%s", get_sim_rootdir(), oldpath); + else + strncpy(buffer1, oldpath, MAX_PATH-1); + + if(newpath[0] == '/') snprintf(buffer2, sizeof(buffer2), "%s%s", get_sim_rootdir(), newpath); + else + strncpy(buffer2, newpath, MAX_PATH-1); - /* debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); */ - return RENAME(buffer1, buffer2); - } - return -1; -#endif + /* debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); */ + return RENAME(buffer1, buffer2); } /* rockbox off_t may be different from system off_t */ @@ -537,7 +537,7 @@ #endif #ifdef WIN32 - long secperclus, bytespersec, free_clusters, num_clusters; + unsigned long secperclus, bytespersec, free_clusters, num_clusters; if (GetDiskFreeSpace(NULL, &secperclus, &bytespersec, &free_clusters, &num_clusters)) { @@ -577,19 +577,21 @@ #ifdef WIN32 /* sim-win32 */ +typedef void (__stdcall *dllfunc)(); #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_)) -#define dlsym(_x_, _y_) (void *)GetProcAddress(_x_, _y_) +#define dlsym(_x_, _y_) (dllfunc)GetProcAddress(_x_, _y_) #define dlclose(_x_) FreeLibrary(_x_) #else /* sim-x11 */ #include +#define dllfunc void* #endif #define TEMP_CODEC_FILE "archos/_temp_codec%d.dll" -void *sim_codec_load_ram(char* codecptr, int size, void **pd) +dllfunc sim_codec_load_ram(char* codecptr, int size, void **pd) { - void *hdr; + dllfunc hdr; char path[MAX_PATH]; int fd; int codec_count; @@ -649,9 +651,9 @@ dlclose(pd); } -void *sim_plugin_load(char *plugin, void **pd) +dllfunc sim_plugin_load(char *plugin, void **pd) { - void *hdr; + dllfunc hdr; char path[MAX_PATH]; #ifdef WIN32 char buf[MAX_PATH]; Index: firmware/include/rbunicode.h =================================================================== --- firmware/include/rbunicode.h (revision 18421) +++ firmware/include/rbunicode.h (working copy) @@ -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, Index: firmware/common/unicode.c =================================================================== --- firmware/common/unicode.c (revision 18421) +++ firmware/common/unicode.c (working copy) @@ -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 @@ -195,7 +195,7 @@ 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 */ @@ -204,7 +204,7 @@ 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);