Index: utils/songdb/readme.txt =================================================================== --- utils/songdb/readme.txt (revision 0) +++ utils/songdb/readme.txt (revision 0) @@ -0,0 +1,123 @@ + __________ __ ___. + 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 + [-d|--rockbox-directory ] + [-s|--song-directory ] + [-c|--codepage ] + [-h|--help] + [-V|--version] + +-r|--root-path + Rockbox root directory. + + / + and //codepages/*.cp + should exist. + + When songdb is used on Windows, the drive letter is written + Windows style (such as "C:/path/of/root"). + + Song database (database_*.tcd) is build for + / directory. + +-m|--mode + create: build database newly. + update: update database. + commit: commit database. + append: append non registered files. + It is not checked whether the file registered in the database + has been deleted. + +-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 songdb does not use SDL library, 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. 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,101 @@ +# __________ __ ___. +# 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 + +ifneq "$(MAKECMDGOALS)" "clean" + VERSION:=$(shell ../../tools/svnversion.sh ../../) + BUILDDATE:=$(shell date -u +'-DYEAR=%Y -DMONTH=%m -DDAY=%d') +endif + +# -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 -DAPP_VERSION=\"$(VERSION)\" $(BUILDDATE) +INCLUDES := $(INC_OPT)../../apps $(INC_OPT)../../apps/metadata $(INC_OPT)../../firmware/export $(INC_OPT)../../firmware/include $(SYS_INC_OPT) +LIBS := + +EXTRA_DEFINES := -DROCKBOX_HAS_LOGF + +ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) + GCCOPTS += -mno-cygwin +else + ifneq ($(findstring MINGW,$(shell uname)),MINGW) + LIBS += -ldl + endif +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 \ +../../apps/metadata.c \ +../../apps/misc.c \ +../../apps/mp3data.c \ +../../apps/replaygain.c \ +../../apps/tagcache.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,234 @@ +/**************************************************************************** + * __________ __ ___. + * 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 "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 svn. %s\n", APP_VERSION); + fprintf(stdout, "Copyright (C) 2008 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; + } + strcpy(rockboxdir, "/"); + strcat(rockboxdir, argv[idx]); + } + 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(); + + 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; +} Property changes on: utils/songdb/songdb.c ___________________________________________________________________ Added: svn:executable + * Index: apps/tree.c =================================================================== --- apps/tree.c (revision 19361) +++ apps/tree.c (working copy) @@ -1123,7 +1123,7 @@ #endif #ifdef HAVE_TC_RAMCACHE - remove(TAGCACHE_STATEFILE); + tagcache_remove_statefile(); #endif #ifdef HAVE_DIRCACHE Index: apps/metadata/mp3.c =================================================================== --- apps/metadata/mp3.c (revision 19361) +++ apps/metadata/mp3.c (working copy) @@ -926,7 +926,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: apps/metadata/asf.c =================================================================== --- apps/metadata/asf.c (revision 19361) +++ 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 19361) +++ apps/metadata/metadata_common.c (working copy) @@ -175,7 +175,7 @@ static char* skip_space(char* str) { - while (isspace(*str)) + while (isspace((unsigned char)*str)) { str++; } @@ -193,7 +193,7 @@ { value = skip_space(value); - while (*value && !isspace(*value)) + while (*value && !isspace((unsigned char)*value)) { value++; } Index: apps/settings.h =================================================================== --- apps/settings.h (revision 19361) +++ 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" Index: apps/metadata.c =================================================================== --- apps/metadata.c (revision 19361) +++ apps/metadata.c (working copy) @@ -27,15 +27,19 @@ #include "playback.h" #include "debug.h" #include "logf.h" +#ifndef __PCTOOL__ #include "cuesheet.h" +#endif #include "metadata.h" #include "metadata/metadata_parsers.h" #if CONFIG_CODEC == SWCODEC +#ifndef __PCTOOL__ /* For trailing tag stripping */ #include "buffering.h" +#endif #include "metadata/metadata_common.h" @@ -398,6 +402,7 @@ } #if CONFIG_CODEC == SWCODEC +#ifndef __PCTOOL__ void strip_tags(int handle_id) { static const unsigned char tag[] = "TAG"; @@ -433,6 +438,7 @@ logf("Cutting off APE tag (%ldB)", len); bufcuttail(handle_id, len); } +#endif /* __PCTOOL__ */ #endif /* CONFIG_CODEC == SWCODEC */ void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig) Index: apps/tagcache.c =================================================================== --- apps/tagcache.c (revision 19361) +++ 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 "metadata.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. */ @@ -261,6 +263,38 @@ static bool delete_entry(long idx_id); +/* Tag database files. (without Rockbox directory) */ + +/* Temporary database containing new tags to be committed to the main db. */ +#define TAGCACHE_FILE_TEMP "/database_tmp.tcd" + +/* The main database master index and numeric data. */ +#define TAGCACHE_FILE_MASTER "/database_idx.tcd" + +/* The main database string data. */ +#define TAGCACHE_FILE_INDEX "/database_%d.tcd" + +/* ASCII dumpfile of the DB contents. */ +#define TAGCACHE_FILE_CHANGELOG "/database_changelog.txt" + +/* Serialized DB. */ +#define TAGCACHE_STATEFILE "/database_state.tcd" + +/* Tag database files. (with rockbox directory) */ +#ifdef __PCTOOL__ +static char TAGCACHE_PATH_TEMP[MAX_PATH]; +static char TAGCACHE_PATH_MASTER[MAX_PATH]; +static char TAGCACHE_PATH_INDEX[MAX_PATH]; +static char TAGCACHE_PATH_CHANGELOG[MAX_PATH]; +static char TAGCACHE_PATH_STATEFILE[MAX_PATH]; +#else +#define TAGCACHE_PATH_TEMP ROCKBOX_DIR TAGCACHE_FILE_TEMP +#define TAGCACHE_PATH_MASTER ROCKBOX_DIR TAGCACHE_FILE_MASTER +#define TAGCACHE_PATH_INDEX ROCKBOX_DIR TAGCACHE_FILE_INDEX +#define TAGCACHE_PATH_CHANGELOG ROCKBOX_DIR TAGCACHE_FILE_CHANGELOG +#define TAGCACHE_PATH_STATEFILE ROCKBOX_DIR TAGCACHE_STATEFILE +#endif + const char* tagcache_tag_to_str(int tag) { return tags_str[tag]; @@ -325,7 +359,7 @@ if (tagcache_is_numeric_tag(tag) || tag < 0 || tag >= TAG_COUNT) return -1; - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag); + snprintf(buf, sizeof buf, TAGCACHE_PATH_INDEX, tag); fd = open(buf, write ? O_RDWR : O_RDONLY); if (fd < 0) @@ -352,8 +386,8 @@ { int fd; int rc; - - fd = open(TAGCACHE_FILE_MASTER, write ? O_RDWR : O_RDONLY); + + fd = open(TAGCACHE_PATH_MASTER, write ? O_RDWR : O_RDONLY); if (fd < 0) { logf("master file open failed for R/W"); @@ -633,6 +667,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,14 +712,14 @@ return true; } - +#endif /* !__PCTOOL__ */ static bool open_files(struct tagcache_search *tcs, int tag) { if (tcs->idxfd[tag] < 0) { char fn[MAX_PATH]; - snprintf(fn, sizeof fn, TAGCACHE_FILE_INDEX, tag); + snprintf(fn, sizeof fn, TAGCACHE_PATH_INDEX, tag); tcs->idxfd[tag] = open(fn, O_RDONLY); } @@ -1148,18 +1183,26 @@ tc_stat.ready = false; tc_stat.ramcache = false; tc_stat.econ = false; - remove(TAGCACHE_FILE_MASTER); + remove(TAGCACHE_PATH_MASTER); for (i = 0; i < TAG_COUNT; i++) { if (tagcache_is_numeric_tag(i)) continue; - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, i); + snprintf(buf, sizeof buf, TAGCACHE_PATH_INDEX, i); remove(buf); } } +#ifdef __PCTOOL__ +void tagcache_remove_database(void) +{ + remove_files(); + remove(TAGCACHE_PATH_TEMP); +} +#endif + static bool check_all_headers(void) { struct master_header myhdr; @@ -1300,7 +1343,7 @@ { char buf[MAX_PATH]; - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag); + snprintf(buf, sizeof buf, TAGCACHE_PATH_INDEX, clause->tag); tcs->idxfd[clause->tag] = open(buf, O_RDONLY); } @@ -1310,6 +1353,11 @@ return true; } +void tagcache_remove_statefile(void) +{ + remove(TAGCACHE_PATH_STATEFILE); +} + /* TODO: Remove this mess. */ #ifdef HAVE_DIRCACHE #define TAG_FILENAME_RAM(tcs) ((tcs->type == tag_filename) \ @@ -2451,7 +2499,7 @@ * Creating new index file to store the tags. No need to preload * anything whether the index type is sorted or not. */ - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, index_type); + snprintf(buf, sizeof buf, TAGCACHE_PATH_INDEX, index_type); fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC); if (fd < 0) { @@ -2474,16 +2522,16 @@ /* Loading the tag lookup file as "master file". */ logf("Loading index file"); - masterfd = open(TAGCACHE_FILE_MASTER, O_RDWR); + masterfd = open(TAGCACHE_PATH_MASTER, O_RDWR); if (masterfd < 0) { logf("Creating new DB"); - masterfd = open(TAGCACHE_FILE_MASTER, O_WRONLY | O_CREAT | O_TRUNC); + masterfd = open(TAGCACHE_PATH_MASTER, O_WRONLY | O_CREAT | O_TRUNC); if (masterfd < 0) { - logf("Failure to create index file (%s)", TAGCACHE_FILE_MASTER); + logf("Failure to create index file (%s)", TAGCACHE_PATH_MASTER); close(fd); return -2; } @@ -2797,7 +2845,7 @@ while (write_lock) sleep(1); - tmpfd = open(TAGCACHE_FILE_TEMP, O_RDONLY); + tmpfd = open(TAGCACHE_PATH_TEMP, O_RDONLY); if (tmpfd < 0) { logf("nothing to commit"); @@ -2813,7 +2861,7 @@ { logf("incorrect header"); close(tmpfd); - remove(TAGCACHE_FILE_TEMP); + remove(TAGCACHE_PATH_TEMP); return false; } @@ -2821,12 +2869,12 @@ { logf("nothing to commit"); close(tmpfd); - remove(TAGCACHE_FILE_TEMP); + remove(TAGCACHE_PATH_TEMP); return true; } #ifdef HAVE_EEPROM_SETTINGS - remove(TAGCACHE_STATEFILE); + tagcache_remove_statefile(); #endif /* At first be sure to unload the ramcache! */ @@ -2939,7 +2987,7 @@ close(masterfd); logf("tagcache committed"); - remove(TAGCACHE_FILE_TEMP); + remove(TAGCACHE_PATH_TEMP); tc_stat.ready = check_all_headers(); tc_stat.readyvalid = true; @@ -2993,6 +3041,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,6 +3060,7 @@ return write_index(masterfd, idx_id, &idx); } +#endif #if 0 bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, @@ -3028,6 +3078,7 @@ } #endif +#ifndef __PCTOOL__ #define COMMAND_QUEUE_IS_EMPTY (command_queue_ridx == command_queue_widx) static bool command_queue_is_full(void) @@ -3040,6 +3091,7 @@ return (next == command_queue_ridx); } + static bool command_queue_sync_callback(void) { @@ -3162,6 +3214,7 @@ { return current_tcmh.commitid; } +#endif /* !__PCTOOL__ */ static bool write_tag(int fd, const char *tagstr, const char *datastr) { @@ -3187,6 +3240,7 @@ return true; } +#ifndef __PCTOOL__ static bool read_tag(char *dest, long size, const char *src, const char *tagstr) { @@ -3326,7 +3380,6 @@ return write_index(masterfd, idx_id, &idx) ? 0 : -5; } -#ifndef __PCTOOL__ bool tagcache_import_changelog(void) { struct master_header myhdr; @@ -3341,7 +3394,7 @@ while (read_lock) sleep(1); - clfd = open(TAGCACHE_FILE_CHANGELOG, O_RDONLY); + clfd = open(TAGCACHE_PATH_CHANGELOG, O_RDONLY); if (clfd < 0) { logf("failure to open changelog"); @@ -3373,7 +3426,7 @@ return true; } -#endif +#endif /* !__PCTOOL__ */ bool tagcache_create_changelog(struct tagcache_search *tcs) { @@ -3391,7 +3444,7 @@ return false; /* Initialize the changelog */ - clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC); + clfd = open(TAGCACHE_PATH_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC); if (clfd < 0) { logf("failure to open changelog"); @@ -3719,7 +3772,7 @@ long offpos; int i; - fd = open(TAGCACHE_STATEFILE, O_RDONLY); + fd = open(TAGCACHE_PATH_STATEFILE, O_RDONLY); if (fd < 0) { logf("no tagcache statedump"); @@ -3770,7 +3823,7 @@ if (!tc_stat.ramcache) return false; - fd = open(TAGCACHE_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); + fd = open(TAGCACHE_PATH_STATEFILE, O_WRONLY | O_CREAT | O_TRUNC); if (fd < 0) { logf("failed to create a statedump"); @@ -3808,7 +3861,7 @@ logf("loading tagcache to ram..."); - fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); + fd = open(TAGCACHE_PATH_MASTER, O_RDONLY); if (fd < 0) { logf("tagcache open failed"); @@ -4022,7 +4075,7 @@ struct tagfile_entry tfe; logf("reverse scan..."); - snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, tag_filename); + snprintf(buf, sizeof buf, TAGCACHE_PATH_INDEX, tag_filename); fd = open(buf, O_RDONLY); if (fd < 0) @@ -4182,7 +4235,7 @@ logf("updating tagcache"); - cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); + cachefd = open(TAGCACHE_PATH_TEMP, O_RDONLY); if (cachefd >= 0) { logf("skipping, cache already waiting for commit"); @@ -4190,16 +4243,18 @@ return ; } - cachefd = open(TAGCACHE_FILE_TEMP, O_RDWR | O_CREAT | O_TRUNC); + cachefd = open(TAGCACHE_PATH_TEMP, O_RDWR | O_CREAT | O_TRUNC); if (cachefd < 0) { - logf("master file open failed: %s", TAGCACHE_FILE_TEMP); + logf("master file open failed: %s", TAGCACHE_PATH_TEMP); return ; } filenametag_fd = open_tag_fd(&header, tag_filename, false); +#ifndef __PCTOOL__ cpu_boost(true); +#endif logf("Scanning files..."); /* Scan for new files. */ @@ -4227,7 +4282,9 @@ if (!ret) { logf("Aborted."); +#ifndef __PCTOOL__ cpu_boost(false); +#endif return ; } @@ -4237,7 +4294,7 @@ #endif if (commit()) { - remove(TAGCACHE_FILE_TEMP); + remove(TAGCACHE_PATH_TEMP); logf("tagcache built!"); } #ifdef __PCTOOL__ @@ -4253,7 +4310,9 @@ } #endif +#ifndef __PCTOOL__ cpu_boost(false); +#endif } #ifdef HAVE_TC_RAMCACHE @@ -4262,7 +4321,9 @@ if (!hdr) return ; +#ifndef __PCTOOL__ cpu_boost(true); +#endif /* At first we should load the cache (if exists). */ tc_stat.ramcache = load_tagcache(); @@ -4275,7 +4336,9 @@ hdr = NULL; } +#ifndef __PCTOOL__ cpu_boost(false); +#endif } void tagcache_unload_ramcache(void) @@ -4304,7 +4367,7 @@ if (firmware_settings.initialized && firmware_settings.disk_clean) check_done = tagcache_dumpload(); - remove(TAGCACHE_STATEFILE); + tagcache_remove_statefile(); # endif /* Allocate space for the tagcache if found on disk. */ @@ -4334,7 +4397,7 @@ case Q_REBUILD: remove_files(); - remove(TAGCACHE_FILE_TEMP); + remove(TAGCACHE_PATH_TEMP); tagcache_build("/"); break; @@ -4498,6 +4561,12 @@ IF_PRIO(, PRIORITY_BACKGROUND) IF_COP(, CPU)); #else + get_rockbox_path(TAGCACHE_FILE_TEMP, TAGCACHE_PATH_TEMP); + get_rockbox_path(TAGCACHE_FILE_MASTER, TAGCACHE_PATH_MASTER); + get_rockbox_path(TAGCACHE_FILE_INDEX, TAGCACHE_PATH_INDEX); + get_rockbox_path(TAGCACHE_FILE_CHANGELOG, TAGCACHE_PATH_CHANGELOG); + get_rockbox_path(TAGCACHE_STATEFILE, TAGCACHE_PATH_STATEFILE); + tc_stat.initialized = true; allocate_tempbuf(); commit(); Index: apps/tagcache.h =================================================================== --- apps/tagcache.h (revision 19361) +++ apps/tagcache.h (working copy) @@ -77,23 +77,6 @@ #define TAGCACHE_MAX_FILTERS 4 #define TAGCACHE_MAX_CLAUSES 32 -/* Tag database files. */ - -/* Temporary database containing new tags to be committed to the main db. */ -#define TAGCACHE_FILE_TEMP ROCKBOX_DIR "/database_tmp.tcd" - -/* The main database master index and numeric data. */ -#define TAGCACHE_FILE_MASTER ROCKBOX_DIR "/database_idx.tcd" - -/* The main database string data. */ -#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/database_%d.tcd" - -/* ASCII dumpfile of the DB contents. */ -#define TAGCACHE_FILE_CHANGELOG ROCKBOX_DIR "/database_changelog.txt" - -/* Serialized DB. */ -#define TAGCACHE_STATEFILE ROCKBOX_DIR "/database_state.tcd" - /* Flags */ #define FLAG_DELETED 0x0001 /* Entry has been removed from db */ #define FLAG_DIRCACHE 0x0002 /* Filename is a dircache pointer */ @@ -179,6 +162,7 @@ #ifdef __PCTOOL__ void tagcache_reverse_scan(void); +void tagcache_remove_database(void); #endif const char* tagcache_tag_to_str(int tag); @@ -230,5 +214,6 @@ bool tagcache_update(void); bool tagcache_rebuild(void); int tagcache_get_max_commit_step(void); +void tagcache_remove_statefile(void); #endif #endif Index: apps/replaygain.c =================================================================== --- apps/replaygain.c (revision 19361) +++ apps/replaygain.c (working copy) @@ -26,7 +26,7 @@ #include #include #include -#include +#include "system.h" #include "metadata.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: apps/main.c =================================================================== --- apps/main.c (revision 19361) +++ apps/main.c (working copy) @@ -512,7 +512,7 @@ if (init_dircache(true) < 0) { #ifdef HAVE_TAGCACHE - remove(TAGCACHE_STATEFILE); + tagcache_remove_statefile(); #endif } Index: apps/misc.c =================================================================== --- apps/misc.c (revision 19361) +++ 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" @@ -1109,26 +1107,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); @@ -1172,6 +1150,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 19361) +++ 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 19361) +++ firmware/export/system.h (working copy) @@ -202,9 +202,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) /* @@ -238,7 +238,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 19361) +++ 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/include/dir_uncached.h =================================================================== --- firmware/include/dir_uncached.h (revision 19361) +++ 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/rbunicode.h =================================================================== --- firmware/include/rbunicode.h (revision 19361) +++ 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/include/file.h =================================================================== --- firmware/include/file.h (revision 19361) +++ firmware/include/file.h (working copy) @@ -22,7 +22,13 @@ #ifndef _FILE_H_ #define _FILE_H_ +#ifdef __PCTOOL__ +#include +#include +#else #include +#include +#endif #undef MAX_PATH /* this avoids problems when building simulator */ #define MAX_PATH 260 @@ -48,20 +54,24 @@ #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 +#ifdef __PCTOOL__ +#define get_rockbox_path get_sim_rockbox_path +#endif + typedef int (*open_func)(const char* pathname, int flags); typedef ssize_t (*read_func)(int fd, void *buf, size_t count); typedef int (*creat_func)(const char *pathname); @@ -73,13 +83,25 @@ 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 +#ifdef __PCTOOL__ +extern char *get_rockbox_path(char *dir, char *out_path); +#else +#define get_rockbox_path(dir, path) snprintf(path, MAX_PATH, "%s%s", ROCKBOX_DIR, dir) #endif +#endif Index: firmware/common/unicode.c =================================================================== --- firmware/common/unicode.c (revision 19361) +++ firmware/common/unicode.c (working copy) @@ -36,11 +36,12 @@ #define O_BINARY 0 #endif -#define CODEPAGE_DIR ROCKBOX_DIR"/codepages" +/* codepage file into /CODEPAGE_DIR */ +#define CODEPAGE_DIR "/codepages" 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 @@ -121,29 +122,29 @@ int table = cp_2_table[cp]; int file, tablesize; unsigned char tmp[2]; + char path[MAX_PATH]; if (table == 0 || table == loaded_cp_table) return 1; - file = open(filename[table-1], O_RDONLY|O_BINARY); - + get_rockbox_path(filename[table-1], path); + file = open(path, O_RDONLY|O_BINARY); if (file < 0) { - DEBUGF("Can't open codepage file: %s.cp\n", filename[table-1]); + DEBUGF("Can't open codepage file: %s.cp\n", path); return 0; } tablesize = filesize(file) / 2; if (tablesize > MAX_CP_TABLE_SIZE) { - DEBUGF("Invalid codepage file: %s.cp\n", filename[table-1]); + DEBUGF("Invalid codepage file: %s.cp\n", path); close(file); return 0; } while (i < tablesize) { if (!read(file, tmp, 2)) { - DEBUGF("Can't read from codepage file: %s.cp\n", - filename[table-1]); + DEBUGF("Can't read from codepage file: %s.cp\n", path); loaded_cp_table = 0; return 0; } @@ -195,7 +196,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 +205,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); Index: uisimulator/common/io.c =================================================================== --- uisimulator/common/io.c (revision 19361) +++ uisimulator/common/io.c (working copy) @@ -31,11 +31,11 @@ #elif defined(__APPLE__) #include #include -#elif !defined(WIN32) +#elif !defined(_WIN32) #include #endif -#ifdef WIN32 +#ifdef _WIN32 #include #endif @@ -50,14 +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. @@ -99,8 +101,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 +117,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__ */ @@ -147,6 +149,11 @@ #define SIMULATOR_DEFAULT_ROOT "simdisk" extern const char *sim_root_dir; +#ifdef __PCTOOL__ +#define SIMULATOR_DEFAULT_ROCKBOX_DIR "/.rockbox" +extern const char *sim_rockbox_dir; +#endif + static int num_openfiles = 0; struct sim_dirent { @@ -170,7 +177,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 +208,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 +223,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 +246,7 @@ io.accum = 0; mythread = thread_sdl_thread_unlock(); } +#endif switch (cmd) { @@ -242,13 +257,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; } @@ -259,19 +274,32 @@ return SIMULATOR_DEFAULT_ROOT; } +#ifdef __PCTOOL__ +char *get_sim_rockbox_path(char *dir, char *out_path) +{ + if (sim_root_dir != NULL) + strcpy(out_path, sim_rockbox_dir); + else + strcpy(out_path, SIMULATOR_DEFAULT_ROCKBOX_DIR); + + strcat(out_path, "/"); + strcat(out_path, dir); + + return out_path; +} +#endif + MYDIR *sim_opendir(const char *name) { 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 +324,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 +361,34 @@ 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 +401,6 @@ int sim_creat(const char *name) { -#ifndef __PCTOOL__ char buffer[MAX_PATH]; /* sufficiently big */ if(name[0] == '/') { @@ -385,67 +409,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 +477,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 +494,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 +505,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 */ @@ -512,7 +534,7 @@ long sim_filesize(int fd) { -#ifdef WIN32 +#ifdef _WIN32 return _filelength(fd); #else struct stat buf; @@ -536,8 +558,8 @@ } #endif -#ifdef WIN32 - long secperclus, bytespersec, free_clusters, num_clusters; +#ifdef _WIN32 + unsigned long secperclus, bytespersec, free_clusters, num_clusters; if (GetDiskFreeSpace(NULL, &secperclus, &bytespersec, &free_clusters, &num_clusters)) { @@ -568,32 +590,34 @@ int sim_fsync(int fd) { -#ifdef WIN32 +#ifdef _WIN32 return _commit(fd); #else return fsync(fd); #endif } -#ifdef WIN32 +#ifdef _WIN32 /* sim-win32 */ +typedef void (__stdcall *dlfunc)(); #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_)) -#define dlsym(_x_, _y_) (void *)GetProcAddress(_x_, _y_) +#define dlsym(_x_, _y_) (dlfunc)GetProcAddress(_x_, _y_) #define dlclose(_x_) FreeLibrary(_x_) #else /* sim-x11 */ #include +#define dlfunc void* #endif #define TEMP_CODEC_FILE SIMULATOR_DEFAULT_ROOT "/_temp_codec%d.dll" -void *sim_codec_load_ram(char* codecptr, int size, void **pd) +dlfunc sim_codec_load_ram(char* codecptr, int size, void **pd) { - void *hdr; + dlfunc hdr; char path[MAX_PATH]; int fd; int codec_count; -#ifdef WIN32 +#ifdef _WIN32 char buf[MAX_PATH]; #endif @@ -627,7 +651,7 @@ *pd = dlopen(path, RTLD_NOW); if (*pd == NULL) { DEBUGF("failed to load %s\n", path); -#ifdef WIN32 +#ifdef _WIN32 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buf, sizeof buf, NULL); DEBUGF("dlopen(%s): %s\n", path, buf); @@ -649,11 +673,11 @@ dlclose(pd); } -void *sim_plugin_load(char *plugin, void **pd) +dlfunc sim_plugin_load(char *plugin, void **pd) { - void *hdr; + dlfunc hdr; char path[MAX_PATH]; -#ifdef WIN32 +#ifdef _WIN32 char buf[MAX_PATH]; #endif @@ -664,7 +688,7 @@ *pd = dlopen(path, RTLD_NOW); if (*pd == NULL) { DEBUGF("failed to load %s\n", plugin); -#ifdef WIN32 +#ifdef _WIN32 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buf, sizeof(buf), NULL); DEBUGF("dlopen(%s): %s\n", path, buf); @@ -686,7 +710,7 @@ dlclose(pd); } -#ifdef WIN32 +#ifdef _WIN32 static unsigned old_cp; void debug_exit(void) @@ -730,7 +754,7 @@ /* rockbox off_t may be different from system off_t */ int sim_ftruncate(int fd, long length) { -#ifdef WIN32 +#ifdef _WIN32 return _chsize(fd, length); #else return ftruncate(fd, length);