~emersion/mrsh

b73d3a4c2725da651efb408a2d78b9faabe7719c — Simon Ser 8 months ago 46a4cb4
shell/task/word: add parameter plus op
2 files changed, 10 insertions(+), 0 deletions(-)

M shell/task/word.c
M test/word.sh
M shell/task/word.c => shell/task/word.c +8 -0
@@ 162,8 162,16 @@ static int apply_parameter_op(struct mrsh_word_parameter *wp, const char *str,
		}
		return 0;
	case MRSH_PARAM_EQUAL: // Assign Default Values
		assert(false); // TODO
	case MRSH_PARAM_QMARK: // Indicate Error if Null or Unset
		assert(false); // TODO
	case MRSH_PARAM_PLUS: // Use Alternative Value
		if (str == NULL || (str[0] == '\0' && wp->colon)) {
			*result_str = strdup("");
		} else {
			assign_word_or_null(wp->arg, result_str, result_word);
		}
		return 0;
	case MRSH_PARAM_LEADING_HASH: // String Length
	case MRSH_PARAM_PERCENT: // Remove Smallest Suffix Pattern
	case MRSH_PARAM_DPERCENT: // Remove Largest Suffix Pattern

M test/word.sh => test/word.sh +2 -0
@@ 17,6 17,8 @@ echo $a ${b} ">$a<"
echo \$a '$a'
echo ${a:-BAD} ${idontexist:-GOOD} ${null:-GOOD} ${idontexist:-}
echo ${a-BAD} ${idontexist-GOOD} ${null-BAD} ${null-}
echo ${a:+GOOD} ${idontexist:+BAD} ${null:+BAD} ${idontexist:+}
echo ${a+GOOD} ${idontexist+BAD} ${null-GOOD} ${null+}
#echo ${#hello}

echo ""