1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-09-07 08:18:45 +10:00
collapseos/tools/blkunpack.c
Virgil Dupras 95ab1ad588 Transform "blk/" folders into "blk.fs" text files
Working in "blk/" folder from a modern system is harder than it
should be. Moving blocks around is a bit awkward, grepping is a
bit less convenient than it could be, git blame has troubles
following, etc.

In this commit, we modify blkpack and blkunpack to work with single
text files with blocks being separated by a special markup.

I think this will make the code significantly more convenient to
work into.
2020-11-14 18:34:15 -05:00

57 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
void usage()
{
fprintf(stderr, "Usage: blkunpack < blkfs > blk.fs\n");
}
int main(int argc, char *argv[])
{
char buf[1024];
int blkid = 0;
if (argc != 1) {
usage();
return 1;
}
while (fread(buf, 1024, 1, stdin) == 1) {
int linecnt = 0 ;
for (int i=1023; i>=0; i--) {
if (buf[i]) {
linecnt = (i / 64) + 1;
break;
}
}
if (linecnt) {
// not an empty block
printf("( ----- %03d )\n", blkid);
for (int i=0; i<linecnt; i++) {
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] = ' ';
}
}
fwrite(line, len, 1, stdout);
}
fputc('\n', stdout);
}
}
blkid++;
}
return 0;
}