-
Notifications
You must be signed in to change notification settings - Fork 0
/
XPRINTF.DOC
152 lines (109 loc) · 5.22 KB
/
XPRINTF.DOC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
XPRINTF: Extended version of PRINTF
Craig A. Finseth
9 October 1992
OVERVIEW
The XPRINTF functions provide a versions of printf and sprintf with
extended functionality. Most printf functions are supported.
FUNCTIONS
void xprintf(const char *format, ...)
Formats the arguments as specified by the format string (see below).
All output is buffered (in 1024 byte chunks) and sent with one
"write(1,...)" call. Fputs was not used because the string may
contain NULs.
void xdprintf(const int fd, const char *format, ...)
As xprintf except the all output is sent to file descriptor FD.
void xeprintf(const char *format, ...)
As xprintf except the all output is sent to standard error, file
descriptor 2.
void xsprintf(char *string, const char *format, ...)
As xprintf except that the formatted output is stored in the string
STRING. STRING is assumed to be long enough. If the resulting string
contains NULs, STRING will appear to be truncated.
void xprintf_set_text(FLAG istext)
Sets the internal text processing mode (default is on). If on,
expands \n characters in format strings and %s output to
operating-system-dependant newlines.
FLAG xprintf_get_text(void)
Returns the current text processing mode.
THE FORMAT STRING
All characters except "%" print as themselves. "%" introduces a
format item. "%%" prints as "%". The general format is:
%<digits><character>
The character specifies how the formatting should be done. The digits
form a number (the argument) which provides information about how to
format. Digits are not required. If the digits are "*", the next
argument is fetched and its value is used as the argument. The
upper/lower case of the formatting character is ignored.
Formatting characters:
Control
%[a%;b..%:z%] Case/If statement. The next argument is fetched. If
it is zero, the first text (A) is formatted. If the
next argument is one, text B is formatted. Texts are
separated by "%;". "%:" serves as an else clause.
Case/ifs do not nest.
%(a%) Loop. The next argument is fetched and the text is
repeated the specified number of times. Loops do not
nest.
%r Recursion. The next two arguments are fetched. The
first one indicates a format string to be interpreted
and the second one is a pointer to an array of
argument values.
Numbers
%#, Format an int as a signed, decimal number with commas
every three digits. # is the field width to use NOT
COUNTING THE COMMAS. If the number is smaller than
the field width, it is right justified and space
filled. If the number is larger than the field width,
it will spill off to the right.
%#d Format an int as a signed, decimal number. # is the
field width to use. If the number is smaller than the
field width, it is right justified and space filled.
If # starts with a leading zero, the field is zero
filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
%#h Format a long as an unsigned, hexadecimal number. #
is the field width to use. If the number is smaller
than the wfield width, it is right justified and space
filled. If # starts with a leading zero, the field is
zero filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
%#l Format a long as a signed, decimal number. # is the
field width to use. If the number is smaller than the
field width, it is right justified and space filled.
If # starts with a leading zero, the field is zero
filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
%#o Format an int as an unsigned, octal number. # is the
field width to use. If the number is smaller than the
field width, it is right justified and space filled.
If # starts with a leading zero, the field is zero
filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
%#u Format an int as an unsigned, decimal number. # is the
field width to use. If the number is smaller than the
field width, it is right justified and space filled.
If # starts with a leading zero, the field is zero
filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
%#x Format an int as an unsigned, hexadecimal number. #
is the field width to use. If the number is smaller
than the field width, it is right justified and space
filled. If # starts with a leading zero, the field is
zero filled instead of space filled. If the number is
larger than the field width, it will spill off to the
right.
Strings
%#s The argument is a pointer to a NUL-terminated array of
characters. Copy that string to the output. # is a
field width. Padding is always with spaces on the right.
%c Format an int as a character.
%#z Output a NUL character. # is a repeat count.
%#DEL (Where DEL is the delete character, ^?, 127 decimal.)
Output a DEL. # is a repeat count.
%#SP (Where SP is the space character, 32 decimal.) Output
a Space. # is a repeat count.