A program started by a path (./_build/x, ${DIR}/x, $(LOCALBIN)/x) SPAWNS * the Process of its name -- the value's last segment, or, the value * unknown, the word's literal last segment. A path naming a file of the * repository is a script (sh_spawn_script), not a Process. */
| 1996 | * unknown, the word's literal last segment. A path naming a file of the |
| 1997 | * repository is a script (sh_spawn_script), not a Process. */ |
| 1998 | static void sh_spawn(sh_t *s, TSNode cmd, const sh_argv_t *a) { |
| 1999 | int p = sh_program(s, a); |
| 2000 | if (p < 0) { |
| 2001 | return; |
| 2002 | } |
| 2003 | const char *v = a->v[p]; |
| 2004 | const char *name = NULL; |
| 2005 | if (v) { |
| 2006 | if (sh_in(sh_basename(v), SH_MAKES)) { |
| 2007 | sh_make(s, cmd, a, p); |
| 2008 | } |
| 2009 | sh_spawn_script(s, cmd, a, p); |
| 2010 | if (!strchr(v, '/') || strpbrk(v, "*?[")) { |
| 2011 | return; |
| 2012 | } |
| 2013 | const char *c[PAIR_LEN] = {NULL, NULL}; |
| 2014 | int n = sh_candidates(s, v, c); |
| 2015 | for (int i = 0; i < n; i++) { |
| 2016 | if (sh_repo_file_id(s, c[i]) > 0) { |
| 2017 | return; |
| 2018 | } |
| 2019 | } |
| 2020 | name = sh_value_basename(s->a, v); |
| 2021 | } else { |
| 2022 | uint32_t b = a->span[PAIR_LEN * p]; |
| 2023 | uint32_t e = a->span[PAIR_LEN * p + SKIP_ONE]; |
| 2024 | while (e > b && (s->src[e - SKIP_ONE] == '"' || s->src[e - SKIP_ONE] == '\'')) { |
| 2025 | e--; |
| 2026 | } |
| 2027 | uint32_t k = e; |
| 2028 | while (k > b && s->src[k - SKIP_ONE] != '/') { |
| 2029 | k--; |
| 2030 | } |
| 2031 | if (k == b) { |
| 2032 | return; |
| 2033 | } |
| 2034 | name = cbm_arena_strndup(s->a, s->src + k, e - k); |
| 2035 | if (name && strpbrk(name, "$`*?[]{}()\"' \t\\")) { |
| 2036 | return; |
| 2037 | } |
| 2038 | } |
| 2039 | if (!name || !name[0] || strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { |
| 2040 | return; |
| 2041 | } |
| 2042 | sh_hit_push(s, cmd, (sh_hit_t){.via = s->exec ? "exec" : "shell", .ext = name, .spawn = true}); |
| 2043 | } |
| 2044 | |
| 2045 | /* ── HTTP requests (F3) ─────────────────────────────────────────────── */ |
| 2046 |
no test coverage detected