1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18 #ifndef lint
19 static char sccsid[] = "@(#)bpad.c 5.2 (Berkeley) 08/29/89";
20 #endif /* not lint */
21
22 #include <sys/types.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include "hexdump.h"
26
bpad(fu,pr)27 bpad(fu, pr)
28 FU *fu;
29 PR *pr;
30 {
31 register char *p1, *p2;
32
33 /*
34 * the format string has no more data to print out. Go through
35 * the rest of the format string, and, for all non-%s conversions,
36 * replace with %s and remove any conversion flags that don't
37 * apply to %s. This should replace any output with an equivalent
38 * number of spaces.
39 */
40 for (;;) {
41 if (fu->flags&F_IGNORE)
42 continue;
43 for (; pr; pr = pr->nextpr) {
44 if (pr->flags == F_TEXT)
45 continue;
46 pr->flags = F_BPAD;
47 *pr->cchar = 's';
48 /* remove conversion flags %s can't handle. */
49 for (p1 = p2 = pr->fmt; *p1; *p2++ = *p1++)
50 if (*p1 == '%') {
51 static char *spec1 = "-0+ #";
52 static char *spec2 = ".0123456789";
53
54 *p2++ = *p1;
55 while (index(spec1, *++p1))
56 if (*p1 == '-')
57 *p2++ = '-';
58 while (index(spec2, *p2++ = *p1++));
59 }
60 *p2 = '\0';
61 }
62 if (!(fu = fu->nextfu))
63 break;
64 pr = fu->nextpr;
65 }
66 }
67