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

Function fxFindModule

xs/platforms/qca4020/xsHost.c:552–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
553{
554 txPreparation* preparation = the->preparation;
555 char name[PATH_MAX];
556 char path[PATH_MAX];
557 txBoolean absolute = 0, relative = 0, search = 0;
558 txInteger dot = 0;
559 txString slash;
560 txID id;
561
562 fxToStringBuffer(the, slot, name, sizeof(name));
563// #if MODDEF_XS_MODS
564// if (findMod(the, name, NULL)) {
565// c_strcpy(path, "/");
566// c_strcat(path, name);
567// c_strcat(path, ".xsb");
568// return fxNewNameC(the, path);
569// }
570// #endif
571//
572 if (!c_strncmp(name, "/", 1)) {
573 absolute = 1;
574 }
575 else if (!c_strncmp(name, "./", 2)) {
576 dot = 1;
577 relative = 1;
578 }
579 else if (!c_strncmp(name, "../", 3)) {
580 dot = 2;
581 relative = 1;
582 }
583 else {
584 relative = 1;
585 search = 1;
586 }
587 if (absolute) {
588 c_strcpy(path, preparation->base);
589 c_strcat(path, name + 1);
590 if (fxFindScript(the, realm, path, &id))
591 return id;
592 }
593 if (relative && (moduleID != XS_NO_ID)) {
594 c_strcpy(path, fxGetKeyName(the, moduleID));
595 slash = c_strrchr(path, '/');
596 if (!slash)
597 return XS_NO_ID;
598 if (dot == 0)
599 slash++;
600 else if (dot == 2) {
601 *slash = 0;
602 slash = c_strrchr(path, '/');
603 if (!slash)
604 return XS_NO_ID;
605 }
606 if (!c_strncmp(path, preparation->base, preparation->baseLength)) {
607 *slash = 0;
608 c_strcat(path, name + dot);
609 if (fxFindScript(the, realm, path, &id))

Callers

nothing calls this directly

Calls 4

fxToStringBufferFunction · 0.85
fxGetKeyNameFunction · 0.85
fxNewNameCFunction · 0.85
fxFindScriptFunction · 0.70

Tested by

no test coverage detected