aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-05-29 21:19:32 -0400
committerRuss Cox <rsc@swtch.com>2020-05-29 21:28:59 -0400
commit3850e6e177677885074c8896ef24534894726ad5 (patch)
tree9978899545aad1214513d7801d938f4925c6128c /src
parent2c70acc3ab751ab1ccb1999f1d22310ad8c35b27 (diff)
downloadplan9port-3850e6e177677885074c8896ef24534894726ad5.tar.gz
plan9port-3850e6e177677885074c8896ef24534894726ad5.tar.bz2
plan9port-3850e6e177677885074c8896ef24534894726ad5.zip
devdraw: accept 5- and 6-byte Unicode hex values
Alt X 1234 for U+1234 Alt X X 12345 for U+12345 Alt X X X 103456 for U+103456.
Diffstat (limited to 'src')
-rw-r--r--src/cmd/devdraw/latin1.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/cmd/devdraw/latin1.c b/src/cmd/devdraw/latin1.c
index a3d13a08..87c0be45 100644
--- a/src/cmd/devdraw/latin1.c
+++ b/src/cmd/devdraw/latin1.c
@@ -17,16 +17,15 @@ static struct cvlist
};
/*
- * Given 5 characters k[0]..k[4], find the rune or return -1 for failure.
+ * Given 5 characters k[0]..k[n], find the rune or return -1 for failure.
*/
static long
-unicode(Rune *k)
+unicode(Rune *k, int n)
{
long i, c;
- k++; /* skip 'X' */
c = 0;
- for(i=0; i<4; i++,k++){
+ for(i=0; i<n; i++,k++){
c <<= 4;
if('0'<=*k && *k<='9')
c += *k-'0';
@@ -36,6 +35,8 @@ unicode(Rune *k)
c += 10 + *k-'A';
else
return -1;
+ if(c > Runemax)
+ return -1;
}
return c;
}
@@ -53,10 +54,32 @@ latin1(Rune *k, int n)
char* p;
if(k[0] == 'X'){
- if(n>=5)
- return unicode(k);
- else
- return -5;
+ if(n < 2)
+ return -2;
+ if(k[1] == 'X') {
+ if(n < 3)
+ return -3;
+ if(k[2] == 'X') {
+ if(n < 9) {
+ if(unicode(k+3, n-3) < 0)
+ return -1;
+ return -(n+1);
+ }
+ return unicode(k+3, 6);
+ }
+ if(n < 7) {
+ if(unicode(k+2, n-2) < 0)
+ return -1;
+ return -(n+1);
+ }
+ return unicode(k+2, 5);
+ }
+ if(n < 5) {
+ if(unicode(k+1, n-1) < 0)
+ return -1;
+ return -(n+1);
+ }
+ return unicode(k+1, 4);
}
for(l=latintab; l->ld!=0; l++)