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 = realloc(f->strp, n+Stralloc+1);
183 panic("Can't realloc %d bytes in flush!", n+Stralloc+1);
184 f->bufp = f->strp + n;
185 f->ebuf = f->bufp + Stralloc;
186 memset(f->bufp, '\0', Stralloc+1);
190 if(n && Write(f->fd, f->buf, n) != n){
191 Write(2, "Write error\n", 12);
196 f->ebuf = f->buf+NBUF;
203 io *f = new(struct io);
205 f->bufp = f->ebuf = f->buf;
213 io *f = new(struct io);
216 f->bufp = f->strp = emalloc(Stralloc+1);
217 f->ebuf = f->bufp + Stralloc;
218 memset(f->bufp, '\0', Stralloc+1);
222 * Open a corebuffer to read. EOF occurs after reading len
223 * characters from buf.
227 opencore(char *s, int len)
229 io *f = new(struct io);
230 uchar *buf = emalloc(len);
232 f->fd = -1 /*open("/dev/null", 0)*/;
233 f->bufp = f->strp = buf;
245 io->bufp = io->ebuf = io->buf;
264 if(f->fd==-1 || (n = Read(f->fd, f->buf, NBUF))<=0) return EOF;
266 f->ebuf = f->buf + n;