6 enum { Stralloc = 100, };
11 pfmt(io *f, char *fmt, ...)
23 if(*++fmt == '\0') /* "blah%"? */
27 pchr(f, va_arg(ap, int));
30 pdec(f, va_arg(ap, int));
33 poct(f, va_arg(ap, unsigned));
36 pptr(f, va_arg(ap, void*));
39 pquo(f, va_arg(ap, char *));
42 pwrd(f, va_arg(ap, char *));
45 errstr(err, sizeof err); pstr(f, err);
48 pstr(f, va_arg(ap, char *));
51 pcmd(f, va_arg(ap, struct tree *));
54 pval(f, va_arg(ap, struct word *));
97 for(t = s;*t;t++) if(*t >= 0 && needsrcquote(*t)) break;
110 if(sizeof(uintptr) == sizeof(uvlong) && p>>32)
111 for(n = 60;n>=32;n-=4) pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
113 for(n = 28;n>=0;n-=4) pchr(f, "0123456789ABCDEF"[(p>>n)&0xF]);
121 while(*s) pchr(f, *s++);
134 /* n is two's complement minimum integer */
147 poct(io *f, unsigned n)
158 while(a->next && a->next->word){
159 pwrd(f, (char *)a->word);
163 pwrd(f, (char *)a->word);
168 fullbuf(io *f, int c)
180 n = f->ebuf - f->strp;
181 f->strp = erealloc(f->strp, n+Stralloc+1);
182 f->bufp = f->strp + n;
183 f->ebuf = f->bufp + Stralloc;
184 memset(f->bufp, '\0', Stralloc+1);
188 if(n && Write(f->fd, f->buf, n) != n){
189 Write(2, "Write error\n", 12);
194 f->ebuf = f->buf+NBUF;
201 io *f = new(struct io);
203 f->bufp = f->ebuf = f->buf;
211 io *f = new(struct io);
214 f->bufp = f->strp = emalloc(Stralloc+1);
215 f->ebuf = f->bufp + Stralloc;
216 memset(f->bufp, '\0', Stralloc+1);
220 * Open a corebuffer to read. EOF occurs after reading len
221 * characters from buf.
225 opencore(char *s, int len)
227 io *f = new(struct io);
228 uchar *buf = emalloc(len);
230 f->fd = -1 /*open("/dev/null", 0)*/;
231 f->bufp = f->strp = buf;
243 io->bufp = io->ebuf = io->buf;
262 if(f->fd==-1 || (n = Read(f->fd, f->buf, NBUF))<=0) return EOF;
264 f->ebuf = f->buf + n;