From e830a908498c8f0270948fd08c50f6d773315880 Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 6 Nov 2005 22:16:48 +0000 Subject: New 9term using rio sources more directly. --- src/cmd/9term/util.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/cmd/9term/util.c (limited to 'src/cmd/9term/util.c') diff --git a/src/cmd/9term/util.c b/src/cmd/9term/util.c new file mode 100644 index 00000000..8a35d1d7 --- /dev/null +++ b/src/cmd/9term/util.c @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" + +void +cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls) +{ + uchar *q; + Rune *s; + int j, w; + + /* + * Always guaranteed that n bytes may be interpreted + * without worrying about partial runes. This may mean + * reading up to UTFmax-1 more bytes than n; the caller + * knows this. If n is a firm limit, the caller should + * set p[n] = 0. + */ + q = (uchar*)p; + s = r; + for(j=0; j?@[\\]^`{|}~", c)) + return FALSE; + return TRUE; +} + +Rune* +strrune(Rune *s, Rune c) +{ + Rune c1; + + if(c == 0) { + while(*s++) + ; + return s-1; + } + + while(c1 = *s++) + if(c1 == c) + return s-1; + return nil; +} + +int +min(int a, int b) +{ + if(a < b) + return a; + return b; +} + +int +max(int a, int b) +{ + if(a > b) + return a; + return b; +} + +char* +runetobyte(Rune *r, int n, int *ip) +{ + char *s; + int m; + + s = emalloc(n*UTFmax+1); + m = snprint(s, n*UTFmax+1, "%.*S", n, r); + *ip = m; + return s; +} + -- cgit v1.2.3