46 lines
1.4 KiB
Diff
46 lines
1.4 KiB
Diff
--- a/toys/other/xxd.c
|
|
+++ b/toys/other/xxd.c
|
|
@@ -77,11 +77,13 @@ static void do_xxd(int fd, char *name)
|
|
|
|
static void do_xxd_include(int fd, char *name)
|
|
{
|
|
+ long long total = 0;
|
|
int c = 1, i, len;
|
|
|
|
// The original xxd outputs a header/footer if given a filename (not stdin).
|
|
// We don't, which means that unlike the original we can implement -ri.
|
|
while ((len = read(fd, toybuf, sizeof(toybuf))) > 0) {
|
|
+ total += len;
|
|
for (i = 0; i < len; ++i) {
|
|
printf("%s%#.02x", c > 1 ? ", " : " ", toybuf[i]);
|
|
if (c++ == TT.c) {
|
|
--- a/toys/other/xxd.c
|
|
+++ b/toys/other/xxd.c
|
|
@@ -80,7 +80,12 @@
|
|
int c = 1, i, len;
|
|
|
|
// The original xxd outputs a header/footer if given a filename (not stdin).
|
|
- // We don't, which means that unlike the original we can implement -ri.
|
|
+ // We don't, which means that unlike the original we can implement -ri
|
|
+ printf("unsigned char %s", isdigit(name[0]) ? "__": "");
|
|
+ for (char *n = name; *n; n++)
|
|
+ putchar(*n == '.' ? '_' : *n);
|
|
+ puts("[] = {");
|
|
+
|
|
while ((len = read(fd, toybuf, sizeof(toybuf))) > 0) {
|
|
total += len;
|
|
for (i = 0; i < len; ++i) {
|
|
@@ -91,6 +96,13 @@
|
|
}
|
|
}
|
|
}
|
|
+ puts("};");
|
|
+ printf("unsigned int %s", isdigit(name[0]) ? "__": "");
|
|
+ for (char *n = name; *n; n++)
|
|
+ putchar(*n == '.' ? '_' : *n);
|
|
+
|
|
+ printf("_len = %lld;\n", total);
|
|
+
|
|
if (len < 0) perror_msg_raw(name);
|
|
if (c > 1) xputc('\n');
|
|
}
|