top(1): rollback r335836
Encoding-specific processing introduced in r335836 is not recommended. And doing getenv("LANG") and assuming an encoding based on it is a very bad practice to internationalize software. Submitted by: hrs Differential Revision: https://reviews.freebsd.org/D16203
This commit is contained in:
parent
82df14c3ab
commit
7452122499
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336160
@ -1275,43 +1275,19 @@ line_update(char *old, char *new, int start, int line)
|
|||||||
char *
|
char *
|
||||||
printable(char str[])
|
printable(char str[])
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
ptr = str;
|
ptr = str;
|
||||||
if (utf8flag) {
|
while ((ch = *ptr) != '\0')
|
||||||
while ((ch = *ptr) != '\0') {
|
{
|
||||||
if (0x00 == (0x80 & ch)) {
|
if (!isprint(ch))
|
||||||
if (!isprint(ch)) {
|
{
|
||||||
*ptr = '?';
|
*ptr = '?';
|
||||||
}
|
|
||||||
++ptr;
|
|
||||||
} else if (0xC0 == (0xE0 & ch)) {
|
|
||||||
++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
} else if (0xE0 == (0xF0 & ch)) {
|
|
||||||
++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
} else if (0xF0 == (0xF8 & ch)) {
|
|
||||||
++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
if ('\0' != *ptr) ++ptr;
|
|
||||||
} else {
|
|
||||||
*ptr = '?';
|
|
||||||
++ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while ((ch = *ptr) != '\0') {
|
|
||||||
if (!isprint(ch)) {
|
|
||||||
*ptr = '?';
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return(str);
|
ptr++;
|
||||||
|
}
|
||||||
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -985,13 +985,9 @@ format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags
|
|||||||
if (*src == '\0')
|
if (*src == '\0')
|
||||||
continue;
|
continue;
|
||||||
len = (argbuflen - (dst - argbuf) - 1) / 4;
|
len = (argbuflen - (dst - argbuf) - 1) / 4;
|
||||||
if (utf8flag) {
|
strvisx(dst, src,
|
||||||
utf8strvisx(dst, src, MIN(strlen(src), len));
|
MIN(strlen(src), len),
|
||||||
} else {
|
VIS_NL | VIS_CSTYLE);
|
||||||
strvisx(dst, src,
|
|
||||||
MIN(strlen(src), len),
|
|
||||||
VIS_NL | VIS_CSTYLE);
|
|
||||||
}
|
|
||||||
while (*dst != '\0')
|
while (*dst != '\0')
|
||||||
dst++;
|
dst++;
|
||||||
if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
|
if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
|
||||||
|
@ -69,7 +69,6 @@ static int max_topn; /* maximum displayable processes */
|
|||||||
struct process_select ps;
|
struct process_select ps;
|
||||||
const char * myname = "top";
|
const char * myname = "top";
|
||||||
pid_t mypid;
|
pid_t mypid;
|
||||||
bool utf8flag = false;
|
|
||||||
|
|
||||||
/* pointers to display routines */
|
/* pointers to display routines */
|
||||||
static void (*d_loadave)(int mpid, double *avenrun) = i_loadave;
|
static void (*d_loadave)(int mpid, double *avenrun) = i_loadave;
|
||||||
@ -607,14 +606,6 @@ main(int argc, char *argv[])
|
|||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if you are using UTF-8 */
|
|
||||||
char *env_lang;
|
|
||||||
if (NULL != (env_lang = getenv("LANG")) &&
|
|
||||||
0 != strcmp(env_lang, "") &&
|
|
||||||
NULL != strstr(env_lang, "UTF-8")) {
|
|
||||||
utf8flag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#define TOP_H
|
#define TOP_H
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
/* Number of lines of header information on the standard screen */
|
/* Number of lines of header information on the standard screen */
|
||||||
extern int Header_lines;
|
extern int Header_lines;
|
||||||
@ -35,7 +34,6 @@ extern enum displaymodes displaymode;
|
|||||||
extern int pcpu_stats;
|
extern int pcpu_stats;
|
||||||
extern int overstrike;
|
extern int overstrike;
|
||||||
extern pid_t mypid;
|
extern pid_t mypid;
|
||||||
extern bool utf8flag;
|
|
||||||
|
|
||||||
extern const char * myname;
|
extern const char * myname;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
* This program may be freely redistributed,
|
* This program may be freely redistributed,
|
||||||
* but this entire comment MUST remain intact.
|
* but this entire comment MUST remain intact.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2018, Daichi Goto
|
|
||||||
* Copyright (c) 2018, Eitan Adler
|
* Copyright (c) 2018, Eitan Adler
|
||||||
* Copyright (c) 1984, 1989, William LeFebvre, Rice University
|
* Copyright (c) 1984, 1989, William LeFebvre, Rice University
|
||||||
* Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
|
* Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
|
||||||
@ -329,61 +328,3 @@ find_pid(pid_t pid)
|
|||||||
kvm_close(kd);
|
kvm_close(kd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* utf8strvisx(dst,src,src_len)
|
|
||||||
* strvisx(dst,src,src_len,VIS_NL|VIS_CSTYLE) coresponding to UTF-8.
|
|
||||||
*/
|
|
||||||
static const char *vis_encodes[] = {
|
|
||||||
"\\0", "\\^A", "\\^B", "\\^C", "\\^D", "\\^E", "\\^F", "\\a",
|
|
||||||
"\\b", "\t", "\\n", "\\v", "\\f", "\\r", "\\^N", "\\^O", "\\^P",
|
|
||||||
"\\^Q", "\\^R", "\\^S", "\\^T", "\\^U", "\\^V", "\\^W", "\\^X",
|
|
||||||
"\\^Y", "\\^Z", "\\^[", "\\^\\", "\\^]", "\\^^", "\\^_"
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
utf8strvisx(char *dst, const char *src, size_t src_len)
|
|
||||||
{
|
|
||||||
const signed char *src_p;
|
|
||||||
char *dst_p;
|
|
||||||
int i, j, olen, len;
|
|
||||||
|
|
||||||
src_p = src;
|
|
||||||
dst_p = dst;
|
|
||||||
i = olen = 0;
|
|
||||||
len = (int)src_len;
|
|
||||||
while (i < len) {
|
|
||||||
if (0x00 == (0x80 & *src_p)) {
|
|
||||||
if (0 <= *src_p && *src_p <= 31) {
|
|
||||||
j = strlen(vis_encodes[(int)*src_p]);
|
|
||||||
strcpy(dst_p, vis_encodes[(int)*src_p]);
|
|
||||||
dst_p += j;
|
|
||||||
olen += j;
|
|
||||||
} else if (127 == *src_p) {
|
|
||||||
strcpy(dst_p, "\\^?");
|
|
||||||
olen += 3;
|
|
||||||
} else {
|
|
||||||
*dst_p++ = *src_p;
|
|
||||||
++olen;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
++src_p;
|
|
||||||
} else if (0xC0 == (0xE0 & *src_p)) {
|
|
||||||
*dst_p++ = *src_p++; ++i; ++olen;
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
} else if (0xE0 == (0xF0 & *src_p)) {
|
|
||||||
*dst_p++ = *src_p++; ++i; ++olen;
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
} else if (0xF0 == (0xF8 & *src_p)) {
|
|
||||||
*dst_p++ = *src_p++; ++i; ++olen;
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
if (i < len) { *dst_p++ = *src_p++; ++i; ++olen; }
|
|
||||||
} else {
|
|
||||||
*dst_p++ = '?'; ++i; ++olen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return olen;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user