xref: /csrg-svn/usr.bin/hexdump/bpad.c (revision 38860)
138853Sbostic /*
238853Sbostic  * Copyright (c) 1989 The Regents of the University of California.
338853Sbostic  * All rights reserved.
438853Sbostic  *
538853Sbostic  * Redistribution and use in source and binary forms are permitted
638853Sbostic  * provided that the above copyright notice and this paragraph are
738853Sbostic  * duplicated in all such forms and that any documentation,
838853Sbostic  * advertising materials, and other materials related to such
938853Sbostic  * distribution and use acknowledge that the software was developed
1038853Sbostic  * by the University of California, Berkeley.  The name of the
1138853Sbostic  * University may not be used to endorse or promote products derived
1238853Sbostic  * from this software without specific prior written permission.
1338853Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1438853Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1538853Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1638853Sbostic  */
1738853Sbostic 
1838853Sbostic #ifndef lint
19*38860Sbostic static char sccsid[] = "@(#)bpad.c	5.2 (Berkeley) 08/29/89";
2038853Sbostic #endif /* not lint */
2138853Sbostic 
2238853Sbostic #include <sys/types.h>
2338853Sbostic #include <stdio.h>
2438853Sbostic #include <ctype.h>
2538853Sbostic #include "hexdump.h"
2638853Sbostic 
bpad(fu,pr)27*38860Sbostic bpad(fu, pr)
2838853Sbostic 	FU *fu;
2938853Sbostic 	PR *pr;
3038853Sbostic {
3138853Sbostic 	register char *p1, *p2;
3238853Sbostic 
3338853Sbostic 	/*
3438853Sbostic 	 * the format string has no more data to print out.  Go through
3538853Sbostic 	 * the rest of the format string, and, for all non-%s conversions,
3638853Sbostic 	 * replace with %s and remove any conversion flags that don't
3738853Sbostic 	 * apply to %s.  This should replace any output with an equivalent
38*38860Sbostic 	 * number of spaces.
3938853Sbostic 	 */
4038853Sbostic 	for (;;) {
4138853Sbostic 		if (fu->flags&F_IGNORE)
4238853Sbostic 			continue;
4338853Sbostic 		for (; pr; pr = pr->nextpr) {
44*38860Sbostic 			if (pr->flags == F_TEXT)
45*38860Sbostic 				continue;
46*38860Sbostic 			pr->flags = F_BPAD;
47*38860Sbostic 			*pr->cchar = 's';
48*38860Sbostic 			/* remove conversion flags %s can't handle. */
4938853Sbostic 			for (p1 = p2 = pr->fmt; *p1; *p2++ = *p1++)
50*38860Sbostic 				if (*p1 == '%') {
51*38860Sbostic 					static char *spec1 = "-0+ #";
52*38860Sbostic 					static char *spec2 = ".0123456789";
53*38860Sbostic 
5438853Sbostic 					*p2++ = *p1;
5538853Sbostic 					while (index(spec1, *++p1))
5638853Sbostic 						if (*p1 == '-')
5738853Sbostic 							*p2++ = '-';
5838853Sbostic 					while (index(spec2, *p2++ = *p1++));
5938853Sbostic 				}
6038853Sbostic 			*p2 = '\0';
6138853Sbostic 		}
6238853Sbostic 		if (!(fu = fu->nextfu))
6338853Sbostic 			break;
6438853Sbostic 		pr = fu->nextpr;
6538853Sbostic 	}
6638853Sbostic }
67