summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-09-27 10:08:12 +0100
committerRon Yorston <rmy@pobox.com>2017-09-27 10:11:19 +0100
commitd9383e984da8de72e61e5094a3cf6404c5707ddc (patch)
treedd42825854fc42aea40d4f7a95548d53721d1733 /miscutils
parent166b3e4e82799f87d3b002c7177891111eff079e (diff)
parent0c4dbd481aedb5d22c1048e7f7eb547a3b5e50a5 (diff)
downloadbusybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.gz
busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.tar.bz2
busybox-w32-d9383e984da8de72e61e5094a3cf6404c5707ddc.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/beep.c1
-rw-r--r--miscutils/chat.c10
-rw-r--r--miscutils/fbsplash.c6
-rw-r--r--miscutils/hexedit.c465
-rw-r--r--miscutils/i2c_tools.c109
-rw-r--r--miscutils/less.c28
-rw-r--r--miscutils/microcom.c14
-rw-r--r--miscutils/nandwrite.c1
-rw-r--r--miscutils/raidautorun.c1
-rw-r--r--miscutils/rfkill.c13
-rw-r--r--miscutils/setfattr.c68
-rw-r--r--miscutils/setserial.c1
-rw-r--r--miscutils/ubi_tools.c1
13 files changed, 631 insertions, 87 deletions
diff --git a/miscutils/beep.c b/miscutils/beep.c
index b9b62f79b..0c8a8225e 100644
--- a/miscutils/beep.c
+++ b/miscutils/beep.c
@@ -5,7 +5,6 @@
5 * Copyright (C) 2009 Bernhard Reutner-Fischer 5 * Copyright (C) 2009 Bernhard Reutner-Fischer
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 *
9 */ 8 */
10//config:config BEEP 9//config:config BEEP
11//config: bool "beep (3 kb)" 10//config: bool "beep (3 kb)"
diff --git a/miscutils/chat.c b/miscutils/chat.c
index 1446a040c..2dfe52c4f 100644
--- a/miscutils/chat.c
+++ b/miscutils/chat.c
@@ -238,10 +238,18 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
238 , *argv 238 , *argv
239 ); 239 );
240 if (key >= 0) { 240 if (key >= 0) {
241 bool onoff;
241 // cache directive value 242 // cache directive value
242 char *arg = *++argv; 243 char *arg = *++argv;
244
245 if (!arg) {
246#if ENABLE_FEATURE_CHAT_TTY_HIFI
247 tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0);
248#endif
249 bb_show_usage();
250 }
243 // OFF -> 0, anything else -> 1 251 // OFF -> 0, anything else -> 1
244 bool onoff = (0 != strcmp("OFF", arg)); 252 onoff = (0 != strcmp("OFF", arg));
245 // process directive 253 // process directive
246 if (DIR_HANGUP == key) { 254 if (DIR_HANGUP == key) {
247 // turn SIGHUP on/off 255 // turn SIGHUP on/off
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 9ac91e01e..5b2e5ac56 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -65,6 +65,8 @@
65/* If you want logging messages on /tmp/fbsplash.log... */ 65/* If you want logging messages on /tmp/fbsplash.log... */
66#define DEBUG 0 66#define DEBUG 0
67 67
68#define ESC "\033"
69
68struct globals { 70struct globals {
69#if DEBUG 71#if DEBUG
70 bool bdebug_messages; // enable/disable logging 72 bool bdebug_messages; // enable/disable logging
@@ -514,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
514 516
515 if (fifo_filename && bCursorOff) { 517 if (fifo_filename && bCursorOff) {
516 // hide cursor (BEFORE any fb ops) 518 // hide cursor (BEFORE any fb ops)
517 full_write(STDOUT_FILENO, "\033[?25l", 6); 519 full_write(STDOUT_FILENO, ESC"[?25l", 6);
518 } 520 }
519 521
520 fb_drawimage(); 522 fb_drawimage();
@@ -559,7 +561,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
559 } 561 }
560 562
561 if (bCursorOff) // restore cursor 563 if (bCursorOff) // restore cursor
562 full_write(STDOUT_FILENO, "\033[?25h", 6); 564 full_write(STDOUT_FILENO, ESC"[?25h", 6);
563 565
564 return EXIT_SUCCESS; 566 return EXIT_SUCCESS;
565} 567}
diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c
new file mode 100644
index 000000000..bafb834b5
--- /dev/null
+++ b/miscutils/hexedit.c
@@ -0,0 +1,465 @@
1/*
2 * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
3 *
4 * Licensed under GPLv2, see file LICENSE in this source tree.
5 */
6//config:config HEXEDIT
7//config: bool "hexedit"
8//config: default y
9//config: help
10//config: Edit file in hexadecimal.
11
12//applet:IF_HEXEDIT(APPLET(hexedit, BB_DIR_USR_BIN, BB_SUID_DROP))
13
14//kbuild:lib-$(CONFIG_HEXEDIT) += hexedit.o
15
16#include "libbb.h"
17
18#define ESC "\033"
19#define HOME ESC"[H"
20#define CLEAR ESC"[J"
21#define CLEAR_TILL_EOL ESC"[K"
22#define SET_ALT_SCR ESC"[?1049h"
23#define POP_ALT_SCR ESC"[?1049l"
24
25#undef CTRL
26#define CTRL(c) ((c) & (uint8_t)~0x60)
27
28struct globals {
29 smallint half;
30 smallint in_read_key;
31 int fd;
32 unsigned height;
33 unsigned row;
34 unsigned pagesize;
35 uint8_t *baseaddr;
36 uint8_t *current_byte;
37 uint8_t *eof_byte;
38 off_t size;
39 off_t offset;
40 /* needs to be zero-inited, thus keeping it in G: */
41 char read_key_buffer[KEYCODE_BUFFER_SIZE];
42 struct termios orig_termios;
43};
44#define G (*ptr_to_globals)
45#define INIT_G() do { \
46 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
47} while (0)
48
49//TODO: move to libbb
50#if defined(__x86_64__) || defined(i386)
51# define G_pagesize 4096
52# define INIT_PAGESIZE() ((void)0)
53#else
54# define G_pagesize (G.pagesize)
55# define INIT_PAGESIZE() ((void)(G.pagesize = getpagesize()))
56#endif
57
58/* hopefully there aren't arches with PAGE_SIZE > 64k */
59#define G_mapsize (64*1024)
60
61/* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */
62#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13)
63
64static void restore_term(void)
65{
66 tcsetattr_stdin_TCSANOW(&G.orig_termios);
67 printf(POP_ALT_SCR);
68 fflush_all();
69}
70
71static void sig_catcher(int sig)
72{
73 if (!G.in_read_key) {
74 /* now it's not safe to do I/O, just inform the main loop */
75 bb_got_signal = sig;
76 return;
77 }
78 restore_term();
79 kill_myself_with_sig(sig);
80}
81
82static int format_line(char *hex, uint8_t *data, off_t offset)
83{
84 int ofs_pos;
85 char *text;
86 uint8_t *end, *end1;
87
88#if 1
89 /* Can be more than 4Gb, thus >8 chars, thus use a variable - don't assume 8! */
90 ofs_pos = sprintf(hex, "%08"OFF_FMT"x ", offset);
91#else
92 if (offset <= 0xffff)
93 ofs_pos = sprintf(hex, "%04"OFF_FMT"x ", offset);
94 else
95 ofs_pos = sprintf(hex, "%08"OFF_FMT"x ", offset);
96#endif
97 hex += ofs_pos;
98
99 text = hex + 16 * 3;
100 end1 = data + 15;
101 if ((G.size - offset) > 0) {
102 end = end1;
103 if ((G.size - offset) <= 15)
104 end = data + (G.size - offset) - 1;
105 while (data <= end) {
106 uint8_t c = *data++;
107 *hex++ = bb_hexdigits_upcase[c >> 4];
108 *hex++ = bb_hexdigits_upcase[c & 0xf];
109 *hex++ = ' ';
110 if (c < ' ' || c > 0x7e)
111 c = '.';
112 *text++ = c;
113 }
114 }
115 while (data <= end1) {
116 *hex++ = ' ';
117 *hex++ = ' ';
118 *hex++ = ' ';
119 *text++ = ' ';
120 data++;
121 }
122 *text = '\0';
123
124 return ofs_pos;
125}
126
127static void redraw(unsigned cursor)
128{
129 uint8_t *data;
130 off_t offset;
131 unsigned i, pos;
132
133 printf(HOME CLEAR);
134
135 /* if cursor is past end of screen, how many lines to move down? */
136 i = (cursor / 16) - G.height + 1;
137 if ((int)i < 0)
138 i = 0;
139
140 data = G.baseaddr + i * 16;
141 offset = G.offset + i * 16;
142 cursor -= i * 16;
143 pos = i = 0;
144 while (i < G.height) {
145 char buf[LINEBUF_SIZE];
146 pos = format_line(buf, data, offset);
147 printf(
148 "\r\n%s" + (!i) * 2, /* print \r\n only on 2nd line and later */
149 buf
150 );
151 data += 16;
152 offset += 16;
153 i++;
154 }
155
156 printf(ESC"[%u;%uH", 1 + cursor / 16, 1 + pos + (cursor & 0xf) * 3);
157}
158
159static void redraw_cur_line(void)
160{
161 char buf[LINEBUF_SIZE];
162 uint8_t *data;
163 off_t offset;
164 int column;
165
166 column = (0xf & (uintptr_t)G.current_byte);
167 data = G.current_byte - column;
168 offset = G.offset + (data - G.baseaddr);
169
170 column = column*3 + G.half;
171 column += format_line(buf, data, offset);
172 printf("%s"
173 "\r"
174 "%.*s",
175 buf + column,
176 column, buf
177 );
178}
179
180/* if remappers return 0, no change was done */
181static int remap(unsigned cur_pos)
182{
183 if (G.baseaddr)
184 munmap(G.baseaddr, G_mapsize);
185
186 G.baseaddr = mmap(NULL,
187 G_mapsize,
188 PROT_READ | PROT_WRITE,
189 MAP_SHARED,
190 G.fd,
191 G.offset
192 );
193 if (G.baseaddr == MAP_FAILED) {
194 restore_term();
195 bb_perror_msg_and_die("mmap");
196 }
197
198 G.current_byte = G.baseaddr + cur_pos;
199
200 G.eof_byte = G.baseaddr + G_mapsize;
201 if ((G.size - G.offset) < G_mapsize) {
202 /* mapping covers tail of the file */
203 /* we do have a mapped byte which is past eof */
204 G.eof_byte = G.baseaddr + (G.size - G.offset);
205 }
206 return 1;
207}
208static int move_mapping_further(void)
209{
210 unsigned pos;
211 unsigned pagesize;
212
213 if ((G.size - G.offset) < G_mapsize)
214 return 0; /* can't move mapping even further, it's at the end already */
215
216 pagesize = G_pagesize; /* constant on most arches */
217 pos = G.current_byte - G.baseaddr;
218 if (pos >= pagesize) {
219 /* move offset up until current position is in 1st page */
220 do {
221 G.offset += pagesize;
222 if (G.offset == 0) { /* whoops */
223 G.offset -= pagesize;
224 break;
225 }
226 pos -= pagesize;
227 } while (pos >= pagesize);
228 return remap(pos);
229 }
230 return 0;
231}
232static int move_mapping_lower(void)
233{
234 unsigned pos;
235 unsigned pagesize;
236
237 if (G.offset == 0)
238 return 0; /* we are at 0 already */
239
240 pagesize = G_pagesize; /* constant on most arches */
241 pos = G.current_byte - G.baseaddr;
242
243 /* move offset down until current position is in last page */
244 pos += pagesize;
245 while (pos < G_mapsize) {
246 pos += pagesize;
247 G.offset -= pagesize;
248 if (G.offset == 0)
249 break;
250 }
251 pos -= pagesize;
252
253 return remap(pos);
254}
255
256//usage:#define hexedit_trivial_usage
257//usage: "FILE"
258//usage:#define hexedit_full_usage "\n\n"
259//usage: "Edit FILE in hexadecimal"
260int hexedit_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
261int hexedit_main(int argc UNUSED_PARAM, char **argv)
262{
263 INIT_G();
264 INIT_PAGESIZE();
265
266 get_terminal_width_height(-1, NULL, &G.height);
267 if (1) {
268 /* reduce number of write() syscalls while PgUp/Down: fully buffered output */
269 unsigned sz = (G.height | 0xf) * LINEBUF_SIZE;
270 setvbuf(stdout, xmalloc(sz), _IOFBF, sz);
271 }
272
273 getopt32(argv, "^" "" "\0" "=1"/*one arg*/);
274 argv += optind;
275
276 G.fd = xopen(*argv, O_RDWR);
277 G.size = xlseek(G.fd, 0, SEEK_END);
278
279 /* TERMIOS_RAW_CRNL suppresses \n -> \r\n translation, helps with down-arrow */
280 printf(SET_ALT_SCR);
281 set_termios_to_raw(STDIN_FILENO, &G.orig_termios, TERMIOS_RAW_CRNL);
282 bb_signals(BB_FATAL_SIGS, sig_catcher);
283
284 remap(0);
285 redraw(0);
286
287//TODO: //Home/End: start/end of line; '<'/'>': start/end of file
288 //Backspace: undo
289 //Ctrl-L: redraw
290 //Ctrl-Z: suspend
291 //'/', Ctrl-S: search
292//TODO: detect window resize
293
294 for (;;) {
295 unsigned cnt;
296 int32_t key = key; /* for compiler */
297 uint8_t byte;
298
299 fflush_all();
300 G.in_read_key = 1;
301 if (!bb_got_signal)
302 key = read_key(STDIN_FILENO, G.read_key_buffer, -1);
303 G.in_read_key = 0;
304 if (bb_got_signal)
305 key = CTRL('X');
306
307 cnt = 1;
308 if ((unsigned)(key - 'A') <= 'Z' - 'A')
309 key |= 0x20; /* convert A-Z to a-z */
310 switch (key) {
311 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
312 /* convert to '0'+10...15 */
313 key = key - ('a' - '0' - 10);
314 /* fall through */
315 case '0': case '1': case '2': case '3': case '4':
316 case '5': case '6': case '7': case '8': case '9':
317 if (G.current_byte == G.eof_byte) {
318 if (!move_mapping_further()) {
319 /* already at EOF; extend the file */
320 if (++G.size <= 0 /* overflow? */
321 || ftruncate(G.fd, G.size) != 0 /* error extending? (e.g. block dev) */
322 ) {
323 G.size--;
324 break;
325 }
326 G.eof_byte++;
327 }
328 }
329 key -= '0';
330 byte = *G.current_byte & 0xf0;
331 if (!G.half) {
332 byte = *G.current_byte & 0x0f;
333 key <<= 4;
334 }
335 *G.current_byte = byte + key;
336 /* can't just print one updated hex char: need to update right-hand ASCII too */
337 redraw_cur_line();
338 /* fall through */
339 case KEYCODE_RIGHT:
340 if (G.current_byte == G.eof_byte)
341 break; /* eof - don't allow going past it */
342 byte = *G.current_byte;
343 if (!G.half) {
344 G.half = 1;
345 putchar(bb_hexdigits_upcase[byte >> 4]);
346 } else {
347 G.half = 0;
348 G.current_byte++;
349 if ((0xf & (uintptr_t)G.current_byte) == 0) {
350 /* rightmost pos, wrap to next line */
351 if (G.current_byte == G.eof_byte)
352 move_mapping_further();
353 printf(ESC"[46D"); /* cursor left 3*15 + 1 chars */
354 goto down;
355 }
356 putchar(bb_hexdigits_upcase[byte & 0xf]);
357 putchar(' ');
358 }
359 break;
360 case KEYCODE_PAGEDOWN:
361 cnt = G.height;
362 case KEYCODE_DOWN:
363 k_down:
364 G.current_byte += 16;
365 if (G.current_byte >= G.eof_byte) {
366 move_mapping_further();
367 if (G.current_byte > G.eof_byte) {
368 /* _after_ eof - don't allow this */
369 G.current_byte -= 16;
370 break;
371 }
372 }
373 down:
374 putchar('\n'); /* down one line, possibly scroll screen */
375 G.row++;
376 if (G.row >= G.height) {
377 G.row--;
378 redraw_cur_line();
379 }
380 if (--cnt)
381 goto k_down;
382 break;
383
384 case KEYCODE_LEFT:
385 if (G.half) {
386 G.half = 0;
387 printf(ESC"[D");
388 break;
389 }
390 if ((0xf & (uintptr_t)G.current_byte) == 0) {
391 /* leftmost pos, wrap to prev line */
392 if (G.current_byte == G.baseaddr) {
393 if (!move_mapping_lower())
394 break; /* first line, don't do anything */
395 }
396 G.half = 1;
397 G.current_byte--;
398 printf(ESC"[46C"); /* cursor right 3*15 + 1 chars */
399 goto up;
400 }
401 G.half = 1;
402 G.current_byte--;
403 printf(ESC"[2D");
404 break;
405 case KEYCODE_PAGEUP:
406 cnt = G.height;
407 case KEYCODE_UP:
408 k_up:
409 if ((G.current_byte - G.baseaddr) < 16) {
410 if (!move_mapping_lower())
411 break; /* already at 0, stop */
412 }
413 G.current_byte -= 16;
414 up:
415 if (G.row != 0) {
416 G.row--;
417 printf(ESC"[A"); /* up (won't scroll) */
418 } else {
419 //printf(ESC"[T"); /* scroll up */ - not implemented on Linux VT!
420 printf(ESC"M"); /* scroll up */
421 redraw_cur_line();
422 }
423 if (--cnt)
424 goto k_up;
425 break;
426
427 case '\n':
428 case '\r':
429 /* [Enter]: goto specified position */
430 {
431 char buf[sizeof(G.offset)*3 + 4];
432 printf(ESC"[999;1H" CLEAR_TILL_EOL); /* go to last line */
433 if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) > 0) {
434 off_t t;
435 unsigned cursor;
436
437 t = bb_strtoull(buf, NULL, 0);
438 if (t >= G.size)
439 t = G.size - 1;
440 cursor = t & (G_pagesize - 1);
441 t -= cursor;
442 if (t < 0)
443 cursor = t = 0;
444 if (t != 0 && cursor < 0x1ff) {
445 /* very close to end of page, possibly to EOF */
446 /* move one page lower */
447 t -= G_pagesize;
448 cursor += G_pagesize;
449 }
450 G.offset = t;
451 remap(cursor);
452 redraw(cursor);
453 break;
454 }
455 /* ^C/EOF/error: fall through to exiting */
456 }
457 case CTRL('X'):
458 restore_term();
459 return EXIT_SUCCESS;
460 } /* switch */
461 } /* for (;;) */
462
463 /* not reached */
464 return EXIT_SUCCESS;
465}
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index 30f606e8e..fc392d9dc 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -8,7 +8,6 @@
8 * 8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 */ 10 */
11
12//config:config I2CGET 11//config:config I2CGET
13//config: bool "i2cget (5.6 kb)" 12//config: bool "i2cget (5.6 kb)"
14//config: default y 13//config: default y
@@ -61,10 +60,8 @@
61 */ 60 */
62 61
63#include "libbb.h" 62#include "libbb.h"
64#include "common_bufsiz.h"
65 63
66#include <linux/i2c.h> 64#include <linux/i2c.h>
67#include <linux/i2c-dev.h>
68 65
69#define I2CDUMP_NUM_REGS 256 66#define I2CDUMP_NUM_REGS 256
70 67
@@ -72,6 +69,25 @@
72#define I2CDETECT_MODE_QUICK 1 69#define I2CDETECT_MODE_QUICK 1
73#define I2CDETECT_MODE_READ 2 70#define I2CDETECT_MODE_READ 2
74 71
72/* linux/i2c-dev.h from i2c-tools overwrites the one from linux uapi
73 * and defines symbols already defined by linux/i2c.h.
74 * Also, it defines a bunch of static inlines which we would rather NOT
75 * inline. What a mess.
76 * We need only these definitions from linux/i2c-dev.h:
77 */
78#define I2C_SLAVE 0x0703
79#define I2C_SLAVE_FORCE 0x0706
80#define I2C_FUNCS 0x0705
81#define I2C_PEC 0x0708
82#define I2C_SMBUS 0x0720
83struct i2c_smbus_ioctl_data {
84 __u8 read_write;
85 __u8 command;
86 __u32 size;
87 union i2c_smbus_data *data;
88};
89/* end linux/i2c-dev.h */
90
75/* 91/*
76 * This is needed for ioctl_or_perror_and_die() since it only accepts pointers. 92 * This is needed for ioctl_or_perror_and_die() since it only accepts pointers.
77 */ 93 */
@@ -438,19 +454,20 @@ static void confirm_action(int bus_addr, int mode, int data_addr, int pec)
438 454
439#if ENABLE_I2CGET 455#if ENABLE_I2CGET
440//usage:#define i2cget_trivial_usage 456//usage:#define i2cget_trivial_usage
441//usage: "[-f] [-y] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]" 457//usage: "[-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]"
442//usage:#define i2cget_full_usage "\n\n" 458//usage:#define i2cget_full_usage "\n\n"
443//usage: "Read from I2C/SMBus chip registers\n" 459//usage: "Read from I2C/SMBus chip registers"
444//usage: "\n I2CBUS i2c bus number" 460//usage: "\n"
445//usage: "\n ADDRESS 0x03 - 0x77" 461//usage: "\n I2CBUS I2C bus number"
462//usage: "\n ADDRESS 0x03-0x77"
446//usage: "\nMODE is:" 463//usage: "\nMODE is:"
447//usage: "\n b read byte data (default)" 464//usage: "\n b Read byte data (default)"
448//usage: "\n w read word data" 465//usage: "\n w Read word data"
449//usage: "\n c write byte/read byte" 466//usage: "\n c Write byte/read byte"
450//usage: "\n Append p for SMBus PEC" 467//usage: "\n Append p for SMBus PEC"
451//usage: "\n" 468//usage: "\n"
452//usage: "\n -f force access" 469//usage: "\n -f Force access"
453//usage: "\n -y disable interactive mode" 470//usage: "\n -y Disable interactive mode"
454int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 471int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
455int i2cget_main(int argc UNUSED_PARAM, char **argv) 472int i2cget_main(int argc UNUSED_PARAM, char **argv)
456{ 473{
@@ -520,23 +537,24 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv)
520 537
521#if ENABLE_I2CSET 538#if ENABLE_I2CSET
522//usage:#define i2cset_trivial_usage 539//usage:#define i2cset_trivial_usage
523//usage: "[-f] [-y] [-m MASK] BUS CHIP-ADDR DATA-ADDR [VALUE] ... [MODE]" 540//usage: "[-fy] [-m MASK] BUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]"
524//usage:#define i2cset_full_usage "\n\n" 541//usage:#define i2cset_full_usage "\n\n"
525//usage: "Set I2C registers\n" 542//usage: "Set I2C registers"
526//usage: "\n I2CBUS i2c bus number" 543//usage: "\n"
527//usage: "\n ADDRESS 0x03 - 0x77" 544//usage: "\n I2CBUS I2C bus number"
545//usage: "\n ADDRESS 0x03-0x77"
528//usage: "\nMODE is:" 546//usage: "\nMODE is:"
529//usage: "\n c byte, no value" 547//usage: "\n c Byte, no value"
530//usage: "\n b byte data (default)" 548//usage: "\n b Byte data (default)"
531//usage: "\n w word data" 549//usage: "\n w Word data"
532//usage: "\n i I2C block data" 550//usage: "\n i I2C block data"
533//usage: "\n s SMBus block data" 551//usage: "\n s SMBus block data"
534//usage: "\n Append p for SMBus PEC" 552//usage: "\n Append p for SMBus PEC"
535//usage: "\n" 553//usage: "\n"
536//usage: "\n -f force access" 554//usage: "\n -f Force access"
537//usage: "\n -y disable interactive mode" 555//usage: "\n -y Disable interactive mode"
538//usage: "\n -r read back and compare the result" 556//usage: "\n -r Read back and compare the result"
539//usage: "\n -m MASK mask specifying which bits to write" 557//usage: "\n -m MASK Mask specifying which bits to write"
540int i2cset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 558int i2cset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
541int i2cset_main(int argc, char **argv) 559int i2cset_main(int argc, char **argv)
542{ 560{
@@ -879,23 +897,24 @@ static void dump_word_data(int bus_fd, unsigned first, unsigned last)
879} 897}
880 898
881//usage:#define i2cdump_trivial_usage 899//usage:#define i2cdump_trivial_usage
882//usage: "[-f] [-r FIRST-LAST] [-y] BUS ADDR [MODE]" 900//usage: "[-fy] [-r FIRST-LAST] BUS ADDR [MODE]"
883//usage:#define i2cdump_full_usage "\n\n" 901//usage:#define i2cdump_full_usage "\n\n"
884//usage: "Examine I2C registers\n" 902//usage: "Examine I2C registers"
885//usage: "\n I2CBUS i2c bus number" 903//usage: "\n"
886//usage: "\n ADDRESS 0x03 - 0x77" 904//usage: "\n I2CBUS I2C bus number"
905//usage: "\n ADDRESS 0x03-0x77"
887//usage: "\nMODE is:" 906//usage: "\nMODE is:"
888//usage: "\n b byte (default)" 907//usage: "\n b Byte (default)"
889//usage: "\n w word" 908//usage: "\n w Word"
890//usage: "\n W word on even register addresses" 909//usage: "\n W Word on even register addresses"
891//usage: "\n i I2C block" 910//usage: "\n i I2C block"
892//usage: "\n s SMBus block" 911//usage: "\n s SMBus block"
893//usage: "\n c consecutive byte" 912//usage: "\n c Consecutive byte"
894//usage: "\n Append p for SMBus PEC" 913//usage: "\n Append p for SMBus PEC"
895//usage: "\n" 914//usage: "\n"
896//usage: "\n -f force access" 915//usage: "\n -f Force access"
897//usage: "\n -y disable interactive mode" 916//usage: "\n -y Disable interactive mode"
898//usage: "\n -r limit the number of registers being accessed" 917//usage: "\n -r Limit the number of registers being accessed"
899int i2cdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 918int i2cdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
900int i2cdump_main(int argc UNUSED_PARAM, char **argv) 919int i2cdump_main(int argc UNUSED_PARAM, char **argv)
901{ 920{
@@ -1188,18 +1207,17 @@ static void will_skip(const char *cmd)
1188} 1207}
1189 1208
1190//usage:#define i2cdetect_trivial_usage 1209//usage:#define i2cdetect_trivial_usage
1191//usage: "[-F I2CBUS] [-l] [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]" 1210//usage: "-l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]"
1192//usage:#define i2cdetect_full_usage "\n\n" 1211//usage:#define i2cdetect_full_usage "\n\n"
1193//usage: "Detect I2C chips.\n" 1212//usage: "Detect I2C chips"
1194//usage: "\n I2CBUS i2c bus number"
1195//usage: "\n FIRST and LAST limit the probing range"
1196//usage: "\n" 1213//usage: "\n"
1197//usage: "\n -l output list of installed busses" 1214//usage: "\n -l List installed buses"
1198//usage: "\n -y disable interactive mode" 1215//usage: "\n -F BUS# List functionalities on this bus"
1199//usage: "\n -a force scanning of non-regular addresses" 1216//usage: "\n -y Disable interactive mode"
1200//usage: "\n -q use smbus quick write commands for probing (default)" 1217//usage: "\n -a Force scanning of non-regular addresses"
1201//usage: "\n -r use smbus read byte commands for probing" 1218//usage: "\n -q Use smbus quick write commands for probing (default)"
1202//usage: "\n -F display list of functionalities" 1219//usage: "\n -r Use smbus read byte commands for probing"
1220//usage: "\n FIRST and LAST limit probing range"
1203int i2cdetect_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1221int i2cdetect_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1204int i2cdetect_main(int argc UNUSED_PARAM, char **argv) 1222int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
1205{ 1223{
@@ -1214,7 +1232,8 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
1214 opts = getopt32(argv, "^" 1232 opts = getopt32(argv, "^"
1215 "yaqrFl" 1233 "yaqrFl"
1216 "\0" 1234 "\0"
1217 "q--r:r--q:"/*mutually exclusive*/ "?3"/*up to 3 args*/ 1235 "q--r:r--q:"/*mutually exclusive*/
1236 "?3"/*up to 3 args*/
1218 ); 1237 );
1219 argv += optind; 1238 argv += optind;
1220 1239
diff --git a/miscutils/less.c b/miscutils/less.c
index 8a5b9ff0b..4ab0e17da 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -6,7 +6,6 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9
10/* 9/*
11 * TODO: 10 * TODO:
12 * - Add more regular expression support - search modifiers, certain matches, etc. 11 * - Add more regular expression support - search modifiers, certain matches, etc.
@@ -20,7 +19,6 @@
20 * - the inp file pointer is used so that keyboard input works after 19 * - the inp file pointer is used so that keyboard input works after
21 * redirected input has been read from stdin 20 * redirected input has been read from stdin
22 */ 21 */
23
24//config:config LESS 22//config:config LESS
25//config: bool "less (15 kb)" 23//config: bool "less (15 kb)"
26//config: default y 24//config: default y
@@ -141,9 +139,9 @@
141#define ESC "\033" 139#define ESC "\033"
142/* The escape codes for highlighted and normal text */ 140/* The escape codes for highlighted and normal text */
143#define HIGHLIGHT ESC"[7m" 141#define HIGHLIGHT ESC"[7m"
144#define NORMAL ESC"[0m" 142#define NORMAL ESC"[m"
145/* The escape code to home and clear to the end of screen */ 143/* The escape code to home and clear to the end of screen */
146#define CLEAR ESC"[H\033[J" 144#define CLEAR ESC"[H"ESC"[J"
147/* The escape code to clear to the end of line */ 145/* The escape code to clear to the end of line */
148#define CLEAR_2_EOL ESC"[K" 146#define CLEAR_2_EOL ESC"[K"
149 147
@@ -285,9 +283,9 @@ static void set_tty_cooked(void)
285 283
286/* Move the cursor to a position (x,y), where (0,0) is the 284/* Move the cursor to a position (x,y), where (0,0) is the
287 top-left corner of the console */ 285 top-left corner of the console */
288static void move_cursor(int line, int row) 286static void move_cursor(int line, int col)
289{ 287{
290 printf(ESC"[%u;%uH", line, row); 288 printf(ESC"[%u;%uH", line, col);
291} 289}
292 290
293static void clear_line(void) 291static void clear_line(void)
@@ -1070,7 +1068,7 @@ static void reinitialize(void)
1070 open_file_and_read_lines(); 1068 open_file_and_read_lines();
1071#if ENABLE_FEATURE_LESS_ASK_TERMINAL 1069#if ENABLE_FEATURE_LESS_ASK_TERMINAL
1072 if (G.winsize_err) 1070 if (G.winsize_err)
1073 printf("\033[999;999H" "\033[6n"); 1071 printf(ESC"[999;999H" ESC"[6n");
1074#endif 1072#endif
1075#if ENABLE_PLATFORM_MINGW32 1073#if ENABLE_PLATFORM_MINGW32
1076 reset_screen(); 1074 reset_screen();
@@ -1135,7 +1133,7 @@ static int64_t getch_nowait(void)
1135 goto again; 1133 goto again;
1136 } 1134 }
1137 /* EOF/error (ssh session got killed etc) */ 1135 /* EOF/error (ssh session got killed etc) */
1138 less_exit(0); 1136 less_exit(EXIT_SUCCESS);
1139 } 1137 }
1140 set_tty_cooked(); 1138 set_tty_cooked();
1141 return key64; 1139 return key64;
@@ -1839,8 +1837,8 @@ int less_main(int argc, char **argv)
1839{ 1837{
1840#if !ENABLE_PLATFORM_MINGW32 1838#if !ENABLE_PLATFORM_MINGW32
1841 char *tty_name; 1839 char *tty_name;
1842 int tty_fd;
1843#endif 1840#endif
1841 int tty_fd;
1844 1842
1845 INIT_G(); 1843 INIT_G();
1846 1844
@@ -1901,18 +1899,12 @@ int less_main(int argc, char **argv)
1901 G.kbd_fd_orig_flags = ndelay_on(tty_fd); 1899 G.kbd_fd_orig_flags = ndelay_on(tty_fd);
1902 kbd_fd = tty_fd; /* save in a global */ 1900 kbd_fd = tty_fd; /* save in a global */
1903#else 1901#else
1904 kbd_fd = 0; 1902 kbd_fd = tty_fd = 0;
1905#endif 1903#endif
1906 1904
1907 tcgetattr(kbd_fd, &term_orig); 1905 get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL);
1908 term_less = term_orig;
1909 term_less.c_lflag &= ~(ICANON | ECHO);
1910 term_less.c_iflag &= ~(IXON | ICRNL);
1911 /*term_less.c_oflag &= ~ONLCR;*/
1912 term_less.c_cc[VMIN] = 1;
1913 term_less.c_cc[VTIME] = 0;
1914 1906
1915 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line); 1907 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line);
1916 /* 20: two tabstops + 4 */ 1908 /* 20: two tabstops + 4 */
1917 if (width < 20 || max_displayed_line < 3) 1909 if (width < 20 || max_displayed_line < 3)
1918 return bb_cat(argv); 1910 return bb_cat(argv);
diff --git a/miscutils/microcom.c b/miscutils/microcom.c
index b87f3273f..fa090057e 100644
--- a/miscutils/microcom.c
+++ b/miscutils/microcom.c
@@ -33,15 +33,11 @@
33// set raw tty mode 33// set raw tty mode
34static void xget1(int fd, struct termios *t, struct termios *oldt) 34static void xget1(int fd, struct termios *t, struct termios *oldt)
35{ 35{
36//TODO: use set_termios_to_raw() 36 get_termios_and_make_raw(fd, t, oldt, 0
37 tcgetattr(fd, oldt); 37 | TERMIOS_CLEAR_ISIG /* ^C is ASCII char 3, not "interrupt me!" */
38 *t = *oldt; 38 | TERMIOS_RAW_INPUT /* pass all chars verbatim, no special handling or translating CR->NL */
39 cfmakeraw(t); 39 | TERMIOS_RAW_CRNL /* dont convert NL<->CR on output too */
40// t->c_lflag &= ~(ISIG|ICANON|ECHO|IEXTEN); 40 );
41// t->c_iflag &= ~(BRKINT|IXON|ICRNL);
42// t->c_oflag &= ~(ONLCR);
43// t->c_cc[VMIN] = 1;
44// t->c_cc[VTIME] = 0;
45} 41}
46 42
47static int xset1(int fd, struct termios *tio, const char *device) 43static int xset1(int fd, struct termios *tio, const char *device)
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
index 80a005821..72f028ed3 100644
--- a/miscutils/nandwrite.c
+++ b/miscutils/nandwrite.c
@@ -7,7 +7,6 @@
7 * 7 *
8 * TODO: add support for large (>4GB) MTD devices 8 * TODO: add support for large (>4GB) MTD devices
9 */ 9 */
10
11//config:config NANDWRITE 10//config:config NANDWRITE
12//config: bool "nandwrite (5.9 kb)" 11//config: bool "nandwrite (5.9 kb)"
13//config: default y 12//config: default y
diff --git a/miscutils/raidautorun.c b/miscutils/raidautorun.c
index caf6e0821..d315c2734 100644
--- a/miscutils/raidautorun.c
+++ b/miscutils/raidautorun.c
@@ -5,7 +5,6 @@
5 * Copyright (C) 2006 Bernhard Reutner-Fischer 5 * Copyright (C) 2006 Bernhard Reutner-Fischer
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 *
9 */ 8 */
10//config:config RAIDAUTORUN 9//config:config RAIDAUTORUN
11//config: bool "raidautorun (1.4 kb)" 10//config: bool "raidautorun (1.4 kb)"
diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c
index 546928402..ae38c182d 100644
--- a/miscutils/rfkill.c
+++ b/miscutils/rfkill.c
@@ -1,12 +1,11 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3* rfkill implementation for busybox 3 * rfkill implementation for busybox
4* 4 *
5* Copyright (C) 2010 Malek Degachi <malek-degachi@laposte.net> 5 * Copyright (C) 2010 Malek Degachi <malek-degachi@laposte.net>
6* 6 *
7* Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8*/ 8 */
9
10//config:config RFKILL 9//config:config RFKILL
11//config: bool "rfkill (5.3 kb)" 10//config: bool "rfkill (5.3 kb)"
12//config: default n # doesn't build on Ubuntu 9.04 11//config: default n # doesn't build on Ubuntu 9.04
diff --git a/miscutils/setfattr.c b/miscutils/setfattr.c
new file mode 100644
index 000000000..f0ef227cb
--- /dev/null
+++ b/miscutils/setfattr.c
@@ -0,0 +1,68 @@
1/*
2 * setfattr - set extended attributes of filesystem objects.
3 *
4 * Copyright (C) 2017 by Denys Vlasenko <vda.linux@googlemail.com>
5 *
6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */
8//config:config SETFATTR
9//config: bool "setfattr"
10//config: default y
11//config: help
12//config: Set/delete extended attributes on files
13
14//applet:IF_SETFATTR(APPLET_NOEXEC(setfattr, setfattr, BB_DIR_USR_BIN, BB_SUID_DROP, setfattr))
15
16//kbuild:lib-$(CONFIG_SETFATTR) += setfattr.o
17
18#include <sys/xattr.h>
19#include "libbb.h"
20
21//usage:#define setfattr_trivial_usage
22//usage: "[-h] -n|-x ATTR [-v VALUE] FILE..."
23//usage:#define setfattr_full_usage "\n\n"
24//usage: "Set extended attributes"
25//usage: "\n"
26//usage: "\n -h Do not follow symlinks"
27//usage: "\n -x ATTR Remove attribute ATTR"
28//usage: "\n -n ATTR Set attribute ATTR to VALUE"
29//usage: "\n -v VALUE (default: empty)"
30int setfattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
31int setfattr_main(int argc UNUSED_PARAM, char **argv)
32{
33 const char *name;
34 const char *value = "";
35 int status;
36 int opt;
37 enum {
38 OPT_h = (1 << 0),
39 OPT_x = (1 << 1),
40 };
41
42 opt = getopt32(argv, "^"
43 "hx:n:v:"
44 /* Min one arg, either -x or -n is a must, -x does not allow -v */
45 "\0" "-1:x:n:n--x:x--nv:v--x"
46 , &name, &name, &value
47 );
48 argv += optind;
49
50 status = EXIT_SUCCESS;
51 do {
52 int r;
53 if (opt & OPT_x)
54 r = ((opt & OPT_h) ? lremovexattr : removexattr)(*argv, name);
55 else {
56 r = ((opt & OPT_h) ? lsetxattr : setxattr)(
57 *argv, name,
58 value, strlen(value), /*flags:*/ 0
59 );
60 }
61 if (r) {
62 bb_simple_perror_msg(*argv);
63 status = EXIT_FAILURE;
64 }
65 } while (*++argv);
66
67 return status;
68}
diff --git a/miscutils/setserial.c b/miscutils/setserial.c
index f217c3beb..fd88ed106 100644
--- a/miscutils/setserial.c
+++ b/miscutils/setserial.c
@@ -7,7 +7,6 @@
7 * 7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 */ 9 */
10
11//config:config SETSERIAL 10//config:config SETSERIAL
12//config: bool "setserial (6.6 kb)" 11//config: bool "setserial (6.6 kb)"
13//config: default y 12//config: default y
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index d142d1144..1ef8fd90e 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -2,7 +2,6 @@
2 * 2 *
3 * Licensed under GPLv2, see file LICENSE in this source tree. 3 * Licensed under GPLv2, see file LICENSE in this source tree.
4 */ 4 */
5
6//config:config UBIATTACH 5//config:config UBIATTACH
7//config: bool "ubiattach (4.7 kb)" 6//config: bool "ubiattach (4.7 kb)"
8//config: default y 7//config: default y