aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2011-01-02 13:44:15 -0500
committerRuss Cox <rsc@swtch.com>2011-01-02 13:44:15 -0500
commit0786c9647c0232825777d8e1c464bef72fdac738 (patch)
tree10bfefddaf24fab2f9c0bb1f8fe4d4c6da81a3bb /src/cmd/rc
parent72f66c2d3ca556d35b818158e9de578c4bfa153e (diff)
downloadplan9port-0786c9647c0232825777d8e1c464bef72fdac738.tar.gz
plan9port-0786c9647c0232825777d8e1c464bef72fdac738.tar.bz2
plan9port-0786c9647c0232825777d8e1c464bef72fdac738.zip
rc: handle 4-byte utf-8
R=rsc http://codereview.appspot.com/3833043
Diffstat (limited to 'src/cmd/rc')
-rw-r--r--src/cmd/rc/glob.c13
-rw-r--r--src/cmd/rc/lex.c5
-rw-r--r--src/cmd/rc/rc.h2
3 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/rc/glob.c b/src/cmd/rc/glob.c
index 6eaa8316..baea44d9 100644
--- a/src/cmd/rc/glob.c
+++ b/src/cmd/rc/glob.c
@@ -125,6 +125,17 @@ equtf(char *p, char *q)
return 1; /* broken code at end of string! */
return p[2]==q[2];
}
+ if(fourbyte(*p)){
+ if(p[1]!=q[1])
+ return 0;
+ if(p[1]=='\0')
+ return 1;
+ if(p[2]!=q[2])
+ return 0;
+ if(p[2]=='\0')
+ return 1;
+ return p[3]==q[3];
+ }
return 1;
}
/*
@@ -137,6 +148,7 @@ nextutf(char *p)
{
if(twobyte(*p)) return p[1]=='\0'?p+1:p+2;
if(threebyte(*p)) return p[1]=='\0'?p+1:p[2]=='\0'?p+2:p+3;
+ if(fourbyte(*p)) return p[1]=='\0'?p+1:p[2]=='\0'?p+2:p[3]=='\0'?p+3:p+4;
return p+1;
}
/*
@@ -149,6 +161,7 @@ unicode(char *p)
int u=*p&0xff;
if(twobyte(u)) return ((u&0x1f)<<6)|(p[1]&0x3f);
if(threebyte(u)) return (u<<12)|((p[1]&0x3f)<<6)|(p[2]&0x3f);
+ if(fourbyte(u)) return (u<<18)|((p[1]&0x3f)<<12)|((p[2]&0x3f)<<6)|(p[3]&0x3f);
return u;
}
/*
diff --git a/src/cmd/rc/lex.c b/src/cmd/rc/lex.c
index 36934832..d9369e5c 100644
--- a/src/cmd/rc/lex.c
+++ b/src/cmd/rc/lex.c
@@ -173,6 +173,11 @@ addutf(char *p, int c)
p = addtok(p, advance());
return addtok(p, advance());
}
+ if(fourbyte(c)){ /* 4-byte escape */
+ p = addtok(p, advance());
+ p = addtok(p, advance());
+ return addtok(p, advance());
+ }
return p;
}
int lastdol; /* was the last token read '$' or '$#' or '"'? */
diff --git a/src/cmd/rc/rc.h b/src/cmd/rc/rc.h
index f95b5287..7778ff4c 100644
--- a/src/cmd/rc/rc.h
+++ b/src/cmd/rc/rc.h
@@ -121,6 +121,8 @@ int mypid;
#define onebyte(c) ((c&0x80)==0x00)
#define twobyte(c) ((c&0xe0)==0xc0)
#define threebyte(c) ((c&0xf0)==0xe0)
+#define fourbyte(c) ((c&0xf8)==0xf0)
+
char **argp;
char **args;
int nerror; /* number of errors encountered during compilation */