Tcl Source Code

Changes On Branch tip-586-binary-scan-c-string
Login
Bounty program for improvements to Tcl and certain Tcl packages.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch tip-586-binary-scan-c-string Excluding Merge-Ins

This is equivalent to a diff from c15e8bc4bb to 2c1ee70bdc

2020-11-16
10:53
TIP #586 implementation: C String Parsing Support for binary scan check-in: 5aa764a795 user: jan.nijtmans tags: core-8-branch
2020-11-06
14:43
Deprecate the (internal) functions TclGuessPackageName/TclGetLoadedPackages functions, since they tu... check-in: 7b2277bf8b user: jan.nijtmans tags: core-8-branch
09:59
Lesser TIP #590 implementation: Only package renaming, no code changes check-in: 5cb1460243 user: jan.nijtmans tags: tip-590
2020-11-05
17:06
Merge 8.7 check-in: 23c0c45dd0 user: jan.nijtmans tags: tip-575
2020-11-03
15:32
Case-sensitive package names check-in: b15b349bfb user: jan.nijtmans tags: case-sensitive-pkg
2020-11-01
14:25
Merge 8.7 Closed-Leaf check-in: ef5fd3e260 user: dkf tags: tip-582
2020-10-30
20:23
merge 8.7 check-in: 8da1570d62 user: dgp tags: tip-568
20:17
merge 8.7 check-in: 5cbe392b39 user: dgp tags: dgp-review
15:31
Merge 8.7 check-in: 707d6eadba user: jan.nijtmans tags: build-info
15:13
Merge 8.7 Closed-Leaf check-in: 2c1ee70bdc user: jan.nijtmans tags: tip-586-binary-scan-c-string
14:25
Merge 8.7 check-in: 0f952be066 user: jan.nijtmans tags: trunk, main
14:05
Merge 8.6 check-in: c15e8bc4bb user: jan.nijtmans tags: core-8-branch
13:56
Simplify testcases using "incr" check-in: 165a804445 user: jan.nijtmans tags: core-8-6-branch
13:37
Merge 8.6 check-in: 6312e0d10c user: jan.nijtmans tags: core-8-branch
2020-10-28
15:10
Merge 8.7 check-in: 063b7a740c user: jan.nijtmans tags: tip-586-binary-scan-c-string

Changes to doc/binary.n.

758
759
760
761
762
763
764









765
766
767
768
769
770
771
.CS
\fBbinary scan\fR \ex70\ex87\ex05 B5B* var1 var2
.CE
.PP
will return \fB2\fR with \fB01110\fR stored in \fIvar1\fR and
\fB1000011100000101\fR stored in \fIvar2\fR.
.RE









.IP \fBH\fR 5
The data is turned into a string of \fIcount\fR hexadecimal digits in
high-to-low order represented as a sequence of characters in the set
.QW 0123456789abcdef .
The data bytes are scanned in first to last
order with the hex digits being taken in high-to-low order within each
byte. Any extra bits in the last byte are ignored. If \fIcount\fR is






>
>
>
>
>
>
>
>
>







758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
.CS
\fBbinary scan\fR \ex70\ex87\ex05 B5B* var1 var2
.CE
.PP
will return \fB2\fR with \fB01110\fR stored in \fIvar1\fR and
\fB1000011100000101\fR stored in \fIvar2\fR.
.RE
.IP \fBC\fR 5
This form is similar to \fBA\fR, except that it scans the data from start
and terminates at the first null (C string semantics). For example,
.RS
.CS
\fBbinary scan\fR "abc\e000efghi" C* var1
.CE
will return \fB1\fR with \fBabc\fR stored in \fIvar1\fR.
.RE
.IP \fBH\fR 5
The data is turned into a string of \fIcount\fR hexadecimal digits in
high-to-low order represented as a sequence of characters in the set
.QW 0123456789abcdef .
The data bytes are scanned in first to last
order with the hex digits being taken in high-to-low order within each
byte. Any extra bits in the last byte are ignored. If \fIcount\fR is

