Lines Matching +full:- +full:p1
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
42 FU *endfu; /* format at end-of-data */
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()
205 unsigned char *p1, *p2, *fmtp; in rewrite() local
211 for (fu = fs->nextfu; fu; fu = fu->nextfu) { in rewrite()
216 nextpr = &fu->nextpr; in rewrite()
217 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { in rewrite()
223 for (p1 = fmtp; *p1 && *p1 != '%'; ++p1); in rewrite()
226 if (!*p1) { 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()
239 while (*++p1 != 0 && strchr(spec, *p1) != NULL) in rewrite()
241 if (*p1 == 0) in rewrite()
245 while (*++p1 != 0 && strchr(spec + 1, *p1) != NULL) in rewrite()
247 if (*p1 == 0) in rewrite()
249 if (*p1 == '.' && isdigit(*++p1)) { in rewrite()
251 prec = atoi(p1); in rewrite()
252 while (isdigit(*++p1)); 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()
265 * rewrite the format as necessary, set up blank- in rewrite()
270 pr->flags = F_CHAR; in rewrite()
271 switch(fu->bcnt) { in rewrite()
273 pr->bcnt = 1; in rewrite()
276 p1[1] = '\0'; in rewrite()
277 badcnt(p1); 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()
302 p1[1] = '\0'; in rewrite()
303 badcnt(p1); 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()
322 p1[1] = '\0'; in rewrite()
323 badcnt(p1); in rewrite()
328 pr->flags = F_STR; in rewrite()
333 pr->bcnt = fu->bcnt; in rewrite()
336 pr->bcnt = prec; in rewrite()
342 switch(p1[1]) { in rewrite()
345 fu->flags |= F_IGNORE; in rewrite()
348 pr->flags = F_ADDRESS; in rewrite()
350 switch(p1[2]) { in rewrite()
353 cs[1] = p1[2]; in rewrite()
357 p1[3] = '\0'; in rewrite()
358 badconv(p1); 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()
377 p1[2] = '\0'; in rewrite()
378 badcnt(p1); in rewrite()
382 p1[2] = '\0'; in rewrite()
383 badconv(p1); in rewrite()
387 p1[1] = '\0'; in rewrite()
388 badconv(p1); in rewrite()
396 p1[0] = '\0'; in rewrite()
397 if (asprintf(&pr->fmt, "%s%s", fmtp, cs) == -1) in rewrite()
400 pr->cchar = pr->fmt + (p1 - fmtp); in rewrite()
404 if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) 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()
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()
433 p2 = isspace(*p1) ? p1 : NULL; 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()
449 escape(char *p1) in escape() argument
454 for (p2 = p1;; p1++, p2++) { in escape()
455 if (*p1 == '\\') { in escape()
456 p1++; in escape()
457 switch(*p1) { in escape()
485 *p2 = *p1; in escape()
489 *p2 = *p1; in escape()
490 if (*p1 == '\0') in escape()