fix printf %c.

This commit is contained in:
Christopher Jeffrey 2013-02-27 19:39:08 -06:00
parent f2c4c01d9e
commit 086414a5c5
1 changed files with 19 additions and 13 deletions

View File

@ -670,6 +670,12 @@ Tput.prototype._compile = function(val) {
// as in printf, flags are [-+#] and space. Use a `:' to allow the
// next character to be a `-' flag, avoiding interpreting "%-" as an
// operator.
// %c print pop() like %c in printf
// Example from screen terminfo:
// S0: "\u001b(%p1%c"
// %d print pop()
// "Print (e.g., "%d") is a special case."
// %s print pop() like %s in printf
if (read(/^%((?::-|[+# ]){1,4})?(\d+(?:\.\d+)?)?([doxXs])/)) {
if (this.printf) {
echo('sprintf("'+ cap[0].replace(':-', '-') + '", stack.pop())');
@ -680,29 +686,29 @@ Tput.prototype._compile = function(val) {
}
// %c print pop() like %c in printf
// Example from screen terminfo:
// S0: "\u001b(%p1%c"
if (read(/^%c/)) {
if (this.printf) {
echo('sprintf("%c", stack.pop())');
} else {
// echo('stack.pop()'); // TODO: check screen terminfo for an example
echo('String.fromCharCode(stack.pop())');
//echo('(v = stack.pop() || "", isFinite(v) ? String.fromCharCode(v) : v[0])');
echo('(v = stack.pop() || "", isFinite(v) ? String.fromCharCode(v) : v[0])');
}
continue;
}
// %d print pop()
// "Print (e.g., "%d") is a special case."
//if (read(/^%d/)) {
// if (read(/^%d/)) {
// echo('stack.pop()');
// continue;
//}
// }
// %s print pop() like %s in printf
//if (read(/^%s/)) {
// if (read(/^%s/)) {
// echo('stack.pop()');
// continue;
//}
// }
// %p[1-9]
// push i'th parameter
@ -1212,8 +1218,8 @@ function sprintf(src) {
// Should return here?
param = isFinite(param)
? String.fromCharCode(param)
: '';
//: param[0];
: param[0];
//: '';
break;
}