struct usb_device *dev_of_path(const char *path) { struct usb_bus *bus; struct usb_device *dev; char dirname[PATH_MAX]; char filename[PATH_MAX]; const char *p; int bnum; int dnum; int ret; assert(path != NULL); if(access(path, F_OK) < 0) { perror(path); return NULL; } /* Find last '/' */ if((p = memrchr(path, '/', strlen(path))) == NULL) { ERR("Missing a '/' in %s\n", path); return NULL; } /* Get the device number */ ret = sscanf(p + 1, "%d", &dnum); if(ret != 1) { ERR("Path tail is not a device number: '%s'\n", p); return NULL; } /* Search for a '/' before that */ p = memrchr(path, '/', p - path); if(p == NULL) p = path; /* Relative path */ else p++; /* skip '/' */ /* Get the bus number */ ret = sscanf(p, "%d", &bnum); if(ret != 1) { ERR("Path tail is not a bus number: '%s'\n", p); return NULL; } sprintf(dirname, "%03d", bnum); sprintf(filename, "%03d", dnum); for (bus = usb_busses; bus; bus = bus->next) { if (! num_matches(bnum, bus->dirname)) //if(strcmp(bus->dirname, dirname) != 0) continue; for (dev = bus->devices; dev; dev = dev->next) { //if(strcmp(dev->filename, filename) == 0) if (num_matches(dnum, dev->filename)) return dev; } } ERR("no usb device match '%s'\n", path); return NULL; }
Shit *find_shit(const char *userhost, const char *channel) { Shit *shit,*save; int num,best; if (!userhost) return(NULL); save = NULL; best = 0; for(shit=current->shitlist;shit;shit=shit->next) { if (!channel || !stringcasecmp(channel,shit->chan) || (*shit->chan == '*') || (*channel == '*')) { num = num_matches(shit->mask,userhost); if (num > best) { best = num; save = shit; } } } if (save && save->expire < now) { remove_shit(save); save = NULL; } return(save); }
KickSay *find_kicksay(char *text, char *channel) { KickSay *kick,*save; int num,best; save = NULL; best = 0; for(kick=current->kicklist;kick;kick=kick->next) { if (!channel || *kick->chan == '*' || !Strcasecmp(channel,kick->chan)) { num = num_matches(kick->mask,text); if (num > best) { best = num; save = kick; } } } return(save); }
// s1 should be the original spectrum DoubleReal CompNovoIdentificationBase::compareSpectra_(const PeakSpectrum & s1, const PeakSpectrum & s2) { DoubleReal score(0.0); PeakSpectrum::ConstIterator it1 = s1.begin(); PeakSpectrum::ConstIterator it2 = s2.begin(); Size num_matches(0); while (it1 != s1.end() && it2 != s2.end()) { DoubleReal pos1(it1->getPosition()[0]), pos2(it2->getPosition()[0]); if (fabs(pos1 - pos2) < fragment_mass_tolerance_) { score += it1->getIntensity(); ++num_matches; } if (pos1 <= pos2) { ++it1; } else { ++it2; } } if (num_matches == 0) { return 0; } score /= sqrt((DoubleReal)num_matches); return score; }