Back to index

lshw  02.16
Functions | Variables
heuristics.cc File Reference
#include "version.h"
#include "sysfs.h"
#include "jedec.h"
#include "osutils.h"
#include <stdlib.h>
#include <regex.h>

Go to the source code of this file.

Functions

 __ID ("@(#) $Id: heuristics.cc 2433 2012-01-10 22:01:30Z lyonel $")
string guessBusInfo (const string &info)
static string guessParentBusInfo (const hwNode &child)
hwNodeguessParent (const hwNode &child, hwNode &base)
bool guessVendor (hwNode &device)
static string parsehex (const string &s)
bool guessProduct (hwNode &device)

Variables

static const char * disk_manufacturers []

Function Documentation

__ID ( "@(#) $Id: heuristics.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
string guessBusInfo ( const string &  info)

Definition at line 17 of file heuristics.cc.

{
                                                  // 2.6-style PCI
  if(matches(info,"^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]\\.[[:xdigit:]]$"))
  {
    return "pci@" + info;
  }
                                                  // 2.4-style PCI
  if(matches(info,"^[[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]]\\.[[:xdigit:]]$"))
  {
    return "pci@0000:" + info;
  }

                                                  // USB: host-port[.port]:config.interface
  if(matches(info, "^[0-9]+-[0-9]+(\\.[0-9]+)*:[0-9]+\\.[0-9]+$"))
  {
    size_t colon = info.rfind(":");
    size_t dash = info.find("-");

    return "usb@" + info.substr(0, dash) + ":" + info.substr(dash+1, colon-dash-1);
  }

  if(matches(info, "^[[:xdigit:]]+-[0-9]+$"))     // Firewire: guid-function
  {
    size_t dash = info.find("-");

    return "firewire@" + info.substr(0, dash);
  }

#if 1
//#ifdef __hppa__
  if(matches(info, "^[0-9]+(:[0-9]+)*$"))         // PA-RISC: x:y:z:t corresponds to /x/y/z/t
  {
    string result = "parisc@";

    for(unsigned i=0; i<info.length(); i++)
      if(info[i] == ':')
        result += '/';
    else
      result += info[i];
    return result;
  }
#endif
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

hwNode* guessParent ( const hwNode child,
hwNode base 
)

Definition at line 88 of file heuristics.cc.

{
  return base.findChildByBusInfo(guessParentBusInfo(child));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string guessParentBusInfo ( const hwNode child) [static]

Definition at line 64 of file heuristics.cc.

{
  string sysfs_path = sysfs_finddevice(child.getLogicalName());
  vector < string > path;
  string result = "";

  if(sysfs_path == "") return "";

  splitlines(sysfs_path, path, '/');

  if(path.size()>1)
    path.pop_back();
  else
    return "";

  while((result=="") && (path.size()>1))
  {
    result = guessBusInfo(path[path.size()-1]);
    path.pop_back();
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool guessProduct ( hwNode device)

Definition at line 167 of file heuristics.cc.

{
  string product = device.getProduct();

  if(product == "")
    return false;

  device.setProduct(parsehex(product));

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool guessVendor ( hwNode device)

Definition at line 115 of file heuristics.cc.

{
  int i = 0;
  bool result = false;


  device.setVendor(jedec_resolve(device.getVendor()));

  if(device.getVendor() != "")
    return false;

 
  if(device.getClass() == hw::disk)
    while (disk_manufacturers[i])
    {
      if (matches(device.getProduct().c_str(), disk_manufacturers[i], REG_ICASE))
      {
        device.setVendor(disk_manufacturers[i + 1]);
        result = true;
      }
      i += 2;
    }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string parsehex ( const string &  s) [static]

Definition at line 142 of file heuristics.cc.

{
  int i = 0;
  string result = "";

  if(matches(s,"^0x[[:xdigit:]][[:xdigit:]]+$"))
  {
    for(i=2; i<s.length(); i+=2)
    {
      string c = s.substr(i,2);
      static char code[2];

      code[0] = strtol(c.c_str(), NULL, 16);
      code[1] = '\0';
      
      if(code[0] < ' ') return s;
      result += string(code);
    }
   }
   else
     return s;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* disk_manufacturers[] [static]
Initial value:
{
  "^ST.+", "Seagate",
  "^D...-.+", "IBM",
  "^IBM.+", "IBM",
  "^HITACHI.+", "Hitachi",
  "^IC.+", "Hitachi",
  "^HTS.+", "Hitachi",
  "^FUJITSU.+", "Fujitsu",
  "^MP.+", "Fujitsu",
  "^TOSHIBA.+", "Toshiba",
  "^MK.+", "Toshiba",
  "^MAXTOR.+", "Maxtor",
  "^Pioneer.+", "Pioneer",
  "^PHILIPS.+", "Philips",
  "^QUANTUM.+", "Quantum",
  "FIREBALL.+", "Quantum",
  "^WDC.+", "Western Digital",
  "WD.+", "Western Digital",
  NULL, NULL
}

Definition at line 93 of file heuristics.cc.