Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 May 2001 15:19:06 -0400 (EDT)
From:      "Andrew R. Reiter" <arr@watson.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        freebsd-doc@FreeBSD.org, Dima Dorfman <dima@unixfreak.org>
Subject:   RE: Updated uprintf.9 (was Re: uprintf.9)
Message-ID:  <Pine.NEB.3.96L.1010502151747.70313A-200000@fledge.watson.org>
In-Reply-To: <XFMail.010430130020.jhb@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]

Ok, I updated the printf.9 page a bunch, but am not positive that it's
finished.  I'd appreciate more comments... :-/

If you don't want the attached copy, you can find a copy at:
http://www.watson.org/~arr/fbsd-stuff/printf.9

Thanks,

Andrew

[-- Attachment #2 --]
.\"
.\" Copyright (c) 2001 Andrew R. Reiter.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"
.Dd April 25, 2001 
.Dt PRINTF 9
.Os FreeBSD
.Sh NAME
.Nm printf ,
.Nm uprintf  ,
.Nm tprintf
.Nd formatted output to the associated terminal
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/systm.h>
.Ft int
.Fn printf "const char *fmt" "..."
.Ft void
.Fn tprintf "struct proc *p" "int pri" "const char *fmt" "..."
.Ft int
.Fn uprintf "const char *fmt" "..."
.Sh DESCRIPTION
The
.Nm
functions act very similar to how the libc
.Fn printf
call works, but each has a specific output stream depending on which is called. 
The
.Fn uprintf
function outputs to the currect process' controlling tty, while 
.Fn printf
will write to the console as well as the logging facility.  
.Fn tprintf
on the other hand will output to the associated tty found from the 
.Fa struct proc *p
parameter, but will also write to the logging facility if the 
.Fa int pri
value is not -1.
.Pp 
Each of these related functions all use the 
.Fa const char *fmt
parameters in the same manner and uses almost the same set of format conversion 
identifiers as the libc 
.Fn printf
function.  However, there are two other conversion identifiers that are used 
by the kernel, but are not present in the libc
.Fn printf
functions.  The 
.Cm %b 
identifier expects two arguments to represent what it is, an 
.Fa integer 
and a 
.Fa char *
, which will be used together as a register value and a print mask for decoding
error registers.  The print mask is made up of two parts, the base and the 
arguments.  The base value is the output base expressed as a control character,
for example, \10 gives octal and \20 gives hex.  The arguments are made up of a
sequence of characters, the first of which gives the bit number, of the 
register value, to be inspected and the next characters (up to a control 
character, i.e. a character <= 32), give the name of the register, as in:
.Pp
.ti +0.4i
uprintf("reg=%b\\n", 3, "\\10\\2BITTWO\\1BITONE\\n");
.Pp
which will output:
.Pp
.ti +0.4i
reg=3<BITTWO,BITONE>
.Pp
Another conversion directive that is supported by the kernel 
.Fn printf
family of functions is the 
.Cm %D
identifier which is meant to assist in doing a hexdump.  It requires two 
arguments to follow the directive, which are a 
.Cm pointer
and a 
.Cm const char *
string.  The string is used as the delimeter when the 
.Fn printf
function prints out, byte-by-byte, the pointer argument. 
This directive 
is usually used with a precision or width value, given either statically or 
with an asterisk and providing an 
.Cm int
argument which represents the value.  For example, the following line of code:
.Pp
.ti +0.4i
uprintf("out: %4D\\n", "AAAA", ":");
.Pp
will produce the following output:
.Pp
.ti +0.4i
out: 41:41:41:41
.Pp
.El
.Sh RETURN VALUES
The
.Fn printf
and the
.Fn uprintf
functions both return 0 on success as well as on failure. 
.El
.Sh SEE ALSO
.Xr printf 3
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1010502151747.70313A-200000>