diff options
Diffstat (limited to 'src/base/utf/vendor/common.c')
-rw-r--r-- | src/base/utf/vendor/common.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/src/base/utf/vendor/common.c b/src/base/utf/vendor/common.c index fcf1177..c35d022 100644 --- a/src/base/utf/vendor/common.c +++ b/src/base/utf/vendor/common.c @@ -4,36 +4,32 @@ // input functions int -parse(io·Stream *io, int nfield, char **field, int len, char *line) +parse(io·Buffer *io, int nfield, char field[][FieldLen]) { int n; - if((n=io·readln(io, len, line)) <= 0) - return ParseEOF; - - if(n == len) - panicf("line too long"); - - if(line[n-1] != '\n') - panicf("invalid line: expected '\n', found '%c'", line[n]); + char *b, *e; - line[n-1] = 0; + if(!(b=io·readline((io·Header*)io,1))) + return ParseEOF; - if(line[0] == '#' || line[0] == 0) + if(b[0] == '#' || b[0] == 0) return ParseSkip; /* tokenize line into fields */ n = 0; - field[n] = line; - while(*line){ - if(*line == ';'){ - *line = 0; - field[++n] = line+1; - } - line++; + e = b; + while(*e){ + if(*e == ';'){ + *e = 0; + strcpy(field[n++], b); + b = ++e; + }else + ++e; } + strcpy(field[n++], b); - if(n != nfield-1) - panicf("expected %d number of fields, got %d: %s", nfield, n, line); + if(n != nfield) + panicf("expected %d number of fields, got %d: %s", nfield, n, b); return ParseOK; } @@ -58,10 +54,10 @@ codepoint(char *s) } void -codepointrange(io·Stream *utf8, char *field[NumFields], int *start, int *stop) +codepointrange(io·Buffer *utf8, char field[NumFields][FieldLen], int *start, int *stop) { int e, c; - char *other[NumFields], line[1024]; + char other[NumFields][FieldLen]; // XXX: the stop variable passes in the previous stopping character e = *stop; @@ -74,7 +70,7 @@ codepointrange(io·Stream *utf8, char *field[NumFields], int *start, int *stop) e = c; if(strstr(field[Fname], ", First>") != nil){ - if(!parse(utf8, arrlen(other), other, arrlen(line), line)) + if(!parse(utf8, arrlen(other), other)) panicf("range start at end of file"); if(strstr(other[Fname], ", Last>") == nil) panicf("range start not followed by range end"); @@ -101,8 +97,7 @@ putsearch(void) "#include <u.h>\n" "#include <base/utf.h>\n" "\n" - "static\n" - "rune*\n" + "static rune*\n" "rangesearch(rune c, rune *t, int n, int ne)\n" "{\n" " rune *p;\n" |