31 lines
871 B
Diff
31 lines
871 B
Diff
|
--- 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');
|
||
|
}
|