]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
transport: store the transports sorted by alphabetic name order
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 31 Dec 2024 16:01:41 +0000 (17:01 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Thu, 1 May 2025 15:27:14 +0000 (15:27 +0000)
While this operation has no real interest so far, it will be used
later to avoid listing twice protocols with the same name.

Change-Id: I59f3634830f94dc992d28863cf29d5d869726918
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8685
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
src/transport/transport.c

index 8a210fe94c63a8d3f01f5c232366beecfe749bed..755e21054e2089816545464d3fcb92fbcf880d86 100644 (file)
@@ -59,7 +59,7 @@ static const struct {
        { TRANSPORT_SWIM,           "swim",           },
 };
 
-/** List of transports registered in OpenOCD. */
+/** List of transports registered in OpenOCD, alphabetically sorted per name. */
 static OOCD_LIST_HEAD(transport_list);
 
 /**
@@ -207,8 +207,14 @@ int transport_register(struct transport *new_transport)
                LOG_ERROR("invalid transport %s",
                                  transport_name(new_transport->id));
 
-       /* splice this into the list */
-       list_add(&new_transport->lh, &transport_list);
+       /* splice this into the list, sorted in alphabetic order */
+       list_for_each_entry(t, &transport_list, lh) {
+               if (strcmp(transport_name(t->id),
+                                  transport_name(new_transport->id)) >= 0)
+                       break;
+       }
+       list_add_tail(&new_transport->lh, &t->lh);
+
        LOG_DEBUG("register '%s' (ID %d)",
                          transport_name(new_transport->id), new_transport->id);