optimize Shell Cmd ShowBus using node from Liu_Weichao

it is OK
This commit is contained in:
xuedongliang 2021-05-08 11:30:11 +08:00
commit 1599057195
1 changed files with 46 additions and 50 deletions

View File

@ -654,7 +654,7 @@ static char *const bus_type_str[] =
"Unknown" "Unknown"
}; };
static DriverType showBusFindDriver(struct Bus *bus) static DriverType ShowBusFindDriver(struct Bus *bus)
{ {
struct Driver *driver = NONE; struct Driver *driver = NONE;
@ -670,9 +670,12 @@ static DriverType showBusFindDriver(struct Bus *bus)
long ShowBus(void) long ShowBus(void)
{ {
ListGetNext_t find_arg; BusType bus;
DoubleLinklistType *obj_list[LIST_FIND_OBJ_NR]; DriverType driver;
DoubleLinklistType *next = (DoubleLinklistType*)NONE; HardwareDevType device;
DoubleLinklistType *bus_node = NONE;
DoubleLinklistType *bus_head = &bus_linklist;
int i = 0; int i = 0;
int dev_cnt, maxlen; int dev_cnt, maxlen;
@ -682,8 +685,6 @@ long ShowBus(void)
const char *item_name_2 = "dev_name"; const char *item_name_2 = "dev_name";
const char *item_cnt = "cnt"; const char *item_cnt = "cnt";
ListFindManagelistInit(&find_arg, Cmpt_KindN_Bus, obj_list, sizeof(obj_list)/sizeof(obj_list[0]));
KPrintf(" %-15s%-15s%-15s%-15s%-20s\n", item_type, item_name_0, item_name_1, item_name_2, item_cnt); KPrintf(" %-15s%-15s%-15s%-15s%-20s\n", item_type, item_name_0, item_name_1, item_name_2, item_cnt);
maxlen = 65; maxlen = 65;
while (i < maxlen) { while (i < maxlen) {
@ -695,63 +696,58 @@ long ShowBus(void)
} }
} }
bus_node = bus_head->node_next;
do do
{ {
next = ListGetNext(next, &find_arg); bus = SYS_DOUBLE_LINKLIST_ENTRY(bus_node, struct Bus, bus_link);
{ if (bus) {
int i; KPrintf("%s", " ");
for (i = 0; i < find_arg.nr_out; i++) { KPrintf("%-15s%-15s",
struct Bus *bus; bus_type_str[bus->bus_type],
bus->bus_name);
driver = ShowBusFindDriver(bus);
bus = SYS_DOUBLE_LINKLIST_ENTRY(obj_list[i], struct Bus, bus_link); if (driver) {
if (bus) { KPrintf("%-15s", driver->drv_name);
KPrintf("%s", " "); } else {
KPrintf("%-15s%-15s", KPrintf("%-15s", "nil");
bus_type_str[bus->bus_type], }
bus->bus_name);
DriverType driver = showBusFindDriver(bus);
if (driver) { if (bus->haldev_cnt) {
KPrintf("%-15s", driver->drv_name); DoubleLinklistType *dev_node = NONE;
} else { DoubleLinklistType *dev_head = &bus->bus_devlink;
KPrintf("%-15s", "nil");
}
if (bus->haldev_cnt) { dev_node = dev_head->node_next;
DoubleLinklistType *node = NONE; dev_cnt = 1;
DoubleLinklistType *head = &bus->bus_devlink; while (dev_node != dev_head) {
device = SYS_DOUBLE_LINKLIST_ENTRY(dev_node, struct HardwareDev, dev_link);
node = head->node_next; if (1 == dev_cnt) {
dev_cnt = 1; if (device) {
while (node != head) { KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
HardwareDevType device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link); } else {
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
if (1 == dev_cnt) {
if (device) {
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
} else {
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
}
} else {
KPrintf("%46s", " ");
if (device) {
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
} else {
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
}
}
dev_cnt++;
node = node->node_next;
} }
} else { } else {
KPrintf("\n"); KPrintf("%46s", " ");
if (device) {
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
} else {
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
}
} }
dev_cnt++;
dev_node = dev_node->node_next;
} }
} else {
KPrintf("\n");
} }
} }
bus_node = bus_node->node_next;
} }
while (next != (DoubleLinklistType*)NONE); while (bus_node != bus_head);
return 0; return 0;
} }