Skip to content

Commit 98c09dc

Browse files
committed
transport: store the transports sorted by alphabetic name order
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 <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8685 Tested-by: jenkins Reviewed-by: zapb <[email protected]>
1 parent 9643379 commit 98c09dc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/transport/transport.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static const struct {
5959
{ TRANSPORT_SWIM, "swim", },
6060
};
6161

62-
/** List of transports registered in OpenOCD. */
62+
/** List of transports registered in OpenOCD, alphabetically sorted per name. */
6363
static OOCD_LIST_HEAD(transport_list);
6464

6565
/**
@@ -207,8 +207,14 @@ int transport_register(struct transport *new_transport)
207207
LOG_ERROR("invalid transport %s",
208208
transport_name(new_transport->id));
209209

210-
/* splice this into the list */
211-
list_add(&new_transport->lh, &transport_list);
210+
/* splice this into the list, sorted in alphabetic order */
211+
list_for_each_entry(t, &transport_list, lh) {
212+
if (strcmp(transport_name(t->id),
213+
transport_name(new_transport->id)) >= 0)
214+
break;
215+
}
216+
list_add_tail(&new_transport->lh, &t->lh);
217+
212218
LOG_DEBUG("register '%s' (ID %d)",
213219
transport_name(new_transport->id), new_transport->id);
214220

0 commit comments

Comments
 (0)