fiss

Friedel's Initialization and Service Supervision
Log | Files | Refs | LICENSE

bgetrune.c (645B)


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