MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sphinx_parse

Function sphinx_parse

src/discover/discover.c:985–1043  ·  view source on GitHub ↗

`source_suffix = '.txt'`, `= ['.rst', '.txt']` or * `= {'.rst': 'restructuredtext', '.txt': 'restructuredtext'}` (a dict * entry counts only when it maps to restructuredtext). */

Source from the content-addressed store, hash-verified

983 * `= {'.rst': 'restructuredtext', '.txt': 'restructuredtext'}` (a dict
984 * entry counts only when it maps to restructuredtext). */
985static void sphinx_parse(const char *s, size_t n, sphinx_suffixes_t *out) {
986 static const char key[] = "source_suffix";
987 size_t kl = strlen(key);
988 for (size_t line = 0; line < n;) {
989 const char *nl = memchr(s + line, '\n', n - line);
990 size_t end = nl ? (size_t)(nl - s) : n;
991 size_t i = line + kl;
992 if (end >= i && memcmp(s + line, key, kl) == 0) {
993 while (i < n && (s[i] == ' ' || s[i] == '\t')) {
994 i++;
995 }
996 if (i < n && s[i] == '=') {
997 i++;
998 while (i < n && (s[i] == ' ' || s[i] == '\t')) {
999 i++;
1000 }
1001 char open = i < n ? s[i] : '\0';
1002 char close = '\0';
1003 if (open == '[' || open == '(' || open == '{') {
1004 close = open == '[' ? ']' : (open == '(' ? ')' : '}');
1005 }
1006 /* the value: up to its closing bracket, or this line */
1007 size_t stop = end;
1008 if (close) {
1009 const char *c = memchr(s + i, close, n - i);
1010 stop = c ? (size_t)(c - s) : end;
1011 }
1012 size_t k = i;
1013 while (k < stop) {
1014 size_t a;
1015 size_t b;
1016 if (!sphinx_quoted(s, stop, k, &a, &b)) {
1017 k++;
1018 continue;
1019 }
1020 k = b + SKIP_ONE;
1021 if (open != '{') {
1022 sphinx_add(out, s + a, b - a);
1023 continue;
1024 }
1025 while (k < stop && (s[k] == ' ' || s[k] == ':')) {
1026 k++;
1027 }
1028 size_t va;
1029 size_t vb;
1030 if (sphinx_quoted(s, stop, k, &va, &vb)) {
1031 if (vb - va == strlen("restructuredtext") &&
1032 memcmp(s + va, "restructuredtext", vb - va) == 0) {
1033 sphinx_add(out, s + a, b - a);
1034 }
1035 k = vb + SKIP_ONE;
1036 }
1037 }
1038 return; /* the first assignment */
1039 }
1040 }
1041 line = end + SKIP_ONE;
1042 }

Callers 1

sphinx_loadFunction · 0.85

Calls 2

sphinx_quotedFunction · 0.85
sphinx_addFunction · 0.85

Tested by

no test coverage detected