implement print -N: set output word and line separator to NUL
This commit is contained in:
37
funcs.c
37
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.311 2016/11/11 19:12:52 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.312 2016/11/11 19:18:40 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -292,9 +292,9 @@ c_print(const char **wp)
|
|||||||
/* temporary storage for a multibyte character */
|
/* temporary storage for a multibyte character */
|
||||||
char ts[4];
|
char ts[4];
|
||||||
/* output word separator */
|
/* output word separator */
|
||||||
char ows;
|
char ws;
|
||||||
/* print trailing newline? */
|
/* output line separator ('!' to not print any) */
|
||||||
bool nl;
|
char nl;
|
||||||
/* expand backslash sequences? */
|
/* expand backslash sequences? */
|
||||||
bool exp;
|
bool exp;
|
||||||
/* print to history instead of file descriptor / stdout? */
|
/* print to history instead of file descriptor / stdout? */
|
||||||
@ -309,8 +309,8 @@ c_print(const char **wp)
|
|||||||
} po;
|
} po;
|
||||||
|
|
||||||
po.fd = 1;
|
po.fd = 1;
|
||||||
po.ows = ' ';
|
po.ws = ' ';
|
||||||
po.nl = true;
|
po.nl = '\n';
|
||||||
po.exp = true;
|
po.exp = true;
|
||||||
po.hist = false;
|
po.hist = false;
|
||||||
po.chars = false;
|
po.chars = false;
|
||||||
@ -336,13 +336,14 @@ 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 = false;
|
po.nl = '!';
|
||||||
++wp;
|
++wp;
|
||||||
}
|
}
|
||||||
/* print everything as-is */
|
/* print everything as-is */
|
||||||
po.exp = false;
|
po.exp = false;
|
||||||
} else {
|
} else {
|
||||||
bool new_exp = po.exp, new_nl = po.nl;
|
bool new_exp = po.exp;
|
||||||
|
char new_nl = po.nl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a compromise between sysV and BSD echo commands:
|
* a compromise between sysV and BSD echo commands:
|
||||||
@ -366,7 +367,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 = false;
|
new_nl = '!';
|
||||||
goto print_tradparse_ch;
|
goto print_tradparse_ch;
|
||||||
case '\0':
|
case '\0':
|
||||||
po.exp = new_exp;
|
po.exp = new_exp;
|
||||||
@ -378,7 +379,7 @@ c_print(const char **wp)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* "print" builtin */
|
/* "print" builtin */
|
||||||
const char *opts = "AlnpRrsu,";
|
const char *opts = "AlNnpRrsu,";
|
||||||
const char *emsg;
|
const char *emsg;
|
||||||
|
|
||||||
po.pminusminus = false;
|
po.pminusminus = false;
|
||||||
@ -392,10 +393,14 @@ c_print(const char **wp)
|
|||||||
po.exp = true;
|
po.exp = true;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
po.ows = '\n';
|
po.ws = '\n';
|
||||||
|
break;
|
||||||
|
case 'N':
|
||||||
|
po.ws = '\0';
|
||||||
|
po.nl = '\0';
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
po.nl = false;
|
po.nl = '!';
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if ((po.fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
if ((po.fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
||||||
@ -471,7 +476,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 = false;
|
po.nl = '!';
|
||||||
/* AT&T brain damage */
|
/* AT&T brain damage */
|
||||||
continue;
|
continue;
|
||||||
case '\0':
|
case '\0':
|
||||||
@ -495,12 +500,12 @@ c_print(const char **wp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*wp != NULL) {
|
if (*wp != NULL) {
|
||||||
Xput(xs, xp, po.ows);
|
Xput(xs, xp, po.ws);
|
||||||
goto print_read_arg;
|
goto print_read_arg;
|
||||||
}
|
}
|
||||||
print_no_arg:
|
print_no_arg:
|
||||||
if (po.nl)
|
if (po.nl != '!')
|
||||||
Xput(xs, xp, '\n');
|
Xput(xs, xp, po.nl);
|
||||||
|
|
||||||
c = 0;
|
c = 0;
|
||||||
if (po.hist) {
|
if (po.hist) {
|
||||||
|
Reference in New Issue
Block a user