#define first_3 "-+-"
struct globals {
- PROC *list;
+ /* 0-based. IOW: the number of chars we printer on current line */
+ unsigned cur_x;
+ unsigned output_width;
/* The buffers will be dynamically increased in size as needed */
unsigned capacity;
- int *width;
- int *more;
+ unsigned *width;
+ uint8_t *more;
+
+ PROC *list;
-// Disabled, since code is broken anyway and needs fixing
-// unsigned output_width;
- unsigned cur_x;
smallint dumped; /* used by dump_by_user */
};
#define G (*ptr_to_globals)
* Allocates additional buffer space for width and more as needed.
* The first call will allocate the first buffer.
*
- * bufindex the index that will be used after the call
- * to this function.
+ * bufindex the index that will be used after the call to this function.
*/
static void ensure_buffer_capacity(int bufindex)
{
static void out_char(char c)
{
G.cur_x++;
-// if (G.cur_x <= G.output_width)
+ if (G.cur_x == G.output_width)
+ c = '+';
+ if (G.cur_x <= G.output_width)
putchar(c);
-// else if (G.cur_x == G.output_width - 1)
-// putchar('+');
}
/* NB: this function is never called with "bad" chars
static void out_newline(void)
{
putchar('\n');
- G.cur_x = 1;
+ G.cur_x = 0;
}
static PROC *find_proc(pid_t pid)
{
CHILD *walk, *next, **scan;
int lvl, i, add, offset, count, comm_len, first;
+ char tmp[sizeof(int)*3 + 4];
if (!current)
return;
}
}
- if (rep < 2)
- add = 0;
- else {
- add = printf("%d", rep) + 2;
- out_string("*[");
+ add = 0;
+ if (rep > 1) {
+ add += sprintf(tmp, "%d*[", rep);
+ out_string(tmp);
}
comm_len = out_args(current->comm);
if (option_mask32 /*& OPT_PID*/) {
- out_char('(');
- comm_len += printf("%d", (int)current->pid) + 2;
- out_char(')');
+ comm_len += sprintf(tmp, "(%d)", (int)current->pid);
+ out_string(tmp);
}
offset = G.cur_x;
G.more[level] = !last;
G.width[level] = comm_len + G.cur_x - offset + add;
-// if (G.cur_x >= G.output_width) {
-// out_string(first_3);
-// out_char('+');
-// out_newline();
-// return;
-// }
+ if (G.cur_x >= G.output_width) {
+ //out_string(first_3); - why? it won't print anything
+ //out_char('+');
+ out_newline();
+ return;
+ }
first = 1;
for (walk = current->children; walk; walk = next) {
long uid = 0;
INIT_G();
- G.cur_x = 1;
-// get_terminal_width_height(1, &G.output_width, NULL);
+ get_terminal_width_height(1, &G.output_width, NULL);
getopt32(argv, "p");
argv += optind;