| 137 | } |
| 138 | |
| 139 | void PiuCodeSearchDirectory(xsMachine* the, KprCodeSearch self) |
| 140 | { |
| 141 | #if mxLinux |
| 142 | char* path = self->path; |
| 143 | char* former = path + strlen(path); |
| 144 | GDir* iterator = g_dir_open(path, 0, NULL); |
| 145 | if (iterator) { |
| 146 | char* name; |
| 147 | *former = '/'; |
| 148 | while ((name = (xsStringValue)g_dir_read_name(iterator))) { |
| 149 | struct stat _stat; |
| 150 | strcpy(former + 1, name); |
| 151 | if (stat(path, &_stat) == 0) { |
| 152 | if (S_ISDIR(_stat.st_mode)) { |
| 153 | PiuCodeSearchDirectory(the, self); |
| 154 | } |
| 155 | else { |
| 156 | char* dot = strrchr(name, '.'); |
| 157 | if (dot && (!strcmp(dot, ".js") || !strcmp(dot, ".ts"))) { |
| 158 | int fd = open(path, O_RDONLY); |
| 159 | if (fd >= 0) { |
| 160 | xsStringValue string = mmap(NULL, _stat.st_size, PROT_READ, MAP_SHARED, fd, 0); |
| 161 | if (string != MAP_FAILED) { |
| 162 | xsVar(XS_FILE) = xsUndefined; |
| 163 | xsVar(XS_NAME) = xsString(name); |
| 164 | xsVar(XS_PATH) = xsString(path); |
| 165 | PiuCodeSearchData(the, self, string, _stat.st_size); |
| 166 | munmap(string, _stat.st_size); |
| 167 | } |
| 168 | close(fd); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | *former = 0; |
| 175 | } |
| 176 | #endif |
| 177 | #if mxMacOSX |
| 178 | CFStringRef basePath = CFStringCreateWithCString(NULL, xsToString(xsVar(XS_PATH)), kCFStringEncodingUTF8); |
| 179 | CFURLRef baseURL = CFURLCreateWithFileSystemPath(NULL, basePath, kCFURLPOSIXPathStyle, true); |
| 180 | CFURLEnumeratorRef enumerator = CFURLEnumeratorCreateForDirectoryURL(NULL, baseURL, kCFURLEnumeratorDescendRecursively | kCFURLEnumeratorSkipInvisibles, NULL); |
| 181 | CFURLRef fileURL; |
| 182 | while (CFURLEnumeratorGetNextURL(enumerator, &fileURL, NULL) == kCFURLEnumeratorSuccess) { |
| 183 | CFStringRef path = CFURLCopyFileSystemPath(fileURL, kCFURLPOSIXPathStyle); |
| 184 | CFStringRef name = CFURLCopyLastPathComponent(fileURL); |
| 185 | if (CFStringHasSuffix(name, CFSTR(".js")) || CFStringHasSuffix(name, CFSTR(".ts"))) { |
| 186 | char PATH[1024]; |
| 187 | char NAME[1024]; |
| 188 | if (CFStringGetCString(path, PATH, sizeof(PATH), kCFStringEncodingUTF8) && CFStringGetCString(name, NAME, sizeof(NAME), kCFStringEncodingUTF8)) { |
| 189 | int fd = open(PATH, O_RDONLY); |
| 190 | if (fd >= 0) { |
| 191 | struct stat statbuf; |
| 192 | xsIntegerValue size; |
| 193 | fstat(fd, &statbuf); |
| 194 | size = statbuf.st_size; |
| 195 | if (size > 0) { |
| 196 | xsStringValue string = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
no test coverage detected