Page MenuHomeFreeBSD

D16203.id45090.diff
No OneTemporary

D16203.id45090.diff

Index: usr.bin/top/display.h
===================================================================
--- usr.bin/top/display.h
+++ usr.bin/top/display.h
@@ -11,7 +11,6 @@
void clear_message(void);
int display_resize(void);
void i_header(const char *text);
-char *printable(char *string);
void display_header(int t);
int display_init(struct statics *statics);
void i_arc(int *stats);
Index: usr.bin/top/display.c
===================================================================
--- usr.bin/top/display.c
+++ usr.bin/top/display.c
@@ -1265,55 +1265,6 @@
}
}
-/*
- * 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;
- if (utf8flag) {
- while ((ch = *ptr) != '\0') {
- if (0x00 == (0x80 & ch)) {
- if (!isprint(ch)) {
- *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);
-}
-
void
i_uptime(struct timeval *bt, time_t *tod)
{
Index: usr.bin/top/machine.c
===================================================================
--- usr.bin/top/machine.c
+++ usr.bin/top/machine.c
@@ -985,13 +985,8 @@
if (*src == '\0')
continue;
len = (argbuflen - (dst - argbuf) - 1) / 4;
- if (utf8flag) {
- utf8strvisx(dst, src, MIN(strlen(src), len));
- } else {
- strvisx(dst, src,
- MIN(strlen(src), len),
- VIS_NL | VIS_CSTYLE);
- }
+ strvisx(dst, src, MIN(strlen(src), len),
+ VIS_NL | VIS_CSTYLE | VIS_OCTAL);
while (*dst != '\0')
dst++;
if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
@@ -1088,7 +1083,7 @@
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, "%s", printable(cmdbuf));
+ sbuf_printf(procbuf, "%s", cmdbuf);
free(cmdbuf);
return (sbuf_data(procbuf));
}
Index: usr.bin/top/top.h
===================================================================
--- usr.bin/top/top.h
+++ usr.bin/top/top.h
@@ -8,7 +8,6 @@
#define TOP_H
#include <unistd.h>
-#include <stdbool.h>
/* Number of lines of header information on the standard screen */
extern int Header_lines;
@@ -35,7 +34,6 @@
extern int pcpu_stats;
extern int overstrike;
extern pid_t mypid;
-extern bool utf8flag;
extern const char * myname;
Index: usr.bin/top/top.c
===================================================================
--- usr.bin/top/top.c
+++ usr.bin/top/top.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include <getopt.h>
#include <jail.h>
+#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -69,7 +70,6 @@
struct process_select ps;
const char * myname = "top";
pid_t mypid;
-bool utf8flag = false;
/* pointers to display routines */
static void (*d_loadave)(int mpid, double *avenrun) = i_loadave;
@@ -276,6 +276,11 @@
}
}
+ if (setlocale(LC_ALL, "") == NULL) {
+ fprintf(stderr, "%s: invalid locale.\n", myname);
+ exit(1);
+ }
+
mypid = getpid();
/* get our name */
@@ -607,14 +612,6 @@
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:
/*
Index: usr.bin/top/utils.h
===================================================================
--- usr.bin/top/utils.h
+++ usr.bin/top/utils.h
@@ -22,5 +22,4 @@
char *format_k(int64_t);
int string_index(const char *string, const char * const *array);
int find_pid(pid_t pid);
-int utf8strvisx(char *, const char *, size_t);
Index: usr.bin/top/utils.c
===================================================================
--- usr.bin/top/utils.c
+++ usr.bin/top/utils.c
@@ -2,7 +2,6 @@
* This program may be freely redistributed,
* but this entire comment MUST remain intact.
*
- * Copyright (c) 2018, Daichi Goto
* Copyright (c) 2018, Eitan Adler
* Copyright (c) 1984, 1989, William LeFebvre, Rice University
* Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
@@ -329,61 +328,3 @@
kvm_close(kd);
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;
-}

File Metadata

Mime Type
text/plain
Expires
Thu, Sep 3, 11:19 AM (48 m, 29 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38104711
Default Alt Text
D16203.id45090.diff (6 KB)

Event Timeline