aboutsummaryrefslogtreecommitdiffstats
path: root/pulse.cc
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-03 22:29:43 -0500
committerDave Reisner <dreisner@archlinux.org>2013-01-03 22:29:43 -0500
commit81d7ece0122dd853f18b9c041ac3cf0c52ad5847 (patch)
treedc0e93a523d9bf7e2f46913f82d9dd0110536b85 /pulse.cc
parent5c7d8e7d407be9aef46ed422f51a599f56a740c7 (diff)
downloadmirror-ponymix-81d7ece0122dd853f18b9c041ac3cf0c52ad5847.tar.gz
mirror-ponymix-81d7ece0122dd853f18b9c041ac3cf0c52ad5847.tar.bz2
mirror-ponymix-81d7ece0122dd853f18b9c041ac3cf0c52ad5847.zip
allow fuzzy matching on devices
Diffstat (limited to 'pulse.cc')
-rw-r--r--pulse.cc31
1 files changed, 27 insertions, 4 deletions
diff --git a/pulse.cc b/pulse.cc
index 3a248de..f6b633b 100644
--- a/pulse.cc
+++ b/pulse.cc
@@ -151,12 +151,23 @@ Card* PulseClient::GetCard(const uint32_t& index) {
Card* PulseClient::GetCard(const string& name) {
long val;
+ vector<Card> res;
if (xstrtol(name.c_str(), &val) == 0) return GetCard(val);
for (Card& card : cards_) {
- if (card.name_ == name) return &card;
+ if (card.name_.find(name) != string::npos) res.push_back(card);
}
- return nullptr;
+
+ switch (res.size()) {
+ case 0:
+ return nullptr;
+ case 1:
+ break;
+ default:
+ warnx("warning: ambiguous result for '%s', using '%s'",
+ name.c_str(), res[0].name_.c_str());
+ }
+ return &res[0];
}
Card* PulseClient::GetCard(const Device& device) {
@@ -176,12 +187,24 @@ Device* PulseClient::get_device(vector<Device>& devices,
Device* PulseClient::get_device(vector<Device>& devices, const string& name) {
long val;
+ vector<Device> res;
if (xstrtol(name.c_str(), &val) == 0) return get_device(devices, val);
for (Device& device : devices) {
- if (device.name_ == name) return &device;
+ if (device.name_.find(name) != string::npos) res.push_back(device);
}
- return nullptr;
+
+ switch (res.size()) {
+ case 0:
+ return nullptr;
+ case 1:
+ break;
+ default:
+ warnx("warning: ambiguous result for '%s', using '%s'",
+ name.c_str(), res[0].name_.c_str());
+ }
+
+ return &res[0];
}
Device* PulseClient::GetDevice(const uint32_t& index, enum DeviceType type) {