PERFORCE change 32324 for review
Peter Wemm
peter at FreeBSD.org
Sun Jun 1 14:12:00 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=32324
Change 32324 by peter at 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[] = {
More information about the p4-projects
mailing list