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

Function PiuCode_search

tools/xsbug/SearchService.c:84–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82static void PiuCodeSearchData(xsMachine* the, KprCodeSearch self, xsStringValue data, xsIntegerValue size);
83
84void PiuCode_search(xsMachine* the)
85{
86 KprCodeSearchRecord searchRecord;
87 KprCodeSearch self = &searchRecord;
88 xsStringValue pattern = xsToString(xsArg(0));
89 xsBooleanValue caseless = xsToBoolean(xsArg(1));
90 xsStringValue modifier = (caseless) ? "imu" : "mu";
91 int c, i;
92 xsVars(XS_COUNT);
93 xsTry {
94 c_memset(self, 0, sizeof(KprCodeSearchRecord));
95 xsResult = xsNewArray(0);
96 xsVar(XS_MAP) = xsNew0(xsGlobal, xsID_Map);
97 xsSet(xsGlobal, xsID("search/results"), xsVar(XS_MAP));
98 if (!fxCompileRegExp(NULL, pattern, modifier, &self->code, &self->data, NULL, 0))
99 xsUnknownError("invalid regexp");
100 c = xsToInteger(xsGet(xsArg(2), xsID_length));
101 for (i = 0; i < c; i++) {
102 // if (!KprMessageContinue(self->message))
103 // break;
104 xsVar(XS_DIRECTORY) = xsGetIndex(xsArg(2), i);
105 xsVar(XS_PATH) = xsGet(xsVar(XS_DIRECTORY), xsID_path);
106 xsVar(XS_TITLE) = xsGet(xsVar(XS_DIRECTORY), xsID_name);
107 #if mxLinux
108 xsToStringBuffer(xsVar(XS_PATH), self->path, sizeof(self->path));
109 #endif
110 #if mxWindows
111 xsToStringBufferW(xsVar(XS_PATH), self->path, sizeof(self->path));
112 #endif
113 PiuCodeSearchDirectory(the, self);
114 }
115 if (self->total > 100) {
116 c = xsToInteger(xsGet(xsResult, xsID_length));
117 for (i = 0; i < c; i++) {
118 // if (!KprMessageContinue(self->message))
119 // break;
120 xsVar(XS_FILE) = xsGetIndex(xsResult, i);
121 xsSet(xsVar(XS_FILE), xsID_expanded, xsFalse);
122 xsSet(xsVar(XS_FILE), xsID_items, xsNull);
123 }
124 }
125 }
126 xsCatch {
127 }
128 fxDeleteRegExp(NULL, self->code, self->data);
129}
130
131void PiuCode_searchResults(xsMachine* the)
132{

Callers

nothing calls this directly

Calls 3

fxCompileRegExpFunction · 0.85
PiuCodeSearchDirectoryFunction · 0.85
fxDeleteRegExpFunction · 0.85

Tested by

no test coverage detected