Attachment "grouping_lsort.patch" to
ticket [2082681fff]
added by
kieranelby
2008-09-01 22:38:11.
0000: 3f 20 67 72 6f 75 70 69 6e 67 5f 6c 73 6f 72 74 ? grouping_lsort
0010: 2e 70 61 74 63 68 0a 49 6e 64 65 78 3a 20 64 6f .patch.Index: do
0020: 63 2f 6c 73 6f 72 74 2e 6e 0a 3d 3d 3d 3d 3d 3d c/lsort.n.======
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0060: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 =============.RC
0070: 53 20 66 69 6c 65 3a 20 2f 63 76 73 72 6f 6f 74 S file: /cvsroot
0080: 2f 74 63 6c 2f 74 63 6c 2f 64 6f 63 2f 6c 73 6f /tcl/tcl/doc/lso
0090: 72 74 2e 6e 2c 76 0a 72 65 74 72 69 65 76 69 6e rt.n,v.retrievin
00a0: 67 20 72 65 76 69 73 69 6f 6e 20 31 2e 33 30 0a g revision 1.30.
00b0: 64 69 66 66 20 2d 2d 75 6e 69 66 69 65 64 3d 33 diff --unified=3
00c0: 20 2d 72 31 2e 33 30 20 6c 73 6f 72 74 2e 6e 0a -r1.30 lsort.n.
00d0: 2d 2d 2d 20 64 6f 63 2f 6c 73 6f 72 74 2e 6e 09 --- doc/lsort.n.
00e0: 32 39 20 4a 75 6e 20 32 30 30 38 20 32 32 3a 32 29 Jun 2008 22:2
00f0: 38 3a 32 34 20 2d 30 30 30 30 09 31 2e 33 30 0a 8:24 -0000.1.30.
0100: 2b 2b 2b 20 64 6f 63 2f 6c 73 6f 72 74 2e 6e 09 +++ doc/lsort.n.
0110: 31 20 53 65 70 20 32 30 30 38 20 31 35 3a 33 35 1 Sep 2008 15:35
0120: 3a 35 35 20 2d 30 30 30 30 0a 40 40 20 2d 38 31 :55 -0000.@@ -81
0130: 2c 31 31 20 2b 38 31 2c 31 31 20 40 40 0a 20 5c ,11 +81,11 @@. \
0140: 66 42 5c 2d 69 6e 64 65 78 5c 30 5c 66 49 69 6e fB\-index\0\fIin
0150: 64 65 78 4c 69 73 74 5c 66 52 0a 20 2e 0a 20 49 dexList\fR. .. I
0160: 66 20 74 68 69 73 20 6f 70 74 69 6f 6e 20 69 73 f this option is
0170: 20 73 70 65 63 69 66 69 65 64 2c 20 65 61 63 68 specified, each
0180: 20 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e 74 73 of the elements
0190: 20 6f 66 20 5c 66 49 6c 69 73 74 5c 66 52 20 6d of \fIlist\fR m
01a0: 75 73 74 0a 2d 69 74 73 65 6c 66 20 62 65 20 61 ust.-itself be a
01b0: 20 70 72 6f 70 65 72 20 54 63 6c 20 73 75 62 6c proper Tcl subl
01c0: 69 73 74 2e 20 20 49 6e 73 74 65 61 64 20 6f 66 ist. Instead of
01d0: 20 73 6f 72 74 69 6e 67 20 62 61 73 65 64 20 6f sorting based o
01e0: 6e 20 77 68 6f 6c 65 0a 2d 73 75 62 6c 69 73 74 n whole.-sublist
01f0: 73 2c 20 5c 66 42 6c 73 6f 72 74 5c 66 52 20 77 s, \fBlsort\fR w
0200: 69 6c 6c 20 65 78 74 72 61 63 74 20 74 68 65 20 ill extract the
0210: 5c 66 49 69 6e 64 65 78 4c 69 73 74 5c 66 52 27 \fIindexList\fR'
0220: 74 68 20 65 6c 65 6d 65 6e 74 20 66 72 6f 6d 0a th element from.
0230: 2d 65 61 63 68 20 73 75 62 6c 69 73 74 0a 2d 28 -each sublist.-(
0240: 61 73 20 69 66 20 74 68 65 20 6f 76 65 72 61 6c as if the overal
0250: 6c 20 65 6c 65 6d 65 6e 74 20 61 6e 64 20 74 68 l element and th
0260: 65 20 5c 66 49 69 6e 64 65 78 4c 69 73 74 5c 66 e \fIindexList\f
0270: 52 20 77 65 72 65 20 70 61 73 73 65 64 20 74 6f R were passed to
0280: 0a 2d 5c 66 42 6c 69 6e 64 65 78 5c 66 52 29 20 .-\fBlindex\fR)
0290: 61 6e 64 20 73 6f 72 74 20 62 61 73 65 64 20 6f and sort based o
02a0: 6e 20 74 68 65 20 67 69 76 65 6e 20 65 6c 65 6d n the given elem
02b0: 65 6e 74 2e 20 20 0a 2b 69 74 73 65 6c 66 20 62 ent. .+itself b
02c0: 65 20 61 20 70 72 6f 70 65 72 20 54 63 6c 20 73 e a proper Tcl s
02d0: 75 62 6c 69 73 74 20 28 75 6e 6c 65 73 73 20 5c ublist (unless \
02e0: 66 42 2d 67 72 6f 75 70 5c 66 52 20 69 73 20 75 fB-group\fR is u
02f0: 73 65 64 29 2e 0a 2b 49 6e 73 74 65 61 64 20 6f sed)..+Instead o
0300: 66 20 73 6f 72 74 69 6e 67 20 62 61 73 65 64 20 f sorting based
0310: 6f 6e 20 77 68 6f 6c 65 20 73 75 62 6c 69 73 74 on whole sublist
0320: 73 2c 20 5c 66 42 6c 73 6f 72 74 5c 66 52 20 77 s, \fBlsort\fR w
0330: 69 6c 6c 20 65 78 74 72 61 63 74 0a 2b 74 68 65 ill extract.+the
0340: 20 5c 66 49 69 6e 64 65 78 4c 69 73 74 5c 66 52 \fIindexList\fR
0350: 27 74 68 20 65 6c 65 6d 65 6e 74 20 66 72 6f 6d 'th element from
0360: 20 65 61 63 68 20 73 75 62 6c 69 73 74 20 28 61 each sublist (a
0370: 73 20 69 66 20 74 68 65 20 6f 76 65 72 61 6c 6c s if the overall
0380: 0a 2b 65 6c 65 6d 65 6e 74 20 61 6e 64 20 74 68 .+element and th
0390: 65 20 5c 66 49 69 6e 64 65 78 4c 69 73 74 5c 66 e \fIindexList\f
03a0: 52 20 77 65 72 65 20 70 61 73 73 65 64 20 74 6f R were passed to
03b0: 20 5c 66 42 6c 69 6e 64 65 78 5c 66 52 29 20 61 \fBlindex\fR) a
03c0: 6e 64 20 73 6f 72 74 0a 2b 62 61 73 65 64 20 6f nd sort.+based o
03d0: 6e 20 74 68 65 20 67 69 76 65 6e 20 65 6c 65 6d n the given elem
03e0: 65 6e 74 2e 0a 20 46 6f 72 20 65 78 61 6d 70 6c ent.. For exampl
03f0: 65 2c 0a 20 2e 52 53 0a 20 2e 43 53 0a 40 40 20 e,. .RS. .CS.@@
0400: 2d 31 31 35 2c 36 20 2b 31 31 35 2c 33 30 20 40 -115,6 +115,30 @
0410: 40 0a 20 74 6f 20 61 63 68 69 65 76 65 20 74 68 @. to achieve th
0420: 65 20 73 61 6d 65 20 65 66 66 65 63 74 2e 0a 20 e same effect..
0430: 2e 52 45 0a 20 2e 54 50 20 32 30 0a 2b 5c 66 42 .RE. .TP 20.+\fB
0440: 5c 2d 67 72 6f 75 70 5c 30 5c 66 49 67 72 70 53 \-group\0\fIgrpS
0450: 69 7a 65 5c 66 52 0a 2b 2e 0a 2b 49 66 20 74 68 ize\fR.+..+If th
0460: 69 73 20 6f 70 74 69 6f 6e 20 69 73 20 73 70 65 is option is spe
0470: 63 69 66 69 65 64 2c 20 74 68 65 20 6c 69 73 74 cified, the list
0480: 20 69 73 20 74 72 65 61 74 65 64 20 61 73 20 63 is treated as c
0490: 6f 6e 73 69 73 74 69 6e 67 20 6f 66 0a 2b 67 72 onsisting of.+gr
04a0: 6f 75 70 73 20 6f 66 20 5c 66 49 67 72 70 53 69 oups of \fIgrpSi
04b0: 7a 65 5c 66 52 20 65 6c 65 6d 65 6e 74 73 20 61 ze\fR elements a
04c0: 6e 64 20 74 68 65 20 67 72 6f 75 70 73 20 61 72 nd the groups ar
04d0: 65 20 73 6f 72 74 65 64 20 62 79 0a 2b 65 69 74 e sorted by.+eit
04e0: 68 65 72 20 74 68 65 69 72 20 66 69 72 73 74 20 her their first
04f0: 65 6c 65 6d 65 6e 74 20 6f 72 2c 20 69 66 20 74 element or, if t
0500: 68 65 20 5c 66 42 2d 69 6e 64 65 78 5c 66 52 20 he \fB-index\fR
0510: 6f 70 74 69 6f 6e 20 69 73 20 75 73 65 64 2c 0a option is used,.
0520: 2b 62 79 20 74 68 65 20 65 6c 65 6d 65 6e 74 20 +by the element
0530: 77 69 74 68 69 6e 20 65 61 63 68 20 67 72 6f 75 within each grou
0540: 70 20 67 69 76 65 6e 20 62 79 20 74 68 65 20 66 p given by the f
0550: 69 72 73 74 20 69 6e 64 65 78 20 70 61 73 73 65 irst index passe
0560: 64 20 74 6f 0a 2b 5c 66 42 2d 69 6e 64 65 78 5c d to.+\fB-index\
0570: 66 52 20 28 77 68 69 63 68 20 69 73 20 74 68 65 fR (which is the
0580: 6e 20 69 67 6e 6f 72 65 64 20 62 79 20 5c 66 42 n ignored by \fB
0590: 2d 69 6e 64 65 78 5c 66 52 29 2e 20 45 6c 65 6d -index\fR). Elem
05a0: 65 6e 74 73 0a 2b 61 6c 77 61 79 73 20 72 65 6d ents.+always rem
05b0: 61 69 6e 20 69 6e 20 74 68 65 20 73 61 6d 65 20 ain in the same
05c0: 70 6f 73 69 74 69 6f 6e 20 77 69 74 68 69 6e 20 position within
05d0: 74 68 65 69 72 20 67 72 6f 75 70 2e 0a 2b 2e 0a their group..+..
05e0: 2b 54 68 65 20 6c 69 73 74 20 6c 65 6e 67 74 68 +The list length
05f0: 20 6d 75 73 74 20 62 65 20 61 6e 20 69 6e 74 65 must be an inte
0600: 67 65 72 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 ger multiple of
0610: 5c 66 49 67 72 70 53 69 7a 65 5c 66 52 2c 20 77 \fIgrpSize\fR, w
0620: 68 69 63 68 0a 2b 69 6e 20 74 75 72 6e 20 6d 75 hich.+in turn mu
0630: 73 74 20 62 65 20 61 74 20 6c 65 61 73 74 20 32 st be at least 2
0640: 2e 0a 2b 2e 0a 2b 46 6f 72 20 65 78 61 6d 70 6c ..+..+For exampl
0650: 65 2c 0a 2b 2e 52 53 0a 2b 2e 43 53 0a 2b 6c 73 e,.+.RS.+.CS.+ls
0660: 6f 72 74 20 2d 67 72 6f 75 70 20 32 20 7b 63 61 ort -group 2 {ca
0670: 72 72 6f 74 20 31 30 20 61 70 70 6c 65 20 35 30 rrot 10 apple 50
0680: 20 62 61 6e 61 6e 61 20 32 35 7d 0a 2b 2e 43 45 banana 25}.+.CE
0690: 0a 2b 72 65 74 75 72 6e 73 20 7b 61 70 70 6c 65 .+returns {apple
06a0: 20 35 30 20 62 61 6e 61 6e 61 20 32 35 20 63 61 50 banana 25 ca
06b0: 72 72 6f 74 20 31 30 7d 2c 20 61 6e 64 0a 2b 2e rrot 10}, and.+.
06c0: 43 53 0a 2b 6c 73 6f 72 74 20 2d 67 72 6f 75 70 CS.+lsort -group
06d0: 20 32 20 2d 69 6e 64 65 78 20 31 20 2d 69 6e 74 2 -index 1 -int
06e0: 65 67 65 72 20 7b 63 61 72 72 6f 74 20 31 30 20 eger {carrot 10
06f0: 61 70 70 6c 65 20 35 30 20 62 61 6e 61 6e 61 20 apple 50 banana
0700: 32 35 7d 0a 2b 2e 43 45 0a 2b 72 65 74 75 72 6e 25}.+.CE.+return
0710: 73 20 7b 63 61 72 72 6f 74 20 31 30 20 62 61 6e s {carrot 10 ban
0720: 61 6e 61 20 32 35 20 61 70 70 6c 65 20 35 30 7d ana 25 apple 50}
0730: 2e 0a 2b 2e 52 45 0a 2b 2e 54 50 20 32 30 0a 20 ..+.RE.+.TP 20.
0740: 5c 66 42 5c 2d 6e 6f 63 61 73 65 5c 66 52 0a 20 \fB\-nocase\fR.
0750: 2e 0a 20 43 61 75 73 65 73 20 63 6f 6d 70 61 72 .. Causes compar
0760: 69 73 6f 6e 73 20 74 6f 20 62 65 20 68 61 6e 64 isons to be hand
0770: 6c 65 64 20 69 6e 20 61 20 63 61 73 65 2d 69 6e led in a case-in
0780: 73 65 6e 73 69 74 69 76 65 20 6d 61 6e 6e 65 72 sensitive manner
0790: 2e 20 20 48 61 73 20 6e 6f 0a 40 40 20 2d 31 38 . Has no.@@ -18
07a0: 30 2c 36 20 2b 32 30 34 2c 31 34 20 40 40 0a 20 0,6 +204,14 @@.
07b0: 7b 65 20 31 7d 20 7b 64 20 32 7d 20 7b 20 63 20 {e 1} {d 2} { c
07c0: 33 7d 20 7b 62 20 34 7d 20 7b 61 20 35 7d 0a 20 3} {b 4} {a 5}.
07d0: 2e 43 45 0a 20 2e 50 50 0a 2b 53 6f 72 74 69 6e .CE. .PP.+Sortin
07e0: 67 20 75 73 69 6e 67 20 67 72 6f 75 70 69 6e 67 g using grouping
07f0: 20 61 6e 64 20 6d 75 6c 74 69 70 6c 65 20 69 6e and multiple in
0800: 64 69 63 65 73 3a 0a 2b 2e 43 53 0a 2b 25 20 23 dices:.+.CS.+% #
0810: 20 4e 6f 74 65 20 74 68 65 20 66 69 72 73 74 20 Note the first
0820: 69 6e 64 65 78 20 76 61 6c 75 65 20 69 73 20 72 index value is r
0830: 65 6c 61 74 69 76 65 20 74 6f 20 74 68 65 20 67 elative to the g
0840: 72 6f 75 70 0a 2b 25 20 5c 66 42 6c 73 6f 72 74 roup.+% \fBlsort
0850: 5c 66 52 20 2d 67 72 6f 75 70 20 33 20 2d 69 6e \fR -group 3 -in
0860: 64 65 78 20 7b 30 20 31 7d 20 5c 65 0a 2b 20 20 dex {0 1} \e.+
0870: 20 20 20 7b 7b 42 6f 62 20 53 6d 69 74 68 7d 20 {{Bob Smith}
0880: 32 35 20 41 75 64 69 20 7b 4a 61 6e 65 20 44 6f 25 Audi {Jane Do
0890: 65 7d 20 34 30 20 46 6f 72 64 7d 0a 2b 7b 7b 4a e} 40 Ford}.+{{J
08a0: 61 6e 65 20 44 6f 65 7d 20 34 30 20 46 6f 72 64 ane Doe} 40 Ford
08b0: 20 7b 42 6f 62 20 53 6d 69 74 68 7d 20 32 35 20 {Bob Smith} 25
08c0: 41 75 64 69 7d 0a 2b 2e 43 45 0a 2b 2e 50 50 0a Audi}.+.CE.+.PP.
08d0: 20 53 74 72 69 70 70 69 6e 67 20 64 75 70 6c 69 Stripping dupli
08e0: 63 61 74 65 20 76 61 6c 75 65 73 20 75 73 69 6e cate values usin
08f0: 67 20 73 6f 72 74 69 6e 67 3a 0a 20 2e 43 53 0a g sorting:. .CS.
0900: 20 25 20 5c 66 42 6c 73 6f 72 74 5c 66 52 20 2d % \fBlsort\fR -
0910: 75 6e 69 71 75 65 20 7b 61 20 62 20 63 20 61 20 unique {a b c a
0920: 62 20 63 20 61 20 62 20 63 7d 0a 49 6e 64 65 78 b c a b c}.Index
0930: 3a 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 6d 64 : generic/tclCmd
0940: 49 4c 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d IL.c.===========
0950: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0960: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0970: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0980: 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c ========.RCS fil
0990: 65 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f e: /cvsroot/tcl/
09a0: 74 63 6c 2f 67 65 6e 65 72 69 63 2f 74 63 6c 43 tcl/generic/tclC
09b0: 6d 64 49 4c 2e 63 2c 76 0a 72 65 74 72 69 65 76 mdIL.c,v.retriev
09c0: 69 6e 67 20 72 65 76 69 73 69 6f 6e 20 31 2e 31 ing revision 1.1
09d0: 35 31 0a 64 69 66 66 20 2d 2d 75 6e 69 66 69 65 51.diff --unifie
09e0: 64 3d 33 20 2d 72 31 2e 31 35 31 20 74 63 6c 43 d=3 -r1.151 tclC
09f0: 6d 64 49 4c 2e 63 0a 2d 2d 2d 20 67 65 6e 65 72 mdIL.c.--- gener
0a00: 69 63 2f 74 63 6c 43 6d 64 49 4c 2e 63 09 32 31 ic/tclCmdIL.c.21
0a10: 20 41 75 67 20 32 30 30 38 20 32 33 3a 35 37 3a Aug 2008 23:57:
0a20: 34 33 20 2d 30 30 30 30 09 31 2e 31 35 31 0a 2b 43 -0000.1.151.+
0a30: 2b 2b 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 6d ++ generic/tclCm
0a40: 64 49 4c 2e 63 09 31 20 53 65 70 20 32 30 30 38 dIL.c.1 Sep 2008
0a50: 20 31 35 3a 33 35 3a 35 36 20 2d 30 30 30 30 0a 15:35:56 -0000.
0a60: 40 40 20 2d 33 34 38 31 2c 31 38 20 2b 33 34 38 @@ -3481,18 +348
0a70: 31 2c 32 30 20 40 40 0a 20 20 20 20 20 54 63 6c 1,20 @@. Tcl
0a80: 5f 4f 62 6a 20 2a 63 6f 6e 73 74 20 6f 62 6a 76 _Obj *const objv
0a90: 5b 5d 29 09 2f 2a 20 41 72 67 75 6d 65 6e 74 20 [])./* Argument
0aa0: 76 61 6c 75 65 73 2e 20 2a 2f 0a 20 7b 0a 20 20 values. */. {.
0ab0: 20 20 20 69 6e 74 20 69 2c 20 6a 2c 20 69 6e 64 int i, j, ind
0ac0: 65 78 2c 20 75 6e 69 71 75 65 2c 20 69 6e 64 69 ex, unique, indi
0ad0: 63 65 73 2c 20 6c 65 6e 67 74 68 2c 20 6e 6f 63 ces, length, noc
0ae0: 61 73 65 20 3d 20 30 2c 20 73 6f 72 74 4d 6f 64 ase = 0, sortMod
0af0: 65 2c 20 69 6e 64 65 78 63 3b 0a 2b 20 20 20 20 e, indexc;.+
0b00: 69 6e 74 20 67 72 6f 75 70 2c 20 67 72 6f 75 70 int group, group
0b10: 73 69 7a 65 2c 20 67 72 6f 75 70 6f 66 66 73 65 size, groupoffse
0b20: 74 2c 20 69 64 78 2c 20 2a 6e 65 77 5f 69 6e 64 t, idx, *new_ind
0b30: 65 78 76 3b 0a 20 20 20 20 20 54 63 6c 5f 4f 62 exv;. Tcl_Ob
0b40: 6a 20 2a 72 65 73 75 6c 74 50 74 72 2c 20 2a 63 j *resultPtr, *c
0b50: 6d 64 50 74 72 2c 20 2a 2a 6c 69 73 74 4f 62 6a mdPtr, **listObj
0b60: 50 74 72 73 2c 20 2a 6c 69 73 74 4f 62 6a 2c 20 Ptrs, *listObj,
0b70: 2a 69 6e 64 65 78 50 74 72 3b 0a 20 20 20 20 20 *indexPtr;.
0b80: 53 6f 72 74 45 6c 65 6d 65 6e 74 20 2a 65 6c 65 SortElement *ele
0b90: 6d 65 6e 74 41 72 72 61 79 2c 20 2a 65 6c 65 6d mentArray, *elem
0ba0: 65 6e 74 50 74 72 3b 0a 20 20 20 20 20 53 6f 72 entPtr;. Sor
0bb0: 74 49 6e 66 6f 20 73 6f 72 74 49 6e 66 6f 3b 09 tInfo sortInfo;.
0bc0: 09 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 ./* Information
0bd0: 61 62 6f 75 74 20 74 68 69 73 20 73 6f 72 74 20 about this sort
0be0: 74 68 61 74 20 6e 65 65 64 73 20 74 6f 0a 20 09 that needs to. .
0bf0: 09 09 09 20 2a 20 62 65 20 70 61 73 73 65 64 20 ... * be passed
0c00: 74 6f 20 74 68 65 20 63 6f 6d 70 61 72 69 73 6f to the compariso
0c10: 6e 20 66 75 6e 63 74 69 6f 6e 2e 20 2a 2f 0a 20 n function. */.
0c20: 20 20 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 static const
0c30: 20 63 68 61 72 20 2a 73 77 69 74 63 68 65 73 5b char *switches[
0c40: 5d 20 3d 20 7b 0a 20 09 22 2d 61 73 63 69 69 22 ] = {. ."-ascii"
0c50: 2c 20 22 2d 63 6f 6d 6d 61 6e 64 22 2c 20 22 2d , "-command", "-
0c60: 64 65 63 72 65 61 73 69 6e 67 22 2c 20 22 2d 64 decreasing", "-d
0c70: 69 63 74 69 6f 6e 61 72 79 22 2c 20 22 2d 69 6e ictionary", "-in
0c80: 63 72 65 61 73 69 6e 67 22 2c 0a 2d 09 22 2d 69 creasing",.-."-i
0c90: 6e 64 65 78 22 2c 20 22 2d 69 6e 64 69 63 65 73 ndex", "-indices
0ca0: 22 2c 20 22 2d 69 6e 74 65 67 65 72 22 2c 20 22 ", "-integer", "
0cb0: 2d 6e 6f 63 61 73 65 22 2c 20 22 2d 72 65 61 6c -nocase", "-real
0cc0: 22 2c 20 22 2d 75 6e 69 71 75 65 22 2c 20 4e 55 ", "-unique", NU
0cd0: 4c 4c 0a 2b 09 22 2d 69 6e 64 65 78 22 2c 20 22 LL.+."-index", "
0ce0: 2d 69 6e 64 69 63 65 73 22 2c 20 22 2d 69 6e 74 -indices", "-int
0cf0: 65 67 65 72 22 2c 20 22 2d 6e 6f 63 61 73 65 22 eger", "-nocase"
0d00: 2c 20 22 2d 72 65 61 6c 22 2c 20 22 2d 75 6e 69 , "-real", "-uni
0d10: 71 75 65 22 2c 0a 2b 09 22 2d 67 72 6f 75 70 22 que",.+."-group"
0d20: 2c 20 4e 55 4c 4c 0a 20 20 20 20 20 7d 3b 0a 20 , NULL. };.
0d30: 20 20 20 20 65 6e 75 6d 20 4c 73 6f 72 74 5f 53 enum Lsort_S
0d40: 77 69 74 63 68 65 73 20 7b 0a 20 09 4c 53 4f 52 witches {. .LSOR
0d50: 54 5f 41 53 43 49 49 2c 20 4c 53 4f 52 54 5f 43 T_ASCII, LSORT_C
0d60: 4f 4d 4d 41 4e 44 2c 20 4c 53 4f 52 54 5f 44 45 OMMAND, LSORT_DE
0d70: 43 52 45 41 53 49 4e 47 2c 20 4c 53 4f 52 54 5f CREASING, LSORT_
0d80: 44 49 43 54 49 4f 4e 41 52 59 2c 0a 20 09 4c 53 DICTIONARY,. .LS
0d90: 4f 52 54 5f 49 4e 43 52 45 41 53 49 4e 47 2c 20 ORT_INCREASING,
0da0: 4c 53 4f 52 54 5f 49 4e 44 45 58 2c 20 4c 53 4f LSORT_INDEX, LSO
0db0: 52 54 5f 49 4e 44 49 43 45 53 2c 20 4c 53 4f 52 RT_INDICES, LSOR
0dc0: 54 5f 49 4e 54 45 47 45 52 2c 0a 2d 09 4c 53 4f T_INTEGER,.-.LSO
0dd0: 52 54 5f 4e 4f 43 41 53 45 2c 20 4c 53 4f 52 54 RT_NOCASE, LSORT
0de0: 5f 52 45 41 4c 2c 20 4c 53 4f 52 54 5f 55 4e 49 _REAL, LSORT_UNI
0df0: 51 55 45 0a 2b 09 4c 53 4f 52 54 5f 4e 4f 43 41 QUE.+.LSORT_NOCA
0e00: 53 45 2c 20 4c 53 4f 52 54 5f 52 45 41 4c 2c 20 SE, LSORT_REAL,
0e10: 4c 53 4f 52 54 5f 55 4e 49 51 55 45 2c 20 4c 53 LSORT_UNIQUE, LS
0e20: 4f 52 54 5f 47 52 4f 55 50 0a 20 20 20 20 20 7d ORT_GROUP. }
0e30: 3b 0a 20 0a 20 20 20 20 20 2f 2a 0a 40 40 20 2d ;. . /*.@@ -
0e40: 33 35 32 31 2c 36 20 2b 33 35 32 33 2c 39 20 40 3521,6 +3523,9 @
0e50: 40 0a 20 20 20 20 20 63 6d 64 50 74 72 20 3d 20 @. cmdPtr =
0e60: 4e 55 4c 4c 3b 0a 20 20 20 20 20 75 6e 69 71 75 NULL;. uniqu
0e70: 65 20 3d 20 30 3b 0a 20 20 20 20 20 69 6e 64 69 e = 0;. indi
0e80: 63 65 73 20 3d 20 30 3b 0a 2b 20 20 20 20 67 72 ces = 0;.+ gr
0e90: 6f 75 70 20 3d 20 30 3b 0a 2b 20 20 20 20 67 72 oup = 0;.+ gr
0ea0: 6f 75 70 73 69 7a 65 20 3d 20 31 3b 0a 2b 20 20 oupsize = 1;.+
0eb0: 20 20 67 72 6f 75 70 6f 66 66 73 65 74 20 3d 20 groupoffset =
0ec0: 30 3b 0a 20 20 20 20 20 66 6f 72 20 28 69 20 3d 0;. for (i =
0ed0: 20 31 3b 20 69 20 3c 20 6f 62 6a 63 2d 31 3b 20 1; i < objc-1;
0ee0: 69 2b 2b 29 20 7b 0a 20 09 69 66 20 28 54 63 6c i++) {. .if (Tcl
0ef0: 5f 47 65 74 49 6e 64 65 78 46 72 6f 6d 4f 62 6a _GetIndexFromObj
0f00: 28 69 6e 74 65 72 70 2c 20 6f 62 6a 76 5b 69 5d (interp, objv[i]
0f10: 2c 20 73 77 69 74 63 68 65 73 2c 20 22 6f 70 74 , switches, "opt
0f20: 69 6f 6e 22 2c 20 30 2c 0a 20 09 09 26 69 6e 64 ion", 0,. ..&ind
0f30: 65 78 29 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b ex) != TCL_OK) {
0f40: 0a 40 40 20 2d 33 36 32 31 2c 36 20 2b 33 36 32 .@@ -3621,6 +362
0f50: 36 2c 33 33 20 40 40 0a 20 09 63 61 73 65 20 4c 6,33 @@. .case L
0f60: 53 4f 52 54 5f 49 4e 44 49 43 45 53 3a 0a 20 09 SORT_INDICES:. .
0f70: 20 20 20 20 69 6e 64 69 63 65 73 20 3d 20 31 3b indices = 1;
0f80: 0a 20 09 20 20 20 20 62 72 65 61 6b 3b 0a 2b 09 . . break;.+.
0f90: 63 61 73 65 20 4c 53 4f 52 54 5f 47 52 4f 55 50 case LSORT_GROUP
0fa0: 3a 0a 2b 09 09 69 66 20 28 69 20 3d 3d 20 28 6f :.+..if (i == (o
0fb0: 62 6a 63 2d 32 29 29 20 7b 0a 2b 09 09 09 69 66 bjc-2)) {.+...if
0fc0: 20 28 73 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 (sortInfo.index
0fd0: 63 20 3e 20 31 29 20 7b 0a 2b 09 09 09 09 63 6b c > 1) {.+....ck
0fe0: 66 72 65 65 28 28 63 68 61 72 20 2a 29 20 73 6f free((char *) so
0ff0: 72 74 49 6e 66 6f 2e 69 6e 64 65 78 76 29 3b 0a rtInfo.indexv);.
1000: 2b 09 09 09 7d 0a 2b 09 09 09 54 63 6c 5f 41 70 +...}.+...Tcl_Ap
1010: 70 65 6e 64 52 65 73 75 6c 74 28 69 6e 74 65 72 pendResult(inter
1020: 70 2c 0a 2b 09 09 09 09 22 5c 22 2d 67 72 6f 75 p,.+...."\"-grou
1030: 70 5c 22 20 6f 70 74 69 6f 6e 20 6d 75 73 74 20 p\" option must
1040: 62 65 20 66 6f 6c 6c 6f 77 65 64 20 22 0a 2b 09 be followed ".+.
1050: 09 09 09 22 62 79 20 67 72 6f 75 70 20 73 69 7a ..."by group siz
1060: 65 22 2c 20 4e 55 4c 4c 29 3b 0a 2b 09 09 09 72 e", NULL);.+...r
1070: 65 74 75 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b eturn TCL_ERROR;
1080: 0a 2b 09 09 7d 0a 2b 09 09 69 66 20 28 54 63 6c .+..}.+..if (Tcl
1090: 5f 47 65 74 49 6e 74 46 72 6f 6d 4f 62 6a 28 69 _GetIntFromObj(i
10a0: 6e 74 65 72 70 2c 20 6f 62 6a 76 5b 69 2b 31 5d nterp, objv[i+1]
10b0: 2c 20 26 67 72 6f 75 70 73 69 7a 65 29 20 21 3d , &groupsize) !=
10c0: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 2b 09 09 09 69 TCL_OK) {.+...i
10d0: 66 20 28 73 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 f (sortInfo.inde
10e0: 78 63 20 3e 20 31 29 20 7b 0a 2b 09 09 09 09 63 xc > 1) {.+....c
10f0: 6b 66 72 65 65 28 28 63 68 61 72 20 2a 29 20 73 kfree((char *) s
1100: 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 76 29 3b ortInfo.indexv);
1110: 0a 2b 09 09 09 7d 0a 2b 09 09 09 54 63 6c 5f 41 .+...}.+...Tcl_A
1120: 70 70 65 6e 64 52 65 73 75 6c 74 28 69 6e 74 65 ppendResult(inte
1130: 72 70 2c 20 22 20 74 6f 20 5c 22 2d 67 72 6f 75 rp, " to \"-grou
1140: 70 5c 22 20 6f 70 74 69 6f 6e 22 2c 20 4e 55 4c p\" option", NUL
1150: 4c 29 3b 0a 2b 09 09 09 72 65 74 75 72 6e 20 54 L);.+...return T
1160: 43 4c 5f 45 52 52 4f 52 3b 0a 2b 09 09 7d 0a 2b CL_ERROR;.+..}.+
1170: 09 09 69 66 20 28 67 72 6f 75 70 73 69 7a 65 20 ..if (groupsize
1180: 3c 20 32 29 20 7b 0a 2b 09 09 09 69 66 20 28 73 < 2) {.+...if (s
1190: 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 63 20 3e ortInfo.indexc >
11a0: 20 31 29 20 7b 0a 2b 09 09 09 09 63 6b 66 72 65 1) {.+....ckfre
11b0: 65 28 28 63 68 61 72 20 2a 29 20 73 6f 72 74 49 e((char *) sortI
11c0: 6e 66 6f 2e 69 6e 64 65 78 76 29 3b 0a 2b 09 09 nfo.indexv);.+..
11d0: 09 7d 0a 2b 09 09 09 54 63 6c 5f 41 70 70 65 6e .}.+...Tcl_Appen
11e0: 64 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 dResult(interp,
11f0: 22 67 72 6f 75 70 20 73 69 7a 65 20 6d 75 73 74 "group size must
1200: 20 62 65 20 61 74 20 6c 65 61 73 74 20 32 22 2c be at least 2",
1210: 20 4e 55 4c 4c 29 3b 0a 2b 09 09 09 72 65 74 75 NULL);.+...retu
1220: 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 2b 09 rn TCL_ERROR;.+.
1230: 09 7d 0a 2b 09 09 67 72 6f 75 70 20 3d 20 31 3b .}.+..group = 1;
1240: 0a 2b 09 09 69 2b 2b 3b 0a 2b 09 09 62 72 65 61 .+..i++;.+..brea
1250: 6b 3b 0a 20 09 7d 0a 20 20 20 20 20 7d 0a 20 20 k;. .}. }.
1260: 20 20 20 69 66 20 28 6e 6f 63 61 73 65 20 26 26 if (nocase &&
1270: 20 28 73 6f 72 74 49 6e 66 6f 2e 73 6f 72 74 4d (sortInfo.sortM
1280: 6f 64 65 20 3d 3d 20 53 4f 52 54 4d 4f 44 45 5f ode == SORTMODE_
1290: 41 53 43 49 49 29 29 20 7b 0a 40 40 20 2d 33 36 ASCII)) {.@@ -36
12a0: 37 35 2c 36 20 2b 33 37 30 37 2c 34 36 20 40 40 75,6 +3707,46 @@
12b0: 0a 20 20 20 20 20 69 66 20 28 73 6f 72 74 49 6e . if (sortIn
12c0: 66 6f 2e 72 65 73 75 6c 74 43 6f 64 65 20 21 3d fo.resultCode !=
12d0: 20 54 43 4c 5f 4f 4b 20 7c 7c 20 6c 65 6e 67 74 TCL_OK || lengt
12e0: 68 20 3c 3d 20 30 29 20 7b 0a 20 09 67 6f 74 6f h <= 0) {. .goto
12f0: 20 64 6f 6e 65 3b 0a 20 20 20 20 20 7d 0a 2b 0a done;. }.+.
1300: 2b 09 69 66 20 28 67 72 6f 75 70 29 20 7b 0a 2b +.if (group) {.+
1310: 09 09 69 66 20 28 6c 65 6e 67 74 68 20 25 20 67 ..if (length % g
1320: 72 6f 75 70 73 69 7a 65 29 20 7b 0a 2b 09 09 09 roupsize) {.+...
1330: 54 63 6c 5f 41 70 70 65 6e 64 52 65 73 75 6c 74 Tcl_AppendResult
1340: 28 69 6e 74 65 72 70 2c 0a 2b 09 09 09 20 20 22 (interp,.+... "
1350: 6c 69 73 74 20 73 69 7a 65 20 6d 75 73 74 20 62 list size must b
1360: 65 20 61 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 e a multiple of
1370: 74 68 65 20 67 72 6f 75 70 20 73 69 7a 65 22 2c the group size",
1380: 20 4e 55 4c 4c 29 3b 0a 2b 09 09 09 73 6f 72 74 NULL);.+...sort
1390: 49 6e 66 6f 2e 72 65 73 75 6c 74 43 6f 64 65 20 Info.resultCode
13a0: 3d 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 2b 09 09 = TCL_ERROR;.+..
13b0: 09 67 6f 74 6f 20 64 6f 6e 65 3b 0a 2b 09 09 7d .goto done;.+..}
13c0: 0a 2b 09 09 6c 65 6e 67 74 68 20 3d 20 6c 65 6e .+..length = len
13d0: 67 74 68 20 2f 20 67 72 6f 75 70 73 69 7a 65 3b gth / groupsize;
13e0: 0a 2b 09 09 69 66 20 28 73 6f 72 74 49 6e 66 6f .+..if (sortInfo
13f0: 2e 69 6e 64 65 78 63 20 3e 20 30 29 20 7b 0a 2b .indexc > 0) {.+
1400: 09 09 09 2f 2a 0a 2b 09 09 09 2a 20 55 73 65 20 .../*.+...* Use
1410: 74 68 65 20 66 69 72 73 74 20 76 61 6c 75 65 20 the first value
1420: 69 6e 20 74 68 65 20 6c 69 73 74 20 73 75 70 70 in the list supp
1430: 6c 69 65 64 20 74 6f 20 2d 69 6e 64 65 78 20 61 lied to -index a
1440: 73 20 74 68 65 20 6f 66 66 73 65 74 0a 2b 09 09 s the offset.+..
1450: 09 2a 20 6f 66 20 74 68 65 20 65 6c 65 6d 65 6e .* of the elemen
1460: 74 20 77 69 74 68 69 6e 20 65 61 63 68 20 67 72 t within each gr
1470: 6f 75 70 20 62 79 20 77 68 69 63 68 20 74 6f 20 oup by which to
1480: 73 6f 72 74 2e 0a 2b 09 09 09 2a 2f 0a 2b 09 09 sort..+...*/.+..
1490: 09 67 72 6f 75 70 6f 66 66 73 65 74 20 3d 20 73 .groupoffset = s
14a0: 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 76 5b 30 ortInfo.indexv[0
14b0: 5d 3b 0a 2b 09 09 09 69 66 20 28 67 72 6f 75 70 ];.+...if (group
14c0: 6f 66 66 73 65 74 20 3c 3d 20 53 4f 52 54 49 44 offset <= SORTID
14d0: 58 5f 45 4e 44 29 20 7b 0a 2b 09 09 09 09 67 72 X_END) {.+....gr
14e0: 6f 75 70 6f 66 66 73 65 74 20 3d 20 28 67 72 6f oupoffset = (gro
14f0: 75 70 6f 66 66 73 65 74 20 2d 20 53 4f 52 54 49 upoffset - SORTI
1500: 44 58 5f 45 4e 44 29 20 2b 20 67 72 6f 75 70 73 DX_END) + groups
1510: 69 7a 65 20 2d 20 31 3b 0a 2b 09 09 09 7d 0a 2b ize - 1;.+...}.+
1520: 09 09 09 69 66 20 28 67 72 6f 75 70 6f 66 66 73 ...if (groupoffs
1530: 65 74 20 3c 20 30 20 7c 7c 20 67 72 6f 75 70 6f et < 0 || groupo
1540: 66 66 73 65 74 20 3e 3d 20 67 72 6f 75 70 73 69 ffset >= groupsi
1550: 7a 65 29 20 7b 0a 2b 09 09 09 09 54 63 6c 5f 41 ze) {.+....Tcl_A
1560: 70 70 65 6e 64 52 65 73 75 6c 74 28 69 6e 74 65 ppendResult(inte
1570: 72 70 2c 0a 2b 09 09 09 09 20 20 22 77 68 65 6e rp,.+.... "when
1580: 20 75 73 65 64 20 77 69 74 68 20 5c 22 2d 67 72 used with \"-gr
1590: 6f 75 70 5c 22 2c 20 74 68 65 20 6c 65 61 64 69 oup\", the leadi
15a0: 6e 67 20 5c 22 2d 69 6e 64 65 78 5c 22 20 76 61 ng \"-index\" va
15b0: 6c 75 65 20 22 2c 0a 2b 09 09 09 09 20 20 22 20 lue ",.+.... "
15c0: 6d 75 73 74 20 62 65 20 77 69 74 68 69 6e 20 74 must be within t
15d0: 68 65 20 67 72 6f 75 70 22 2c 20 4e 55 4c 4c 29 he group", NULL)
15e0: 3b 0a 2b 09 09 09 09 73 6f 72 74 49 6e 66 6f 2e ;.+....sortInfo.
15f0: 72 65 73 75 6c 74 43 6f 64 65 20 3d 20 54 43 4c resultCode = TCL
1600: 5f 45 52 52 4f 52 3b 0a 2b 09 09 09 09 67 6f 74 _ERROR;.+....got
1610: 6f 20 64 6f 6e 65 3b 0a 2b 09 09 09 7d 0a 2b 09 o done;.+...}.+.
1620: 09 09 69 66 20 28 73 6f 72 74 49 6e 66 6f 2e 69 ..if (sortInfo.i
1630: 6e 64 65 78 63 20 3d 3d 20 31 29 20 7b 0a 2b 09 ndexc == 1) {.+.
1640: 09 09 09 73 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 ...sortInfo.inde
1650: 78 63 20 3d 20 30 3b 0a 2b 09 09 09 09 73 6f 72 xc = 0;.+....sor
1660: 74 49 6e 66 6f 2e 69 6e 64 65 78 76 20 3d 20 4e tInfo.indexv = N
1670: 55 4c 4c 3b 0a 2b 09 09 09 7d 20 65 6c 73 65 20 ULL;.+...} else
1680: 7b 0a 2b 09 09 09 09 73 6f 72 74 49 6e 66 6f 2e {.+....sortInfo.
1690: 69 6e 64 65 78 63 2d 2d 3b 0a 2b 09 09 09 09 6e indexc--;.+....n
16a0: 65 77 5f 69 6e 64 65 78 76 20 3d 20 28 69 6e 74 ew_indexv = (int
16b0: 20 2a 29 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 *) ckalloc(size
16c0: 6f 66 28 69 6e 74 29 20 2a 20 73 6f 72 74 49 6e of(int) * sortIn
16d0: 66 6f 2e 69 6e 64 65 78 63 29 3b 0a 2b 09 09 09 fo.indexc);.+...
16e0: 09 66 6f 72 20 28 69 20 3d 20 30 3b 20 69 20 3c .for (i = 0; i <
16f0: 20 73 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 63 sortInfo.indexc
1700: 3b 20 69 2b 2b 29 20 7b 0a 2b 09 09 09 09 09 6e ; i++) {.+.....n
1710: 65 77 5f 69 6e 64 65 78 76 5b 69 5d 20 3d 20 73 ew_indexv[i] = s
1720: 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 76 5b 69 ortInfo.indexv[i
1730: 2b 31 5d 3b 0a 2b 09 09 09 09 7d 0a 2b 09 09 09 +1];.+....}.+...
1740: 09 63 6b 66 72 65 65 28 28 63 68 61 72 20 2a 29 .ckfree((char *)
1750: 20 73 6f 72 74 49 6e 66 6f 2e 69 6e 64 65 78 76 sortInfo.indexv
1760: 29 3b 0a 2b 09 09 09 09 73 6f 72 74 49 6e 66 6f );.+....sortInfo
1770: 2e 69 6e 64 65 78 76 20 3d 20 6e 65 77 5f 69 6e .indexv = new_in
1780: 64 65 78 76 3b 0a 2b 09 09 09 7d 0a 2b 09 09 7d dexv;.+...}.+..}
1790: 0a 2b 09 7d 0a 2b 0a 20 20 20 20 20 73 6f 72 74 .+.}.+. sort
17a0: 49 6e 66 6f 2e 6e 75 6d 45 6c 65 6d 65 6e 74 73 Info.numElements
17b0: 20 3d 20 6c 65 6e 67 74 68 3b 0a 20 0a 20 20 20 = length;. .
17c0: 20 20 69 6e 64 65 78 63 20 3d 20 73 6f 72 74 49 indexc = sortI
17d0: 6e 66 6f 2e 69 6e 64 65 78 63 3b 0a 40 40 20 2d nfo.indexc;.@@ -
17e0: 33 37 30 36 2c 31 36 20 2b 33 37 37 38 2c 31 37 3706,16 +3778,17
17f0: 20 40 40 0a 20 20 20 20 20 65 6c 65 6d 65 6e 74 @@. element
1800: 41 72 72 61 79 20 3d 20 28 53 6f 72 74 45 6c 65 Array = (SortEle
1810: 6d 65 6e 74 20 2a 29 20 63 6b 61 6c 6c 6f 63 28 ment *) ckalloc(
1820: 20 6c 65 6e 67 74 68 20 2a 20 73 69 7a 65 6f 66 length * sizeof
1830: 28 53 6f 72 74 45 6c 65 6d 65 6e 74 29 29 3b 0a (SortElement));.
1840: 20 0a 20 20 20 20 20 66 6f 72 20 28 69 3d 30 3b . for (i=0;
1850: 20 69 20 3c 20 6c 65 6e 67 74 68 3b 20 69 2b 2b i < length; i++
1860: 29 7b 0a 2b 09 69 64 78 20 3d 20 67 72 6f 75 70 ){.+.idx = group
1870: 73 69 7a 65 20 2a 20 69 20 2b 20 67 72 6f 75 70 size * i + group
1880: 6f 66 66 73 65 74 3b 0a 20 09 69 66 20 28 69 6e offset;. .if (in
1890: 64 65 78 63 29 20 7b 0a 20 09 20 20 20 20 2f 2a dexc) {. . /*
18a0: 0a 20 09 20 20 20 20 20 2a 20 49 66 20 74 68 69 . . * If thi
18b0: 73 20 69 73 20 61 6e 20 69 6e 64 65 78 65 64 20 s is an indexed
18c0: 73 6f 72 74 2c 20 72 65 74 72 69 65 76 65 20 74 sort, retrieve t
18d0: 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 he corresponding
18e0: 20 65 6c 65 6d 65 6e 74 0a 20 09 20 20 20 20 20 element. .
18f0: 2a 2f 0a 2d 09 20 20 20 20 69 6e 64 65 78 50 74 */.-. indexPt
1900: 72 20 3d 20 53 65 6c 65 63 74 4f 62 6a 46 72 6f r = SelectObjFro
1910: 6d 53 75 62 6c 69 73 74 28 6c 69 73 74 4f 62 6a mSublist(listObj
1920: 50 74 72 73 5b 69 5d 2c 20 26 73 6f 72 74 49 6e Ptrs[i], &sortIn
1930: 66 6f 29 3b 0a 2b 09 20 20 20 20 69 6e 64 65 78 fo);.+. index
1940: 50 74 72 20 3d 20 53 65 6c 65 63 74 4f 62 6a 46 Ptr = SelectObjF
1950: 72 6f 6d 53 75 62 6c 69 73 74 28 6c 69 73 74 4f romSublist(listO
1960: 62 6a 50 74 72 73 5b 69 64 78 5d 2c 20 26 73 6f bjPtrs[idx], &so
1970: 72 74 49 6e 66 6f 29 3b 0a 20 09 20 20 20 20 69 rtInfo);. . i
1980: 66 20 28 73 6f 72 74 49 6e 66 6f 2e 72 65 73 75 f (sortInfo.resu
1990: 6c 74 43 6f 64 65 20 21 3d 20 54 43 4c 5f 4f 4b ltCode != TCL_OK
19a0: 29 20 7b 0a 20 09 09 67 6f 74 6f 20 64 6f 6e 65 ) {. ..goto done
19b0: 31 3b 0a 20 09 20 20 20 20 7d 0a 20 09 7d 20 65 1;. . }. .} e
19c0: 6c 73 65 20 7b 0a 2d 09 20 20 20 20 69 6e 64 65 lse {.-. inde
19d0: 78 50 74 72 20 3d 20 6c 69 73 74 4f 62 6a 50 74 xPtr = listObjPt
19e0: 72 73 5b 69 5d 3b 0a 2b 09 20 20 20 20 69 6e 64 rs[i];.+. ind
19f0: 65 78 50 74 72 20 3d 20 6c 69 73 74 4f 62 6a 50 exPtr = listObjP
1a00: 74 72 73 5b 69 64 78 5d 3b 0a 20 09 7d 0a 20 0a trs[idx];. .}. .
1a10: 20 09 2f 2a 0a 40 40 20 2d 33 37 34 37 2c 37 20 ./*.@@ -3747,7
1a20: 2b 33 38 32 30 2c 31 31 20 40 40 0a 20 09 20 2a +3820,11 @@. . *
1a30: 20 74 68 65 20 6f 62 6a 50 74 72 20 69 74 73 65 the objPtr itse
1a40: 6c 66 2c 20 6f 72 20 69 74 73 20 69 6e 64 65 78 lf, or its index
1a50: 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e 61 6c in the original
1a60: 20 6c 69 73 74 2e 0a 20 09 20 2a 2f 0a 20 0a 2d list.. . */. .-
1a70: 09 65 6c 65 6d 65 6e 74 41 72 72 61 79 5b 69 5d .elementArray[i]
1a80: 2e 6f 62 6a 50 74 72 20 3d 20 28 69 6e 64 69 63 .objPtr = (indic
1a90: 65 73 20 3f 20 49 4e 54 32 50 54 52 28 69 29 20 es ? INT2PTR(i)
1aa0: 3a 20 6c 69 73 74 4f 62 6a 50 74 72 73 5b 69 5d : listObjPtrs[i]
1ab0: 29 3b 0a 2b 09 69 66 20 28 69 6e 64 69 63 65 73 );.+.if (indices
1ac0: 20 7c 7c 20 67 72 6f 75 70 29 20 7b 0a 2b 09 09 || group) {.+..
1ad0: 65 6c 65 6d 65 6e 74 41 72 72 61 79 5b 69 5d 2e elementArray[i].
1ae0: 6f 62 6a 50 74 72 20 3d 20 49 4e 54 32 50 54 52 objPtr = INT2PTR
1af0: 28 69 64 78 29 3b 0a 2b 09 7d 20 65 6c 73 65 20 (idx);.+.} else
1b00: 7b 0a 2b 09 09 65 6c 65 6d 65 6e 74 41 72 72 61 {.+..elementArra
1b10: 79 5b 69 5d 2e 6f 62 6a 50 74 72 20 3d 20 6c 69 y[i].objPtr = li
1b20: 73 74 4f 62 6a 50 74 72 73 5b 69 64 78 5d 3b 0a stObjPtrs[idx];.
1b30: 2b 09 7d 0a 20 0a 20 09 2f 2a 0a 20 09 20 2a 20 +.}. . ./*. . *
1b40: 4d 65 72 67 65 20 74 68 69 73 20 65 6c 65 6d 65 Merge this eleme
1b50: 6e 74 20 69 6e 20 74 68 65 20 70 72 65 2d 65 78 nt in the pre-ex
1b60: 69 73 74 69 6e 67 20 73 75 62 6c 69 73 74 73 20 isting sublists
1b70: 28 61 6e 64 20 6d 65 72 67 65 20 74 6f 67 65 74 (and merge toget
1b80: 68 65 72 0a 40 40 20 2d 33 37 38 35 2c 31 30 20 her.@@ -3785,10
1b90: 2b 33 38 36 32 2c 32 35 20 40 40 0a 20 09 54 63 +3862,25 @@. .Tc
1ba0: 6c 5f 4f 62 6a 20 2a 2a 6e 65 77 41 72 72 61 79 l_Obj **newArray
1bb0: 2c 20 2a 6f 62 6a 50 74 72 3b 0a 20 09 69 6e 74 , *objPtr;. .int
1bc0: 20 69 3b 0a 20 0a 2d 09 72 65 73 75 6c 74 50 74 i;. .-.resultPt
1bd0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
1be0: 62 6a 28 73 6f 72 74 49 6e 66 6f 2e 6e 75 6d 45 bj(sortInfo.numE
1bf0: 6c 65 6d 65 6e 74 73 2c 20 4e 55 4c 4c 29 3b 0a lements, NULL);.
1c00: 2b 09 72 65 73 75 6c 74 50 74 72 20 3d 20 54 63 +.resultPtr = Tc
1c10: 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 73 6f 72 l_NewListObj(sor
1c20: 74 49 6e 66 6f 2e 6e 75 6d 45 6c 65 6d 65 6e 74 tInfo.numElement
1c30: 73 20 2a 20 67 72 6f 75 70 73 69 7a 65 2c 20 4e s * groupsize, N
1c40: 55 4c 4c 29 3b 0a 20 09 6c 69 73 74 52 65 70 50 ULL);. .listRepP
1c50: 74 72 20 3d 20 28 4c 69 73 74 20 2a 29 20 72 65 tr = (List *) re
1c60: 73 75 6c 74 50 74 72 2d 3e 69 6e 74 65 72 6e 61 sultPtr->interna
1c70: 6c 52 65 70 2e 74 77 6f 50 74 72 56 61 6c 75 65 lRep.twoPtrValue
1c80: 2e 70 74 72 31 3b 0a 20 09 6e 65 77 41 72 72 61 .ptr1;. .newArra
1c90: 79 20 3d 20 26 6c 69 73 74 52 65 70 50 74 72 2d y = &listRepPtr-
1ca0: 3e 65 6c 65 6d 65 6e 74 73 3b 0a 2d 09 69 66 20 >elements;.-.if
1cb0: 28 69 6e 64 69 63 65 73 29 20 7b 0a 2b 09 69 66 (indices) {.+.if
1cc0: 20 28 67 72 6f 75 70 29 20 7b 0a 2b 09 09 66 6f (group) {.+..fo
1cd0: 72 20 28 69 20 3d 20 30 3b 20 65 6c 65 6d 65 6e r (i = 0; elemen
1ce0: 74 50 74 72 20 21 3d 20 4e 55 4c 4c 20 3b 20 65 tPtr != NULL ; e
1cf0: 6c 65 6d 65 6e 74 50 74 72 20 3d 20 65 6c 65 6d lementPtr = elem
1d00: 65 6e 74 50 74 72 2d 3e 6e 65 78 74 50 74 72 29 entPtr->nextPtr)
1d10: 20 7b 0a 2b 09 09 09 69 64 78 20 3d 20 50 54 52 {.+...idx = PTR
1d20: 32 49 4e 54 28 65 6c 65 6d 65 6e 74 50 74 72 2d 2INT(elementPtr-
1d30: 3e 6f 62 6a 50 74 72 29 3b 0a 2b 09 09 09 66 6f >objPtr);.+...fo
1d40: 72 20 28 6a 20 3d 20 30 3b 20 6a 20 3c 20 67 72 r (j = 0; j < gr
1d50: 6f 75 70 73 69 7a 65 3b 20 6a 2b 2b 29 20 7b 0a oupsize; j++) {.
1d60: 2b 09 09 09 09 69 66 20 28 69 6e 64 69 63 65 73 +....if (indices
1d70: 29 20 7b 0a 2b 09 09 09 09 09 6f 62 6a 50 74 72 ) {.+.....objPtr
1d80: 20 3d 20 54 63 6c 5f 4e 65 77 49 6e 74 4f 62 6a = Tcl_NewIntObj
1d90: 28 69 64 78 20 2b 20 6a 20 2d 20 67 72 6f 75 70 (idx + j - group
1da0: 6f 66 66 73 65 74 29 3b 0a 2b 09 09 09 09 09 6e offset);.+.....n
1db0: 65 77 41 72 72 61 79 5b 69 2b 2b 5d 20 3d 20 6f ewArray[i++] = o
1dc0: 62 6a 50 74 72 3b 0a 2b 09 09 09 09 09 54 63 6c bjPtr;.+.....Tcl
1dd0: 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f 62 _IncrRefCount(ob
1de0: 6a 50 74 72 29 3b 0a 2b 09 09 09 09 7d 20 65 6c jPtr);.+....} el
1df0: 73 65 20 7b 0a 2b 09 09 09 09 09 6f 62 6a 50 74 se {.+.....objPt
1e00: 72 20 3d 20 6c 69 73 74 4f 62 6a 50 74 72 73 5b r = listObjPtrs[
1e10: 69 64 78 20 2b 20 6a 20 2d 20 67 72 6f 75 70 6f idx + j - groupo
1e20: 66 66 73 65 74 5d 3b 0a 2b 09 09 09 09 09 6e 65 ffset];.+.....ne
1e30: 77 41 72 72 61 79 5b 69 2b 2b 5d 20 3d 20 6f 62 wArray[i++] = ob
1e40: 6a 50 74 72 3b 0a 2b 09 09 09 09 09 54 63 6c 5f jPtr;.+.....Tcl_
1e50: 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f 62 6a IncrRefCount(obj
1e60: 50 74 72 29 3b 0a 2b 09 09 09 09 7d 0a 2b 09 09 Ptr);.+....}.+..
1e70: 09 7d 0a 2b 09 09 7d 0a 2b 09 7d 20 65 6c 73 65 .}.+..}.+.} else
1e80: 20 69 66 20 28 69 6e 64 69 63 65 73 29 20 7b 0a if (indices) {.
1e90: 20 09 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 . for (i = 0
1ea0: 3b 20 65 6c 65 6d 65 6e 74 50 74 72 20 21 3d 20 ; elementPtr !=
1eb0: 4e 55 4c 4c 20 3b 20 65 6c 65 6d 65 6e 74 50 74 NULL ; elementPt
1ec0: 72 20 3d 20 65 6c 65 6d 65 6e 74 50 74 72 2d 3e r = elementPtr->
1ed0: 6e 65 78 74 50 74 72 29 7b 0a 20 09 09 6f 62 6a nextPtr){. ..obj
1ee0: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 49 6e 74 Ptr = Tcl_NewInt
1ef0: 4f 62 6a 28 50 54 52 32 49 4e 54 28 65 6c 65 6d Obj(PTR2INT(elem
1f00: 65 6e 74 50 74 72 2d 3e 6f 62 6a 50 74 72 29 29 entPtr->objPtr))
1f10: 3b 0a 20 09 09 6e 65 77 41 72 72 61 79 5b 69 2b ;. ..newArray[i+
1f20: 2b 5d 20 3d 20 6f 62 6a 50 74 72 3b 0a +] = objPtr;.