Index: apps/plugins/viewer.c =================================================================== --- apps/plugins/viewer.c (revision 18378) +++ apps/plugins/viewer.c (working copy) @@ -316,23 +316,7 @@ WIDE, } view_mode; - enum { - ISO_8859_1=0, - ISO_8859_7, - ISO_8859_8, - CP1251, - ISO_8859_11, - ISO_8859_6, - ISO_8859_9, - ISO_8859_2, - CP1250, - SJIS, - GB2312, - KSX1001, - BIG5, - UTF8, - ENCODINGS - } encoding; /* FIXME: What should default encoding be? */ + enum codepages encoding; #ifdef HAVE_LCD_BITMAP enum { @@ -401,7 +385,7 @@ unsigned char utf8_tmp[6]; int count; - if (prefs.encoding == UTF8) + if (prefs.encoding == UTF_8) return (unsigned char*)rb->utf8decode(str, ch); count = BUFFER_OOB(str+2)? 1:2; @@ -1298,23 +1282,15 @@ static bool encoding_setting(void) { - static const struct opt_items names[] = { - {"ISO-8859-1", -1}, - {"ISO-8859-7", -1}, - {"ISO-8859-8", -1}, - {"CP1251", -1}, - {"ISO-8859-11", -1}, - {"ISO-8859-6", -1}, - {"ISO-8859-9", -1}, - {"ISO-8859-2", -1}, - {"CP1250", -1}, - {"SJIS", -1}, - {"GB-2312", -1}, - {"KSX-1001", -1}, - {"BIG5", -1}, - {"UTF-8", -1}, - }; + static struct opt_items names[NUM_CODEPAGES]; + int idx; + for (idx = 0; idx < NUM_CODEPAGES; idx++) + { + names[idx].string = rb->get_codepage_name(idx); + names[idx].voice_id = -1; + } + return rb->set_option("Encoding", &prefs.encoding, INT, names, sizeof(names) / sizeof(names[0]), NULL); } Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 18378) +++ apps/plugin.c (working copy) @@ -382,6 +382,7 @@ utf8encode, utf8length, utf8seek, + get_codepage_name, /* sound */ sound_set, Index: apps/plugin.h =================================================================== --- apps/plugin.h (revision 18378) +++ apps/plugin.h (working copy) @@ -130,12 +130,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 122 +#define PLUGIN_API_VERSION 123 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 122 +#define PLUGIN_MIN_API_VERSION 123 /* plugin return codes */ enum plugin_status { @@ -503,6 +503,7 @@ unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8); unsigned long (*utf8length)(const unsigned char *utf8); int (*utf8seek)(const unsigned char* utf8, int offset); + const char* (*get_codepage_name)(int cp); /* sound */ void (*sound_set)(int setting, int value); Index: firmware/include/rbunicode.h =================================================================== --- firmware/include/rbunicode.h (revision 18378) +++ firmware/include/rbunicode.h (working copy) @@ -1,17 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (c) 2004,2005 by Marcoen Hirschberg + * + * 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. + * + ****************************************************************************/ /* Some conversion functions for handling UTF-8 * - * copyright Marcoen Hirschberg (2004,2005) - * * I got all the info from: * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 * and * http://en.wikipedia.org/wiki/Unicode */ +#ifndef _RBUNICODE_H_ +#define _RBUNICODE_H_ + +#ifndef __PCTOOL__ +#include "config.h" +#endif #define MASK 0xC0 /* 11000000 */ #define COMP 0x80 /* 10x */ +#ifdef HAVE_LCD_BITMAP + +enum codepages { + ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251, + ISO_8859_11, WIN_1256, ISO_8859_9, ISO_8859_2, WIN_1250, + SJIS, GB_2312, KSX_1001, BIG_5, UTF_8, NUM_CODEPAGES +}; +#else /* !HAVE_LCD_BITMAP, reduced support */ + +enum codepages { + ISO_8859_1 = 0, ISO_8859_7, WIN_1251, ISO_8859_9, + ISO_8859_2, WIN_1250, UTF_8, NUM_CODEPAGES +}; + +#endif + /* Encode a UCS value as UTF-8 and return a pointer after this UTF-8 char. */ unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8); unsigned char* iso_decode(const unsigned char *latin1, unsigned char *utf8, int cp, int count); @@ -21,3 +61,5 @@ const unsigned char* utf8decode(const unsigned char *utf8, unsigned short *ucs); void set_codepage(int cp); int utf8seek(const unsigned char* utf8, int offset); +const char* get_codepage_name(int cp); +#endif /* _RBUNICODE_H_ */ Index: firmware/common/unicode.c =================================================================== --- firmware/common/unicode.c (revision 18378) +++ firmware/common/unicode.c (working copy) @@ -1,7 +1,25 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (c) 2004,2005 by Marcoen Hirschberg + * + * 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. + * + ****************************************************************************/ /* Some conversion functions for handling UTF-8 * - * copyright Marcoen Hirschberg (2004,2005) - * * I got all the info from: * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 * and @@ -27,11 +45,6 @@ #define MAX_CP_TABLE_SIZE 32768 #define NUM_TABLES 5 -enum { - ISO_8859_1 = 0, ISO_8859_7, ISO_8859_8, WIN_1251, - ISO_8859_11, WIN_1256, ISO_8859_9, ISO_8859_2, WIN_1250, - SJIS, GB_2312, KSX_1001, BIG_5, UTF_8, NUM_CODEPAGES -}; static const char *filename[NUM_TABLES] = { CODEPAGE_DIR"/iso.cp", @@ -40,29 +53,58 @@ CODEPAGE_DIR"/949.cp", /* KSX1001 */ CODEPAGE_DIR"/950.cp" /* BIG5 */ }; + static const char cp_2_table[NUM_CODEPAGES] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 0 }; +static const char name_codepages[NUM_CODEPAGES+1][12] = +{ + "ISO-8859-1", + "ISO-8859-7", + "ISO-8859-8", + "CP1251", + "ISO-8859-11", + "CP1256", + "ISO-8859-9", + "ISO-8859-2", + "CP1250", + "SJIS", + "GB-2312", + "KSX-1001", + "BIG5", + "UTF-8", + "unknown" +}; + #else /* !HAVE_LCD_BITMAP, reduced support */ #define MAX_CP_TABLE_SIZE 640 #define NUM_TABLES 1 -enum { - ISO_8859_1 = 0, ISO_8859_7, WIN_1251, ISO_8859_9, - ISO_8859_2, WIN_1250, UTF_8, NUM_CODEPAGES -}; static const char *filename[NUM_TABLES] = { CODEPAGE_DIR"/isomini.cp", }; + static const char cp_2_table[NUM_CODEPAGES] = { 0, 1, 1, 1, 1, 1, 0 }; +static const char name_codepages[NUM_CODEPAGES+1][12] = +{ + "ISO-8859-1", + "ISO-8859-7", + "CP1251", + "ISO-8859-9", + "ISO-8859-2", + "CP1250", + "UTF-8", + "unknown" +}; + #endif static unsigned short codepage_table[MAX_CP_TABLE_SIZE]; @@ -344,3 +386,10 @@ } return pos; } + +const char* get_codepage_name(int cp) +{ + if (cp < 0 || cp>= NUM_CODEPAGES) + return name_codepages[NUM_CODEPAGES]; + return name_codepages[cp]; +}