Xref: utzoo comp.unix.wizards:15167 comp.lang.c:17131 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!garfield!michael From: michael@garfield.MUN.EDU (Mike Rendell) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: How to predict size of outcome of vsprintf? Message-ID: <5124@garfield.MUN.EDU> Date: 23 Mar 89 15:29:49 GMT References: <993@etnibsd.UUCP> <9872@smoke.BRL.MIL> <28831@bu-cs.BU.EDU> <16491@mimsy.UUCP> <24451@watmath.waterloo.edu> Reply-To: michael@garfield.UUCP (Mike Rendell) Organization: Memorial University of Newfoundland Lines: 25 In article bader+@andrew.cmu.edu (Miles Bader) writes: >What I'd really like would be a new function that could act as a basis >for all the other printf functions, and make it possible to emulate >them in nice ways. > >I would make it a varargs function that takes a bounded output buffer >and is restartable at the point where it stops due to running into the >end of the buffer. I wrote a version of doprnt() which does something like this. Instead of taking a FILE * argument it's passed a function pointer and a "generic argument" (void/char *). new_doprnt() fills up a stack buffer and calls the function (which takes the same arguments as fwrite()) to deal with it. This makes printf() and a bounds checking sprintf() (or a re-alloc()ing sprintf()) easy to write as well as providing a simple method for programmers to hook into it. I've used it in some screen based programs to page output and in some stand alone programs to do output to a console. The only draw back is that it doesn't handle %[egf] - but who needs those anyway :-). Mike Rendell Department of Computer Science michael@garfield.mun.edu Memorial University of Newfoundland uunet!garfield!michael St. John's, Nfld., Canada (709) 737-4550 A1C 5S7