Lines Matching +full:end +full:- +full:of +full:- +full:conversion

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
5 * The Regents of the University of California. All rights reserved.
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * notice, this list of conditions and the following disclaimer in the
15 * 3. Neither the name of the University nor the names of its contributors
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 FU *endfu; /* format at end-of-data */
77 /* start new linked list of format units */ in add()
84 nextfs = &tfs->nextfs; in add()
85 nextfu = &tfs->nextfu; in add()
98 nextfu = &tfu->nextfu; in add()
99 tfu->reps = 1; in add()
107 tfu->reps = atoi(savep); in add()
108 tfu->flags = F_SETREP; in add()
122 tfu->bcnt = atoi(savep); in add()
133 if (!(tfu->fmt = malloc(p - savep + 1))) in add()
135 (void) strlcpy(tfu->fmt, savep, p - savep + 1); in add()
136 escape(tfu->fmt); in add()
141 static const char *spec = ".#-+ 0123456789";
152 for (cursize = 0, fu = fs->nextfu; fu; fu = fu->nextfu) { in size()
153 if (fu->bcnt) { in size()
154 cursize += fu->bcnt * fu->reps; in size()
157 for (bcnt = prec = 0, fmt = fu->fmt; *fmt; ++fmt) { in size()
161 * skip any special chars -- save precision in in size()
194 cursize += bcnt * fu->reps; in size()
211 for (fu = fs->nextfu; fu; fu = fu->nextfu) { in rewrite()
213 * Break each format unit into print units; each conversion in rewrite()
216 nextpr = &fu->nextpr; in rewrite()
217 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { in rewrite()
227 pr->fmt = fmtp; in rewrite()
228 pr->flags = F_TEXT; in rewrite()
233 * Get precision for %s -- if have a byte count, don't in rewrite()
236 if (fu->bcnt) { in rewrite()
238 /* Skip to conversion character. */ in rewrite()
257 p2 = *p1 ? p1 + 1 : p1; /* Set end pointer -- make sure in rewrite()
258 * that it's non-NUL/-NULL first in rewrite()
260 cs[0] = *p1; /* Set conversion string. */ in rewrite()
264 * Figure out the byte count for each conversion; in rewrite()
265 * rewrite the format as necessary, set up blank- in rewrite()
266 * padding for end of data. in rewrite()
270 pr->flags = F_CHAR; in rewrite()
271 switch(fu->bcnt) { in rewrite()
273 pr->bcnt = 1; in rewrite()
281 pr->flags = F_INT; in rewrite()
284 pr->flags = F_UINT; in rewrite()
288 switch(fu->bcnt) { in rewrite()
290 pr->bcnt = 4; in rewrite()
293 pr->bcnt = 1; in rewrite()
296 pr->bcnt = 2; in rewrite()
299 pr->bcnt = 8; in rewrite()
307 pr->flags = F_DBL; in rewrite()
308 switch(fu->bcnt) { in rewrite()
310 pr->bcnt = 8; in rewrite()
313 pr->bcnt = 4; in rewrite()
316 if (fu->bcnt == sizeof(long double)) { in rewrite()
320 pr->bcnt = sizeof(long double); in rewrite()
328 pr->flags = F_STR; in rewrite()
333 pr->bcnt = fu->bcnt; in rewrite()
336 pr->bcnt = prec; in rewrite()
345 fu->flags |= F_IGNORE; in rewrite()
348 pr->flags = F_ADDRESS; in rewrite()
362 pr->flags = F_C; in rewrite()
366 pr->flags = F_P; in rewrite()
370 pr->flags = F_U; in rewrite()
372 isint2: switch(fu->bcnt) { in rewrite()
374 pr->bcnt = 1; in rewrite()
392 * Copy to PR format string, set conversion character in rewrite()
397 if (asprintf(&pr->fmt, "%s%s", fmtp, cs) == -1) in rewrite()
400 pr->cchar = pr->fmt + (p1 - fmtp); in rewrite()
403 /* Only one conversion character if byte count. */ in rewrite()
404 if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) in rewrite()
405 errx(1, "byte count with multiple conversion characters"); in rewrite()
411 if (!fu->bcnt) in rewrite()
412 for (pr = fu->nextpr; pr; pr = pr->nextpr) in rewrite()
413 fu->bcnt += pr->bcnt; in rewrite()
422 * gets output from the last iteration of the format unit. in rewrite()
424 for (fu = fs->nextfu; fu; fu = fu->nextfu) { in rewrite()
425 if (!fu->nextfu && fs->bcnt < blocksize && in rewrite()
426 !(fu->flags&F_SETREP) && fu->bcnt) in rewrite()
427 fu->reps += (blocksize - fs->bcnt) / fu->bcnt; in rewrite()
428 if (fu->reps > 1) { in rewrite()
429 for (pr = fu->nextpr;; pr = pr->nextpr) in rewrite()
430 if (!pr->nextpr) in rewrite()
432 for (p1 = pr->fmt, p2 = NULL; *p1; ++p1) in rewrite()
435 pr->nospace = p2; in rewrite()
439 for (fu = fs->nextfu; fu; fu = fu->nextfu) { in rewrite()
441 for (pr = fu->nextpr; pr; pr = pr->nextpr) in rewrite()
442 (void)printf(" {%s}", pr->fmt); in rewrite()
517 errx(1, "%%%s: bad conversion character", ch); in badconv()
523 errx(1, "missing conversion character"); in badnoconv()