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

Function mk_reference

src/pipeline/pass_shell.c:2970–2998  ·  view source on GitHub ↗

$(NAME) / ${NAME} / $(shell pwd) / $(abspath X): its expansion. */

Source from the content-addressed store, hash-verified

2968
2969/* $(NAME) / ${NAME} / $(shell pwd) / $(abspath X): its expansion. */
2970static const char *mk_reference(mk_t *m, const char *ref) {
2971 static const char *const pwd[] = {"pwd", NULL};
2972 static const char *const pwd_p[] = {"pwd", "-P", NULL};
2973 static const char *const toplevel[] = {"git", "rev-parse", "--show-toplevel", NULL};
2974 size_t rl = strcspn(ref, " \t");
2975 if (!ref[rl]) {
2976 return mk_lookup(m, ref);
2977 }
2978 const char *fn = cbm_arena_strndup(m->a, ref, rl);
2979 const char *arg = mk_trim(m->a, ref + rl, strlen(ref + rl));
2980 if (!fn || !arg) {
2981 return MK_UNKNOWN;
2982 }
2983 if (strcmp(fn, "shell") == 0) {
2984 const char *cmd = mk_expand(m, arg);
2985 if (cmd && (mk_words(cmd, pwd) || mk_words(cmd, pwd_p))) {
2986 return m->makefile ? "${__cbm_curdir}" : MK_UNKNOWN;
2987 }
2988 if (cmd && mk_words(cmd, toplevel)) {
2989 return "${__cbm_root}";
2990 }
2991 return MK_UNKNOWN;
2992 }
2993 if (strcmp(fn, "abspath") == 0 || strcmp(fn, "realpath") == 0) {
2994 const char *v = mk_expand(m, arg);
2995 return v && !strchr(v, ' ') ? v : MK_UNKNOWN;
2996 }
2997 return MK_UNKNOWN;
2998}
2999
3000/* Make's expansion of `text`: references replaced, $$ -> $, what is not
3001 * known -> a shell variable no line sets. */

Callers 1

mk_expandFunction · 0.85

Calls 5

mk_lookupFunction · 0.85
mk_trimFunction · 0.85
mk_expandFunction · 0.85
mk_wordsFunction · 0.85
cbm_arena_strndupFunction · 0.50

Tested by

no test coverage detected