fix print -cn
This commit is contained in:
parent
6c04e4a665
commit
6267ea36a4
30
funcs.c
30
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.316 2016/11/11 21:13:23 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.317 2016/11/11 21:37:35 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -294,8 +294,10 @@ c_print(const char **wp)
|
|||||||
char ts[4];
|
char ts[4];
|
||||||
/* output word separator */
|
/* output word separator */
|
||||||
char ws;
|
char ws;
|
||||||
/* output line separator ('!' to not print any) */
|
/* output line separator */
|
||||||
char nl;
|
char ls;
|
||||||
|
/* output a trailing line separator? */
|
||||||
|
bool nl;
|
||||||
/* expand backslash sequences? */
|
/* expand backslash sequences? */
|
||||||
bool exp;
|
bool exp;
|
||||||
/* columnise output? */
|
/* columnise output? */
|
||||||
@ -313,7 +315,8 @@ c_print(const char **wp)
|
|||||||
|
|
||||||
po.fd = 1;
|
po.fd = 1;
|
||||||
po.ws = ' ';
|
po.ws = ' ';
|
||||||
po.nl = '\n';
|
po.ls = '\n';
|
||||||
|
po.nl = true;
|
||||||
po.exp = true;
|
po.exp = true;
|
||||||
po.col = false;
|
po.col = false;
|
||||||
po.hist = false;
|
po.hist = false;
|
||||||
@ -340,14 +343,13 @@ c_print(const char **wp)
|
|||||||
/* Debian Policy 10.4 compliant "echo" builtin */
|
/* Debian Policy 10.4 compliant "echo" builtin */
|
||||||
if (*wp && !strcmp(*wp, "-n")) {
|
if (*wp && !strcmp(*wp, "-n")) {
|
||||||
/* recognise "-n" only as the first arg */
|
/* recognise "-n" only as the first arg */
|
||||||
po.nl = '!';
|
po.nl = false;
|
||||||
++wp;
|
++wp;
|
||||||
}
|
}
|
||||||
/* print everything as-is */
|
/* print everything as-is */
|
||||||
po.exp = false;
|
po.exp = false;
|
||||||
} else {
|
} else {
|
||||||
bool new_exp = po.exp;
|
bool new_exp = po.exp, new_nl = po.nl;
|
||||||
char new_nl = po.nl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a compromise between sysV and BSD echo commands:
|
* a compromise between sysV and BSD echo commands:
|
||||||
@ -371,7 +373,7 @@ c_print(const char **wp)
|
|||||||
new_exp = true;
|
new_exp = true;
|
||||||
goto print_tradparse_ch;
|
goto print_tradparse_ch;
|
||||||
case 'n':
|
case 'n':
|
||||||
new_nl = '!';
|
new_nl = false;
|
||||||
goto print_tradparse_ch;
|
goto print_tradparse_ch;
|
||||||
case '\0':
|
case '\0':
|
||||||
po.exp = new_exp;
|
po.exp = new_exp;
|
||||||
@ -404,10 +406,10 @@ c_print(const char **wp)
|
|||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
po.ws = '\0';
|
po.ws = '\0';
|
||||||
po.nl = '\0';
|
po.ls = '\0';
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
po.nl = '!';
|
po.nl = false;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if ((po.fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
if ((po.fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
||||||
@ -490,7 +492,7 @@ c_print(const char **wp)
|
|||||||
/* rejected by generic function */
|
/* rejected by generic function */
|
||||||
switch ((c = *s++)) {
|
switch ((c = *s++)) {
|
||||||
case 'c':
|
case 'c':
|
||||||
po.nl = '!';
|
po.nl = false;
|
||||||
/* AT&T brain damage */
|
/* AT&T brain damage */
|
||||||
continue;
|
continue;
|
||||||
case '\0':
|
case '\0':
|
||||||
@ -529,7 +531,7 @@ c_print(const char **wp)
|
|||||||
|
|
||||||
XPput(words, NULL);
|
XPput(words, NULL);
|
||||||
co.shf = shf_sopen(NULL, 128, SHF_WR | SHF_DYNAMIC, NULL);
|
co.shf = shf_sopen(NULL, 128, SHF_WR | SHF_DYNAMIC, NULL);
|
||||||
co.linesep = po.nl;
|
co.linesep = po.ls;
|
||||||
co.prefcol = co.do_last = false;
|
co.prefcol = co.do_last = false;
|
||||||
pr_list(&co, (char **)XPptrv(words));
|
pr_list(&co, (char **)XPptrv(words));
|
||||||
while (w--)
|
while (w--)
|
||||||
@ -542,8 +544,8 @@ c_print(const char **wp)
|
|||||||
shf_sclose(co.shf);
|
shf_sclose(co.shf);
|
||||||
}
|
}
|
||||||
print_no_arg:
|
print_no_arg:
|
||||||
if (po.nl != '!')
|
if (po.nl)
|
||||||
Xput(xs, xp, po.nl);
|
Xput(xs, xp, po.ls);
|
||||||
|
|
||||||
c = 0;
|
c = 0;
|
||||||
if (po.hist) {
|
if (po.hist) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user