On Thu, 11 Apr 2002, Guest section DW wrote:

| On Wed, Apr 10, 2002 at 07:40:28PM -0700, Greg KH wrote:
| > On Thu, Apr 11, 2002 at 02:57:14AM +0200, Guest section DW wrote:
|
| > > The unreadable /proc/bus/usb always annoyed me, and I added a
| > > blank line, separating entries. Hope that no utilities are
| > > confused by this.

My procusb script inserts a "---" line between entries.

'procusb' and 'usbtree' are attached...
If they have problems (which I doubt), I will gladly fix them.

Thanks,
~Randy

| > ??? /proc/bus/usb/ is a directory.  Are you talking about
| > /proc/bus/usb/devices?
|
| Yes, sorry.
|
| > It's easy enough for you to try running the different programs that
| > parse this file (usbview, some perl scripts from Randy Dunlap, kde
| > control panel, gnome-pilot, and I think evolution.)  There's a few
| > others out there, but that should be enough to start with :)
|
| usbview has no problems
| have not tried other programs
|
| Andries
#!/usr/bin/perl

# Reads /proc/bus/usb/devices and selectively lists and/or
# interprets it.

$DEVFILENAME = "/proc/bus/usb/devices";
$PROGNAME = $0;

$TAGS = $ARGV[0];               # save user TAGS
if (length ($TAGS) == 0)
{
        print "usage: $PROGNAME tags\n";
        print "  where 'tags' can be any number of 'TBDPSCIE' or 'A(LL)'\n";
        exit 1;
}

$ALL = ($TAGS =~ /all/i) || ($TAGS =~ /a/i);

# TBD: Check that $TAGS is valid.
if (! $ALL)
{
}

if (! open (DEVNUM, "<$DEVFILENAME"))
{
        print "$PROGNAME: cannot open '$DEVFILENAME'\n";
        exit 1;
}

while ($line = <DEVNUM>)        # read a text line from DEVNUM
{
        if ($line =~ /^T:/)     # put device break line
        {
                print "---\n";
        }

        if (($ALL) || ($line =~ /^[$TAGS]:/i))  # any of TAGS at beg. of line?
        {
                print "$line";  # still has newline char on it
                                # TBD: add more/paging functionality.
        }
} # end while DEVNUM

close (DEVNUM);
print "\n";

# END.
#!/usr/bin/perl

# Reads /proc/bus/usb/devices and selectively lists and/or
# interprets it.

$DEVFILENAME = "/proc/bus/usb/devices";
$PROGNAME = $0;

print "\n";

$TAGS = $ARGV[0];               # save user TAGS
if (length ($TAGS) == 0)
{
}

if (! open (DEVNUM, "<$DEVFILENAME"))
{
        print "$PROGNAME: cannot open '$DEVFILENAME'\n";
        exit 1;
}

while ($line = <DEVNUM>)        # read a text line from DEVNUM
{
        # skip all lines except those that begin with "T:" or "D:" or "I:".
        if (($line !~ "^T:") && ($line !~ "^I:") && ($line !~ "^D:"))
        {
                next;   # to the next line
        }

        chomp $line;            # remove line endings

        # First convert '=' signs to spaces.
        $line =~ tr/=/ /;

        # and convert all '(' and ')' to spaces.
        $line =~ tr/(/ /;
        $line =~ tr/)/ /;

        # split the line at spaces.
        @fields = split / +/, $line;

        if ($line =~ "^T:")
        {
                # split yields: $bus, $level, $parent, $port, $count, $devnum, $speed, 
$maxchild.

                $bus    = @fields [2];
                $level  = @fields [4];
                $parent = @fields [6];          # parent devnum
                $port   = @fields [8] + 1;      # make $port 1-based
                $count  = @fields [10];
                $devnum = @fields [12];
                $speed  = @fields [14];
                $maxchild = @fields [16];
                $devclass = "?";
                $intclass = "?";
                $driver   = "?";
                $ifnum    = "?";
                $showclass = "?";       # derived from $devclass or $intclass
                next;
        } # end T: line
        elsif ($line =~ "^D:")
        { # for D: line
                $devclass = @fields [5];
                next;
        }
        else
        { # for I: line
                $intclass = @fields [9];
                $ifnum    = @fields [2];
                $driver   = @fields [15];
        } # end I: line

        if ($level >= 1)
        {
                $temp = $level;
                while ($temp >= 1)
                {
                        print "    ";
                        $temp--;
                }
        }

        if (($devclass eq ">ifc") || ($devclass eq "unk."))
        {       # then use InterfaceClass, not DeviceClass
                $showclass = $intclass;
        }
        else
        {       # use DeviceClass
                $showclass = $devclass;
        }

        if ($level == 0)
        {
                print sprintf ("/:  Bus $bus.Port $port: Dev $devnum, Class=root_hub, 
Driver=hub/%sp, %sM\n",
                        $maxchild, $speed);
        }
        else
        {
                print sprintf ("|__ Port $port: Dev $devnum, If $ifnum, 
Class=$showclass, Driver=$driver%s, %sM\n",
                        ($maxchild == 0) ? "" : ("/" . $maxchild . "p"),
                        $speed);
        }
} # end while DEVNUM

close (DEVNUM);
print "\n";

# END.

Reply via email to