implement print -l: change output word separator to newline

This commit is contained in:
tg 2016-11-11 19:12:52 +00:00
parent d4b81df050
commit 8c2eda2f0f
1 changed files with 9 additions and 3 deletions

12
funcs.c
View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.310 2016/11/11 19:09:44 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.311 2016/11/11 19:12:52 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -291,6 +291,8 @@ c_print(const char **wp)
int fd; int fd;
/* temporary storage for a multibyte character */ /* temporary storage for a multibyte character */
char ts[4]; char ts[4];
/* output word separator */
char ows;
/* print trailing newline? */ /* print trailing newline? */
bool nl; bool nl;
/* expand backslash sequences? */ /* expand backslash sequences? */
@ -307,6 +309,7 @@ c_print(const char **wp)
} po; } po;
po.fd = 1; po.fd = 1;
po.ows = ' ';
po.nl = true; po.nl = true;
po.exp = true; po.exp = true;
po.hist = false; po.hist = false;
@ -375,7 +378,7 @@ c_print(const char **wp)
} }
} else { } else {
/* "print" builtin */ /* "print" builtin */
const char *opts = "AnpRrsu,"; const char *opts = "AlnpRrsu,";
const char *emsg; const char *emsg;
po.pminusminus = false; po.pminusminus = false;
@ -388,6 +391,9 @@ c_print(const char **wp)
case 'e': case 'e':
po.exp = true; po.exp = true;
break; break;
case 'l':
po.ows = '\n';
break;
case 'n': case 'n':
po.nl = false; po.nl = false;
break; break;
@ -489,7 +495,7 @@ c_print(const char **wp)
} }
} }
if (*wp != NULL) { if (*wp != NULL) {
Xput(xs, xp, ' '); Xput(xs, xp, po.ows);
goto print_read_arg; goto print_read_arg;
} }
print_no_arg: print_no_arg: