~mrms/tarum

27d692b1eb88b9dd0c3aaf8e4e619875c6545fa8 — Marek Maškarinec 10 months ago cdab839
Update to Umka v1.3.0
2 files changed, 13 insertions(+), 26 deletions(-)

M tar.c
M tar.um
M tar.c => tar.c +9 -19
@@ 102,14 102,13 @@ umc__tar_open_bytes(UmkaStackSlot *p, UmkaStackSlot *r)
	r->intVal = 0;
}

void *fileArrType = NULL;

// fn umc__tar_get_files(tar: ^struct{}, out: ^[]File): int
// fn umc__tar_get_files(tar: ^struct{}, out: ^[]File, fileArrType: ^void): int
void
umc__tar_get_files(UmkaStackSlot *p, UmkaStackSlot *r)
{
	mtar_t *tar = (mtar_t *)p[1].ptrVal;
	UmkaDynArray(File) *out = p[0].ptrVal;
	mtar_t *tar = (mtar_t *)p[2].ptrVal;
	UmkaDynArray(File) *out = p[1].ptrVal;
	void *fileArrType = p[0].ptrVal;
	void *umka = r->ptrVal;
	r->intVal = 0;



@@ 126,10 125,6 @@ umc__tar_get_files(UmkaStackSlot *p, UmkaStackSlot *r)
		mtar_next(tar);
	}

	if (fileArrType == NULL) {
		fileArrType = umkaGetType(umka, "tar.um", "FileArr");
	}

	umkaMakeDynArray(umka, out, fileArrType, count);

	mtar_seek(tar, 0);


@@ 148,19 143,14 @@ umc__tar_get_files(UmkaStackSlot *p, UmkaStackSlot *r)
	}
}

static void *byteArrType = NULL;

// fn umc__tar_read_bin(tar: ^struct{}, file: str, out: ^[]byte): int
// fn umc__tar_read_bin(tar: ^struct{}, file: str, out: ^[]byte, byteArrType: ^void): int
void
umc__tar_read(UmkaStackSlot *p, UmkaStackSlot *r)
{
	if (byteArrType == NULL) {
		byteArrType = umkaGetType(r->ptrVal, "tar.um", "__Bytes");
	}

	mtar_t *tar = (mtar_t *)p[2].ptrVal;
	char *file = p[1].ptrVal;
	UmkaDynArray(uint8_t) *out = p[0].ptrVal;
	mtar_t *tar = (mtar_t *)p[3].ptrVal;
	char *file = p[2].ptrVal;
	UmkaDynArray(uint8_t) *out = p[1].ptrVal;
	void *byteArrType = p[0].ptrVal;
	void *umka = r->ptrVal;
	r->intVal = 0;


M tar.um => tar.um +4 -7
@@ 67,28 67,25 @@ fn (t: ^Tar) close*(): Errno {
    return umc__tar_close(t._)
}

type FileArr* = []File

fn umc__tar_get_files(tar: ^struct{}, out: ^FileArr): Errno
fn umc__tar_get_files(tar: ^struct{}, out: ^[]File, fileArrType: ^void): Errno
                                                      
//~~fn getFiles
// Returns a list of files in the given tar archive.
fn (t: ^Tar) getFiles*(): ([]File, Errno) {
//~~
    files := []File{}
    err := umc__tar_get_files(t._, &files)
    err := umc__tar_get_files(t._, &files, typeptr([]File))
    return files, err
}

type __Bytes* = []uint8
fn umc__tar_read(tar: ^struct{}, path: str, out: ^[]uint8): Errno
fn umc__tar_read(tar: ^struct{}, path: str, out: ^[]uint8, bytesArrType: ^void): Errno

//~~fn readBin
// Reads the given file from the tar archive as a byte array.
fn (t: ^Tar) read*(path: str): ([]uint8, Errno) {
//~~
    var s: []uint8
    err := umc__tar_read(t._, path, &s)
    err := umc__tar_read(t._, path, &s, typeptr([]uint8))
    return s, err
}