MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / findMod

Function findMod

xs/platforms/qca4020/xsHost.c:492–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490#define FOURCC(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
491
492static uint8_t *findMod(txMachine *the, char *name, int *modSize)
493{
494 uint8_t *xsb = (uint8_t *)kModulesStart;
495 int modsSize;
496 uint8_t *mods;
497 int index = 0;
498 int nameLen;
499 char *dot;
500
501 if (!xsb || !gHasMods) return NULL;
502
503 mods = findAtom(FOURCC('M', 'O', 'D', 'S'), xsb, c_read32be(xsb), &modsSize);
504 if (!mods) return NULL;
505
506 dot = c_strchr(name, '.');
507 if (dot)
508 nameLen = dot - name;
509 else
510 nameLen = c_strlen(name);
511
512 while (true) {
513 uint8_t *aName = findNthAtom(FOURCC('P', 'A', 'T', 'H'), ++index, mods, modsSize, NULL);
514 if (!aName)
515 break;
516 if (0 == c_strncmp(name, aName, nameLen)) {
517 if (0 == c_strcmp(".xsb", aName + nameLen))
518 return findNthAtom(FOURCC('C', 'O', 'D', 'E'), index, mods, modsSize, modSize);
519 }
520 }
521
522 return NULL;
523}
524#endif
525
526static txBoolean fxFindScript(txMachine* the, txSlot* realm, txString path, txID* id)

Callers 2

fxFindScriptFunction · 0.70
fxLoadModuleFunction · 0.70

Calls 1

findNthAtomFunction · 0.85

Tested by

no test coverage detected