Changes to generic/tclBinary.c.

1514
1515
1516
1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527
1528
	str = format;
	flags = 0;
	if (!GetFormatSpec(&format, &cmd, &count, &flags)) {
	    goto done;
	}
	switch (cmd) {
	case 'a':

	case 'A': {
	    unsigned char *src;

	    if (arg >= objc) {
		DeleteScanNumberCache(numberCachePtr);
		goto badIndex;
	    }
	    if (count == BINARY_ALL) {






>
|







1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
	str = format;
	flags = 0;
	if (!GetFormatSpec(&format, &cmd, &count, &flags)) {
	    goto done;
	}
	switch (cmd) {
	case 'a':
	case 'A':
	case 'C': {
	    unsigned char *src;

	    if (arg >= objc) {
		DeleteScanNumberCache(numberCachePtr);
		goto badIndex;
	    }
	    if (count == BINARY_ALL) {
1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546







1547
1548
1549
1550
1551
1552
1553
		}
	    }

	    src = buffer + offset;
	    size = count;

	    /*

	     * Trim trailing nulls and spaces, if necessary.
	     */

	    if (cmd == 'A') {







		while (size > 0) {
		    if (src[size - 1] != '\0' && src[size - 1] != ' ') {
			break;
		    }
		    size--;
		}
	    }






>
|


|
>
>
>
>
>
>
>







1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
		}
	    }

	    src = buffer + offset;
	    size = count;

	    /*
	     * Apply C string semantics or trim trailing
	     * nulls and spaces, if necessary.
	     */

	    if (cmd == 'C') {
		for (i = 0; i < size; i++) {
		    if (src[i] == '\0') {
			size = i;
			break;
		    }
		}
	    } else if (cmd == 'A') {
		while (size > 0) {
		    if (src[size - 1] != '\0' && src[size - 1] != ' ') {
			break;
		    }
		    size--;
		}
	    }

Changes to tests/binary.test.

755
756
757
758
759
760
761
762









763
764
765
766
767
768
769
    list [binary scan "abc def \x00  " A* arg1] $arg1
} -result {1 {abc def}}
test binary-21.12 {Tcl_BinaryObjCmd: scan} -setup {
    unset -nocomplain arg1
} -body {
    list [binary scan "abc def \x00ghi  " A* arg1] $arg1
} -result [list 1 "abc def \x00ghi"]










test binary-22.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
    binary scan abc b
} -result {not enough arguments for all format specifiers}
test binary-22.2 {Tcl_BinaryObjCmd: scan} {
    unset -nocomplain arg1
    list [binary scan \x52\x53 b* arg1] $arg1
} {1 0100101011001010}






|
>
>
>
>
>
>
>
>
>







755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
    list [binary scan "abc def \x00  " A* arg1] $arg1
} -result {1 {abc def}}
test binary-21.12 {Tcl_BinaryObjCmd: scan} -setup {
    unset -nocomplain arg1
} -body {
    list [binary scan "abc def \x00ghi  " A* arg1] $arg1
} -result [list 1 "abc def \x00ghi"]
test binary-21.13 {Tcl_BinaryObjCmd: scan} -setup {
    unset -nocomplain arg1
} -body {
    list [binary scan "abc def \x00  " C* arg1] $arg1
} -result {1 {abc def }}
test binary-21.12 {Tcl_BinaryObjCmd: scan} -setup {
    unset -nocomplain arg1
} -body {
    list [binary scan "abc def \x00ghi" C* arg1] $arg1
} -result {1 {abc def }}
test binary-22.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
    binary scan abc b
} -result {not enough arguments for all format specifiers}
test binary-22.2 {Tcl_BinaryObjCmd: scan} {
    unset -nocomplain arg1
    list [binary scan \x52\x53 b* arg1] $arg1
} {1 0100101011001010}