Kaynağa Gözat

tools: add blkpack

pull/102/head
Virgil Dupras 4 yıl önce
ebeveyn
işleme
d4cdb659b4
6 değiştirilmiş dosya ile 87 ekleme ve 2 silme
  1. +2
    -1
      README.md
  2. +15
    -0
      blk/000
  3. +2
    -0
      blk/001
  4. +1
    -0
      tools/.gitignore
  5. +3
    -1
      tools/Makefile
  6. +64
    -0
      tools/blkpack.c

+ 2
- 1
README.md Dosyayı Görüntüle

@@ -41,11 +41,12 @@ path to giving Collapse OS a try.
from this folder.
* `recipes`: collection of recipes that assemble parts together on a specific
machine.
* `blk`: Collapse OS filesystem's content. See `000` for intro.
* `doc`: User guide for when you've successfully installed Collapse OS.
* `tools`: Tools for working with Collapse OS from "modern" environments. For
example, tools for facilitating data upload to a Collapse OS machine
through a serial port.
* `emul`: Emulated applications, such as zasm and the shell.
* `emul`: Emulated applications.
* `tests`: Automated test suite for the whole project.

## Status


+ 15
- 0
blk/000 Dosyayı Görüntüle

@@ -0,0 +1,15 @@
Collapse OS file system

This is a Forth-style filesystems which is very simple. It is a
list of 1024 bytes block, organised in 16 lines of 64 columns
each. You refer to blocks by numbers. You show them with LIST.
You interpret them with LOAD.

Conventions: When you see "(cont.)" at the bottom right of a
block, it means that the next block continues the same kind of
contents. This of course only work for informational text.

Block numbers are abbreviated with prefix "B". "BX" means
"block X".

The master index of this filesystem is at B1.

+ 2
- 0
blk/001 Dosyayı Görüntüle

@@ -0,0 +1,2 @@
MASTER INDEX


+ 1
- 0
tools/.gitignore Dosyayı Görüntüle

@@ -8,3 +8,4 @@
/stripfc
/bin2c
/exec
/blkpack

+ 3
- 1
tools/Makefile Dosyayı Görüntüle

@@ -8,9 +8,10 @@ SLATEST_TGT = slatest
STRIPFC_TGT = stripfc
BIN2C_TGT = bin2c
EXEC_TGT = exec
BLKPACK_TGT = blkpack
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \
$(BIN2C_TGT) $(EXEC_TGT)
$(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT)
OBJS = common.o

all: $(TARGETS)
@@ -29,6 +30,7 @@ $(SLATEST_TGT): $(SLATEST_TGT).c
$(STRIPFC_TGT): $(STRIPFC_TGT).c
$(BIN2C_TGT): $(BIN2C_TGT).c
$(EXEC_TGT): $(EXEC_TGT).c
$(BLKPACK_TGT): $(BLKPACK_TGT).c
$(TARGETS): $(OBJS)
$(CC) $(CFLAGS) $@.c $(OBJS) -o $@



+ 64
- 0
tools/blkpack.c Dosyayı Görüntüle

@@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

void usage()
{
fprintf(stderr, "Usage: blkpack dirname\n");
}

int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *ep;
char *buf = NULL;
int blkcnt = 0;
if (argc != 2) {
usage();
return 1;
}
dp = opendir(argv[1]);
if (dp == NULL) {
fprintf(stderr, "Couldn't open directory.\n");
return 1;
}
while ((ep = readdir(dp))) {
if ((strcmp(ep->d_name, ".") == 0) || strcmp(ep->d_name, "..") == 0) {
continue;
}
if (ep->d_type != DT_REG) {
continue;
}
int blkid = atoi(ep->d_name);
if (blkid >= blkcnt) {
int newcnt = blkid+1;
buf = realloc(buf, newcnt*1024);
bzero(buf+(blkcnt*1024), (newcnt-blkcnt)*1024);
blkcnt = newcnt;
}
char fullpath[0x200];
strcpy(fullpath, argv[1]);
strcat(fullpath, "/");
strcat(fullpath, ep->d_name);
FILE *fp = fopen(fullpath, "r");
char *line = NULL;
size_t n = 0;
for (int i=0; i<16; i++) {
ssize_t cnt = getline(&line, &n, fp);
if (cnt < 0) break;
if (cnt > 65) {
fprintf(stderr, "Line %d too long in blk %s\n", i+1, ep->d_name);
}
strncpy(buf+(blkid*1024)+(i*64), line, cnt-1);
}
free(line);
}
fwrite(buf, 1024, blkcnt, stdout);
free(buf);
closedir(dp);
return 0;
}


Yükleniyor…
İptal
Kaydet