diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-21 17:51:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-21 17:52:50 +0200 |
commit | 34d79c9aa0c2ba23f62e49134c337797b37d2878 (patch) | |
tree | 31823e4c65da4c2bd485b604ee38664e78c190db | |
parent | 51358757c709f9c489aa6b13b34141edf84183fa (diff) | |
download | busybox-w32-34d79c9aa0c2ba23f62e49134c337797b37d2878.tar.gz busybox-w32-34d79c9aa0c2ba23f62e49134c337797b37d2878.tar.bz2 busybox-w32-34d79c9aa0c2ba23f62e49134c337797b37d2878.zip |
ascii: new applet
function old new delta
.rodata 103397 103670 +273
ascii_main - 177 +177
applet_names 2739 2745 +6
applet_main 1584 1588 +4
applet_suid 99 100 +1
applet_install_loc 198 199 +1
packed_usage 33716 33713 -3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 462/-3) Total: 459 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/ascii.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/miscutils/ascii.c b/miscutils/ascii.c new file mode 100644 index 000000000..98c11fa51 --- /dev/null +++ b/miscutils/ascii.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright (C) 2021 Denys Vlasenko <vda.linux@googlemail.com> | ||
4 | * | ||
5 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
6 | */ | ||
7 | //config:config ASCII | ||
8 | //config: bool "ascii" | ||
9 | //config: default y | ||
10 | //config: help | ||
11 | //config: Print ascii table. | ||
12 | //config: | ||
13 | |||
14 | //applet:IF_ASCII(APPLET(ascii, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
15 | |||
16 | //kbuild:lib-$(CONFIG_ASCII) += ascii.o | ||
17 | |||
18 | //usage:#define ascii_trivial_usage NOUSAGE_STR | ||
19 | //usage:#define ascii_full_usage "" | ||
20 | |||
21 | #include "libbb.h" | ||
22 | |||
23 | int ascii_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
24 | int ascii_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | ||
25 | { | ||
26 | const char *ctrl = | ||
27 | "NUL""SOH""STX""ETX""EOT""ENQ""ACK""BEL" | ||
28 | "BS ""HT ""NL ""VT ""FF ""CR ""SO ""SI " | ||
29 | "DLE""DC1""DC2""DC3""DC4""NAK""SYN""ETB" | ||
30 | "CAN""EM ""SUB""ESC""FS ""GS ""RS ""US " | ||
31 | ; | ||
32 | //TODO: od has a similar table, can we reuse it? | ||
33 | char last[2]; | ||
34 | unsigned i; | ||
35 | |||
36 | last[1] = '\0'; | ||
37 | printf("Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex Dec Hex\n"); | ||
38 | for (i = 0; i < 16; i++) { | ||
39 | printf("%3u %02x %.3s%4u %02x %.3s%4u %02x %c%4u %02x %c%4u %02x %c%4u %02x %c%5u %02x %c%5u %02x %s\n", | ||
40 | i+0x00, i+0x00, ctrl + i*3, | ||
41 | i+0x10, i+0x10, ctrl + i*3 + 16*3, | ||
42 | i+0x20, i+0x20, i+0x20, | ||
43 | i+0x30, i+0x30, i+0x30, | ||
44 | i+0x40, i+0x40, i+0x40, | ||
45 | i+0x50, i+0x50, i+0x50, | ||
46 | i+0x60, i+0x60, i+0x60, | ||
47 | i+0x70, i+0x70, (i+0x70 == 0x7f ? "DEL" : (last[0] = i+0x70, last)) | ||
48 | ); | ||
49 | } | ||
50 | return EXIT_SUCCESS; | ||
51 | } | ||