[Top] [Prev] [Next]

print

print, fprint, sprint - print formatted output

Synopsis

include "sys.m";
sys:= load Sys Sys->PATH;
fprint: fn(fd: ref FD, format: string, *): int;
print:  fn(format: string, *): int;
sprint: fn(format: string, *): string;

Description

These functions format and print their arguments as UTF text.
print (format, *)

Write text to the standard output. Return the number of bytes transmitted or a negative value if an error was encountered when writing the output.

fprint (fd, *)

Write to the fd file descriptor. Return the number of bytes transmitted or a negative value if an error was encountered when writing the output.

sprint (format, *)

Format text into a string and return the string. Returns the formatted string.

Each of these functions converts, formats, and prints its trailing arguments under control of a format string. The format contains two types of objects:
plain characters

Plain characters are simply copied to the output stream.

conversion specifications

Each conversion results in fetching of zero or more arguments.

The Limbo compiler recognizes calls to these functions and checks that the arguments match the format specifications in number and type.

Each conversion specification has the following format:

	%[flags]verb

The verb is a single character and each flag is a single character or a (decimal) numeric string. Up to two numeric strings may be used; the first is called f1, the second f2. A period can be used to separate them, and if the period is present then f1 and f2 are taken to be zero if missing, otherwise they are omitted. Either or both of the numbers may be replaced with the character *, meaning that the actual number will be obtained from the argument list as an integer. The flags and numbers are arguments to the verb described below.
d, x

The numeric verbs d and x format their int arguments in decimal and hexadecimal, respectively. Each interprets the flags # and - to mean alternate format and left justified. If f2 is not omitted, the number is padded on the left with zeros until at least f2 digits appear. Then, if alternate format is specified for x conversion, the number is preceded by 16r. Finally, if f1 is not omitted, the number is padded on the left (or right, if left justification is specified) with enough blanks to make the field at least f1 characters long.

e, f, g

The floating point verbs e, f, and g take a real argument. Each interprets the flags +, -, and # to mean always print a sign, left justified, and alternate format. The f1 flag is the minimum field width and, if the converted value takes up less than f1 characters, it is padded on the left (or right, if 'left justified') with spaces. The f2 flag is the number of digits that are converted after the decimal place for e and f conversions, and f2 is the maximum number of significant digits for g conversions. The f verb produces output of the form [-]digits. [.digits]. The e conversion appends an exponent e[-]digits. The g verb will output the argument in either e or f with the goal of producing the smallest output. Also, trailing zeros are omitted from the fraction part of the output, and a trailing decimal point appears only if it is followed by a digit. When alternate format is specified, the result will always contain a decimal point, and for g conversions, trailing zeros are not removed.

c

The c verb copies a single character (integer) argument justified within a field of f1 characters as described above.

r

The r verb takes no arguments; it prints the error string associated with the most recent system error.

s

The s verb copies a string to the output. The number of characters copied (n) is the minimum of the size of the string and f2. These n characters are justified within a field of f1 characters as described above.

See Also

Limbo System Modules and open

Errors

Output longer than 256 bytes is truncated.

The x verb does not apply the 0x prefix when f2 is present.



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.