void xs_dbg_setBreakpoint(xsMachine *the) { #if mxDebug char num[13]; xsToStringBuffer(xsArg(1), num, sizeof(num)); fxSetBreakpoint(the, xsToString(xsArg(0)), num); #endif }
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; }
void Grammar_nameToID(xsMachine* the) { char buffer[1024]; xsIntegerValue id; xsToStringBuffer(xsArg(0), buffer, sizeof(buffer)); if (buffer[0] == '*') id = 0; else if (buffer[0] == '@') id = -1; else id = xsID(buffer); xsResult = xsInteger(id); }
void xsToolListDirectory(xsMachine* the) { #if mxWindows xsStringValue path, name = NULL; UINT32 length, index; UINT16 *pathW = NULL; HANDLE findHandle = INVALID_HANDLE_VALUE; WIN32_FIND_DATAW findData; xsTry { xsVars(1); xsResult = xsNewInstanceOf(xsArrayPrototype); path = xsToString(xsArg(0)); length = strlen(path); pathW = malloc((length + 3) * 2); xsElseError(pathW); MultiByteToWideChar(CP_UTF8, 0, path, length + 1, pathW, length + 1); for (index = 0; index < length; index++) { if (pathW[index] == '/') pathW[index] = '\\'; } pathW[length] = '\\'; pathW[length + 1] = '*'; pathW[length + 2] = 0; findHandle = FindFirstFileW(pathW, &findData); if (findHandle != INVALID_HANDLE_VALUE) { do { if ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || !wcscmp(findData.cFileName, L".") || !wcscmp(findData.cFileName, L"..")) continue; length = wcslen(findData.cFileName); name = malloc((length + 1) * 2); xsElseError(name); WideCharToMultiByte(CP_UTF8, 0, findData.cFileName, length + 1, name, length + 1, NULL, NULL); xsVar(0) = xsNewInstanceOf(xsObjectPrototype); xsSet(xsVar(0), xsID("name"), xsString(name)); if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) xsSet(xsVar(0), xsID("directory"), xsTrue); else xsSet(xsVar(0), xsID("directory"), xsFalse); xsCall1(xsResult, xsID("push"), xsVar(0)); free(name); name = NULL; } while (FindNextFileW(findHandle, &findData)); } } xsCatch { } if (name) free(name); if (findHandle != INVALID_HANDLE_VALUE) FindClose(findHandle); if (pathW) free(pathW); #else DIR* dir; char path[1024]; int length; xsVars(1); xsResult = xsNewInstanceOf(xsArrayPrototype); dir = opendir(xsToStringBuffer(xsArg(0), path, sizeof(path) - 1)); length = strlen(path); path[length] = '/'; length++; if (dir) { struct dirent *ent; while ((ent = readdir(dir))) { struct stat a_stat; if (ent->d_name[0] == '.') continue; strcpy(path + length, ent->d_name); if (!stat(path, &a_stat)) { xsVar(0) = xsNewInstanceOf(xsObjectPrototype); xsSet(xsVar(0), xsID("name"), xsString(ent->d_name)); if (S_ISDIR(a_stat.st_mode)) xsSet(xsVar(0), xsID("directory"), xsTrue); else xsSet(xsVar(0), xsID("directory"), xsFalse); (void)xsCall1(xsResult, xsID("push"), xsVar(0)); } } closedir(dir); } #endif }