From 50a6ca39ad4ed01922aa4f755f0ca579788226cf Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 6 May 2010 21:04:40 +0000 Subject: Move c/h files implementing/defining standard library stuff into a new libc directory, also standard'ify some parts of the code base (almost entirely #include fixes). This is to a) to cleanup firmware/common and firmware/include a bit, but also b) for Rockbox as an application which should use the host system's c library and headers, separating makes it easy to exclude our files from the build. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25850 a1c6a512-1295-4272-9138-f99709370657 --- apps/alarm_menu.c | 1 - apps/apps.make | 5 +- apps/bookmark.c | 6 +- apps/buffering.c | 1 - apps/codecs.c | 3 +- apps/codecs.h | 2 + apps/codecs/adx.c | 2 + apps/codecs/demac/demac.c | 1 - apps/codecs/demac/libdemac/parser.c | 2 +- apps/codecs/demac/wavwrite.c | 2 +- apps/codecs/lib/codeclib.h | 10 +- apps/codecs/lib/tlsf/src/tlsf.c | 2 +- apps/codecs/lib/tlsf/src/tlsf.h | 2 +- apps/codecs/libatrac/main.c | 2 +- apps/codecs/libcook/main.c | 2 +- apps/codecs/libfaad/common.h | 2 +- apps/codecs/libmad/libmad.make | 2 +- apps/codecs/libpcm/adpcm_seek.h | 2 +- apps/codecs/libpcm/ima_adpcm_common.c | 16 +- apps/codecs/libpcm/ima_adpcm_common.h | 1 - apps/codecs/libpcm/pcm_common.h | 2 +- apps/codecs/librm/rm.c | 2 +- apps/codecs/libtremor/config-tremor.h | 2 + apps/codecs/libtremor/ctype.c | 4 +- apps/codecs/libwavpack/words.c | 6 +- apps/cuesheet.c | 1 - apps/debug_menu.c | 1 - apps/enc_config.c | 1 - apps/filetree.c | 1 - apps/filetypes.c | 1 - apps/gui/bitmap/list.c | 1 - apps/gui/charcell/list.c | 1 - apps/gui/list.c | 2 +- apps/gui/option_select.c | 3 +- apps/gui/pitchscreen.c | 15 +- apps/gui/skin_engine/skin_backdrops.c | 3 +- apps/gui/skin_engine/skin_display.c | 2 +- apps/gui/skin_engine/skin_tokens.c | 14 +- apps/gui/statusbar.c | 2 +- apps/gui/usb_screen.c | 1 - apps/gui/viewport.c | 1 - apps/gui/wps.c | 1 - apps/main.c | 1 - apps/menus/eq_menu.c | 1 - apps/menus/recording_menu.c | 1 - apps/menus/settings_menu.c | 1 - apps/menus/time_menu.c | 30 +-- apps/metadata.c | 3 +- apps/metadata/metadata_common.c | 2 +- apps/metadata/metadata_common.h | 1 + apps/metadata/mp3.c | 4 +- apps/metadata/smaf.c | 2 +- apps/misc.c | 10 +- apps/onplay.c | 1 - apps/player/keyboard.c | 1 - apps/playlist.c | 7 +- apps/playlist_catalog.c | 3 +- apps/playlist_viewer.c | 1 - apps/plugin.c | 1 - apps/plugin.h | 9 +- apps/plugins/calculator.c | 3 + apps/plugins/doom/d_deh.c | 2 +- apps/plugins/doom/doom.make | 2 +- apps/plugins/doom/rockmacros.h | 20 +- apps/plugins/frotz/frotz.c | 6 +- apps/plugins/frotz/frotzplugin.h | 9 +- apps/plugins/imageviewer/png/png.c | 2 +- apps/plugins/invadrox.c | 4 + apps/plugins/lib/buflib.c | 4 +- apps/plugins/lib/jhash.h | 4 +- apps/plugins/lib/strncpy.c | 1 + apps/plugins/lua/gmtime.c | 6 +- apps/plugins/midi/midiplay.c | 2 + apps/plugins/midi/midiutil.c | 5 - apps/plugins/midi/midiutil.h | 3 +- apps/plugins/mpegplayer/disk_buf.c | 2 +- apps/plugins/random_folder_advance_config.c | 10 +- apps/plugins/rockboy/menu.c | 8 +- apps/plugins/rockboy/rockboy.make | 2 +- apps/plugins/rockboy/rtc.c | 1 - apps/plugins/search.c | 2 +- apps/plugins/shortcuts/shortcuts.h | 2 +- apps/plugins/shortcuts/shortcuts_common.c | 2 +- apps/plugins/stats.c | 10 +- apps/plugins/wav2wv.c | 8 +- apps/plugins/zxbox/helpers.h | 7 +- apps/plugins/zxbox/snapshot.c | 8 +- apps/plugins/zxbox/spconf.c | 8 +- apps/plugins/zxbox/sptape.c | 1 - apps/plugins/zxbox/tapefile.c | 2 +- apps/plugins/zxbox/zxmisc.h | 2 +- apps/recorder/albumart.c | 3 +- apps/recorder/icons.c | 1 - apps/recorder/jpeg_load.c | 18 +- apps/recorder/keyboard.c | 2 +- apps/recorder/peakmeter.c | 1 - apps/recorder/radio.c | 3 +- apps/recorder/recording.c | 4 +- apps/replaygain.c | 9 +- apps/root_menu.c | 2 +- apps/screen_access.c | 5 +- apps/screens.c | 1 - apps/scrobbler.c | 2 +- apps/settings.c | 4 +- apps/settings_list.c | 2 +- apps/tagcache.c | 6 +- apps/tagtree.c | 2 +- apps/talk.c | 2 +- apps/tree.c | 3 +- apps/voice_thread.c | 1 + firmware/SOURCES | 55 ++-- firmware/common/atoi.c | 57 ---- firmware/common/config.c | 28 ++ firmware/common/ctype.c | 22 -- firmware/common/dircache.c | 2 +- firmware/common/errno.c | 1 - firmware/common/format.c | 227 ++++++++++++++++ firmware/common/memchr.c | 116 -------- firmware/common/memcmp.c | 113 -------- firmware/common/memcpy.c | 117 -------- firmware/common/memmove.c | 147 ---------- firmware/common/memset.c | 109 -------- firmware/common/qsort.c | 222 --------------- firmware/common/random.c | 119 -------- firmware/common/sprintf.c | 299 --------------------- firmware/common/sscanf.c | 282 ------------------- firmware/common/strcat.c | 14 - firmware/common/strchr.c | 108 -------- firmware/common/strcmp.c | 106 -------- firmware/common/strcpy.c | 99 ------- firmware/common/strlcat.c | 1 - firmware/common/strlcpy.c | 1 - firmware/common/strlen.c | 93 ------- firmware/common/strncmp.c | 122 --------- firmware/common/strrchr.c | 59 ---- firmware/common/strstr.c | 38 --- firmware/common/strtok.c | 63 ----- firmware/common/timefuncs.c | 37 --- firmware/drivers/lcd-bitmap-common.c | 5 +- firmware/drivers/lcd-charcell.c | 1 - firmware/drivers/tuner/lv24020lp.c | 1 - firmware/export/audio.h | 2 +- firmware/export/config/sim.h | 2 + firmware/export/pcm.h | 2 +- firmware/firmware.make | 2 +- firmware/general.c | 4 +- firmware/ifp_usb_serial.c | 1 - firmware/include/ctype.h | 75 ------ firmware/include/errno.h | 145 ---------- firmware/include/file.h | 3 +- firmware/include/format.h | 37 +++ firmware/include/inttypes.h | 112 -------- firmware/include/memory.h | 2 +- firmware/include/sprintf.h | 40 --- firmware/include/sscanf.h | 32 --- firmware/include/stdio.h | 48 ---- firmware/include/stdlib.h | 58 ---- firmware/include/strcasecmp.h | 28 ++ firmware/include/strcasestr.h | 26 ++ firmware/include/string-extra.h | 27 ++ firmware/include/string.h | 86 ------ firmware/include/strlcat.h | 26 ++ firmware/include/strlcpy.h | 26 ++ firmware/include/sys/types.h | 23 +- firmware/include/time.h | 49 ---- firmware/include/timefuncs.h | 3 - firmware/libc/atoi.c | 57 ++++ firmware/libc/ctype.c | 22 ++ firmware/libc/errno.c | 1 + firmware/libc/include/ctype.h | 75 ++++++ firmware/libc/include/errno.h | 145 ++++++++++ firmware/libc/include/inttypes.h | 29 ++ firmware/libc/include/stdint.h | 107 ++++++++ firmware/libc/include/stdio.h | 60 +++++ firmware/libc/include/stdlib.h | 58 ++++ firmware/libc/include/string.h | 94 +++++++ firmware/libc/include/time.h | 49 ++++ firmware/libc/memchr.c | 116 ++++++++ firmware/libc/memcmp.c | 113 ++++++++ firmware/libc/memcpy.c | 117 ++++++++ firmware/libc/memmove.c | 147 ++++++++++ firmware/libc/memset.c | 110 ++++++++ firmware/libc/mktime.c | 61 +++++ firmware/libc/qsort.c | 222 +++++++++++++++ firmware/libc/random.c | 119 ++++++++ firmware/libc/sprintf.c | 93 +++++++ firmware/libc/sscanf.c | 282 +++++++++++++++++++ firmware/libc/strcat.c | 14 + firmware/libc/strchr.c | 108 ++++++++ firmware/libc/strcmp.c | 106 ++++++++ firmware/libc/strcpy.c | 99 +++++++ firmware/libc/strlen.c | 93 +++++++ firmware/libc/strncmp.c | 122 +++++++++ firmware/libc/strrchr.c | 59 ++++ firmware/libc/strstr.c | 38 +++ firmware/libc/strtok.c | 63 +++++ firmware/profile.c | 2 +- firmware/rolo.c | 1 - firmware/target/arm/as3525/debug-as3525.c | 1 - firmware/target/arm/imx31/debug-imx31.c | 1 - .../target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c | 2 +- firmware/target/arm/ipod/video/lcd-video.c | 2 +- firmware/target/arm/lcd-c200_c200v2.c | 2 +- firmware/target/arm/philips/hdd1630/lcd-hdd1630.c | 2 +- .../target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c | 1 - firmware/target/arm/s3c2440/debug-s3c2440.c | 1 - firmware/target/arm/s3c2440/lcd-s3c2440.c | 4 +- firmware/target/arm/s5l8700/debug-s5l8700.c | 1 - firmware/target/arm/samsung/yh820/lcd-yh820.c | 2 +- firmware/target/arm/sandisk/sansa-e200/lcd-e200.c | 2 +- firmware/target/arm/tcc77x/debug-tcc77x.c | 1 - firmware/target/arm/tcc77x/iaudio7/ata2501.c | 1 - firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c | 2 +- firmware/target/arm/tcc780x/debug-tcc780x.c | 1 - .../arm/tms320dm320/creative-zvm/pic-creativezvm.c | 1 - firmware/target/arm/tms320dm320/debug-dm320.c | 1 - firmware/target/arm/usb-s3c6400x.c | 1 - firmware/target/arm/usb-tcc.c | 1 - firmware/target/mips/ingenic_jz47xx/lcd-jz4740.c | 2 +- .../target/mips/ingenic_jz47xx/system-jz4740.c | 1 - firmware/test/snprintf/test.c | 1 - firmware/thread.c | 2 +- firmware/usb.c | 1 - tools/configure | 3 +- uisimulator/sdl/sprintf.h | 38 --- 225 files changed, 3499 insertions(+), 3315 deletions(-) delete mode 100644 firmware/common/atoi.c create mode 100644 firmware/common/config.c delete mode 100644 firmware/common/ctype.c delete mode 100644 firmware/common/errno.c create mode 100644 firmware/common/format.c delete mode 100644 firmware/common/memchr.c delete mode 100644 firmware/common/memcmp.c delete mode 100644 firmware/common/memcpy.c delete mode 100644 firmware/common/memmove.c delete mode 100644 firmware/common/memset.c delete mode 100644 firmware/common/qsort.c delete mode 100644 firmware/common/random.c delete mode 100644 firmware/common/sprintf.c delete mode 100644 firmware/common/sscanf.c delete mode 100644 firmware/common/strcat.c delete mode 100644 firmware/common/strchr.c delete mode 100644 firmware/common/strcmp.c delete mode 100644 firmware/common/strcpy.c delete mode 100644 firmware/common/strlen.c delete mode 100644 firmware/common/strncmp.c delete mode 100644 firmware/common/strrchr.c delete mode 100644 firmware/common/strstr.c delete mode 100644 firmware/common/strtok.c delete mode 100644 firmware/include/ctype.h delete mode 100644 firmware/include/errno.h create mode 100644 firmware/include/format.h delete mode 100644 firmware/include/inttypes.h delete mode 100644 firmware/include/sprintf.h delete mode 100644 firmware/include/sscanf.h delete mode 100644 firmware/include/stdio.h delete mode 100644 firmware/include/stdlib.h create mode 100644 firmware/include/strcasecmp.h create mode 100644 firmware/include/strcasestr.h create mode 100644 firmware/include/string-extra.h delete mode 100644 firmware/include/string.h create mode 100644 firmware/include/strlcat.h create mode 100644 firmware/include/strlcpy.h delete mode 100644 firmware/include/time.h create mode 100644 firmware/libc/atoi.c create mode 100644 firmware/libc/ctype.c create mode 100644 firmware/libc/errno.c create mode 100644 firmware/libc/include/ctype.h create mode 100644 firmware/libc/include/errno.h create mode 100644 firmware/libc/include/inttypes.h create mode 100644 firmware/libc/include/stdint.h create mode 100644 firmware/libc/include/stdio.h create mode 100644 firmware/libc/include/stdlib.h create mode 100644 firmware/libc/include/string.h create mode 100644 firmware/libc/include/time.h create mode 100644 firmware/libc/memchr.c create mode 100644 firmware/libc/memcmp.c create mode 100644 firmware/libc/memcpy.c create mode 100644 firmware/libc/memmove.c create mode 100644 firmware/libc/memset.c create mode 100644 firmware/libc/mktime.c create mode 100644 firmware/libc/qsort.c create mode 100644 firmware/libc/random.c create mode 100644 firmware/libc/sprintf.c create mode 100644 firmware/libc/sscanf.c create mode 100644 firmware/libc/strcat.c create mode 100644 firmware/libc/strchr.c create mode 100644 firmware/libc/strcmp.c create mode 100644 firmware/libc/strcpy.c create mode 100644 firmware/libc/strlen.c create mode 100644 firmware/libc/strncmp.c create mode 100644 firmware/libc/strrchr.c create mode 100644 firmware/libc/strstr.c create mode 100644 firmware/libc/strtok.c delete mode 100644 uisimulator/sdl/sprintf.h diff --git a/apps/alarm_menu.c b/apps/alarm_menu.c index 3a44fa472a..1cd0bc4670 100644 --- a/apps/alarm_menu.c +++ b/apps/alarm_menu.c @@ -25,7 +25,6 @@ #include "lcd.h" #include "action.h" #include "kernel.h" -#include "sprintf.h" #include #include "settings.h" #include "power.h" diff --git a/apps/apps.make b/apps/apps.make index 3717c5bd34..8814147102 100644 --- a/apps/apps.make +++ b/apps/apps.make @@ -15,9 +15,10 @@ SRC += $(call preprocess, $(APPSDIR)/SOURCES) # to genlang and thus (translated) phrases can be used based on those names. # button.h is included for the HAS_BUTTON_HOLD define. # -# Kludge: depends on ctype.o only to depend on config-*.h ... +# Kludge: depends on config.o which only depends on config-*.h to have config.h +# changes trigger a genlang re-run # -features $(BUILDDIR)/apps/features $(BUILDDIR)/apps/genlang-features: $(APPSDIR)/features.txt $(BUILDDIR)/firmware/common/ctype.o +features $(BUILDDIR)/apps/features $(BUILDDIR)/apps/genlang-features: $(APPSDIR)/features.txt $(BUILDDIR)/firmware/common/config.o $(SILENT)mkdir -p $(BUILDDIR)/apps $(SILENT)mkdir -p $(BUILDDIR)/lang $(call PRINTS,PP $(%d;%d;%ld;%d;%ld;%d;%d;%d;%d;%s;%s", + ">%d;%d;%ld;%d;%ld;%d;%d;%ld;%ld;%s;%s", #else ">%d;%d;%ld;%d;%ld;%d;%d;%s;%s", #endif @@ -360,8 +360,8 @@ static char* create_bookmark() global_settings.playlist_shuffle, /* ...and their values should go here */ #if CONFIG_CODEC == SWCODEC - sound_get_pitch(), - dsp_get_timestretch(), + (long)sound_get_pitch(), + (long)dsp_get_timestretch(), #endif /* more mandatory tokens */ playlist_get_name(NULL, global_temp_buffer, diff --git a/apps/buffering.c b/apps/buffering.c index afc7c7ad6b..2c26c6634d 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -38,7 +38,6 @@ #include "kernel.h" #include "tree.h" #include "debug.h" -#include "sprintf.h" #include "settings.h" #include "codecs.h" #include "audio.h" diff --git a/apps/codecs.c b/apps/codecs.c index b20aa7f969..4d97baacbe 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -26,12 +26,13 @@ #include #include #include +#include +#include "string-extra.h" #include "debug.h" #include "button.h" #include "dir.h" #include "file.h" #include "kernel.h" -#include "sprintf.h" #include "screens.h" #include "misc.h" #include "mas.h" diff --git a/apps/codecs.h b/apps/codecs.h index 34fd3940ad..27c9caba13 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -31,8 +31,10 @@ #define MEM 2 #endif +#include <_ansi.h> #include #include +#include "strlcpy.h" #include "config.h" #include "system.h" #include "metadata.h" diff --git a/apps/codecs/adx.c b/apps/codecs/adx.c index fe32653b18..dd5bba16e7 100644 --- a/apps/codecs/adx.c +++ b/apps/codecs/adx.c @@ -18,6 +18,8 @@ * KIND, either express or implied. * ****************************************************************************/ + +#include #include "codeclib.h" #include "inttypes.h" #include "math.h" diff --git a/apps/codecs/demac/demac.c b/apps/codecs/demac/demac.c index 5e9893687d..3e97fff2c9 100644 --- a/apps/codecs/demac/demac.c +++ b/apps/codecs/demac/demac.c @@ -46,7 +46,6 @@ avoided by writing the decoded data one sample at a time. #include #include #include -#include #include #include #include diff --git a/apps/codecs/demac/libdemac/parser.c b/apps/codecs/demac/libdemac/parser.c index ebde36deed..2af4a292b8 100644 --- a/apps/codecs/demac/libdemac/parser.c +++ b/apps/codecs/demac/libdemac/parser.c @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA #ifndef ROCKBOX #include #include -#include +#include "inttypes.h" #include #include #include diff --git a/apps/codecs/demac/wavwrite.c b/apps/codecs/demac/wavwrite.c index 72c7950dd4..71d2b7bb97 100644 --- a/apps/codecs/demac/wavwrite.c +++ b/apps/codecs/demac/wavwrite.c @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA #include #include #include -#include +#include "inttypes.h" #include #include #include diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index 817d86a6a3..b7685ebbcb 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h @@ -22,9 +22,10 @@ #ifndef __CODECLIB_H__ #define __CODECLIB_H__ +#include +#include #include "config.h" #include "codecs.h" -#include #include "mdct.h" #include "fft.h" @@ -44,6 +45,7 @@ extern unsigned char* filebuf; /* The rest of the MP3 buffer #define calloc(x,y) codec_calloc(x,y) #define realloc(x,y) codec_realloc(x,y) #define free(x) codec_free(x) +#undef alloca #define alloca(x) __builtin_alloca(x) void* codec_malloc(size_t size); @@ -59,7 +61,11 @@ void *memmove(void *s1, const void *s2, size_t n); size_t strlen(const char *s); char *strcpy(char *dest, const char *src); char *strcat(char *dest, const char *src); -int strcmp(const char *, const char *); + +/* on some platforms strcmp() seems to be a tricky define which + * breaks if we write down strcmp's prototype */ +#undef strcmp +int strcmp(const char *s1, const char *s2); void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); diff --git a/apps/codecs/lib/tlsf/src/tlsf.c b/apps/codecs/lib/tlsf/src/tlsf.c index 6d15c3a3f6..570e472607 100644 --- a/apps/codecs/lib/tlsf/src/tlsf.c +++ b/apps/codecs/lib/tlsf/src/tlsf.c @@ -165,7 +165,7 @@ #endif #if defined(ROCKBOX) && defined(SIMULATOR) || !defined(ROCKBOX) -int printf(char*, ...); +int printf(const char* fmt, ...); #define PRINT_MSG(fmt, args...) printf(fmt, ## args) #define ERROR_MSG(fmt, args...) printf(fmt, ## args) #else diff --git a/apps/codecs/lib/tlsf/src/tlsf.h b/apps/codecs/lib/tlsf/src/tlsf.h index 5d016f4369..4feb5c42cc 100644 --- a/apps/codecs/lib/tlsf/src/tlsf.h +++ b/apps/codecs/lib/tlsf/src/tlsf.h @@ -19,7 +19,7 @@ #ifndef _TLSF_H_ #define _TLSF_H_ -#include +#include /* defines size_t */ extern size_t init_memory_pool(size_t, void *); extern size_t get_used_size(void *); diff --git a/apps/codecs/libatrac/main.c b/apps/codecs/libatrac/main.c index e0a3f8507d..30307c2946 100644 --- a/apps/codecs/libatrac/main.c +++ b/apps/codecs/libatrac/main.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c index 25e263dd60..928cad298e 100644 --- a/apps/codecs/libcook/main.c +++ b/apps/codecs/libcook/main.c @@ -19,7 +19,7 @@ * ****************************************************************************/ #include -#include +#include #include #include #include diff --git a/apps/codecs/libfaad/common.h b/apps/codecs/libfaad/common.h index 658e92f23f..01164e3746 100644 --- a/apps/codecs/libfaad/common.h +++ b/apps/codecs/libfaad/common.h @@ -185,7 +185,7 @@ typedef float float32_t; #include #ifdef HAVE_SYS_TYPES_H -# include +# include "inttypes.h" #endif #ifdef HAVE_SYS_STAT_H # include diff --git a/apps/codecs/libmad/libmad.make b/apps/codecs/libmad/libmad.make index c5b197ead8..331ee8916f 100644 --- a/apps/codecs/libmad/libmad.make +++ b/apps/codecs/libmad/libmad.make @@ -11,7 +11,7 @@ # (one for codec, one for mpegplayer) # so a little trickery is necessary -MADFLAGS = $(CODECFLAGS) -UDEBUG -DNDEBUG -O2 -I$(APPSDIR)/codecs/libmad +MADFLAGS = $(CODECFLAGS) -UDEBUG -DNDEBUG -O2 -I$(APPSDIR)/codecs/libmad -DHAVE_LIMITS_H MPEGMADFLAGS = $(MADFLAGS) -DMPEGPLAYER # libmad diff --git a/apps/codecs/libpcm/adpcm_seek.h b/apps/codecs/libpcm/adpcm_seek.h index 66ec390097..2dd3f000b1 100644 --- a/apps/codecs/libpcm/adpcm_seek.h +++ b/apps/codecs/libpcm/adpcm_seek.h @@ -21,9 +21,9 @@ #ifndef CODEC_LIBPCM_ADPCM_SEEK_H #define CODEC_LIBPCM_ADPCM_SEEK_H -#include #include #include +#include struct adpcm_data { int16_t pcmdata[2]; diff --git a/apps/codecs/libpcm/ima_adpcm_common.c b/apps/codecs/libpcm/ima_adpcm_common.c index ff5051f166..724cce31b0 100644 --- a/apps/codecs/libpcm/ima_adpcm_common.c +++ b/apps/codecs/libpcm/ima_adpcm_common.c @@ -63,7 +63,7 @@ static const int index_tables[4][16] ICONST_ATTR = { }; static int32_t pcmdata[2]; -static int8_t index[2]; +static int8_t indices[2]; static int adpcm_data_size; static uint8_t step_mask; @@ -107,7 +107,7 @@ void set_decode_parameters(int channels, int32_t *init_pcmdata, int8_t *init_ind for (ch = 0; ch < channels; ch++) { pcmdata[ch] = init_pcmdata[ch]; - index[ch] = init_index[ch]; + indices[ch] = init_index[ch]; } } @@ -121,7 +121,7 @@ int16_t create_pcmdata(int ch, uint8_t nibble) { int check_bit = 1 << step_shift; int32_t delta = 0; - int16_t step = step_table[index[ch]]; + int16_t step = step_table[indices[ch]]; do { if (nibble & check_bit) @@ -136,8 +136,8 @@ int16_t create_pcmdata(int ch, uint8_t nibble) else pcmdata[ch] += delta; - index[ch] += use_index_table[nibble & step_mask]; - CLIP(index[ch], 0, 88); + indices[ch] += use_index_table[nibble & step_mask]; + CLIP(indices[ch], 0, 88); CLIP(pcmdata[ch], -32768, 32767); @@ -150,7 +150,7 @@ int16_t create_pcmdata(int ch, uint8_t nibble) int16_t create_pcmdata_size4(int ch, uint8_t nibble) { int32_t delta; - int16_t step = step_table[index[ch]]; + int16_t step = step_table[indices[ch]]; delta = (step >> 3); if (nibble & 4) delta += step; @@ -162,8 +162,8 @@ int16_t create_pcmdata_size4(int ch, uint8_t nibble) else pcmdata[ch] += delta; - index[ch] += use_index_table[nibble & 0x07]; - CLIP(index[ch], 0, 88); + indices[ch] += use_index_table[nibble & 0x07]; + CLIP(indices[ch], 0, 88); CLIP(pcmdata[ch], -32768, 32767); diff --git a/apps/codecs/libpcm/ima_adpcm_common.h b/apps/codecs/libpcm/ima_adpcm_common.h index 0a2129bdf2..46fd6083ec 100644 --- a/apps/codecs/libpcm/ima_adpcm_common.h +++ b/apps/codecs/libpcm/ima_adpcm_common.h @@ -21,7 +21,6 @@ #ifndef CODEC_LIBPCM_IMA_ADPCM_COMMON_H #define CODEC_LIBPCM_IMA_ADPCM_COMMON_H -#include #include #include diff --git a/apps/codecs/libpcm/pcm_common.h b/apps/codecs/libpcm/pcm_common.h index 91c3ab7f1e..90e29c98ee 100644 --- a/apps/codecs/libpcm/pcm_common.h +++ b/apps/codecs/libpcm/pcm_common.h @@ -21,9 +21,9 @@ #ifndef CODEC_LIBPCM_PCM_COMMON_H #define CODEC_LIBPCM_PCM_COMMON_H -#include #include #include +#include /* decoded pcm sample depth (sample 28bit + sign 1bit) */ #define PCM_OUTPUT_DEPTH 29 diff --git a/apps/codecs/librm/rm.c b/apps/codecs/librm/rm.c index a179688e7a..b543da50d7 100644 --- a/apps/codecs/librm/rm.c +++ b/apps/codecs/librm/rm.c @@ -32,7 +32,7 @@ #ifdef TEST #include #include -#include +#include "inttypes.h" #include int filesize(int fd) diff --git a/apps/codecs/libtremor/config-tremor.h b/apps/codecs/libtremor/config-tremor.h index 8a68ce325f..abed96533b 100644 --- a/apps/codecs/libtremor/config-tremor.h +++ b/apps/codecs/libtremor/config-tremor.h @@ -7,6 +7,7 @@ #define _ARM_ASSEM_ #endif +#ifndef BYTE_ORDER #ifdef ROCKBOX_BIG_ENDIAN #define BIG_ENDIAN 1 #define LITTLE_ENDIAN 0 @@ -16,6 +17,7 @@ #define LITTLE_ENDIAN 1 #define BIG_ENDIAN 0 #endif +#endif #ifndef ICODE_ATTR_TREMOR_MDCT #define ICODE_ATTR_TREMOR_MDCT ICODE_ATTR diff --git a/apps/codecs/libtremor/ctype.c b/apps/codecs/libtremor/ctype.c index 10468bc27d..359be61e5a 100644 --- a/apps/codecs/libtremor/ctype.c +++ b/apps/codecs/libtremor/ctype.c @@ -1 +1,3 @@ -#include "common/ctype.c" +#ifndef SIMULATOR +#include "libc/ctype.c" +#endif diff --git a/apps/codecs/libwavpack/words.c b/apps/codecs/libwavpack/words.c index 6da716119c..c3ae50dcf4 100644 --- a/apps/codecs/libwavpack/words.c +++ b/apps/codecs/libwavpack/words.c @@ -141,7 +141,7 @@ void init_words (WavpackStream *wps) CLEAR (wps->w); } -static int mylog2 (unsigned int32_t avalue); +static int mylog2 (uint32_t avalue); // Read the median log2 values from the specifed metadata structure, convert // them back to 32-bit unsigned values and store them. If length is not @@ -553,7 +553,7 @@ void send_words (int32_t *buffer, int nsamples, uint32_t flags, if (sign) value = ~value; - if ((unsigned int32_t) value < GET_MED (0)) { + if ((uint32_t) value < GET_MED (0)) { ones_count = low = 0; high = GET_MED (0) - 1; DEC_MED0 (); @@ -709,7 +709,7 @@ void flush_word (struct words_data *w, Bitstream *bs) // This function returns the log2 for the specified 32-bit unsigned value. // The maximum value allowed is about 0xff800000 and returns 8447. -static int mylog2 (unsigned int32_t avalue) +static int mylog2 (uint32_t avalue) { int dbits; diff --git a/apps/cuesheet.c b/apps/cuesheet.c index cb3ba6569a..c75ea65334 100644 --- a/apps/cuesheet.c +++ b/apps/cuesheet.c @@ -28,7 +28,6 @@ #include "audio.h" #include "kernel.h" #include "logf.h" -#include "sprintf.h" #include "misc.h" #include "screens.h" #include "list.h" diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 054bfd4c99..e8104f74dc 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -28,7 +28,6 @@ #include "menu.h" #include "debug_menu.h" #include "kernel.h" -#include "sprintf.h" #include "structec.h" #include "action.h" #include "debug.h" diff --git a/apps/enc_config.c b/apps/enc_config.c index 48ad18f771..ca8aebb451 100644 --- a/apps/enc_config.c +++ b/apps/enc_config.c @@ -19,7 +19,6 @@ * ****************************************************************************/ #include -#include #include #include #include "config.h" diff --git a/apps/filetree.c b/apps/filetree.c index e3977e5a44..9ff48dc451 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -38,7 +38,6 @@ #include "screens.h" #include "plugin.h" #include "rolo.h" -#include "sprintf.h" #include "splash.h" #include "cuesheet.h" #include "filetree.h" diff --git a/apps/filetypes.c b/apps/filetypes.c index 4aefef1f0d..3c8f4b9a39 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -26,7 +26,6 @@ #include "string.h" #include -#include "sprintf.h" #include "settings.h" #include "debug.h" #include "lang.h" diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index 10616c9df4..0da67c7c1e 100644 --- a/apps/gui/bitmap/list.c +++ b/apps/gui/bitmap/list.c @@ -25,7 +25,6 @@ #include "lcd.h" #include "font.h" #include "button.h" -#include "sprintf.h" #include "string.h" #include "settings.h" #include "kernel.h" diff --git a/apps/gui/charcell/list.c b/apps/gui/charcell/list.c index f36d3c9f7d..8eebfe7fa1 100644 --- a/apps/gui/charcell/list.c +++ b/apps/gui/charcell/list.c @@ -25,7 +25,6 @@ #include "lcd.h" #include "font.h" #include "button.h" -#include "sprintf.h" #include "string.h" #include "settings.h" #include "kernel.h" diff --git a/apps/gui/list.c b/apps/gui/list.c index 11a4c36015..de76310e0b 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -19,11 +19,11 @@ * ****************************************************************************/ +#include #include "config.h" #include "lcd.h" #include "font.h" #include "button.h" -#include "sprintf.h" #include "string.h" #include "settings.h" #include "kernel.h" diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 71a28cb520..feed1dc2db 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -20,10 +20,9 @@ * ****************************************************************************/ #include -#include +#include "string-extra.h" #include "config.h" #include "option_select.h" -#include "sprintf.h" #include "kernel.h" #include "lang.h" #include "talk.h" diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c index 77b5739be1..a0058724ec 100644 --- a/apps/gui/pitchscreen.c +++ b/apps/gui/pitchscreen.c @@ -23,9 +23,8 @@ #include #include #include -#include /* for ABS() */ +#include /* for abs() */ #include "config.h" -#include "sprintf.h" #include "action.h" #include "dsp.h" #include "sound.h" @@ -248,10 +247,10 @@ static void pitchscreen_draw(struct screen *display, int max_lines, /* Pitch:XXX.X% */ if(global_settings.pitch_mode_semitone) { - snprintf(buf, sizeof(buf), "%s: %s%ld.%02ld", str(LANG_PITCH), + snprintf(buf, sizeof(buf), "%s: %s%d.%02d", str(LANG_PITCH), semitone >= 0 ? "+" : "-", - ABS(semitone / PITCH_SPEED_PRECISION), - ABS((semitone % PITCH_SPEED_PRECISION) / + abs(semitone / PITCH_SPEED_PRECISION), + abs((semitone % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 100)) ); } @@ -290,10 +289,10 @@ static void pitchscreen_draw(struct screen *display, int max_lines, { if(global_settings.pitch_mode_semitone) { - snprintf(buf, sizeof(buf), "%s%ld.%02ld", + snprintf(buf, sizeof(buf), "%s%d.%02d", semitone >= 0 ? "+" : "-", - ABS(semitone / PITCH_SPEED_PRECISION), - ABS((semitone % PITCH_SPEED_PRECISION) / + abs(semitone / PITCH_SPEED_PRECISION), + abs((semitone % PITCH_SPEED_PRECISION) / (PITCH_SPEED_PRECISION / 100)) ); } diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c index fd786a7882..77de8bdc1a 100644 --- a/apps/gui/skin_engine/skin_backdrops.c +++ b/apps/gui/skin_engine/skin_backdrops.c @@ -21,9 +21,8 @@ #include "config.h" #include -#include #include - +#include "string-extra.h" #include "settings.h" #include "skin_buffer.h" #include "wps_internals.h" diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c index 0d7824aaf6..d3169be43a 100644 --- a/apps/gui/skin_engine/skin_display.c +++ b/apps/gui/skin_engine/skin_display.c @@ -21,7 +21,7 @@ ****************************************************************************/ #include "config.h" #include -#include +#include "string-extra.h" #include "misc.h" #include "font.h" #include "system.h" diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 4ee8c74cdd..6e5a2eae85 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -21,7 +21,7 @@ ****************************************************************************/ #include "font.h" #include -#include +#include "string-extra.h" #include #include "action.h" #include "system.h" @@ -247,7 +247,7 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, { *intval = limit * elapsed / length + 1; } - snprintf(buf, buf_size, "%d", 100 * elapsed / length); + snprintf(buf, buf_size, "%lu", 100 * elapsed / length); return buf; @@ -269,7 +269,7 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, if ((id3->frequency % 1000) < 100) snprintf(buf, buf_size, "%ld", id3->frequency / 1000); else - snprintf(buf, buf_size, "%ld.%d", + snprintf(buf, buf_size, "%ld.%lu", id3->frequency / 1000, (id3->frequency % 1000) / 100); return buf; @@ -302,12 +302,12 @@ const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, case WPS_TOKEN_DATABASE_RATING: if (intval) *intval = id3->rating + 1; - snprintf(buf, buf_size, "%ld", id3->rating); + snprintf(buf, buf_size, "%d", id3->rating); return buf; case WPS_TOKEN_DATABASE_AUTOSCORE: if (intval) *intval = id3->score + 1; - snprintf(buf, buf_size, "%ld", id3->score); + snprintf(buf, buf_size, "%d", id3->score); return buf; #endif @@ -1064,7 +1064,7 @@ const char *get_token_value(struct gui_wps *gwps, break;) } } - snprintf(buf, buf_size, "%d.%1d", samprk/1000,samprk%1000); + snprintf(buf, buf_size, "%lu.%1lu", samprk/1000,samprk%1000); #else /* HWCODEC */ static const char * const freq_strings[] = @@ -1164,7 +1164,7 @@ const char *get_token_value(struct gui_wps *gwps, #endif *intval = global_settings.mp3_enc_config.bitrate+1; } - snprintf(buf, buf_size, "%d", global_settings.mp3_enc_config.bitrate+1); + snprintf(buf, buf_size, "%lu", global_settings.mp3_enc_config.bitrate+1); return buf; } else diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c index bc5570ee4e..901615d98a 100644 --- a/apps/gui/statusbar.c +++ b/apps/gui/statusbar.c @@ -19,11 +19,11 @@ * ****************************************************************************/ +#include #include "config.h" #include "font.h" #include "kernel.h" #include "string.h" /* for memcmp oO*/ -#include "sprintf.h" #include "sound.h" #include "settings.h" #include "viewport.h" diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c index 019aec61ff..9895defc2b 100644 --- a/apps/gui/usb_screen.c +++ b/apps/gui/usb_screen.c @@ -30,7 +30,6 @@ #include "usb_core.h" #ifdef USB_ENABLE_HID #include "usb_keymaps.h" -#include "sprintf.h" #endif #endif #include "settings.h" diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index 03f004ba87..7d128188c3 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c @@ -41,7 +41,6 @@ /* all below isn't needed for pc tools (i.e. checkwps/wps editor) * only viewport_parse_viewport() is */ #ifndef __PCTOOL__ -#include "sprintf.h" #include "string.h" #include "kernel.h" #include "system.h" diff --git a/apps/gui/wps.c b/apps/gui/wps.c index afd7f3f2d0..916ca2cbcf 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c @@ -31,7 +31,6 @@ #include "action.h" #include "kernel.h" #include "filetypes.h" -#include "sprintf.h" #include "settings.h" #include "skin_engine/skin_engine.h" #include "mp3_playback.h" diff --git a/apps/main.c b/apps/main.c index 5b9ecdad79..b043dacede 100644 --- a/apps/main.c +++ b/apps/main.c @@ -49,7 +49,6 @@ #include "status.h" #include "debug_menu.h" #include "version.h" -#include "sprintf.h" #include "font.h" #include "language.h" #include "wps.h" diff --git a/apps/menus/eq_menu.c b/apps/menus/eq_menu.c index 16d5b82c91..066787a896 100644 --- a/apps/menus/eq_menu.c +++ b/apps/menus/eq_menu.c @@ -35,7 +35,6 @@ #include "icons.h" #include "font.h" #include "lang.h" -#include "sprintf.h" #include "talk.h" #include "misc.h" #include "sound.h" diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index 800918b755..daea1ea8fc 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -38,7 +38,6 @@ #include "scrollbar.h" #endif #include "lang.h" -#include "sprintf.h" #include "talk.h" #include "misc.h" #include "sound.h" diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index db2ad78fdc..1007d2aeb0 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -35,7 +35,6 @@ #include "usb.h" #include "splash.h" #include "talk.h" -#include "sprintf.h" #include "powermgmt.h" #if CONFIG_CODEC == SWCODEC #include "playback.h" diff --git a/apps/menus/time_menu.c b/apps/menus/time_menu.c index 597f7e0c3a..a529837b07 100644 --- a/apps/menus/time_menu.c +++ b/apps/menus/time_menu.c @@ -22,9 +22,9 @@ #include #include #include +#include #include "config.h" #include "string.h" -#include "sprintf.h" #include "lang.h" #include "action.h" #include "settings.h" @@ -201,7 +201,7 @@ static void draw_timedate(struct viewport *vp, struct screen *display) } -static struct viewport clock[NB_SCREENS], menu[NB_SCREENS]; +static struct viewport clock_vps[NB_SCREENS], menu[NB_SCREENS]; static bool menu_was_pressed; static int time_menu_callback(int action, const struct menu_item_ex *this_item) @@ -233,7 +233,7 @@ static int time_menu_callback(int action, { last_redraw = current_tick; FOR_NB_SCREENS(i) - draw_timedate(&clock[i], &screens[i]); + draw_timedate(&clock_vps[i], &screens[i]); } return action; } @@ -257,30 +257,30 @@ int time_screen(void* ignored) FOR_NB_SCREENS(i) { - viewport_set_defaults(&clock[i], i); + viewport_set_defaults(&clock_vps[i], i); #ifdef HAVE_BUTTONBAR if (global_settings.buttonbar) { - clock[i].height -= BUTTONBAR_HEIGHT; + clock_vps[i].height -= BUTTONBAR_HEIGHT; } #endif - nb_lines = viewport_get_nb_lines(&clock[i]); + nb_lines = viewport_get_nb_lines(&clock_vps[i]); - menu[i] = clock[i]; + menu[i] = clock_vps[i]; /* force time to be drawn centered */ - clock[i].flags |= VP_FLAG_ALIGN_CENTER; + clock_vps[i].flags |= VP_FLAG_ALIGN_CENTER; - font_h = font_get(clock[i].font)->height; + font_h = font_get(clock_vps[i].font)->height; nb_lines -= 2; /* at least 2 lines for menu */ if (nb_lines > 4) nb_lines = 4; if (nb_lines >= 2) - clock[i].height = nb_lines*font_h; - else /* disable the clock drawing */ - clock[i].height = 0; - menu[i].y += clock[i].height; - menu[i].height -= clock[i].height; - draw_timedate(&clock[i], &screens[i]); + clock_vps[i].height = nb_lines*font_h; + else /* disable the clock_vps drawing */ + clock_vps[i].height = 0; + menu[i].y += clock_vps[i].height; + menu[i].height -= clock_vps[i].height; + draw_timedate(&clock_vps[i], &screens[i]); } ret = do_menu(&time_menu, NULL, menu, false); diff --git a/apps/metadata.c b/apps/metadata.c index 1dfc3763c6..2a49392193 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -19,10 +19,9 @@ * ****************************************************************************/ #include -#include #include #include -#include +#include "string-extra.h" #include "debug.h" #include "logf.h" diff --git a/apps/metadata/metadata_common.c b/apps/metadata/metadata_common.c index fd1cd553e8..e1ef9a0d62 100644 --- a/apps/metadata/metadata_common.c +++ b/apps/metadata/metadata_common.c @@ -19,7 +19,7 @@ * ****************************************************************************/ #include -#include +#include "string-extra.h" #include #include #include diff --git a/apps/metadata/metadata_common.h b/apps/metadata/metadata_common.h index 3962e2cd17..b2c76afb45 100644 --- a/apps/metadata/metadata_common.h +++ b/apps/metadata/metadata_common.h @@ -18,6 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ +#include #include "metadata.h" #ifdef ROCKBOX_BIG_ENDIAN diff --git a/apps/metadata/mp3.c b/apps/metadata/mp3.c index 84c565b8be..49d5c7362e 100644 --- a/apps/metadata/mp3.c +++ b/apps/metadata/mp3.c @@ -30,11 +30,11 @@ #include #include -#include #include #include #include -#include +#include +#include "string-extra.h" #include "config.h" #include "file.h" #include "logf.h" diff --git a/apps/metadata/smaf.c b/apps/metadata/smaf.c index ca5b690e0b..fa12c99fb9 100644 --- a/apps/metadata/smaf.c +++ b/apps/metadata/smaf.c @@ -18,9 +18,9 @@ * KIND, either express or implied. * ****************************************************************************/ -#include #include +#include "string-extra.h" #include "system.h" #include "metadata.h" #include "metadata_common.h" diff --git a/apps/misc.c b/apps/misc.c index 22f21d2106..3dfc2892ca 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -20,17 +20,15 @@ ****************************************************************************/ #include #include -#include +#include +#include #include +#include "string-extra.h" #include "config.h" #include "misc.h" #include "lcd.h" #include "file.h" -#ifdef __PCTOOL__ -#include -#include -#else -#include "sprintf.h" +#ifndef __PCTOOL__ #include "lang.h" #include "dir.h" #include "lcd-remote.h" diff --git a/apps/onplay.c b/apps/onplay.c index 617f523879..009b375871 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -25,7 +25,6 @@ #include #include "debug.h" -#include "sprintf.h" #include "lcd.h" #include "dir.h" #include "file.h" diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c index e657f36697..1c6dc9bb0d 100644 --- a/apps/player/keyboard.c +++ b/apps/player/keyboard.c @@ -23,7 +23,6 @@ #include "kernel.h" #include "system.h" #include "version.h" -#include "sprintf.h" #include #include "settings.h" #include "statusbar.h" diff --git a/apps/playlist.c b/apps/playlist.c index da801968ef..21e1eed083 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -68,15 +68,14 @@ */ #include -#include -#include -#include +#include +#include +#include "string-extra.h" #include "playlist.h" #include "ata_idle_notify.h" #include "file.h" #include "action.h" #include "dir.h" -#include "sprintf.h" #include "debug.h" #include "audio.h" #include "lcd.h" diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 4f3c8af231..f9a43da411 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include "string-extra.h" #include "action.h" #include "dir.h" #include "file.h" @@ -36,7 +36,6 @@ #include "playlist.h" #include "settings.h" #include "splash.h" -#include "sprintf.h" #include "tree.h" #include "yesno.h" #include "filetypes.h" diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index e2be36ce5d..e0ab3bb9bd 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -24,7 +24,6 @@ * multi-screen support, rewrote a lot of code */ #include -#include #include "playlist.h" #include "audio.h" #include "screens.h" diff --git a/apps/plugin.c b/apps/plugin.c index baf9b60eb8..8a32a159b4 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -21,7 +21,6 @@ #include "plugin.h" #include #include -#include #include #include "debug.h" #include "i2c.h" diff --git a/apps/plugin.h b/apps/plugin.h index 5f594e6cf5..e6e41e1a3f 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -32,11 +32,13 @@ #endif #include +#include #include #include #include #include #include +#include "string-extra.h" char* strncpy(char *, const char *, size_t); void* plugin_get_buffer(size_t *buffer_size); @@ -111,6 +113,11 @@ void* plugin_get_buffer(size_t *buffer_size); #include "usbstack/usb_hid_usage_tables.h" #endif + +/* on some platforms strcmp() seems to be a tricky define which + * breaks if we write down strcmp's prototype */ +#undef strcmp + #ifdef PLUGIN #if defined(DEBUG) || defined(SIMULATOR) @@ -529,7 +536,7 @@ struct plugin_api { /* strings and memory */ int (*snprintf)(char *buf, size_t size, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); - int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap); + int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list ap); char* (*strcpy)(char *dst, const char *src); size_t (*strlcpy)(char *dst, const char *src, size_t length); size_t (*strlen)(const char *str); diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c index 942f031890..c19d6bbc5b 100644 --- a/apps/plugins/calculator.c +++ b/apps/plugins/calculator.c @@ -102,6 +102,9 @@ PLUGIN_HEADER #define X_5_POS (X_4_POS + REC_WIDTH) /* x5 = 110, column 111 left blank */ #define SIGN(x) ((x)<0?-1:1) +#ifndef ABS +#define ABS(a) (((a) < 0) ? -(a) : (a)) +#endif /* variable button definitions */ #if CONFIG_KEYPAD == RECORDER_PAD diff --git a/apps/plugins/doom/d_deh.c b/apps/plugins/doom/d_deh.c index d3f7496885..82426c1bab 100644 --- a/apps/plugins/doom/d_deh.c +++ b/apps/plugins/doom/d_deh.c @@ -44,7 +44,7 @@ #include "d_think.h" #include "w_wad.h" -#include "sscanf.h" +#include /* sscanf */ #include "rockmacros.h" #define TRUE 1 diff --git a/apps/plugins/doom/doom.make b/apps/plugins/doom/doom.make index bdc32230eb..54a63eb707 100644 --- a/apps/plugins/doom/doom.make +++ b/apps/plugins/doom/doom.make @@ -13,7 +13,7 @@ DOOMBUILDDIR := $(BUILDDIR)/apps/plugins/doom ROCKS += $(DOOMBUILDDIR)/doom.rock DOOM_SRC := $(call preprocess, $(DOOMSRCDIR)/SOURCES) -DOOM_SRC += $(ROOTDIR)/firmware/common/sscanf.c +DOOM_SRC += $(ROOTDIR)/firmware/libc/sscanf.c DOOM_OBJ := $(call c2obj, $(DOOM_SRC)) # add source files to OTHER_SRC to get automatic dependencies diff --git a/apps/plugins/doom/rockmacros.h b/apps/plugins/doom/rockmacros.h index e066fe861c..89c943622a 100644 --- a/apps/plugins/doom/rockmacros.h +++ b/apps/plugins/doom/rockmacros.h @@ -33,9 +33,13 @@ extern bool doomexit; int printf(const char *fmt, ...); int fileexists(const char * fname); char *my_strtok( char * s, const char * delim ); +#undef alloca #define alloca __builtin_alloca -#define fdprintf(...) rb->fdprintf(__VA_ARGS__) +#undef fdprintf +#define fdprintf(...) rb->fdprintf(__VA_ARGS__) +#undef vsnprintf #define vsnprintf(...) rb->vsnprintf(__VA_ARGS__) +#undef read_line #define read_line(a,b,c) rb->read_line((a),(b),(c)) #ifdef SIMULATOR @@ -52,19 +56,33 @@ int my_close(int id); #define filesize(a) rb->filesize((a)) #define read(a,b,c) rb->read((a),(b),(c)) #define write(a,b,c) rb->write((a),(b),(c)) +#undef strtok #define strtok(a,b) my_strtok((a),(b)) +#undef strcat #define strcat(a,b) rb->strcat((a),(b)) +#undef memset #define memset(a,b,c) rb->memset((a),(b),(c)) +#undef memmove #define memmove(a,b,c) rb->memmove((a),(b),(c)) +#undef memcmp #define memcmp(a,b,c) rb->memcmp((a),(b),(c)) +#undef memchr #define memchr(a,b,c) rb->memchr((a),(b),(c)) +#undef strcpy #define strcpy(a,b) rb->strcpy((a),(b)) +#undef strlen #define strlen(a) rb->strlen((a)) +#undef strcmp #define strcmp(a,b) rb->strcmp((a),(b)) +#undef strncmp #define strncmp(a,b,c) rb->strncmp((a),(b),(c)) +#undef strchr #define strchr(a,b) rb->strchr((a),(b)) +#undef strrchr #define strrchr(a,b) rb->strrchr((a),(b)) +#undef strcasecmp #define strcasecmp(a,b) rb->strcasecmp((a),(b)) +#undef strncasecmp #define strncasecmp(a,b,c) rb->strncasecmp((a),(b),(c)) #define srand(a) rb->srand((a)) #define rand() rb->rand() diff --git a/apps/plugins/frotz/frotz.c b/apps/plugins/frotz/frotz.c index 96029b85cb..f64431f14e 100644 --- a/apps/plugins/frotz/frotz.c +++ b/apps/plugins/frotz/frotz.c @@ -285,14 +285,14 @@ void os_beep(int volume) static unsigned char unget_buf; static int unget_file; -int ungetc(int c, int f) +int frotz_ungetc(int c, int f) { unget_file = f; unget_buf = c; return c; } -int fgetc(int f) +int frotz_fgetc(int f) { unsigned char cb; if (unget_file == f) @@ -305,7 +305,7 @@ int fgetc(int f) return cb; } -int fputc(int c, int f) +int frotz_fputc(int c, int f) { unsigned char cb = c; if (rb->write(f, &cb, 1) != 1) diff --git a/apps/plugins/frotz/frotzplugin.h b/apps/plugins/frotz/frotzplugin.h index 8caddb470d..1a52bdb913 100644 --- a/apps/plugins/frotz/frotzplugin.h +++ b/apps/plugins/frotz/frotzplugin.h @@ -37,9 +37,12 @@ /* * we need functions for character io */ -extern int ungetc(int c, int f); -extern int fgetc(int f); -extern int fputc(int c, int f); +extern int frotz_ungetc(int c, int f); +#define ungetc frotz_ungetc +extern int frotz_fgetc(int f); +#define fgetc frotz_fgetc +extern int frotz_fputc(int c, int f); +#define fputc frotz_fputc /* * this is used instead of os_read_key for more prompts and the like diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c index 310b08d990..c398af70c5 100644 --- a/apps/plugins/imageviewer/png/png.c +++ b/apps/plugins/imageviewer/png/png.c @@ -1359,7 +1359,7 @@ int load_image(char *filename, struct image_info *info, } else { if (!running_slideshow) { - rb->snprintf(print, sizeof(print), "loading %lu bytes", image_size); + rb->snprintf(print, sizeof(print), "loading %zu bytes", image_size); rb->lcd_puts(0, 1, print); rb->lcd_update(); } diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c index 3e5c98e2a3..851487cf9a 100644 --- a/apps/plugins/invadrox.c +++ b/apps/plugins/invadrox.c @@ -81,6 +81,10 @@ PLUGIN_HEADER #define DBG(format, arg...) {} #endif +#ifndef ABS +#define ABS(a) (((a) < 0) ? -(a) : (a)) +#endif + #if CONFIG_KEYPAD == IRIVER_H100_PAD #define QUIT BUTTON_OFF diff --git a/apps/plugins/lib/buflib.c b/apps/plugins/lib/buflib.c index 5d03ca4bb9..930e49d02e 100644 --- a/apps/plugins/lib/buflib.c +++ b/apps/plugins/lib/buflib.c @@ -23,8 +23,8 @@ * ****************************************************************************/ +#include /* for abs() */ #include "buflib.h" - /* The main goal of this design is fast fetching of the pointer for a handle. * For that reason, the handles are stored in a table at the end of the buffer * with a fixed address, so that returning the pointer for a handle is a simple @@ -311,7 +311,7 @@ buflib_free(struct buflib_context *ctx, int handle_num) while (next_block < freed_block) { block = next_block; - next_block += ABS(block->val); + next_block += abs(block->val); } /* If next_block == block, the above loop didn't go anywhere. If it did, * and the block before this one is empty, we can combine them. diff --git a/apps/plugins/lib/jhash.h b/apps/plugins/lib/jhash.h index 97d1ac3d93..7699e24587 100644 --- a/apps/plugins/lib/jhash.h +++ b/apps/plugins/lib/jhash.h @@ -24,8 +24,8 @@ #ifndef _LIB_JHASH_H_ #define _LIB_JHASH_H_ #include /* defines uint32_t etc */ -#include -#include +#include /* size_t */ +#include "plugin.h" /* hashw() -- hash an array of uint32_t into a 32-bit value diff --git a/apps/plugins/lib/strncpy.c b/apps/plugins/lib/strncpy.c index 7c1973ba66..f80e759969 100644 --- a/apps/plugins/lib/strncpy.c +++ b/apps/plugins/lib/strncpy.c @@ -39,6 +39,7 @@ QUICKREF #include #include +#include "plugin.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ diff --git a/apps/plugins/lua/gmtime.c b/apps/plugins/lua/gmtime.c index f13c855de8..deb24e08c9 100644 --- a/apps/plugins/lua/gmtime.c +++ b/apps/plugins/lua/gmtime.c @@ -20,7 +20,7 @@ const short __spm[13] = (31+28+31+30+31+30+31+31+30+31+30+31), }; -int __isleap(int year) { +static inline int isleap(int year) { /* every fourth year is a leap year except for century years that are * not divisible by 400. */ /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ @@ -36,7 +36,7 @@ struct tm *gmtime(const time_t *timep) { work=*timep/(SPD); r.tm_wday=(4+work)%7; for (i=1970; ; ++i) { - register time_t k=__isleap(i)?366:365; + register time_t k=isleap(i)?366:365; if (work>=k) work-=k; else @@ -46,7 +46,7 @@ struct tm *gmtime(const time_t *timep) { r.tm_yday=work; r.tm_mday=1; - if (__isleap(i) && (work>58)) { + if (isleap(i) && (work>58)) { if (work==59) r.tm_mday=2; /* 29.2. */ work-=1; } diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index b225014fce..2c685f2e4b 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -450,6 +450,8 @@ static int midimain(const void * filename) enum plugin_status plugin_start(const void* parameter) { int retval; + PLUGINLIB_EXIT_INIT; + PLUGIN_IRAM_INIT(rb) if (parameter == NULL) diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c index f1b6668be2..87e0f9d9a4 100644 --- a/apps/plugins/midi/midiutil.c +++ b/apps/plugins/midi/midiutil.c @@ -163,8 +163,3 @@ int printf(const char *fmt, ...) return 1; } -void exit(int code) -{ - code = code; /* Stub function, kill warning for now */ -} - diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h index f984e71aff..b1ed6569b7 100644 --- a/apps/plugins/midi/midiutil.h +++ b/apps/plugins/midi/midiutil.h @@ -21,6 +21,8 @@ #define FRACTSIZE 12 +#include "lib/pluginlib_exit.h" + #define BUF_SIZE 16384 /* 64 kB output buffers */ #define NBUF 2 @@ -145,7 +147,6 @@ int readFourBytes(int file); int readVarData(int file); int eof(int fd); unsigned char * readData(int file, int len); -void exit(int code); #define malloc(n) my_malloc(n) void * my_malloc(int size); diff --git a/apps/plugins/mpegplayer/disk_buf.c b/apps/plugins/mpegplayer/disk_buf.c index 4f37bfa5bf..59d4816fb4 100644 --- a/apps/plugins/mpegplayer/disk_buf.c +++ b/apps/plugins/mpegplayer/disk_buf.c @@ -855,7 +855,7 @@ bool disk_buf_init(void) disk_buf.pos_last = 0; disk_buf.low_wm = DISK_BUF_LOW_WATERMARK; - disk_buf.start = mpeg_malloc_all(&disk_buf.size, MPEG_ALLOC_DISKBUF); + disk_buf.start = mpeg_malloc_all((size_t*)&disk_buf.size, MPEG_ALLOC_DISKBUF); if (disk_buf.start == NULL) return false; diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index d5e7a10cdc..f7bb790dc1 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c @@ -23,7 +23,7 @@ PLUGIN_HEADER -static bool abort; +static bool cancel; static int fd; static int dirs_count; static int lasttick; @@ -70,7 +70,7 @@ void traversedir(char* location, char* name) if (dir) { entry = rb->readdir(dir); while (entry) { - if (abort) + if (cancel) break; /* Skip .. and . */ if (entry->d_name[0] == '.') @@ -113,7 +113,7 @@ void traversedir(char* location, char* name) lasttick = *rb->current_tick; if (rb->action_userabort(TIMEOUT_NOBLOCK)) { - abort = true; + cancel = true; break; } } @@ -213,7 +213,7 @@ bool custom_dir(void) void generate(void) { dirs_count = 0; - abort = false; + cancel = false; fd = rb->open(RFA_FILE,O_CREAT|O_WRONLY, 0666); rb->write(fd,&dirs_count,sizeof(int)); if (fd < 0) @@ -621,7 +621,7 @@ enum plugin_status plugin_start(const void* parameter) { (void)parameter; - abort = false; + cancel = false; return main_menu(); } diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index 2f6c3102ff..e081a81d18 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c @@ -158,7 +158,7 @@ static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) { munge_name(name_buf, strlen(name_buf)); /* glom the whole mess together */ - snprintf(buf, bufsiz, "%s/%s-%ld.rbs", STATE_DIR, name_buf, slot_id + 1); + snprintf(buf, bufsiz, "%s/%s-%zud.rbs", STATE_DIR, name_buf, slot_id + 1); } /* @@ -253,17 +253,17 @@ static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) { if (read(fd, buf, 20) > 0) { buf[20] = '\0'; - snprintf(info_buf, info_bufsiz, "%ld. %s", slot_id + 1, buf); + snprintf(info_buf, info_bufsiz, "%zud. %s", slot_id + 1, buf); } else - snprintf(info_buf, info_bufsiz, "%ld. ERROR", slot_id + 1); + snprintf(info_buf, info_bufsiz, "%zud. ERROR", slot_id + 1); close(fd); } else { /* if we couldn't open the file, then the slot is empty */ - snprintf(info_buf, info_bufsiz, "%ld. %s", slot_id + 1, ""); + snprintf(info_buf, info_bufsiz, "%zu. %s", slot_id + 1, ""); } } diff --git a/apps/plugins/rockboy/rockboy.make b/apps/plugins/rockboy/rockboy.make index ca0ed17a0a..81e9a1f798 100644 --- a/apps/plugins/rockboy/rockboy.make +++ b/apps/plugins/rockboy/rockboy.make @@ -11,7 +11,7 @@ ROCKBOY_SRCDIR = $(APPSDIR)/plugins/rockboy ROCKBOY_OBJDIR = $(BUILDDIR)/apps/plugins/rockboy ROCKBOY_SRC := $(call preprocess, $(ROCKBOY_SRCDIR)/SOURCES) -ROCKBOY_SRC += $(ROOTDIR)/firmware/common/sscanf.c +ROCKBOY_SRC += $(ROOTDIR)/firmware/libc/sscanf.c ROCKBOY_OBJ := $(call c2obj, $(ROCKBOY_SRC)) OTHER_SRC += $(ROCKBOY_SRC) diff --git a/apps/plugins/rockboy/rtc.c b/apps/plugins/rockboy/rtc.c index 6f33bc4f9d..248ebc0714 100644 --- a/apps/plugins/rockboy/rtc.c +++ b/apps/plugins/rockboy/rtc.c @@ -7,7 +7,6 @@ #include "defs.h" #include "mem.h" #include "rtc-gb.h" -#include "sscanf.h" struct rtc rtc; diff --git a/apps/plugins/search.c b/apps/plugins/search.c index ba16b8821b..7edb7e229a 100644 --- a/apps/plugins/search.c +++ b/apps/plugins/search.c @@ -20,7 +20,7 @@ * ****************************************************************************/ #include "plugin.h" -#include "ctype.h" +#include PLUGIN_HEADER diff --git a/apps/plugins/shortcuts/shortcuts.h b/apps/plugins/shortcuts/shortcuts.h index bfe3540c4d..3d6c421c5a 100644 --- a/apps/plugins/shortcuts/shortcuts.h +++ b/apps/plugins/shortcuts/shortcuts.h @@ -51,7 +51,7 @@ typedef struct sc_file_s extern void *memory_buf; -extern long memory_bufsize; +extern size_t memory_bufsize; extern sc_file_t sc_file; diff --git a/apps/plugins/shortcuts/shortcuts_common.c b/apps/plugins/shortcuts/shortcuts_common.c index dee1657afc..da212a55a3 100644 --- a/apps/plugins/shortcuts/shortcuts_common.c +++ b/apps/plugins/shortcuts/shortcuts_common.c @@ -35,7 +35,7 @@ /* Memory (will be used for entries) */ void *memory_buf; -long memory_bufsize; /* Size of memory_buf in bytes */ +size_t memory_bufsize; /* Size of memory_buf in bytes */ /* The file we're processing */ diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c index eaa1055a73..3420579881 100644 --- a/apps/plugins/stats.c +++ b/apps/plugins/stats.c @@ -24,7 +24,7 @@ PLUGIN_HEADER static int files, dirs, musicfiles, largestdir; static int lasttick; -static bool abort; +static bool cancel; #if CONFIG_KEYPAD == PLAYER_PAD #define STATS_STOP BUTTON_STOP @@ -173,7 +173,7 @@ void traversedir(char* location, char* name) if (dir) { entry = rb->readdir(dir); while (entry) { - if (abort) + if (cancel) break; /* Skip .. and . */ if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, "..")) @@ -206,7 +206,7 @@ void traversedir(char* location, char* name) || button == STATS_STOP_REMOTE #endif ) { - abort = true; + cancel = true; break; } } @@ -229,14 +229,14 @@ enum plugin_status plugin_start(const void* parameter) dirs = 0; musicfiles = 0; largestdir = 0; - abort = false; + cancel = false; rb->splash(HZ, "Counting..."); update_screen(); lasttick = *rb->current_tick; traversedir("", ""); - if (abort) { + if (cancel) { rb->splash(HZ, "Aborted"); return PLUGIN_OK; } diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c index 03900884f9..3211203db9 100644 --- a/apps/plugins/wav2wv.c +++ b/apps/plugins/wav2wv.c @@ -97,8 +97,8 @@ static int32_t temp_buffer [TEMP_SAMPLES] IDATA_ATTR; static int wav2wv(const char *infile) { int in_fd, out_fd, num_chans, error = false, last_buttons; - unsigned int32_t total_bytes_read = 0, total_bytes_written = 0; - unsigned int32_t total_samples, samples_remaining; + uint32_t total_bytes_read = 0, total_bytes_written = 0; + uint32_t total_samples, samples_remaining; int32_t *input_buffer = (int32_t *) audiobuf; unsigned char *output_buffer = (unsigned char *)(audiobuf + 0x100000); char outfile[MAX_PATH]; @@ -180,7 +180,7 @@ static int wav2wv(const char *infile) wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0); for (samples_remaining = total_samples; samples_remaining;) { - unsigned int32_t samples_count, samples_to_pack, bytes_count; + uint32_t samples_count, samples_to_pack, bytes_count; int cnt, buttons; int32_t value, *lp; signed char *cp; @@ -204,7 +204,7 @@ static int wav2wv(const char *infile) cp = (signed char *) input_buffer; while (samples_to_pack) { - unsigned int32_t samples_this_pass = TEMP_SAMPLES / num_chans; + uint32_t samples_this_pass = TEMP_SAMPLES / num_chans; if (samples_this_pass > samples_to_pack) samples_this_pass = samples_to_pack; diff --git a/apps/plugins/zxbox/helpers.h b/apps/plugins/zxbox/helpers.h index ba8607d5cb..c8cb9c1554 100644 --- a/apps/plugins/zxbox/helpers.h +++ b/apps/plugins/zxbox/helpers.h @@ -7,9 +7,12 @@ extern off_t my_ftell(int); extern void *my_malloc(size_t size); +#undef getc #define getc my_getc -#define malloc my_malloc -#define ftell my_ftell +#undef putc #define putc my_putc +#undef ftell +#define ftell my_ftell +#define malloc my_malloc #endif /* HELPERS_H */ diff --git a/apps/plugins/zxbox/snapshot.c b/apps/plugins/zxbox/snapshot.c index 0b80b64497..468f46667e 100644 --- a/apps/plugins/zxbox/snapshot.c +++ b/apps/plugins/zxbox/snapshot.c @@ -18,8 +18,9 @@ * */ +#include +#include /* size_t */ #include "zxmisc.h" -#include "helpers.h" #include "spperif.h" #include "z80.h" @@ -29,9 +30,8 @@ #include "spconf.h" -#include -#include -#include +/* include this at last to avoid clashes with stdio functions */ +#include "helpers.h" #define COMPRESS_SAVE 1 diff --git a/apps/plugins/zxbox/spconf.c b/apps/plugins/zxbox/spconf.c index 728f78638c..0daabc7d77 100644 --- a/apps/plugins/zxbox/spconf.c +++ b/apps/plugins/zxbox/spconf.c @@ -17,6 +17,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ + +#include +#include +#include #include "zxmisc.h" #include "spconf_p.h" #include "interf.h" @@ -26,11 +30,7 @@ #include "snapshot.h" /* for SN_Z80 and SN_SNA */ #include "tapefile.h" /* for TAP_TAP and TAP_TZX */ #include "zxconfig.h" -#include "stdio.h" -#include "string.h" -#include "sys/types.h" #include "helpers.h" -#include "ctype.h" extern const char *spcf_keynames_ascii[]; diff --git a/apps/plugins/zxbox/sptape.c b/apps/plugins/zxbox/sptape.c index 21f962ea28..80921a0afd 100644 --- a/apps/plugins/zxbox/sptape.c +++ b/apps/plugins/zxbox/sptape.c @@ -31,7 +31,6 @@ #include #include #include -#include #define MAXLINELEN 256 diff --git a/apps/plugins/zxbox/tapefile.c b/apps/plugins/zxbox/tapefile.c index 0e262aa0f7..92f4ea69f6 100644 --- a/apps/plugins/zxbox/tapefile.c +++ b/apps/plugins/zxbox/tapefile.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include "inttypes.h" #include "zxconfig.h" #include "helpers.h" #define max(x, y) ((x) > (y) ? (x) : (y)) diff --git a/apps/plugins/zxbox/zxmisc.h b/apps/plugins/zxbox/zxmisc.h index 4ad25a0604..904af24e3d 100644 --- a/apps/plugins/zxbox/zxmisc.h +++ b/apps/plugins/zxbox/zxmisc.h @@ -21,7 +21,7 @@ #ifndef ZXMISC_H #define ZXMISC_H -#include +#include /* size_t */ extern char *get_base_name(char *fname); extern int check_ext(const char *filename, const char *ext); diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index be787538a3..5eca713542 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c @@ -19,8 +19,7 @@ * ****************************************************************************/ -#include -#include "sprintf.h" +#include "string-extra.h" #include "system.h" #include "albumart.h" #include "metadata.h" diff --git a/apps/recorder/icons.c b/apps/recorder/icons.c index 0b48c125d1..e6c3926759 100644 --- a/apps/recorder/icons.c +++ b/apps/recorder/icons.c @@ -22,7 +22,6 @@ #include "lcd.h" #include "font.h" #include "kernel.h" -#include "sprintf.h" #include "rtc.h" #include "powermgmt.h" diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c index f75176dae1..1af65fab6c 100644 --- a/apps/recorder/jpeg_load.c +++ b/apps/recorder/jpeg_load.c @@ -856,7 +856,7 @@ static const struct idct_entry idct_tbl[] = { /* JPEG decoder implementation */ #ifdef JPEG_FROM_MEM -INLINE unsigned char *getc(struct jpeg* p_jpeg) +INLINE unsigned char *jpeg_getc(struct jpeg* p_jpeg) { if (LIKELY(p_jpeg->len)) { @@ -880,7 +880,7 @@ INLINE bool skip_bytes(struct jpeg* p_jpeg, int count) } } -INLINE void putc(struct jpeg* p_jpeg) +INLINE void jpeg_putc(struct jpeg* p_jpeg) { p_jpeg->len++; p_jpeg->data--; @@ -892,7 +892,7 @@ INLINE void fill_buf(struct jpeg* p_jpeg) p_jpeg->buf_index = 0; } -static unsigned char *getc(struct jpeg* p_jpeg) +static unsigned char *jpeg_getc(struct jpeg* p_jpeg) { if (UNLIKELY(p_jpeg->buf_left < 1)) fill_buf(p_jpeg); @@ -917,7 +917,7 @@ static bool skip_bytes(struct jpeg* p_jpeg, int count) return p_jpeg->buf_left >= 0 || skip_bytes_seek(p_jpeg); } -static void putc(struct jpeg* p_jpeg) +static void jpeg_putc(struct jpeg* p_jpeg) { p_jpeg->buf_left++; p_jpeg->buf_index--; @@ -933,14 +933,14 @@ do {\ #define e_getc(jpeg, code) \ ({ \ unsigned char *c; \ - if (UNLIKELY(!(c = getc(jpeg)))) \ + if (UNLIKELY(!(c = jpeg_getc(jpeg)))) \ return (code); \ *c; \ }) #define d_getc(jpeg, def) \ ({ \ - unsigned char *cp = getc(jpeg); \ + unsigned char *cp = jpeg_getc(jpeg); \ unsigned char c = LIKELY(cp) ? *cp : (def); \ c; \ }) @@ -958,7 +958,7 @@ static int process_markers(struct jpeg* p_jpeg) if (c != 0xFF) /* no marker? */ { JDEBUGF("Non-marker data\n"); - putc(p_jpeg); + jpeg_putc(p_jpeg); break; /* exit marker processing */ } @@ -969,7 +969,7 @@ static int process_markers(struct jpeg* p_jpeg) case 0xFF: /* Fill byte */ ret |= FILL_FF; case 0x00: /* Zero stuffed byte - entropy data */ - putc(p_jpeg); + jpeg_putc(p_jpeg); continue; case 0xC0: /* SOF Huff - Baseline DCT */ @@ -1669,7 +1669,7 @@ static void search_restart(struct jpeg *p_jpeg) return; } else - putc(p_jpeg); + jpeg_putc(p_jpeg); } } } diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index 3df3142897..f8b390d932 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c @@ -20,7 +20,7 @@ ****************************************************************************/ #include "kernel.h" #include "system.h" -#include +#include "string-extra.h" #include "font.h" #include "screens.h" #include "talk.h" diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c index 8f32a837a7..154f605898 100644 --- a/apps/recorder/peakmeter.c +++ b/apps/recorder/peakmeter.c @@ -29,7 +29,6 @@ #include "storage.h" #include "lcd.h" #include "scrollbar.h" -#include "sprintf.h" #include "button.h" #include "system.h" #include "font.h" diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 7cf91d62f7..7761f248ca 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -23,7 +23,6 @@ #include #include #include -#include "sprintf.h" #include "mas.h" #include "settings.h" #include "button.h" @@ -35,7 +34,7 @@ #include "file.h" #include "general.h" #include "errno.h" -#include "string.h" +#include "string-extra.h" #include "system.h" #include "radio.h" #include "menu.h" diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index fc527923db..0f1ff30cf5 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -1762,7 +1762,7 @@ bool recording_screen(bool no_source) draw attention */ /* Don't use language string unless agreed upon to make this method permanent - could do something in the statusbar */ - snprintf(buf, sizeof(buf), "Warning: %08X", + snprintf(buf, sizeof(buf), "Warning: %08lX", pcm_rec_get_warnings()); } else @@ -1771,7 +1771,7 @@ bool recording_screen(bool no_source) (global_settings.rec_split_method)) { dmb = dsize/1024/1024; - snprintf(buf, sizeof(buf), "%s %dMB", + snprintf(buf, sizeof(buf), "%s %luMB", str(LANG_SPLIT_SIZE), dmb); } else diff --git a/apps/replaygain.c b/apps/replaygain.c index 6ece1104b4..81f1a45ad7 100644 --- a/apps/replaygain.c +++ b/apps/replaygain.c @@ -20,13 +20,14 @@ ****************************************************************************/ #include -#include #include #include #include #include -#include -#include +#include +#include "strlcpy.h" +#include "strcasecmp.h" +#include "system.h" #include "metadata.h" #include "debug.h" #include "replaygain.h" @@ -244,7 +245,7 @@ long parse_replaygain_int(bool album, long gain, long peak, if (buffer != NULL) { - len = snprintf(buffer, length, "%d.%02d dB", gain / 512, + len = snprintf(buffer, length, "%ld.%02d dB", gain / 512, ((abs(gain) & 0x01ff) * 100 + 256) / 512); len++; } diff --git a/apps/root_menu.c b/apps/root_menu.c index 5124375490..e533c8ccc7 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -19,9 +19,9 @@ * ****************************************************************************/ #include -#include #include #include +#include "string-extra.h" #include "config.h" #include "appevents.h" #include "menu.h" diff --git a/apps/screen_access.c b/apps/screen_access.c index 871b1f8a60..df071020e5 100644 --- a/apps/screen_access.c +++ b/apps/screen_access.c @@ -19,17 +19,18 @@ * ****************************************************************************/ +#include +#include "config.h" #include #include #include -#include "backlight.h" #include #include -#include #include #include #include +#include "backlight.h" #include "screen_access.h" #include "backdrop.h" diff --git a/apps/screens.c b/apps/screens.c index 1ac6633ccc..d988a521d0 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -34,7 +34,6 @@ #include "settings.h" #include "status.h" #include "playlist.h" -#include "sprintf.h" #include "kernel.h" #include "power.h" #include "system.h" diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 5ab13f3d15..401f5b93b6 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c @@ -23,8 +23,8 @@ Audioscrobbler spec at: http://www.audioscrobbler.net/wiki/Portable_Player_Logging */ +#include #include "file.h" -#include "sprintf.h" #include "logf.h" #include "metadata.h" #include "kernel.h" diff --git a/apps/settings.c b/apps/settings.c index 690243b537..4901957263 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -33,7 +33,8 @@ #include "backlight.h" #include "audio.h" #include "talk.h" -#include "string.h" +#include "strlcpy.h" +#include "strcasestr.h" #include "rtc.h" #include "power.h" #include "ata_idle_notify.h" @@ -52,7 +53,6 @@ #include "lang.h" #include "language.h" #include "powermgmt.h" -#include "sprintf.h" #include "keyboard.h" #include "version.h" #include "sound.h" diff --git a/apps/settings_list.c b/apps/settings_list.c index 044f9e8066..34d4fc52e0 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -21,7 +21,7 @@ #include "config.h" #include -#include +#include "string-extra.h" #include "system.h" #include "storage.h" #include "lang.h" diff --git a/apps/tagcache.c b/apps/tagcache.c index ab76fbadfe..29c00ae311 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -66,7 +66,7 @@ #include "kernel.h" #include "system.h" #include "logf.h" -#include "string.h" +#include "string-extra.h" #include "usb.h" #include "metadata.h" #include "tagcache.h" @@ -1392,7 +1392,7 @@ static bool get_next(struct tagcache_search *tcs) if (TAGCACHE_IS_NUMERIC(tcs->type)) { - snprintf(buf, sizeof(buf), "%d", tcs->position); + snprintf(buf, sizeof(buf), "%ld", tcs->position); tcs->result = buf; tcs->result_len = strlen(buf) + 1; return true; @@ -3490,7 +3490,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) { if (TAGCACHE_IS_NUMERIC(j)) { - snprintf(temp, sizeof temp, "%d", idx.tag_seek[j]); + snprintf(temp, sizeof temp, "%d", (int)idx.tag_seek[j]); write_tag(clfd, tagcache_tag_to_str(j), temp); continue; } diff --git a/apps/tagtree.c b/apps/tagtree.c index ef9c9d2de7..3b13df06ab 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -27,8 +27,8 @@ /*#define LOGF_ENABLE*/ #include -#include #include +#include "string-extra.h" #include "config.h" #include "system.h" #include "kernel.h" diff --git a/apps/talk.c b/apps/talk.c index 93e76fa69e..9f31645ca5 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -25,7 +25,7 @@ #include #include -#include +#include "string-extra.h" #include "file.h" #include "buffer.h" #include "system.h" diff --git a/apps/tree.c b/apps/tree.c index db8f507146..8fbc793bda 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -19,9 +19,9 @@ * ****************************************************************************/ #include -#include #include #include +#include "string-extra.h" #include "applimits.h" #include "dir.h" @@ -32,7 +32,6 @@ #include "kernel.h" #include "usb.h" #include "tree.h" -#include "sprintf.h" #include "audio.h" #include "playlist.h" #include "menu.h" diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 7b5bba20e7..076bd2ea1b 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c @@ -18,6 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ +#include #include "system.h" #include "thread.h" #include "voice_thread.h" diff --git a/firmware/SOURCES b/firmware/SOURCES index 4e35850aa8..5253e5fde4 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -22,12 +22,30 @@ panic.c debug.c /* Common */ -common/atoi.c +#if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) +libc/errno.c +#endif /* !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) */ +libc/atoi.c +libc/ctype.c +libc/memcmp.c +libc/memchr.c +libc/qsort.c +libc/random.c +libc/sprintf.c +libc/strcat.c +libc/strchr.c +libc/strcmp.c +libc/strcpy.c +libc/strncmp.c +libc/strrchr.c +libc/strtok.c +libc/strstr.c +libc/mktime.c +common/config.c common/crc32.c #ifdef MI4_FORMAT common/crc32-mi4.c #endif -common/ctype.c #ifndef SIMULATOR common/dir_uncached.c common/file.c @@ -36,28 +54,13 @@ common/file.c common/dircache.c #endif /* HAVE_DIRCACHE */ common/disk.c -#if !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) -common/errno.c -#endif /* !defined(SIMULATOR) || defined(__MINGW32__) || defined(__CYGWIN__) */ common/filefuncs.c -common/memcmp.c -common/memchr.c -common/qsort.c -common/random.c -common/sprintf.c +common/format.c common/strcasecmp.c common/strcasestr.c -common/strcat.c -common/strchr.c -common/strcmp.c common/strnatcmp.c -common/strcpy.c -common/strncmp.c common/strlcat.c common/strlcpy.c -common/strrchr.c -common/strtok.c -common/strstr.c common/structec.c common/timefuncs.c common/unicode.c @@ -377,7 +380,7 @@ target/coldfire/i2c-coldfire.c target/arm/support-arm.S target/arm/memcpy-arm.S target/arm/memmove-arm.S -common/strlen.c +libc/strlen.c #ifndef SIMULATOR target/arm/memset-arm.S target/arm/memset16-arm.S @@ -472,9 +475,9 @@ target/arm/crt0.S #elif defined(CPU_MIPS) #undef mips /*target/mips/strlen.S*/ -common/memmove.c +libc/memmove.c common/memset16.c -common/strlen.c +libc/strlen.c target/mips/ffs-mips.S target/mips/memcpy-mips.S target/mips/memset-mips.S @@ -488,11 +491,11 @@ target/mips/ingenic_jz47xx/crt0.S #ifdef HAVE_PRIORITY_SCHEDULING common/ffs.c #endif -common/memcpy.c -common/memmove.c -common/memset.c +libc/memcpy.c +libc/memmove.c +libc/memset.c common/memset16.c -common/strlen.c +libc/strlen.c #ifndef SIMULATOR crt0.S drivers/i2c.c @@ -752,7 +755,7 @@ target/coldfire/iaudio/audio-iaudio.c #ifdef IRIVER_IFP7XX_SERIES #ifdef STUB ifp_usb_serial.c -common/sscanf.c +libc/sscanf.c #endif /* STUB */ #endif /* IRIVER_IFP7XX_SERIES */ diff --git a/firmware/common/atoi.c b/firmware/common/atoi.c deleted file mode 100644 index 3393839b27..0000000000 --- a/firmware/common/atoi.c +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Gary Czvitkovicz - * - * 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 "ctype.h" - -int atoi (const char *str) -{ - int value = 0; - int sign = 1; - - while (isspace(*str)) - { - str++; - } - - if ('-' == *str) - { - sign = -1; - str++; - } - else if ('+' == *str) - { - str++; - } - - while ('0' == *str) - { - str++; - } - - while (isdigit(*str)) - { - value = (value * 10) + (*str - '0'); - str++; - } - - return value * sign; -} diff --git a/firmware/common/config.c b/firmware/common/config.c new file mode 100644 index 0000000000..5245d34135 --- /dev/null +++ b/firmware/common/config.c @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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. + * + ****************************************************************************/ + + +/** + * This file is only there to depend on config.h. + * Use this if non-C stuff depends on config.h (e.g. language generation) + * See apps/apps.make + **/ +#include "config.h" diff --git a/firmware/common/ctype.c b/firmware/common/ctype.c deleted file mode 100644 index 6e9b4eb601..0000000000 --- a/firmware/common/ctype.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -const unsigned char _ctype_[257]={ - 0, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _S|_B, _P, _P, _P, _P, _P, _P, _P, - _P, _P, _P, _P, _P, _P, _P, _P, - _N, _N, _N, _N, _N, _N, _N, _N, - _N, _N, _P, _P, _P, _P, _P, _P, - _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _P, _P, _P, _P, _P, - _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _P, _P, _P, _P, _C -}; - diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 225ed1aff1..e642296a35 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -27,7 +27,7 @@ #include #include -#include +#include "string-extra.h" #include #include #include "debug.h" diff --git a/firmware/common/errno.c b/firmware/common/errno.c deleted file mode 100644 index 6e7bb62b51..0000000000 --- a/firmware/common/errno.c +++ /dev/null @@ -1 +0,0 @@ -int errno; diff --git a/firmware/common/format.c b/firmware/common/format.c new file mode 100644 index 0000000000..987af417da --- /dev/null +++ b/firmware/common/format.c @@ -0,0 +1,227 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Gary Czvitkovicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include +#include +#include +#include +#include "file.h" + +static const char hexdigit[] = "0123456789ABCDEF"; + +int format( + /* call 'push()' for each output letter */ + int (*push)(void *userp, unsigned char data), + void *userp, + const char *fmt, + va_list ap) +{ + char *str; + char tmpbuf[12], pad; + int ch, width, val, sign, precision; + long lval, lsign; + unsigned int uval; + unsigned long ulval; + bool ok = true; + + tmpbuf[sizeof tmpbuf - 1] = '\0'; + + while ((ch = *fmt++) != '\0' && ok) + { + if (ch == '%') + { + ch = *fmt++; + pad = ' '; + if (ch == '0') + pad = '0'; + + width = 0; + while (ch >= '0' && ch <= '9') + { + width = 10*width + ch - '0'; + ch = *fmt++; + } + + precision = 0; + if(ch == '.') + { + ch = *fmt++; + while (ch >= '0' && ch <= '9') + { + precision = 10*precision + ch - '0'; + ch = *fmt++; + } + } else { + precision = INT_MAX; + } + + str = tmpbuf + sizeof tmpbuf - 1; + switch (ch) + { + case 'c': + *--str = va_arg (ap, int); + break; + + case 's': + str = va_arg (ap, char*); + break; + + case 'd': + val = sign = va_arg (ap, int); + if (val < 0) + val = -val; + do + { + *--str = (val % 10) + '0'; + val /= 10; + } + while (val > 0); + if (sign < 0) + *--str = '-'; + break; + + case 'u': + uval = va_arg(ap, unsigned int); + do + { + *--str = (uval % 10) + '0'; + uval /= 10; + } + while (uval > 0); + break; + + case 'x': + case 'X': + pad='0'; + uval = va_arg (ap, int); + do + { + *--str = hexdigit[uval & 0xf]; + uval >>= 4; + } + while (uval); + break; + + case 'l': + ch = *fmt++; + switch(ch) { + case 'x': + case 'X': + pad='0'; + ulval = va_arg (ap, long); + do + { + *--str = hexdigit[ulval & 0xf]; + ulval >>= 4; + } + while (ulval); + break; + case 'd': + lval = lsign = va_arg (ap, long); + if (lval < 0) + lval = -lval; + do + { + *--str = (lval % 10) + '0'; + lval /= 10; + } + while (lval > 0); + if (lsign < 0) + *--str = '-'; + break; + + case 'u': + ulval = va_arg(ap, unsigned long); + do + { + *--str = (ulval % 10) + '0'; + ulval /= 10; + } + while (ulval > 0); + break; + + default: + *--str = 'l'; + *--str = ch; + } + + break; + + default: + *--str = ch; + break; + } + + if (width > 0) + { + width -= strlen (str); + while (width-- > 0 && ok) + ok=push(userp, pad); + } + while (*str != '\0' && ok && precision--) + ok=push(userp, *str++); + } + else + ok=push(userp, ch); + } + return ok; /* true means good */ +} + +struct for_fprintf { + int fd; /* where to store it */ + int bytes; /* amount stored */ +}; + +static int fprfunc(void *pr, unsigned char letter) +{ + struct for_fprintf *fpr = (struct for_fprintf *)pr; + int rc = write(fpr->fd, &letter, 1); + + if(rc > 0) { + fpr->bytes++; /* count them */ + return true; /* we are ok */ + } + + return false; /* failure */ +} + + +int fdprintf(int fd, const char *fmt, ...) +{ + bool ok; + va_list ap; + struct for_fprintf fpr; + + fpr.fd=fd; + fpr.bytes=0; + + va_start(ap, fmt); + ok = format(fprfunc, &fpr, fmt, ap); + va_end(ap); + + return fpr.bytes; /* return 0 on error */ +} + +int vuprintf(int (*push)(void *userp, unsigned char data), void *userp, const char *fmt, va_list ap) +{ + return format(push, userp, fmt, ap); +} diff --git a/firmware/common/memchr.c b/firmware/common/memchr.c deleted file mode 100644 index 26bdb9eea3..0000000000 --- a/firmware/common/memchr.c +++ /dev/null @@ -1,116 +0,0 @@ -/* -FUNCTION - <>---search for character in memory - -INDEX - memchr - -ANSI_SYNOPSIS - #include - void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>); - -TRAD_SYNOPSIS - #include - void * memchr(<[s1]>, <[c]>, <[n]>); - void *<[string]>; - int *<[c]>; - size_t *<[n]>; - -DESCRIPTION - This function scans the first <[n]> bytes of the memory pointed - to by <[s1]> for the character <[c]> (converted to a char). - -RETURNS - Returns a pointer to the matching byte, or a null pointer if - <[c]> does not occur in <[s1]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memchr ansi pure -*/ - -#include -#include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) - -void * -_DEFUN (memchr, (s1, i, n), - _CONST void *s1 _AND - int i _AND size_t n) -{ - _CONST unsigned char *s = (_CONST unsigned char *)s1; -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char c = (unsigned char)i; - - while (n-- > 0) - { - if (*s == c) - { - return (void *)s; - } - s++; - } - - return NULL; -#else - unsigned char c = (unsigned char)i; - unsigned long mask,j; - unsigned long *aligned_addr; - - if (!UNALIGNED (s)) - { - mask = 0; - for (j = 0; j < LBLOCKSIZE; j++) - mask = (mask << 8) | c; - - aligned_addr = (unsigned long*)s; - while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE)) - { - aligned_addr++; - n -= LBLOCKSIZE; - } - - /* The block of bytes currently pointed to by aligned_addr - may contain the target character or there may be less than - LBLOCKSIZE bytes left to search. We check the last few - bytes using the bytewise search. */ - - s = (unsigned char*)aligned_addr; - } - - while (n-- > 0) - { - if (*s == c) - { - return (void *)s; - } - s++; - } - - return NULL; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memcmp.c b/firmware/common/memcmp.c deleted file mode 100644 index 1535fcf5b5..0000000000 --- a/firmware/common/memcmp.c +++ /dev/null @@ -1,113 +0,0 @@ -/* -FUNCTION - <>---compare two memory areas - -INDEX - memcmp - -ANSI_SYNOPSIS - #include - int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); - -TRAD_SYNOPSIS - #include - int memcmp(<[s1]>, <[s2]>, <[n]>) - void *<[s1]>; - void *<[s2]>; - size_t <[n]>; - -DESCRIPTION - This function compares not more than <[n]> characters of the - object pointed to by <[s1]> with the object pointed to by <[s2]>. - - -RETURNS - The function returns an integer greater than, equal to or - less than zero according to whether the object pointed to by - <[s1]> is greater than, equal to or less than the object - pointed to by <[s2]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memcmp ansi pure -*/ - -#include - - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -int -_DEFUN (memcmp, (m1, m2, n), - _CONST _PTR m1 _AND - _CONST _PTR m2 _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; - - while (n--) - { - if (*s1 != *s2) - { - return *s1 - *s2; - } - s1++; - s2++; - } - return 0; -#else - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; - unsigned long *a1; - unsigned long *a2; - - /* If the size is too small, or either pointer is unaligned, - then we punt to the byte compare loop. Hopefully this will - not turn up in inner loops. */ - if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) - { - /* Otherwise, load and compare the blocks of memory one - word at a time. */ - a1 = (unsigned long*) s1; - a2 = (unsigned long*) s2; - while (n >= LBLOCKSIZE) - { - if (*a1 != *a2) - break; - a1++; - a2++; - n -= LBLOCKSIZE; - } - - /* check m mod LBLOCKSIZE remaining characters */ - - s1 = (unsigned char*)a1; - s2 = (unsigned char*)a2; - } - - while (n--) - { - if (*s1 != *s2) - return *s1 - *s2; - s1++; - s2++; - } - - return 0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} - diff --git a/firmware/common/memcpy.c b/firmware/common/memcpy.c deleted file mode 100644 index a89ac3c557..0000000000 --- a/firmware/common/memcpy.c +++ /dev/null @@ -1,117 +0,0 @@ -/* -FUNCTION - <>---copy memory regions - -ANSI_SYNOPSIS - #include - void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); - -TRAD_SYNOPSIS - void *memcpy(<[out]>, <[in]>, <[n]> - void *<[out]>; - void *<[in]>; - size_t <[n]>; - -DESCRIPTION - This function copies <[n]> bytes from the memory region - pointed to by <[in]> to the memory region pointed to by - <[out]>. - - If the regions overlap, the behavior is undefined. - -RETURNS - <> returns a pointer to the first byte of the <[out]> - region. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memcpy ansi pure - */ - -#include "config.h" -#include <_ansi.h> -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -_PTR -_DEFUN (memcpy, (dst0, src0, len0), - _PTR dst0 _AND - _CONST _PTR src0 _AND - size_t len0) ICODE_ATTR; - -_PTR -_DEFUN (memcpy, (dst0, src0, len0), - _PTR dst0 _AND - _CONST _PTR src0 _AND - size_t len0) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = (char *) dst0; - char *src = (char *) src0; - - _PTR save = dst0; - - while (len0--) - { - *dst++ = *src++; - } - - return save; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - unsigned int len = len0; - - /* If the size is small, or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (len >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len -= (unsigned int)BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (len >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - len -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (len--) - *dst++ = *src++; - - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memmove.c b/firmware/common/memmove.c deleted file mode 100644 index 5f423964bb..0000000000 --- a/firmware/common/memmove.c +++ /dev/null @@ -1,147 +0,0 @@ -/* -FUNCTION - <>---move possibly overlapping memory - -INDEX - memmove - -ANSI_SYNOPSIS - #include - void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - void *memmove(<[dst]>, <[src]>, <[length]>) - void *<[dst]>; - void *<[src]>; - size_t <[length]>; - -DESCRIPTION - This function moves <[length]> characters from the block of - memory starting at <<*<[src]>>> to the memory starting at - <<*<[dst]>>>. <> reproduces the characters correctly - at <<*<[dst]>>> even if the two areas overlap. - - -RETURNS - The function returns <[dst]> as passed. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memmove ansi pure -*/ - -#include "config.h" -#include <_ansi.h> -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -_PTR -_DEFUN (memmove, (dst_void, src_void, length), - _PTR dst_void _AND - _CONST _PTR src_void _AND - size_t length) ICODE_ATTR; - -_PTR -_DEFUN (memmove, (dst_void, src_void, length), - _PTR dst_void _AND - _CONST _PTR src_void _AND - size_t length) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = dst_void; - _CONST char *src = src_void; - - if (src < dst && dst < src + length) - { - /* Have to copy backwards */ - src += length; - dst += length; - while (length--) - { - *--dst = *--src; - } - } - else - { - while (length--) - { - *dst++ = *src++; - } - } - - return dst_void; -#else - char *dst = dst_void; - _CONST char *src = src_void; - long *aligned_dst; - _CONST long *aligned_src; - unsigned int len = length; - - if (src < dst && dst < src + len) - { - /* Destructive overlap...have to copy backwards */ - src += len; - dst += len; - while (len--) - { - *--dst = *--src; - } - } - else - { - /* Use optimizing algorithm for a non-destructive copy to closely - match memcpy. If the size is small or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (len >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len -= BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (len >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - len -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (len--) - { - *dst++ = *src++; - } - } - - return dst_void; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memset.c b/firmware/common/memset.c deleted file mode 100644 index 6c4a66bf13..0000000000 --- a/firmware/common/memset.c +++ /dev/null @@ -1,109 +0,0 @@ -/* -FUNCTION - <>---set an area of memory - -INDEX - memset - -ANSI_SYNOPSIS - #include - void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - void *memset(<[dst]>, <[c]>, <[length]>) - void *<[dst]>; - int <[c]>; - size_t <[length]>; - -DESCRIPTION - This function converts the argument <[c]> into an unsigned - char and fills the first <[length]> characters of the array - pointed to by <[dst]> to the value. - -RETURNS - <> returns the value of <[m]>. - -PORTABILITY -<> is ANSI C. - - <> requires no supporting OS subroutines. - -QUICKREF - memset ansi pure -*/ - -#include - -#define LBLOCKSIZE (sizeof(long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -_PTR -_DEFUN (memset, (m, c, n), - _PTR m _AND - int c _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = (char *) m; - - while (n-- != 0) - { - *s++ = (char) c; - } - - return m; -#else - char *s = (char *) m; - unsigned int i; - unsigned long buffer; - unsigned long *aligned_addr; - - if (!TOO_SMALL (n) && !UNALIGNED (m)) - { - /* If we get this far, we know that n is large and m is word-aligned. */ - - aligned_addr = (unsigned long*)m; - - /* Store C into each char sized location in BUFFER so that - we can set large blocks quickly. */ - c &= 0xff; - if (LBLOCKSIZE == 4) - { - buffer = (c << 8) | c; - buffer |= (buffer << 16); - } - else - { - buffer = 0; - for (i = 0; i < LBLOCKSIZE; i++) - buffer = (buffer << 8) | c; - } - - while (n >= LBLOCKSIZE*4) - { - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - n -= 4*LBLOCKSIZE; - } - - while (n >= LBLOCKSIZE) - { - *aligned_addr++ = buffer; - n -= LBLOCKSIZE; - } - /* Pick up the remainder with a bytewise loop. */ - s = (char*)aligned_addr; - } - - while (n--) - { - *s++ = (char)c; - } - - return m; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/qsort.c b/firmware/common/qsort.c deleted file mode 100644 index 8c4d1ad511..0000000000 --- a/firmware/common/qsort.c +++ /dev/null @@ -1,222 +0,0 @@ -/* -FUNCTION -<>---sort an array - -INDEX - qsort - -ANSI_SYNOPSIS - #include - void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, - int (*<[compar]>)(const void *, const void *) ); - -TRAD_SYNOPSIS - #include - qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> ) - char *<[base]>; - size_t <[nmemb]>; - size_t <[size]>; - int (*<[compar]>)(); - -DESCRIPTION -<> sorts an array (beginning at <[base]>) of <[nmemb]> objects. -<[size]> describes the size of each element of the array. - -You must supply a pointer to a comparison function, using the argument -shown as <[compar]>. (This permits sorting objects of unknown -properties.) Define the comparison function to accept two arguments, -each a pointer to an element of the array starting at <[base]>. The -result of <<(*<[compar]>)>> must be negative if the first argument is -less than the second, zero if the two arguments match, and positive if -the first argument is greater than the second (where ``less than'' and -``greater than'' refer to whatever arbitrary ordering is appropriate). - -The array is sorted in place; that is, when <> returns, the -array elements beginning at <[base]> have been reordered. - -RETURNS -<> does not return a result. - -PORTABILITY -<> is required by ANSI (without specifying the sorting algorithm). -*/ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <_ansi.h> -#include - -#ifndef __GNUC__ -#define inline -#endif - -static inline char *med3 _PARAMS((char *, char *, char *, int (*cmp)(const _PTR,const _PTR))); -static inline void swapfunc _PARAMS((char *, char *, int, int)); - -#define min(a, b) (a) < (b) ? a : b - -/* - * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". - */ -#define swapcode(TYPE, parmi, parmj, n) { \ - long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ - do { \ - register TYPE t = *pi; \ - *pi++ = *pj; \ - *pj++ = t; \ - } while (--i > 0); \ -} - -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; - -static inline void -_DEFUN(swapfunc, (a, b, n, swaptype), - char *a _AND - char *b _AND - int n _AND - int swaptype) -{ - if(swaptype <= 1) - swapcode(long, a, b, n) - else - swapcode(char, a, b, n) -} - -#define swap(a, b) \ - if (swaptype == 0) { \ - long t = *(long *)(a); \ - *(long *)(a) = *(long *)(b); \ - *(long *)(b) = t; \ - } else \ - swapfunc(a, b, es, swaptype) - -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) - -static inline char * -_DEFUN(med3, (a, b, c, cmp), - char *a _AND - char *b _AND - char *c _AND - int (*cmp)(const _PTR,const _PTR)) -{ - return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); -} - -void -_DEFUN(qsort, (a, n, es, cmp), - void *a _AND - size_t n _AND - size_t es _AND - int (*cmp)(const _PTR,const _PTR)) -{ - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; - -loop: SWAPINIT(a, es); - swap_cnt = 0; - if (n < 7) { - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - pm = (char *) a + (n / 2) * es; - if (n > 7) { - pl = a; - pn = (char *) a + (n - 1) * es; - if (n > 40) { - d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp); - pm = med3(pm - d, pm, pm + d, cmp); - pn = med3(pn - 2 * d, pn - d, pn, cmp); - } - pm = med3(pl, pm, pn, cmp); - } - swap(a, pm); - pa = pb = (char *) a + es; - - pc = pd = (char *) a + (n - 1) * es; - for (;;) { - while (pb <= pc && (r = cmp(pb, a)) <= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pa, pb); - pa += es; - } - pb += es; - } - while (pb <= pc && (r = cmp(pc, a)) >= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pc, pd); - pd -= es; - } - pc -= es; - } - if (pb > pc) - break; - swap(pb, pc); - swap_cnt = 1; - pb += es; - pc -= es; - } - if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - - pn = (char *) a + n * es; - r = min(pa - (char *)a, pb - pa); - vecswap(a, pb - r, r); - r = min((unsigned int)(pd - pc), pn - pd - es); - vecswap(pb, pn - r, r); - if ((unsigned int)(r = pb - pa) > es) - qsort(a, r / es, es, cmp); - if ((unsigned int)(r = pd - pc) > es) { - /* Iterate rather than recurse to save stack space */ - a = pn - r; - n = r / es; - goto loop; - } -/* qsort(pn - r, r / es, es, cmp);*/ -} diff --git a/firmware/common/random.c b/firmware/common/random.c deleted file mode 100644 index f3efe89351..0000000000 --- a/firmware/common/random.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - A C-program for MT19937, with initialization improved 2002/2/10. - Coded by Takuji Nishimura and Makoto Matsumoto. - This is a faster version by taking Shawn Cokus's optimization, - Matthe Bellew's simplification. - - Before using, initialize the state by using srand(seed). - - Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Any feedback is very welcome. - http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html - email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) -*/ - -/* - Adapted to Rockbox by Jens Arnold -*/ - -#include - -/* Period parameters */ -#define N 624 -#define M 397 -#define MATRIX_A 0x9908b0dfUL /* constant vector a */ -#define UMASK 0x80000000UL /* most significant w-r bits */ -#define LMASK 0x7fffffffUL /* least significant r bits */ -#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) ) -#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL)) - -static unsigned long state[N]; /* the array for the state vector */ -static int left = 0; -static unsigned long *next; - -/* initializes state[N] with a seed */ -void srand(unsigned int seed) -{ - unsigned long x = seed & 0xffffffffUL; - unsigned long *s = state; - int j; - - for (*s++ = x, j = 1; j < N; j++) { - x = (1812433253UL * (x ^ (x >> 30)) + j) & 0xffffffffUL; - *s++ = x; - /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ - /* In the previous versions, MSBs of the seed affect */ - /* only MSBs of the array state[]. */ - /* 2002/01/09 modified by Makoto Matsumoto */ - } - left = 1; -} - -static void next_state(void) -{ - unsigned long *p = state; - int j; - - /* if srand() has not been called, */ - /* a default initial seed is used */ - if (left < 0) - srand(5489UL); - - left = N; - next = state; - - for (j = N - M + 1; --j; p++) - *p = p[M] ^ TWIST(p[0], p[1]); - - for (j = M; --j; p++) - *p = p[M-N] ^ TWIST(p[0], p[1]); - - *p = p[M-N] ^ TWIST(p[0], state[0]); -} - -/* generates a random number on [0,RAND_MAX]-interval */ -int rand(void) -{ - unsigned long y; - - if (--left <= 0) - next_state(); - y = *next++; - - /* Tempering */ - y ^= (y >> 11); - y ^= (y << 7) & 0x9d2c5680UL; - y ^= (y << 15) & 0xefc60000UL; - y ^= (y >> 18); - - return ((unsigned int)y) >> 1; -} diff --git a/firmware/common/sprintf.c b/firmware/common/sprintf.c deleted file mode 100644 index 35f977a0a3..0000000000 --- a/firmware/common/sprintf.c +++ /dev/null @@ -1,299 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Gary Czvitkovicz - * - * 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. - * - ****************************************************************************/ - -/* - * Minimal printf and snprintf formatting functions - * - * These support %c %s %d and %x - * Field width and zero-padding flag only - */ - -#include -#include -#include -#include - -#include "file.h" /* for write(), used in fprintf() */ -#include "sprintf.h" /* to allow the simulator magic */ - -static const char hexdigit[] = "0123456789ABCDEF"; - -static int format( - /* call 'push()' for each output letter */ - int (*push)(void *userp, unsigned char data), - void *userp, - const char *fmt, - va_list ap) -{ - char *str; - char tmpbuf[12], pad; - int ch, width, val, sign, precision; - long lval, lsign; - unsigned int uval; - unsigned long ulval; - bool ok = true; - - tmpbuf[sizeof tmpbuf - 1] = '\0'; - - while ((ch = *fmt++) != '\0' && ok) - { - if (ch == '%') - { - ch = *fmt++; - pad = ' '; - if (ch == '0') - pad = '0'; - - width = 0; - while (ch >= '0' && ch <= '9') - { - width = 10*width + ch - '0'; - ch = *fmt++; - } - - precision = 0; - if(ch == '.') - { - ch = *fmt++; - while (ch >= '0' && ch <= '9') - { - precision = 10*precision + ch - '0'; - ch = *fmt++; - } - } else { - precision = INT_MAX; - } - - str = tmpbuf + sizeof tmpbuf - 1; - switch (ch) - { - case 'c': - *--str = va_arg (ap, int); - break; - - case 's': - str = va_arg (ap, char*); - break; - - case 'd': - val = sign = va_arg (ap, int); - if (val < 0) - val = -val; - do - { - *--str = (val % 10) + '0'; - val /= 10; - } - while (val > 0); - if (sign < 0) - *--str = '-'; - break; - - case 'u': - uval = va_arg(ap, unsigned int); - do - { - *--str = (uval % 10) + '0'; - uval /= 10; - } - while (uval > 0); - break; - - case 'x': - case 'X': - pad='0'; - uval = va_arg (ap, int); - do - { - *--str = hexdigit[uval & 0xf]; - uval >>= 4; - } - while (uval); - break; - - case 'l': - ch = *fmt++; - switch(ch) { - case 'x': - case 'X': - pad='0'; - ulval = va_arg (ap, long); - do - { - *--str = hexdigit[ulval & 0xf]; - ulval >>= 4; - } - while (ulval); - break; - case 'd': - lval = lsign = va_arg (ap, long); - if (lval < 0) - lval = -lval; - do - { - *--str = (lval % 10) + '0'; - lval /= 10; - } - while (lval > 0); - if (lsign < 0) - *--str = '-'; - break; - - case 'u': - ulval = va_arg(ap, unsigned long); - do - { - *--str = (ulval % 10) + '0'; - ulval /= 10; - } - while (ulval > 0); - break; - - default: - *--str = 'l'; - *--str = ch; - } - - break; - - default: - *--str = ch; - break; - } - - if (width > 0) - { - width -= strlen (str); - while (width-- > 0 && ok) - ok=push(userp, pad); - } - while (*str != '\0' && ok && precision--) - ok=push(userp, *str++); - } - else - ok=push(userp, ch); - } - return ok; /* true means good */ -} - -#if !defined(SIMULATOR) || !defined(linux) -/* ALSA library requires a more advanced snprintf, so let's not - override it in simulator for Linux. Note that Cygwin requires - our snprintf or it produces garbled output after a while. */ - -struct for_snprintf { - unsigned char *ptr; /* where to store it */ - int bytes; /* amount already stored */ - int max; /* max amount to store */ -}; - -static int sprfunc(void *ptr, unsigned char letter) -{ - struct for_snprintf *pr = (struct for_snprintf *)ptr; - if(pr->bytes < pr->max) { - *pr->ptr = letter; - pr->ptr++; - pr->bytes++; - return true; - } - return false; /* filled buffer */ -} - - -int snprintf(char *buf, size_t size, const char *fmt, ...) -{ - bool ok; - va_list ap; - struct for_snprintf pr; - - pr.ptr = (unsigned char *)buf; - pr.bytes = 0; - pr.max = size; - - va_start(ap, fmt); - ok = format(sprfunc, &pr, fmt, ap); - va_end(ap); - - /* make sure it ends with a trailing zero */ - pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; - - return pr.bytes; -} - -int vsnprintf(char *buf, int size, const char *fmt, va_list ap) -{ - bool ok; - struct for_snprintf pr; - - pr.ptr = (unsigned char *)buf; - pr.bytes = 0; - pr.max = size; - - ok = format(sprfunc, &pr, fmt, ap); - - /* make sure it ends with a trailing zero */ - pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; - - return pr.bytes; -} - -#endif /* Linux SIMULATOR */ - -struct for_fprintf { - int fd; /* where to store it */ - int bytes; /* amount stored */ -}; - -static int fprfunc(void *pr, unsigned char letter) -{ - struct for_fprintf *fpr = (struct for_fprintf *)pr; - int rc = write(fpr->fd, &letter, 1); - - if(rc > 0) { - fpr->bytes++; /* count them */ - return true; /* we are ok */ - } - - return false; /* failure */ -} - - -int fdprintf(int fd, const char *fmt, ...) -{ - bool ok; - va_list ap; - struct for_fprintf fpr; - - fpr.fd=fd; - fpr.bytes=0; - - va_start(ap, fmt); - ok = format(fprfunc, &fpr, fmt, ap); - va_end(ap); - - return fpr.bytes; /* return 0 on error */ -} - -int vuprintf(int (*push)(void *userp, unsigned char data), void *userp, const char *fmt, va_list ap) -{ - return format(push, userp, fmt, ap); -} - diff --git a/firmware/common/sscanf.c b/firmware/common/sscanf.c deleted file mode 100644 index 5fbe81f3e0..0000000000 --- a/firmware/common/sscanf.c +++ /dev/null @@ -1,282 +0,0 @@ -#include -#include -#include - -static inline bool isspace(char c) -{ - return (c == ' ') || (c == '\t') || (c == '\n'); -} - -static inline bool isdigit(char c) -{ - return (c >= '0') && (c <= '9'); -} - -static inline bool isxdigit(char c) -{ - return ((c >= '0') && (c <= '9')) - || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); -} - -static int parse_dec(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - long *vp) -{ - long v = 0; - int n = 0; - int minus = 0; - char ch; - - if ((*peek)(userp) == '-') - { - (*pop)(userp); - n++; - minus = 1; - } - - ch = (*peek)(userp); - if (!isdigit(ch)) - return -1; - - do - { - v = v * 10 + ch - '0'; - (*pop)(userp); - n++; - ch = (*peek)(userp); - } while (isdigit(ch)); - - *vp = minus ? -v : v; - return n; -} - -static int parse_chars(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - char *vp, - bool fake) -{ - int n = 0; - - char *pt=vp; - - while (!isspace((*peek)(userp))) - { - if(fake==false) - *(pt++) = (*peek)(userp); - - n++; - (*pop)(userp); - } - - if(fake==false) - (*pt)='\0'; - - return n; -} - -static int parse_hex(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - unsigned long *vp) -{ - unsigned long v = 0; - int n = 0; - char ch; - - ch = (*peek)(userp); - if (!isxdigit(ch)) - return -1; - - do - { - if (ch >= 'a') - ch = ch - 'a' + 10; - else if (ch >= 'A') - ch = ch - 'A' + 10; - else - ch = ch - '0'; - v = v * 16 + ch; - (*pop)(userp); - n++; - ch = (*peek)(userp); - } while (isxdigit(ch)); - - *vp = v; - return n; -} - -static int skip_spaces(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp) -{ - int n = 0; - while (isspace((*peek)(userp))) { - n++; - (*pop)(userp); - } - return n; -} - -static int scan(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - const char *fmt, - va_list ap) -{ - char ch; - int n = 0; - int n_chars = 0; - int r; - long lval; - bool skip=false; - unsigned long ulval; - - while ((ch = *fmt++) != '\0') - { - bool literal = false; - - if (ch == '%') - { - ch = *fmt++; - - if(ch== '*') /* We should process this, but not store it in an arguement */ - { - ch=*fmt++; - skip=true; - } - else - { - skip=false; - } - - switch (ch) - { - case 'x': - n_chars += skip_spaces(peek, pop, userp); - if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, unsigned int *)) = ulval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'd': - n_chars += skip_spaces(peek, pop, userp); - if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, int *)) = lval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'n': - if(skip==false) - { - *(va_arg(ap, int *)) = n_chars; - n++; - } - break; - case 'l': - n_chars += skip_spaces(peek, pop, userp); - ch = *fmt++; - switch (ch) - { - case 'x': - if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, unsigned long *)) = ulval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'd': - if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, long *)) = lval; - n++; - } - n_chars += r; - } - else - return n; - break; - case '\0': - return n; - default: - literal = true; - break; - } - break; - case 's': - n_chars += skip_spaces(peek, pop, userp); - n_chars += parse_chars(peek,pop, userp,skip?0:va_arg(ap, char *), skip ); - if(skip==false) - { - n++; - } - break; - case '\0': - return n; - default: - literal = true; - break; - } - } else - literal = true; - - if (literal) - { - n_chars += skip_spaces(peek, pop, userp); - if ((*peek)(userp) != ch) - continue; - else - { - (*pop)(userp); - n_chars++; - } - } - } - return n; -} - -static int sspeek(void *userp) -{ - return **((char **)userp); -} - -static void sspop(void *userp) -{ - (*((char **)userp))++; -} - -int sscanf(const char *s, const char *fmt, ...) -{ - int r; - va_list ap; - const char *p; - - p = s; - va_start(ap, fmt); - r = scan(sspeek, sspop, &p, fmt, ap); - va_end(ap); - return r; -} diff --git a/firmware/common/strcat.c b/firmware/common/strcat.c deleted file mode 100644 index 221529519c..0000000000 --- a/firmware/common/strcat.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -char *strcat(char *s1, - const char *s2) -{ - char *s = s1; - - while (*s1) - s1++; - - while ((*s1++ = *s2++)) - ; - return s; -} diff --git a/firmware/common/strchr.c b/firmware/common/strchr.c deleted file mode 100644 index 96acf5edf6..0000000000 --- a/firmware/common/strchr.c +++ /dev/null @@ -1,108 +0,0 @@ -/* -FUNCTION - <>---search for character in string - -INDEX - strchr - -ANSI_SYNOPSIS - #include - char * strchr(const char *<[string]>, int <[c]>); - -TRAD_SYNOPSIS - #include - char * strchr(<[string]>, <[c]>); - char *<[string]>; - int *<[c]>; - -DESCRIPTION - This function finds the first occurence of <[c]> (converted to - a char) in the string pointed to by <[string]> (including the - terminating null character). - -RETURNS - Returns a pointer to the located character, or a null pointer - if <[c]> does not occur in <[string]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strchr ansi pure -*/ - -#include -#include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) - -char * -_DEFUN (strchr, (s1, i), - _CONST char *s1 _AND - int i) -{ - _CONST unsigned char *s = (_CONST unsigned char *)s1; -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char c = (unsigned int)i; - - while (*s && *s != c) - { - s++; - } - - if (*s != c) - { - s = NULL; - } - - return (char *) s; -#else - unsigned char c = (unsigned char)i; - unsigned long mask,j; - unsigned long *aligned_addr; - - if (!UNALIGNED (s)) - { - mask = 0; - for (j = 0; j < LBLOCKSIZE; j++) - mask = (mask << 8) | c; - - aligned_addr = (unsigned long*)s; - while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) - aligned_addr++; - - /* The block of bytes currently pointed to by aligned_addr - contains either a null or the target char, or both. We - catch it using the bytewise search. */ - - s = (unsigned char*)aligned_addr; - } - - while (*s && *s != c) - s++; - if (*s == c) - return (char *)s; - return NULL; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strcmp.c b/firmware/common/strcmp.c deleted file mode 100644 index bbbf4b174a..0000000000 --- a/firmware/common/strcmp.c +++ /dev/null @@ -1,106 +0,0 @@ -/* -FUNCTION - <>---character string compare - -INDEX - strcmp - -ANSI_SYNOPSIS - #include - int strcmp(const char *<[a]>, const char *<[b]>); - -TRAD_SYNOPSIS - #include - int strcmp(<[a]>, <[b]>) - char *<[a]>; - char *<[b]>; - -DESCRIPTION - <> compares the string at <[a]> to - the string at <[b]>. - -RETURNS - If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, - <> returns a number greater than zero. If the two - strings match, <> returns zero. If <<*<[a]>>> - sorts lexicographically before <<*<[b]>>>, <> returns a - number less than zero. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strcmp ansi pure -*/ - -#include -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -int -_DEFUN (strcmp, (s1, s2), - _CONST char *s1 _AND - _CONST char *s2) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - while (*s1 != '\0' && *s1 == *s2) - { - s1++; - s2++; - } - - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#else - unsigned long *a1; - unsigned long *a2; - - /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) - { - /* If s1 and s2 are word-aligned, compare them a word at a time. */ - a1 = (unsigned long*)s1; - a2 = (unsigned long*)s2; - while (*a1 == *a2) - { - /* To get here, *a1 == *a2, thus if we find a null in *a1, - then the strings must be equal, so return zero. */ - if (DETECTNULL (*a1)) - return 0; - - a1++; - a2++; - } - - /* A difference was detected in last few bytes of s1, so search bytewise */ - s1 = (char*)a1; - s2 = (char*)a2; - } - - while (*s1 != '\0' && *s1 == *s2) - { - s1++; - s2++; - } - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strcpy.c b/firmware/common/strcpy.c deleted file mode 100644 index 077ae73cc6..0000000000 --- a/firmware/common/strcpy.c +++ /dev/null @@ -1,99 +0,0 @@ -/* -FUNCTION - <>---copy string - -INDEX - strcpy - -ANSI_SYNOPSIS - #include - char *strcpy(char *<[dst]>, const char *<[src]>); - -TRAD_SYNOPSIS - #include - char *strcpy(<[dst]>, <[src]>) - char *<[dst]>; - char *<[src]>; - -DESCRIPTION - <> copies the string pointed to by <[src]> - (including the terminating null character) to the array - pointed to by <[dst]>. - -RETURNS - This function returns the initial value of <[dst]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strcpy ansi pure -*/ - -#include -#include - -/*SUPPRESS 560*/ -/*SUPPRESS 530*/ - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -char* -_DEFUN (strcpy, (dst0, src0), - char *dst0 _AND - _CONST char *src0) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = dst0; - - while ((*dst0++ = *src0++)) - ; - - return s; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - - /* If SRC or DEST is unaligned, then copy bytes. */ - if (!UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* SRC and DEST are both "long int" aligned, try to do "long int" - sized copies. */ - while (!DETECTNULL(*aligned_src)) - { - *aligned_dst++ = *aligned_src++; - } - - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while ((*dst++ = *src++)) - ; - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strlcat.c b/firmware/common/strlcat.c index da0d253e79..783ea4daba 100644 --- a/firmware/common/strlcat.c +++ b/firmware/common/strlcat.c @@ -16,7 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include /* diff --git a/firmware/common/strlcpy.c b/firmware/common/strlcpy.c index 6e06eb81d2..e320649140 100644 --- a/firmware/common/strlcpy.c +++ b/firmware/common/strlcpy.c @@ -16,7 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include /* diff --git a/firmware/common/strlen.c b/firmware/common/strlen.c deleted file mode 100644 index 4d33eafce6..0000000000 --- a/firmware/common/strlen.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -FUNCTION - <>---character string length - -INDEX - strlen - -ANSI_SYNOPSIS - #include - size_t strlen(const char *<[str]>); - -TRAD_SYNOPSIS - #include - size_t strlen(<[str]>) - char *<[src]>; - -DESCRIPTION - The <> function works out the length of the string - starting at <<*<[str]>>> by counting chararacters until it - reaches a <> character. - -RETURNS - <> returns the character count. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strlen ansi pure -*/ - -#include "config.h" -#include <_ansi.h> -#include -#include - -#define LBLOCKSIZE (sizeof (long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -size_t -_DEFUN (strlen, (str), - _CONST char *str) ICODE_ATTR; - -size_t -_DEFUN (strlen, (str), - _CONST char *str) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - _CONST char *start = str; - - while (*str) - str++; - - return str - start; -#else - _CONST char *start = str; - unsigned long *aligned_addr; - - if (!UNALIGNED (str)) - { - /* If the string is word-aligned, we can check for the presence of - a null in each word-sized block. */ - aligned_addr = (unsigned long*)str; - while (!DETECTNULL (*aligned_addr)) - aligned_addr++; - - /* Once a null is detected, we check each byte in that block for a - precise position of the null. */ - str = (char*)aligned_addr; - } - - while (*str) - str++; - return str - start; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strncmp.c b/firmware/common/strncmp.c deleted file mode 100644 index b1d8d9d43a..0000000000 --- a/firmware/common/strncmp.c +++ /dev/null @@ -1,122 +0,0 @@ -/* -FUNCTION - <>---character string compare - -INDEX - strncmp - -ANSI_SYNOPSIS - #include - int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - int strncmp(<[a]>, <[b]>, <[length]>) - char *<[a]>; - char *<[b]>; - size_t <[length]> - -DESCRIPTION - <> compares up to <[length]> characters - from the string at <[a]> to the string at <[b]>. - -RETURNS - If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, - <> returns a number greater than zero. If the two - strings are equivalent, <> returns zero. If <<*<[a]>>> - sorts lexicographically before <<*<[b]>>>, <> returns a - number less than zero. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strncmp ansi pure -*/ - -#include -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -int -_DEFUN (strncmp, (s1, s2, n), - _CONST char *s1 _AND - _CONST char *s2 _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - if (n == 0) - return 0; - - while (n-- != 0 && *s1 == *s2) - { - if (n == 0 || *s1 == '\0') - break; - s1++; - s2++; - } - - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#else - unsigned long *a1; - unsigned long *a2; - - if (n == 0) - return 0; - - /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) - { - /* If s1 and s2 are word-aligned, compare them a word at a time. */ - a1 = (unsigned long*)s1; - a2 = (unsigned long*)s2; - while (n >= sizeof (long) && *a1 == *a2) - { - n -= sizeof (long); - - /* If we've run out of bytes or hit a null, return zero - since we already know *a1 == *a2. */ - if (n == 0 || DETECTNULL (*a1)) - return 0; - - a1++; - a2++; - } - - /* A difference was detected in last few bytes of s1, so search bytewise */ - s1 = (char*)a1; - s2 = (char*)a2; - } - - while (n-- > 0 && *s1 == *s2) - { - /* If we've run out of bytes or hit a null, return zero - since we already know *s1 == *s2. */ - if (n == 0 || *s1 == '\0') - return 0; - s1++; - s2++; - } - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strrchr.c b/firmware/common/strrchr.c deleted file mode 100644 index 31b0d049b3..0000000000 --- a/firmware/common/strrchr.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -FUNCTION - <>---reverse search for character in string - -INDEX - strrchr - -ANSI_SYNOPSIS - #include - char * strrchr(const char *<[string]>, int <[c]>); - -TRAD_SYNOPSIS - #include - char * strrchr(<[string]>, <[c]>); - char *<[string]>; - int *<[c]>; - -DESCRIPTION - This function finds the last occurence of <[c]> (converted to - a char) in the string pointed to by <[string]> (including the - terminating null character). - -RETURNS - Returns a pointer to the located character, or a null pointer - if <[c]> does not occur in <[string]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strrchr ansi pure -*/ - -#include - -char * -_DEFUN (strrchr, (s, i), - _CONST char *s _AND - int i) -{ - _CONST char *last = NULL; - - if (i) - { - while ((s=strchr(s, i))) - { - last = s; - s++; - } - } - else - { - last = strchr(s, i); - } - - return (char *) last; -} diff --git a/firmware/common/strstr.c b/firmware/common/strstr.c deleted file mode 100644 index 73fab1cc63..0000000000 --- a/firmware/common/strstr.c +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id: $ - * - * Copyright (C) 1991, 1992 Linus Torvalds - * (from linux/lib/string.c) - * - ****************************************************************************/ - -#include - -/** - * strstr - Find the first substring in a %NUL terminated string - * @s1: The string to be searched - * @s2: The string to search for - */ -char *strstr(const char *s1, const char *s2) -{ - int l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *)s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1, s2, l2)) - return (char *)s1; - s1++; - } - return NULL; -} - diff --git a/firmware/common/strtok.c b/firmware/common/strtok.c deleted file mode 100644 index 9e2eddf599..0000000000 --- a/firmware/common/strtok.c +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Daniel Stenberg - * - * 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 "config.h" - -#ifndef HAVE_STRTOK_R -#include -#include - -char * -strtok_r(char *ptr, const char *sep, char **end) -{ - if (!ptr) - /* we got NULL input so then we get our last position instead */ - ptr = *end; - - /* pass all letters that are including in the separator string */ - while (*ptr && strchr(sep, *ptr)) - ++ptr; - - if (*ptr) { - /* so this is where the next piece of string starts */ - char *start = ptr; - - /* set the end pointer to the first byte after the start */ - *end = start + 1; - - /* scan through the string to find where it ends, it ends on a - null byte or a character that exists in the separator string */ - while (**end && !strchr(sep, **end)) - ++*end; - - if (**end) { - /* the end is not a null byte */ - **end = '\0'; /* zero terminate it! */ - ++*end; /* advance last pointer to beyond the null byte */ - } - - return start; /* return the position where the string starts */ - } - - /* we ended up on a null byte, there are no more strings to find! */ - return NULL; -} - -#endif /* this was only compiled if strtok_r wasn't present */ diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index e423e016fd..42babbd8e3 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c @@ -103,43 +103,6 @@ int set_time(const struct tm *tm) #endif /* RTC */ } -#if CONFIG_RTC -/* mktime() code taken from lynx-2.8.5 source, written - by Philippe De Muyter */ -time_t mktime(struct tm *t) -{ - short month, year; - time_t result; - static int m_to_d[12] = - {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - - month = t->tm_mon; - year = t->tm_year + month / 12 + 1900; - month %= 12; - if (month < 0) - { - year -= 1; - month += 12; - } - result = (year - 1970) * 365 + (year - 1969) / 4 + m_to_d[month]; - result = (year - 1970) * 365 + m_to_d[month]; - if (month <= 1) - year -= 1; - result += (year - 1968) / 4; - result -= (year - 1900) / 100; - result += (year - 1600) / 400; - result += t->tm_mday; - result -= 1; - result *= 24; - result += t->tm_hour; - result *= 60; - result += t->tm_min; - result *= 60; - result += t->tm_sec; - return(result); -} -#endif - void set_day_of_week(struct tm *tm) { int y=tm->tm_year+1900; diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 8f0b61ef6a..1b31ee8a18 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c @@ -27,8 +27,9 @@ * KIND, either express or implied. * ****************************************************************************/ -#include "stdarg.h" -#include "sprintf.h" +#include +#include +#include "string-extra.h" #include "diacritic.h" #ifndef LCDFN /* Not compiling for remote - define macros for main LCD. */ diff --git a/firmware/drivers/lcd-charcell.c b/firmware/drivers/lcd-charcell.c index 8af08e64bb..0186c26106 100644 --- a/firmware/drivers/lcd-charcell.c +++ b/firmware/drivers/lcd-charcell.c @@ -22,7 +22,6 @@ #include "config.h" #include "hwcompat.h" #include "stdarg.h" -#include "sprintf.h" #include "lcd.h" #include "kernel.h" #include "thread.h" diff --git a/firmware/drivers/tuner/lv24020lp.c b/firmware/drivers/tuner/lv24020lp.c index 5f23338eee..75796a5d7b 100644 --- a/firmware/drivers/tuner/lv24020lp.c +++ b/firmware/drivers/tuner/lv24020lp.c @@ -40,7 +40,6 @@ static struct mutex tuner_mtx; #undef SANYO_TUNER_LOGF #ifdef SANYO_TUNER_LOG_FILE -#include "sprintf.h" #include "file.h" static int fd_log = -1; diff --git a/firmware/export/audio.h b/firmware/export/audio.h index 6833761652..1e09081ba5 100644 --- a/firmware/export/audio.h +++ b/firmware/export/audio.h @@ -22,7 +22,7 @@ #define AUDIO_H #include -#include +#include /* size_t */ #include "config.h" /* These must always be included with audio.h for this to compile under cetain conditions. Do it here or else spread the complication around to diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h index 56c3e18229..5b42394b1f 100644 --- a/firmware/export/config/sim.h +++ b/firmware/export/config/sim.h @@ -95,3 +95,5 @@ /* default for 100% in the sim */ #define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING #endif + +#define _ISOC99_SOURCE 1 diff --git a/firmware/export/pcm.h b/firmware/export/pcm.h index e67d459693..0f8222f90d 100644 --- a/firmware/export/pcm.h +++ b/firmware/export/pcm.h @@ -21,7 +21,7 @@ #ifndef PCM_PLAYBACK_H #define PCM_PLAYBACK_H -#include +#include /* size_t */ #define DMA_REC_ERROR_DMA (-1) #ifdef HAVE_SPDIF_REC diff --git a/firmware/firmware.make b/firmware/firmware.make index ec24b4ebee..115bfacad0 100644 --- a/firmware/firmware.make +++ b/firmware/firmware.make @@ -7,7 +7,7 @@ # $Id$ # -INCLUDES += -I$(FIRMDIR) -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers +INCLUDES += -I$(FIRMDIR)/libc/include -I$(FIRMDIR) -I$(FIRMDIR)/export -I$(FIRMDIR)/drivers -I$(FIRMDIR)/include FIRMLIB_SRC += $(call preprocess, $(FIRMDIR)/SOURCES) FIRMLIB_OBJ := $(call c2obj, $(FIRMLIB_SRC)) diff --git a/firmware/general.c b/firmware/general.c index 6f7238ead1..fa1025492b 100644 --- a/firmware/general.c +++ b/firmware/general.c @@ -20,13 +20,13 @@ ****************************************************************************/ #include "config.h" +#include #include "general.h" #include "dir.h" #include "limits.h" -#include "sprintf.h" #include "stdlib.h" -#include "string.h" +#include "string-extra.h" #include "system.h" #include "time.h" #include "timefuncs.h" diff --git a/firmware/ifp_usb_serial.c b/firmware/ifp_usb_serial.c index 06b286ab85..530f2c122b 100644 --- a/firmware/ifp_usb_serial.c +++ b/firmware/ifp_usb_serial.c @@ -37,7 +37,6 @@ #ifdef LCD_DEBUG #include "lcd.h" -#include "sprintf.h" #endif diff --git a/firmware/include/ctype.h b/firmware/include/ctype.h deleted file mode 100644 index 648e06dc5c..0000000000 --- a/firmware/include/ctype.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _CTYPE_H_ -#ifdef __cplusplus -extern "C" { -#endif -#define _CTYPE_H_ - -#include "_ansi.h" - -int _EXFUN(isalnum, (int __c)); -int _EXFUN(isalpha, (int __c)); -int _EXFUN(iscntrl, (int __c)); -int _EXFUN(isdigit, (int __c)); -int _EXFUN(isgraph, (int __c)); -int _EXFUN(islower, (int __c)); -int _EXFUN(isprint, (int __c)); -int _EXFUN(ispunct, (int __c)); -int _EXFUN(isspace, (int __c)); -int _EXFUN(isupper, (int __c)); -int _EXFUN(isxdigit,(int __c)); -int _EXFUN(tolower, (int __c)); -int _EXFUN(toupper, (int __c)); - -#ifndef __STRICT_ANSI__ -int _EXFUN(isascii, (int __c)); -int _EXFUN(toascii, (int __c)); -int _EXFUN(_tolower, (int __c)); -int _EXFUN(_toupper, (int __c)); -#endif - -#define _U 01 -#define _L 02 -#define _N 04 -#define _S 010 -#define _P 020 -#define _C 040 -#define _X 0100 -#define _B 0200 - -#ifdef PLUGIN -#define _ctype_ (rb->_rbctype_) -#else -extern const unsigned char _ctype_[257]; -#endif - -#ifndef __cplusplus -#define isalpha(c) ((_ctype_+1)[(unsigned char)(c)]&(_U|_L)) -#define isupper(c) ((_ctype_+1)[(unsigned char)(c)]&_U) -#define islower(c) ((_ctype_+1)[(unsigned char)(c)]&_L) -#define isdigit(c) ((_ctype_+1)[(unsigned char)(c)]&_N) -#define isxdigit(c) ((_ctype_+1)[(unsigned char)(c)]&(_X|_N)) -#define isspace(c) ((_ctype_+1)[(unsigned char)(c)]&_S) -#define ispunct(c) ((_ctype_+1)[(unsigned char)(c)]&_P) -#define isalnum(c) ((_ctype_+1)[(unsigned char)(c)]&(_U|_L|_N)) -#define isprint(c) ((_ctype_+1)[(unsigned char)(c)]&(_P|_U|_L|_N|_B)) -#define isgraph(c) ((_ctype_+1)[(unsigned char)(c)]&(_P|_U|_L|_N)) -#define iscntrl(c) ((_ctype_+1)[(unsigned char)(c)]&_C) -/* Non-gcc versions will get the library versions, and will be - slightly slower */ -#ifdef __GNUC__ -# define toupper(c) \ - __extension__ ({ int __x = (unsigned char) (c); islower(__x) ? (__x - 'a' + 'A') : __x;}) -# define tolower(c) \ - __extension__ ({ int __x = (unsigned char) (c); isupper(__x) ? (__x - 'A' + 'a') : __x;}) -#endif -#endif /* !__cplusplus */ - -#ifndef __STRICT_ANSI__ -#define isascii(c) ((unsigned char)(c)<=0177) -#define toascii(c) ((c)&0177) -#endif - -#ifdef __cplusplus -} -#endif -#endif /* _CTYPE_H_ */ diff --git a/firmware/include/errno.h b/firmware/include/errno.h deleted file mode 100644 index 6a24a1938f..0000000000 --- a/firmware/include/errno.h +++ /dev/null @@ -1,145 +0,0 @@ -/* errno is not a global variable, because that would make using it - non-reentrant. Instead, its address is returned by the function - __errno. */ - -#if (defined(SIMULATOR)||defined(__PCTOOL__)) && !defined(__MINGW32__) && !defined(__CYGWIN__) - -#include "/usr/include/errno.h" /* use the host system implementation */ - -#else /* use our own implementation */ - -#ifndef _SYS_ERRNO_H_ - -#ifdef PLUGIN -#define errno (*rb->__errno) -#else -extern int errno; -#endif - -#define EPERM 1 /* Not super-user */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Arg list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No children */ -#define EAGAIN 11 /* No more processes */ -#define ENOMEM 12 /* Not enough core */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Mount device busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* Too many open files in system */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math arg out of domain of func */ -#define ERANGE 34 /* Math result not representable */ -#define ENOMSG 35 /* No message of desired type */ -#define EIDRM 36 /* Identifier removed */ -#define ECHRNG 37 /* Channel number out of range */ -#define EL2NSYNC 38 /* Level 2 not synchronized */ -#define EL3HLT 39 /* Level 3 halted */ -#define EL3RST 40 /* Level 3 reset */ -#define ELNRNG 41 /* Link number out of range */ -#define EUNATCH 42 /* Protocol driver not attached */ -#define ENOCSI 43 /* No CSI structure available */ -#define EL2HLT 44 /* Level 2 halted */ -#define EDEADLK 45 /* Deadlock condition */ -#define ENOLCK 46 /* No record locks available */ -#define EBADE 50 /* Invalid exchange */ -#define EBADR 51 /* Invalid request descriptor */ -#define EXFULL 52 /* Exchange full */ -#define ENOANO 53 /* No anode */ -#define EBADRQC 54 /* Invalid request code */ -#define EBADSLT 55 /* Invalid slot */ -#define EDEADLOCK 56 /* File locking deadlock error */ -#define EBFONT 57 /* Bad font file fmt */ -#define ENOSTR 60 /* Device not a stream */ -#define ENODATA 61 /* No data (for no delay io) */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ -#define ENONET 64 /* Machine is not on the network */ -#define ENOPKG 65 /* Package not installed */ -#define EREMOTE 66 /* The object is remote */ -#define ENOLINK 67 /* The link has been severed */ -#define EADV 68 /* Advertise error */ -#define ESRMNT 69 /* Srmount error */ -#define ECOMM 70 /* Communication error on send */ -#define EPROTO 71 /* Protocol error */ -#define EMULTIHOP 74 /* Multihop attempted */ -#define ELBIN 75 /* Inode is remote (not really error) */ -#define EDOTDOT 76 /* Cross mount point (not really error) */ -#define EBADMSG 77 /* Trying to read unreadable message */ -#define ENOTUNIQ 80 /* Given log. name not unique */ -#define EBADFD 81 /* f.d. invalid for this operation */ -#define EREMCHG 82 /* Remote address changed */ -#define ELIBACC 83 /* Can't access a needed shared lib */ -#define ELIBBAD 84 /* Accessing a corrupted shared lib */ -#define ELIBSCN 85 /* .lib section in a.out corrupted */ -#define ELIBMAX 86 /* Attempting to link in too many libs */ -#define ELIBEXEC 87 /* Attempting to exec a shared library */ -#define ENOSYS 88 /* Function not implemented */ -#define ENMFILE 89 /* No more files */ -#define ENOTEMPTY 90 /* Directory not empty */ -#define ENAMETOOLONG 91 /* File or path name too long */ -#define ELOOP 92 /* Too many symbolic links */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#define ECONNRESET 104 /* Connection reset by peer */ -#define ENOBUFS 105 /* No buffer space available */ -#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ -#define EPROTOTYPE 107 /* Protocol wrong type for socket */ -#define ENOTSOCK 108 /* Socket operation on non-socket */ -#define ENOPROTOOPT 109 /* Protocol not available */ -#define ESHUTDOWN 110 /* Can't send after socket shutdown */ -#define ECONNREFUSED 111 /* Connection refused */ -#define EADDRINUSE 112 /* Address already in use */ -#define ECONNABORTED 113 /* Connection aborted */ -#define ENETUNREACH 114 /* Network is unreachable */ -#define ENETDOWN 115 /* Network interface is not configured */ -#define ETIMEDOUT 116 /* Connection timed out */ -#define EHOSTDOWN 117 /* Host is down */ -#define EHOSTUNREACH 118 /* Host is unreachable */ -#define EINPROGRESS 119 /* Connection already in progress */ -#define EALREADY 120 /* Socket already connected */ -#define EDESTADDRREQ 121 /* Destination address required */ -#define EMSGSIZE 122 /* Message too long */ -#define EPROTONOSUPPORT 123 /* Unknown protocol */ -#define ESOCKTNOSUPPORT 124 /* Socket type not supported */ -#define EADDRNOTAVAIL 125 /* Address not available */ -#define ENETRESET 126 -#define EISCONN 127 /* Socket is already connected */ -#define ENOTCONN 128 /* Socket is not connected */ -#define ETOOMANYREFS 129 -#define EPROCLIM 130 -#define EUSERS 131 -#define EDQUOT 132 -#define ESTALE 133 -#define ENOTSUP 134 /* Not supported */ -#define ENOMEDIUM 135 /* No medium (in tape drive) */ -#define ENOSHARE 136 /* No such host or network path */ -#define ECASECLASH 137 /* Filename exists with different case */ - -/* From cygwin32. */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ - -#define __ELASTERROR 2000 /* Users can add values starting here */ - -#endif /* _SYS_ERRNO_H */ -#endif /* !SIMULATOR */ diff --git a/firmware/include/file.h b/firmware/include/file.h index ec0ab87759..2d5c9b88ab 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h @@ -23,6 +23,7 @@ #define _FILE_H_ #include +#include "_ansi.h" #undef MAX_PATH /* this avoids problems when building simulator */ #define MAX_PATH 260 @@ -94,5 +95,5 @@ extern int rename(const char* path, const char* newname); extern int ftruncate(int fd, off_t length); extern off_t filesize(int fd); extern int release_files(int volume); - +int fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); #endif diff --git a/firmware/include/format.h b/firmware/include/format.h new file mode 100644 index 0000000000..6a00574644 --- /dev/null +++ b/firmware/include/format.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Felix Arends + * + * 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. + * + ****************************************************************************/ + +#ifndef __FORMAT_H__ +#define __FORMAT_H__ + +int format( + /* call 'push()' for each output letter */ + int (*push)(void *userp, unsigned char data), + void *userp, + const char *fmt, + va_list ap); + +/* callback function is called for every output character (byte) with userp and + * should return 0 when ch is a char other than '\0' that should stop printing */ +int vuprintf(int (*push)(void *userp, unsigned char data), + void *userp, const char *fmt, va_list ap); + +#endif /* __FORMAT_H__ */ diff --git a/firmware/include/inttypes.h b/firmware/include/inttypes.h deleted file mode 100644 index f7f5099bd7..0000000000 --- a/firmware/include/inttypes.h +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2005 by Dave Chapman - * - * 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. - * - ****************************************************************************/ - -#ifndef __INTTYPES_H__ -#define __INTTYPES_H__ - -#ifndef WPSEDITOR - -#include - -/* 8 bit */ -#define INT8_MIN SCHAR_MIN -#define INT8_MAX SCHAR_MAX -#define UINT8_MAX UCHAR_MAX -#define int8_t signed char -#define uint8_t unsigned char - -/* 16 bit */ -#if USHRT_MAX == 0xffff - -#define INT16_MIN SHRT_MIN -#define INT16_MAX SHRT_MAX -#define UINT16_MAX USHRT_MAX -#define int16_t short -#define uint16_t unsigned short - -#endif - -/* 32 bit */ -#if ULONG_MAX == 0xfffffffful - -#define INT32_MIN LONG_MIN -#define INT32_MAX LONG_MAX -#define UINT32_MAX ULONG_MAX -#define int32_t long -#define uint32_t unsigned long - -#define INTPTR_MIN LONG_MIN -#define INTPTR_MAX LONG_MAX -#define UINTPTR_MAX ULONG_MAX -#define intptr_t long -#define uintptr_t unsigned long - -#elif UINT_MAX == 0xffffffffu - -#define INT32_MIN INT_MIN -#define INT32_MAX INT_MAX -#define UINT32_MAX UINT_MAX -#define int32_t int -#define uint32_t unsigned int - -#endif - -/* 64 bit */ -#ifndef LLONG_MIN -#define LLONG_MIN ((long long)9223372036854775808ull) -#endif - -#ifndef LLONG_MAX -#define LLONG_MAX 9223372036854775807ll -#endif - -#ifndef ULLONG_MAX -#define ULLONG_MAX 18446744073709551615ull -#endif - -#if ULONG_MAX == 0xffffffffffffffffull - -#define INT64_MIN LONG_MIN -#define INT64_MAX LONG_MAX -#define UINT64_MAX ULONG_MAX -#define int64_t long -#define uint64_t unsigned long - -#define INTPTR_MIN LONG_MIN -#define INTPTR_MAX LONG_MAX -#define UINTPTR_MAX ULONG_MAX -#define intptr_t long -#define uintptr_t unsigned long - -#else - -#define INT64_MIN LLONG_MIN -#define INT64_MAX LLONG_MAX -#define UINT64_MAX ULLONG_MAX -#define int64_t long long -#define uint64_t unsigned long long - -#endif -#else -#include -#endif /* !WPSEDITOR*/ - -#endif /* __INTTYPES_H__ */ diff --git a/firmware/include/memory.h b/firmware/include/memory.h index 0b12629049..d025bce610 100644 --- a/firmware/include/memory.h +++ b/firmware/include/memory.h @@ -22,7 +22,7 @@ #ifndef _MEMORY_H_ #define _MEMORY_H_ -#include +#include "inttypes.h" void memset16(void *dst, int val, size_t len); diff --git a/firmware/include/sprintf.h b/firmware/include/sprintf.h deleted file mode 100644 index 869b73eb13..0000000000 --- a/firmware/include/sprintf.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Felix Arends - * - * 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. - * - ****************************************************************************/ - -#ifndef __SPRINTF_H__ -#define __SPRINTF_H__ - -#include -#include -#include <_ansi.h> - -int snprintf (char *buf, size_t size, const char *fmt, ...) - ATTRIBUTE_PRINTF(3, 4); - -int vsnprintf (char *buf, int size, const char *fmt, va_list ap); -int fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); - -/* callback function is called for every output character (byte) with userp and - * should return 0 when ch is a char other than '\0' that should stop printing */ -int vuprintf(int (*push)(void *userp, unsigned char data), - void *userp, const char *fmt, va_list ap); - -#endif /* __SPRINTF_H__ */ diff --git a/firmware/include/sscanf.h b/firmware/include/sscanf.h deleted file mode 100644 index 26f63dd16d..0000000000 --- a/firmware/include/sscanf.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Tomasz Malesinski - * - * 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. - * - ****************************************************************************/ - -#ifndef __SSCANF_H__ -#define __SSCANF_H__ - -#include -#include -#include <_ansi.h> - -int sscanf(const char *s, const char *fmt, ...) - ATTRIBUTE_SCANF(2, 3); - -#endif /* __SSCANF_H__ */ diff --git a/firmware/include/stdio.h b/firmware/include/stdio.h deleted file mode 100644 index 6ae2ff603a..0000000000 --- a/firmware/include/stdio.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _STDIO_H_ -#define _STDIO_H_ - -#include <_ansi.h> - -#define __need_size_t -#include - -#define __need___va_list -#include - -#ifndef NULL -#define NULL 0 -#endif - -#define EOF (-1) - -#ifndef SEEK_SET -#define SEEK_SET 0 /* set file offset to offset */ -#endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#endif -#ifndef SEEK_END -#define SEEK_END 2 /* set file offset to EOF plus offset */ -#endif - -#define TMP_MAX 26 - -#ifdef __GNUC__ -#define __VALIST __gnuc_va_list -#else -#define __VALIST char* -#endif - -int snprintf (char *buf, size_t size, const char *fmt, ...); -int vsnprintf (char *buf, int size, const char *fmt, __VALIST ap); - -#ifdef SIMULATOR -typedef void FILE; -int vfprintf(FILE *stream, const char *format, __VALIST ap); -#ifdef WIN32 -#define FILENAME_MAX 260 /* ugly hard-coded value of a limit that is set - in file.h */ -#endif -#endif - -#endif /* _STDIO_H_ */ diff --git a/firmware/include/stdlib.h b/firmware/include/stdlib.h deleted file mode 100644 index 6de00c816d..0000000000 --- a/firmware/include/stdlib.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * stdlib.h - * - * Definitions for common types, variables, and functions. - */ - -#ifndef _STDLIB_H_ -#ifdef __cplusplus -extern "C" { -#endif -#define _STDLIB_H_ - -#include "_ansi.h" - -#define __need_size_t -#define __need_wchar_t -#include - -#ifndef NULL -#define NULL ((void*)0) -#endif - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, int(*_compar)(const _PTR, const _PTR))); - -void *malloc(size_t); -void *calloc (size_t nmemb, size_t size); -void free(void *); -void *realloc(void *, size_t); - -#define RAND_MAX INT_MAX - -void srand(unsigned int seed); -int rand(void); - -#ifndef ABS -#if defined(__GNUC__) -#define ABS(a) ({typeof (a) ___a = (a); ___a < 0 ? -___a: ___a; }) -#else -#define ABS(a) (((a) < 0) ? -(a) : (a)) -#endif /* __GNUC__ */ -#endif - -#define abs(x) (ABS(x)) -#define labs(x) abs(x) - -#ifdef SIMULATOR -void exit(int status); -#endif - -int atoi (const char *str); - -#ifdef __cplusplus -} -#endif -#endif /* _STDLIB_H_ */ diff --git a/firmware/include/strcasecmp.h b/firmware/include/strcasecmp.h new file mode 100644 index 0000000000..630f3c9fd8 --- /dev/null +++ b/firmware/include/strcasecmp.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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. + * + ****************************************************************************/ + + +#ifndef __STRCASECMP_H__ +#define __STRCASECMP_H__ +#include +int strcasecmp(const char *s1, const char *s2); +int strncasecmp(const char *s1, const char *s2, size_t n); +#endif diff --git a/firmware/include/strcasestr.h b/firmware/include/strcasestr.h new file mode 100644 index 0000000000..a6d2f2c472 --- /dev/null +++ b/firmware/include/strcasestr.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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. + * + ****************************************************************************/ + + +#ifndef __STRLCASESTR_H__ +#define __STRLCASESTR_H__ +char *strcasestr(const char *, const char *); +#endif diff --git a/firmware/include/string-extra.h b/firmware/include/string-extra.h new file mode 100644 index 0000000000..5fe5ab8119 --- /dev/null +++ b/firmware/include/string-extra.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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 "strlcpy.h" +#include "strlcat.h" +#include "strcasecmp.h" +#include "strcasestr.h" diff --git a/firmware/include/string.h b/firmware/include/string.h deleted file mode 100644 index 1a2e056717..0000000000 --- a/firmware/include/string.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * string.h - * - * Definitions for memory and string functions. - */ - -#ifndef _STRING_H_ -#define _STRING_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "_ansi.h" - -#define __need_size_t -#include - -#ifndef NULL -#define NULL ((void*)0) -#endif - -_PTR _EXFUN(memchr,(const _PTR, int, size_t)); -int _EXFUN(memcmp,(const _PTR, const _PTR, size_t)); -_PTR _EXFUN(memcpy,(_PTR, const _PTR, size_t)); -_PTR _EXFUN(memmove,(_PTR, const _PTR, size_t)); -_PTR _EXFUN(memset,(_PTR, int, size_t)); -char *_EXFUN(strcat,(char *, const char *)); -char *_EXFUN(strchr,(const char *, int)); -int _EXFUN(strcmp,(const char *, const char *)); -int _EXFUN(strcoll,(const char *, const char *)); -char *_EXFUN(strcpy,(char *, const char *)); -size_t _EXFUN(strcspn,(const char *, const char *)); -char *_EXFUN(strerror,(int)); -size_t _EXFUN(strlen,(const char *)); -char *_EXFUN(strncat,(char *, const char *, size_t)); -int _EXFUN(strncmp,(const char *, const char *, size_t)); -char *_EXFUN(strpbrk,(const char *, const char *)); -char *_EXFUN(strrchr,(const char *, int)); -size_t _EXFUN(strspn,(const char *, const char *)); -char *_EXFUN(strstr,(const char *, const char *)); -char *_EXFUN(strcasestr,(const char *, const char *)); - -size_t strlcpy(char *dst, const char *src, size_t siz); -size_t strlcat(char *dst, const char *src, size_t siz); - -#ifndef _REENT_ONLY -char *_EXFUN(strtok,(char *, const char *)); -#endif - -size_t _EXFUN(strxfrm,(char *, const char *, size_t)); - -#ifndef __STRICT_ANSI__ -char *_EXFUN(strtok_r,(char *, const char *, char **)); - -_PTR _EXFUN(memccpy,(_PTR, const _PTR, int, size_t)); -int _EXFUN(strcasecmp,(const char *, const char *)); -int _EXFUN(strncasecmp,(const char *, const char *, size_t)); - -#ifdef __CYGWIN__ -#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ -const char *_EXFUN(strsignal, (int __signo)); -#endif -int _EXFUN(strtosigno, (const char *__name)); -#endif - -/* These function names are used on Windows and perhaps other systems. */ -#ifndef strcmpi -#define strcmpi strcasecmp -#endif -#ifndef stricmp -#define stricmp strcasecmp -#endif -#ifndef strncmpi -#define strncmpi strncasecmp -#endif -#ifndef strnicmp -#define strnicmp strncasecmp -#endif - -#endif /* ! __STRICT_ANSI__ */ - -#ifdef __cplusplus -} -#endif -#endif /* _STRING_H_ */ diff --git a/firmware/include/strlcat.h b/firmware/include/strlcat.h new file mode 100644 index 0000000000..dbde60c21b --- /dev/null +++ b/firmware/include/strlcat.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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. + * + ****************************************************************************/ + + +#ifndef __STRLCAT_H__ +#define __STRLCAT_H__ +size_t strlcat(char *dst, const char *src, size_t siz); +#endif diff --git a/firmware/include/strlcpy.h b/firmware/include/strlcpy.h new file mode 100644 index 0000000000..f94ed52ba8 --- /dev/null +++ b/firmware/include/strlcpy.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * 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. + * + ****************************************************************************/ + + +#ifndef __STRLCPY_H__ +#define __STRLCPY_H__ +size_t strlcpy(char *dst, const char *src, size_t siz); +#endif diff --git a/firmware/include/sys/types.h b/firmware/include/sys/types.h index 95181dab19..07f9e9c8c7 100644 --- a/firmware/include/sys/types.h +++ b/firmware/include/sys/types.h @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2005 by Daniel Stenberg + * Copyright (C) 2010 Thomas Martitz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -19,8 +19,17 @@ * ****************************************************************************/ -#ifndef _SYS_TYPES_H_ -#define _SYS_TYPES_H_ +/** + * provide a sys/types.h for compatibility with imported code + **/ + +#ifndef __TYPES_H__ +#define __TYPES_H__ + + +/* + * include string.h for size_t for convinence */ +#include #if !defined(__ssize_t_defined) && !defined(_SSIZE_T_) && !defined(ssize_t) && !defined(_SSIZE_T_DECLARED) #define __ssize_t_defined @@ -43,10 +52,4 @@ typedef signed long off_t; typedef unsigned int mode_t; #endif -#if !defined(_SIZE_T) && !defined(_SIZE_T_DECLARED) -#define _SIZE_T -#define _SIZE_T_DECLARED -typedef unsigned long size_t; -#endif - -#endif /* _SYS_TYPES_H */ +#endif /* __TYPES_H__ */ diff --git a/firmware/include/time.h b/firmware/include/time.h deleted file mode 100644 index 28680494f9..0000000000 --- a/firmware/include/time.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * time.h - * - * Struct declaration for dealing with time. - */ - -#ifndef _TIME_H_ -#define _TIME_H_ - -#ifdef WPSEDITOR -#include -#include -#endif - -struct tm -{ - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; -}; - -#if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED) -typedef long time_t; - -/* this define below is used by the mingw headers to prevent duplicate - typedefs */ -#define _TIME_T_DEFINED -#define _TIME_T_DECLARED -time_t time(time_t *t); -struct tm *localtime(const time_t *timep); - -#endif /* SIMULATOR */ - -#ifdef __PCTOOL__ -/* this time.h does not define struct timespec, - so tell sys/stat.h not to use it */ -#undef __USE_MISC -#endif - - -#endif /* _TIME_H_ */ - - diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h index f51fa996cc..86a41a516b 100644 --- a/firmware/include/timefuncs.h +++ b/firmware/include/timefuncs.h @@ -30,9 +30,6 @@ struct tm *get_time(void); int set_time(const struct tm *tm); bool valid_time(const struct tm *tm); void set_day_of_week(struct tm *tm); -#if CONFIG_RTC -time_t mktime(struct tm *t); -#endif #endif /* _TIMEFUNCS_H_ */ diff --git a/firmware/libc/atoi.c b/firmware/libc/atoi.c new file mode 100644 index 0000000000..3393839b27 --- /dev/null +++ b/firmware/libc/atoi.c @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Gary Czvitkovicz + * + * 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 "ctype.h" + +int atoi (const char *str) +{ + int value = 0; + int sign = 1; + + while (isspace(*str)) + { + str++; + } + + if ('-' == *str) + { + sign = -1; + str++; + } + else if ('+' == *str) + { + str++; + } + + while ('0' == *str) + { + str++; + } + + while (isdigit(*str)) + { + value = (value * 10) + (*str - '0'); + str++; + } + + return value * sign; +} diff --git a/firmware/libc/ctype.c b/firmware/libc/ctype.c new file mode 100644 index 0000000000..6e9b4eb601 --- /dev/null +++ b/firmware/libc/ctype.c @@ -0,0 +1,22 @@ +#include + +const unsigned char _ctype_[257]={ + 0, + _C, _C, _C, _C, _C, _C, _C, _C, + _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, + _C, _C, _C, _C, _C, _C, _C, _C, + _C, _C, _C, _C, _C, _C, _C, _C, + _S|_B, _P, _P, _P, _P, _P, _P, _P, + _P, _P, _P, _P, _P, _P, _P, _P, + _N, _N, _N, _N, _N, _N, _N, _N, + _N, _N, _P, _P, _P, _P, _P, _P, + _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, + _U, _U, _U, _U, _U, _U, _U, _U, + _U, _U, _U, _U, _U, _U, _U, _U, + _U, _U, _U, _P, _P, _P, _P, _P, + _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, + _L, _L, _L, _L, _L, _L, _L, _L, + _L, _L, _L, _L, _L, _L, _L, _L, + _L, _L, _L, _P, _P, _P, _P, _C +}; + diff --git a/firmware/libc/errno.c b/firmware/libc/errno.c new file mode 100644 index 0000000000..6e7bb62b51 --- /dev/null +++ b/firmware/libc/errno.c @@ -0,0 +1 @@ +int errno; diff --git a/firmware/libc/include/ctype.h b/firmware/libc/include/ctype.h new file mode 100644 index 0000000000..648e06dc5c --- /dev/null +++ b/firmware/libc/include/ctype.h @@ -0,0 +1,75 @@ +#ifndef _CTYPE_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _CTYPE_H_ + +#include "_ansi.h" + +int _EXFUN(isalnum, (int __c)); +int _EXFUN(isalpha, (int __c)); +int _EXFUN(iscntrl, (int __c)); +int _EXFUN(isdigit, (int __c)); +int _EXFUN(isgraph, (int __c)); +int _EXFUN(islower, (int __c)); +int _EXFUN(isprint, (int __c)); +int _EXFUN(ispunct, (int __c)); +int _EXFUN(isspace, (int __c)); +int _EXFUN(isupper, (int __c)); +int _EXFUN(isxdigit,(int __c)); +int _EXFUN(tolower, (int __c)); +int _EXFUN(toupper, (int __c)); + +#ifndef __STRICT_ANSI__ +int _EXFUN(isascii, (int __c)); +int _EXFUN(toascii, (int __c)); +int _EXFUN(_tolower, (int __c)); +int _EXFUN(_toupper, (int __c)); +#endif + +#define _U 01 +#define _L 02 +#define _N 04 +#define _S 010 +#define _P 020 +#define _C 040 +#define _X 0100 +#define _B 0200 + +#ifdef PLUGIN +#define _ctype_ (rb->_rbctype_) +#else +extern const unsigned char _ctype_[257]; +#endif + +#ifndef __cplusplus +#define isalpha(c) ((_ctype_+1)[(unsigned char)(c)]&(_U|_L)) +#define isupper(c) ((_ctype_+1)[(unsigned char)(c)]&_U) +#define islower(c) ((_ctype_+1)[(unsigned char)(c)]&_L) +#define isdigit(c) ((_ctype_+1)[(unsigned char)(c)]&_N) +#define isxdigit(c) ((_ctype_+1)[(unsigned char)(c)]&(_X|_N)) +#define isspace(c) ((_ctype_+1)[(unsigned char)(c)]&_S) +#define ispunct(c) ((_ctype_+1)[(unsigned char)(c)]&_P) +#define isalnum(c) ((_ctype_+1)[(unsigned char)(c)]&(_U|_L|_N)) +#define isprint(c) ((_ctype_+1)[(unsigned char)(c)]&(_P|_U|_L|_N|_B)) +#define isgraph(c) ((_ctype_+1)[(unsigned char)(c)]&(_P|_U|_L|_N)) +#define iscntrl(c) ((_ctype_+1)[(unsigned char)(c)]&_C) +/* Non-gcc versions will get the library versions, and will be + slightly slower */ +#ifdef __GNUC__ +# define toupper(c) \ + __extension__ ({ int __x = (unsigned char) (c); islower(__x) ? (__x - 'a' + 'A') : __x;}) +# define tolower(c) \ + __extension__ ({ int __x = (unsigned char) (c); isupper(__x) ? (__x - 'A' + 'a') : __x;}) +#endif +#endif /* !__cplusplus */ + +#ifndef __STRICT_ANSI__ +#define isascii(c) ((unsigned char)(c)<=0177) +#define toascii(c) ((c)&0177) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _CTYPE_H_ */ diff --git a/firmware/libc/include/errno.h b/firmware/libc/include/errno.h new file mode 100644 index 0000000000..6a24a1938f --- /dev/null +++ b/firmware/libc/include/errno.h @@ -0,0 +1,145 @@ +/* errno is not a global variable, because that would make using it + non-reentrant. Instead, its address is returned by the function + __errno. */ + +#if (defined(SIMULATOR)||defined(__PCTOOL__)) && !defined(__MINGW32__) && !defined(__CYGWIN__) + +#include "/usr/include/errno.h" /* use the host system implementation */ + +#else /* use our own implementation */ + +#ifndef _SYS_ERRNO_H_ + +#ifdef PLUGIN +#define errno (*rb->__errno) +#else +extern int errno; +#endif + +#define EPERM 1 /* Not super-user */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No children */ +#define EAGAIN 11 /* No more processes */ +#define ENOMEM 12 /* Not enough core */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Mount device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math arg out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define ENOMSG 35 /* No message of desired type */ +#define EIDRM 36 /* Identifier removed */ +#define ECHRNG 37 /* Channel number out of range */ +#define EL2NSYNC 38 /* Level 2 not synchronized */ +#define EL3HLT 39 /* Level 3 halted */ +#define EL3RST 40 /* Level 3 reset */ +#define ELNRNG 41 /* Link number out of range */ +#define EUNATCH 42 /* Protocol driver not attached */ +#define ENOCSI 43 /* No CSI structure available */ +#define EL2HLT 44 /* Level 2 halted */ +#define EDEADLK 45 /* Deadlock condition */ +#define ENOLCK 46 /* No record locks available */ +#define EBADE 50 /* Invalid exchange */ +#define EBADR 51 /* Invalid request descriptor */ +#define EXFULL 52 /* Exchange full */ +#define ENOANO 53 /* No anode */ +#define EBADRQC 54 /* Invalid request code */ +#define EBADSLT 55 /* Invalid slot */ +#define EDEADLOCK 56 /* File locking deadlock error */ +#define EBFONT 57 /* Bad font file fmt */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data (for no delay io) */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* The object is remote */ +#define ENOLINK 67 /* The link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 74 /* Multihop attempted */ +#define ELBIN 75 /* Inode is remote (not really error) */ +#define EDOTDOT 76 /* Cross mount point (not really error) */ +#define EBADMSG 77 /* Trying to read unreadable message */ +#define ENOTUNIQ 80 /* Given log. name not unique */ +#define EBADFD 81 /* f.d. invalid for this operation */ +#define EREMCHG 82 /* Remote address changed */ +#define ELIBACC 83 /* Can't access a needed shared lib */ +#define ELIBBAD 84 /* Accessing a corrupted shared lib */ +#define ELIBSCN 85 /* .lib section in a.out corrupted */ +#define ELIBMAX 86 /* Attempting to link in too many libs */ +#define ELIBEXEC 87 /* Attempting to exec a shared library */ +#define ENOSYS 88 /* Function not implemented */ +#define ENMFILE 89 /* No more files */ +#define ENOTEMPTY 90 /* Directory not empty */ +#define ENAMETOOLONG 91 /* File or path name too long */ +#define ELOOP 92 /* Too many symbolic links */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ +#define EPROTOTYPE 107 /* Protocol wrong type for socket */ +#define ENOTSOCK 108 /* Socket operation on non-socket */ +#define ENOPROTOOPT 109 /* Protocol not available */ +#define ESHUTDOWN 110 /* Can't send after socket shutdown */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EADDRINUSE 112 /* Address already in use */ +#define ECONNABORTED 113 /* Connection aborted */ +#define ENETUNREACH 114 /* Network is unreachable */ +#define ENETDOWN 115 /* Network interface is not configured */ +#define ETIMEDOUT 116 /* Connection timed out */ +#define EHOSTDOWN 117 /* Host is down */ +#define EHOSTUNREACH 118 /* Host is unreachable */ +#define EINPROGRESS 119 /* Connection already in progress */ +#define EALREADY 120 /* Socket already connected */ +#define EDESTADDRREQ 121 /* Destination address required */ +#define EMSGSIZE 122 /* Message too long */ +#define EPROTONOSUPPORT 123 /* Unknown protocol */ +#define ESOCKTNOSUPPORT 124 /* Socket type not supported */ +#define EADDRNOTAVAIL 125 /* Address not available */ +#define ENETRESET 126 +#define EISCONN 127 /* Socket is already connected */ +#define ENOTCONN 128 /* Socket is not connected */ +#define ETOOMANYREFS 129 +#define EPROCLIM 130 +#define EUSERS 131 +#define EDQUOT 132 +#define ESTALE 133 +#define ENOTSUP 134 /* Not supported */ +#define ENOMEDIUM 135 /* No medium (in tape drive) */ +#define ENOSHARE 136 /* No such host or network path */ +#define ECASECLASH 137 /* Filename exists with different case */ + +/* From cygwin32. */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ + +#define __ELASTERROR 2000 /* Users can add values starting here */ + +#endif /* _SYS_ERRNO_H */ +#endif /* !SIMULATOR */ diff --git a/firmware/libc/include/inttypes.h b/firmware/libc/include/inttypes.h new file mode 100644 index 0000000000..c03609c6d8 --- /dev/null +++ b/firmware/libc/include/inttypes.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Dave Chapman + * + * 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. + * + ****************************************************************************/ + +#ifndef __INTTYPES_H__ +#define __INTTYPES_H__ + +#include + +/* could possibly have (f)printf format specifies here */ + +#endif /* __INTTYPES_H__ */ diff --git a/firmware/libc/include/stdint.h b/firmware/libc/include/stdint.h new file mode 100644 index 0000000000..93f234c0e8 --- /dev/null +++ b/firmware/libc/include/stdint.h @@ -0,0 +1,107 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Dave Chapman + * + * 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. + * + ****************************************************************************/ + +#ifndef __STDINT_H__ +#define __STDINT_H__ + +#include + +/* 8 bit */ +#define INT8_MIN SCHAR_MIN +#define INT8_MAX SCHAR_MAX +#define UINT8_MAX UCHAR_MAX +#define int8_t signed char +#define uint8_t unsigned char + +/* 16 bit */ +#if USHRT_MAX == 0xffff + +#define INT16_MIN SHRT_MIN +#define INT16_MAX SHRT_MAX +#define UINT16_MAX USHRT_MAX +#define int16_t short +#define uint16_t unsigned short + +#endif + +/* 32 bit */ +#if ULONG_MAX == 0xfffffffful + +#define INT32_MIN LONG_MIN +#define INT32_MAX LONG_MAX +#define UINT32_MAX ULONG_MAX +#define int32_t long +#define uint32_t unsigned long + +#define INTPTR_MIN LONG_MIN +#define INTPTR_MAX LONG_MAX +#define UINTPTR_MAX ULONG_MAX +#define intptr_t long +#define uintptr_t unsigned long + +#elif UINT_MAX == 0xffffffffu + +#define INT32_MIN INT_MIN +#define INT32_MAX INT_MAX +#define UINT32_MAX UINT_MAX +#define int32_t int +#define uint32_t unsigned int + +#endif + +/* 64 bit */ +#ifndef LLONG_MIN +#define LLONG_MIN ((long long)9223372036854775808ull) +#endif + +#ifndef LLONG_MAX +#define LLONG_MAX 9223372036854775807ll +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX 18446744073709551615ull +#endif + +#if ULONG_MAX == 0xffffffffffffffffull + +#define INT64_MIN LONG_MIN +#define INT64_MAX LONG_MAX +#define UINT64_MAX ULONG_MAX +#define int64_t long +#define uint64_t unsigned long + +#define INTPTR_MIN LONG_MIN +#define INTPTR_MAX LONG_MAX +#define UINTPTR_MAX ULONG_MAX +#define intptr_t long +#define uintptr_t unsigned long + +#else + +#define INT64_MIN LLONG_MIN +#define INT64_MAX LLONG_MAX +#define UINT64_MAX ULLONG_MAX +#define int64_t long long +#define uint64_t unsigned long long + +#endif + +#endif /* __STDINT_H__ */ diff --git a/firmware/libc/include/stdio.h b/firmware/libc/include/stdio.h new file mode 100644 index 0000000000..d9a6dce55f --- /dev/null +++ b/firmware/libc/include/stdio.h @@ -0,0 +1,60 @@ +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include <_ansi.h> + +#define __need_size_t +#include + +#define __need___va_list +#include + +#ifndef NULL +#define NULL 0 +#endif + +#define EOF (-1) + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define TMP_MAX 26 + +#ifdef __GNUC__ +#define __VALIST __gnuc_va_list +#else +#define __VALIST char* +#endif + +int vsnprintf (char *buf, size_t size, const char *fmt, __VALIST ap); + +int sprintf (char *buf, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); + +int snprintf (char *buf, size_t size, const char *fmt, ...) + ATTRIBUTE_PRINTF(3, 4); + +/* callback function is called for every output character (byte) with userp and + * should return 0 when ch is a char other than '\0' that should stop printing */ +int vuprintf(int (*push)(void *userp, unsigned char data), + void *userp, const char *fmt, __VALIST ap); + +int sscanf(const char *s, const char *fmt, ...) + ATTRIBUTE_SCANF(2, 3); + +#ifdef SIMULATOR +typedef void FILE; +int vfprintf(FILE *stream, const char *format, __VALIST ap); +#ifdef WIN32 +#define FILENAME_MAX 260 /* ugly hard-coded value of a limit that is set + in file.h */ +#endif +#endif + +#endif /* _STDIO_H_ */ diff --git a/firmware/libc/include/stdlib.h b/firmware/libc/include/stdlib.h new file mode 100644 index 0000000000..5f6db6da8a --- /dev/null +++ b/firmware/libc/include/stdlib.h @@ -0,0 +1,58 @@ +/* + * stdlib.h + * + * Definitions for common types, variables, and functions. + */ + +#ifndef _STDLIB_H_ +#ifdef __cplusplus +extern "C" { +#endif +#define _STDLIB_H_ + +#include "_ansi.h" + +#define __need_size_t +#define __need_wchar_t +#include + +#ifndef NULL +#define NULL ((void*)0) +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, int(*_compar)(const _PTR, const _PTR))); + +void *malloc(size_t); +void *calloc (size_t nmemb, size_t size); +void free(void *); +void *realloc(void *, size_t); + +#define RAND_MAX INT_MAX + +void srand(unsigned int seed); +int rand(void); + +#ifndef ABS +#if defined(__GNUC__) +#define ABS(a) ({typeof (a) ___a = (a); ___a < 0 ? -___a: ___a; }) +#else +#define ABS(a) (((a) < 0) ? -(a) : (a)) +#endif /* __GNUC__ */ +#endif + +#define abs(x) ((int)ABS(x)) +#define labs(x) ((long)abs(x)) + +#ifdef SIMULATOR +void exit(int status); +#endif + +int atoi (const char *str); + +#ifdef __cplusplus +} +#endif +#endif /* _STDLIB_H_ */ diff --git a/firmware/libc/include/string.h b/firmware/libc/include/string.h new file mode 100644 index 0000000000..8986bd6a0c --- /dev/null +++ b/firmware/libc/include/string.h @@ -0,0 +1,94 @@ +/* + * string.h + * + * Definitions for memory and string functions. + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "_ansi.h" + +#include + +#if !defined(__size_t_defined)&& !defined(_SIZE_T_) && !defined(size_t) && !defined(_SIZE_T_DECLARED) +#define __size_t_defined +#define _SIZE_T +#define _SIZE_T_ +#define _SIZE_T_DECLARED +#define size_t size_t +typedef unsigned long size_t; +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +_PTR _EXFUN(memchr,(const _PTR, int, size_t)); +int _EXFUN(memcmp,(const _PTR, const _PTR, size_t)); +_PTR _EXFUN(memcpy,(_PTR, const _PTR, size_t)); +_PTR _EXFUN(memmove,(_PTR, const _PTR, size_t)); +_PTR _EXFUN(memset,(_PTR, int, size_t)); +char *_EXFUN(strcat,(char *, const char *)); +char *_EXFUN(strchr,(const char *, int)); +int _EXFUN(strcmp,(const char *, const char *)); +int _EXFUN(strcoll,(const char *, const char *)); +char *_EXFUN(strcpy,(char *, const char *)); +size_t _EXFUN(strcspn,(const char *, const char *)); +char *_EXFUN(strerror,(int)); +size_t _EXFUN(strlen,(const char *)); +char *_EXFUN(strncat,(char *, const char *, size_t)); +int _EXFUN(strncmp,(const char *, const char *, size_t)); +char *_EXFUN(strpbrk,(const char *, const char *)); +char *_EXFUN(strrchr,(const char *, int)); +size_t _EXFUN(strspn,(const char *, const char *)); +char *_EXFUN(strstr,(const char *, const char *)); +char *_EXFUN(strcasestr,(const char *, const char *)); + +size_t strlcpy(char *dst, const char *src, size_t siz); +size_t strlcat(char *dst, const char *src, size_t siz); + +#ifndef _REENT_ONLY +char *_EXFUN(strtok,(char *, const char *)); +#endif + +size_t _EXFUN(strxfrm,(char *, const char *, size_t)); + +#ifndef __STRICT_ANSI__ +char *_EXFUN(strtok_r,(char *, const char *, char **)); + +_PTR _EXFUN(memccpy,(_PTR, const _PTR, int, size_t)); +int _EXFUN(strcasecmp,(const char *, const char *)); +int _EXFUN(strncasecmp,(const char *, const char *, size_t)); + +#ifdef __CYGWIN__ +#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ +const char *_EXFUN(strsignal, (int __signo)); +#endif +int _EXFUN(strtosigno, (const char *__name)); +#endif + +/* These function names are used on Windows and perhaps other systems. */ +#ifndef strcmpi +#define strcmpi strcasecmp +#endif +#ifndef stricmp +#define stricmp strcasecmp +#endif +#ifndef strncmpi +#define strncmpi strncasecmp +#endif +#ifndef strnicmp +#define strnicmp strncasecmp +#endif + +#endif /* ! __STRICT_ANSI__ */ + +#ifdef __cplusplus +} +#endif +#endif /* _STRING_H_ */ diff --git a/firmware/libc/include/time.h b/firmware/libc/include/time.h new file mode 100644 index 0000000000..912fafe7ca --- /dev/null +++ b/firmware/libc/include/time.h @@ -0,0 +1,49 @@ +/* + * time.h + * + * Struct declaration for dealing with time. + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#ifdef WPSEDITOR +#include "inttypes.h" +#include +#endif + +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +}; + +#if !defined(_TIME_T_DEFINED) && !defined(_TIME_T_DECLARED) +typedef long time_t; + +/* this define below is used by the mingw headers to prevent duplicate + typedefs */ +#define _TIME_T_DEFINED +#define _TIME_T_DECLARED +time_t time(time_t *t); +struct tm *localtime(const time_t *timep); +time_t mktime(struct tm *t); + +#endif /* SIMULATOR */ + +#ifdef __PCTOOL__ +/* this time.h does not define struct timespec, + so tell sys/stat.h not to use it */ +#undef __USE_MISC +#endif + +#endif /* _TIME_H_ */ + + diff --git a/firmware/libc/memchr.c b/firmware/libc/memchr.c new file mode 100644 index 0000000000..26bdb9eea3 --- /dev/null +++ b/firmware/libc/memchr.c @@ -0,0 +1,116 @@ +/* +FUNCTION + <>---search for character in memory + +INDEX + memchr + +ANSI_SYNOPSIS + #include + void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include + void * memchr(<[s1]>, <[c]>, <[n]>); + void *<[string]>; + int *<[c]>; + size_t *<[n]>; + +DESCRIPTION + This function scans the first <[n]> bytes of the memory pointed + to by <[s1]> for the character <[c]> (converted to a char). + +RETURNS + Returns a pointer to the matching byte, or a null pointer if + <[c]> does not occur in <[s1]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memchr ansi pure +*/ + +#include +#include + +/* Nonzero if X is not aligned on a "long" boundary. */ +#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) + +/* How many bytes are loaded each iteration of the word copy loop. */ +#define LBLOCKSIZE (sizeof (long)) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +/* DETECTCHAR returns nonzero if (long)X contains the byte used + to fill (long)MASK. */ +#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) + +void * +_DEFUN (memchr, (s1, i, n), + _CONST void *s1 _AND + int i _AND size_t n) +{ + _CONST unsigned char *s = (_CONST unsigned char *)s1; +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + unsigned char c = (unsigned char)i; + + while (n-- > 0) + { + if (*s == c) + { + return (void *)s; + } + s++; + } + + return NULL; +#else + unsigned char c = (unsigned char)i; + unsigned long mask,j; + unsigned long *aligned_addr; + + if (!UNALIGNED (s)) + { + mask = 0; + for (j = 0; j < LBLOCKSIZE; j++) + mask = (mask << 8) | c; + + aligned_addr = (unsigned long*)s; + while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE)) + { + aligned_addr++; + n -= LBLOCKSIZE; + } + + /* The block of bytes currently pointed to by aligned_addr + may contain the target character or there may be less than + LBLOCKSIZE bytes left to search. We check the last few + bytes using the bytewise search. */ + + s = (unsigned char*)aligned_addr; + } + + while (n-- > 0) + { + if (*s == c) + { + return (void *)s; + } + s++; + } + + return NULL; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/memcmp.c b/firmware/libc/memcmp.c new file mode 100644 index 0000000000..1535fcf5b5 --- /dev/null +++ b/firmware/libc/memcmp.c @@ -0,0 +1,113 @@ +/* +FUNCTION + <>---compare two memory areas + +INDEX + memcmp + +ANSI_SYNOPSIS + #include + int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include + int memcmp(<[s1]>, <[s2]>, <[n]>) + void *<[s1]>; + void *<[s2]>; + size_t <[n]>; + +DESCRIPTION + This function compares not more than <[n]> characters of the + object pointed to by <[s1]> with the object pointed to by <[s2]>. + + +RETURNS + The function returns an integer greater than, equal to or + less than zero according to whether the object pointed to by + <[s1]> is greater than, equal to or less than the object + pointed to by <[s2]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memcmp ansi pure +*/ + +#include + + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) + +int +_DEFUN (memcmp, (m1, m2, n), + _CONST _PTR m1 _AND + _CONST _PTR m2 _AND + size_t n) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + unsigned char *s1 = (unsigned char *) m1; + unsigned char *s2 = (unsigned char *) m2; + + while (n--) + { + if (*s1 != *s2) + { + return *s1 - *s2; + } + s1++; + s2++; + } + return 0; +#else + unsigned char *s1 = (unsigned char *) m1; + unsigned char *s2 = (unsigned char *) m2; + unsigned long *a1; + unsigned long *a2; + + /* If the size is too small, or either pointer is unaligned, + then we punt to the byte compare loop. Hopefully this will + not turn up in inner loops. */ + if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) + { + /* Otherwise, load and compare the blocks of memory one + word at a time. */ + a1 = (unsigned long*) s1; + a2 = (unsigned long*) s2; + while (n >= LBLOCKSIZE) + { + if (*a1 != *a2) + break; + a1++; + a2++; + n -= LBLOCKSIZE; + } + + /* check m mod LBLOCKSIZE remaining characters */ + + s1 = (unsigned char*)a1; + s2 = (unsigned char*)a2; + } + + while (n--) + { + if (*s1 != *s2) + return *s1 - *s2; + s1++; + s2++; + } + + return 0; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} + diff --git a/firmware/libc/memcpy.c b/firmware/libc/memcpy.c new file mode 100644 index 0000000000..a89ac3c557 --- /dev/null +++ b/firmware/libc/memcpy.c @@ -0,0 +1,117 @@ +/* +FUNCTION + <>---copy memory regions + +ANSI_SYNOPSIS + #include + void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); + +TRAD_SYNOPSIS + void *memcpy(<[out]>, <[in]>, <[n]> + void *<[out]>; + void *<[in]>; + size_t <[n]>; + +DESCRIPTION + This function copies <[n]> bytes from the memory region + pointed to by <[in]> to the memory region pointed to by + <[out]>. + + If the regions overlap, the behavior is undefined. + +RETURNS + <> returns a pointer to the first byte of the <[out]> + region. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memcpy ansi pure + */ + +#include "config.h" +#include <_ansi.h> +#include + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +_PTR +_DEFUN (memcpy, (dst0, src0, len0), + _PTR dst0 _AND + _CONST _PTR src0 _AND + size_t len0) ICODE_ATTR; + +_PTR +_DEFUN (memcpy, (dst0, src0, len0), + _PTR dst0 _AND + _CONST _PTR src0 _AND + size_t len0) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *dst = (char *) dst0; + char *src = (char *) src0; + + _PTR save = dst0; + + while (len0--) + { + *dst++ = *src++; + } + + return save; +#else + char *dst = dst0; + _CONST char *src = src0; + long *aligned_dst; + _CONST long *aligned_src; + unsigned int len = len0; + + /* If the size is small, or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (len >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + len -= (unsigned int)BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (len >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + len -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while (len--) + *dst++ = *src++; + + return dst0; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/memmove.c b/firmware/libc/memmove.c new file mode 100644 index 0000000000..5f423964bb --- /dev/null +++ b/firmware/libc/memmove.c @@ -0,0 +1,147 @@ +/* +FUNCTION + <>---move possibly overlapping memory + +INDEX + memmove + +ANSI_SYNOPSIS + #include + void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); + +TRAD_SYNOPSIS + #include + void *memmove(<[dst]>, <[src]>, <[length]>) + void *<[dst]>; + void *<[src]>; + size_t <[length]>; + +DESCRIPTION + This function moves <[length]> characters from the block of + memory starting at <<*<[src]>>> to the memory starting at + <<*<[dst]>>>. <> reproduces the characters correctly + at <<*<[dst]>>> even if the two areas overlap. + + +RETURNS + The function returns <[dst]> as passed. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memmove ansi pure +*/ + +#include "config.h" +#include <_ansi.h> +#include + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +_PTR +_DEFUN (memmove, (dst_void, src_void, length), + _PTR dst_void _AND + _CONST _PTR src_void _AND + size_t length) ICODE_ATTR; + +_PTR +_DEFUN (memmove, (dst_void, src_void, length), + _PTR dst_void _AND + _CONST _PTR src_void _AND + size_t length) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *dst = dst_void; + _CONST char *src = src_void; + + if (src < dst && dst < src + length) + { + /* Have to copy backwards */ + src += length; + dst += length; + while (length--) + { + *--dst = *--src; + } + } + else + { + while (length--) + { + *dst++ = *src++; + } + } + + return dst_void; +#else + char *dst = dst_void; + _CONST char *src = src_void; + long *aligned_dst; + _CONST long *aligned_src; + unsigned int len = length; + + if (src < dst && dst < src + len) + { + /* Destructive overlap...have to copy backwards */ + src += len; + dst += len; + while (len--) + { + *--dst = *--src; + } + } + else + { + /* Use optimizing algorithm for a non-destructive copy to closely + match memcpy. If the size is small or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (len >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + len -= BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (len >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + len -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while (len--) + { + *dst++ = *src++; + } + } + + return dst_void; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/memset.c b/firmware/libc/memset.c new file mode 100644 index 0000000000..7b8d2137e8 --- /dev/null +++ b/firmware/libc/memset.c @@ -0,0 +1,110 @@ +/* +FUNCTION + <>---set an area of memory + +INDEX + memset + +ANSI_SYNOPSIS + #include + void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>); + +TRAD_SYNOPSIS + #include + void *memset(<[dst]>, <[c]>, <[length]>) + void *<[dst]>; + int <[c]>; + size_t <[length]>; + +DESCRIPTION + This function converts the argument <[c]> into an unsigned + char and fills the first <[length]> characters of the array + pointed to by <[dst]> to the value. + +RETURNS + <> returns the value of <[m]>. + +PORTABILITY +<> is ANSI C. + + <> requires no supporting OS subroutines. + +QUICKREF + memset ansi pure +*/ + +#include +#include "_ansi.h" + +#define LBLOCKSIZE (sizeof(long)) +#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) +#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) + +_PTR +_DEFUN (memset, (m, c, n), + _PTR m _AND + int c _AND + size_t n) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *s = (char *) m; + + while (n-- != 0) + { + *s++ = (char) c; + } + + return m; +#else + char *s = (char *) m; + unsigned int i; + unsigned long buffer; + unsigned long *aligned_addr; + + if (!TOO_SMALL (n) && !UNALIGNED (m)) + { + /* If we get this far, we know that n is large and m is word-aligned. */ + + aligned_addr = (unsigned long*)m; + + /* Store C into each char sized location in BUFFER so that + we can set large blocks quickly. */ + c &= 0xff; + if (LBLOCKSIZE == 4) + { + buffer = (c << 8) | c; + buffer |= (buffer << 16); + } + else + { + buffer = 0; + for (i = 0; i < LBLOCKSIZE; i++) + buffer = (buffer << 8) | c; + } + + while (n >= LBLOCKSIZE*4) + { + *aligned_addr++ = buffer; + *aligned_addr++ = buffer; + *aligned_addr++ = buffer; + *aligned_addr++ = buffer; + n -= 4*LBLOCKSIZE; + } + + while (n >= LBLOCKSIZE) + { + *aligned_addr++ = buffer; + n -= LBLOCKSIZE; + } + /* Pick up the remainder with a bytewise loop. */ + s = (char*)aligned_addr; + } + + while (n--) + { + *s++ = (char)c; + } + + return m; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/mktime.c b/firmware/libc/mktime.c new file mode 100644 index 0000000000..a52381ede5 --- /dev/null +++ b/firmware/libc/mktime.c @@ -0,0 +1,61 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * 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 "config.h" + +#if CONFIG_RTC +/* mktime() code taken from lynx-2.8.5 source, written + by Philippe De Muyter */ +time_t mktime(struct tm *t) +{ + short month, year; + time_t result; + static int m_to_d[12] = + {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; + + month = t->tm_mon; + year = t->tm_year + month / 12 + 1900; + month %= 12; + if (month < 0) + { + year -= 1; + month += 12; + } + result = (year - 1970) * 365 + (year - 1969) / 4 + m_to_d[month]; + result = (year - 1970) * 365 + m_to_d[month]; + if (month <= 1) + year -= 1; + result += (year - 1968) / 4; + result -= (year - 1900) / 100; + result += (year - 1600) / 400; + result += t->tm_mday; + result -= 1; + result *= 24; + result += t->tm_hour; + result *= 60; + result += t->tm_min; + result *= 60; + result += t->tm_sec; + return(result); +} +#endif diff --git a/firmware/libc/qsort.c b/firmware/libc/qsort.c new file mode 100644 index 0000000000..8c4d1ad511 --- /dev/null +++ b/firmware/libc/qsort.c @@ -0,0 +1,222 @@ +/* +FUNCTION +<>---sort an array + +INDEX + qsort + +ANSI_SYNOPSIS + #include + void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, + int (*<[compar]>)(const void *, const void *) ); + +TRAD_SYNOPSIS + #include + qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> ) + char *<[base]>; + size_t <[nmemb]>; + size_t <[size]>; + int (*<[compar]>)(); + +DESCRIPTION +<> sorts an array (beginning at <[base]>) of <[nmemb]> objects. +<[size]> describes the size of each element of the array. + +You must supply a pointer to a comparison function, using the argument +shown as <[compar]>. (This permits sorting objects of unknown +properties.) Define the comparison function to accept two arguments, +each a pointer to an element of the array starting at <[base]>. The +result of <<(*<[compar]>)>> must be negative if the first argument is +less than the second, zero if the two arguments match, and positive if +the first argument is greater than the second (where ``less than'' and +``greater than'' refer to whatever arbitrary ordering is appropriate). + +The array is sorted in place; that is, when <> returns, the +array elements beginning at <[base]> have been reordered. + +RETURNS +<> does not return a result. + +PORTABILITY +<> is required by ANSI (without specifying the sorting algorithm). +*/ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <_ansi.h> +#include + +#ifndef __GNUC__ +#define inline +#endif + +static inline char *med3 _PARAMS((char *, char *, char *, int (*cmp)(const _PTR,const _PTR))); +static inline void swapfunc _PARAMS((char *, char *, int, int)); + +#define min(a, b) (a) < (b) ? a : b + +/* + * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". + */ +#define swapcode(TYPE, parmi, parmj, n) { \ + long i = (n) / sizeof (TYPE); \ + register TYPE *pi = (TYPE *) (parmi); \ + register TYPE *pj = (TYPE *) (parmj); \ + do { \ + register TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ +} + +#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ + es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; + +static inline void +_DEFUN(swapfunc, (a, b, n, swaptype), + char *a _AND + char *b _AND + int n _AND + int swaptype) +{ + if(swaptype <= 1) + swapcode(long, a, b, n) + else + swapcode(char, a, b, n) +} + +#define swap(a, b) \ + if (swaptype == 0) { \ + long t = *(long *)(a); \ + *(long *)(a) = *(long *)(b); \ + *(long *)(b) = t; \ + } else \ + swapfunc(a, b, es, swaptype) + +#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) + +static inline char * +_DEFUN(med3, (a, b, c, cmp), + char *a _AND + char *b _AND + char *c _AND + int (*cmp)(const _PTR,const _PTR)) +{ + return cmp(a, b) < 0 ? + (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) + :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); +} + +void +_DEFUN(qsort, (a, n, es, cmp), + void *a _AND + size_t n _AND + size_t es _AND + int (*cmp)(const _PTR,const _PTR)) +{ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int d, r, swaptype, swap_cnt; + +loop: SWAPINIT(a, es); + swap_cnt = 0; + if (n < 7) { + for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + pm = (char *) a + (n / 2) * es; + if (n > 7) { + pl = a; + pn = (char *) a + (n - 1) * es; + if (n > 40) { + d = (n / 8) * es; + pl = med3(pl, pl + d, pl + 2 * d, cmp); + pm = med3(pm - d, pm, pm + d, cmp); + pn = med3(pn - 2 * d, pn - d, pn, cmp); + } + pm = med3(pl, pm, pn, cmp); + } + swap(a, pm); + pa = pb = (char *) a + es; + + pc = pd = (char *) a + (n - 1) * es; + for (;;) { + while (pb <= pc && (r = cmp(pb, a)) <= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pa, pb); + pa += es; + } + pb += es; + } + while (pb <= pc && (r = cmp(pc, a)) >= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pc, pd); + pd -= es; + } + pc -= es; + } + if (pb > pc) + break; + swap(pb, pc); + swap_cnt = 1; + pb += es; + pc -= es; + } + if (swap_cnt == 0) { /* Switch to insertion sort */ + for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) + for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + + pn = (char *) a + n * es; + r = min(pa - (char *)a, pb - pa); + vecswap(a, pb - r, r); + r = min((unsigned int)(pd - pc), pn - pd - es); + vecswap(pb, pn - r, r); + if ((unsigned int)(r = pb - pa) > es) + qsort(a, r / es, es, cmp); + if ((unsigned int)(r = pd - pc) > es) { + /* Iterate rather than recurse to save stack space */ + a = pn - r; + n = r / es; + goto loop; + } +/* qsort(pn - r, r / es, es, cmp);*/ +} diff --git a/firmware/libc/random.c b/firmware/libc/random.c new file mode 100644 index 0000000000..f3efe89351 --- /dev/null +++ b/firmware/libc/random.c @@ -0,0 +1,119 @@ +/* + A C-program for MT19937, with initialization improved 2002/2/10. + Coded by Takuji Nishimura and Makoto Matsumoto. + This is a faster version by taking Shawn Cokus's optimization, + Matthe Bellew's simplification. + + Before using, initialize the state by using srand(seed). + + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Any feedback is very welcome. + http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html + email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) +*/ + +/* + Adapted to Rockbox by Jens Arnold +*/ + +#include + +/* Period parameters */ +#define N 624 +#define M 397 +#define MATRIX_A 0x9908b0dfUL /* constant vector a */ +#define UMASK 0x80000000UL /* most significant w-r bits */ +#define LMASK 0x7fffffffUL /* least significant r bits */ +#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) ) +#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL)) + +static unsigned long state[N]; /* the array for the state vector */ +static int left = 0; +static unsigned long *next; + +/* initializes state[N] with a seed */ +void srand(unsigned int seed) +{ + unsigned long x = seed & 0xffffffffUL; + unsigned long *s = state; + int j; + + for (*s++ = x, j = 1; j < N; j++) { + x = (1812433253UL * (x ^ (x >> 30)) + j) & 0xffffffffUL; + *s++ = x; + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array state[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + } + left = 1; +} + +static void next_state(void) +{ + unsigned long *p = state; + int j; + + /* if srand() has not been called, */ + /* a default initial seed is used */ + if (left < 0) + srand(5489UL); + + left = N; + next = state; + + for (j = N - M + 1; --j; p++) + *p = p[M] ^ TWIST(p[0], p[1]); + + for (j = M; --j; p++) + *p = p[M-N] ^ TWIST(p[0], p[1]); + + *p = p[M-N] ^ TWIST(p[0], state[0]); +} + +/* generates a random number on [0,RAND_MAX]-interval */ +int rand(void) +{ + unsigned long y; + + if (--left <= 0) + next_state(); + y = *next++; + + /* Tempering */ + y ^= (y >> 11); + y ^= (y << 7) & 0x9d2c5680UL; + y ^= (y << 15) & 0xefc60000UL; + y ^= (y >> 18); + + return ((unsigned int)y) >> 1; +} diff --git a/firmware/libc/sprintf.c b/firmware/libc/sprintf.c new file mode 100644 index 0000000000..b02f5a2fae --- /dev/null +++ b/firmware/libc/sprintf.c @@ -0,0 +1,93 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Gary Czvitkovicz + * + * 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. + * + ****************************************************************************/ + +/* + * Minimal printf and snprintf formatting functions + * + * These support %c %s %d and %x + * Field width and zero-padding flag only + */ + +#include +#include +#include +#include +#include "format.h" + +/* ALSA library requires a more advanced snprintf, so let's not + override it in simulator for Linux. Note that Cygwin requires + our snprintf or it produces garbled output after a while. */ + +struct for_snprintf { + unsigned char *ptr; /* where to store it */ + size_t bytes; /* amount already stored */ + size_t max; /* max amount to store */ +}; + +static int sprfunc(void *ptr, unsigned char letter) +{ + struct for_snprintf *pr = (struct for_snprintf *)ptr; + if(pr->bytes < pr->max) { + *pr->ptr = letter; + pr->ptr++; + pr->bytes++; + return true; + } + return false; /* filled buffer */ +} + + +int snprintf(char *buf, size_t size, const char *fmt, ...) +{ + bool ok; + va_list ap; + struct for_snprintf pr; + + pr.ptr = (unsigned char *)buf; + pr.bytes = 0; + pr.max = size; + + va_start(ap, fmt); + ok = format(sprfunc, &pr, fmt, ap); + va_end(ap); + + /* make sure it ends with a trailing zero */ + pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; + + return pr.bytes; +} + +int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap) +{ + bool ok; + struct for_snprintf pr; + + pr.ptr = (unsigned char *)buf; + pr.bytes = 0; + pr.max = size; + + ok = format(sprfunc, &pr, fmt, ap); + + /* make sure it ends with a trailing zero */ + pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; + + return pr.bytes; +} diff --git a/firmware/libc/sscanf.c b/firmware/libc/sscanf.c new file mode 100644 index 0000000000..5fbe81f3e0 --- /dev/null +++ b/firmware/libc/sscanf.c @@ -0,0 +1,282 @@ +#include +#include +#include + +static inline bool isspace(char c) +{ + return (c == ' ') || (c == '\t') || (c == '\n'); +} + +static inline bool isdigit(char c) +{ + return (c >= '0') && (c <= '9'); +} + +static inline bool isxdigit(char c) +{ + return ((c >= '0') && (c <= '9')) + || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); +} + +static int parse_dec(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp, + long *vp) +{ + long v = 0; + int n = 0; + int minus = 0; + char ch; + + if ((*peek)(userp) == '-') + { + (*pop)(userp); + n++; + minus = 1; + } + + ch = (*peek)(userp); + if (!isdigit(ch)) + return -1; + + do + { + v = v * 10 + ch - '0'; + (*pop)(userp); + n++; + ch = (*peek)(userp); + } while (isdigit(ch)); + + *vp = minus ? -v : v; + return n; +} + +static int parse_chars(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp, + char *vp, + bool fake) +{ + int n = 0; + + char *pt=vp; + + while (!isspace((*peek)(userp))) + { + if(fake==false) + *(pt++) = (*peek)(userp); + + n++; + (*pop)(userp); + } + + if(fake==false) + (*pt)='\0'; + + return n; +} + +static int parse_hex(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp, + unsigned long *vp) +{ + unsigned long v = 0; + int n = 0; + char ch; + + ch = (*peek)(userp); + if (!isxdigit(ch)) + return -1; + + do + { + if (ch >= 'a') + ch = ch - 'a' + 10; + else if (ch >= 'A') + ch = ch - 'A' + 10; + else + ch = ch - '0'; + v = v * 16 + ch; + (*pop)(userp); + n++; + ch = (*peek)(userp); + } while (isxdigit(ch)); + + *vp = v; + return n; +} + +static int skip_spaces(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp) +{ + int n = 0; + while (isspace((*peek)(userp))) { + n++; + (*pop)(userp); + } + return n; +} + +static int scan(int (*peek)(void *userp), + void (*pop)(void *userp), + void *userp, + const char *fmt, + va_list ap) +{ + char ch; + int n = 0; + int n_chars = 0; + int r; + long lval; + bool skip=false; + unsigned long ulval; + + while ((ch = *fmt++) != '\0') + { + bool literal = false; + + if (ch == '%') + { + ch = *fmt++; + + if(ch== '*') /* We should process this, but not store it in an arguement */ + { + ch=*fmt++; + skip=true; + } + else + { + skip=false; + } + + switch (ch) + { + case 'x': + n_chars += skip_spaces(peek, pop, userp); + if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) + { + if(skip==false) + { + *(va_arg(ap, unsigned int *)) = ulval; + n++; + } + n_chars += r; + } + else + return n; + break; + case 'd': + n_chars += skip_spaces(peek, pop, userp); + if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) + { + if(skip==false) + { + *(va_arg(ap, int *)) = lval; + n++; + } + n_chars += r; + } + else + return n; + break; + case 'n': + if(skip==false) + { + *(va_arg(ap, int *)) = n_chars; + n++; + } + break; + case 'l': + n_chars += skip_spaces(peek, pop, userp); + ch = *fmt++; + switch (ch) + { + case 'x': + if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) + { + if(skip==false) + { + *(va_arg(ap, unsigned long *)) = ulval; + n++; + } + n_chars += r; + } + else + return n; + break; + case 'd': + if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) + { + if(skip==false) + { + *(va_arg(ap, long *)) = lval; + n++; + } + n_chars += r; + } + else + return n; + break; + case '\0': + return n; + default: + literal = true; + break; + } + break; + case 's': + n_chars += skip_spaces(peek, pop, userp); + n_chars += parse_chars(peek,pop, userp,skip?0:va_arg(ap, char *), skip ); + if(skip==false) + { + n++; + } + break; + case '\0': + return n; + default: + literal = true; + break; + } + } else + literal = true; + + if (literal) + { + n_chars += skip_spaces(peek, pop, userp); + if ((*peek)(userp) != ch) + continue; + else + { + (*pop)(userp); + n_chars++; + } + } + } + return n; +} + +static int sspeek(void *userp) +{ + return **((char **)userp); +} + +static void sspop(void *userp) +{ + (*((char **)userp))++; +} + +int sscanf(const char *s, const char *fmt, ...) +{ + int r; + va_list ap; + const char *p; + + p = s; + va_start(ap, fmt); + r = scan(sspeek, sspop, &p, fmt, ap); + va_end(ap); + return r; +} diff --git a/firmware/libc/strcat.c b/firmware/libc/strcat.c new file mode 100644 index 0000000000..221529519c --- /dev/null +++ b/firmware/libc/strcat.c @@ -0,0 +1,14 @@ +#include + +char *strcat(char *s1, + const char *s2) +{ + char *s = s1; + + while (*s1) + s1++; + + while ((*s1++ = *s2++)) + ; + return s; +} diff --git a/firmware/libc/strchr.c b/firmware/libc/strchr.c new file mode 100644 index 0000000000..96acf5edf6 --- /dev/null +++ b/firmware/libc/strchr.c @@ -0,0 +1,108 @@ +/* +FUNCTION + <>---search for character in string + +INDEX + strchr + +ANSI_SYNOPSIS + #include + char * strchr(const char *<[string]>, int <[c]>); + +TRAD_SYNOPSIS + #include + char * strchr(<[string]>, <[c]>); + char *<[string]>; + int *<[c]>; + +DESCRIPTION + This function finds the first occurence of <[c]> (converted to + a char) in the string pointed to by <[string]> (including the + terminating null character). + +RETURNS + Returns a pointer to the located character, or a null pointer + if <[c]> does not occur in <[string]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strchr ansi pure +*/ + +#include +#include + +/* Nonzero if X is not aligned on a "long" boundary. */ +#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) + +/* How many bytes are loaded each iteration of the word copy loop. */ +#define LBLOCKSIZE (sizeof (long)) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +/* DETECTCHAR returns nonzero if (long)X contains the byte used + to fill (long)MASK. */ +#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) + +char * +_DEFUN (strchr, (s1, i), + _CONST char *s1 _AND + int i) +{ + _CONST unsigned char *s = (_CONST unsigned char *)s1; +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + unsigned char c = (unsigned int)i; + + while (*s && *s != c) + { + s++; + } + + if (*s != c) + { + s = NULL; + } + + return (char *) s; +#else + unsigned char c = (unsigned char)i; + unsigned long mask,j; + unsigned long *aligned_addr; + + if (!UNALIGNED (s)) + { + mask = 0; + for (j = 0; j < LBLOCKSIZE; j++) + mask = (mask << 8) | c; + + aligned_addr = (unsigned long*)s; + while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) + aligned_addr++; + + /* The block of bytes currently pointed to by aligned_addr + contains either a null or the target char, or both. We + catch it using the bytewise search. */ + + s = (unsigned char*)aligned_addr; + } + + while (*s && *s != c) + s++; + if (*s == c) + return (char *)s; + return NULL; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/strcmp.c b/firmware/libc/strcmp.c new file mode 100644 index 0000000000..bbbf4b174a --- /dev/null +++ b/firmware/libc/strcmp.c @@ -0,0 +1,106 @@ +/* +FUNCTION + <>---character string compare + +INDEX + strcmp + +ANSI_SYNOPSIS + #include + int strcmp(const char *<[a]>, const char *<[b]>); + +TRAD_SYNOPSIS + #include + int strcmp(<[a]>, <[b]>) + char *<[a]>; + char *<[b]>; + +DESCRIPTION + <> compares the string at <[a]> to + the string at <[b]>. + +RETURNS + If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, + <> returns a number greater than zero. If the two + strings match, <> returns zero. If <<*<[a]>>> + sorts lexicographically before <<*<[b]>>>, <> returns a + number less than zero. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strcmp ansi pure +*/ + +#include +#include + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +int +_DEFUN (strcmp, (s1, s2), + _CONST char *s1 _AND + _CONST char *s2) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + while (*s1 != '\0' && *s1 == *s2) + { + s1++; + s2++; + } + + return (*(unsigned char *) s1) - (*(unsigned char *) s2); +#else + unsigned long *a1; + unsigned long *a2; + + /* If s1 or s2 are unaligned, then compare bytes. */ + if (!UNALIGNED (s1, s2)) + { + /* If s1 and s2 are word-aligned, compare them a word at a time. */ + a1 = (unsigned long*)s1; + a2 = (unsigned long*)s2; + while (*a1 == *a2) + { + /* To get here, *a1 == *a2, thus if we find a null in *a1, + then the strings must be equal, so return zero. */ + if (DETECTNULL (*a1)) + return 0; + + a1++; + a2++; + } + + /* A difference was detected in last few bytes of s1, so search bytewise */ + s1 = (char*)a1; + s2 = (char*)a2; + } + + while (*s1 != '\0' && *s1 == *s2) + { + s1++; + s2++; + } + return (*(unsigned char *) s1) - (*(unsigned char *) s2); +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/strcpy.c b/firmware/libc/strcpy.c new file mode 100644 index 0000000000..077ae73cc6 --- /dev/null +++ b/firmware/libc/strcpy.c @@ -0,0 +1,99 @@ +/* +FUNCTION + <>---copy string + +INDEX + strcpy + +ANSI_SYNOPSIS + #include + char *strcpy(char *<[dst]>, const char *<[src]>); + +TRAD_SYNOPSIS + #include + char *strcpy(<[dst]>, <[src]>) + char *<[dst]>; + char *<[src]>; + +DESCRIPTION + <> copies the string pointed to by <[src]> + (including the terminating null character) to the array + pointed to by <[dst]>. + +RETURNS + This function returns the initial value of <[dst]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strcpy ansi pure +*/ + +#include +#include + +/*SUPPRESS 560*/ +/*SUPPRESS 530*/ + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +char* +_DEFUN (strcpy, (dst0, src0), + char *dst0 _AND + _CONST char *src0) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *s = dst0; + + while ((*dst0++ = *src0++)) + ; + + return s; +#else + char *dst = dst0; + _CONST char *src = src0; + long *aligned_dst; + _CONST long *aligned_src; + + /* If SRC or DEST is unaligned, then copy bytes. */ + if (!UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* SRC and DEST are both "long int" aligned, try to do "long int" + sized copies. */ + while (!DETECTNULL(*aligned_src)) + { + *aligned_dst++ = *aligned_src++; + } + + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while ((*dst++ = *src++)) + ; + return dst0; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/strlen.c b/firmware/libc/strlen.c new file mode 100644 index 0000000000..4d33eafce6 --- /dev/null +++ b/firmware/libc/strlen.c @@ -0,0 +1,93 @@ +/* +FUNCTION + <>---character string length + +INDEX + strlen + +ANSI_SYNOPSIS + #include + size_t strlen(const char *<[str]>); + +TRAD_SYNOPSIS + #include + size_t strlen(<[str]>) + char *<[src]>; + +DESCRIPTION + The <> function works out the length of the string + starting at <<*<[str]>>> by counting chararacters until it + reaches a <> character. + +RETURNS + <> returns the character count. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strlen ansi pure +*/ + +#include "config.h" +#include <_ansi.h> +#include +#include + +#define LBLOCKSIZE (sizeof (long)) +#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +size_t +_DEFUN (strlen, (str), + _CONST char *str) ICODE_ATTR; + +size_t +_DEFUN (strlen, (str), + _CONST char *str) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + _CONST char *start = str; + + while (*str) + str++; + + return str - start; +#else + _CONST char *start = str; + unsigned long *aligned_addr; + + if (!UNALIGNED (str)) + { + /* If the string is word-aligned, we can check for the presence of + a null in each word-sized block. */ + aligned_addr = (unsigned long*)str; + while (!DETECTNULL (*aligned_addr)) + aligned_addr++; + + /* Once a null is detected, we check each byte in that block for a + precise position of the null. */ + str = (char*)aligned_addr; + } + + while (*str) + str++; + return str - start; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/strncmp.c b/firmware/libc/strncmp.c new file mode 100644 index 0000000000..b1d8d9d43a --- /dev/null +++ b/firmware/libc/strncmp.c @@ -0,0 +1,122 @@ +/* +FUNCTION + <>---character string compare + +INDEX + strncmp + +ANSI_SYNOPSIS + #include + int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); + +TRAD_SYNOPSIS + #include + int strncmp(<[a]>, <[b]>, <[length]>) + char *<[a]>; + char *<[b]>; + size_t <[length]> + +DESCRIPTION + <> compares up to <[length]> characters + from the string at <[a]> to the string at <[b]>. + +RETURNS + If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, + <> returns a number greater than zero. If the two + strings are equivalent, <> returns zero. If <<*<[a]>>> + sorts lexicographically before <<*<[b]>>>, <> returns a + number less than zero. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strncmp ansi pure +*/ + +#include +#include + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +int +_DEFUN (strncmp, (s1, s2, n), + _CONST char *s1 _AND + _CONST char *s2 _AND + size_t n) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + if (n == 0) + return 0; + + while (n-- != 0 && *s1 == *s2) + { + if (n == 0 || *s1 == '\0') + break; + s1++; + s2++; + } + + return (*(unsigned char *) s1) - (*(unsigned char *) s2); +#else + unsigned long *a1; + unsigned long *a2; + + if (n == 0) + return 0; + + /* If s1 or s2 are unaligned, then compare bytes. */ + if (!UNALIGNED (s1, s2)) + { + /* If s1 and s2 are word-aligned, compare them a word at a time. */ + a1 = (unsigned long*)s1; + a2 = (unsigned long*)s2; + while (n >= sizeof (long) && *a1 == *a2) + { + n -= sizeof (long); + + /* If we've run out of bytes or hit a null, return zero + since we already know *a1 == *a2. */ + if (n == 0 || DETECTNULL (*a1)) + return 0; + + a1++; + a2++; + } + + /* A difference was detected in last few bytes of s1, so search bytewise */ + s1 = (char*)a1; + s2 = (char*)a2; + } + + while (n-- > 0 && *s1 == *s2) + { + /* If we've run out of bytes or hit a null, return zero + since we already know *s1 == *s2. */ + if (n == 0 || *s1 == '\0') + return 0; + s1++; + s2++; + } + return (*(unsigned char *) s1) - (*(unsigned char *) s2); +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/firmware/libc/strrchr.c b/firmware/libc/strrchr.c new file mode 100644 index 0000000000..31b0d049b3 --- /dev/null +++ b/firmware/libc/strrchr.c @@ -0,0 +1,59 @@ +/* +FUNCTION + <>---reverse search for character in string + +INDEX + strrchr + +ANSI_SYNOPSIS + #include + char * strrchr(const char *<[string]>, int <[c]>); + +TRAD_SYNOPSIS + #include + char * strrchr(<[string]>, <[c]>); + char *<[string]>; + int *<[c]>; + +DESCRIPTION + This function finds the last occurence of <[c]> (converted to + a char) in the string pointed to by <[string]> (including the + terminating null character). + +RETURNS + Returns a pointer to the located character, or a null pointer + if <[c]> does not occur in <[string]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strrchr ansi pure +*/ + +#include + +char * +_DEFUN (strrchr, (s, i), + _CONST char *s _AND + int i) +{ + _CONST char *last = NULL; + + if (i) + { + while ((s=strchr(s, i))) + { + last = s; + s++; + } + } + else + { + last = strchr(s, i); + } + + return (char *) last; +} diff --git a/firmware/libc/strstr.c b/firmware/libc/strstr.c new file mode 100644 index 0000000000..73fab1cc63 --- /dev/null +++ b/firmware/libc/strstr.c @@ -0,0 +1,38 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: $ + * + * Copyright (C) 1991, 1992 Linus Torvalds + * (from linux/lib/string.c) + * + ****************************************************************************/ + +#include + +/** + * strstr - Find the first substring in a %NUL terminated string + * @s1: The string to be searched + * @s2: The string to search for + */ +char *strstr(const char *s1, const char *s2) +{ + int l1, l2; + + l2 = strlen(s2); + if (!l2) + return (char *)s1; + l1 = strlen(s1); + while (l1 >= l2) { + l1--; + if (!memcmp(s1, s2, l2)) + return (char *)s1; + s1++; + } + return NULL; +} + diff --git a/firmware/libc/strtok.c b/firmware/libc/strtok.c new file mode 100644 index 0000000000..9e2eddf599 --- /dev/null +++ b/firmware/libc/strtok.c @@ -0,0 +1,63 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Daniel Stenberg + * + * 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 "config.h" + +#ifndef HAVE_STRTOK_R +#include +#include + +char * +strtok_r(char *ptr, const char *sep, char **end) +{ + if (!ptr) + /* we got NULL input so then we get our last position instead */ + ptr = *end; + + /* pass all letters that are including in the separator string */ + while (*ptr && strchr(sep, *ptr)) + ++ptr; + + if (*ptr) { + /* so this is where the next piece of string starts */ + char *start = ptr; + + /* set the end pointer to the first byte after the start */ + *end = start + 1; + + /* scan through the string to find where it ends, it ends on a + null byte or a character that exists in the separator string */ + while (**end && !strchr(sep, **end)) + ++*end; + + if (**end) { + /* the end is not a null byte */ + **end = '\0'; /* zero terminate it! */ + ++*end; /* advance last pointer to beyond the null byte */ + } + + return start; /* return the position where the string starts */ + } + + /* we ended up on a null byte, there are no more strings to find! */ + return NULL; +} + +#endif /* this was only compiled if strtok_r wasn't present */ diff --git a/firmware/profile.c b/firmware/profile.c index 30a1e9fccc..0545acce3c 100644 --- a/firmware/profile.c +++ b/firmware/profile.c @@ -59,7 +59,7 @@ #include #include #include -#include +#include "inttypes.h" #include "profile.h" /* PFD is Profiled Function Data */ diff --git a/firmware/rolo.c b/firmware/rolo.c index 0f398770e6..69166785ad 100644 --- a/firmware/rolo.c +++ b/firmware/rolo.c @@ -24,7 +24,6 @@ #include "lcd-remote.h" #include "thread.h" #include "kernel.h" -#include "sprintf.h" #include "button.h" #include "file.h" #include "audio.h" diff --git a/firmware/target/arm/as3525/debug-as3525.c b/firmware/target/arm/as3525/debug-as3525.c index cfd7c37b16..75cce72dcd 100644 --- a/firmware/target/arm/as3525/debug-as3525.c +++ b/firmware/target/arm/as3525/debug-as3525.c @@ -25,7 +25,6 @@ #include "lcd.h" #include "font.h" #include "system.h" -#include "sprintf.h" #include "cpu.h" #include "pl180.h" #include "ascodec-target.h" diff --git a/firmware/target/arm/imx31/debug-imx31.c b/firmware/target/arm/imx31/debug-imx31.c index 783ba728a6..07f9453b29 100644 --- a/firmware/target/arm/imx31/debug-imx31.c +++ b/firmware/target/arm/imx31/debug-imx31.c @@ -23,7 +23,6 @@ #include "string.h" #include "button.h" #include "lcd.h" -#include "sprintf.h" #include "font.h" #include "debug-target.h" #include "mc13783.h" diff --git a/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c index 71d8e4bef4..5a0f81358d 100644 --- a/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/lcd-gigabeat-s.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include "inttypes.h" #include "config.h" #include "cpu.h" diff --git a/firmware/target/arm/ipod/video/lcd-video.c b/firmware/target/arm/ipod/video/lcd-video.c index ea9738b3a4..74d627730f 100644 --- a/firmware/target/arm/ipod/video/lcd-video.c +++ b/firmware/target/arm/ipod/video/lcd-video.c @@ -25,8 +25,8 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include /* off_t */ #include "config.h" #include "cpu.h" #include "lcd.h" diff --git a/firmware/target/arm/lcd-c200_c200v2.c b/firmware/target/arm/lcd-c200_c200v2.c index 45a37d9d7b..14749aa1ff 100644 --- a/firmware/target/arm/lcd-c200_c200v2.c +++ b/firmware/target/arm/lcd-c200_c200v2.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include "inttypes.h" #include "config.h" #include "cpu.h" diff --git a/firmware/target/arm/philips/hdd1630/lcd-hdd1630.c b/firmware/target/arm/philips/hdd1630/lcd-hdd1630.c index 500120a432..93abd300ec 100644 --- a/firmware/target/arm/philips/hdd1630/lcd-hdd1630.c +++ b/firmware/target/arm/philips/hdd1630/lcd-hdd1630.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include "inttypes.h" #include "config.h" #include "cpu.h" diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c index 7e0594b47d..2f3c4189e5 100644 --- a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c +++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c @@ -31,7 +31,6 @@ #include "lcd.h" #include "usb.h" #include "button.h" -#include "sprintf.h" #include "string.h" void usb_init_device(void) diff --git a/firmware/target/arm/s3c2440/debug-s3c2440.c b/firmware/target/arm/s3c2440/debug-s3c2440.c index 064cca9135..196a0b4177 100644 --- a/firmware/target/arm/s3c2440/debug-s3c2440.c +++ b/firmware/target/arm/s3c2440/debug-s3c2440.c @@ -26,7 +26,6 @@ #include #include "button.h" #include "lcd.h" -#include "sprintf.h" #include "font.h" #include "debug-target.h" diff --git a/firmware/target/arm/s3c2440/lcd-s3c2440.c b/firmware/target/arm/s3c2440/lcd-s3c2440.c index 8b24aced5b..b9f7d3ef3d 100644 --- a/firmware/target/arm/s3c2440/lcd-s3c2440.c +++ b/firmware/target/arm/s3c2440/lcd-s3c2440.c @@ -18,8 +18,8 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * -****************************************************************************/ -#include +****************************************************************************/ +#include /* off_t */ #include "config.h" #include "system.h" diff --git a/firmware/target/arm/s5l8700/debug-s5l8700.c b/firmware/target/arm/s5l8700/debug-s5l8700.c index 0ad76037f0..96df1546ef 100644 --- a/firmware/target/arm/s5l8700/debug-s5l8700.c +++ b/firmware/target/arm/s5l8700/debug-s5l8700.c @@ -26,7 +26,6 @@ #include "button.h" #include "lcd.h" #include "font.h" -#include "sprintf.h" #include "storage.h" #ifdef IPOD_NANO2G #include "power.h" diff --git a/firmware/target/arm/samsung/yh820/lcd-yh820.c b/firmware/target/arm/samsung/yh820/lcd-yh820.c index f7d971ab76..4773e27185 100644 --- a/firmware/target/arm/samsung/yh820/lcd-yh820.c +++ b/firmware/target/arm/samsung/yh820/lcd-yh820.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include /* off_t */ #include "config.h" #include "cpu.h" diff --git a/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c b/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c index 03f6a1b971..0f9ca9b046 100644 --- a/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c +++ b/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c @@ -22,7 +22,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include /* off_t */ #include #include "cpu.h" #include "system.h" diff --git a/firmware/target/arm/tcc77x/debug-tcc77x.c b/firmware/target/arm/tcc77x/debug-tcc77x.c index 203a6010ce..bf322f5675 100644 --- a/firmware/target/arm/tcc77x/debug-tcc77x.c +++ b/firmware/target/arm/tcc77x/debug-tcc77x.c @@ -26,7 +26,6 @@ #include #include "button.h" #include "lcd.h" -#include "sprintf.h" #include "font.h" #include "debug-target.h" #include "adc.h" diff --git a/firmware/target/arm/tcc77x/iaudio7/ata2501.c b/firmware/target/arm/tcc77x/iaudio7/ata2501.c index 3d78599ff9..f7526b2b9a 100644 --- a/firmware/target/arm/tcc77x/iaudio7/ata2501.c +++ b/firmware/target/arm/tcc77x/iaudio7/ata2501.c @@ -76,7 +76,6 @@ unsigned short ata2501_read(void) //#define ATA2501_TEST #ifdef ATA2501_TEST #include "lcd.h" -#include "sprintf.h" static void bits(char *str, unsigned short val) diff --git a/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c b/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c index d5a7e2f142..c2800727b9 100644 --- a/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/lcd-cowond2.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include /* off_t */ #include "config.h" #include "hwcompat.h" diff --git a/firmware/target/arm/tcc780x/debug-tcc780x.c b/firmware/target/arm/tcc780x/debug-tcc780x.c index ef6415efc4..11d6d2acab 100644 --- a/firmware/target/arm/tcc780x/debug-tcc780x.c +++ b/firmware/target/arm/tcc780x/debug-tcc780x.c @@ -26,7 +26,6 @@ #include #include "button.h" #include "lcd.h" -#include "sprintf.h" #include "font.h" #include "debug-target.h" #include "adc.h" diff --git a/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c index 98a4b57bd6..52c500f66d 100644 --- a/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c +++ b/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c @@ -26,7 +26,6 @@ #include "kernel.h" #include "button-target.h" #include "i2c-dm320.h" -#include "sprintf.h" #include "logf.h" #ifdef BUTTON_DEBUG diff --git a/firmware/target/arm/tms320dm320/debug-dm320.c b/firmware/target/arm/tms320dm320/debug-dm320.c index 8be21065d6..8bf170048e 100644 --- a/firmware/target/arm/tms320dm320/debug-dm320.c +++ b/firmware/target/arm/tms320dm320/debug-dm320.c @@ -27,7 +27,6 @@ #include "button.h" #include "lcd.h" #include "debug.h" -#include "sprintf.h" #include "font.h" #include "lcd-target.h" diff --git a/firmware/target/arm/usb-s3c6400x.c b/firmware/target/arm/usb-s3c6400x.c index 2fbb1a9849..3f28e7f379 100644 --- a/firmware/target/arm/usb-s3c6400x.c +++ b/firmware/target/arm/usb-s3c6400x.c @@ -35,7 +35,6 @@ #include "usb_ch9.h" #include "usb_core.h" #include -#include "sprintf.h" #include "power.h" struct ep_type diff --git a/firmware/target/arm/usb-tcc.c b/firmware/target/arm/usb-tcc.c index 9d5ae2d50a..1b5f16c223 100644 --- a/firmware/target/arm/usb-tcc.c +++ b/firmware/target/arm/usb-tcc.c @@ -42,7 +42,6 @@ static int global_ep_irq_mask = 0x1; #include -#include "sprintf.h" #include "power.h" #ifndef BOOTLOADER diff --git a/firmware/target/mips/ingenic_jz47xx/lcd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/lcd-jz4740.c index 29f337b13b..ef45317c3f 100644 --- a/firmware/target/mips/ingenic_jz47xx/lcd-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/lcd-jz4740.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ -#include +#include /* off_t */ #include "config.h" #include "jz4740.h" diff --git a/firmware/target/mips/ingenic_jz47xx/system-jz4740.c b/firmware/target/mips/ingenic_jz47xx/system-jz4740.c index c90decc3b6..588cc16aea 100644 --- a/firmware/target/mips/ingenic_jz47xx/system-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/system-jz4740.c @@ -32,7 +32,6 @@ #include "backlight-target.h" #include "font.h" #include "lcd.h" -#include "sprintf.h" #endif #define NUM_DMA 6 diff --git a/firmware/test/snprintf/test.c b/firmware/test/snprintf/test.c index 8923c9c9f5..049be4d257 100644 --- a/firmware/test/snprintf/test.c +++ b/firmware/test/snprintf/test.c @@ -1,7 +1,6 @@ #include -#include "sprintf.h" int main(int argc, char **argv) { diff --git a/firmware/thread.c b/firmware/thread.c index 13d568eafb..d3031d55e3 100644 --- a/firmware/thread.c +++ b/firmware/thread.c @@ -20,9 +20,9 @@ ****************************************************************************/ #include "config.h" #include +#include #include "thread.h" #include "panic.h" -#include "sprintf.h" #include "system.h" #include "kernel.h" #include "cpu.h" diff --git a/firmware/usb.c b/firmware/usb.c index ccf12c197d..c615e97d2b 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -37,7 +37,6 @@ #include "usb-target.h" #include "usb.h" #include "button.h" -#include "sprintf.h" #include "string.h" #ifdef HAVE_USBSTACK #include "usb_core.h" diff --git a/tools/configure b/tools/configure index 186e0d5ace..27609ca13a 100755 --- a/tools/configure +++ b/tools/configure @@ -165,7 +165,8 @@ simcc () { exit 2 else # generic sdl-config checker - GCCOPTS="$GCCOPTS `$sdl --cflags`" + #ignore the -D_GNU_SOURCE=1 inserted by sdl + GCCOPTS="$GCCOPTS `$sdl --cflags` -U_GNU_SOURCE" LDOPTS="$LDOPTS `$sdl --libs`" fi fi diff --git a/uisimulator/sdl/sprintf.h b/uisimulator/sdl/sprintf.h deleted file mode 100644 index 129a6187c2..0000000000 --- a/uisimulator/sdl/sprintf.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Felix Arends - * - * 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. - * - ****************************************************************************/ - -#ifndef __SPRINTF_H__ -#define __SPRINTF_H__ - -#include -#include -#include - -int snprintf (char *buf, size_t size, const char *fmt, ...); -char *strtok_r (char *, const char *, char **); - -int rockbox_fprintf (int fd, const char *fmt, ...); -#define fprintf rockbox_fprintf - -int rockbox_vsnprintf (char *buf, int size, const char *fmt, va_list ap); -#define vsnprintf rockbox_vsnprintf - -#endif /* __SPRINTF_H__ */ -- cgit v1.2.3