void fmtzbinit(Fmt *f, ZBlock *b) { memset(f, 0, sizeof *f); #ifdef PLAN9PORT fmtlocaleinit(f, nil, nil, nil); #endif f->start = b->data; f->to = f->start; f->stop = (char*)f->start + b->len; }
/* * initialize an output buffer for buffered printing */ int fmtfdinit(Fmt *f, int fd, char *buf, int size) { f->runes = 0; f->start = buf; f->to = buf; f->stop = buf + size; f->flush = __fmtFdFlush; f->farg = (void*)(uintptr_t)fd; f->flags = 0; f->nfmt = 0; fmtlocaleinit(f, nil, nil, nil); return 0; }
int fmtstrinit(Fmt *f) { int n; memset(f, 0, sizeof *f); f->runes = 0; n = 32; f->start = malloc(n); if(f->start == nil) return -1; f->to = f->start; f->stop = (char*)f->start + n - 1; f->flush = fmtStrFlush; f->farg = (void*)(uintptr)n; f->nfmt = 0; fmtlocaleinit(f, nil, nil, nil); return 0; }
int runefmtstrinit(Fmt *f) { int n; memset(f, 0, sizeof *f); f->runes = 1; n = 32; f->start = malloc(sizeof(Rune)*n); if(f->start == nil) return -1; f->to = f->start; f->stop = (Rune*)f->start + n - 1; f->flush = runeFmtStrFlush; f->farg = (void*)(uintptr_t)n; f->nfmt = 0; fmtlocaleinit(f, nil, nil, nil); return 0; }
int Bvprint(Biobuf *bp, const char *fmt, va_list arg) { int n; Fmt f; f.runes = 0; f.stop = bp->ebuf; f.start = (char*)f.stop + bp->ocount; f.to = f.start; f.flush = fmtBflush; f.farg = bp; f.nfmt = 0; fmtlocaleinit(&f, nil, nil, nil); n = fmtvprint(&f, fmt, arg); bp->ocount = (char*)f.to - (char*)f.stop; if(n == 0) n = f.nfmt; return n; }
char* vseprint(char *buf, char *e, char *fmt, va_list args) { Fmt f; if(e <= buf) return nil; f.runes = 0; f.start = buf; f.to = buf; f.stop = e - 1; f.flush = 0; f.farg = nil; f.nfmt = 0; VA_COPY(f.args,args); fmtlocaleinit(&f, nil, nil, nil); dofmt(&f, fmt); VA_END(f.args); *(char*)f.to = '\0'; return (char*)f.to; }