Attachment "regsub-code.patch" to
ticket [652953ffff]
added by
nobody
2002-12-13 04:51:56.
0000: 2d 2d 2d 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 --- generic/tclC
0010: 6d 64 4d 5a 2e 63 09 54 75 65 20 4f 63 74 20 31 mdMZ.c.Tue Oct 1
0020: 35 20 31 33 3a 34 39 3a 30 37 20 32 30 30 32 0a 5 13:49:07 2002.
0030: 2b 2b 2b 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 +++ generic/tclC
0040: 6d 64 4d 5a 5f 72 65 67 73 75 62 2d 63 6f 64 65 mdMZ_regsub-code
0050: 2e 63 09 54 68 75 20 44 65 63 20 31 32 20 31 36 .c.Thu Dec 12 16
0060: 3a 32 34 3a 30 37 20 32 30 30 32 0a 40 40 20 2d :24:07 2002.@@ -
0070: 35 32 35 2c 37 20 2b 35 32 35 2c 37 20 40 40 0a 525,7 +525,7 @@.
0080: 20 20 20 20 20 69 6e 74 20 6f 62 6a 63 3b 09 09 int objc;..
0090: 09 09 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 ../* Number of a
00a0: 72 67 75 6d 65 6e 74 73 2e 20 2a 2f 0a 20 20 20 rguments. */.
00b0: 20 20 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 Tcl_Obj *CONST
00c0: 20 6f 62 6a 76 5b 5d 3b 09 09 2f 2a 20 41 72 67 objv[];../* Arg
00d0: 75 6d 65 6e 74 20 6f 62 6a 65 63 74 73 2e 20 2a ument objects. *
00e0: 2f 0a 20 7b 0a 2d 20 20 20 20 69 6e 74 20 69 64 /. {.- int id
00f0: 78 2c 20 72 65 73 75 6c 74 2c 20 63 66 6c 61 67 x, result, cflag
0100: 73 2c 20 61 6c 6c 2c 20 77 6c 65 6e 2c 20 77 73 s, all, wlen, ws
0110: 75 62 6c 65 6e 2c 20 6e 75 6d 4d 61 74 63 68 65 ublen, numMatche
0120: 73 2c 20 6f 66 66 73 65 74 3b 0a 2b 20 20 20 20 s, offset;.+
0130: 69 6e 74 20 69 64 78 2c 20 72 65 73 75 6c 74 2c int idx, result,
0140: 20 63 66 6c 61 67 73 2c 20 61 6c 6c 2c 20 63 6f cflags, all, co
0150: 64 65 2c 20 77 6c 65 6e 2c 20 77 73 75 62 6c 65 de, wlen, wsuble
0160: 6e 2c 20 6e 75 6d 4d 61 74 63 68 65 73 2c 20 6f n, numMatches, o
0170: 66 66 73 65 74 3b 0a 20 20 20 20 20 69 6e 74 20 ffset;. int
0180: 73 74 61 72 74 2c 20 65 6e 64 2c 20 73 75 62 53 start, end, subS
0190: 74 61 72 74 2c 20 73 75 62 45 6e 64 2c 20 6d 61 tart, subEnd, ma
01a0: 74 63 68 3b 0a 20 20 20 20 20 54 63 6c 5f 52 65 tch;. Tcl_Re
01b0: 67 45 78 70 20 72 65 67 45 78 70 72 3b 0a 20 20 gExp regExpr;.
01c0: 20 20 20 54 63 6c 5f 52 65 67 45 78 70 49 6e 66 Tcl_RegExpInf
01d0: 6f 20 69 6e 66 6f 3b 0a 40 40 20 2d 35 33 33 2c o info;.@@ -533,
01e0: 31 38 20 2b 35 33 33 2c 31 39 20 40 40 0a 20 20 18 +533,19 @@.
01f0: 20 20 20 54 63 6c 5f 55 6e 69 43 68 61 72 20 63 Tcl_UniChar c
0200: 68 2c 20 2a 77 73 72 63 2c 20 2a 77 66 69 72 73 h, *wsrc, *wfirs
0210: 74 43 68 61 72 2c 20 2a 77 73 74 72 69 6e 67 2c tChar, *wstring,
0220: 20 2a 77 73 75 62 73 70 65 63 2c 20 2a 77 65 6e *wsubspec, *wen
0230: 64 3b 0a 20 0a 20 20 20 20 20 73 74 61 74 69 63 d;. . static
0240: 20 43 4f 4e 53 54 20 63 68 61 72 20 2a 6f 70 74 CONST char *opt
0250: 69 6f 6e 73 5b 5d 20 3d 20 7b 0a 2d 09 22 2d 61 ions[] = {.-."-a
0260: 6c 6c 22 2c 09 09 22 2d 6e 6f 63 61 73 65 22 2c ll",.."-nocase",
0270: 09 22 2d 65 78 70 61 6e 64 65 64 22 2c 0a 2b 09 ."-expanded",.+.
0280: 22 2d 61 6c 6c 22 2c 09 09 22 2d 6e 6f 63 61 73 "-all",.."-nocas
0290: 65 22 2c 09 22 2d 65 78 70 61 6e 64 65 64 22 2c e",."-expanded",
02a0: 09 22 2d 63 6f 64 65 22 2c 0a 20 09 22 2d 6c 69 ."-code",. ."-li
02b0: 6e 65 22 2c 09 22 2d 6c 69 6e 65 73 74 6f 70 22 ne",."-linestop"
02c0: 2c 09 22 2d 6c 69 6e 65 61 6e 63 68 6f 72 22 2c ,."-lineanchor",
02d0: 09 22 2d 73 74 61 72 74 22 2c 0a 20 09 22 2d 2d ."-start",. ."--
02e0: 22 2c 09 09 4e 55 4c 4c 0a 20 20 20 20 20 7d 3b ",..NULL. };
02f0: 0a 20 20 20 20 20 65 6e 75 6d 20 6f 70 74 69 6f . enum optio
0300: 6e 73 20 7b 0a 2d 09 52 45 47 53 55 42 5f 41 4c ns {.-.REGSUB_AL
0310: 4c 2c 09 52 45 47 53 55 42 5f 4e 4f 43 41 53 45 L,.REGSUB_NOCASE
0320: 2c 09 52 45 47 53 55 42 5f 45 58 50 41 4e 44 45 ,.REGSUB_EXPANDE
0330: 44 2c 0a 2b 09 52 45 47 53 55 42 5f 41 4c 4c 2c D,.+.REGSUB_ALL,
0340: 09 52 45 47 53 55 42 5f 4e 4f 43 41 53 45 2c 09 .REGSUB_NOCASE,.
0350: 52 45 47 53 55 42 5f 45 58 50 41 4e 44 45 44 2c REGSUB_EXPANDED,
0360: 09 52 45 47 53 55 42 5f 43 4f 44 45 2c 0a 20 09 .REGSUB_CODE,. .
0370: 52 45 47 53 55 42 5f 4c 49 4e 45 2c 09 52 45 47 REGSUB_LINE,.REG
0380: 53 55 42 5f 4c 49 4e 45 53 54 4f 50 2c 20 52 45 SUB_LINESTOP, RE
0390: 47 53 55 42 5f 4c 49 4e 45 41 4e 43 48 4f 52 2c GSUB_LINEANCHOR,
03a0: 09 52 45 47 53 55 42 5f 53 54 41 52 54 2c 0a 20 .REGSUB_START,.
03b0: 09 52 45 47 53 55 42 5f 4c 41 53 54 0a 20 20 20 .REGSUB_LAST.
03c0: 20 20 7d 3b 0a 20 0a 20 20 20 20 20 63 66 6c 61 };. . cfla
03d0: 67 73 20 3d 20 54 43 4c 5f 52 45 47 5f 41 44 56 gs = TCL_REG_ADV
03e0: 41 4e 43 45 44 3b 0a 20 20 20 20 20 61 6c 6c 20 ANCED;. all
03f0: 3d 20 30 3b 0a 2b 20 20 20 20 63 6f 64 65 20 3d = 0;.+ code =
0400: 20 30 3b 0a 20 20 20 20 20 6f 66 66 73 65 74 20 0;. offset
0410: 3d 20 30 3b 0a 20 20 20 20 20 72 65 73 75 6c 74 = 0;. result
0420: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 0a 40 40 Ptr = NULL;. .@@
0430: 20 2d 35 36 35 2c 36 20 2b 35 36 36 2c 31 30 20 -565,6 +566,10
0440: 40 40 0a 20 09 09 61 6c 6c 20 3d 20 31 3b 0a 20 @@. ..all = 1;.
0450: 09 09 62 72 65 61 6b 3b 0a 20 09 20 20 20 20 7d ..break;. . }
0460: 0a 2b 09 20 20 20 20 63 61 73 65 20 52 45 47 53 .+. case REGS
0470: 55 42 5f 43 4f 44 45 3a 20 7b 0a 2b 09 09 63 6f UB_CODE: {.+..co
0480: 64 65 20 3d 20 31 3b 0a 2b 09 09 62 72 65 61 6b de = 1;.+..break
0490: 3b 0a 2b 09 20 20 20 20 7d 0a 20 09 20 20 20 20 ;.+. }. .
04a0: 63 61 73 65 20 52 45 47 53 55 42 5f 4e 4f 43 41 case REGSUB_NOCA
04b0: 53 45 3a 20 7b 0a 20 09 09 63 66 6c 61 67 73 20 SE: {. ..cflags
04c0: 7c 3d 20 54 43 4c 5f 52 45 47 5f 4e 4f 43 41 53 |= TCL_REG_NOCAS
04d0: 45 3b 0a 20 09 09 62 72 65 61 6b 3b 0a 40 40 20 E;. ..break;.@@
04e0: 2d 37 35 38 2c 35 35 20 2b 37 36 33 2c 31 32 39 -758,55 +763,129
04f0: 20 40 40 0a 20 09 65 6e 64 20 3d 20 69 6e 66 6f @@. .end = info
0500: 2e 6d 61 74 63 68 65 73 5b 30 5d 2e 65 6e 64 3b .matches[0].end;
0510: 0a 20 09 54 63 6c 5f 41 70 70 65 6e 64 55 6e 69 . .Tcl_AppendUni
0520: 63 6f 64 65 54 6f 4f 62 6a 28 72 65 73 75 6c 74 codeToObj(result
0530: 50 74 72 2c 20 77 73 74 72 69 6e 67 20 2b 20 6f Ptr, wstring + o
0540: 66 66 73 65 74 2c 20 73 74 61 72 74 29 3b 0a 20 ffset, start);.
0550: 0a 2d 09 2f 2a 0a 2d 09 20 2a 20 41 70 70 65 6e .-./*.-. * Appen
0560: 64 20 74 68 65 20 73 75 62 53 70 65 63 20 61 72 d the subSpec ar
0570: 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 76 61 gument to the va
0580: 72 69 61 62 6c 65 2c 20 6d 61 6b 69 6e 67 20 61 riable, making a
0590: 70 70 72 6f 70 72 69 61 74 65 0a 2d 09 20 2a 20 ppropriate.-. *
05a0: 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2e 20 20 substitutions.
05b0: 54 68 69 73 20 63 6f 64 65 20 69 73 20 61 20 62 This code is a b
05c0: 69 74 20 68 61 69 72 79 20 62 65 63 61 75 73 65 it hairy because
05d0: 20 6f 66 20 74 68 65 20 62 61 63 6b 73 6c 61 73 of the backslas
05e0: 68 0a 2d 09 20 2a 20 63 6f 6e 76 65 6e 74 69 6f h.-. * conventio
05f0: 6e 73 20 61 6e 64 20 62 65 63 61 75 73 65 20 74 ns and because t
0600: 68 65 20 63 6f 64 65 20 73 61 76 65 73 20 75 70 he code saves up
0610: 20 72 61 6e 67 65 73 20 6f 66 20 63 68 61 72 61 ranges of chara
0620: 63 74 65 72 73 20 69 6e 0a 2d 09 20 2a 20 73 75 cters in.-. * su
0630: 62 53 70 65 63 20 74 6f 20 72 65 64 75 63 65 20 bSpec to reduce
0640: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 61 the number of ca
0650: 6c 6c 73 20 74 6f 20 54 63 6c 5f 53 65 74 56 61 lls to Tcl_SetVa
0660: 72 2e 0a 2d 09 20 2a 2f 0a 2b 09 69 66 20 28 63 r..-. */.+.if (c
0670: 6f 64 65 29 20 7b 0a 2b 09 20 20 20 20 54 63 6c ode) {.+. Tcl
0680: 5f 4f 62 6a 20 2a 76 61 72 6e 61 6d 65 2c 20 2a _Obj *varname, *
0690: 2a 70 72 65 73 65 72 76 65 64 3b 0a 2b 09 20 20 *preserved;.+.
06a0: 20 20 76 61 72 6e 61 6d 65 20 3d 20 54 63 6c 5f varname = Tcl_
06b0: 4e 65 77 4f 62 6a 28 29 3b 0a 2b 09 20 20 20 20 NewObj();.+.
06c0: 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 Tcl_IncrRefCount
06d0: 28 76 61 72 6e 61 6d 65 29 3b 0a 2b 0a 2b 09 20 (varname);.+.+.
06e0: 20 20 20 2f 2a 20 53 65 74 20 76 61 72 69 61 62 /* Set variab
06f0: 6c 65 73 20 66 72 6f 6d 20 30 2d 6e 20 61 6e 64 les from 0-n and
0700: 20 70 72 65 73 65 72 76 65 20 74 68 65 20 6f 6c preserve the ol
0710: 64 20 76 61 6c 75 65 73 20 2a 2f 0a 2b 09 20 20 d values */.+.
0720: 20 20 70 72 65 73 65 72 76 65 64 20 3d 20 28 54 preserved = (T
0730: 63 6c 5f 4f 62 6a 20 2a 2a 29 63 6b 61 6c 6c 6f cl_Obj **)ckallo
0740: 63 28 73 69 7a 65 6f 66 28 54 63 6c 5f 4f 62 6a c(sizeof(Tcl_Obj
0750: 20 2a 29 20 2a 0a 2b 09 09 20 20 20 20 28 69 6e *) *.+.. (in
0760: 66 6f 2e 6e 73 75 62 73 20 2b 20 31 29 29 3b 0a fo.nsubs + 1));.
0770: 2b 09 20 20 20 20 66 6f 72 20 28 69 64 78 20 3d +. for (idx =
0780: 20 30 3b 20 69 64 78 20 3c 3d 20 69 6e 66 6f 2e 0; idx <= info.
0790: 6e 73 75 62 73 3b 20 69 64 78 2b 2b 29 20 7b 0a nsubs; idx++) {.
07a0: 2b 09 09 54 63 6c 5f 53 65 74 49 6e 74 4f 62 6a +..Tcl_SetIntObj
07b0: 28 76 61 72 6e 61 6d 65 2c 20 69 64 78 29 3b 0a (varname, idx);.
07c0: 20 0a 2d 09 77 73 72 63 20 3d 20 77 66 69 72 73 .-.wsrc = wfirs
07d0: 74 43 68 61 72 20 3d 20 77 73 75 62 73 70 65 63 tChar = wsubspec
07e0: 3b 0a 2d 09 77 65 6e 64 20 3d 20 77 73 75 62 73 ;.-.wend = wsubs
07f0: 70 65 63 20 2b 20 77 73 75 62 6c 65 6e 3b 0a 2d pec + wsublen;.-
0800: 09 66 6f 72 20 28 63 68 20 3d 20 2a 77 73 72 63 .for (ch = *wsrc
0810: 3b 20 77 73 72 63 20 21 3d 20 77 65 6e 64 3b 20 ; wsrc != wend;
0820: 77 73 72 63 2b 2b 2c 20 63 68 20 3d 20 2a 77 73 wsrc++, ch = *ws
0830: 72 63 29 20 7b 0a 2d 09 20 20 20 20 69 66 20 28 rc) {.-. if (
0840: 63 68 20 3d 3d 20 27 26 27 29 20 7b 0a 2d 09 09 ch == '&') {.-..
0850: 69 64 78 20 3d 20 30 3b 0a 2d 09 20 20 20 20 7d idx = 0;.-. }
0860: 20 65 6c 73 65 20 69 66 20 28 63 68 20 3d 3d 20 else if (ch ==
0870: 27 5c 5c 27 29 20 7b 0a 2d 09 09 63 68 20 3d 20 '\\') {.-..ch =
0880: 77 73 72 63 5b 31 5d 3b 0a 2d 09 09 69 66 20 28 wsrc[1];.-..if (
0890: 28 63 68 20 3e 3d 20 27 30 27 29 20 26 26 20 28 (ch >= '0') && (
08a0: 63 68 20 3c 3d 20 27 39 27 29 29 20 7b 0a 2d 09 ch <= '9')) {.-.
08b0: 09 20 20 20 20 69 64 78 20 3d 20 63 68 20 2d 20 . idx = ch -
08c0: 27 30 27 3b 0a 2d 09 09 7d 20 65 6c 73 65 20 69 '0';.-..} else i
08d0: 66 20 28 28 63 68 20 3d 3d 20 27 5c 5c 27 29 20 f ((ch == '\\')
08e0: 7c 7c 20 28 63 68 20 3d 3d 20 27 26 27 29 29 20 || (ch == '&'))
08f0: 7b 0a 2d 09 09 20 20 20 20 2a 77 73 72 63 20 3d {.-.. *wsrc =
0900: 20 63 68 3b 0a 2d 09 09 20 20 20 20 54 63 6c 5f ch;.-.. Tcl_
0910: 41 70 70 65 6e 64 55 6e 69 63 6f 64 65 54 6f 4f AppendUnicodeToO
0920: 62 6a 28 72 65 73 75 6c 74 50 74 72 2c 20 77 66 bj(resultPtr, wf
0930: 69 72 73 74 43 68 61 72 2c 0a 2d 09 09 09 20 20 irstChar,.-...
0940: 20 20 77 73 72 63 20 2d 20 77 66 69 72 73 74 43 wsrc - wfirstC
0950: 68 61 72 20 2b 20 31 29 3b 0a 2d 09 09 20 20 20 har + 1);.-..
0960: 20 2a 77 73 72 63 20 3d 20 27 5c 5c 27 3b 0a 2d *wsrc = '\\';.-
0970: 09 09 20 20 20 20 77 66 69 72 73 74 43 68 61 72 .. wfirstChar
0980: 20 3d 20 77 73 72 63 20 2b 20 32 3b 0a 2d 09 09 = wsrc + 2;.-..
0990: 20 20 20 20 77 73 72 63 2b 2b 3b 0a 2d 09 09 20 wsrc++;.-..
09a0: 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 2b 09 09 continue;.+..
09b0: 73 75 62 53 74 61 72 74 20 3d 20 69 6e 66 6f 2e subStart = info.
09c0: 6d 61 74 63 68 65 73 5b 69 64 78 5d 2e 73 74 61 matches[idx].sta
09d0: 72 74 3b 0a 2b 09 09 73 75 62 45 6e 64 20 3d 20 rt;.+..subEnd =
09e0: 69 6e 66 6f 2e 6d 61 74 63 68 65 73 5b 69 64 78 info.matches[idx
09f0: 5d 2e 65 6e 64 3b 0a 2b 0a 2b 09 09 70 72 65 73 ].end;.+.+..pres
0a00: 65 72 76 65 64 5b 69 64 78 5d 20 3d 20 54 63 6c erved[idx] = Tcl
0a10: 5f 4f 62 6a 47 65 74 56 61 72 32 28 69 6e 74 65 _ObjGetVar2(inte
0a20: 72 70 2c 20 76 61 72 6e 61 6d 65 2c 20 4e 55 4c rp, varname, NUL
0a30: 4c 2c 20 30 29 3b 0a 2b 09 09 69 66 20 28 70 72 L, 0);.+..if (pr
0a40: 65 73 65 72 76 65 64 5b 69 64 78 5d 29 20 7b 0a eserved[idx]) {.
0a50: 2b 09 09 20 20 20 20 54 63 6c 5f 49 6e 63 72 52 +.. Tcl_IncrR
0a60: 65 66 43 6f 75 6e 74 28 70 72 65 73 65 72 76 65 efCount(preserve
0a70: 64 5b 69 64 78 5d 29 3b 0a 2b 09 09 7d 0a 2b 0a d[idx]);.+..}.+.
0a80: 2b 09 09 69 66 20 28 28 73 75 62 53 74 61 72 74 +..if ((subStart
0a90: 20 3e 3d 20 30 29 20 26 26 20 28 73 75 62 45 6e >= 0) && (subEn
0aa0: 64 20 3e 3d 20 30 29 29 20 7b 0a 2b 09 09 20 20 d >= 0)) {.+..
0ab0: 20 20 54 63 6c 5f 4f 62 6a 53 65 74 56 61 72 32 Tcl_ObjSetVar2
0ac0: 28 69 6e 74 65 72 70 2c 20 76 61 72 6e 61 6d 65 (interp, varname
0ad0: 2c 20 4e 55 4c 4c 2c 0a 2b 09 09 09 20 20 20 20 , NULL,.+...
0ae0: 54 63 6c 5f 4e 65 77 55 6e 69 63 6f 64 65 4f 62 Tcl_NewUnicodeOb
0af0: 6a 28 77 73 74 72 69 6e 67 20 2b 20 6f 66 66 73 j(wstring + offs
0b00: 65 74 20 2b 20 73 75 62 53 74 61 72 74 2c 0a 2b et + subStart,.+
0b10: 09 09 09 20 20 20 20 73 75 62 45 6e 64 20 2d 20 ... subEnd -
0b20: 73 75 62 53 74 61 72 74 29 2c 20 30 29 3b 0a 2b subStart), 0);.+
0b30: 09 09 7d 20 65 6c 73 65 20 7b 0a 2b 09 09 20 20 ..} else {.+..
0b40: 20 20 54 63 6c 5f 4f 62 6a 53 65 74 56 61 72 32 Tcl_ObjSetVar2
0b50: 28 69 6e 74 65 72 70 2c 20 76 61 72 6e 61 6d 65 (interp, varname
0b60: 2c 20 4e 55 4c 4c 2c 20 54 63 6c 5f 4e 65 77 4f , NULL, Tcl_NewO
0b70: 62 6a 28 29 2c 20 30 29 3b 0a 2b 09 09 7d 0a 2b bj(), 0);.+..}.+
0b80: 09 20 20 20 20 7d 0a 2b 0a 2b 09 20 20 20 20 2f . }.+.+. /
0b90: 2a 20 52 75 6e 20 74 68 65 20 63 6f 64 65 20 2a * Run the code *
0ba0: 2f 0a 2b 09 20 20 20 20 73 77 69 74 63 68 20 28 /.+. switch (
0bb0: 54 63 6c 5f 45 76 61 6c 4f 62 6a 45 78 28 69 6e Tcl_EvalObjEx(in
0bc0: 74 65 72 70 2c 20 73 75 62 50 74 72 2c 20 30 29 terp, subPtr, 0)
0bd0: 29 20 7b 0a 2b 09 09 63 61 73 65 20 54 43 4c 5f ) {.+..case TCL_
0be0: 4f 4b 3a 0a 2b 09 09 63 61 73 65 20 54 43 4c 5f OK:.+..case TCL_
0bf0: 52 45 54 55 52 4e 3a 20 7b 0a 2b 09 09 20 20 20 RETURN: {.+..
0c00: 20 54 63 6c 5f 41 70 70 65 6e 64 4f 62 6a 54 6f Tcl_AppendObjTo
0c10: 4f 62 6a 28 72 65 73 75 6c 74 50 74 72 2c 20 54 Obj(resultPtr, T
0c20: 63 6c 5f 47 65 74 4f 62 6a 52 65 73 75 6c 74 28 cl_GetObjResult(
0c30: 69 6e 74 65 72 70 29 29 3b 0a 2b 09 09 20 20 20 interp));.+..
0c40: 20 62 72 65 61 6b 3b 0a 2b 09 09 7d 0a 2b 09 09 break;.+..}.+..
0c50: 63 61 73 65 20 54 43 4c 5f 42 52 45 41 4b 3a 20 case TCL_BREAK:
0c60: 7b 0a 2b 09 09 20 20 20 20 2f 2a 20 52 65 70 6c {.+.. /* Repl
0c70: 61 63 65 20 6e 6f 74 68 69 6e 67 2c 20 61 6e 64 ace nothing, and
0c80: 20 68 61 6c 74 20 2d 61 6c 6c 20 2a 2f 0a 2b 09 halt -all */.+.
0c90: 09 20 20 20 20 54 63 6c 5f 41 70 70 65 6e 64 55 . Tcl_AppendU
0ca0: 6e 69 63 6f 64 65 54 6f 4f 62 6a 28 72 65 73 75 nicodeToObj(resu
0cb0: 6c 74 50 74 72 2c 20 77 73 74 72 69 6e 67 20 2b ltPtr, wstring +
0cc0: 20 6f 66 66 73 65 74 20 2b 20 73 74 61 72 74 2c offset + start,
0cd0: 0a 2b 09 09 09 20 20 20 20 65 6e 64 20 2d 20 73 .+... end - s
0ce0: 74 61 72 74 29 3b 0a 2b 09 09 20 20 20 20 61 6c tart);.+.. al
0cf0: 6c 20 3d 20 30 3b 0a 2b 09 09 20 20 20 20 62 72 l = 0;.+.. br
0d00: 65 61 6b 3b 0a 2b 09 09 7d 0a 2b 09 09 63 61 73 eak;.+..}.+..cas
0d10: 65 20 54 43 4c 5f 43 4f 4e 54 49 4e 55 45 3a 20 e TCL_CONTINUE:
0d20: 7b 0a 2b 09 09 20 20 20 20 54 63 6c 5f 41 64 64 {.+.. Tcl_Add
0d30: 45 72 72 6f 72 49 6e 66 6f 28 69 6e 74 65 72 70 ErrorInfo(interp
0d40: 2c 0a 2b 09 09 09 20 20 20 20 22 5c 22 63 6f 6e ,.+... "\"con
0d50: 74 69 6e 75 65 5c 22 20 63 61 6e 6e 6f 74 20 62 tinue\" cannot b
0d60: 65 20 69 6e 76 6f 6b 65 64 20 66 72 6f 6d 20 5c e invoked from \
0d70: 22 72 65 67 73 75 62 5c 22 22 29 3b 0a 2b 09 09 "regsub\"");.+..
0d80: 20 20 20 20 72 65 73 75 6c 74 20 3d 20 54 43 4c result = TCL
0d90: 5f 45 52 52 4f 52 3b 0a 2b 09 09 20 20 20 20 62 _ERROR;.+.. b
0da0: 72 65 61 6b 3b 0a 2b 09 09 7d 0a 2b 09 09 64 65 reak;.+..}.+..de
0db0: 66 61 75 6c 74 3a 20 7b 0a 2b 09 09 20 20 20 20 fault: {.+..
0dc0: 72 65 73 75 6c 74 20 3d 20 54 43 4c 5f 45 52 52 result = TCL_ERR
0dd0: 4f 52 3b 0a 2b 09 09 20 20 20 20 62 72 65 61 6b OR;.+.. break
0de0: 3b 0a 2b 09 09 7d 0a 2b 09 20 20 20 20 7d 0a 2b ;.+..}.+. }.+
0df0: 0a 2b 09 20 20 20 20 2f 2a 20 52 65 73 74 6f 72 .+. /* Restor
0e00: 65 20 74 68 65 20 6e 75 6d 65 72 69 63 20 76 61 e the numeric va
0e10: 72 73 20 2a 2f 0a 2b 09 20 20 20 20 66 6f 72 20 rs */.+. for
0e20: 28 69 64 78 20 3d 20 30 3b 20 69 64 78 20 3c 3d (idx = 0; idx <=
0e30: 20 69 6e 66 6f 2e 6e 73 75 62 73 3b 20 69 64 78 info.nsubs; idx
0e40: 2b 2b 29 20 7b 0a 2b 09 09 54 63 6c 5f 53 65 74 ++) {.+..Tcl_Set
0e50: 49 6e 74 4f 62 6a 28 76 61 72 6e 61 6d 65 2c 20 IntObj(varname,
0e60: 69 64 78 29 3b 0a 2b 09 09 69 66 20 28 70 72 65 idx);.+..if (pre
0e70: 73 65 72 76 65 64 5b 69 64 78 5d 29 20 7b 0a 2b served[idx]) {.+
0e80: 09 09 20 20 20 20 54 63 6c 5f 4f 62 6a 53 65 74 .. Tcl_ObjSet
0e90: 56 61 72 32 28 69 6e 74 65 72 70 2c 20 76 61 72 Var2(interp, var
0ea0: 6e 61 6d 65 2c 20 4e 55 4c 4c 2c 20 70 72 65 73 name, NULL, pres
0eb0: 65 72 76 65 64 5b 69 64 78 5d 2c 20 30 29 3b 0a erved[idx], 0);.
0ec0: 2b 09 09 20 20 20 20 54 63 6c 5f 44 65 63 72 52 +.. Tcl_DecrR
0ed0: 65 66 43 6f 75 6e 74 28 70 72 65 73 65 72 76 65 efCount(preserve
0ee0: 64 5b 69 64 78 5d 29 3b 0a 2b 09 09 7d 20 65 6c d[idx]);.+..} el
0ef0: 73 65 20 7b 0a 2b 09 09 20 20 20 20 54 63 6c 5f se {.+.. Tcl_
0f00: 55 6e 73 65 74 56 61 72 28 69 6e 74 65 72 70 2c UnsetVar(interp,
0f10: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 28 76 Tcl_GetString(v
0f20: 61 72 6e 61 6d 65 29 2c 20 30 29 3b 0a 2b 09 09 arname), 0);.+..
0f30: 7d 0a 2b 09 20 20 20 20 7d 0a 2b 09 20 20 20 20 }.+. }.+.
0f40: 63 6b 66 72 65 65 28 28 63 68 61 72 20 2a 29 70 ckfree((char *)p
0f50: 72 65 73 65 72 76 65 64 29 3b 0a 2b 0a 2b 09 20 reserved);.+.+.
0f60: 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66 43 6f Tcl_DecrRefCo
0f70: 75 6e 74 28 76 61 72 6e 61 6d 65 29 3b 0a 2b 0a unt(varname);.+.
0f80: 2b 09 20 20 20 20 69 66 20 28 72 65 73 75 6c 74 +. if (result
0f90: 20 3d 3d 20 54 43 4c 5f 45 52 52 4f 52 29 20 7b == TCL_ERROR) {
0fa0: 0a 2b 09 09 67 6f 74 6f 20 64 6f 6e 65 3b 0a 2b .+..goto done;.+
0fb0: 09 20 20 20 20 7d 0a 2b 09 7d 20 65 6c 73 65 20 . }.+.} else
0fc0: 7b 0a 2b 09 20 20 20 20 2f 2a 0a 2b 09 20 20 20 {.+. /*.+.
0fd0: 20 20 2a 20 41 70 70 65 6e 64 20 74 68 65 20 73 * Append the s
0fe0: 75 62 53 70 65 63 20 61 72 67 75 6d 65 6e 74 20 ubSpec argument
0ff0: 74 6f 20 74 68 65 20 76 61 72 69 61 62 6c 65 2c to the variable,
1000: 20 6d 61 6b 69 6e 67 20 61 70 70 72 6f 70 72 69 making appropri
1010: 61 74 65 0a 2b 09 20 20 20 20 20 2a 20 73 75 62 ate.+. * sub
1020: 73 74 69 74 75 74 69 6f 6e 73 2e 20 20 54 68 69 stitutions. Thi
1030: 73 20 63 6f 64 65 20 69 73 20 61 20 62 69 74 20 s code is a bit
1040: 68 61 69 72 79 20 62 65 63 61 75 73 65 20 6f 66 hairy because of
1050: 20 74 68 65 20 62 61 63 6b 73 6c 61 73 68 0a 2b the backslash.+
1060: 09 20 20 20 20 20 2a 20 63 6f 6e 76 65 6e 74 69 . * conventi
1070: 6f 6e 73 20 61 6e 64 20 62 65 63 61 75 73 65 20 ons and because
1080: 74 68 65 20 63 6f 64 65 20 73 61 76 65 73 20 75 the code saves u
1090: 70 20 72 61 6e 67 65 73 20 6f 66 20 63 68 61 72 p ranges of char
10a0: 61 63 74 65 72 73 20 69 6e 0a 2b 09 20 20 20 20 acters in.+.
10b0: 20 2a 20 73 75 62 53 70 65 63 20 74 6f 20 72 65 * subSpec to re
10c0: 64 75 63 65 20 74 68 65 20 6e 75 6d 62 65 72 20 duce the number
10d0: 6f 66 20 63 61 6c 6c 73 20 74 6f 20 54 63 6c 5f of calls to Tcl_
10e0: 53 65 74 56 61 72 2e 0a 2b 09 20 20 20 20 20 2a SetVar..+. *
10f0: 2f 0a 2b 0a 2b 09 20 20 20 20 77 73 72 63 20 3d /.+.+. wsrc =
1100: 20 77 66 69 72 73 74 43 68 61 72 20 3d 20 77 73 wfirstChar = ws
1110: 75 62 73 70 65 63 3b 0a 2b 09 20 20 20 20 77 65 ubspec;.+. we
1120: 6e 64 20 3d 20 77 73 75 62 73 70 65 63 20 2b 20 nd = wsubspec +
1130: 77 73 75 62 6c 65 6e 3b 0a 2b 09 20 20 20 20 66 wsublen;.+. f
1140: 6f 72 20 28 63 68 20 3d 20 2a 77 73 72 63 3b 20 or (ch = *wsrc;
1150: 77 73 72 63 20 21 3d 20 77 65 6e 64 3b 20 77 73 wsrc != wend; ws
1160: 72 63 2b 2b 2c 20 63 68 20 3d 20 2a 77 73 72 63 rc++, ch = *wsrc
1170: 29 20 7b 0a 2b 09 09 69 66 20 28 63 68 20 3d 3d ) {.+..if (ch ==
1180: 20 27 26 27 29 20 7b 0a 2b 09 09 20 20 20 20 69 '&') {.+.. i
1190: 64 78 20 3d 20 30 3b 0a 2b 09 09 7d 20 65 6c 73 dx = 0;.+..} els
11a0: 65 20 69 66 20 28 63 68 20 3d 3d 20 27 5c 5c 27 e if (ch == '\\'
11b0: 29 20 7b 0a 2b 09 09 20 20 20 20 63 68 20 3d 20 ) {.+.. ch =
11c0: 77 73 72 63 5b 31 5d 3b 0a 2b 09 09 20 20 20 20 wsrc[1];.+..
11d0: 69 66 20 28 28 63 68 20 3e 3d 20 27 30 27 29 20 if ((ch >= '0')
11e0: 26 26 20 28 63 68 20 3c 3d 20 27 39 27 29 29 20 && (ch <= '9'))
11f0: 7b 0a 2b 09 09 09 69 64 78 20 3d 20 63 68 20 2d {.+...idx = ch -
1200: 20 27 30 27 3b 0a 2b 09 09 20 20 20 20 7d 20 65 '0';.+.. } e
1210: 6c 73 65 20 69 66 20 28 28 63 68 20 3d 3d 20 27 lse if ((ch == '
1220: 5c 5c 27 29 20 7c 7c 20 28 63 68 20 3d 3d 20 27 \\') || (ch == '
1230: 26 27 29 29 20 7b 0a 2b 09 09 09 2a 77 73 72 63 &')) {.+...*wsrc
1240: 20 3d 20 63 68 3b 0a 2b 09 09 09 54 63 6c 5f 41 = ch;.+...Tcl_A
1250: 70 70 65 6e 64 55 6e 69 63 6f 64 65 54 6f 4f 62 ppendUnicodeToOb
1260: 6a 28 72 65 73 75 6c 74 50 74 72 2c 20 77 66 69 j(resultPtr, wfi
1270: 72 73 74 43 68 61 72 2c 0a 2b 09 09 09 09 77 73 rstChar,.+....ws
1280: 72 63 20 2d 20 77 66 69 72 73 74 43 68 61 72 20 rc - wfirstChar
1290: 2b 20 31 29 3b 0a 2b 09 09 09 2a 77 73 72 63 20 + 1);.+...*wsrc
12a0: 3d 20 27 5c 5c 27 3b 0a 2b 09 09 09 77 66 69 72 = '\\';.+...wfir
12b0: 73 74 43 68 61 72 20 3d 20 77 73 72 63 20 2b 20 stChar = wsrc +
12c0: 32 3b 0a 2b 09 09 09 77 73 72 63 2b 2b 3b 0a 2b 2;.+...wsrc++;.+
12d0: 09 09 09 63 6f 6e 74 69 6e 75 65 3b 0a 2b 09 09 ...continue;.+..
12e0: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 09 09 } else {.+..
12f0: 09 63 6f 6e 74 69 6e 75 65 3b 0a 2b 09 09 20 20 .continue;.+..
1300: 20 20 7d 0a 20 09 09 7d 20 65 6c 73 65 20 7b 0a }. ..} else {.
1310: 20 09 09 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b .. continue;
1320: 0a 20 09 09 7d 0a 2d 09 20 20 20 20 7d 20 65 6c . ..}.-. } el
1330: 73 65 20 7b 0a 2d 09 09 63 6f 6e 74 69 6e 75 65 se {.-..continue
1340: 3b 0a 2b 09 09 69 66 20 28 77 66 69 72 73 74 43 ;.+..if (wfirstC
1350: 68 61 72 20 21 3d 20 77 73 72 63 29 20 7b 0a 2b har != wsrc) {.+
1360: 09 09 20 20 20 20 54 63 6c 5f 41 70 70 65 6e 64 .. Tcl_Append
1370: 55 6e 69 63 6f 64 65 54 6f 4f 62 6a 28 72 65 73 UnicodeToObj(res
1380: 75 6c 74 50 74 72 2c 20 77 66 69 72 73 74 43 68 ultPtr, wfirstCh
1390: 61 72 2c 0a 2b 09 09 09 20 20 20 20 77 73 72 63 ar,.+... wsrc
13a0: 20 2d 20 77 66 69 72 73 74 43 68 61 72 29 3b 0a - wfirstChar);.
13b0: 2b 09 09 7d 0a 2b 09 09 69 66 20 28 69 64 78 20 +..}.+..if (idx
13c0: 3c 3d 20 69 6e 66 6f 2e 6e 73 75 62 73 29 20 7b <= info.nsubs) {
13d0: 0a 2b 09 09 20 20 20 20 73 75 62 53 74 61 72 74 .+.. subStart
13e0: 20 3d 20 69 6e 66 6f 2e 6d 61 74 63 68 65 73 5b = info.matches[
13f0: 69 64 78 5d 2e 73 74 61 72 74 3b 0a 2b 09 09 20 idx].start;.+..
1400: 20 20 20 73 75 62 45 6e 64 20 3d 20 69 6e 66 6f subEnd = info
1410: 2e 6d 61 74 63 68 65 73 5b 69 64 78 5d 2e 65 6e .matches[idx].en
1420: 64 3b 0a 2b 09 09 20 20 20 20 69 66 20 28 28 73 d;.+.. if ((s
1430: 75 62 53 74 61 72 74 20 3e 3d 20 30 29 20 26 26 ubStart >= 0) &&
1440: 20 28 73 75 62 45 6e 64 20 3e 3d 20 30 29 29 20 (subEnd >= 0))
1450: 7b 0a 2b 09 09 09 54 63 6c 5f 41 70 70 65 6e 64 {.+...Tcl_Append
1460: 55 6e 69 63 6f 64 65 54 6f 4f 62 6a 28 72 65 73 UnicodeToObj(res
1470: 75 6c 74 50 74 72 2c 0a 2b 09 09 09 09 77 73 74 ultPtr,.+....wst
1480: 72 69 6e 67 20 2b 20 6f 66 66 73 65 74 20 2b 20 ring + offset +
1490: 73 75 62 53 74 61 72 74 2c 20 73 75 62 45 6e 64 subStart, subEnd
14a0: 20 2d 20 73 75 62 53 74 61 72 74 29 3b 0a 2b 09 - subStart);.+.
14b0: 09 20 20 20 20 7d 0a 2b 09 09 7d 0a 2b 09 09 69 . }.+..}.+..i
14c0: 66 20 28 2a 77 73 72 63 20 3d 3d 20 27 5c 5c 27 f (*wsrc == '\\'
14d0: 29 20 7b 0a 2b 09 09 20 20 20 20 77 73 72 63 2b ) {.+.. wsrc+
14e0: 2b 3b 0a 2b 09 09 7d 0a 2b 09 09 77 66 69 72 73 +;.+..}.+..wfirs
14f0: 74 43 68 61 72 20 3d 20 77 73 72 63 20 2b 20 31 tChar = wsrc + 1
1500: 3b 0a 20 09 20 20 20 20 7d 0a 20 09 20 20 20 20 ;. . }. .
1510: 69 66 20 28 77 66 69 72 73 74 43 68 61 72 20 21 if (wfirstChar !
1520: 3d 20 77 73 72 63 29 20 7b 0a 20 09 09 54 63 6c = wsrc) {. ..Tcl
1530: 5f 41 70 70 65 6e 64 55 6e 69 63 6f 64 65 54 6f _AppendUnicodeTo
1540: 4f 62 6a 28 72 65 73 75 6c 74 50 74 72 2c 20 77 Obj(resultPtr, w
1550: 66 69 72 73 74 43 68 61 72 2c 0a 20 09 09 09 77 firstChar,. ...w
1560: 73 72 63 20 2d 20 77 66 69 72 73 74 43 68 61 72 src - wfirstChar
1570: 29 3b 0a 20 09 20 20 20 20 7d 0a 2d 09 20 20 20 );. . }.-.
1580: 20 69 66 20 28 69 64 78 20 3c 3d 20 69 6e 66 6f if (idx <= info
1590: 2e 6e 73 75 62 73 29 20 7b 0a 2d 09 09 73 75 62 .nsubs) {.-..sub
15a0: 53 74 61 72 74 20 3d 20 69 6e 66 6f 2e 6d 61 74 Start = info.mat
15b0: 63 68 65 73 5b 69 64 78 5d 2e 73 74 61 72 74 3b ches[idx].start;
15c0: 0a 2d 09 09 73 75 62 45 6e 64 20 3d 20 69 6e 66 .-..subEnd = inf
15d0: 6f 2e 6d 61 74 63 68 65 73 5b 69 64 78 5d 2e 65 o.matches[idx].e
15e0: 6e 64 3b 0a 2d 09 09 69 66 20 28 28 73 75 62 53 nd;.-..if ((subS
15f0: 74 61 72 74 20 3e 3d 20 30 29 20 26 26 20 28 73 tart >= 0) && (s
1600: 75 62 45 6e 64 20 3e 3d 20 30 29 29 20 7b 0a 2d ubEnd >= 0)) {.-
1610: 09 09 20 20 20 20 54 63 6c 5f 41 70 70 65 6e 64 .. Tcl_Append
1620: 55 6e 69 63 6f 64 65 54 6f 4f 62 6a 28 72 65 73 UnicodeToObj(res
1630: 75 6c 74 50 74 72 2c 0a 2d 09 09 09 20 20 20 20 ultPtr,.-...
1640: 77 73 74 72 69 6e 67 20 2b 20 6f 66 66 73 65 74 wstring + offset
1650: 20 2b 20 73 75 62 53 74 61 72 74 2c 20 73 75 62 + subStart, sub
1660: 45 6e 64 20 2d 20 73 75 62 53 74 61 72 74 29 3b End - subStart);
1670: 0a 2d 09 09 7d 0a 2d 09 20 20 20 20 7d 0a 2d 09 .-..}.-. }.-.
1680: 20 20 20 20 69 66 20 28 2a 77 73 72 63 20 3d 3d if (*wsrc ==
1690: 20 27 5c 5c 27 29 20 7b 0a 2d 09 09 77 73 72 63 '\\') {.-..wsrc
16a0: 2b 2b 3b 0a 2d 09 20 20 20 20 7d 0a 2d 09 20 20 ++;.-. }.-.
16b0: 20 20 77 66 69 72 73 74 43 68 61 72 20 3d 20 77 wfirstChar = w
16c0: 73 72 63 20 2b 20 31 3b 0a 2d 09 7d 0a 2d 09 69 src + 1;.-.}.-.i
16d0: 66 20 28 77 66 69 72 73 74 43 68 61 72 20 21 3d f (wfirstChar !=
16e0: 20 77 73 72 63 29 20 7b 0a 2d 09 20 20 20 20 54 wsrc) {.-. T
16f0: 63 6c 5f 41 70 70 65 6e 64 55 6e 69 63 6f 64 65 cl_AppendUnicode
1700: 54 6f 4f 62 6a 28 72 65 73 75 6c 74 50 74 72 2c ToObj(resultPtr,
1710: 20 77 66 69 72 73 74 43 68 61 72 2c 20 77 73 72 wfirstChar, wsr
1720: 63 20 2d 20 77 66 69 72 73 74 43 68 61 72 29 3b c - wfirstChar);
1730: 0a 20 09 7d 0a 20 09 69 66 20 28 65 6e 64 20 3d . .}. .if (end =
1740: 3d 20 30 29 20 7b 0a 20 09 20 20 20 20 2f 2a 0a = 0) {. . /*.
1750: 40 40 20 2d 38 35 30 2c 37 20 2b 39 32 39 2c 37 @@ -850,7 +929,7
1760: 20 40 40 0a 20 09 20 20 20 20 20 2a 20 68 6f 6c @@. . * hol
1770: 64 69 6e 67 20 74 68 65 20 6e 75 6d 62 65 72 20 ding the number
1780: 6f 66 20 6d 61 74 63 68 65 73 2e 20 0a 20 09 20 of matches. . .
1790: 20 20 20 20 2a 2f 0a 20 0a 2d 09 20 20 20 20 54 */. .-. T
17a0: 63 6c 5f 53 65 74 49 6e 74 4f 62 6a 28 54 63 6c cl_SetIntObj(Tcl
17b0: 5f 47 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e _GetObjResult(in
17c0: 74 65 72 70 29 2c 20 6e 75 6d 4d 61 74 63 68 65 terp), numMatche
17d0: 73 29 3b 0a 2b 09 20 20 20 20 54 63 6c 5f 53 65 s);.+. Tcl_Se
17e0: 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 tObjResult(inter
17f0: 70 2c 20 54 63 6c 5f 4e 65 77 49 6e 74 4f 62 6a p, Tcl_NewIntObj
1800: 28 6e 75 6d 4d 61 74 63 68 65 73 29 29 3b 0a 20 (numMatches));.
1810: 09 7d 0a 20 20 20 20 20 7d 20 65 6c 73 65 20 7b .}. } else {
1820: 0a 20 09 2f 2a 0a . ./*.