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>
This commit is contained in:
parent
0e2cb6d1e2
commit
9173c9cce4
15
editors/ed.c
15
editors/ed.c
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
|
//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP))
|
||||||
|
|
||||||
//usage:#define ed_trivial_usage "[-p PROMPT] [FILE]"
|
//usage:#define ed_trivial_usage "[-p PROMPT] [-s] [FILE]"
|
||||||
//usage:#define ed_full_usage ""
|
//usage:#define ed_full_usage ""
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
@ -71,6 +71,11 @@ struct globals {
|
|||||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define OPTION_STR "sp:"
|
||||||
|
enum {
|
||||||
|
OPT_s = (1 << 0),
|
||||||
|
};
|
||||||
|
|
||||||
static int bad_nums(int num1, int num2, const char *for_what)
|
static int bad_nums(int num1, int num2, const char *for_what)
|
||||||
{
|
{
|
||||||
if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
|
if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) {
|
||||||
@ -458,7 +463,8 @@ static int readLines(const char *file, int num)
|
|||||||
* in the following format:
|
* in the following format:
|
||||||
* "%d\n", <number of bytes read>
|
* "%d\n", <number of bytes read>
|
||||||
*/
|
*/
|
||||||
printf("%u\n", charCount);
|
if (!(option_mask32 & OPT_s))
|
||||||
|
printf("%u\n", charCount);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +516,8 @@ static int writeLines(const char *file, int num1, int num2)
|
|||||||
* unless the -s option was specified, in the following format:
|
* unless the -s option was specified, in the following format:
|
||||||
* "%d\n", <number of bytes written>
|
* "%d\n", <number of bytes written>
|
||||||
*/
|
*/
|
||||||
printf("%u\n", charCount);
|
if (!(option_mask32 & OPT_s))
|
||||||
|
printf("%u\n", charCount);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,7 +1012,7 @@ int ed_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
lines.prev = &lines;
|
lines.prev = &lines;
|
||||||
|
|
||||||
prompt = ""; /* no prompt by default */
|
prompt = ""; /* no prompt by default */
|
||||||
getopt32(argv, "p:", &prompt);
|
getopt32(argv, OPTION_STR, &prompt);
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (argv[0]) {
|
if (argv[0]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user