summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2003-01-14 14:49:19 +0000
committerBjörn Stenberg <bjorn@haxx.se>2003-01-14 14:49:19 +0000
commit32bfc9940c4e35807979b739aa824e4867c13987 (patch)
tree9b65ab66f9609d6c10d0c07f17331de011897f57 /firmware/drivers
parent601d77dc635813682f8d3c03236fc302a101d236 (diff)
Added unicode conversion from cyrillic, greek, hebrew, arabic and thai.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3086 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index a5b900216b..f468111278 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1576,6 +1576,40 @@ int fat_opendir(struct fat_dir *dir, unsigned int startcluster)
return 0;
}
+/* convert from unicode to a single-byte charset */
+void unicode2iso(unsigned char* unicode, unsigned char* iso, int count )
+{
+ int i;
+
+ for (i=0; i<count; i++) {
+ int x = i*2;
+ switch (unicode[x+1]) {
+ case 0x03: /* greek, convert to ISO 8859-7 */
+ iso[i] = unicode[x] + 0x30;
+ break;
+
+ /* Sergei says most russians use Win1251, so we will too.
+ Win1251 differs from ISO 8859-5 by an offset of 0x10. */
+ case 0x04: /* cyrillic, convert to Win1251 */
+ iso[i] = unicode[x] + 0xb0; /* 0xa0 for ISO 8859-5 */
+ break;
+
+ case 0x05: /* hebrew, convert to ISO 8859-8 */
+ iso[i] = unicode[x] + 0x10;
+ break;
+
+ case 0x06: /* arabic, convert to ISO 8859-6 */
+ case 0x0e: /* thai, convert to ISO 8859-11 */
+ iso[i] = unicode[x] + 0xa0;
+ break;
+
+ default:
+ iso[i] = unicode[x];
+ break;
+ }
+ }
+}
+
int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
{
bool done = false;
@@ -1646,7 +1680,7 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
/* replace shortname with longname? */
if ( longs ) {
- int j,k,l=0;
+ int j,l=0;
/* iterate backwards through the dir entries */
for (j=longs-1; j>=0; j--) {
unsigned char* ptr = cached_buf;
@@ -1670,12 +1704,12 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
/* names are stored in unicode, but we
only grab the low byte (iso8859-1). */
- for (k=0; k<5; k++)
- entry->name[l++] = ptr[index + k*2 + 1];
- for (k=0; k<6; k++)
- entry->name[l++] = ptr[index + k*2 + 14];
- for (k=0; k<2; k++)
- entry->name[l++] = ptr[index + k*2 + 28];
+ unicode2iso(ptr + index + 1, entry->name + l, 5);
+ l+= 5;
+ unicode2iso(ptr + index + 14, entry->name + l, 6);
+ l+= 6;
+ unicode2iso(ptr + index + 28, entry->name + l, 2);
+ l+= 2;
}
entry->name[l]=0;
}