PRINT(3)

NAME
print, fprint, sprint, doprnt -- very simple formatted-output routines

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

print(format [, arg] ... )
char *format;

fprint(filep, format [, arg] ... )
File *filep;
char *format;

char *sprint(s, format [, arg] ... )
char *s, *format;

doprnt(filep, format, args)
File *filep;
char *format;
va_list args;

int _format(buf, format, args)
char *buf;
char *format;
va_list args;

DESCRIPTION
Print writes output on standard output. Fprint and doprnt place output on the open file known by filep. filep could for instance be STDOUT or STDERR. Sprint places `output' in the string s, followed by the character `\0'.

Each of these functions converts, formats and prints its arguments, following the format argument, under control of format. Format is a character string which contains two types of objects: plain characters, which are simply copied to the output destination, and conversion specifications, each of which causes conversion and printing of the next successive argument.

A conversion specification is introduced by the character %. Following the %, there may be

•   an optional row of decimal digits specifying the field width; if the converted integral value has fewer characters than the field width, it will be blank-padded on the left; if the field width begins with a zero, zero-padding will be done;

•   the character l specifying that a following b, d, o, u or x corresponds to a long-integer argument;

•   a character which indicates the type of conversion to be applied.

The conversion characters and their meanings are

bdox
    The next argument is an integer and is converted to binary, decimal, octal or hexadecimal notation respectively.

c   Next argument is a character and is put directly into the resulting string. the field width is one character.

s   Next argument is taken to be a character pointer and characters from the string are taken until a null character is reached; a specified field width is not taken into account.

u   The unsigned integer argument is converted to decimal.

Integral arguments are not truncated, even if their size exceeds the specified field width. Padding takes place only if the specified field width exceeds the actual width.

The printing routines build the string to be printed internally and use sys_write to print it.

The _format routine builds the string, but does not null-terminate it. It returns the length of the string.

Doprnt takes args as the address of the arguments of the format string. This allows routines, e.g. print, to be defined as follows:
    #include <varargs.h>
    #include <system.h>
    /*VARARGS*/
    print(va_alist)
    	va_dcl
    {
    	char *fmt;
    	va_list args;
    	va_start(args);
    	fmt = va_arg(args, char *);
    	doprnt(STDOUT, fmt, args);
    	va_end(args);
    }

FILES
~em/modules/lib/libprint.a

MODULES
system(3), string(3)

DIAGNOSTICS

Each illegal conversion specification is replaced by the string "<bad format>".

BUGS
The maximum length of the string to be printed is 1024 characters.

SEE ALSO
printf(3)