From de59a00a303f0acfad8f990f62e5095d0e327298 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 7 Apr 2017 14:48:49 +0000 Subject: Use "0o" in stead of "0" as octal prefix in more places. --- generic/tclStringObj.c | 21 +++++---------------- tests/chanio.test | 8 ++++---- tests/format.test | 4 ++-- tests/io.test | 4 ++-- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index c574003..239f88f 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1880,20 +1880,10 @@ Tcl_AppendFormatToObj( format += step; step = Tcl_UtfToUniChar(format, &ch); } - } else if ((ch == 't') || (ch == 'z')) { + } else if ((ch == 't') || (ch == 'z') || (ch == 'q') || (ch == 'j') || (ch == 'L')) { format += step; step = Tcl_UtfToUniChar(format, &ch); -#ifndef TCL_WIDE_INT_IS_LONG - if (sizeof(size_t) > sizeof(int)) { - useWide = 1; - } -#endif - } else if ((ch == 'q') ||(ch == 'j')) { - format += step; - step = Tcl_UtfToUniChar(format, &ch); -#ifndef TCL_WIDE_INT_IS_LONG - useWide = 1; -#endif + useBig = 1; } format += step; @@ -2035,9 +2025,8 @@ Tcl_AppendFormatToObj( if (gotHash || (ch == 'p')) { switch (ch) { case 'o': - Tcl_AppendToObj(segment, "0", 1); - segmentLimit -= 1; - precision--; + Tcl_AppendToObj(segment, "0o", 2); + segmentLimit -= 2; break; case 'p': case 'x': @@ -2186,7 +2175,7 @@ Tcl_AppendFormatToObj( * Need to be sure zero becomes "0", not "". */ - if ((numDigits == 0) && !((ch == 'o') && gotHash)) { + if (numDigits == 0) { numDigits = 1; } pure = Tcl_NewObj(); diff --git a/tests/chanio.test b/tests/chanio.test index 8e27af9..2d900d0 100644 --- a/tests/chanio.test +++ b/tests/chanio.test @@ -5338,22 +5338,22 @@ test chan-io-40.2 {POSIX open access modes: CREAT} -setup { } -constraints {unix} -body { set f [open $path(test3) {WRONLY CREAT} 0600] file stat $path(test3) stats - set x [format "0%o" [expr $stats(mode)&0o777]] + set x [format "%#o" [expr $stats(mode)&0o777]] chan puts $f "line 1" chan close $f set f [open $path(test3) r] lappend x [chan gets $f] } -cleanup { chan close $f -} -result {0600 {line 1}} +} -result {0o600 {line 1}} test chan-io-40.3 {POSIX open access modes: CREAT} -setup { file delete $path(test3) } -constraints {unix umask} -body { # This test only works if your umask is 2, like ouster's. chan close [open $path(test3) {WRONLY CREAT}] file stat $path(test3) stats - format "0%o" [expr $stats(mode)&0o777] -} -result [format %04o [expr {0o666 & ~ $umaskValue}]] + format "%#o" [expr $stats(mode)&0o777] +} -result [format %#5o [expr {0o666 & ~ $umaskValue}]] test chan-io-40.4 {POSIX open access modes: CREAT} -setup { file delete $path(test3) } -body { diff --git a/tests/format.test b/tests/format.test index ad127a4..801a735 100644 --- a/tests/format.test +++ b/tests/format.test @@ -72,10 +72,10 @@ test format-1.10.1 {integer formatting} longIs64bit { } {0 0x6 0x22 0x421b 0xfffffffffffffff4 } test format-1.11 {integer formatting} longIs32bit { format "%-#5o %-#20o %#-20o %#-20o %#-20o" 0 6 34 16923 -12 -1 -} {0 06 042 041033 037777777764 } +} {0 0o6 0o42 0o41033 0o37777777764 } test format-1.11.1 {integer formatting} longIs64bit { format "%-#5o %-#20o %#-20o %#-20o %#-20o" 0 6 34 16923 -12 -1 -} {0 06 042 041033 01777777777777777777764} +} {0 0o6 0o42 0o41033 0o1777777777777777777764} test format-1.12 {integer formatting} { format "%b %#b %llb" 5 5 [expr {2**100}] } {101 0b101 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000} diff --git a/tests/io.test b/tests/io.test index 6e7420d..aaceec5 100644 --- a/tests/io.test +++ b/tests/io.test @@ -5652,8 +5652,8 @@ test io-40.3 {POSIX open access modes: CREAT} {unix umask} { set f [open $path(test3) {WRONLY CREAT}] close $f file stat $path(test3) stats - format "0%o" [expr $stats(mode)&0o777] -} [format %04o [expr {0o666 & ~ $umaskValue}]] + format "%#o" [expr $stats(mode)&0o777] +} [format %#5o [expr {0o666 & ~ $umaskValue}]] test io-40.4 {POSIX open access modes: CREAT} { file delete $path(test3) set f [open $path(test3) w] -- cgit v0.12