49 lines
1.7 KiB
Diff
49 lines
1.7 KiB
Diff
From ea46d5c41457be0987c8d16bcefec9ad196b06c8 Mon Sep 17 00:00:00 2001
|
|
From: kangenbo <kangenbo@huawei.com>
|
|
Date: Sat, 26 Jan 2019 08:56:48 -0500
|
|
Subject: [PATCH] bugfix: huawei-bugfix-alternatives-prettier-list-output
|
|
|
|
---
|
|
alternatives.c | 15 +++++++++++----
|
|
1 file changed, 11 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/alternatives.c b/alternatives.c
|
|
index c1a68db..2f60011 100644
|
|
--- a/alternatives.c
|
|
+++ b/alternatives.c
|
|
@@ -946,20 +946,27 @@ static int removeAll(const char * title, const char * altDir, const char * state
|
|
static int listServices(const char * altDir, const char * stateDir, int flags) {
|
|
DIR *dir;
|
|
struct dirent *ent;
|
|
- dir = opendir(stateDir);
|
|
struct alternativeSet set;
|
|
+ int max_name = 0;
|
|
+ int l;
|
|
|
|
+ dir = opendir(stateDir);
|
|
if(dir == NULL)
|
|
return 2;
|
|
|
|
while((ent = readdir(dir)) != NULL) {
|
|
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
|
continue;
|
|
-
|
|
+ l = strlen(ent->d_name);
|
|
+ max_name = max_name > l ? max_name : l;
|
|
+ }
|
|
+ rewinddir(dir);
|
|
+ while((ent = readdir(dir)) != NULL) {
|
|
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
|
+ continue;
|
|
if (readConfig(&set, ent->d_name, altDir, stateDir, flags))
|
|
return 2;
|
|
-
|
|
- printf("%s\t%s\t%s\n", ent->d_name, set.mode == AUTO?"auto":"manual", set.currentLink);
|
|
+ printf("%-*s\t%s\t%s\n", max_name, ent->d_name, set.mode == AUTO?"auto ":"manual", set.currentLink);
|
|
}
|
|
|
|
closedir(dir);
|
|
--
|
|
1.8.3.1
|
|
|