Use macro expansion to iterate over all the drivers without explicitly writing them out in usbutils.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/usbutils.c b/usbutils.c
index 909cd37..54b9054 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -3234,42 +3234,14 @@ void usb_initialise()
quit(1, "Invalid --usb DRV:limit - limit must be >= 0");
found = false;
-#ifdef USE_BFLSC
- if (strcasecmp(ptr, bflsc_drv.name) == 0) {
- drv_count[bflsc_drv.drv_id].limit = lim;
- found = true;
+ /* Use the DRIVER_PARSE_COMMANDS macro to iterate
+ * over all the drivers. */
+#define DRIVER_ADD_COMMAND(X) if (strcasecmp(ptr, X##_drv.name) == 0) { \
+ drv_count[X##_drv.drv_id].limit = lim; \
+ found = true; \
}
-#endif
-#ifdef USE_BITFORCE
- if (!found && strcasecmp(ptr, bitforce_drv.name) == 0) {
- drv_count[bitforce_drv.drv_id].limit = lim;
- found = true;
- }
-#endif
-#ifdef USE_BITFURY
- if (!found && strcasecmp(ptr, bitfury_drv.name) == 0) {
- drv_count[bitfury_drv.drv_id].limit = lim;
- found = true;
- }
-#endif
-#ifdef USE_MODMINER
- if (!found && strcasecmp(ptr, modminer_drv.name) == 0) {
- drv_count[modminer_drv.drv_id].limit = lim;
- found = true;
- }
-#endif
-#ifdef USE_ICARUS
- if (!found && strcasecmp(ptr, icarus_drv.name) == 0) {
- drv_count[icarus_drv.drv_id].limit = lim;
- found = true;
- }
-#endif
-#ifdef USE_AVALON
- if (!found && strcasecmp(ptr, avalon_drv.name) == 0) {
- drv_count[avalon_drv.drv_id].limit = lim;
- found = true;
- }
-#endif
+ DRIVER_PARSE_COMMANDS
+#undef DRIVER_ADD_COMMAND
if (!found)
quit(1, "Invalid --usb DRV:limit - unknown DRV='%s'", ptr);