- device = NULL;
- device_num = strtol(devicestring, &tmp, 10);
- if (tmp != devicestring) {
- /* argument is numeric, meaning a device ID. Make all driver
- * plugins scan for devices.
- */
- num_devices = num_real_devices();
- if (device_num < 0 || device_num >= num_devices)
- return NULL;
-
- device_cnt = 0;
- devices = sr_device_list();
- for (l = devices; l; l = l->next) {
- d = l->data;
- if (sr_device_has_hwcap(d, SR_HWCAP_DEMO_DEVICE))
- continue;
- if (device_cnt == device_num) {
- if (device_num == device_cnt) {
- device = d;
- break;
- }
- }
- device_cnt++;
- }
- } else {
- /* select device by driver -- only initialize that driver,
- * no need to let them all scan
- */
- device = NULL;
- plugins = sr_list_hwplugins();
- for (p = plugins; p; p = p->next) {
- plugin = p->data;
- if (strcmp(plugin->name, devicestring))
- continue;
- num_devices = sr_init_hwplugin(plugin);
- if (num_devices == 1) {
- devices = sr_device_list();
- device = devices->data;
- } else if (num_devices > 1) {
- printf("driver '%s' found %d devices, select by ID instead.\n",
- devicestring, num_devices);
- }
- /* fall through: selected driver found no devices */
- break;
- }
- }