| 1437 | } |
| 1438 | |
| 1439 | static char *dk_read(const char *path, size_t *len) { |
| 1440 | FILE *f = cbm_fopen(path, "rb"); |
| 1441 | if (!f) { |
| 1442 | return NULL; |
| 1443 | } |
| 1444 | (void)fseek(f, 0, SEEK_END); |
| 1445 | long size = ftell(f); |
| 1446 | (void)fseek(f, 0, SEEK_SET); |
| 1447 | if (size <= 0 || size > cbm_max_file_bytes()) { |
| 1448 | (void)fclose(f); |
| 1449 | return NULL; |
| 1450 | } |
| 1451 | enum { DK_TS_PAD = 16 }; /* tree-sitter's lexer reads past the end */ |
| 1452 | char *buf = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)size + DK_TS_PAD); |
| 1453 | if (!buf) { |
| 1454 | (void)fclose(f); |
| 1455 | return NULL; |
| 1456 | } |
| 1457 | size_t got = fread(buf, SKIP_ONE, (size_t)size, f); |
| 1458 | (void)fclose(f); |
| 1459 | memset(buf + got, 0, DK_TS_PAD); |
| 1460 | *len = got; |
| 1461 | return buf; |
| 1462 | } |
| 1463 | |
| 1464 | /* Does the line [b, e) hold a parser directive `# escape=...`? */ |
| 1465 | static bool dk_escape_directive(const char *s, size_t b, size_t e) { |
no test coverage detected