top(1): support multibyte characters in command names (ARGV array)
depending on locale. - add setlocale() - remove printable() function - add VIS_OCTAL and VIS_SAFE to the flag of strvisx() to display non-printable characters that do not use C-style backslash sequences in three digit octal sequence, or remove it This change allows multibyte characters to be displayed according to locale. If it is recognized as a non-display character according to the locale, it is displayed in three digit octal sequence. Reference: https://www.mail-archive.com/svn-src-all@freebsd.org/msg165751.html https://www.mail-archive.com/svn-src-all@freebsd.org/msg165766.html https://www.mail-archive.com/svn-src-all@freebsd.org/msg165833.html https://www.mail-archive.com/svn-src-all@freebsd.org/msg165846.html https://www.mail-archive.com/svn-src-all@freebsd.org/msg165891.html Submitted by: hrs Differential Revision: https://reviews.freebsd.org/D16204
This commit is contained in:
parent
39404490b7
commit
b1de37fadd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=352558
@ -1291,31 +1291,6 @@ line_update(char *old, char *new, int start, int line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* printable(str) - make the string pointed to by "str" into one that is
|
|
||||||
* printable (i.e.: all ascii), by converting all non-printable
|
|
||||||
* characters into '?'. Replacements are done in place and a pointer
|
|
||||||
* to the original buffer is returned.
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *
|
|
||||||
printable(char str[])
|
|
||||||
{
|
|
||||||
char *ptr;
|
|
||||||
char ch;
|
|
||||||
|
|
||||||
ptr = str;
|
|
||||||
while ((ch = *ptr) != '\0')
|
|
||||||
{
|
|
||||||
if (!isprint(ch))
|
|
||||||
{
|
|
||||||
*ptr = '?';
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
return(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
i_uptime(struct timeval *bt, time_t *tod)
|
i_uptime(struct timeval *bt, time_t *tod)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,6 @@ int display_updatecpus(struct statics *statics);
|
|||||||
void clear_message(void);
|
void clear_message(void);
|
||||||
int display_resize(void);
|
int display_resize(void);
|
||||||
void i_header(const char *text);
|
void i_header(const char *text);
|
||||||
char *printable(char *string);
|
|
||||||
void display_header(int t);
|
void display_header(int t);
|
||||||
int display_init(struct statics *statics);
|
int display_init(struct statics *statics);
|
||||||
void i_arc(int *stats);
|
void i_arc(int *stats);
|
||||||
|
@ -1003,7 +1003,7 @@ format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags
|
|||||||
len = (argbuflen - (dst - argbuf) - 1) / 4;
|
len = (argbuflen - (dst - argbuf) - 1) / 4;
|
||||||
strvisx(dst, src,
|
strvisx(dst, src,
|
||||||
MIN(strlen(src), len),
|
MIN(strlen(src), len),
|
||||||
VIS_NL | VIS_CSTYLE);
|
VIS_NL | VIS_CSTYLE | VIS_OCTAL | VIS_SAFE);
|
||||||
while (*dst != '\0')
|
while (*dst != '\0')
|
||||||
dst++;
|
dst++;
|
||||||
if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
|
if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
|
||||||
@ -1102,7 +1102,7 @@ format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags
|
|||||||
sbuf_printf(procbuf, "%6s ", format_time(cputime));
|
sbuf_printf(procbuf, "%6s ", format_time(cputime));
|
||||||
sbuf_printf(procbuf, "%6.2f%% ", ps.wcpu ? 100.0 * weighted_cpu(PCTCPU(pp), pp) : 100.0 * PCTCPU(pp));
|
sbuf_printf(procbuf, "%6.2f%% ", ps.wcpu ? 100.0 * weighted_cpu(PCTCPU(pp), pp) : 100.0 * PCTCPU(pp));
|
||||||
}
|
}
|
||||||
sbuf_printf(procbuf, "%s", printable(cmdbuf));
|
sbuf_printf(procbuf, "%s", cmdbuf);
|
||||||
free(cmdbuf);
|
free(cmdbuf);
|
||||||
return (sbuf_data(procbuf));
|
return (sbuf_data(procbuf));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.Dd October 2, 2018
|
.Dd September 20, 2019
|
||||||
.Dt TOP 1
|
.Dt TOP 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -192,6 +192,10 @@ or
|
|||||||
\*(lqall\*(rq.
|
\*(lqall\*(rq.
|
||||||
Boolean flags are toggles.
|
Boolean flags are toggles.
|
||||||
A second specification of any of these options will negate the first.
|
A second specification of any of these options will negate the first.
|
||||||
|
.Pp
|
||||||
|
The display of command names changes according to the locale.
|
||||||
|
If command names displayed in the locale settings are recognized as
|
||||||
|
non-display characters, they are displayed in three digit octal sequence.
|
||||||
.Sh "INTERACTIVE MODE"
|
.Sh "INTERACTIVE MODE"
|
||||||
When
|
When
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <jail.h>
|
#include <jail.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -265,6 +266,11 @@ main(int argc, const char *argv[])
|
|||||||
setbuffer(stdout, stdoutbuf, Buffersize);
|
setbuffer(stdout, stdoutbuf, Buffersize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (setlocale(LC_ALL, "") == NULL) {
|
||||||
|
fprintf(stderr, "invalid locale.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|
||||||
/* get our name */
|
/* get our name */
|
||||||
|
Loading…
Reference in New Issue
Block a user