aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-12-30 01:59:53 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-12-30 01:59:53 +0000
commitd3c042fc605737643c265a7f86fc7a77c88f629e (patch)
treea1850a3ca6493fb6409e8df0a24baf1331d325f6
parentfcd878efcd6df8a8d052cef753305c34c1297267 (diff)
downloadbusybox-w32-d3c042fc605737643c265a7f86fc7a77c88f629e.tar.gz
busybox-w32-d3c042fc605737643c265a7f86fc7a77c88f629e.tar.bz2
busybox-w32-d3c042fc605737643c265a7f86fc7a77c88f629e.zip
libbb: introduce fputc_printable (from ed)
netstat: print control chars as ^C etc vi: style fixlet function old new delta fputc_printable - 100 +100 unix_do_one 451 487 +36 printLines 258 190 -68 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 136/-68) Total: 68 bytes
-rw-r--r--editors/ed.c16
-rw-r--r--editors/vi.c2
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/Kbuild1
-rw-r--r--networking/netstat.c17
5 files changed, 19 insertions, 22 deletions
diff --git a/editors/ed.c b/editors/ed.c
index cceff0c40..a569788ad 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -847,20 +847,8 @@ static int printLines(int num1, int num2, int expandFlag)
847 count--; 847 count--;
848 848
849 while (count-- > 0) { 849 while (count-- > 0) {
850 ch = *cp++; 850 ch = (unsigned char) *cp++;
851 if (ch & 0x80) { 851 fputc_printable(ch | PRINTABLE_META, stdout);
852 fputs("M-", stdout);
853 ch &= 0x7f;
854 }
855 if (ch < ' ') {
856 bb_putchar('^');
857 ch += '@';
858 }
859 if (ch == 0x7f) {
860 bb_putchar('^');
861 ch = '?';
862 }
863 bb_putchar(ch);
864 } 852 }
865 853
866 fputs("$\n", stdout); 854 fputs("$\n", stdout);
diff --git a/editors/vi.c b/editors/vi.c
index b6d4dcf0d..d8492fe74 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -899,7 +899,7 @@ static void colon(char *buf)
899 if (c_is_no_print) { 899 if (c_is_no_print) {
900 c = '.'; 900 c = '.';
901 standout_start(); 901 standout_start();
902 } 902 }
903 if (c == '\n') { 903 if (c == '\n') {
904 write1("$\r"); 904 write1("$\r");
905 } else if (c < ' ' || c == 127) { 905 } else if (c < ' ' || c == 127) {
diff --git a/include/libbb.h b/include/libbb.h
index 1da37edb2..f35f85c33 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -426,6 +426,11 @@ char *safe_strncpy(char *dst, const char *src, size_t size);
426 * But potentially slow, don't use in one-billion-times loops */ 426 * But potentially slow, don't use in one-billion-times loops */
427int bb_putchar(int ch); 427int bb_putchar(int ch);
428char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 428char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
429/* Prints unprintable chars ch as ^C or M-c to file
430 * (M-c is used only if ch is ORed with PRINTABLE_META),
431 * else it is printed as-is (except for ch = 0x9b) */
432enum { PRINTABLE_META = 0x100 };
433void fputc_printable(int ch, FILE *file);
429// gcc-4.1.1 still isn't good enough at optimizing it 434// gcc-4.1.1 still isn't good enough at optimizing it
430// (+200 bytes compared to macro) 435// (+200 bytes compared to macro)
431//static ALWAYS_INLINE 436//static ALWAYS_INLINE
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 6791299f2..c4aac95bb 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -65,6 +65,7 @@ lib-y += perror_msg_and_die.o
65lib-y += perror_nomsg.o 65lib-y += perror_nomsg.o
66lib-y += perror_nomsg_and_die.o 66lib-y += perror_nomsg_and_die.o
67lib-y += pidfile.o 67lib-y += pidfile.o
68lib-y += printable.o
68lib-y += process_escape_sequence.o 69lib-y += process_escape_sequence.o
69lib-y += procps.o 70lib-y += procps.o
70lib-y += read.o 71lib-y += read.o
diff --git a/networking/netstat.c b/networking/netstat.c
index 29c2384a4..348abd8ad 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -349,13 +349,9 @@ static int unix_do_one(int nr, char *line)
349 const char *ss_proto, *ss_state, *ss_type; 349 const char *ss_proto, *ss_state, *ss_type;
350 char ss_flags[32]; 350 char ss_flags[32];
351 351
352 /* TODO: currently we stop at first NUL byte. Is it a problem? */
353
354 if (nr == 0) 352 if (nr == 0)
355 return 0; /* skip header */ 353 return 0; /* skip header */
356 354
357 *strchrnul(line, '\n') = '\0';
358
359 /* 2.6.15 may report lines like "... @/tmp/fam-user-^@^@^@^@^@^@^@..." 355 /* 2.6.15 may report lines like "... @/tmp/fam-user-^@^@^@^@^@^@^@..."
360 * Other users report long lines filled by NUL bytes. 356 * Other users report long lines filled by NUL bytes.
361 * (those ^@ are NUL bytes too). We see them as empty lines. */ 357 * (those ^@ are NUL bytes too). We see them as empty lines. */
@@ -443,9 +439,16 @@ static int unix_do_one(int nr, char *line)
443 strcat(ss_flags, "N "); 439 strcat(ss_flags, "N ");
444 strcat(ss_flags, "]"); 440 strcat(ss_flags, "]");
445 441
446 printf("%-5s %-6ld %-11s %-10s %-13s %6lu %s\n", 442 printf("%-5s %-6ld %-11s %-10s %-13s %6lu ",
447 ss_proto, refcnt, ss_flags, ss_type, ss_state, inode, 443 ss_proto, refcnt, ss_flags, ss_type, ss_state, inode
448 line + path_ofs); 444 );
445
446 /* TODO: currently we stop at first NUL byte. Is it a problem? */
447 line += path_ofs;
448 *strchrnul(line, '\n') = '\0';
449 while (*line)
450 fputc_printable(*line++, stdout);
451 bb_putchar('\n');
449 return 0; 452 return 0;
450} 453}
451 454