summaryrefslogtreecommitdiff
path: root/emu/Nt/r16.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/Nt/r16.c')
-rw-r--r--emu/Nt/r16.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/emu/Nt/r16.c b/emu/Nt/r16.c
new file mode 100644
index 00000000..f340f3e4
--- /dev/null
+++ b/emu/Nt/r16.c
@@ -0,0 +1,94 @@
+#define UNICODE
+#define Unknown win_Unknown
+#include <windows.h>
+#include <winbase.h>
+#undef Unknown
+#undef Sleep
+#include "dat.h"
+#include "fns.h"
+#include "error.h"
+#include "r16.h"
+
+Rune16*
+runesdup(Rune16 *r)
+{
+ int n;
+ Rune16 *s;
+
+ n = runeslen(r) + 1;
+ s = malloc(n * sizeof(Rune16));
+ if(s == nil)
+ error(Enomem);
+ memmove(s, r, n * sizeof(Rune16));
+ return s;
+}
+
+int
+runeslen(Rune16 *r)
+{
+ int n;
+
+ n = 0;
+ while(*r++ != 0)
+ n++;
+ return n;
+}
+
+char*
+runestoutf(char *p, Rune16 *r, int nc)
+{
+ char *op, *ep;
+ int n, c;
+ Rune rc;
+
+ op = p;
+ ep = p + nc;
+ while(c = *r++) {
+ n = 1;
+ if(c >= Runeself)
+ n = runelen(c);
+ if(p + n >= ep)
+ break;
+ rc = c;
+ if(c < Runeself)
+ *p++ = c;
+ else
+ p += runetochar(p, &rc);
+ }
+ *p = '\0';
+ return op;
+}
+
+Rune16*
+utftorunes(Rune16 *r, char *p, int nc)
+{
+ Rune16 *or, *er;
+ Rune rc;
+
+ or = r;
+ er = r + nc;
+ while(*p != '\0' && r + 1 < er){
+ p += chartorune(&rc, p);
+ *r++ = rc; /* we'll ignore surrogate pairs */
+ }
+ *r = '\0';
+ return or;
+}
+
+int
+runescmp(Rune16 *s1, Rune16 *s2)
+{
+ Rune16 r1, r2;
+
+ for(;;) {
+ r1 = *s1++;
+ r2 = *s2++;
+ if(r1 != r2) {
+ if(r1 > r2)
+ return 1;
+ return -1;
+ }
+ if(r1 == 0)
+ return 0;
+ }
+}