summaryrefslogtreecommitdiff
path: root/emu/Nt
diff options
context:
space:
mode:
authorCharles Forsyth <charles.forsyth@gmail.com>2015-06-14 12:32:13 +0100
committerCharles Forsyth <charles.forsyth@gmail.com>2015-06-14 12:32:13 +0100
commit89dfe4bea0ef29d57db26cade21924eb38402e02 (patch)
tree3c1d63e095ae2070c1e2bc595639d23fc5c4bf6f /emu/Nt
parent62d7827bc358c000db9ff48fe61bd28ac352a884 (diff)
handle 16-bit unicode from Windows in clipboard and fs names
Diffstat (limited to 'emu/Nt')
-rw-r--r--emu/Nt/devfs.c6
-rw-r--r--emu/Nt/r16.c44
-rw-r--r--emu/Nt/r16.h17
-rw-r--r--emu/Nt/win.c10
4 files changed, 61 insertions, 16 deletions
diff --git a/emu/Nt/devfs.c b/emu/Nt/devfs.c
index 6d79c35b..2e61e760 100644
--- a/emu/Nt/devfs.c
+++ b/emu/Nt/devfs.c
@@ -1659,10 +1659,10 @@ secstat(Dir *dir, char *file, Rune16 *srv)
free(sd);
if(ok){
dir->mode = st.mode;
- n = runenlen(st.owner->name, runes16len(st.owner->name));
+ n = rune16nlen(st.owner->name, runes16len(st.owner->name));
dir->uid = smalloc(n+1);
runes16toutf(dir->uid, st.owner->name, n+1);
- n = runenlen(st.group->name, runes16len(st.group->name));
+ n = rune16nlen(st.group->name, runes16len(st.group->name));
dir->gid = smalloc(n+1);
runes16toutf(dir->gid, st.group->name, n+1);
}
@@ -1688,7 +1688,7 @@ secsize(char *file, Rune16 *srv)
if(sd != (void*)sdrock)
free(sd);
if(ok)
- return runenlen(st.owner->name, runes16len(st.owner->name))+runenlen(st.group->name, runes16len(st.group->name));
+ return rune16nlen(st.owner->name, runes16len(st.owner->name))+rune16nlen(st.group->name, runes16len(st.group->name));
return -1;
}
diff --git a/emu/Nt/r16.c b/emu/Nt/r16.c
index cdbc13ac..92a36521 100644
--- a/emu/Nt/r16.c
+++ b/emu/Nt/r16.c
@@ -9,6 +9,28 @@
#include "error.h"
#include "r16.h"
+#define Bit(i) (7-(i))
+/* N 0's preceded by i 1's, T(Bit(2)) is 1100 0000 */
+#define T(i) (((1 << (Bit(i)+1))-1) ^ 0xFF)
+/* 0000 0000 0000 0111 1111 1111 */
+#define RuneX(i) ((1 << (Bit(i) + ((i)-1)*Bitx))-1)
+
+enum
+{
+ Bitx = Bit(1),
+
+ Tx = T(1), /* 1000 0000 */
+ Rune1 = (1<<(Bit(0)+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */
+
+ Maskx = (1<<Bitx)-1, /* 0011 1111 */
+ Testx = Maskx ^ 0xFF, /* 1100 0000 */
+
+ SurrogateMin = 0xD800,
+ SurrogateMax = 0xDFFF,
+
+ Bad = Runeerror,
+};
+
Rune16*
runes16dup(Rune16 *r)
{
@@ -59,6 +81,28 @@ runes16toutf(char *p, Rune16 *r, int nc)
return op;
}
+int
+rune16nlen(Rune16 *r, int nrune)
+{
+ int nb, i;
+ Rune c;
+
+ nb = 0;
+ while(nrune--) {
+ c = *r++;
+ if(c <= Rune1){
+ nb++;
+ } else {
+ for(i = 2; i < UTFmax + 1; i++)
+ if(c <= RuneX(i) || i == UTFmax){
+ nb += i;
+ break;
+ }
+ }
+ }
+ return nb;
+}
+
Rune16*
utftorunes16(Rune16 *r, char *p, int nc)
{
diff --git a/emu/Nt/r16.h b/emu/Nt/r16.h
index de09eacc..ea4ee286 100644
--- a/emu/Nt/r16.h
+++ b/emu/Nt/r16.h
@@ -1,10 +1,11 @@
typedef unsigned short Rune16;
- wchar_t *widen(char *s);
- char *narrowen(wchar_t *ws);
- int widebytes(wchar_t *ws);
- int runes16len(Rune16*);
- Rune16* runes16dup(Rune16*);
- Rune16* utftorunes16(Rune16*, char*, int);
- char* runes16toutf(char*, Rune16*, int);
- int runes16cmp(Rune16*, Rune16*);
+wchar_t *widen(char *s);
+char *narrowen(wchar_t *ws);
+int widebytes(wchar_t *ws);
+int runes16len(Rune16*);
+int rune16nlen(Rune16*, int);
+Rune16* runes16dup(Rune16*);
+Rune16* utftorunes16(Rune16*, char*, int);
+char* runes16toutf(char*, Rune16*, int);
+int runes16cmp(Rune16*, Rune16*);
diff --git a/emu/Nt/win.c b/emu/Nt/win.c
index b6330b16..c1bccfa7 100644
--- a/emu/Nt/win.c
+++ b/emu/Nt/win.c
@@ -32,10 +32,10 @@
#include <draw.h>
#include "keyboard.h"
#include "cursor.h"
+#include "r16.h"
extern ulong displaychan;
-extern char* runes16toutf(char*, Rune*, int);
extern int bytesperline(Rectangle, int);
extern int main(int argc, char **argv);
static void dprint(char*, ...);
@@ -698,12 +698,12 @@ drawcursor(Drawcursor* c)
static char*
clipreadunicode(HANDLE h)
{
- Rune *p;
+ Rune16 *p;
int n;
char *q;
p = GlobalLock(h);
- n = runenlen(p, runestrlen(p)+1);
+ n = rune16nlen(p, runes16len(p)+1);
q = malloc(n);
if(q != nil)
runes16toutf(q, p, n);
@@ -753,7 +753,7 @@ clipwrite(char *buf)
{
HANDLE h;
char *p;
- Rune *rp;
+ Rune16 *rp;
int n;
n = 0;
@@ -767,7 +767,7 @@ clipwrite(char *buf)
return -1;
}
- h = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, (n+1)*sizeof(Rune));
+ h = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, (n+1)*sizeof(Rune16));
if(h == NULL)
error(Enovmem);
rp = GlobalLock(h);