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

Function fxFindModule

xs/platforms/mc/xsHosts.c:248–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246#endif
247
248txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
249{
250#if MODDEF_XS_TEST
251 char extension[5] = "";
252#endif
253 char name[C_PATH_MAX];
254 char buffer[C_PATH_MAX];
255 txInteger dot = 0;
256 txInteger i = 0;
257 txInteger hash = 0;
258 txString slash;
259 txString path;
260 txID id;
261 fxToStringBuffer(the, slot, name, sizeof(name));
262 if (name[0] == '.') {
263 if (name[1] == mxSeparator) {
264 dot = 1;
265 i = 1;
266 }
267 else if ((name[1] == '.') && (name[2] == mxSeparator)) {
268 dot = 2;
269 i = 2;
270 while ((name[i + 1] == '.') && (name[i + 2] == '.') && (name[i + 3] == mxSeparator)) {
271 dot++;
272 i += 3;
273 }
274 }
275 }
276 else if (name[0] == '#') {
277 hash = 1;
278 }
279 else if (c_strncmp(name, "moddable:", 9) == 0)
280 c_memmove(name, name + 9, c_strlen(name) - 8);
281
282 slash = c_strrchr(name, mxSeparator);
283 if (!slash)
284 slash = name;
285 slash = c_strrchr(slash, '.');
286 if (slash && (!c_strcmp(slash, ".js") || !c_strcmp(slash, ".mjs"))) {
287#if MODDEF_XS_TEST
288 c_strcpy(extension, slash);
289#endif
290 *slash = 0;
291 }
292 if (dot > 0) {
293 if (moduleID == XS_NO_ID)
294 return XS_NO_ID;
295 buffer[0] = mxSeparator;
296 path = buffer + 1;
297 c_strcpy(path, fxGetKeyName(the, moduleID));
298 slash = c_strrchr(buffer, mxSeparator);
299 if (!slash)
300 return XS_NO_ID;
301 *slash = 0;
302 dot--;
303 while (dot > 0) {
304 slash = c_strrchr(buffer, mxSeparator);
305 if (!slash)

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