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

Function spawn_program_word

internal/cbm/spawn_patterns.c:696–725  ·  view source on GitHub ↗

The program word of a command line: its first word that is not an * environment prefix, without directories. Anything built at run time is not * a program name. */

Source from the content-addressed store, hash-verified

694 * environment prefix, without directories. Anything built at run time is not
695 * a program name. */
696static void spawn_program_word(const char *literal, char *buf, size_t n) {
697 size_t len = 0;
698 for (;;) {
699 while (*literal == ' ' || *literal == '\t') {
700 literal++;
701 }
702 len = strcspn(literal, " \t\r\n");
703 if (!spawn_prefix_word(literal, len) || !literal[len]) {
704 break;
705 }
706 literal += len;
707 }
708 const char *start = literal;
709 for (size_t i = 0; i < len; i++) {
710 if (literal[i] == '/' || literal[i] == '\\') {
711 start = literal + i + 1;
712 }
713 }
714 len -= (size_t)(start - literal);
715 bool dynamic = len == 0 || len >= CBM_SPAWN_PROGRAM_MAX || len >= n;
716 for (size_t i = 0; i < len && !dynamic; i++) {
717 dynamic = strchr("$%{}`()<>|;&*?[]\"'", start[i]) != NULL;
718 }
719 if (dynamic) {
720 snprintf(buf, n, "%s", CBM_SPAWN_DYNAMIC);
721 return;
722 }
723 memcpy(buf, start, len);
724 buf[len] = '\0';
725}
726
727void cbm_spawn_program(const cbm_spawn_api_t *api, CBMLanguage lang, const CBMCall *call, char *buf,
728 size_t n) {

Callers 1

cbm_spawn_programFunction · 0.85

Calls 1

spawn_prefix_wordFunction · 0.85

Tested by

no test coverage detected