On *printf

Brandon S. Allbery allbery at ncoast.ORG
Mon Apr 10 10:48:26 AEST 1989


It might interest those people discussing *sprintf's to know that I'm
working on a ...I can't really call it stdio... library that combines the
concepts of streams (stdio) and STREAMS.  (Code?  You must be kidding.  I'd
have to mortgage my firstborn on speculation to be able to look at the code,
not that I would want to or that it would do me any good.)  It's something
like "functional stdio", except that any XIO stream can have modules pushed
onto it to do random conversions.  XIO streams are bi-directional, and I'm
doing my best to allow for the possibility of multiple threads a' la Mach...
combining threads with some of the features in XIO could produce some
remarkably powerful yet elegant programs.  (Of course, we'll have to see how
far I get before it turns too ugly to complete... although I hope I'm up to
the task, I'm not exactly the world's best programmer.)  One of the standard
"driver modules" will implement writing to memory as if it were a file; this
could easily be extended to the use of dynamically malloc()'ed storage.  It
would solve the buffer-size problem rather neatly:

	XIO *xp;
	char *bufp;

	if (!(xp = xopen(&bufp, xio_dyn_buf, "w"))) {
		fprintf(stderr, "can't xopen(xio_dyn_buf)\n");
		exit(1);
	}
	if (xsprintf(xp, format, ...) <= 0 || !xclose(xp)) {
		fprintf(stderr, "xio_dyn_buf: out of memory\n");
		exit(2);
	}
	use(bufp);
	free(bufp);

Note that, since XIO hides the internals of the XIO descriptor's
functionality, the "xsprintf" above could be any XIO operation or any user
function which makes XIO calls; and the XIO can transparently have modules
pushed on it to modify the data before buffering it.  If I can pull this off
(the trickiest part being trying to allow for future use in a multi-threaded
environment) it should be quite useful.

I'm surprised nobody else thought of this.  (I'll send anyone who's
interested a complete description of the stuff I'm putting together; even if
I can't pull it off, *someone* out there might -- and I might be missing
some bets.  I'm not overproud; let's work together to put together the
ultimate I/O library.  Think of the possibilities... but possibly not in this
newsgroup.)

Here's hoping...
++Brandon
-- 
Brandon S. Allbery, moderator of comp.sources.misc	     allbery at ncoast.org
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery at hal.cwru.edu
      Send comp.sources.misc submissions to comp-sources-misc@<backbone>
NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser



More information about the Comp.unix.wizards mailing list