30
31
static int NEAR checkchar __P_((int, printbuf_t *));
31
32
static int NEAR setint __P_((u_long_t, int, printbuf_t *, int, int));
34
static int NEAR unitint __P_((u_long_t, int, printbuf_t *, int, int));
32
36
static int NEAR setstr __P_((CONST char *, printbuf_t *, int, int));
33
37
static int NEAR commonprintf __P_((printbuf_t *, CONST char *, va_list));
35
39
CONST char printfflagchar[] = {
37
41
#ifndef MINIMUMSHELL
42
'+', ' ', '<', '^', '>',
42
46
CONST int printfflag[] = {
43
47
VF_MINUS, VF_ZERO, VF_THOUSAND,
44
48
#ifndef MINIMUMSHELL
45
VF_PLUS, VF_SPACE, VF_STRICTWIDTH, VF_PRINTABLE,
49
VF_PLUS, VF_SPACE, VF_STRICTWIDTH, VF_PRINTABLE, VF_SIZEUNIT,
48
52
CONST char printfsizechar[] = {
324
332
if (c && setchar(c, pbufp) < 0) return(-1);
326
if (prec >= 0 && len < prec) {
327
for (i = 0; i < prec - len; i++) {
334
if (prec < 0 || len >= prec) /*EMPTY*/;
335
else for (i = 0; i < prec - len; i++) {
328
336
#ifndef MINIMUMSHELL
329
if ((pbufp -> flags & VF_STRICTWIDTH) && width == 1)
337
if ((pbufp -> flags & VF_STRICTWIDTH) && width == 1) break;
334
if ((pbufp -> flags & VF_THOUSAND)
335
&& !((prec - i) % (THDIGIT + 1)))
337
if (setchar(c, pbufp) < 0) return(-1);
341
if ((pbufp -> flags & VF_STRICTWIDTH) && width >= 0 && width < len)
342
for (i = 0; i < width; i++) {
344
341
if ((pbufp -> flags & VF_THOUSAND)
345
&& !((width - i) % (THDIGIT + 1)))
342
&& !((prec - i) % (THDIGIT + 1)))
346
343
c = (i) ? ',' : ' ';
347
344
if (setchar(c, pbufp) < 0) return(-1);
350
#endif /* !MINIMUMSHELL */
351
for (i = 0; i < len; i++) {
352
if (setchar(num[len - i - 1], pbufp) < 0) return(-1);
349
if (width < 0 || width >= len) /*EMPTY*/;
350
else if (pbufp -> flags & VF_SIZEUNIT) return(len);
351
else if (pbufp -> flags & VF_ASPOSSIBLE) i = len - width;
352
else if (pbufp -> flags & VF_STRICTWIDTH)
353
for (len = 0; len < width; len++)
354
if (Xisdigit(num[len])) num[len] = '9';
357
while (i++ < len) if (setchar(num[len - i], pbufp) < 0) return(-1);
355
359
if (width >= 0) for (; i < width; i++) {
356
360
if (setchar(' ', pbufp) < 0) return(-1);
359
363
return(pbufp -> ptr - ptr);
367
static int NEAR unitint(u, base, pbufp, width, prec)
374
int len, unit, uwidth, frac;
376
memcpy((char *)&pbuf, (char *)pbufp, sizeof(pbuf));
378
pbufp -> flags |= VF_FILE;
379
len = unit = uwidth = 0;
381
if (pbufp -> flags & VF_STRICTWIDTH) unit++;
382
if (width >= MINUNITWIDTH) for (;;) {
383
if (unit) uwidth = 3;
384
pbufp -> ptr = pbuf.ptr;
385
len = setint(u, base, pbufp, -1, prec);
390
if (len + uwidth <= width) break;
391
if (!(printfsizeunit[unit])) break;
393
frac = (int)(u & (u_long_t)0x3ff);
397
memcpy((char *)pbufp, (char *)&pbuf, sizeof(pbuf));
398
if ((pbufp -> flags & VF_STRICTWIDTH) || len + 2 + uwidth > width)
400
if (frac < 0) len = width - uwidth;
401
pbufp -> flags &= ~VF_SIZEUNIT;
402
pbufp -> flags |= VF_STRICTWIDTH;
403
len = setint(u, base, pbufp, len, prec);
404
if (len < 0) return(-1);
406
width -= len + 1 + uwidth;
410
if (setchar('.', pbufp) < 0) return(-1);
411
pbufp -> flags &= (VF_NEW | VF_FILE);
412
pbufp -> flags |= (VF_ZERO | VF_ASPOSSIBLE);
413
if (setint(u, base, pbufp, width, prec) < 0) return(-1);
416
if (setchar(' ', pbufp) < 0) return(-1);
417
if (setchar(printfsizeunit[unit - 1], pbufp) < 0) return(-1);
418
if (setchar('B', pbufp) < 0) return(-1);
421
return(pbufp -> ptr - pbuf.ptr);
423
#endif /* !MINIMUMSHELL */
362
425
static int NEAR setstr(s, pbufp, width, prec)
364
427
printbuf_t *pbufp;
691
754
if (u & ~mask) u |= ~mask;
758
if (pbufp -> flags & VF_SIZEUNIT)
759
len = unitint(u, base, pbufp, width, prec);
693
762
len = setint(u, base, pbufp, width, prec);