Bernd Eckenfels wrote:
On Sat, Jun 11, 2005 at 11:47:23PM +0200, Olaf van der Spek wrote:
Also, where is the upstream source code?
Yes I was talking about minding columns if --wide is given. We could perhaps
add a check to see if stdout is a terminal and asume --wide on default.
Hi Bernd,
Please have a look at the attached patch.
It's not ready yet, but what do you think of it?
151a152,155
> int flag_wide = 0;
>
> int local_addr_width = 23;
> int rem_addr_width = 23;
782,783c786,787
< if ((strlen(local_addr) + strlen(buffer)) > 22)
< local_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(local_addr) + strlen(buffer) + 1) > local_addr_width)
> local_addr[local_addr_width - strlen(buffer) - 1] = '\0';
790,791c794,795
< if ((strlen(rem_addr) + strlen(buffer)) > 22)
< rem_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(rem_addr) + strlen(buffer) + 1) > rem_addr_width)
> rem_addr[rem_addr_width - strlen(buffer) - 1] = '\0';
824c828
< protname, rxq, txq, netmax(23,strlen(local_addr)), local_addr,
netmax(23,strlen(rem_addr)), rem_addr, _(tcp_state[state]));
---
> protname, rxq, txq, netmax(local_addr_width,strlen(local_addr)),
> local_addr, netmax(rem_addr_width,strlen(rem_addr)), rem_addr,
> _(tcp_state[state]));
935,936c939,940
< if ((strlen(local_addr) + strlen(buffer)) > 22)
< local_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(local_addr) + strlen(buffer) + 1) > local_addr_width)
> local_addr[local_addr_width - strlen(buffer) - 1] = '\0';
944,945c948,949
< if ((strlen(rem_addr) + strlen(buffer)) > 22)
< rem_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(rem_addr) + strlen(buffer) + 1) > rem_addr_width)
> rem_addr[rem_addr_width - strlen(buffer) - 1] = '\0';
966,967c970,971
< printf("%-4s %6ld %6ld %-23s %-23s %-11s",
< protname, rxq, txq, local_addr, rem_addr, udp_state);
---
> printf("%-4s %6ld %6ld %-*s %-*s %-11s",
> protname, rxq, txq, local_addr_width, local_addr,
> rem_addr_width, rem_addr, udp_state);
1057,1058c1061,1062
< if ((strlen(local_addr) + strlen(buffer)) > 22)
< local_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(local_addr) + strlen(buffer) + 1) > local_addr_width)
> local_addr[local_addr_width - strlen(buffer) - 1] = '\0';
1066,1067c1070,1071
< if ((strlen(rem_addr) + strlen(buffer)) > 22)
< rem_addr[22 - strlen(buffer)] = '\0';
---
> if ((strlen(rem_addr) + strlen(buffer) + 1) > rem_addr_width)
> rem_addr[rem_addr_width - strlen(buffer) - 1] = '\0';
1090,1091c1094,1095
< printf("%-4s %6ld %6ld %-23s %-23s %-11d",
< protname, rxq, txq, local_addr, rem_addr, state);
---
> printf("%-4s %6ld %6ld %-*s %-*s %-11d",
> protname, rxq, txq, local_addr_width, local_addr,
> rem_addr_width, rem_addr, state);
1556a1561
> {"wide", 0, 0, '$'},
1627a1633,1635
> case '$':
> flag_wide = 1;
> break;
1763c1771,1779
< printf(_("\nProto Recv-Q Send-Q Local Address Foreign
Address State ")); /* xxx */
---
> if (flag_wide)
> {
> local_addr_width = 33;
> rem_addr_width = 33;
> }
> printf(_("\nProto Recv-Q Send-Q ")); /* xxx */
> printf("%-*s ", local_addr_width, _("Local Address"));
> printf("%-*s ", rem_addr_width, _("Foreign Address"));
> printf(_("State "));