Blame


1 b2cfc4e2 2003-09-30 devnull .TH PRINT 3
2 b2cfc4e2 2003-09-30 devnull .SH NAME
3 058b0118 2005-01-03 devnull print, fprint, sprint, snprint, seprint, smprint, runesprint, runesnprint, runeseprint, runesmprint, vfprint, vsnprint, vseprint, vsmprint, runevsnprint, runevseprint, runevsmprint \- print formatted output
4 b2cfc4e2 2003-09-30 devnull .SH SYNOPSIS
5 c8b6342d 2005-01-13 devnull .B #include <u.h>
6 b2cfc4e2 2003-09-30 devnull .PP
7 c8b6342d 2005-01-13 devnull .B #include <libc.h>
8 b2cfc4e2 2003-09-30 devnull .PP
9 b2cfc4e2 2003-09-30 devnull .ta \w'\fLchar* 'u
10 b2cfc4e2 2003-09-30 devnull .B
11 b2cfc4e2 2003-09-30 devnull int print(char *format, ...)
12 b2cfc4e2 2003-09-30 devnull .PP
13 b2cfc4e2 2003-09-30 devnull .B
14 b2cfc4e2 2003-09-30 devnull int fprint(int fd, char *format, ...)
15 b2cfc4e2 2003-09-30 devnull .PP
16 b2cfc4e2 2003-09-30 devnull .B
17 b2cfc4e2 2003-09-30 devnull int sprint(char *s, char *format, ...)
18 b2cfc4e2 2003-09-30 devnull .PP
19 b2cfc4e2 2003-09-30 devnull .B
20 b2cfc4e2 2003-09-30 devnull int snprint(char *s, int len, char *format, ...)
21 b2cfc4e2 2003-09-30 devnull .PP
22 b2cfc4e2 2003-09-30 devnull .B
23 b2cfc4e2 2003-09-30 devnull char* seprint(char *s, char *e, char *format, ...)
24 b2cfc4e2 2003-09-30 devnull .PP
25 b2cfc4e2 2003-09-30 devnull .B
26 b2cfc4e2 2003-09-30 devnull char* smprint(char *format, ...)
27 b2cfc4e2 2003-09-30 devnull .PP
28 b2cfc4e2 2003-09-30 devnull .B
29 b2cfc4e2 2003-09-30 devnull int runesprint(Rune *s, char *format, ...)
30 b2cfc4e2 2003-09-30 devnull .PP
31 b2cfc4e2 2003-09-30 devnull .B
32 b2cfc4e2 2003-09-30 devnull int runesnprint(Rune *s, int len, char *format, ...)
33 b2cfc4e2 2003-09-30 devnull .PP
34 b2cfc4e2 2003-09-30 devnull .B
35 b2cfc4e2 2003-09-30 devnull Rune* runeseprint(Rune *s, Rune *e, char *format, ...)
36 b2cfc4e2 2003-09-30 devnull .PP
37 b2cfc4e2 2003-09-30 devnull .B
38 b2cfc4e2 2003-09-30 devnull Rune* runesmprint(char *format, ...)
39 b2cfc4e2 2003-09-30 devnull .PP
40 b2cfc4e2 2003-09-30 devnull .B
41 b2cfc4e2 2003-09-30 devnull int vfprint(int fd, char *format, va_list v)
42 b2cfc4e2 2003-09-30 devnull .PP
43 b2cfc4e2 2003-09-30 devnull .B
44 b2cfc4e2 2003-09-30 devnull int vsnprint(char *s, int len, char *format, va_list v)
45 b2cfc4e2 2003-09-30 devnull .PP
46 b2cfc4e2 2003-09-30 devnull .B
47 b2cfc4e2 2003-09-30 devnull char* vseprint(char *s, char *e, char *format, va_list v)
48 b2cfc4e2 2003-09-30 devnull .PP
49 b2cfc4e2 2003-09-30 devnull .B
50 b2cfc4e2 2003-09-30 devnull char* vsmprint(char *format, va_list v)
51 b2cfc4e2 2003-09-30 devnull .PP
52 b2cfc4e2 2003-09-30 devnull .B
53 b2cfc4e2 2003-09-30 devnull int runevsnprint(Rune *s, int len, char *format, va_list v)
54 b2cfc4e2 2003-09-30 devnull .PP
55 b2cfc4e2 2003-09-30 devnull .B
56 b2cfc4e2 2003-09-30 devnull Rune* runevseprint(Rune *s, Rune *e, char *format, va_list v)
57 b2cfc4e2 2003-09-30 devnull .PP
58 b2cfc4e2 2003-09-30 devnull .B
59 b2cfc4e2 2003-09-30 devnull Rune* runevsmprint(Rune *format, va_list v)
60 b2cfc4e2 2003-09-30 devnull .PP
61 b2cfc4e2 2003-09-30 devnull .B
62 b2cfc4e2 2003-09-30 devnull .SH DESCRIPTION
63 b2cfc4e2 2003-09-30 devnull .I Print
64 b2cfc4e2 2003-09-30 devnull writes text to the standard output.
65 b2cfc4e2 2003-09-30 devnull .I Fprint
66 b2cfc4e2 2003-09-30 devnull writes to the named output
67 c8b6342d 2005-01-13 devnull file descriptor:
68 c8b6342d 2005-01-13 devnull a buffered form
69 c8b6342d 2005-01-13 devnull is described in
70 d32deab1 2020-08-16 rsc .MR bio (3) .
71 b2cfc4e2 2003-09-30 devnull .I Sprint
72 b2cfc4e2 2003-09-30 devnull places text
73 b2cfc4e2 2003-09-30 devnull followed by the NUL character
74 b2cfc4e2 2003-09-30 devnull .RB ( \e0 )
75 b2cfc4e2 2003-09-30 devnull in consecutive bytes starting at
76 b2cfc4e2 2003-09-30 devnull .IR s ;
77 b2cfc4e2 2003-09-30 devnull it is the user's responsibility to ensure that
78 b2cfc4e2 2003-09-30 devnull enough storage is available.
79 b2cfc4e2 2003-09-30 devnull Each function returns the number of bytes
80 b2cfc4e2 2003-09-30 devnull transmitted (not including the NUL
81 b2cfc4e2 2003-09-30 devnull in the case of
82 b2cfc4e2 2003-09-30 devnull .IR sprint ),
83 b2cfc4e2 2003-09-30 devnull or
84 b2cfc4e2 2003-09-30 devnull a negative value if an output error was encountered.
85 b2cfc4e2 2003-09-30 devnull .PP
86 b2cfc4e2 2003-09-30 devnull .I Snprint
87 b2cfc4e2 2003-09-30 devnull is like
88 b2cfc4e2 2003-09-30 devnull .IR sprint ,
89 b2cfc4e2 2003-09-30 devnull but will not place more than
90 b2cfc4e2 2003-09-30 devnull .I len
91 b2cfc4e2 2003-09-30 devnull bytes in
92 b2cfc4e2 2003-09-30 devnull .IR s .
93 b2cfc4e2 2003-09-30 devnull Its result is always NUL-terminated and holds the maximal
94 c8b6342d 2005-01-13 devnull number of complete UTF-8 characters that can fit.
95 b2cfc4e2 2003-09-30 devnull .I Seprint
96 b2cfc4e2 2003-09-30 devnull is like
97 b2cfc4e2 2003-09-30 devnull .IR snprint ,
98 b2cfc4e2 2003-09-30 devnull except that the end is indicated by a pointer
99 b2cfc4e2 2003-09-30 devnull .I e
100 b2cfc4e2 2003-09-30 devnull rather than a count and the return value points to the terminating NUL of the
101 b2cfc4e2 2003-09-30 devnull resulting string.
102 b2cfc4e2 2003-09-30 devnull .I Smprint
103 b2cfc4e2 2003-09-30 devnull is like
104 b2cfc4e2 2003-09-30 devnull .IR sprint ,
105 b2cfc4e2 2003-09-30 devnull except that it prints into and returns a string of the required length, which is
106 b2cfc4e2 2003-09-30 devnull allocated by
107 d32deab1 2020-08-16 rsc .MR malloc (3) .
108 b2cfc4e2 2003-09-30 devnull .PP
109 b2cfc4e2 2003-09-30 devnull The routines
110 b2cfc4e2 2003-09-30 devnull .IR runesprint ,
111 b2cfc4e2 2003-09-30 devnull .IR runesnprint ,
112 b2cfc4e2 2003-09-30 devnull .IR runeseprint ,
113 b2cfc4e2 2003-09-30 devnull and
114 b2cfc4e2 2003-09-30 devnull .I runesmprint
115 b2cfc4e2 2003-09-30 devnull are the same as
116 b2cfc4e2 2003-09-30 devnull .IR sprint ,
117 b2cfc4e2 2003-09-30 devnull .IR snprint ,
118 b2cfc4e2 2003-09-30 devnull .IR seprint
119 b2cfc4e2 2003-09-30 devnull and
120 b2cfc4e2 2003-09-30 devnull .I smprint
121 b2cfc4e2 2003-09-30 devnull except that their output is rune strings instead of byte strings.
122 38bb7c11 2006-07-02 devnull They return a rune count rather than a byte count.
123 b2cfc4e2 2003-09-30 devnull .PP
124 b2cfc4e2 2003-09-30 devnull Finally, the routines
125 b2cfc4e2 2003-09-30 devnull .IR vfprint ,
126 b2cfc4e2 2003-09-30 devnull .IR vsnprint ,
127 b2cfc4e2 2003-09-30 devnull .IR vseprint ,
128 b2cfc4e2 2003-09-30 devnull .IR vsmprint ,
129 b2cfc4e2 2003-09-30 devnull .IR runevsnprint ,
130 b2cfc4e2 2003-09-30 devnull .IR runevseprint ,
131 b2cfc4e2 2003-09-30 devnull and
132 b2cfc4e2 2003-09-30 devnull .I runevsmprint
133 b2cfc4e2 2003-09-30 devnull are like their
134 b2cfc4e2 2003-09-30 devnull .BR v-less
135 b2cfc4e2 2003-09-30 devnull relatives except they take as arguments a
136 b2cfc4e2 2003-09-30 devnull .B va_list
137 b2cfc4e2 2003-09-30 devnull parameter, so they can be called within a variadic function.
138 b2cfc4e2 2003-09-30 devnull The Example section shows a representative usage.
139 b2cfc4e2 2003-09-30 devnull .PP
140 b2cfc4e2 2003-09-30 devnull Each of these functions
141 b2cfc4e2 2003-09-30 devnull converts, formats, and prints its
142 b2cfc4e2 2003-09-30 devnull trailing arguments
143 b2cfc4e2 2003-09-30 devnull under control of a
144 b2cfc4e2 2003-09-30 devnull .IR format
145 b2cfc4e2 2003-09-30 devnull string.
146 b2cfc4e2 2003-09-30 devnull The
147 b2cfc4e2 2003-09-30 devnull format
148 b2cfc4e2 2003-09-30 devnull contains two types of objects:
149 b2cfc4e2 2003-09-30 devnull plain characters, which are simply copied to the
150 b2cfc4e2 2003-09-30 devnull output stream,
151 b2cfc4e2 2003-09-30 devnull and conversion specifications,
152 b2cfc4e2 2003-09-30 devnull each of which results in fetching of
153 b2cfc4e2 2003-09-30 devnull zero or more
154 b2cfc4e2 2003-09-30 devnull arguments.
155 b2cfc4e2 2003-09-30 devnull The results are undefined if there are arguments of the
156 b2cfc4e2 2003-09-30 devnull wrong type or too few
157 b2cfc4e2 2003-09-30 devnull arguments for the format.
158 b2cfc4e2 2003-09-30 devnull If the format is exhausted while
159 b2cfc4e2 2003-09-30 devnull arguments remain, the excess
160 b2cfc4e2 2003-09-30 devnull is ignored.
161 b2cfc4e2 2003-09-30 devnull .PP
162 b2cfc4e2 2003-09-30 devnull Each conversion specification has the following format:
163 b2cfc4e2 2003-09-30 devnull .IP
164 b2cfc4e2 2003-09-30 devnull .B "% [flags] verb
165 b2cfc4e2 2003-09-30 devnull .PP
166 b2cfc4e2 2003-09-30 devnull The verb is a single character and each flag is a single character or a
167 b2cfc4e2 2003-09-30 devnull (decimal) numeric string.
168 b2cfc4e2 2003-09-30 devnull Up to two numeric strings may be used;
169 b2cfc4e2 2003-09-30 devnull the first is called
170 b2cfc4e2 2003-09-30 devnull .IR width ,
171 b2cfc4e2 2003-09-30 devnull the second
172 b2cfc4e2 2003-09-30 devnull .IR precision .
173 b2cfc4e2 2003-09-30 devnull A period can be used to separate them, and if the period is
174 b2cfc4e2 2003-09-30 devnull present then
175 b2cfc4e2 2003-09-30 devnull .I width
176 b2cfc4e2 2003-09-30 devnull and
177 b2cfc4e2 2003-09-30 devnull .I precision
178 b2cfc4e2 2003-09-30 devnull are taken to be zero if missing, otherwise they are `omitted'.
179 b2cfc4e2 2003-09-30 devnull Either or both of the numbers may be replaced with the character
180 b2cfc4e2 2003-09-30 devnull .BR * ,
181 b2cfc4e2 2003-09-30 devnull meaning that the actual number will be obtained from the argument list
182 b2cfc4e2 2003-09-30 devnull as an integer.
183 b2cfc4e2 2003-09-30 devnull The flags and numbers are arguments to
184 b2cfc4e2 2003-09-30 devnull the
185 b2cfc4e2 2003-09-30 devnull .I verb
186 b2cfc4e2 2003-09-30 devnull described below.
187 b2cfc4e2 2003-09-30 devnull .PP
188 b2cfc4e2 2003-09-30 devnull The numeric verbs
189 b2cfc4e2 2003-09-30 devnull .BR d ,
190 b2cfc4e2 2003-09-30 devnull .BR o ,
191 b2cfc4e2 2003-09-30 devnull .BR b ,
192 b2cfc4e2 2003-09-30 devnull .BR x ,
193 b2cfc4e2 2003-09-30 devnull and
194 b2cfc4e2 2003-09-30 devnull .B X
195 c8b6342d 2005-01-13 devnull format their arguments in decimal,
196 c8b6342d 2005-01-13 devnull octal, binary, hexadecimal, and upper case hexadecimal.
197 b2cfc4e2 2003-09-30 devnull Each interprets the flags
198 b2cfc4e2 2003-09-30 devnull .BR 0 ,
199 b2cfc4e2 2003-09-30 devnull .BR h ,
200 b2cfc4e2 2003-09-30 devnull .BR hh ,
201 b2cfc4e2 2003-09-30 devnull .BR l ,
202 c8b6342d 2005-01-13 devnull .BR u ,
203 b2cfc4e2 2003-09-30 devnull .BR + ,
204 b2cfc4e2 2003-09-30 devnull .BR - ,
205 b2cfc4e2 2003-09-30 devnull .BR , ,
206 b2cfc4e2 2003-09-30 devnull and
207 b2cfc4e2 2003-09-30 devnull .B #
208 b2cfc4e2 2003-09-30 devnull to mean pad with zeros,
209 c8b6342d 2005-01-13 devnull short, byte, long, unsigned, always print a sign, left justified, commas every three digits,
210 b2cfc4e2 2003-09-30 devnull and alternate format.
211 b2cfc4e2 2003-09-30 devnull Also, a space character in the flag
212 b2cfc4e2 2003-09-30 devnull position is like
213 b2cfc4e2 2003-09-30 devnull .BR + ,
214 b2cfc4e2 2003-09-30 devnull but prints a space instead of a plus sign for non-negative values.
215 b2cfc4e2 2003-09-30 devnull If neither
216 b2cfc4e2 2003-09-30 devnull short nor long is specified,
217 b2cfc4e2 2003-09-30 devnull then the argument is an
218 b2cfc4e2 2003-09-30 devnull .BR int .
219 c8b6342d 2005-01-13 devnull If unsigned is specified,
220 b2cfc4e2 2003-09-30 devnull then the argument is interpreted as a
221 c8b6342d 2005-01-13 devnull positive number and no sign is output.
222 b2cfc4e2 2003-09-30 devnull If two
223 b2cfc4e2 2003-09-30 devnull .B l
224 b2cfc4e2 2003-09-30 devnull flags are given,
225 b2cfc4e2 2003-09-30 devnull then the argument is interpreted as a
226 b2cfc4e2 2003-09-30 devnull .B vlong
227 b2cfc4e2 2003-09-30 devnull (usually an 8-byte, sometimes a 4-byte integer).
228 b2cfc4e2 2003-09-30 devnull If
229 b2cfc4e2 2003-09-30 devnull .I precision
230 b2cfc4e2 2003-09-30 devnull is not omitted, the number is padded on the left with zeros
231 b2cfc4e2 2003-09-30 devnull until at least
232 b2cfc4e2 2003-09-30 devnull .I precision
233 b2cfc4e2 2003-09-30 devnull digits appear.
234 b2cfc4e2 2003-09-30 devnull If
235 b2cfc4e2 2003-09-30 devnull .I precision
236 b2cfc4e2 2003-09-30 devnull is explicitly 0, and the number is 0,
237 b2cfc4e2 2003-09-30 devnull no digits are generated, and alternate formatting
238 b2cfc4e2 2003-09-30 devnull does not apply.
239 b2cfc4e2 2003-09-30 devnull Then, if alternate format is specified,
240 b2cfc4e2 2003-09-30 devnull for
241 b2cfc4e2 2003-09-30 devnull .B o
242 b2cfc4e2 2003-09-30 devnull conversion, the number is preceded by a
243 b2cfc4e2 2003-09-30 devnull .B 0
244 c8b6342d 2005-01-13 devnull if it doesn't already begin with one;
245 c8b6342d 2005-01-13 devnull for
246 b2cfc4e2 2003-09-30 devnull .B x
247 b2cfc4e2 2003-09-30 devnull conversion, the number is preceded by
248 b2cfc4e2 2003-09-30 devnull .BR 0x ;
249 b2cfc4e2 2003-09-30 devnull for
250 b2cfc4e2 2003-09-30 devnull .B X
251 b2cfc4e2 2003-09-30 devnull conversion, the number is preceded by
252 b2cfc4e2 2003-09-30 devnull .BR 0X .
253 b2cfc4e2 2003-09-30 devnull Finally, if
254 b2cfc4e2 2003-09-30 devnull .I width
255 b2cfc4e2 2003-09-30 devnull is not omitted, the number is padded on the left (or right, if
256 b2cfc4e2 2003-09-30 devnull left justification is specified) with enough blanks to
257 b2cfc4e2 2003-09-30 devnull make the field at least
258 b2cfc4e2 2003-09-30 devnull .I width
259 b2cfc4e2 2003-09-30 devnull characters long.
260 b2cfc4e2 2003-09-30 devnull .PP
261 b2cfc4e2 2003-09-30 devnull The floating point verbs
262 b2cfc4e2 2003-09-30 devnull .BR f ,
263 b2cfc4e2 2003-09-30 devnull .BR e ,
264 b2cfc4e2 2003-09-30 devnull .BR E ,
265 b2cfc4e2 2003-09-30 devnull .BR g ,
266 b2cfc4e2 2003-09-30 devnull and
267 b2cfc4e2 2003-09-30 devnull .B G
268 b2cfc4e2 2003-09-30 devnull take a
269 b2cfc4e2 2003-09-30 devnull .B double
270 b2cfc4e2 2003-09-30 devnull argument.
271 b2cfc4e2 2003-09-30 devnull Each interprets the flags
272 b2cfc4e2 2003-09-30 devnull .BR 0 ,
273 b2cfc4e2 2003-09-30 devnull .BR L
274 b2cfc4e2 2003-09-30 devnull .BR + ,
275 b2cfc4e2 2003-09-30 devnull .BR - ,
276 b2cfc4e2 2003-09-30 devnull and
277 b2cfc4e2 2003-09-30 devnull .B #
278 b2cfc4e2 2003-09-30 devnull to mean pad with zeros,
279 b2cfc4e2 2003-09-30 devnull long double argument,
280 b2cfc4e2 2003-09-30 devnull always print a sign,
281 b2cfc4e2 2003-09-30 devnull left justified,
282 b2cfc4e2 2003-09-30 devnull and
283 b2cfc4e2 2003-09-30 devnull alternate format.
284 b2cfc4e2 2003-09-30 devnull .I Width
285 b2cfc4e2 2003-09-30 devnull is the minimum field width and,
286 b2cfc4e2 2003-09-30 devnull if the converted value takes up less than
287 b2cfc4e2 2003-09-30 devnull .I width
288 b2cfc4e2 2003-09-30 devnull characters, it is padded on the left (or right, if `left justified')
289 b2cfc4e2 2003-09-30 devnull with spaces.
290 b2cfc4e2 2003-09-30 devnull .I Precision
291 b2cfc4e2 2003-09-30 devnull is the number of digits that are converted after the decimal place for
292 b2cfc4e2 2003-09-30 devnull .BR e ,
293 b2cfc4e2 2003-09-30 devnull .BR E ,
294 b2cfc4e2 2003-09-30 devnull and
295 b2cfc4e2 2003-09-30 devnull .B f
296 b2cfc4e2 2003-09-30 devnull conversions,
297 b2cfc4e2 2003-09-30 devnull and
298 b2cfc4e2 2003-09-30 devnull .I precision
299 b2cfc4e2 2003-09-30 devnull is the maximum number of significant digits for
300 b2cfc4e2 2003-09-30 devnull .B g
301 b2cfc4e2 2003-09-30 devnull and
302 b2cfc4e2 2003-09-30 devnull .B G
303 b2cfc4e2 2003-09-30 devnull conversions.
304 b2cfc4e2 2003-09-30 devnull The
305 b2cfc4e2 2003-09-30 devnull .B f
306 b2cfc4e2 2003-09-30 devnull verb produces output of the form
307 b2cfc4e2 2003-09-30 devnull .RB [ - ] digits [ .digits\fR].
308 b2cfc4e2 2003-09-30 devnull .B E
309 b2cfc4e2 2003-09-30 devnull conversion appends an exponent
310 b2cfc4e2 2003-09-30 devnull .BR E [ - ] digits ,
311 b2cfc4e2 2003-09-30 devnull and
312 b2cfc4e2 2003-09-30 devnull .B e
313 b2cfc4e2 2003-09-30 devnull conversion appends an exponent
314 b2cfc4e2 2003-09-30 devnull .BR e [ - ] digits .
315 b2cfc4e2 2003-09-30 devnull The
316 b2cfc4e2 2003-09-30 devnull .B g
317 b2cfc4e2 2003-09-30 devnull verb will output the argument in either
318 b2cfc4e2 2003-09-30 devnull .B e
319 b2cfc4e2 2003-09-30 devnull or
320 b2cfc4e2 2003-09-30 devnull .B f
321 b2cfc4e2 2003-09-30 devnull with the goal of producing the smallest output.
322 b2cfc4e2 2003-09-30 devnull Also, trailing zeros are omitted from the fraction part of
323 b2cfc4e2 2003-09-30 devnull the output, and a trailing decimal point appears only if it is followed
324 b2cfc4e2 2003-09-30 devnull by a digit.
325 b2cfc4e2 2003-09-30 devnull The
326 b2cfc4e2 2003-09-30 devnull .B G
327 b2cfc4e2 2003-09-30 devnull verb is similar, but uses
328 b2cfc4e2 2003-09-30 devnull .B E
329 b2cfc4e2 2003-09-30 devnull format instead of
330 b2cfc4e2 2003-09-30 devnull .BR e .
331 b2cfc4e2 2003-09-30 devnull When alternate format is specified, the result will always contain a decimal point,
332 b2cfc4e2 2003-09-30 devnull and for
333 b2cfc4e2 2003-09-30 devnull .B g
334 b2cfc4e2 2003-09-30 devnull and
335 b2cfc4e2 2003-09-30 devnull .B G
336 b2cfc4e2 2003-09-30 devnull conversions, trailing zeros are not removed.
337 b2cfc4e2 2003-09-30 devnull .PP
338 b2cfc4e2 2003-09-30 devnull The
339 b2cfc4e2 2003-09-30 devnull .B s
340 c8b6342d 2005-01-13 devnull verb copies a NUL-terminated string
341 b2cfc4e2 2003-09-30 devnull (pointer to
342 b2cfc4e2 2003-09-30 devnull .BR char )
343 b2cfc4e2 2003-09-30 devnull to the output.
344 b2cfc4e2 2003-09-30 devnull The number of characters copied
345 b2cfc4e2 2003-09-30 devnull .RI ( n )
346 b2cfc4e2 2003-09-30 devnull is the minimum
347 b2cfc4e2 2003-09-30 devnull of the size of the string and
348 b2cfc4e2 2003-09-30 devnull .IR precision .
349 b2cfc4e2 2003-09-30 devnull These
350 b2cfc4e2 2003-09-30 devnull .I n
351 b2cfc4e2 2003-09-30 devnull characters are justified within a field of
352 b2cfc4e2 2003-09-30 devnull .I width
353 b2cfc4e2 2003-09-30 devnull characters as described above.
354 b2cfc4e2 2003-09-30 devnull If a
355 b2cfc4e2 2003-09-30 devnull .I precision
356 b2cfc4e2 2003-09-30 devnull is given, it is safe for the string not to be nul-terminated
357 b2cfc4e2 2003-09-30 devnull as long as it is at least
358 b2cfc4e2 2003-09-30 devnull .I precision
359 b2cfc4e2 2003-09-30 devnull characters (not bytes!) long.
360 b2cfc4e2 2003-09-30 devnull The
361 b2cfc4e2 2003-09-30 devnull .B S
362 b2cfc4e2 2003-09-30 devnull verb is similar, but it interprets its pointer as an array
363 b2cfc4e2 2003-09-30 devnull of runes (see
364 d32deab1 2020-08-16 rsc .MR utf (7) );
365 b2cfc4e2 2003-09-30 devnull the runes are converted to
366 b2cfc4e2 2003-09-30 devnull .SM UTF
367 b2cfc4e2 2003-09-30 devnull before output.
368 b2cfc4e2 2003-09-30 devnull .PP
369 b2cfc4e2 2003-09-30 devnull The
370 b2cfc4e2 2003-09-30 devnull .B c
371 b2cfc4e2 2003-09-30 devnull verb copies a single
372 b2cfc4e2 2003-09-30 devnull .B char
373 b2cfc4e2 2003-09-30 devnull (promoted to
374 b2cfc4e2 2003-09-30 devnull .BR int )
375 b2cfc4e2 2003-09-30 devnull justified within a field of
376 b2cfc4e2 2003-09-30 devnull .I width
377 b2cfc4e2 2003-09-30 devnull characters as described above.
378 b2cfc4e2 2003-09-30 devnull The
379 b2cfc4e2 2003-09-30 devnull .B C
380 b2cfc4e2 2003-09-30 devnull verb is similar, but works on runes.
381 b2cfc4e2 2003-09-30 devnull .PP
382 b2cfc4e2 2003-09-30 devnull The
383 b2cfc4e2 2003-09-30 devnull .B p
384 b2cfc4e2 2003-09-30 devnull verb formats a pointer value.
385 b2cfc4e2 2003-09-30 devnull At the moment, it is a synonym for
386 b2cfc4e2 2003-09-30 devnull .BR x ,
387 b2cfc4e2 2003-09-30 devnull but that will change if pointers and integers are different sizes.
388 b2cfc4e2 2003-09-30 devnull .PP
389 b2cfc4e2 2003-09-30 devnull The
390 b2cfc4e2 2003-09-30 devnull .B r
391 b2cfc4e2 2003-09-30 devnull verb takes no arguments; it copies the error string returned by a call to
392 d32deab1 2020-08-16 rsc .MR errstr (3) .
393 b2cfc4e2 2003-09-30 devnull .PP
394 b2cfc4e2 2003-09-30 devnull Custom verbs may be installed using
395 d32deab1 2020-08-16 rsc .MR fmtinstall (3) .
396 b2cfc4e2 2003-09-30 devnull .SH EXAMPLE
397 b2cfc4e2 2003-09-30 devnull This function prints an error message with a variable
398 b2cfc4e2 2003-09-30 devnull number of arguments and then quits.
399 b2cfc4e2 2003-09-30 devnull .IP
400 b2cfc4e2 2003-09-30 devnull .EX
401 b2cfc4e2 2003-09-30 devnull .ta 6n +6n +6n
402 b2cfc4e2 2003-09-30 devnull void fatal(char *msg, ...)
403 b2cfc4e2 2003-09-30 devnull {
404 b2cfc4e2 2003-09-30 devnull char buf[1024], *out;
405 b2cfc4e2 2003-09-30 devnull va_list arg;
406 b2cfc4e2 2003-09-30 devnull
407 c8b6342d 2005-01-13 devnull out = seprint(buf, buf+sizeof buf, "Fatal error: ");
408 b2cfc4e2 2003-09-30 devnull va_start(arg, msg);
409 b2cfc4e2 2003-09-30 devnull out = vseprint(out, buf+sizeof buf, msg, arg);
410 b2cfc4e2 2003-09-30 devnull va_end(arg);
411 b2cfc4e2 2003-09-30 devnull write(2, buf, out-buf);
412 c8b6342d 2005-01-13 devnull exits("fatal error");
413 b2cfc4e2 2003-09-30 devnull }
414 b2cfc4e2 2003-09-30 devnull .EE
415 93aa30a8 2005-01-14 devnull .SH SOURCE
416 adc93f60 2005-01-14 devnull .B \*9/src/lib9/fmt
417 b2cfc4e2 2003-09-30 devnull .SH SEE ALSO
418 d32deab1 2020-08-16 rsc .MR fmtinstall (3) ,
419 d32deab1 2020-08-16 rsc .MR fprintf (3) ,
420 d32deab1 2020-08-16 rsc .MR utf (7)
421 b2cfc4e2 2003-09-30 devnull .SH DIAGNOSTICS
422 b2cfc4e2 2003-09-30 devnull Routines that write to a file descriptor or call
423 b2cfc4e2 2003-09-30 devnull .IR malloc
424 b2cfc4e2 2003-09-30 devnull set
425 b2cfc4e2 2003-09-30 devnull .IR errstr .
426 b2cfc4e2 2003-09-30 devnull .SH BUGS
427 b2cfc4e2 2003-09-30 devnull The formatting is close to that specified for ANSI
428 d32deab1 2020-08-16 rsc .MR fprintf (3) ;
429 b2cfc4e2 2003-09-30 devnull the main difference is that
430 b2cfc4e2 2003-09-30 devnull .B b
431 b2cfc4e2 2003-09-30 devnull and
432 b2cfc4e2 2003-09-30 devnull .B r
433 c8b6342d 2005-01-13 devnull are not in ANSI and
434 c8b6342d 2005-01-13 devnull .B u
435 c8b6342d 2005-01-13 devnull is a flag here instead of a verb.
436 b2cfc4e2 2003-09-30 devnull Also, and distinctly not a bug,
437 b2cfc4e2 2003-09-30 devnull .I print
438 b2cfc4e2 2003-09-30 devnull and friends generate
439 b2cfc4e2 2003-09-30 devnull .SM UTF
440 b2cfc4e2 2003-09-30 devnull rather than
441 b2cfc4e2 2003-09-30 devnull .SM ASCII.
442 b2cfc4e2 2003-09-30 devnull .PP
443 b2cfc4e2 2003-09-30 devnull There is no
444 c8b6342d 2005-01-13 devnull .IR runeprint ,
445 c8b6342d 2005-01-13 devnull .IR runefprint ,
446 b2cfc4e2 2003-09-30 devnull etc. because runes are byte-order dependent and should not be written directly to a file; use the
447 b2cfc4e2 2003-09-30 devnull UTF output of
448 b2cfc4e2 2003-09-30 devnull .I print
449 b2cfc4e2 2003-09-30 devnull or
450 b2cfc4e2 2003-09-30 devnull .I fprint
451 b2cfc4e2 2003-09-30 devnull instead.
452 b2cfc4e2 2003-09-30 devnull Also,
453 b2cfc4e2 2003-09-30 devnull .I sprint
454 b2cfc4e2 2003-09-30 devnull is deprecated for safety reasons; use
455 b2cfc4e2 2003-09-30 devnull .IR snprint ,
456 b2cfc4e2 2003-09-30 devnull .IR seprint ,
457 b2cfc4e2 2003-09-30 devnull or
458 b2cfc4e2 2003-09-30 devnull .I smprint
459 b2cfc4e2 2003-09-30 devnull instead.
460 b2cfc4e2 2003-09-30 devnull Safety also precludes the existence of
461 b2cfc4e2 2003-09-30 devnull .IR runesprint .