1 minish-eval is now a separate program.
2 It needs more testing and a little refactoring, but I have it made.
4 If the open parenthesis follows a non-null character,
5 the first word of the command substitution concatenates with
6 the one the precedes the parenthesis.
7 In “a(cmd)d”, if “cmd” outputs “b␀c”,
8 the final command executed is “ab␀cd”.
9 If the word that precedes the open parenthesis is from argv,
10 it cannot be realloc()ated,
11 because it was not allocated with malloc():
12 the first word of the output is realloc()ated instead,
13 its content is moved to the right,
14 and the word that precedes it is copied in.
15 But if there are two command substitutions in a row,
16 then the left one can be realloc()ated,
17 because it is not originally from argv anymore.
18 So we realloc()ate it,
19 copy the first word of the output of the command substitution in it,
20 and the free the copied word,
21 because we words returned by getdelim() are allocated with malloc().
23 There is a similar problem
24 with the last word of the output of command substitution.
26 There is an even bigger problem when the command substitution
28 because the following word cannot be realloc()ated
29 and the preceding one may or may not,
30 depending on the previous command substitutions.
31 If we cannot use realloc(),
32 we use malloc() and copy both of the strings.
34 For the aforementioned operations,
35 I use a global variable named can_realloc.
40 https://en.wikipedia.org/wiki/Worse_is_better