Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix device parsing #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions lsusb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Disclaimer: usage info and functionality from lsusb under Linux

verbose () { system_profiler SPUSBDataType; }
verbose () { system_profiler SPUSBDataType 2>/dev/null; }
version () { echo "lsusb for Mac OS X 007"; }
help () {
cat >&2 <<EOM
Expand All @@ -25,6 +25,30 @@ EOM
}
usage () { echo "Usage: $(basename "$0") [options]..."; }

split_devices() {
awk ' \
/Product ID:/ { \
print TWO_BEFORE; \
print ONE_BEFORE; \
PRINTING=1; \
} \
\
/^$/ { \
if (PRINTING == 1) { \
PRINTING=0; \
print "#"; \
} \
} \
\
{ \
if (PRINTING == 1) { \
print \
} \
TWO_BEFORE=ONE_BEFORE; \
ONE_BEFORE=$0; \
}' <<< "$rawlog"
}

parse () {
# Get the name of the device, it is the first line that ends with a ':'
# Trim the string at the end
Expand Down Expand Up @@ -85,9 +109,13 @@ parse () {
esac
fi

# Convert bus number from hexadecimal to decimal.
bus_num=`echo "$((16#$bus_num))"`
bus_num=`printf "%0*d" 3 "$bus_num"`
if [ ${#bus_num} -ne 0 ]; then
# Convert bus number from hexadecimal to decimal.
bus_num=`echo "$((16#$bus_num))"`
bus_num=`printf "%0*d" 3 "$bus_num"`
else
bus_num='000'
fi

# Strip the parentheses from manufacturer name unless so specified.
if [ -z "$parens" ]; then
Expand Down Expand Up @@ -210,7 +238,7 @@ tree () {
setup
treeflag="yes"

devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'`
devices=$(split_devices)
for device in $devices
do
# Skip null device lines
Expand Down Expand Up @@ -282,7 +310,7 @@ setup
# with the '#' symbol in case other parameters that contain a dash
# will not be interfered

devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'`
devices=$(split_devices)
# Iterate over each entry
for device in $devices
do
Expand Down