Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!think!caip!brl-adm!brl-smoke!smoke!rbj@icst-cmr From: rbj%icst-cmr@smoke.UUCP Newsgroups: net.lang.c Subject: Re: Another printf-type question Message-ID: <2225@brl-smoke.ARPA> Date: Mon, 14-Jul-86 19:07:57 EDT Article-I.D.: brl-smok.2225 Posted: Mon Jul 14 19:07:57 1986 Date-Received: Tue, 15-Jul-86 06:56:07 EDT Sender: news@brl-smoke.ARPA Lines: 83 > In article <2138@brl-smoke.ARPA> LINNDR%VUENGVAX.BITNET@WISCVM.ARPA writes: > >invprintf(fmt,args) > >{ > > printf(); > > printf(fmt,args); > > printf(); > >} > > > >This simple solution didn't work. Oh great gurus of such things, what > >should I have done? The solution presented below is probably correct, given the poster. I find it rather unreadable, and would opt for a more local but readable solution. Having expressed my opinions, I present my solutions along with their required constraints. First I present Berkeley's solution: /* @(#)printf.c 4.1 (Berkeley) 12/21/80 */ #include printf(fmt, args) char *fmt; { ABC: _doprnt(fmt, &args, stdout); return(ferror(stdout)? EOF: 0); XYZ: } The labels ABC & XYZ are where you put the strings to go into reverse video and back to normal. You also must fix up the return status to account for the extra I/O. This only works if all the arguments are pushed on the stack in reverse order. VAXen, SUNS, most any 68k box, Sequent, most any ns32032 box, and anyone else attempting to be reasonable. Secondly, if you are willing to limit 1) the number of parameters to a reasonable number, say ten 2) the type of parameters to only integers and pointers 3) sizeof(int) = sizeof(int *) = sizeof(char *) = sizeof(any *) then you might like the following solution: invprintf(fmt,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9) { printf(); printf(fmt,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9); printf(); } > Assuming you're using UNIX System V Release 2.0 for sake of concreteness, > #include > #include > > void > invprintf( va_alist ) > va_dcl > { > char *fmt; /* printf control string */ > va_list args; /* argument pointer */ > > (void)fputs( "string to enter inverse video mode", stdout ); > > va_start( args ); > > fmt = va_arg( args, char * ); > > (void)vprintf( fmt, args ); /* warning! not printf(va_arg etc. */ > > va_end( args ); > > (void)fputs( "string to leave inverse video mode", stdout ); > } > > The final mechanism of ANSI X3J11 will probably be slightly different. > > P.S. You should perhaps also test whether the write to the terminal succeeds. (Root Boy) Jim Cottrell Are we live or on tape? .