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

Function fxFindModule

xs/platforms/gecko/xsHost.c:407–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405#endif
406
407txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
408{
409 txPreparation* preparation = the->preparation;
410 char name[128];
411 char path[128];
412 txBoolean absolute = 0, relative = 0, search = 0;
413 txInteger dot = 0;
414 txString slash;
415 txID id;
416
417 fxToStringBuffer(the, slot, name, sizeof(name));
418#if MODDEF_XS_MODS
419 if (findMod(the, name, NULL)) {
420 c_strcpy(path, "/");
421 c_strcat(path, name);
422 c_strcat(path, ".xsb");
423 return fxNewNameC(the, path);
424 }
425#endif
426
427 if (!c_strncmp(name, "/", 1)) {
428 absolute = 1;
429 }
430 else if (!c_strncmp(name, "./", 2)) {
431 dot = 1;
432 relative = 1;
433 }
434 else if (!c_strncmp(name, "../", 3)) {
435 dot = 2;
436 relative = 1;
437 }
438 else {
439 relative = 1;
440 search = 1;
441 }
442 if (absolute) {
443 c_strcpy(path, preparation->base);
444 c_strcat(path, name + 1);
445 if (fxFindScript(the, path, &id))
446 return id;
447 }
448 if (relative && (moduleID != XS_NO_ID)) {
449 c_strcpy(path, fxGetKeyName(the, moduleID));
450 slash = c_strrchr(path, '/');
451 if (!slash)
452 return XS_NO_ID;
453 if (dot == 0)
454 slash++;
455 else if (dot == 2) {
456 *slash = 0;
457 slash = c_strrchr(path, '/');
458 if (!slash)
459 return XS_NO_ID;
460 }
461 if (!c_strncmp(path, preparation->base, preparation->baseLength)) {
462 *slash = 0;
463 c_strcat(path, name + dot);
464 if (fxFindScript(the, path, &id))

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected