Skip to content

Commit

Permalink
Resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfreed committed Feb 24, 2014
2 parents 17d2d22 + d5af057 commit 3fe3192
Showing 1 changed file with 48 additions and 49 deletions.
97 changes: 48 additions & 49 deletions lsusb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ parse () {
# Get the manufacturer string
manufacturer=`echo "$VID_all" | cut -d ' ' -f 2- | sed 's/^ *//; s/ *$//'`

#get the Location Id
# Get the Location Id
location=`echo "$device" | egrep "Location ID" | sed -e 's/Location ID://; s/^ *//g; s/ *$//g;'`

# Get the bus number. It's the first two hex digits of the Location ID.
Expand Down Expand Up @@ -101,11 +101,10 @@ parse () {
serial_str=" Serial: ""$serial_number"
fi


# Don't filter if we're building the tree.
if [ "$treeflag" == "yes" ]; then
exitcode=0
return
return
fi

# Filter by VID/PID if given as input argument.
Expand Down Expand Up @@ -166,25 +165,25 @@ parse () {
}

setup () {
# Save the data (if we haven't already).
if [ -z "$rawlog" ]; then
rawlog=$(verbose)
fi
# Save the data (if we haven't already).
if [ -z "$rawlog" ]; then
rawlog=$(verbose)
fi

# Change the IFS to #, backup the current one.
OIFS=$IFS
IFS="#"
# Change the IFS to #, backup the current one.
OIFS=$IFS
IFS="#"

# Default exit code is failure, but if we match anything this will change to success.
exitcode=1
# Default exit code is failure, but if we match anything this will change to success.
exitcode=1

# Flag to know if -t option was set. We ignore filters if so.
treeflag="no"
# Flag to know if -t option was set. We ignore filters if so.
treeflag="no"
}

cleanup () {
IFS=$OIFS
exit "$exitcode"
IFS=$OIFS
exit $exitcode
}

buildtreeline () {
Expand All @@ -207,49 +206,49 @@ buildtreeline () {
treeline="${locationID}${spaces}Bus ""${bus_num}"".Dev ""${device_num}"": ""${name}"", ""${speed}"
}

tree () {
setup
treeflag="yes"
tree () {
setup
treeflag="yes"

devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'`
for device in $devices
do
# Skip null device lines
if [ "${#device}" -ne 1 ]; then
parse
buildtreeline
treedata="$treedata""${treeline}"$'\n'
fi
done

devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'`
for device in $devices
do
#skip null device lines
if [ "${#device}" -ne 1 ]; then
buses=`echo "$rawlog" | egrep -A 7 "Bus:" | sed 's/^--/#/'`
for device in $buses
do
parse
buildtreeline
treedata="$treedata""${treeline}"$'\n'
fi
done
treedata="${treedata}""${treeline}"$'\n'
done

buses=`echo "$rawlog" | egrep -A 7 "Bus:" | sed 's/^--/#/'`
for device in $buses
do
parse
buildtreeline
treedata="${treedata}""${treeline}"$'\n'
done

# Strip off final \n.
treedata=`echo "${treedata}" | awk '{ prev_line = line; line = $0; } NR > 1 { print prev_line; } END { ORS = ""; print line; }'`
# Strip off final \n.
treedata=`echo "${treedata}" | awk '{ prev_line = line; line = $0; } NR > 1 { print prev_line; } END { ORS = ""; print line; }'`

# Sort by Location ID.
treedata=`echo "${treedata}" | sort`
# Sort by Location ID.
treedata=`echo "${treedata}" | sort`

# Now strip off leading Location ID and print to stdout.
for line in $treedata
do
echo "$line" | sed 's/^...........//'
done
# Now strip off leading Location ID and print to stdout.
for line in $treedata
do
echo "$line" | sed 's/^...........//'
done

# Restore the IFS
cleanup
# Restore the IFS
cleanup

# Not really needed, as cleanup routine does the exit.
exit 0
# Not really needed, as cleanup routine does the exit.
exit 0
}

# Parse options
# Parse options
while getopts ":hvpd:s:Vt" opt; do
case "$opt" in
h) help ; exit 0 ;; # help
Expand Down

0 comments on commit 3fe3192

Please sign in to comment.