diff --git a/generic/tclScan.c b/generic/tclScan.c index e852d63816a..ba85c47c61f 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -15,14 +15,15 @@ /* * Flag values used by Tcl_ScanObjCmd. */ +enum ScanFlags { + SCAN_NOSKIP = 0x1, /* Don't skip blanks. */ + SCAN_SUPPRESS = 0x2, /* Suppress assignment. */ + SCAN_UNSIGNED = 0x4, /* Read an unsigned value. */ + SCAN_WIDTH = 0x8, /* A width value was supplied. */ -#define SCAN_NOSKIP 0x1 /* Don't skip blanks. */ -#define SCAN_SUPPRESS 0x2 /* Suppress assignment. */ -#define SCAN_UNSIGNED 0x4 /* Read an unsigned value. */ -#define SCAN_WIDTH 0x8 /* A width value was supplied. */ - -#define SCAN_LONGER 0x400 /* Asked for a wide value. */ -#define SCAN_BIG 0x800 /* Asked for a bignum value. */ + SCAN_LONGER = 0x400, /* Asked for a wide value. */ + SCAN_BIG = 0x800 /* Asked for a bignum value. */ +}; /* * The following structure contains the information associated with a @@ -683,6 +684,7 @@ Tcl_ScanObjCmd( format += TclUtfToUniChar(format, &ch); } else if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ char *formatEnd; + /* Note currently XPG3 range limited to INT_MAX to match type of objc */ value = strtoul(format-1, &formatEnd, 10);/* INTL: "C" locale. */ if (*formatEnd == '$') { format = formatEnd+1; @@ -707,6 +709,13 @@ Tcl_ScanObjCmd( */ switch (ch) { + case 'z': + case 't': + if (sizeof(void *) > sizeof(int)) { + flags |= SCAN_LONGER; + } + format += TclUtfToUniChar(format, &ch); + break; case 'l': if (*format == 'l') { flags |= SCAN_BIG; @@ -716,6 +725,8 @@ Tcl_ScanObjCmd( } /* FALLTHRU */ case 'L': + case 'j': + case 'q': flags |= SCAN_LONGER; /* FALLTHRU */ case 'h': diff --git a/tests/scan.test b/tests/scan.test index 98ec31402f7..fa5b8cf442a 100644 --- a/tests/scan.test +++ b/tests/scan.test @@ -560,6 +560,11 @@ test scan-5.20 {ignore digit separators} -setup { } -body { list [scan "10_23_45" %d_%d_%d a b c] $a $b $c } -result {3 10 23 45} +test scan-5.21 {integer scanning, %j, %q, &z, %t} -setup { + set a {}; set b {}; set c {}; set d {} +} -body { + list [scan "42 43 44 45" "%jd %qd %zd %td" a b c d] $a $b $c $d +} -result {4 42 43 44 45} test scan-6.1 {floating-point scanning} -setup { set a {}; set b {}; set c {}; set d {}