2020-04-17 09:44:17 +10:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
2020-11-15 10:00:31 +11:00
|
|
|
fprintf(stderr, "Usage: blkunpack < blkfs > blk.fs\n");
|
2020-04-17 09:44:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
int blkid = 0;
|
2020-11-15 10:00:31 +11:00
|
|
|
if (argc != 1) {
|
2020-04-17 09:44:17 +10:00
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while (fread(buf, 1024, 1, stdin) == 1) {
|
2020-06-23 20:52:34 +10:00
|
|
|
int linecnt = 0 ;
|
|
|
|
for (int i=1023; i>=0; i--) {
|
|
|
|
if (buf[i]) {
|
|
|
|
linecnt = (i / 64) + 1;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-17 09:44:17 +10:00
|
|
|
}
|
2020-06-23 20:52:34 +10:00
|
|
|
if (linecnt) {
|
2020-04-17 09:44:17 +10:00
|
|
|
// not an empty block
|
2020-11-15 10:00:31 +11:00
|
|
|
printf("( ----- %03d )\n", blkid);
|
2020-06-23 20:52:34 +10:00
|
|
|
for (int i=0; i<linecnt; i++) {
|
2020-06-12 08:12:01 +10:00
|
|
|
char *line = &buf[i*64];
|
|
|
|
// line length is *not* strlen()! it's the
|
|
|
|
// position of the first non-null, starting
|
|
|
|
// from the right. Then, we normalize nulls
|
|
|
|
// to space.
|
|
|
|
int j;
|
|
|
|
for (j=63; j>=0; j--) {
|
|
|
|
if (line[j] != '\0') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int len = j+1;
|
|
|
|
if (len) {
|
|
|
|
for (; j>=0; j--) {
|
|
|
|
if (line[j] == '\0') {
|
|
|
|
line[j] = ' ';
|
|
|
|
}
|
|
|
|
}
|
2020-11-15 10:00:31 +11:00
|
|
|
fwrite(line, len, 1, stdout);
|
2020-06-12 08:12:01 +10:00
|
|
|
}
|
2020-11-15 10:00:31 +11:00
|
|
|
fputc('\n', stdout);
|
2020-04-17 09:44:17 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
blkid++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|