On Wed, Jul 27, 2022 at 06:47:56AM -0700, Andrew Hewus Fresh wrote:
> On Wed, Jul 27, 2022 at 11:06:39AM +0200, Alexander Hall wrote:
> > I think replacing '*' with '*([![:cntrl:]])' can be the droid your looking
> > for.
>
> As I was falling asleep last night I was trying to figure out how to get
> '*([!$_nl])' into the match and couldn't think of a good one. Your
> solution is much better.
Except for that issue with ksh patterns inside a variable.
I had some time to think about this while doing some construction.
Finally had time to try to implement it and it seems like although it's
a bit ugly, it is performant and seems to allow me to use "^cpu0:*Intel"
in the patterns file and (I believe) just match a line that starts with
cpu0: and contains Intel.
My alpha agrees with the speed assessment, the current implementation
that doesn't support the "*" in the patterns runs at about 5.5 seconds
(as before), while this new version takes 6.5 seconds. That's a lot
better than the 17.5 seconds it took to match against each line (and
still didn't actually expand the *).
Index: fw_update.sh
===================================================================
RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
retrieving revision 1.42
diff -u -p -r1.42 fw_update.sh
--- fw_update.sh 20 Feb 2022 21:53:04 -0000 1.42
+++ fw_update.sh 3 Aug 2022 01:11:53 -0000
@@ -168,21 +168,32 @@ verify() {
}
firmware_in_dmesg() {
- local _d _m _line _dmesgtail _last='' _nl=$( echo )
+ local IFS
+ local _d _m _dmesgtail _last='' _nl='
+'
# The dmesg can contain multiple boots, only look in the last one
_dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}'
/var/run/dmesg.boot )"
grep -v '^[[:space:]]*#' "$FWPATTERNS" |
while read -r _d _m; do
- [ "$_d" = "$_last" ] && continue
+ [ "$_d" = "$_last" ] && continue
[ "$_m" ] || _m="${_nl}${_d}[0-9] at "
[ "$_m" = "${_m#^}" ] || _m="${_nl}${_m#^}"
- if [[ $_dmesgtail = *$_m* ]]; then
- echo "$_d"
- _last="$_d"
- fi
+ IFS='*'
+ set -- $_m
+ unset IFS
+
+ case $# in
+ 1) [[ $_dmesgtail = *$** ]] ||
continue;;
+ 2) [[ $_dmesgtail = *$1*([!$_nl])$2* ]] ||
continue;;
+ 3) [[ $_dmesgtail = *$1*([!$_nl])$2*([!$_nl])$3* ]] ||
continue;;
+ *) echo "bad pattern $_m"; exit 1 ;;
+ esac
+
+ echo "$_d"
+ _last="$_d"
done
}