_print/_doprnt; curses on sys III

Guy Harris guy at rlgvax.UUCP
Sat Jun 23 11:54:06 AEST 1984


> Gee guys ... I wouild like to see you implement something
> like printw *correctly* without calling _doprnt.  I do NOT
> consider limiting the number of format items to 10 (or any
> other upper limit) a correct implementation.

Unfortunately, on some systems you can't implement "printw" correctly by
calling "_doprnt", because it doesn't exist; on other systems, I believe
"_doprnt" may have a different calling sequence than the "standard" one.
True, the other implementations don't work in the general case, but it's a
choice between one that works with *most* C implementations (there probably
isn't one that works on *all* implementations) but has limitations, vs.
one that works only on some C/"stdio" implementations but doesn't have those
limitations.

> However (and here's the kicker), _doprnt IS documented
> in 4.2BSD!!!  Look at the manual page for printf(3S) if you
> doubt me. ... I don't have Sys III documentation in front of me,
> but, is _print documented in Sys III?  I suspect that it is.

"_print" isn't documented in System III.  "vprintf", "vfprintf", and "vsprintf",
unfortunately, aren't documented either; they were intended to be the "visible"
hook for routines that need things like "_doprnt".  System V doesn't document
them, but that's because they were removed.  System V Release 2 put them
back in, *and* put "_doprnt" back in, and documented the "vprintf" family
(although *not* "_doprnt"):

     NAME
          vprintf, vfprintf, vsprintf - print formatted output of a
          varargs argument list

     SYNOPSIS
          #include <stdio.h>
          #include <varargs.h>

          int vprintf (format, ap)
          char *format;
          va_list ap;

          int vfprintf (stream, format, ap)
          FILE *stream;
          char *format;
          va_list ap;

          int vsprintf (s, format, ap)
          char *s, *format;
          va_list ap;

     DESCRIPTION
          vprintf, vfprintf, and vsprintf are the same as printf,
          fprintf, and sprintf respectively, except that instead of
          being called with a variable number of arguments, they are
          called with an argument list as defined by varargs(5).

     EXAMPLE
          The following demonstrates how vfprintf could be used to
          write an error routine.

          #include <stdio.h>
          #include <varargs.h>
               .
               .
               .
          /*
           *   error should be called like
           *        error(function_name, format, arg1, arg2...);
           */
          /*VARARGS0*/
          void
          error(va_alist)
          /* Note that the function_name and format arguments cannot be
           *      separately declared because of the definition of varargs.
           */
          va_dcl
          {
               va_list args;
               char *fmt;

               va_start(args);
               /* print out name of function causing error */
               (void)fprintf(stderr, "ERROR in %s: ", va_arg(args, char *));
               fmt = va_arg(args, char *);
               /* print out remainder of message */
               (void)vfprintf(fmt, args);
               va_end(args);
               (void)abort( );
          }

Unfortunately, this still doesn't give a portable way (even between "similar"
C implementations) for doing "printw"-like functions.  You have:

	PDP-11 V7 - use "_doprnt".
	Other V7 - try using "_doprnt", and hope that it exists and has
	the same implementation.
	4.xBSD - use "_doprnt".
	System III (PDP-11, VAX-11, and other ones that adopted one or the
	   other of those implementations) - use "v*printf".
	System V - suffer, unless they revived "_doprnt".
	System V Release 2 (VAX-11 and other ones that adopted that
	   implementation, and possibly PDP-11 as well) - use "v*printf"
	   (the preferred, clean way; it's compatible with System III) or
	   "_doprnt" (if you want to be compatible with one using a compatible
	   "_doprnt" which doesn't provide "v*printf".

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix.wizards mailing list