printf.c (209842) | printf.c (209949) |
---|---|
1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/lib/libstand/printf.c 209842 2010-07-09 05:25:14Z jkim $"); | 38__FBSDID("$FreeBSD: head/lib/libstand/printf.c 209949 2010-07-12 15:32:45Z jkim $"); |
39 40/* 41 * Standaloneified version of the FreeBSD kernel printf family. 42 */ 43 44#include <sys/types.h> 45#include <sys/stddef.h> 46#include <sys/stdint.h> --- 99 unchanged lines hidden (view full) --- 146 * 147 * XXX: %D -- Hexdump, takes pointer and separator string: 148 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX 149 * ("%*D", len, ptr, " " -> XX XX XX XX ... 150 */ 151static int 152kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, va_list ap) 153{ | 39 40/* 41 * Standaloneified version of the FreeBSD kernel printf family. 42 */ 43 44#include <sys/types.h> 45#include <sys/stddef.h> 46#include <sys/stdint.h> --- 99 unchanged lines hidden (view full) --- 146 * 147 * XXX: %D -- Hexdump, takes pointer and separator string: 148 * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX 149 * ("%*D", len, ptr, " " -> XX XX XX XX ... 150 */ 151static int 152kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, va_list ap) 153{ |
154#define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |
155#define PCHAR(c) {int cc=(c); if (func) (*func)(cc); else *d++ = cc; retval++; } 156 char nbuf[MAXNBUF]; 157 char *d; 158 const char *p, *percent, *q; 159 u_char *up; 160 int ch, n; 161 uintmax_t num; 162 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot; --- 254 unchanged lines hidden (view full) --- 417 else if (base == 16) 418 tmp += 2; 419 } 420 if (neg) 421 tmp++; 422 423 if (!ladjust && padc == '0') 424 dwidth = width - tmp; | 154#define PCHAR(c) {int cc=(c); if (func) (*func)(cc); else *d++ = cc; retval++; } 155 char nbuf[MAXNBUF]; 156 char *d; 157 const char *p, *percent, *q; 158 u_char *up; 159 int ch, n; 160 uintmax_t num; 161 int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot; --- 254 unchanged lines hidden (view full) --- 416 else if (base == 16) 417 tmp += 2; 418 } 419 if (neg) 420 tmp++; 421 422 if (!ladjust && padc == '0') 423 dwidth = width - tmp; |
425 width -= tmp + MAX(dwidth, n); | 424 width -= tmp + imax(dwidth, n); |
426 dwidth -= n; 427 if (!ladjust) 428 while (width-- > 0) 429 PCHAR(' '); 430 if (neg) 431 PCHAR('-'); 432 if (sharpflag && num != 0) { 433 if (base == 8) { --- 32 unchanged lines hidden --- | 425 dwidth -= n; 426 if (!ladjust) 427 while (width-- > 0) 428 PCHAR(' '); 429 if (neg) 430 PCHAR('-'); 431 if (sharpflag && num != 0) { 432 if (base == 8) { --- 32 unchanged lines hidden --- |