Skip to content

Commit

Permalink
module modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet committed Jan 3, 2022
1 parent 9499115 commit a07b7af
Showing 1 changed file with 26 additions and 48 deletions.
74 changes: 26 additions & 48 deletions modules/base/modules/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,42 @@ extern void* xsPreparationAndCreation(xsCreation **creation);
void xs_modules_host(xsMachine *the)
{
txPreparation *preparation = xsPreparationAndCreation(NULL);
txInteger scriptCount = preparation->scriptCount, i = 0;
txScript* script = preparation->scripts;

xsResult = xsNewArray(0);

while (scriptCount--) {
char path[C_PATH_MAX];
char *dot;

c_strcpy(path, script->path);
dot = c_strchr(path, '.');
if (dot)
*dot = 0;

xsSetIndex(xsResult, i++, xsString(path));

script++;
if (preparation) {
txInteger scriptCount = preparation->scriptCount, i = 0;
txScript* script = preparation->scripts;
while (scriptCount--) {
char path[C_PATH_MAX];
c_strcpy(path, script->path);
xsSetIndex(xsResult, i++, xsString(path));
script++;
}
}
}

#define mxArchiveHeaderSize (sizeof(Atom) + sizeof(Atom) + XS_VERSION_SIZE + sizeof(Atom) + XS_DIGEST_SIZE + sizeof(Atom) + XS_DIGEST_SIZE)

void xs_modules_archive(xsMachine *the)
{
uint8_t *p, *q;
int i = 0;
char path[128];
txPreparation *preparation;

uint8_t *p = the->archive;
xsResult = xsNewArray(0);

preparation = xsPreparationAndCreation(NULL);
if (!preparation)
return;
c_memcpy(path, preparation->base, preparation->baseLength);

p = the->archive;
if (!p) return;

p += mxArchiveHeaderSize;
// NAME
p += c_read32be(p);
// SYMB
p += c_read32be(p);
// MODS
q = p + c_read32be(p);
p += sizeof(Atom);

while (p < q) {
int atomSize = c_read32be(p);

c_strcpy(path + preparation->baseLength, (txString)(p + sizeof(Atom)));
path[atomSize - sizeof(Atom) - 4] = 0;

xsSetIndex(xsResult, i++, xsString(path + preparation->baseLength));

p += atomSize;
if (p) {
uint8_t *q;
int i = 0;
p += mxArchiveHeaderSize;
// NAME
p += c_read32be(p);
// SYMB
p += c_read32be(p);
// MODS
q = p + c_read32be(p);
p += sizeof(Atom);
while (p < q) {
int atomSize = c_read32be(p);
xsSetIndex(xsResult, i++, xsString((txString)(p + sizeof(Atom))));
p += atomSize;
p += c_read32be(p);
}
}
}

Expand Down

0 comments on commit a07b7af

Please sign in to comment.