Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!cwruecmp!hal!ncoast!allbery From: allbery@ncoast.UUCP Newsgroups: net.sources Subject: Re: Public Domain _doprnt in C Message-ID: <2285@ncoast.UUCP> Date: Sat, 4-Apr-87 11:01:34 EST Article-I.D.: ncoast.2285 Posted: Sat Apr 4 11:01:34 1987 Date-Received: Sun, 5-Apr-87 13:01:33 EST References: <938@copper.TEK.COM> <100@asi.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: net.sources Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 70 As quoted from <100@asi.UUCP> by metro@asi.UUCP (Metro T. Sauper): +--------------- | I am not familiar with the _doprnt() routine, however I had a need to perform | a similar function. I wanted to write a function of the form: >... | fperror(fmt,args) char *fmt; int args; | { | char msgbuff[128]; | | vsprintf(msgbuff,fmt,&args); /* format args into msgbuff based on fmt */ +--------------- This works on some systems, but if you have vsprintf() you canb also make these functions fully portable. Use varargs. Skeleton which appears in many programs I write (see io.c in UNaXcess Conferencing as an example): #include void writef(va_alist) va_dcl { register char *fmt; static char _buf[5120]; va_list args; va_start(args); fmt = va_arg(args, char *); /* NO PARENTHESES AROUND THE TYPE! */ /* They will cause a syntax error */ (void) vsprintf(_buf, fmt, args); va_end(args); for (fmt = _buf; *fmt != '\0'; fmt++) writec(*fmt); } Note that varargs is defined such that it will work even on machines such as the Pyramid which pass arguments in registers (common on RISC machines). You MUST declare only one argument -- va_alist -- and include the type of it as "va_dcl" without a semicolon. (C compilers can then recognize this directly to do any special processing needed, as for the Pyramid.) Variables declared as "va_list" can then be passed to other functions as arguments, which is what makes the v*printf() functions work. I have seen varargs implemented under: AT&T System V Plexus Sys3 -- and possibly vanilla AT&T System III Xenix 2.x (Tandy 16a) Xenix 3.x (Tandy 6000, Altos x86) Pyramid OS/x Ultrix 1.1 (MicroVax) Moreover, UNaXcess Conferencing seems to be running on quite a few systems by means of it. (Actually, UC doesn't call vsprintf, since that function doesn't exist on all systems; it has its own format code. You're free to lift it out and use it, provided you attribute it to me and clearly state any changes you make to it so I don't get bug reports on your changes.) ++Brandon -- ____ ______________ / \ / __ __ __ \ Brandon S. Allbery | /^\ USS ___ | /__> / \ / \ aXcess Company | A A A CHALLENGER / \ | | `--, `--, 6615 Center St. #A1-105 | H V H | | \__/ \__/ \__/ Mentor, OH 44060-4101 | H . H SEVEN \____/ \______________/ +1 216 974 9210 | / | \ WHO ________________________________________________________| /___|___\ DARED As long as there is the spirit to dare new frontiers, the dream will never die. cbatt!cwruecmp!ncoast!allbery ncoast!allbery%case.CSNET@relay.CS.NET BALLBERY (UUCP) (CSNET/Internet) (MCIMail)