[PATCH v2] ed: add support for -p command-line option as mandated by POSIX
Denys Vlasenko
vda.linux at googlemail.com
Fri Dec 17 21:36:01 UTC 2021
Applied, thank you.
On Sun, Nov 21, 2021 at 12:25 PM <soeren at soeren-tempel.net> wrote:
>
> From: Sören Tempel <soeren+git at soeren-tempel.net>
>
> The POSIX.1-2008 specification of ed(1) mandates two command-line
> options: -p (for specifying a prompt string) and -s (to suppress writing
> of byte counts). This commit adds support for the former. Furthermore,
> it also changes the default prompt string to an empty string (instead
> of ": ") since this is also mandated by POSIX:
>
> -p string Use string as the prompt string when in command mode.
> By default, there shall be no prompt string.
>
> Support for the remaining -s option will be added in a separate commit
> since it requires a general restructuring of error handling in Busybox
> ed.
>
> Signed-off-by: Sören Tempel <soeren+git at soeren-tempel.net>
> ---
> editors/ed.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/editors/ed.c b/editors/ed.c
> index 0d96d263c..a54a0b0a6 100644
> --- a/editors/ed.c
> +++ b/editors/ed.c
> @@ -48,6 +48,7 @@ struct globals {
> char *bufBase;
> char *bufPtr;
> char *fileName;
> + const char *prompt;
> LINE lines;
> smallint dirty;
> int marks[26];
> @@ -57,6 +58,7 @@ struct globals {
> #define bufBase (G.bufBase )
> #define bufPtr (G.bufPtr )
> #define fileName (G.fileName )
> +#define prompt (G.prompt )
> #define curNum (G.curNum )
> #define lastNum (G.lastNum )
> #define bufUsed (G.bufUsed )
> @@ -790,7 +792,7 @@ static void doCommands(void)
> * 0 on ctrl-C,
> * >0 length of input string, including terminating '\n'
> */
> - len = read_line_input(NULL, ": ", buf, sizeof(buf));
> + len = read_line_input(NULL, prompt, buf, sizeof(buf));
> if (len <= 0)
> return;
> while (len && isspace(buf[--len]))
> @@ -994,6 +996,8 @@ static void doCommands(void)
> int ed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
> int ed_main(int argc UNUSED_PARAM, char **argv)
> {
> + int opt;
> +
> INIT_G();
>
> bufSize = INITBUF_SIZE;
> @@ -1002,8 +1006,15 @@ int ed_main(int argc UNUSED_PARAM, char **argv)
> lines.next = &lines;
> lines.prev = &lines;
>
> - if (argv[1]) {
> - fileName = xstrdup(argv[1]);
> + opt = getopt32(argv, "p:", &prompt);
> + if (!(opt & 0x01))
> + prompt = ""; /* no prompt by default */
> +
> + argc -= optind;
> + argv += optind;
> +
> + if (argc >= 1) {
> + fileName = xstrdup(argv[0]);
> if (!readLines(fileName, 1)) {
> return EXIT_SUCCESS;
> }
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list