The documentation set this directory starts, if it has a conf.py. */
| 1044 | |
| 1045 | /* The documentation set this directory starts, if it has a conf.py. */ |
| 1046 | static bool sphinx_load(const char *dir, sphinx_suffixes_t *out) { |
| 1047 | char conf[CBM_SZ_4K]; |
| 1048 | if (snprintf(conf, sizeof(conf), "%s/conf.py", dir) >= (int)sizeof(conf)) { |
| 1049 | return false; |
| 1050 | } |
| 1051 | struct stat st; |
| 1052 | if (wide_stat(conf, &st) != 0 || !S_ISREG(st.st_mode)) { |
| 1053 | return false; |
| 1054 | } |
| 1055 | FILE *f = cbm_fopen(conf, "rb"); |
| 1056 | if (!f) { |
| 1057 | return false; |
| 1058 | } |
| 1059 | char *buf = (char *)cbm_alloc(CBM_MEM_CLASS_OTHER, SPHINX_CONF_READ); |
| 1060 | size_t n = buf ? fread(buf, SKIP_ONE, SPHINX_CONF_READ, f) : 0; |
| 1061 | (void)fclose(f); |
| 1062 | memset(out, 0, sizeof(*out)); |
| 1063 | if (buf) { |
| 1064 | sphinx_parse(buf, n, out); |
| 1065 | } |
| 1066 | cbm_free(CBM_MEM_CLASS_OTHER, buf); |
| 1067 | return true; |
| 1068 | } |
| 1069 | |
| 1070 | static bool sphinx_is_rst(const sphinx_suffixes_t *set, const char *name) { |
| 1071 | size_t nl = strlen(name); |