From: utzoo!decvax!cca!v.wales@Ucla-Security@sri-unix Newsgroups: net.unix-wizards Title: %r format item in some printf implementations Article-I.D.: sri-unix.2989 Posted: Sun Aug 29 19:40:33 1982 Received: Wed Sep 8 03:11:49 1982 From: v.wales at Ucla-Security (Rich Wales) Date: 24 August 1982 1012-PDT (Tuesday) Dan Franklin's "cmderr" routine for having programs print out error messages reminds me of how nice the "%r" (remote) format item for "printf" is. "%r" is especially helpful for "printf"-like routines that take a variable number of arguments -- much cleaner, in my view, than writing a zillion dummy arguments. Several UNIX implementations -- 4.1BSD among them -- removed "%r" from "printf" (or, more precisely, from /usr/src/libc/stdio/doprnt.s). I consider it such an unqualified "win" that I put it back into our code. In case anyone is interested in the changes to "doprnt.s" necessary to implement "%r", here's what I did: (1) Add the following comment at the beginning of "doprnt.s": #ifdef REMOTE /* * "%r" (remote) format option added. The argument associated * with "%r" is a pointer to a new argument list (format list and * series of values). The original argument list is abandoned * forever. */ #endif REMOTE (2) Make the following change in the "L5" table: #ifdef REMOTE /* "%r" (remote) format */ .word remote-L5 # r #else .word fmtbad-L5 # r #endif REMOTE (3) Add the following (it could go almost anywhere; I put it just before the existing label "float"): #ifdef REMOTE /* "%r" (remote) format */ remote: movl (ap)+,ap movl (ap)+,r11 jbr loop #endif REMOTE Also, of course, you want to update the manual entry for printf(3S) so that people know that "%r" is there. Here is an example of a routine which uses "%r": oops (args) char *args; { fprintf (stderr, "ERROR: %r", &args); exit (1); } You can then call "oops" exactly as you would call "printf": oops ("\"%s\" is an unknown option\n", option); Happy hacking. -- Rich