Python relative import: ".foo", "..bar.baz" → resolve against source dir. */
| 244 | |
| 245 | /* Python relative import: ".foo", "..bar.baz" → resolve against source dir. */ |
| 246 | static char *resolve_python_relative(char *buf, size_t buf_size, const char *module_path) { |
| 247 | const char *p = module_path; |
| 248 | int dot_count = 0; |
| 249 | while (*p == '.') { |
| 250 | dot_count++; |
| 251 | p++; |
| 252 | } |
| 253 | for (int i = FQN_MIN_PY_DOTS; i < dot_count; i++) { |
| 254 | path_pop_segment(buf); |
| 255 | } |
| 256 | while (*p) { |
| 257 | const char *seg_start = p; |
| 258 | while (*p && *p != '.') { |
| 259 | p++; |
| 260 | } |
| 261 | size_t seg_len = (size_t)(p - seg_start); |
| 262 | if (seg_len > 0 && !path_append_segment(buf, buf_size, seg_start, seg_len)) { |
| 263 | return NULL; |
| 264 | } |
| 265 | if (*p == '.') { |
| 266 | p++; |
| 267 | } |
| 268 | } |
| 269 | return strdup(buf); |
| 270 | } |
| 271 | |
| 272 | /* Strip a trailing file extension from a segment (e.g. "helpers.ts" → "helpers"). |
| 273 | * Returns the new segment length. */ |
no test coverage detected