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 --- apps/Makefile | 16 ++++++++++-- apps/playlist.c | 18 ++++++------- apps/plugin.c | 60 ++++++++++--------------------------------- apps/plugin.h | 38 ++++++++++++++++----------- apps/plugins/Makefile | 6 +++++ apps/plugins/calendar.c | 14 +++++----- apps/plugins/lib/configfile.c | 8 +++--- apps/settings.c | 20 +++++++-------- 8 files changed, 86 insertions(+), 94 deletions(-) (limited to 'apps') diff --git a/apps/Makefile b/apps/Makefile index bcdc1ef265..4f80e045b7 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -43,6 +43,8 @@ MAXOUTFILE = $(OBJDIR)/romstart ifdef SIMVER # this is a sim build all: $(OBJDIR)/$(BINARY) $(CODECS) $(ROCKS) + @$(MAKE) -C $(SIMDIR) + @$(MAKE) -C $(ROOTDIR)/uisimulator/common else # regular target build all: $(OBJDIR)/$(BINARY) $(FLASHFILE) $(CODECS) $(ROCKS) $(ARCHOSROM) @@ -101,12 +103,22 @@ $(OBJDIR)/$(BINARY) : $(OBJDIR)/rockbox.bin else # this is a simulator build -$(OBJDIR)/$(BINARY) : $(OBJS) $(OBJDIR)/librockbox.a $(DEPFILE) $(OBJDIR)/libsim.a + +ifeq ($(SIMVER), win32) +# OK, this is ugly but we need it on the link line to make it do right +EXTRAOBJ = $(OBJDIR)/uisw32-res.o +endif + + +$(OBJDIR)/$(BINARY) : $(OBJS) $(OBJDIR)/librockbox.a $(DEPFILE) $(OBJDIR)/libsim.a $(OBJDIR)/libcomsim.a @echo "LD $(BINARY)" - $(CC) $(GCCOPTS) -o $@ $(OBJS) $(LDOPTS) -L$(OBJDIR) -lrockbox -lsim -Wl,-Map,$(OBJDIR)/rockbox.map + $(CC) $(GCCOPTS) -o $@ $(OBJS) -L$(OBJDIR) -lrockbox -lsim -lcomsim $(LDOPTS) $(EXTRAOBJ) -Wl,-Map,$(OBJDIR)/rockbox.map $(OBJDIR)/libsim.a: @$(MAKE) -C $(SIMDIR) + +$(OBJDIR)/libcomsim.a: + @$(MAKE) -C $(ROOTDIR)/uisimulator/common endif $(OBJDIR)/rockbox.ucl: $(OBJDIR)/rockbox.bin diff --git a/apps/playlist.c b/apps/playlist.c index 5e7f679800..cb9d2ba3ea 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -231,7 +231,7 @@ static void new_playlist(struct playlist_info* playlist, const char *dir, if (playlist->control_fd >= 0) { - if (fprintf(playlist->control_fd, "P:%d:%s:%s\n", + if (fdprintf(playlist->control_fd, "P:%d:%s:%s\n", PLAYLIST_CONTROL_FILE_VERSION, dir, file) > 0) fsync(playlist->control_fd); else @@ -279,7 +279,7 @@ static int check_control(struct playlist_info* playlist) playlist->filename[playlist->dirlen-1] = '\0'; - if (fprintf(playlist->control_fd, "P:%d:%s:%s\n", + if (fdprintf(playlist->control_fd, "P:%d:%s:%s\n", PLAYLIST_CONTROL_FILE_VERSION, dir, file) > 0) fsync(playlist->control_fd); else @@ -499,13 +499,13 @@ static int add_track_to_playlist(struct playlist_info* playlist, if (lseek(playlist->control_fd, 0, SEEK_END) >= 0) { - if (fprintf(playlist->control_fd, "%c:%d:%d:", (queue?'Q':'A'), + if (fdprintf(playlist->control_fd, "%c:%d:%d:", (queue?'Q':'A'), position, playlist->last_insert_pos) > 0) { /* save the position in file where track name is written */ seek_pos = lseek(playlist->control_fd, 0, SEEK_CUR); - if (fprintf(playlist->control_fd, "%s\n", filename) > 0) + if (fdprintf(playlist->control_fd, "%s\n", filename) > 0) result = 0; } } @@ -697,7 +697,7 @@ static int remove_track_from_playlist(struct playlist_info* playlist, if (lseek(playlist->control_fd, 0, SEEK_END) >= 0) { - if (fprintf(playlist->control_fd, "D:%d\n", position) > 0) + if (fdprintf(playlist->control_fd, "D:%d\n", position) > 0) { fsync(playlist->control_fd); result = 0; @@ -1098,10 +1098,10 @@ static int flush_pending_control(struct playlist_info* playlist) if (lseek(playlist->control_fd, 0, SEEK_END) >= 0) { if (global_settings.resume_seed == 0) - result = fprintf(playlist->control_fd, "U:%d\n", + result = fdprintf(playlist->control_fd, "U:%d\n", playlist->first_index); else - result = fprintf(playlist->control_fd, "S:%d:%d\n", + result = fdprintf(playlist->control_fd, "S:%d:%d\n", global_settings.resume_seed, playlist->first_index); if (result > 0) @@ -1737,7 +1737,7 @@ int playlist_next(int steps) if (lseek(playlist->control_fd, 0, SEEK_END) >= 0) { - if (fprintf(playlist->control_fd, "R\n") > 0) + if (fdprintf(playlist->control_fd, "R\n") > 0) { fsync(playlist->control_fd); result = 0; @@ -2407,7 +2407,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) break; } - if (fprintf(fd, "%s\n", tmp_buf) < 0) + if (fdprintf(fd, "%s\n", tmp_buf) < 0) { splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_UPDATE_ERROR)); result = -1; diff --git a/apps/plugin.c b/apps/plugin.c index 10daeaf325..194ec34484 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -50,18 +50,6 @@ #include "widgets.h" #endif -#ifdef SIMULATOR - #include - #ifdef WIN32 - #include "plugin-win32.h" - #else - #include - #endif - #define PREFIX(_x_) sim_ ## _x_ -#else -#define PREFIX(_x_) _x_ -#endif - #if MEM >= 32 #define PLUGIN_BUFFER_SIZE 0xC0000 #else @@ -70,7 +58,9 @@ #ifdef SIMULATOR static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE]; +void *sim_plugin_load(char *plugin, int *fd); #else +#define sim_plugin_close(x) extern unsigned char pluginbuf[]; #include "bitswap.h" #endif @@ -142,16 +132,16 @@ static const struct plugin_api rockbox_api = { /* file */ (open_func)PREFIX(open), - PREFIX(close), + close, (read_func)read, lseek, (creat_func)PREFIX(creat), (write_func)write, PREFIX(remove), PREFIX(rename), - ftruncate, + PREFIX(ftruncate), PREFIX(filesize), - fprintf, + fdprintf, read_line, settings_parseline, #ifndef SIMULATOR @@ -189,6 +179,9 @@ static const struct plugin_api rockbox_api = { memcpy, _ctype_, atoi, + strchr, + strcat, + memcmp, /* sound */ mpeg_sound_set, @@ -201,7 +194,7 @@ static const struct plugin_api rockbox_api = { #endif /* playback control */ - mpeg_play, + PREFIX(mpeg_play), mpeg_stop, mpeg_pause, mpeg_resume, @@ -264,10 +257,6 @@ static const struct plugin_api rockbox_api = { /* new stuff at the end, sort into place next time the API gets incompatible */ - - strchr, - strcat, - memcmp }; int plugin_load(const char* plugin, void* parameter) @@ -275,12 +264,8 @@ int plugin_load(const char* plugin, void* parameter) enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); int rc; char buf[64]; -#ifdef SIMULATOR - void* pd; - char path[256]; -#else int fd; -#endif + #ifdef HAVE_LCD_BITMAP int xm,ym; #endif @@ -301,26 +286,9 @@ int plugin_load(const char* plugin, void* parameter) lcd_clear_display(); #endif #ifdef SIMULATOR - snprintf(path, sizeof path, "archos%s", plugin); - - pd = dlopen(path, RTLD_NOW); - if (!pd) { - snprintf(buf, sizeof buf, str(LANG_PLUGIN_CANT_OPEN), plugin); - splash(HZ*2, true, buf); - DEBUGF("dlopen(%s): %s\n",path,dlerror()); - dlclose(pd); + plugin_start = sim_plugin_load(plugin, &fd); + if(!plugin_start) return -1; - } - - plugin_start = dlsym(pd, "plugin_start"); - if (!plugin_start) { - plugin_start = dlsym(pd, "_plugin_start"); - if (!plugin_start) { - splash(HZ*2, true, "Can't find entry point"); - dlclose(pd); - return -1; - } - } #else fd = open(plugin, O_RDONLY); if (fd < 0) { @@ -379,9 +347,7 @@ int plugin_load(const char* plugin, void* parameter) break; } -#ifdef SIMULATOR - dlclose(pd); -#endif + sim_plugin_close(fd); #ifdef HAVE_LCD_BITMAP /* restore margins */ diff --git a/apps/plugin.h b/apps/plugin.h index 96a9aabe1d..896565e9a0 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -32,6 +32,7 @@ #include #include #include +#include #include "config.h" #include "dir.h" #include "kernel.h" @@ -51,7 +52,9 @@ #ifdef PLUGIN #if defined(DEBUG) || defined(SIMULATOR) +#undef DEBUGF #define DEBUGF rb->debugf +#undef LDEBUGF #define LDEBUGF rb->debugf #else #define DEBUGF(...) @@ -59,13 +62,19 @@ #endif #endif +#ifdef SIMULATOR +#define PREFIX(_x_) sim_ ## _x_ +#else +#define PREFIX(_x_) _x_ +#endif + /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 31 +#define PLUGIN_API_VERSION 32 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 29 +#define PLUGIN_MIN_API_VERSION 32 /* plugin return codes */ enum plugin_status { @@ -165,17 +174,17 @@ struct plugin_api { void (*button_clear_queue)(void); /* file */ - int (*open)(const char* pathname, int flags); + int (*PREFIX(open))(const char* pathname, int flags); int (*close)(int fd); ssize_t (*read)(int fd, void* buf, size_t count); off_t (*lseek)(int fd, off_t offset, int whence); - int (*creat)(const char *pathname, mode_t mode); + int (*PREFIX(creat))(const char *pathname, mode_t mode); ssize_t (*write)(int fd, const void* buf, size_t count); - int (*remove)(const char* pathname); - int (*rename)(const char* path, const char* newname); - int (*ftruncate)(int fd, off_t length); - off_t (*filesize)(int fd); - int (*fprintf)(int fd, const char *fmt, ...); + int (*PREFIX(remove))(const char* pathname); + int (*PREFIX(rename))(const char* path, const char* newname); + int (*PREFIX(ftruncate))(int fd, off_t length); + off_t (*PREFIX(filesize))(int fd); + int (*fdprintf)(int fd, const char *fmt, ...); int (*read_line)(int fd, char* buffer, int buffer_size); bool (*settings_parseline)(char* line, char** name, char** value); #ifndef SIMULATOR @@ -188,7 +197,7 @@ struct plugin_api { struct dirent* (*readdir)(DIR* dir); /* kernel/ system */ - void (*sleep)(int ticks); + void (*PREFIX(sleep))(int ticks); void (*yield)(void); long* current_tick; long (*default_event_handler)(long event); @@ -213,6 +222,9 @@ struct plugin_api { void* (*memcpy)(void *out, const void *in, size_t n); const char *_ctype_; int (*atoi)(const char *str); + char *(*strchr)(const char *s, int c); + char *(*strcat)(char *s1, const char *s2); + int (*memcmp)(const void *s1, const void *s2, size_t n); /* sound */ void (*mpeg_sound_set)(int setting, int value); @@ -225,7 +237,7 @@ struct plugin_api { #endif /* playback control */ - void (*mpeg_play)(int offset); + void (*PREFIX(mpeg_play))(int offset); void (*mpeg_stop)(void); void (*mpeg_pause)(void); void (*mpeg_resume)(void); @@ -295,10 +307,6 @@ struct plugin_api { /* new stuff at the end, sort into place next time the API gets incompatible */ - - char *(*strchr)(const char *s, int c); - char *(*strcat)(char *s1, const char *s2); - int (*memcmp)(const void *s1, const void *s2, size_t n); }; /* defined by the plugin loader (plugin.c) */ diff --git a/apps/plugins/Makefile b/apps/plugins/Makefile index 9549959bbd..ef506a9c4a 100644 --- a/apps/plugins/Makefile +++ b/apps/plugins/Makefile @@ -71,7 +71,13 @@ $(OBJDIR)/%.rock : $(OBJDIR)/%.o $(APPSDIR)/plugin.h @echo "DLL $@" @$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< @$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< $(OBJDIR)/libplugin.a -o $@ +ifeq ($(UNAME),CYGWIN) +# 'x' must be kept or you'll have "Win32 error 5" +# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 +# #define ERROR_ACCESS_DENIED 5L +else @chmod -x $@ +endif endif # end of win32-simulator endif # end of simulator section diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 44b3685c40..8627c9a558 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c @@ -325,13 +325,13 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) } if (new_mod) { - rb->fprintf(fq, "%02d%02d%04d%01d%01d%s\n", - memos[changed].day, - memos[changed].month, - memos[changed].year, - memos[changed].wday, - memos[changed].type, - memos[changed].message); + rb->fdprintf(fq, "%02d%02d%04d%01d%01d%s\n", + memos[changed].day, + memos[changed].month, + memos[changed].year, + memos[changed].wday, + memos[changed].type, + memos[changed].message); } rb->lseek(fp, memos[changed].file_pointer_end, SEEK_SET); for (i = memos[changed].file_pointer_end; diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c index ff4809a3f4..f2f0a39da0 100644 --- a/apps/plugins/lib/configfile.c +++ b/apps/plugins/lib/configfile.c @@ -38,24 +38,24 @@ int configfile_save(const char *filename, struct configdata *cfg, if(fd < 0) return fd*10 - 1; - cfg_rb->fprintf(fd, "file version: %d\n", version); + cfg_rb->fdprintf(fd, "file version: %d\n", version); for(i = 0;i < num_items;i++) { switch(cfg[i].type) { case TYPE_INT: - cfg_rb->fprintf(fd, "%s: %d\n", + cfg_rb->fdprintf(fd, "%s: %d\n", cfg[i].name, *cfg[i].val); break; case TYPE_ENUM: - cfg_rb->fprintf(fd, "%s: %s\n", + cfg_rb->fdprintf(fd, "%s: %s\n", cfg[i].name, cfg[i].values[*cfg[i].val]); break; case TYPE_STRING: - cfg_rb->fprintf(fd, "%s: %s\n", + cfg_rb->fdprintf(fd, "%s: %s\n", cfg[i].name, cfg[i].string); break; diff --git a/apps/settings.c b/apps/settings.c index ba80bfb9d9..86c1178745 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -1127,13 +1127,13 @@ static void save_cfg_table(const struct bit_entry* p_table, int count, int fd) if (p_run->cfg_val == NULL) /* write as number */ { - fprintf(fd, "%s: %ld\r\n", p_run->cfg_name, value); + fdprintf(fd, "%s: %ld\r\n", p_run->cfg_name, value); } else /* write as item */ { const char* p = p_run->cfg_val; - fprintf(fd, "%s: ", p_run->cfg_name); + fdprintf(fd, "%s: ", p_run->cfg_name); while(value >= 0) { @@ -1146,9 +1146,9 @@ static void save_cfg_table(const struct bit_entry* p_table, int count, int fd) write(fd, &c, 1); /* char by char, this is lame, OK */ } - fprintf(fd, "\r\n"); + fdprintf(fd, "\r\n"); if (p_run->cfg_val != off_on) /* explaination for non-bool */ - fprintf(fd, "# (possible values: %s)\r\n", p_run->cfg_val); + fdprintf(fd, "# (possible values: %s)\r\n", p_run->cfg_val); } } } @@ -1195,21 +1195,21 @@ bool settings_save_config(void) return false; } - fprintf(fd, "# >>> .cfg file created by rockbox %s <<<\r\n", appsversion); - fprintf(fd, "# >>> http://rockbox.haxx.se <<<\r\n#\r\n"); - fprintf(fd, "#\r\n# wps / language / font \r\n#\r\n"); + fdprintf(fd, "# .cfg file created by rockbox %s - ", appsversion); + fdprintf(fd, "http://www.rockbox.org\r\n#\r\n"); + fdprintf(fd, "#\r\n# wps / language / font \r\n#\r\n"); if (global_settings.wps_file[0] != 0) - fprintf(fd, "wps: %s/%s.wps\r\n", ROCKBOX_DIR, + fdprintf(fd, "wps: %s/%s.wps\r\n", ROCKBOX_DIR, global_settings.wps_file); if (global_settings.lang_file[0] != 0) - fprintf(fd, "lang: %s/%s.lng\r\n", ROCKBOX_DIR LANG_DIR, + fdprintf(fd, "lang: %s/%s.lng\r\n", ROCKBOX_DIR LANG_DIR, global_settings.lang_file); #ifdef HAVE_LCD_BITMAP if (global_settings.font_file[0] != 0) - fprintf(fd, "font: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR, + fdprintf(fd, "font: %s/%s.fnt\r\n", ROCKBOX_DIR FONT_DIR, global_settings.font_file); #endif -- cgit v1.2.3