blob: f1b065bcee408c25c163162aed6da34eb61cc815 [file] [log] [blame]
rscb2cfc4e2003-09-30 17:47:41 +00001#include "lib9.h"
2#include <bio.h>
3#include <utf.h>
4
5long
6Bgetrune(Biobuf *bp)
7{
8 int c, i;
9 Rune rune;
10 char str[4];
11
12 c = Bgetc(bp);
13 if(c < Runeself) { /* one char */
14 bp->runesize = 1;
15 return c;
16 }
17 str[0] = c;
18
19 for(i=1;;) {
20 c = Bgetc(bp);
21 if(c < 0)
22 return c;
23 str[i++] = c;
24
25 if(fullrune(str, i)) {
26 bp->runesize = chartorune(&rune, str);
27 while(i > bp->runesize) {
28 Bungetc(bp);
29 i--;
30 }
31 return rune;
32 }
33 }
34}
35
36int
37Bungetrune(Biobuf *bp)
38{
39
40 if(bp->state == Bracteof)
41 bp->state = Bractive;
42 if(bp->state != Bractive)
43 return Beof;
44 bp->icount -= bp->runesize;
45 bp->runesize = 0;
46 return 1;
47}