summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-05 03:07:04 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-05 03:08:10 (GMT)
commit4e026921322553ffaa6a58f6551c29ea890d5e1d (patch)
tree0f65059996b6ff73c964568c433f1cb6b5468683
parent140bf5601d8400846cbf844ab5a9aaf62bbfb784 (diff)
downloadabcdisk-4e026921322553ffaa6a58f6551c29ea890d5e1d.zip
abcdisk-4e026921322553ffaa6a58f6551c29ea890d5e1d.tar.gz
abcdisk-4e026921322553ffaa6a58f6551c29ea890d5e1d.tar.bz2
abcdisk-4e026921322553ffaa6a58f6551c29ea890d5e1d.tar.xz
abcwrite: handle UTF-8 encoded source filesystems
-rw-r--r--abcwrite.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/abcwrite.c b/abcwrite.c
index c6373a1..a052cf5 100644
--- a/abcwrite.c
+++ b/abcwrite.c
@@ -3,14 +3,17 @@
*
* Program to build a populated ABC-DOS hard disk image
*/
+#include <ctype.h>
+#include <dirent.h>
+#include <limits.h>
+#include <locale.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-#include <ctype.h>
+#include <string.h>
#include <unistd.h>
-#include <sys/types.h>
+#include <wchar.h>
#include <sys/stat.h>
-#include <dirent.h>
+#include <sys/types.h>
const char *program;
@@ -48,9 +51,20 @@ void mark_used(int sector)
*/
int mangle_name(char *dst, const char *src)
{
+ static const wchar_t srcset[] =
+ L"0123456789_."
+ L"ÉABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÅÜÆØ"
+ L"éabcdefghijklmnopqrstuvwxyzäöåüæø";
+ static const char dstset[] =
+ "0123456789_."
+ "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^[\\"
+ "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^[\\";
char *d = dst;
const char *s, *p;
- char c;
+ wchar_t sc;
+ const wchar_t *scp;
+ char dc;
+ int n;
if ( (p = strrchr(src,'/')) )
s = p+1;
@@ -60,16 +74,21 @@ int mangle_name(char *dst, const char *src)
memset(dst, ' ', 11);
dst[11] = '\0';
- while ( (c = *s++) && d < dst+11 ) {
- const char *xstr = "";
- if ( (p = strchr(xstr, c)) ) {
- c = "@][\\^@][\\^"[p-xstr];
+ mbtowc(NULL, NULL, 0); /* Reset the shift state */
+
+ while (d < dst+11 && (n = mbtowc(&sc, s, (size_t)~0)) > 0) {
+ s += n;
+
+ if ( (scp = wcschr(srcset, sc)) ) {
+ dc = dstset[scp - srcset];
+ } else {
+ dc = '_';
}
- if ( c == '.' )
+ if ( dc == '.' )
d = dst+8;
else
- *d++ = toupper((unsigned char)c);
+ *d++ = dc;
}
return 0;
@@ -371,6 +390,8 @@ int main(int argc, char *argv[])
{
int i;
+ setlocale(LC_ALL, "");
+
program = argv[0];
memset(image, 0xe5, 238*256*256);