pyr201@psc90.UUCP (d^2) (02/11/90)
Below is a piece of code used in the recently posted Tetris game.
On our system, (BSD), this produces crap. Namely the last text
output is kept forever in some buffer somewhere and it shows up
in the integer output, ie, 15Press any key.
I made some hacks to it, but I need to know what the library function
_doprnt does or better yet what this function form() does.
Can anyone answer this question for me? Thanks in advance.
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*);
b._flag = _IOWRT|_IOSTRG;
b._ptr = result;
b._cnt = LINELEN;
---> _doprnt(fmt_string, pvar, &b); <---
putc('\0', &b);
va_end (pvar);
return (result);
}
dkim@wam.umd.edu (Daeshik Kim) (02/13/90)
In article <1153@psc90.UUCP> pyr201@.UUCP (d^2) writes: >char *form (va_alist) > va_dcl >{ > va_list pvar; > char *fmt_string; > static char result[LINELEN]; > FILE b; Why isn't this "File *b;" ? > > va_start (pvar); > fmt_string = va_arg (pvar, char*); > > b._flag = _IOWRT|_IOSTRG; > b._ptr = result; > b._cnt = LINELEN; > >---> _doprnt(fmt_string, pvar, &b); <--- File b seems to be opended here. > > putc('\0', &b); > > va_end (pvar); > return (result); >} Where File b is closed? What is this file? I have not seen the whole program but either '_doprnt()' does something wrong or file 'b' better to be closed with 'fclose()'. Just an opinion! -- Daeshik Kim H: (301) 445-0475/2147 O: (703) 689-5878 SCHOOL: dkim@wam.umd.edu, dskim@eng.umd.edu, mz518@umd5.umd.edu WORK: dkim@daffy.uu.net (uunet!daffy!dkim)
steve@wattres.UUCP (Steve Watt) (02/13/90)
In article <1990Feb12.201406.215@wam.umd.edu+ dkim@wam.umd.edu (Daeshik Kim) writes: + In article <1153@psc90.UUCP> pyr201@.UUCP (d^2) writes: ++ char *form (va_alist) [ strange header ] ++ FILE b; + + Why isn't this "File *b;" ? I believe this is because the FILE structure is being used to fake out the putchar's that are called in doprnt. + ++ va_start (pvar); ++ fmt_string = va_arg (pvar, char*); ++ ++ b._flag = _IOWRT|_IOSTRG; ++ b._ptr = result; ++ b._cnt = LINELEN; ++ ++---> _doprnt(fmt_string, pvar, &b); <--- + File b seems to be opended here. File b is actually "opened" where b._flag =... happens. The thing that this code is interested in is that b._ptr = result, the buffer to put the result from doprnt into. ++ putc('\0', &b); /* Put a null terminator on result */ ++ ++ va_end (pvar); ++ return (result); ++} + + Where File b is closed? + What is this file? + I have not seen the whole program but either '_doprnt()' does + something wrong or file 'b' better to be closed with 'fclose()'. + Just an opinion! +-- + Daeshik Kim H: (301) 445-0475/2147 O: (703) 689-5878 + SCHOOL: dkim@wam.umd.edu, dskim@eng.umd.edu, mz518@umd5.umd.edu + WORK: dkim@daffy.uu.net (uunet!daffy!dkim) #if defined(FLAME) && FLAME >= 0 The entire piece of code, however, is *awful*!!!!!! If there is a varargs package around, there tends to be a vsprintf around! vsprintf is the very correct way of doing this sort of thing. Depending on having _doprnt around is NOT NICE! #endif -- Steve Watt ...!claris!wattres!steve wattres!steve@claris.com is reported to work. Is rm -rf a way to remove high-frequence noise? (No names mentioned! :-)
karl@haddock.ima.isc.com (Karl Heuer) (02/15/90)
In article <420@wattres.UUCP> steve@wattres.UUCP (Steve Watt) writes: >The entire piece of code, however, is *awful*!!!!!! If there is a varargs >package around, there tends to be a vsprintf around! vsprintf is the very >correct way of doing this sort of thing. Depending on having _doprnt around >is NOT NICE! You are mistaken about the chronology. <varargs.h> and _doprnt() date back to V7, while the v*printf() family is a relatively recent invention (SVR2, I think; 4.3BSD still doesn't have it except in SysV compatibility mode). Any printf-like code that was written within that window had to use _doprnt(), or pass a fixed number of arguments to sprintf() directly, or reinvent the printf() wheel from scratch. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint