kschnitz@puff.UUCP (Soccer Stud) (07/12/89)
Help! This function came with the tetris game I got for Unix based machines. The problem is vsprintf is undefined using my C libraries. Does anyone have a simple solution? Please post the answer because others have had the same problem. Thanks in advance. /***************************************************************************\ |* *| |* This is my home-made varargs-based version of C++'s neat function of *| |* the same name. It saves all that tedious mucking about with static *| |* buffers which you sprintf into, then forget all about, by basically *| |* being a sprintf with its own statis storage. It takes as arguments *| |* exactly the same things as printf(3), and returns a pointer to the *| |* resultant string. *| |* *| \***************************************************************************/ /*VARARGS*/ char *form (va_alist) va_dcl { va_list pvar; char *fmt_string; static char result[LINELEN]; va_start (pvar); fmt_string = va_arg (pvar, char*); (void) vsprintf (result, fmt_string, pvar); va_end (pvar); return (result); } -- Kevin Schnitzius (Encore Computer Corporation, Ft. Lauderdale, Florida) (formerly Gould CSD) ********************* Please ignore the From: line ************************ Uucp: {pur-ee,sun,codas!novavax,uunet,mcnc!rti,etc}!gould!kschnitizius Internet: temporarily disconnected What a bunch of typing, huh?
melvin@argus.CS.ORST.EDU (Todd Ferguson) (07/12/89)
In article <3171@puff.UUCP> kschnitz@puff.UUCP (Soccer Stud) writes: > >Help! This function came with the tetris game I got for Unix based >machines. The problem is vsprintf is undefined using my C libraries. Some one posted a "portable" vsprintf to comp.sources.misc (I think). You can probably grab this from an archieve site. Or, if all else fails, you can mail me and I'll send it to you. Todd Ferguson
gwyn@smoke.BRL.MIL (Doug Gwyn) (07/12/89)
In article <3171@puff.UUCP> kschnitz@puff.UUCP (Soccer Stud) writes: >The problem is vsprintf is undefined using my C libraries. >Does anyone have a simple solution? Please post the answer because >others have had the same problem. Thanks in advance. Well, you could try building the software under the System V environment on your Gould system, since the v*printf() functions exist there. Or, you could dig up the sources to the C library and see whether or not you can readily implement v*printf(); most V7/BSD-derived systems use an internal function named "_doprnt" to implement all the *printf() family, and if you're lucky yours may be suitable for implementing v*printf(). Or, you could replace the form() function you posted with something like the following, which is not "kosher" but nonetheless often works by accident: char * form( z, a, b, c, d, e, f, g, h, i, j ) char *z; int a, b, c, d, e, f, g, h, i, j; { static char result[LINELEN]; (void)sprintf( result, z, a, b, c, d, e, f, g, h, i, j ); return result; }
chet@kiwi.CWRU.EDU (Chet Ramey) (07/12/89)
In article <3171@puff.UUCP> kschnitz@puff.UUCP (Soccer Stud) writes: > >Help! This function came with the tetris game I got for Unix based >machines. The problem is vsprintf is undefined using my C libraries. > >Does anyone have a simple solution? Please post the answer because >others have had the same problem. Thanks in advance. > This is the version of vsprintf that appears on uunet as part of the 4.3-tahoe freed files. #include <stdio.h> #include <varargs.h> int vsprintf(str, fmt, ap) char *str, *fmt; va_list ap; { FILE f; int len; f._flag = _IOWRT+_IOSTRG; f._ptr = str; f._cnt = 32767; len = _doprnt(fmt, ap, &f); *f._ptr = 0; return (len); } Chet Ramey "We are preparing to think about contemplating Network Services Group, CWRU preliminary work on plans to develop a chet@cwjcc.INS.CWRU.Edu schedule for producing the 10th Edition of the Unix Programmers Manual." -- Andrew Hume
ccsmm@gdt.bath.ac.uk (Martin Maclaren) (07/13/89)
kschnitz@puff.UUCP (Soccer Stud) writes: >Help! This function came with the tetris game I got for Unix based >machines. The problem is vsprintf is undefined using my C libraries. >Does anyone have a simple solution? Please post the answer because >others have had the same problem. Thanks in advance. > ... >/*VARARGS*/ >char *form (va_alist) > va_dcl >{ > va_list pvar; > char *fmt_string; > static char result[LINELEN]; > > va_start (pvar); > fmt_string = va_arg (pvar, char*); > (void) vsprintf (result, fmt_string, pvar); > va_end (pvar); > return (result); >} How about the following.... /*VARARGS*/ char *form (va_alist) va_dcl { va_list pvar; char *fmt_string; static char result[LINELEN]; FILE b; va_start (pvar); fmt_string = va_arg (pvar, char*); /* (void) vsprintf (result, fmt_string, pvar); */ b._flag = _IOWRT|_IOSTRG; b._ptr = result; b._cnt = LINELEN; _doprnt(fmt_string, pvar, &b); putc('\0', &b); va_end (pvar); return (result); } Works fine for me. Martin.
gleason@pegasus.UUCP (Jim Gleason) (07/21/89)
In article <3171@puff.UUCP>, kschnitz@puff.UUCP (Soccer Stud) writes: > > Help! This function came with the tetris game I got for Unix based > machines. The problem is vsprintf is undefined using my C libraries. > > Does anyone have a simple solution? Please post the answer because > others have had the same problem. Thanks in advance. > > Kevin Schnitzius (Encore Computer Corporation, Ft. Lauderdale, Florida) Try this quick and dirty little programming trick... Just beware that this has a fixed & limited parameter capability i.e. floats take 2 args[], chars & ints take 1 args[]. If more capability is needed, just continue adding args[]. /**************************************************************/ /* Pseudo vsprintf routine --- Limited parameter capabilities */ /**************************************************************/ /*VARARGS2 PRINTFLIKE2*/ int Vsprintf (str, argv) char *str; char *argv; { /* Begin Vsprintf **********************************************************/ /********** Local Declaration Section **********/ char **args; int nchars; /********** Code Section **********/ args = (char **) &argv; nchars = sprintf(str, args[ 0],args[ 1],args[ 2],args[ 3],args[ 4], args[ 5],args[ 6],args[ 7],args[ 8],args[ 9], args[10],args[11],args[12],args[13],args[14], args[15],args[16],args[17],args[18],args[19]); #ifdef BSD4 /* Berkeley's sprintf does not return string length: */ nchars = strlen(str); #endif return(nchars); } /* End Vsprintf ************************************************************/
gleason@giga.UUCP (Jim Gleason) (07/21/89)
In article <3171@puff.UUCP>, kschnitz@puff.UUCP (Soccer Stud) writes: > > Help! This function came with the tetris game I got for Unix based > machines. The problem is vsprintf is undefined using my C libraries. > > Does anyone have a simple solution? Please post the answer because > others have had the same problem. Thanks in advance. > > Kevin Schnitzius (Encore Computer Corporation, Ft. Lauderdale, Florida) Try this little programming trick... Note: The format string uses one args[], floats use 2 args[], ints use 1 args[] and so forth and so on. If you need more parameter capabilities than this offers, just add more args[]. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = /********************************************************/ /* Pseudo vsprintf ----- Limited parameter capabilities */ /********************************************************/ /*VARARGS1 PRINTFLIKE1*/ int Vsprintf (str, argv) char *str; char *argv; { /* Begin Vsprintf **********************************************************/ /********** Local Declaration Section **********/ char **args; int nchars; /********** Code Section **********/ args = (char **) &argv; nchars = sprintf(str, args[ 0],args[ 1],args[ 2],args[ 3],args[ 4], args[ 5],args[ 6],args[ 7],args[ 8],args[ 9], args[10],args[11],args[12],args[13],args[14], args[15],args[16],args[17],args[18],args[19]); #ifdef BSD4 /* Berkeley's sprintf does not return string length: */ nchars = strlen(str); #endif return(nchars); } /* End Vsprintf ************************************************************/ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :-) Jimbo = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =