Skip to content

Commit d36d9cb

Browse files
committed
🔧 Use string manglers in scripts
1 parent 9e6981e commit d36d9cb

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

buildroot/bin/build_all_examples

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
6868
d|v) DEBUG=1 ; bugout "Debug ON" ;;
6969
n) DRYRUN=1 ; bugout "Dry Run" ;;
7070
p) PURGE=1 ; bugout "Purge stat file" ;;
71-
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
71+
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
7272
case "$ONAM" in
7373
archive) ARCHIVE=1 ; bugout "Archiving" ;;
7474
base) OPATH=${OVAL%/} ; bugout "Base: $OPATH" ;;
@@ -90,6 +90,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
9090
*) EXIT_USAGE=2 ; break ;;
9191
esac
9292
done
93+
shift $((OPTIND - 1))
9394

9495
# Check for mixed continue, skip, resume arguments. Only one should be used.
9596
((CONTINUE + CONTSKIP + ISRES + PURGE > 1)) && { echo "Don't mix -c, -p, -s, and -r options" ; echo ; EXIT_USAGE=2 ; }
@@ -154,7 +155,7 @@ CONF_TREE=$( ls -d "$OPATH"/config/examples/**/ | grep -vE ".+\.(\w+)$" )
154155
for CONF in $CONF_TREE ; do
155156

156157
# Get a config's directory name
157-
DIR=$( echo "$CONF" | "$SED" "s|$OPATH/config/examples/||" )
158+
DIR=${CONF#$OPATH/config/examples/}
158159

159160
# If looking for a config, skip others
160161
[[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue

buildroot/bin/build_example

+5-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ while getopts 'ab:c:e:fhio:r-:' OFLAG; do
5858
h) EXIT_USAGE=1 ; break ;;
5959
f) NOFAIL=1 ;;
6060
r) REVEAL=1 ;;
61-
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
61+
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
6262
case "$ONAM" in
6363
archive) ARCHIVE=1 ;;
6464
allow) ALLOW=1 ;;
@@ -75,6 +75,7 @@ while getopts 'ab:c:e:fhio:r-:' OFLAG; do
7575
*) EXIT_USAGE=2 ; break ;;
7676
esac
7777
done
78+
shift $((OPTIND - 1))
7879

7980
# Must be called from another script (or with --allow)
8081
[[ $ALLOW || $SHLVL -gt 2 ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; }
@@ -121,11 +122,9 @@ rm -f Marlin/Config.h Marlin/Config-export.h
121122

122123
set -e
123124

124-
# Strip #error lines from Configuration.h
125-
IFS=$'\n'; set -f
126-
$SED -i~ -e "20,30{/#error/d}" Marlin/Configuration.h
127-
rm Marlin/Configuration.h~
128-
unset IFS; set +f
125+
# Strip #error lines from Configuration.h using
126+
awk 'NR < 20 || NR > 30 || !/#error/' Marlin/Configuration.h > Marlin/Configuration.h~
127+
mv Marlin/Configuration.h~ Marlin/Configuration.h
129128

130129
# Hide several warnings when not exporting
131130
[[ -z $EXPNUM ]] && CLEANER=1

buildroot/bin/ci_src_filter

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
# exit on first failure
44
set -e
55

6-
SED=$(which gsed sed | head -n1)
76
FN="platformio.ini"
87

98
if [[ $1 == "-n" ]]; then
10-
"${SED}" -i "s/default_src_filter/org_src_filter/" $FN
11-
"${SED}" -i "/org_src_filter/ s/^/default_src_filter = +<src\/*>\n/" $FN
9+
awk '/default_src_filter/ { sub("default_src_filter", "org_src_filter"); print "default_src_filter = +<src/*>"; } 1' $FN > $FN~ && mv $FN~ $FN
1210
else
1311
git checkout $FN 2>/dev/null
1412
fi

buildroot/bin/mftest

+17-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ while getopts 'abdhmrsuvyn:t:-:' OFLAG; do
7474
u) AUTO_BUILD=2 ; bugout "Auto-Upload target..." ;;
7575
v) DEBUG=1 ; bugout "Debug ON" ;;
7676
y) BUILD_YES='Y' ; bugout "Build will initiate..." ;;
77-
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
77+
-) ONAM="${OPTARG%%=*}" ; OVAL="${OPTARG#*=}"
7878
case "$ONAM" in
7979
help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
8080
autobuild) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
@@ -107,6 +107,7 @@ debug|verbose) DEBUG=1 ; bugout "Debug ON" ;;
107107
*) EXIT_USAGE=2 ;;
108108
esac
109109
done
110+
shift $((OPTIND - 1))
110111

