Blob
1 #include <u.h>2 #include <libc.h>3 #include <bio.h>6 int7 getn(Biobuf *b)8 {9 int c, n;11 n = 0;12 while((c = Bgetc(b)) != -1 && '0'<=c && c<='9')13 n = n*10+c-'0';14 if(c != ' ')15 sysfatal("bad number syntax");16 return n;17 }19 char*20 getrune(Biobuf *b, char *p)21 {22 int c;23 char *q;25 c = Bgetc(b);26 if(c == -1)27 sysfatal("eof");28 q = p;29 *q++ = c;30 if(c >= Runeself){31 while(!fullrune(p, q-p)){32 c = Bgetc(b);33 if(c == -1)34 sysfatal("eof");35 *q++ = c;36 }37 }38 return q;39 }41 void42 getevent(Biobuf *b, int *c1, int *c2, int *q0, int *q1, int *flag, int *nr, char *buf)43 {44 int i;45 char *p;47 *c1 = Bgetc(b);48 if(*c1 == -1)49 exits(0);50 *c2 = Bgetc(b);51 *q0 = getn(b);52 *q1 = getn(b);53 *flag = getn(b);54 *nr = getn(b);55 if(*nr >= 256)56 sysfatal("event string too long");57 p = buf;58 for(i=0; i<*nr; i++)59 p = getrune(b, p);60 *p = 0;61 if(Bgetc(b) != '\n')62 sysfatal("expected newline");63 }65 void66 main(void)67 {68 int c1, c2, q0, q1, eq0, eq1, flag, nr, x;69 Biobuf b;70 char buf[2000], buf2[2000], buf3[2000];72 doquote = needsrcquote;73 quotefmtinstall();74 Binit(&b, 0, OREAD);75 for(;;){76 getevent(&b, &c1, &c2, &q0, &q1, &flag, &nr, buf);77 eq0 = q0;78 eq1 = q1;79 buf2[0] = 0;80 buf3[0] = 0;81 if(flag & 2){82 /* null string with non-null expansion */83 getevent(&b, &x, &x, &eq0, &eq1, &x, &nr, buf);84 }85 if(flag & 8){86 /* chorded argument */87 getevent(&b, &x, &x, &x, &x, &x, &x, buf2);88 getevent(&b, &x, &x, &x, &x, &x, &x, buf3);89 }90 print("event %c %c %d %d %d %d %d %d %q %q %q\n",91 c1, c2, q0, q1, eq0, eq1, flag, nr, buf, buf2, buf3);92 }93 }