summaryrefslogtreecommitdiff
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
parent601d77dc635813682f8d3c03236fc302a101d236 (diff)
downloadrockbox-32bfc9940c4e35807979b739aa824e4867c13987.tar.gz
rockbox-32bfc9940c4e35807979b739aa824e4867c13987.zip
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
-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)
1576 return 0; 1576 return 0;
1577} 1577}
1578 1578
1579/* convert from unicode to a single-byte charset */
1580void unicode2iso(unsigned char* unicode, unsigned char* iso, int count )
1581{
1582 int i;
1583
1584 for (i=0; i<count; i++) {
1585 int x = i*2;
1586 switch (unicode[x+1]) {
1587 case 0x03: /* greek, convert to ISO 8859-7 */
1588 iso[i] = unicode[x] + 0x30;
1589 break;
1590
1591 /* Sergei says most russians use Win1251, so we will too.
1592 Win1251 differs from ISO 8859-5 by an offset of 0x10. */
1593 case 0x04: /* cyrillic, convert to Win1251 */
1594 iso[i] = unicode[x] + 0xb0; /* 0xa0 for ISO 8859-5 */
1595 break;
1596
1597 case 0x05: /* hebrew, convert to ISO 8859-8 */
1598 iso[i] = unicode[x] + 0x10;
1599 break;
1600
1601 case 0x06: /* arabic, convert to ISO 8859-6 */
1602 case 0x0e: /* thai, convert to ISO 8859-11 */
1603 iso[i] = unicode[x] + 0xa0;
1604 break;
1605
1606 default:
1607 iso[i] = unicode[x];
1608 break;
1609 }
1610 }
1611}
1612
1579int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) 1613int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1580{ 1614{
1581 bool done = false; 1615 bool done = false;
@@ -1646,7 +1680,7 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1646 1680
1647 /* replace shortname with longname? */ 1681 /* replace shortname with longname? */
1648 if ( longs ) { 1682 if ( longs ) {
1649 int j,k,l=0; 1683 int j,l=0;
1650 /* iterate backwards through the dir entries */ 1684 /* iterate backwards through the dir entries */
1651 for (j=longs-1; j>=0; j--) { 1685 for (j=longs-1; j>=0; j--) {
1652 unsigned char* ptr = cached_buf; 1686 unsigned char* ptr = cached_buf;
@@ -1670,12 +1704,12 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1670 1704
1671 /* names are stored in unicode, but we 1705 /* names are stored in unicode, but we
1672 only grab the low byte (iso8859-1). */ 1706 only grab the low byte (iso8859-1). */
1673 for (k=0; k<5; k++) 1707 unicode2iso(ptr + index + 1, entry->name + l, 5);
1674 entry->name[l++] = ptr[index + k*2 + 1]; 1708 l+= 5;
1675 for (k=0; k<6; k++) 1709 unicode2iso(ptr + index + 14, entry->name + l, 6);
1676 entry->name[l++] = ptr[index + k*2 + 14]; 1710 l+= 6;
1677 for (k=0; k<2; k++) 1711 unicode2iso(ptr + index + 28, entry->name + l, 2);
1678 entry->name[l++] = ptr[index + k*2 + 28]; 1712 l+= 2;
1679 } 1713 }
1680 entry->name[l]=0; 1714 entry->name[l]=0;
1681 } 1715 }