Add "nocrypt" target to create a subdirectory
[unix-history] / usr / src / usr.bin / hexdump / bpad.c
CommitLineData
671713a5
KB
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
6d23aef6 19static char sccsid[] = "@(#)bpad.c 5.2 (Berkeley) %G%";
671713a5
KB
20#endif /* not lint */
21
22#include <sys/types.h>
23#include <stdio.h>
24#include <ctype.h>
25#include "hexdump.h"
26
6d23aef6 27bpad(fu, pr)
671713a5
KB
28 FU *fu;
29 PR *pr;
671713a5 30{
671713a5 31 register char *p1, *p2;
671713a5
KB
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
6d23aef6 38 * number of spaces.
671713a5 39 */
671713a5
KB
40 for (;;) {
41 if (fu->flags&F_IGNORE)
42 continue;
43 for (; pr; pr = pr->nextpr) {
6d23aef6
KB
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. */
671713a5 49 for (p1 = p2 = pr->fmt; *p1; *p2++ = *p1++)
6d23aef6
KB
50 if (*p1 == '%') {
51 static char *spec1 = "-0+ #";
52 static char *spec2 = ".0123456789";
53
671713a5
KB
54 *p2++ = *p1;
55 while (index(spec1, *++p1))
56 if (*p1 == '-')
57 *p2++ = '-';
58 while (index(spec2, *p2++ = *p1++));
671713a5
KB
59 }
60 *p2 = '\0';
61 }
62 if (!(fu = fu->nextfu))
63 break;
64 pr = fu->nextpr;
65 }
671713a5 66}