Print this page
4854 printf(1) doesn't support %b and \c properly
*** 90,100 ****
int
main(int argc, char *argv[])
{
size_t len;
! int chopped, end, rval;
char *format, *fmt, *start;
(void) setlocale(LC_ALL, "");
argv++;
--- 90,100 ----
int
main(int argc, char *argv[])
{
size_t len;
! int end, rval;
char *format, *fmt, *start;
(void) setlocale(LC_ALL, "");
argv++;
*** 122,132 ****
* format strings are reused as necessary to use up the provided
* arguments, arguments of zero/null string are provided to use
* up the format string.
*/
fmt = format = *argv;
! chopped = escape(fmt, 1, &len); /* backslash interpretation */
rval = end = 0;
gargv = ++argv;
for (;;) {
maxargv = gargv;
--- 122,132 ----
* format strings are reused as necessary to use up the provided
* arguments, arguments of zero/null string are provided to use
* up the format string.
*/
fmt = format = *argv;
! (void) escape(fmt, 1, &len); /* backslash interpretation */
rval = end = 0;
gargv = ++argv;
for (;;) {
maxargv = gargv;
*** 160,170 ****
if (end == 1) {
warnx1(_("missing format character"), NULL, NULL);
return (1);
}
(void) fwrite(start, 1, PTRDIFF(fmt, start), stdout);
! if (chopped || !*gargv)
return (rval);
/* Restart at the beginning of the format string. */
fmt = format;
end = 1;
}
--- 160,170 ----
if (end == 1) {
warnx1(_("missing format character"), NULL, NULL);
return (1);
}
(void) fwrite(start, 1, PTRDIFF(fmt, start), stdout);
! if (!*gargv)
return (rval);
/* Restart at the beginning of the format string. */
fmt = format;
end = 1;
}
*** 336,352 ****
if (p == NULL) {
warnx2("%s", strerror(ENOMEM), NULL);
return (NULL);
}
getout = escape(p, 0, &len);
! *(fmt - 1) = 's';
! PF(start, p);
! *(fmt - 1) = 'b';
free(p);
if (getout)
! return (fmt);
break;
}
case 'c': {
char p;
--- 336,350 ----
if (p == NULL) {
warnx2("%s", strerror(ENOMEM), NULL);
return (NULL);
}
getout = escape(p, 0, &len);
! (void) fputs(p, stdout);
free(p);
if (getout)
! exit(*rval);
break;
}
case 'c': {
char p;
*** 454,466 ****
--- 452,468 ----
break;
case 'b': /* backspace */
*store = '\b';
break;
case 'c':
+ if (!percent) {
*store = '\0';
*len = PTRDIFF(store, save);
return (1);
+ }
+ *store = 'c';
+ break;
case 'f': /* form-feed */
*store = '\f';
break;
case 'n': /* newline */
*store = '\n';