diff rvinterf/etmsync/fsread.c @ 285:bb28ba9e82c5

fc-fsio: file read primitive and hd command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 06:16:02 +0000
parents 7b4d4e3e610a
children 211b35db427c
line wrap: on
line diff
--- a/rvinterf/etmsync/fsread.c	Fri Feb 28 05:50:01 2014 +0000
+++ b/rvinterf/etmsync/fsread.c	Fri Feb 28 06:16:02 2014 +0000
@@ -91,9 +91,45 @@
 	return(0);
 }
 
+void
+hexdump_line(offset, buf, len)
+	u_char *buf;
+{
+	int i, c;
+
+	printf("%02X:  ", offset);
+	for (i = 0; i < 16; i++) {
+		if (i < len)
+			printf("%02X ", buf[i]);
+		else
+			fputs("   ", stdout);
+		if (i == 7 || i == 15)
+			putchar(' ');
+	}
+	for (i = 0; i < len; i++) {
+		c = buf[i];
+		if (c < ' ' || c > '~')
+			c = '.';
+		putchar(c);
+	}
+	putchar('\n');
+}
+
 cmd_hd(argc, argv)
 	char **argv;
 {
-
+	u_char databuf[MAX_READ_DATA];
+	int rc, sz, off, l;
 
+	rc = do_file_read(argv[1], databuf, MAX_READ_DATA, &sz);
+	if (rc)
+		return(rc);
+	printf("%d bytes read\n", sz);
+	for (off = 0; off < sz; off += 16) {
+		l = sz - off;
+		if (l > 16)
+			l = 16;
+		hexdump_line(off, databuf + off, l);
+	}
+	return(0);
 }