aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-12-29 16:15:50 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-12-29 19:01:32 +0100
commit9173c9cce48dc4c867fb06bb72e8c762740c5c86 (patch)
tree38cf150e3a3aca58b514556aa10a02b4c71aea12
parent0e2cb6d1e2553675bba2999829bbc29219aea987 (diff)
downloadbusybox-w32-9173c9cce48dc4c867fb06bb72e8c762740c5c86.tar.gz
busybox-w32-9173c9cce48dc4c867fb06bb72e8c762740c5c86.tar.bz2
busybox-w32-9173c9cce48dc4c867fb06bb72e8c762740c5c86.zip
ed: add support for -s command-line option as mandated by POSIX
Apart from the -p option, POSIX also mandates an -s option which suppresses the output of byte counts for the e, E, r, and w command. From these commands, Busybox ed presently only implements the r and w commands. This commit ensures that these two command do not output any bytes counts when the -s option is passed. The shell escape command, also effected by the -s option, is not implemented by Busybox at the moment. function old new delta packed_usage 34096 34115 +19 doCommands 1887 1900 +13 readLines 388 397 +9 .rodata 104196 104200 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 45/0) Total: 45 bytes Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/ed.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/editors/ed.c b/editors/ed.c
index dfe0f1a77..209ce9942 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -18,7 +18,7 @@
18 18
19//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) 19//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
20 20
21//usage:#define ed_trivial_usage "[-p PROMPT] [FILE]" 21//usage:#define ed_trivial_usage "[-p PROMPT] [-s] [FILE]"
22//usage:#define ed_full_usage "" 22//usage:#define ed_full_usage ""
23 23
24#include "libbb.h" 24#include "libbb.h"
@@ -71,6 +71,11 @@ struct globals {
71 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 71 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
72} while (0) 72} while (0)
73 73
74#define OPTION_STR "sp:"
75enum {
76 OPT_s = (1 << 0),
77};
78
74static int bad_nums(int num1, int num2, const char *for_what) 79static int bad_nums(int num1, int num2, const char *for_what)
75{ 80{
76 if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { 81 if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
@@ -458,7 +463,8 @@ static int readLines(const char *file, int num)
458 * in the following format: 463 * in the following format:
459 * "%d\n", <number of bytes read> 464 * "%d\n", <number of bytes read>
460 */ 465 */
461 printf("%u\n", charCount); 466 if (!(option_mask32 & OPT_s))
467 printf("%u\n", charCount);
462 return TRUE; 468 return TRUE;
463} 469}
464 470
@@ -510,7 +516,8 @@ static int writeLines(const char *file, int num1, int num2)
510 * unless the -s option was specified, in the following format: 516 * unless the -s option was specified, in the following format:
511 * "%d\n", <number of bytes written> 517 * "%d\n", <number of bytes written>
512 */ 518 */
513 printf("%u\n", charCount); 519 if (!(option_mask32 & OPT_s))
520 printf("%u\n", charCount);
514 return TRUE; 521 return TRUE;
515} 522}
516 523
@@ -1005,7 +1012,7 @@ int ed_main(int argc UNUSED_PARAM, char **argv)
1005 lines.prev = &lines; 1012 lines.prev = &lines;
1006 1013
1007 prompt = ""; /* no prompt by default */ 1014 prompt = ""; /* no prompt by default */
1008 getopt32(argv, "p:", &prompt); 1015 getopt32(argv, OPTION_STR, &prompt);
1009 argv += optind; 1016 argv += optind;
1010 1017
1011 if (argv[0]) { 1018 if (argv[0]) {