From 22b7701fe75cce9afdbc27046821dc089f9e7dac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 22 Feb 2005 12:19:12 +0000 Subject: Build cleanup and general fixes. fprintf() is now fdprintf(), the separation between uisimulator files and firmware/apps files are better done. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6031 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/Makefile | 6 +- uisimulator/common/dir.h | 45 --------------- uisimulator/common/file.h | 76 ------------------------ uisimulator/common/io.c | 124 +++++++++++++++++++++++++++++++++++++--- uisimulator/common/lcd-common.c | 4 +- uisimulator/common/stubs.c | 3 +- 6 files changed, 124 insertions(+), 134 deletions(-) delete mode 100644 uisimulator/common/dir.h delete mode 100644 uisimulator/common/file.h (limited to 'uisimulator/common') diff --git a/uisimulator/common/Makefile b/uisimulator/common/Makefile index b044440adf..e2b6b2a4f8 100644 --- a/uisimulator/common/Makefile +++ b/uisimulator/common/Makefile @@ -23,7 +23,7 @@ RM = rm -f DEBUG = -g # Use this for simulator-only files -INCLUDES = -I. -I$(OBJDIR) -I$(FIRMDIR)/export -I$(APPSDIR) +INCLUDES = -I. -I$(OBJDIR) -I$(FIRMDIR)/export -I$(APPSDIR) -I$(ROOTDIR)/uisimulator/$(SIMVER) SRC := $(shell cat SOURCES | gcc -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) \ $(TARGET) $(DEFINES) $(EXTRA_DEFINES) -E -P -include "config.h" - ) @@ -38,7 +38,7 @@ DIRS = . CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -OUTFILE = $(OBJDIR)/libsim.a +OUTFILE = $(OBJDIR)/libcomsim.a all: $(OUTFILE) @@ -46,7 +46,7 @@ include $(TOOLSDIR)/make.inc clean: @echo "cleaning commonsim" - @$(RM) $(OBJS) *~ core $(DEPFILE) + @$(RM) $(OBJS) *~ core $(DEPFILE) $(OUTFILE) $(OUTFILE): $(OBJS) @echo "AR+RANLIB $@" diff --git a/uisimulator/common/dir.h b/uisimulator/common/dir.h deleted file mode 100644 index 18cfbb3736..0000000000 --- a/uisimulator/common/dir.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Daniel Stenberg - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef _SIM_DIR_H_ -#define _SIM_DIR_H_ - -#include - -#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ -#define dirent sim_dirent -#include "../../firmware/include/dir.h" -#undef dirent - -typedef void * MYDIR; - -extern MYDIR *sim_opendir(const char *name); -extern struct sim_dirent* sim_readdir(MYDIR* dir); -extern int sim_closedir(MYDIR *dir); -extern int sim_mkdir(const char *name, int mode); -extern int sim_rmdir(char *name); - -#define DIR MYDIR -#define dirent sim_dirent -#define opendir(x) sim_opendir(x) -#define readdir(x) sim_readdir(x) -#define closedir(x) sim_closedir(x) -#define mkdir(x, y) sim_mkdir(x, y) -#define rmdir(x) sim_rmdir(x) - -#endif diff --git a/uisimulator/common/file.h b/uisimulator/common/file.h deleted file mode 100644 index 7ea59a0b74..0000000000 --- a/uisimulator/common/file.h +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Daniel Stenberg - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef _SIM_FILE_H_ -#define _SIM_FILE_H_ - -#ifdef WIN32 -#include -#include -#else -#include -#endif - -#include - -#ifdef WIN32 -#ifndef _commit -extern int _commit( int handle ); - -#ifdef _MSC_VER -typedef unsigned int mode_t; -#endif - -#endif -#endif - -int sim_open(const char *name, int opts); -int sim_close(int fd); -int sim_rename(const char *oldpath, const char *newpath); -off_t sim_filesize(int fd); -int sim_creat(const char *name, mode_t mode); -int sim_remove(const char *name); - -#ifndef NO_REDEFINES_PLEASE -#define open(x,y) sim_open(x,y) -#define close(x) sim_close(x) -#define filesize(x) sim_filesize(x) -#define creat(x,y) sim_creat(x,y) -#define remove(x) sim_remove(x) -#define rename(x,y) sim_rename(x,y) -#ifdef WIN32 -#define fsync _commit -#endif -#endif - -#include "../../firmware/include/file.h" - -#ifndef WIN32 -int open(const char* pathname, int flags); -int close(int fd); -int printf(const char *format, ...); -int ftruncate(int fd, off_t length); -int fsync(int fd); - -off_t lseek(int fildes, off_t offset, int whence); -ssize_t read(int fd, void *buf, size_t count); -ssize_t write(int fd, const void *buf, size_t count); -#endif - -#endif diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 6335735f8f..48b888a027 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #ifdef __FreeBSD__ #include @@ -28,6 +29,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + #ifndef _MSC_VER #include #include @@ -35,18 +40,27 @@ #include "dir-win32.h" #endif +#define MAX_PATH 260 + #include #include "debug.h" -#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ -#define dirent sim_dirent -#define DIR SIMDIR -#include "../../firmware/include/dir.h" -#undef dirent -#undef DIR - #define SIMULATOR_ARCHOS_ROOT "archos" +struct sim_dirent { + unsigned char d_name[MAX_PATH]; + int attribute; + int size; + int startcluster; + unsigned short wrtdate; /* Last write date */ + unsigned short wrttime; /* Last write time */ +}; + +struct dirstruct { + void *dir; /* actually a DIR* dir */ + char *name; +} SIM_DIR; + struct mydir { DIR *dir; char *name; @@ -113,6 +127,8 @@ struct sim_dirent *sim_readdir(MYDIR *dir) dir->name, x11->d_name); stat(buffer, &s); /* get info */ +#define ATTR_DIRECTORY 0x10 + secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; secret.size = s.st_size; secret.wrtdate = (unsigned short)(s.st_mtime >> 16); @@ -181,6 +197,7 @@ int sim_mkdir(const char *name, mode_t mode) debugf("We create the real directory '%s'\n", buffer); #ifdef WIN32 + /* since we build with -DNOCYGWIN we have the plain win32 version */ return (mkdir)(buffer); #else return (mkdir)(buffer, 0666); @@ -260,3 +277,96 @@ void fat_size(unsigned int* size, unsigned int* free) } #endif } + +int sim_fsync(int fd) +{ +#ifdef WIN32 + return _commit(fd); +#else + return fsync(fd); +#endif +} + +#ifdef WIN32 +/* sim-win32 */ +typedef enum plugin_status (*plugin_fn)(void* api, void* param); +#define dlopen(_x_, _y_) LoadLibrary(_x_) +#define dlsym(_x_, _y_) (plugin_fn)GetProcAddress(_x_, _y_) +#define dlclose(_x_) FreeLibrary(_x_) +#define dlerror() "Unknown" +#else +/* sim-x11 */ +#include +#endif + +void *sim_plugin_load(char *plugin, int *fd) +{ + void* pd; + char path[256]; + char buf[256]; + int (*plugin_start)(void * api, void* param); + + snprintf(path, sizeof path, "archos%s", plugin); + + *fd = -1; + + pd = dlopen(path, RTLD_NOW); + if (!pd) { + snprintf(buf, sizeof buf, "failed to load %s", plugin); + DEBUGF("dlopen(%s): %s\n",path,dlerror()); + dlclose(pd); + return NULL; + } + + plugin_start = dlsym(pd, "plugin_start"); + if (!plugin_start) { + plugin_start = dlsym(pd, "_plugin_start"); + if (!plugin_start) { + dlclose(pd); + return NULL; + } + } + *fd = pd; /* success */ + return plugin_start; +} + +void sim_plugin_close(int pd) +{ + dlclose(pd); +} + +#ifndef WIN32 +/* the win32 version is in debug-win32.c */ + +void debug_init(void) +{ + /* nothing to be done */ +} + +void debugf(const char *fmt, ...) +{ + va_list ap; + va_start( ap, fmt ); + vfprintf( stderr, fmt, ap ); + va_end( ap ); +} + +void ldebugf(const char* file, int line, const char *fmt, ...) +{ + va_list ap; + va_start( ap, fmt ); + fprintf( stderr, "%s:%d ", file, line ); + vfprintf( stderr, fmt, ap ); + va_end( ap ); +} + +#endif + +int sim_ftruncate(int fd, off_t length) +{ +#ifdef WIN32 + return _chsize(fd, length); +#else + return ftruncate(fd, length); +#endif +} diff --git a/uisimulator/common/lcd-common.c b/uisimulator/common/lcd-common.c index c69ef06f1f..95c42ad8db 100644 --- a/uisimulator/common/lcd-common.c +++ b/uisimulator/common/lcd-common.c @@ -25,9 +25,9 @@ #include "lcd.h" #ifdef WIN32 - #include "lcd-win32.h" +#include "lcd-win32.h" #else - #include "lcd-x11.h" +#include "lcd-x11.h" #endif void lcd_blit(const unsigned char* p_data, int x, int y, int width, int height, diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index c43fb5f1f2..3ed16e8e34 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -28,7 +28,7 @@ #include "string.h" #include "lcd.h" -#include "settings.h" + #include "ata.h" /* for volume definitions */ extern char having_new_lcd; @@ -285,5 +285,6 @@ void remove_thread(int threadnum) } /* assure an unused place to direct virtual pointers to */ +#define VIRT_SIZE 0xFFFF /* more than enough for our string ID range */ unsigned char vp_dummy[VIRT_SIZE]; -- cgit v1.2.3