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

Function findMod

xs/platforms/gecko/xsHost.c:373–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371#define FOURCC(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
372
373static uint8_t *findMod(txMachine *the, char *name, int *modSize)
374{
375 uint8_t *xsb = (uint8_t *)kModulesStart;
376 int modsSize;
377 uint8_t *mods;
378 int index = 0;
379 int nameLen;
380 char *dot;
381
382 if (!xsb) return NULL;
383
384 mods = findAtom(FOURCC('M', 'O', 'D', 'S'), xsb, c_read32be(xsb), &modsSize);
385 if (!mods) return NULL;
386
387 dot = c_strchr(name, '.');
388 if (dot)
389 nameLen = dot - name;
390 else
391 nameLen = c_strlen(name);
392
393 while (true) {
394 uint8_t *aName = findNthAtom(FOURCC('P', 'A', 'T', 'H'), ++index, mods, modsSize, NULL);
395 if (!aName)
396 break;
397 if (0 == c_strncmp(name, aName, nameLen)) {
398 if (0 == c_strcmp(".xsb", aName + nameLen))
399 return findNthAtom(FOURCC('C', 'O', 'D', 'E'), index, mods, modsSize, modSize);
400 }
401 }
402
403 return NULL;
404}
405#endif
406
407txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)

Callers 2

fxFindModuleFunction · 0.70
fxLoadModuleFunction · 0.70

Calls 1

findNthAtomFunction · 0.85

Tested by

no test coverage detected