111112
((EXIT_USAGE)) && { usage ; let EXIT_USAGE-- ; exit $EXIT_USAGE ; }
112113

@@ -158,16 +159,21 @@ if ((AUTO_BUILD)); then
158159
*) SYS='uni' ;;
159160
esac
160161
echo ; echo -n "Auto " ; ((AUTO_BUILD == 2)) && echo "Upload..." || echo "Build..."
161-
MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h 2>/dev/null | awk '{ print $3 }' | $SED 's/BOARD_//;s/\r//' )
162-
[[ -z $MB ]] && {
163-
MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Config.h 2>/dev/null | awk '{ print $3 }' | $SED 's/BOARD_//;s/\r//' )
164-
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
165-
}
162+
163+
#
164+
# Get the MOTHERBOARD define value from the .h file and strip off the "BOARD_" prefix
165+
#
166+
ACODE='/[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]/ { sub(/^BOARD_/, "", $3); print $3 }'
167+
MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null)
168+
[[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null)
169+
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
170+
echo "Got $MB"
171+
exit
166172
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
167-
BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
168-
BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
173+
BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
174+
BDESC=$( sed -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
169175
[[ -z $BNUM ]] && { echo "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
170-
ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | $SED -E "s/(env|$SYS)://" ) )
176+
ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | sed -E "s/(env|$SYS)://" ) )
171177
[[ -z $ENVS ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
172178
ECOUNT=${#ENVS[*]}
173179

@@ -276,7 +282,7 @@ if [[ $CHOICE == 0 ]]; then
276282
while IFS= read -r LINE
277283
do
278284
if [[ $LINE =~ $ISEXEC ]]; then
279-
DESC=$( "$SED" -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
285+
DESC=$( sed -E 's/^exec_test \$1 \$2 "([^"]+)".*$/\1/g' <<<"$LINE" )
280286
(( ++IND < 10 )) && echo -n " "
281287
echo " $IND) $DESC"
282288
fi
@@ -321,7 +327,7 @@ echo "$OUT" | {
321327
((IND == CHOICE)) && {
322328
GOTX=1
323329
[[ -n $DL_DEFAULTS && $LINE =~ $ISRST ]] && LINE="use_example_configs"
324-
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' | $SED -E 's/ +/ /g' )
330+
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' | sed -E 's/ +/ /g' )
325331
[[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
326332
}
327333
fi

buildroot/share/git/mfprep

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ TMPF="$TMPDIR/tmp.txt"
3636
SCRF="$TMPDIR/update-$DEST.sh"
3737

3838
git checkout bugfix-2.1.x
39-
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | $SED '1!G;h;$!d' >"$LOGB"
39+
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | sed '1!G;h;$!d' >"$LOGB"
4040

4141
git checkout $DEST
42-
git log --pretty="[%h] %s" $TAG1..$TAG2 | $SED '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
42+
git log --pretty="[%h] %s" $TAG1..$TAG2 | sed '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
4343

4444
# Go through commit text from DEST removing all matches from the bugfix log
4545

@@ -57,7 +57,7 @@ cat "$LOG2" | while read line; do
5757
#echo "... $PATT"
5858
[[ -n "$PATT" ]] && { grep -vE "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
5959
else
60-
PATT=$( $SED -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
60+
PATT=$( sed -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
6161
[[ -n "$PATT" ]] && { grep -v "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
6262
fi
6363
done

0 commit comments

Comments
 (0)