I'm trying to extract information out of my /proc/pci file (linux) and I'm
not at all good with regexp matching and the like, so I'm hoping someone here
can help me out.

    This is the original code which extracts the device type and device pair,
ignoring those that have 'bridge' or 'USB' in the device type string.  This
works.  The array it creates is what I need.

function pci () {
  $results = array();

  if ($fd = fopen('/proc/pci', 'r')) {
    while ($buf = fgets($fd, 4096)) {
      if (preg_match('/Bus/', $buf)) {
        $device = 1;
        continue;
      }

      if ($device) {
        list($type, $device) = split(': ', $buf, 2);

        if (!preg_match('/bridge/i', $type) && !preg_match('/USB/i', $type)) {
          $results[$device] = array();
          $results[$device]['name'] = preg_replace('/\([^\)]+\)\.$/', '',
trim($device));
        }
        $device = 0;
      }
    }
  }
  return $results;
}


    The result of this is basically an array of arrays, which I would like to
continue adding to.  My final goal is to have something like this (for
starters):

    $results[$device]['bus']
    $results[$device]['device']
    $results[$device]['type']
    $results[$device]['name']
    $results[$device]['irq']
    $results[$device]['io']

    Problem is, I don't know how to extract those values from that file.  What
I've noticed is this:

    - The IRQ value isn't always in the same spot in the string, so I can't
blindly explode the string and expect that value to be at the same position
every time.
    - Not everything has an IRQ value, so that will be empty sometimes.

    So, can someone help write this beast up, based on what /proc/pci reports?
It has to be fairly generic so that it would work across any (linux) machine.
If you'd like me to send you /proc/pci from my machines for you to work with,
please let me know.


--
H | I haven't lost my mind; it's backed up on tape somewhere.
  +--------------------------------------------------------------------
  Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
  IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
  Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6
  http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to