Fix remaining two code-review findings, both verified live: 30-selfdiag.sh regex-metachar breakage (g++), fx.sh dedup collision on ] in candidate text
This commit is contained in:
+8
-2
@@ -79,11 +79,17 @@ fx() {
|
|||||||
out=$("$src" "$cmd" 2>/dev/null)
|
out=$("$src" "$cmd" 2>/dev/null)
|
||||||
if [ -n "$out" ]; then
|
if [ -n "$out" ]; then
|
||||||
printf '%s\n' "$out" | while IFS= read -r line; do
|
printf '%s\n' "$out" | while IFS= read -r line; do
|
||||||
[ -n "$line" ] && printf '[%s] %s\n' "$label" "$line"
|
[ -n "$line" ] && printf '%s\t%s\n' "$label" "$line"
|
||||||
done
|
done
|
||||||
[ -n "$FX_AUTO" ] && break
|
[ -n "$FX_AUTO" ] && break
|
||||||
fi
|
fi
|
||||||
done | awk -F'] ' '!seen[$2]++'
|
done | awk -F'\t' '
|
||||||
|
{
|
||||||
|
label = $1
|
||||||
|
text = substr($0, length(label) + 2)
|
||||||
|
if (!seen[text]++) print "[" label "] " text
|
||||||
|
}
|
||||||
|
'
|
||||||
)
|
)
|
||||||
|
|
||||||
chosen=""
|
chosen=""
|
||||||
|
|||||||
@@ -21,8 +21,19 @@ cmd="$1"
|
|||||||
prog=$(printf '%s' "$cmd" | awk '{print $1}')
|
prog=$(printf '%s' "$cmd" | awk '{print $1}')
|
||||||
[ -n "$prog" ] || exit 0
|
[ -n "$prog" ] || exit 0
|
||||||
[ -n "$FX_OUTPUT" ] || exit 0
|
[ -n "$FX_OUTPUT" ] || exit 0
|
||||||
printf '%s\n' "$FX_OUTPUT" | grep -qE "^[[:space:]]*${prog}[[:space:]]" || exit 0
|
|
||||||
|
# Literal prefix comparison (substr/index), never a regex built from
|
||||||
|
# $prog: proven broken live for program names containing ERE
|
||||||
|
# metacharacters -- e.g. "g++ foo.cpp" produced the pattern
|
||||||
|
# "^[[:space:]]*g++[[:space:]]", a malformed stacked-quantifier regex,
|
||||||
|
# and this source silently found nothing even when $FX_OUTPUT clearly
|
||||||
|
# started a line with "g++ ". Same fix applied to the emitted function
|
||||||
|
# below, since it runs the identical check on every future call.
|
||||||
|
printf '%s\n' "$FX_OUTPUT" | awk -v p="$prog" '
|
||||||
|
{ line = $0; sub(/^[ \t]*/, "", line); if (substr(line, 1, length(p) + 1) == p " ") { found = 1; exit } }
|
||||||
|
END { exit !found }
|
||||||
|
' || exit 0
|
||||||
|
|
||||||
cat <<FIX
|
cat <<FIX
|
||||||
${prog}(){ out=\$(command ${prog} "\$@" 2>&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk '/^[ \\t]*${prog}[ \\t]/{sub(/^[ \\t]*/,""); s=\$0} END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; }
|
${prog}(){ out=\$(command ${prog} "\$@" 2>&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk -v p="${prog}" '{ line=\$0; sub(/^[ \\t]*/,"",line); if (substr(line,1,length(p)+1)==p" ") s=line } END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; }
|
||||||
FIX
|
FIX
|
||||||
|
|||||||
Reference in New Issue
Block a user