From owner-p4-projects@FreeBSD.ORG Sun Jun 1 14:12:00 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CB5FC37B404; Sun, 1 Jun 2003 14:11:59 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4C23037B401 for ; Sun, 1 Jun 2003 14:11:59 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB22143F3F for ; Sun, 1 Jun 2003 14:11:58 -0700 (PDT) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h51LBw0U071655 for ; Sun, 1 Jun 2003 14:11:58 -0700 (PDT) (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h51LBwDp071652 for perforce@freebsd.org; Sun, 1 Jun 2003 14:11:58 -0700 (PDT) Date: Sun, 1 Jun 2003 14:11:58 -0700 (PDT) Message-Id: <200306012111.h51LBwDp071652@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm To: Perforce Change Reviews Subject: PERFORCE change 32324 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jun 2003 21:12:00 -0000 http://perforce.freebsd.org/chv.cgi?CH=32324 Change 32324 by peter@peter_hammer on 2003/06/01 14:11:21 autosense the width of the screen. I'm not sure if this is a good idea or not. Affected files ... .. //depot/projects/hammer/usr.bin/kdump/kdump.c#4 edit Differences ... ==== //depot/projects/hammer/usr.bin/kdump/kdump.c#4 (text+ko) ==== @@ -72,7 +72,8 @@ void ktrsyscall(struct ktr_syscall *); void ktrsysret(struct ktr_sysret *); void ktrnamei(char *, int); -void hd(void *, int); +void hexdump(char *, int, int); +void visdump(char *, int, int); void ktrgenio(struct ktr_genio *, int); void ktrpsig(struct ktr_psig *); void ktrcsw(struct ktr_csw *); @@ -396,27 +397,38 @@ } void -hd(void *buf, int len) +hexdump(char *p, int len, int screenwidth) { - unsigned char *p; int n, i; + int width; - p = buf; - for (n = 0; n < len; n += 16) { - for (i = n; i < n + 16; i++) { - if ((i % 16) == 0) { /* beginning of line */ - printf(" 0x%04x\t", i); + width = 0; + do { + width += 2; + i = 13; /* base offset */ + i += (width / 2) + 1; /* spaces every second byte */ + i += (width * 2); /* width of bytes */ + i += 3; /* " |" */ + i += width; /* each byte */ + i += 1; /* "|" */ + } while (i < screenwidth); + width -= 2; + + for (n = 0; n < len; n += width) { + for (i = n; i < n + width; i++) { + if ((i % width) == 0) { /* beginning of line */ + printf(" 0x%04x", i); } if ((i % 2) == 0) { printf(" "); } if (i < len) - printf("%02x", p[i]); + printf("%02x", p[i] & 0xff); else printf(" "); } - printf("\t"); - for (i = n; i < n + 16; i++) { + printf(" |"); + for (i = n; i < n + width; i++) { if (i >= len) break; if (p[i] >= ' ' && p[i] <= '~') @@ -424,11 +436,56 @@ else printf("."); } - printf("\n"); + printf("|\n"); } - if ((i % 16) != 0) { + if ((i % width) != 0) printf("\n"); +} + +void +visdump(char *dp, int datalen, int screenwidth) +{ + int col = 0; + char *cp; + int width; + char visbuf[5]; + + (void)printf(" \""); + col = 8; + for (;datalen > 0; datalen--, dp++) { + (void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1)); + cp = visbuf; + /* + * Keep track of printables and + * space chars (like fold(1)). + */ + if (col == 0) { + (void)putchar('\t'); + col = 8; + } + switch(*cp) { + case '\n': + col = 0; + (void)putchar('\n'); + continue; + case '\t': + width = 8 - (col&07); + break; + default: + width = strlen(cp); + } + if (col + width > (screenwidth-2)) { + (void)printf("\\\n\t"); + col = 8; + } + col += width; + do { + (void)putchar(*cp++); + } while (*cp); } + if (col == 0) + (void)printf(" "); + (void)printf("\"\n"); } void @@ -436,10 +493,6 @@ { int datalen = len - sizeof (struct ktr_genio); char *dp = (char *)ktr + sizeof (struct ktr_genio); - char *cp; - int col = 0; - int width; - char visbuf[5]; static int screenwidth = 0; int i, binary; @@ -465,46 +518,10 @@ continue; binary = 1; } - if (binary) { - hd(dp, datalen); - } else { - (void)printf(" \""); - col = 8; - for (;datalen > 0; datalen--, dp++) { - (void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1)); - cp = visbuf; - /* - * Keep track of printables and - * space chars (like fold(1)). - */ - if (col == 0) { - (void)putchar('\t'); - col = 8; - } - switch(*cp) { - case '\n': - col = 0; - (void)putchar('\n'); - continue; - case '\t': - width = 8 - (col&07); - break; - default: - width = strlen(cp); - } - if (col + width > (screenwidth-2)) { - (void)printf("\\\n\t"); - col = 8; - } - col += width; - do { - (void)putchar(*cp++); - } while (*cp); - } - if (col == 0) - (void)printf(" "); - (void)printf("\"\n"); - } + if (binary) + hexdump(dp, datalen, screenwidth); + else + visdump(dp, datalen, screenwidth); } const char *signames[] = {