#!/usr/bin/env bash # exit on first failure set -e # Get SED_CMD, SED_I, and the BSDSED flag . $(dirname $0)/opt_sed for opt in "$@" ; do DID=0 ; FOUND=0 for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do if [[ $BSDSED ]]; then # BSD sed version (macOS) "${SED_CMD}" "${SED_I[@]}" \ "/^[[:space:]]*\/\/[[:space:]]*#define[[:space:]]+${opt}\b/{ s/^[[:space:]]*\/\/[[:space:]]*\(#define[[:space:]]+${opt}\b\)[[:space:]]*/\1 / h \$b end } \$!b :end x /./{ x; q0; } x q1" \ $FN && DID=1 else # GNU sed version "${SED_CMD}" "${SED_I[@]}" \ "/^\(\s*\)\/\/\(\s*\)\(#define\s\+${opt}\b\)\( \?\)/{s//\1\2\3\4\4\4/;h};\${x;/./{x;q0};x;q1}" \ $FN && DID=1 fi ((DID||FOUND)) || { grep -E "^\s*#define\s+${opt}\b" $FN >/dev/null && FOUND=1 ; } done ((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9) done