w: do not truncate command when width is not known
Merge remote-tracking branch 'sami/2012wk28'
This commit is contained in:
commit
f7eb5a49a0
12
w.c
12
w.c
@ -69,6 +69,8 @@ typedef struct utmp utmp_t;
|
|||||||
# define FROM_STRING "off"
|
# define FROM_STRING "off"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_CMD_WIDTH 512
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine is careful since some programs leave utmp strings
|
* This routine is careful since some programs leave utmp strings
|
||||||
* unprintable. Always outputs at least 16 chars padded with
|
* unprintable. Always outputs at least 16 chars padded with
|
||||||
@ -419,7 +421,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
}
|
}
|
||||||
fputs(" ", stdout);
|
fputs(" ", stdout);
|
||||||
if (likely(best)) {
|
if (likely(best)) {
|
||||||
char cmdbuf[512];
|
char cmdbuf[MAX_CMD_WIDTH];
|
||||||
escape_command(cmdbuf, best, sizeof cmdbuf, &maxcmd, ESC_ARGS);
|
escape_command(cmdbuf, best, sizeof cmdbuf, &maxcmd, ESC_ARGS);
|
||||||
fputs(cmdbuf, stdout);
|
fputs(cmdbuf, stdout);
|
||||||
} else {
|
} else {
|
||||||
@ -554,10 +556,14 @@ int main(int argc, char **argv)
|
|||||||
else if ((p = getenv("COLUMNS")))
|
else if ((p = getenv("COLUMNS")))
|
||||||
maxcmd = atoi(p);
|
maxcmd = atoi(p);
|
||||||
else
|
else
|
||||||
maxcmd = 80;
|
maxcmd = MAX_CMD_WIDTH;
|
||||||
if (maxcmd < 71)
|
if (maxcmd < 71)
|
||||||
xerrx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
|
xerrx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
|
||||||
|
if (MAX_CMD_WIDTH < maxcmd) {
|
||||||
|
xwarnx(_("%d column width exceeds command buffer size, truncating to %d"),
|
||||||
|
maxcmd, MAX_CMD_WIDTH);
|
||||||
|
maxcmd = MAX_CMD_WIDTH;
|
||||||
|
}
|
||||||
maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
|
maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
|
||||||
if (maxcmd < 3)
|
if (maxcmd < 3)
|
||||||
xwarnx(_("warning: screen width %d suboptimal"), win.ws_col);
|
xwarnx(_("warning: screen width %d suboptimal"), win.ws_col);
|
||||||
|
Loading…
Reference in New Issue
Block a user