Exemple #1
0
xsIndex fxFindModuleKPR(xsMachine* the, xsIndex moduleID, xsSlot* slot)
{
	char name[1024];
	xsBooleanValue absolute, relative;
	xsStringValue dot, slash;
	xsIndex id;
	
	xsToStringBuffer(*slot, name, sizeof(name));
	if ((!FskStrCompareWithLength(name, "./", 2)) || (!FskStrCompareWithLength(name, "../", 3))) {
		absolute = 0;
		relative = (moduleID == XS_NO_ID) ? 0 : 1;
	}
	else if ((!FskStrCompareWithLength(name, "/", 1))) {
		FskMemMove(name, name + 1, FskStrLen(name));
		absolute = 1;
		relative = 0;
	}
	else {
		absolute = 1;
		relative = (moduleID == XS_NO_ID) ? 0 : 1;
	}
	slash = FskStrRChr(name, '/');
	if (!slash)
		slash = name;
	dot = FskStrRChr(slash, '.');
	if (dot) {
		xsBooleanValue known = 0;
		xsStringValue* extension;
		for (extension = gxExtensions; *extension; extension++) {
			if (!FskStrCompare(dot, *extension)) {
				known = 1;
				break;
			}
		}
		if (!known)
			dot = NULL;
	}
	if (!dot)
		dot = name + FskStrLen(name);
	if (relative) {
		if (fxFindURI(the, xsName(moduleID), name, dot, &id))
			return id;
	}
	if (absolute) {
		xsStringValue* bases = gModulesBases;
		UInt32 c = gModulesBasesCount;
		UInt32 i = 1;
		while (i < c) {
			if (fxFindURI(the, bases[i], name, dot, &id))
				return id;
			i++;
		}
	}
	return XS_NO_ID;
}
Exemple #2
0
txID fxFindModule(txMachine* the, txID moduleID, txSlot* slot)
{
	char name[PATH_MAX];
	char base[PATH_MAX];
	txBoolean absolute, relative, search;
	txSlot *key, *iterator, *result;
	txString dot, slash;
	txID id;
	
	fxToStringBuffer(the, slot, name, sizeof(name));
	if ((!c_strncmp(name, "./", 2)) || (!c_strncmp(name, "../", 3))) {
		absolute = 0;
		relative = (moduleID == XS_NO_ID) ? 0 : 1;
		search = 0;
	}
	else if ((!c_strncmp(name, "/", 1))) {
		absolute = 1;
		relative = 0;
		search = 0;
	}
	else {
		absolute = 0;
		relative = (moduleID == XS_NO_ID) ? 0 : 1;
		search = 1;
	}
	slash = c_strrchr(name, '/');
	if (!slash)
		slash = name;
	dot = c_strrchr(slash, '.');
	if (!dot)
		dot = name + c_strlen(name);
	
	if (absolute) {
		if (fxFindURI(the, "", name, dot, &id))
			return id;
	}
	if (relative) {
		key = fxGetKey(the, moduleID);
  		c_strcpy(base, key->value.key.string);
		if (fxFindURI(the, base, name, dot, &id))
			return id;
	}
	if (search) {
		mxCallID(&mxModulePaths, mxID(_Symbol_iterator), 0);
		iterator = the->stack;
		for (;;) {
			mxCallID(iterator, mxID(_next), 0);
			result = the->stack;
			mxGetID(result, mxID(_done));
			if (fxToBoolean(the, the->stack))
				break;
			the->stack++;
			mxGetID(result, mxID(_value));
			fxToStringBuffer(the, the->stack++, base, sizeof(base));
			if (fxFindURI(the, base, name, dot, &id))
				return id;
		}
	}
	mxReferenceError("module \"%s\" not found", name);
	return XS_NO_ID;
}