Another printf-type question
rbj%icst-cmr at smoke.UUCP
rbj%icst-cmr at smoke.UUCP
Tue Jul 15 09:07:57 AEST 1986
> In article <2138 at brl-smoke.ARPA> LINNDR%VUENGVAX.BITNET at WISCVM.ARPA writes:
> >invprintf(fmt,args)
> >{
> > printf(<string to go into inverse video mode>);
> > printf(fmt,args);
> > printf(<string to leave inverse mode>);
> >}
> >
> >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 <stdio.h>
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(<reverse video>);
printf(fmt,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9);
printf(<reverse video>);
}
> Assuming you're using UNIX System V Release 2.0 for sake of concreteness,
> #include <stdio.h>
> #include <varargs.h>
>
> 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 <rbj at icst-cmr.arpa>
Are we live or on tape?
.
More information about the Comp.lang.c
mailing list