diff options
| author | Lauri Kasanen <curaga@operamail.com> | 2010-12-05 15:53:55 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-05 15:55:06 +0100 |
| commit | e48e6f85bf1966cb3a6350f5c2276ca73251a2f6 (patch) | |
| tree | 2d814b506978d6d19b643913282d01182a0a7990 | |
| parent | 6578f2cf5b97a72562b56e7d9ad5d49dee9953b0 (diff) | |
| download | busybox-w32-e48e6f85bf1966cb3a6350f5c2276ca73251a2f6.tar.gz busybox-w32-e48e6f85bf1966cb3a6350f5c2276ca73251a2f6.tar.bz2 busybox-w32-e48e6f85bf1966cb3a6350f5c2276ca73251a2f6.zip | |
pstree: fix width logic. +30 bytes
Signed-off-by: Lauri Kasanen <curaga@operamail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | procps/pstree.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/procps/pstree.c b/procps/pstree.c index f09e8da34..25fb65d79 100644 --- a/procps/pstree.c +++ b/procps/pstree.c | |||
| @@ -61,16 +61,17 @@ typedef struct child { | |||
| 61 | #define first_3 "-+-" | 61 | #define first_3 "-+-" |
| 62 | 62 | ||
| 63 | struct globals { | 63 | struct globals { |
| 64 | PROC *list; | 64 | /* 0-based. IOW: the number of chars we printer on current line */ |
| 65 | unsigned cur_x; | ||
| 66 | unsigned output_width; | ||
| 65 | 67 | ||
| 66 | /* The buffers will be dynamically increased in size as needed */ | 68 | /* The buffers will be dynamically increased in size as needed */ |
| 67 | unsigned capacity; | 69 | unsigned capacity; |
| 68 | int *width; | 70 | unsigned *width; |
| 69 | int *more; | 71 | uint8_t *more; |
| 72 | |||
| 73 | PROC *list; | ||
| 70 | 74 | ||
| 71 | // Disabled, since code is broken anyway and needs fixing | ||
| 72 | // unsigned output_width; | ||
| 73 | unsigned cur_x; | ||
| 74 | smallint dumped; /* used by dump_by_user */ | 75 | smallint dumped; /* used by dump_by_user */ |
| 75 | }; | 76 | }; |
| 76 | #define G (*ptr_to_globals) | 77 | #define G (*ptr_to_globals) |
| @@ -83,8 +84,7 @@ struct globals { | |||
| 83 | * Allocates additional buffer space for width and more as needed. | 84 | * Allocates additional buffer space for width and more as needed. |
| 84 | * The first call will allocate the first buffer. | 85 | * The first call will allocate the first buffer. |
| 85 | * | 86 | * |
| 86 | * bufindex the index that will be used after the call | 87 | * bufindex the index that will be used after the call to this function. |
| 87 | * to this function. | ||
| 88 | */ | 88 | */ |
| 89 | static void ensure_buffer_capacity(int bufindex) | 89 | static void ensure_buffer_capacity(int bufindex) |
| 90 | { | 90 | { |
| @@ -111,10 +111,10 @@ static void maybe_free_buffers(void) | |||
| 111 | static void out_char(char c) | 111 | static void out_char(char c) |
| 112 | { | 112 | { |
| 113 | G.cur_x++; | 113 | G.cur_x++; |
| 114 | // if (G.cur_x <= G.output_width) | 114 | if (G.cur_x == G.output_width) |
| 115 | c = '+'; | ||
| 116 | if (G.cur_x <= G.output_width) | ||
| 115 | putchar(c); | 117 | putchar(c); |
| 116 | // else if (G.cur_x == G.output_width - 1) | ||
| 117 | // putchar('+'); | ||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | /* NB: this function is never called with "bad" chars | 120 | /* NB: this function is never called with "bad" chars |
| @@ -129,7 +129,7 @@ static void out_string(const char *str) | |||
| 129 | static void out_newline(void) | 129 | static void out_newline(void) |
| 130 | { | 130 | { |
| 131 | putchar('\n'); | 131 | putchar('\n'); |
| 132 | G.cur_x = 1; | 132 | G.cur_x = 0; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | static PROC *find_proc(pid_t pid) | 135 | static PROC *find_proc(pid_t pid) |
| @@ -249,6 +249,7 @@ dump_tree(PROC *current, int level, int rep, int leaf, int last, int closing) | |||
| 249 | { | 249 | { |
| 250 | CHILD *walk, *next, **scan; | 250 | CHILD *walk, *next, **scan; |
| 251 | int lvl, i, add, offset, count, comm_len, first; | 251 | int lvl, i, add, offset, count, comm_len, first; |
| 252 | char tmp[sizeof(int)*3 + 4]; | ||
| 252 | 253 | ||
| 253 | if (!current) | 254 | if (!current) |
| 254 | return; | 255 | return; |
| @@ -275,17 +276,15 @@ dump_tree(PROC *current, int level, int rep, int leaf, int last, int closing) | |||
| 275 | } | 276 | } |
| 276 | } | 277 | } |
| 277 | 278 | ||
| 278 | if (rep < 2) | 279 | add = 0; |
| 279 | add = 0; | 280 | if (rep > 1) { |
| 280 | else { | 281 | add += sprintf(tmp, "%d*[", rep); |
| 281 | add = printf("%d", rep) + 2; | 282 | out_string(tmp); |
| 282 | out_string("*["); | ||
| 283 | } | 283 | } |
| 284 | comm_len = out_args(current->comm); | 284 | comm_len = out_args(current->comm); |
| 285 | if (option_mask32 /*& OPT_PID*/) { | 285 | if (option_mask32 /*& OPT_PID*/) { |
| 286 | out_char('('); | 286 | comm_len += sprintf(tmp, "(%d)", (int)current->pid); |
| 287 | comm_len += printf("%d", (int)current->pid) + 2; | 287 | out_string(tmp); |
| 288 | out_char(')'); | ||
| 289 | } | 288 | } |
| 290 | offset = G.cur_x; | 289 | offset = G.cur_x; |
| 291 | 290 | ||
| @@ -298,12 +297,12 @@ dump_tree(PROC *current, int level, int rep, int leaf, int last, int closing) | |||
| 298 | G.more[level] = !last; | 297 | G.more[level] = !last; |
| 299 | 298 | ||
| 300 | G.width[level] = comm_len + G.cur_x - offset + add; | 299 | G.width[level] = comm_len + G.cur_x - offset + add; |
| 301 | // if (G.cur_x >= G.output_width) { | 300 | if (G.cur_x >= G.output_width) { |
| 302 | // out_string(first_3); | 301 | //out_string(first_3); - why? it won't print anything |
| 303 | // out_char('+'); | 302 | //out_char('+'); |
| 304 | // out_newline(); | 303 | out_newline(); |
| 305 | // return; | 304 | return; |
| 306 | // } | 305 | } |
| 307 | 306 | ||
| 308 | first = 1; | 307 | first = 1; |
| 309 | for (walk = current->children; walk; walk = next) { | 308 | for (walk = current->children; walk; walk = next) { |
| @@ -382,9 +381,8 @@ int pstree_main(int argc UNUSED_PARAM, char **argv) | |||
| 382 | long uid = 0; | 381 | long uid = 0; |
| 383 | 382 | ||
| 384 | INIT_G(); | 383 | INIT_G(); |
| 385 | G.cur_x = 1; | ||
| 386 | 384 | ||
| 387 | // get_terminal_width_height(1, &G.output_width, NULL); | 385 | get_terminal_width_height(1, &G.output_width, NULL); |
| 388 | 386 | ||
| 389 | getopt32(argv, "p"); | 387 | getopt32(argv, "p"); |
| 390 | argv += optind; | 388 | argv += optind; |
