diff options
Diffstat (limited to 'emu')
| -rw-r--r-- | emu/Nt/devfs.c | 6 | ||||
| -rw-r--r-- | emu/Nt/r16.c | 44 | ||||
| -rw-r--r-- | emu/Nt/r16.h | 17 | ||||
| -rw-r--r-- | emu/Nt/win.c | 10 |
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); |
