Tcl Source Code

Check-in [23b23af342]
Login

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

Overview
Comment:
Merged String and Unicode object types. Added new functions to the puplic API: Tcl_NewUnicodeObj, Tcl_SetUnicodeObj, Tcl_GetUnicode, Tcl_GetUniChar, Tcl_GetCharLength, Tcl_GetRange, Tcl_AppendUnicodeToObj.

Note: some stringObj tests are still failing--the teststringobj command still needs to be updated.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 23b23af342a570dab211294eff79a331869224c5
User & Date: hershey 1999-06-15 01:16:21
Context
1999-06-15
03:14
Improved the appendObj functions (uncomented the optimized code that was present in the Unicode obj)... check-in: 6a28946962 user: hershey tags: trunk
01:16
Merged String and Unicode object types. Added new functions to the puplic API: Tcl_NewUnicodeObj...
check-in: 23b23af342 user: hershey tags: trunk
1999-06-11
02:06
Continued work on configure and make scripts check-in: 35a6cd6205 user: surles tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.














1
2
3
4
5
6
7













1999-06-09    <[email protected]>

	* generic/tclUnicodeObj.c: Lots of cleanup and simplification.
	Fixed several memory bugs.  Added TclAppendUnicodeToObj.  

	* generic/tclInt.h: Added declarations for various Unicode string
	functions.  
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1999-06-14  Melissa Hirschl  <[email protected]>

	* doc/StringObj.3
	* test/stringObj.test
	* unix/Makefile.in
	* win/Makefile.in
	* win/makefile.vc
	* generic/tclStringObj.c:
	Merged String and Unicode object types.  Added new functions to
	the puplic API:  Tcl_NewUnicodeObj, Tcl_SetUnicodeObj,
	Tcl_GetUnicode, Tcl_GetUniChar, Tcl_GetCharLength, Tcl_GetRange,
	Tcl_AppendUnicodeToObj.

1999-06-09    <[email protected]>

	* generic/tclUnicodeObj.c: Lots of cleanup and simplification.
	Fixed several memory bugs.  Added TclAppendUnicodeToObj.  

	* generic/tclInt.h: Added declarations for various Unicode string
	functions.  

Changes to doc/StringObj.3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20





21





22
23
24
25
26
27

28














29
30
31

32
33
34




35
36

37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53



















54
55
56
57
58
59
60
61
62
63
64
65
66
'\"
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" 
'\" RCS: @(#) $Id: StringObj.3,v 1.4 1999/04/16 00:46:33 stanton Exp $
'\" 
.so man.macros
.TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_NewStringObj, Tcl_SetStringObj, Tcl_GetStringFromObj, Tcl_GetString, Tcl_AppendToObj, Tcl_AppendStringsToObj, Tcl_AppendStringsToObjVA, Tcl_AppendObjToObj, Tcl_SetObjLength, Tcl_ConcatObj \- manipulate Tcl objects as strings
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
.sp
Tcl_Obj *
\fBTcl_NewStringObj\fR(\fIbytes, length\fR)

.sp





\fBTcl_SetStringObj\fR(\fIobjPtr, bytes, length\fR)





.sp
char *
\fBTcl_GetStringFromObj\fR(\fIobjPtr, lengthPtr\fR)
.sp
char *
\fBTcl_GetString\fR(\fIobjPtr\fR)

.sp














\fBTcl_AppendToObj\fR(\fIobjPtr, bytes, length\fR)
.VS
.sp

\fBTcl_AppendObjToObj\fR(\fIobjPtr, appendObjPtr\fR)
.VE
.sp




\fBTcl_AppendStringsToObj\fR(\fIobjPtr, string, string, ... \fB(char *) NULL\fR)
.sp

\fBTcl_AppendStringsToObjVA\fR(\fIobjPtr, argList\fR)
.sp

\fBTcl_SetObjLength\fR(\fIobjPtr, newLength\fR)
.sp
Tcl_Obj *
\fBTcl_ConcatObj\fR(\fIobjc, objv\fR)
.SH ARGUMENTS
.AS Tcl_Interp *appendObjPtr in/out
.AP char *bytes in
Points to the first byte of an array of bytes
used to set or append to a string object.
This byte array may contain embedded null bytes
unless \fIlength\fR is negative.
.AP int length in
The number of bytes to copy from \fIbytes\fR when
initializing, setting, or appending to a string object.
If negative, all bytes up to the first null are used.



















.AP Tcl_Obj *objPtr in/out
Points to an object to manipulate.
.VS
.AP Tcl_Obj *appendObjPtr in
The object to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR.
.VE
.AP int *lengthPtr out
If non-NULL, the location where \fBTcl_GetStringFromObj\fR will store
the the length of an object's string representation.
.AP char *string in
Null-terminated string value to append to \fIobjPtr\fR.
.AP va_list argList in
An argument list which must have been initialised using






|





|






>

>
>
>
>
>

>
>
>
>
>






>

>
>
>
>
>
>
>
>
>
>
>
>
>
>

|

>
|


>
>
>
>


>


>















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<


<







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109

110
111
112
113
114
115
116
'\"
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" 
'\" RCS: @(#) $Id: StringObj.3,v 1.5 1999/06/15 01:16:21 hershey Exp $
'\" 
.so man.macros
.TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_NewStringObj, Tcl_NewUnicodeObj, Tcl_SetStringObj, Tcl_SetUnicodeObj, Tcl_GetStringFromObj, Tcl_GetString, Tcl_GetUnicode, Tcl_GetUniChar, Tcl_GetCharLength, Tcl_GetRange, Tcl_AppendToObj, Tcl_AppendUnicodeToObj, Tcl_AppendStringsToObj, Tcl_AppendStringsToObjVA, Tcl_AppendObjToObj, Tcl_SetObjLength, Tcl_ConcatObj \- manipulate Tcl objects as strings
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
.sp
Tcl_Obj *
\fBTcl_NewStringObj\fR(\fIbytes, length\fR)
.VS 8.1.2
.sp
Tcl_Obj *
\fBTcl_NewUnicodeObj\fR(\fIunicode, numChars\fR)
.VE
.sp
void
\fBTcl_SetStringObj\fR(\fIobjPtr, bytes, length\fR)
.VS 8.1.2
.sp
void
\fBTcl_SetUnicodeObj\fR(\fIobjPtr, unicode, numChars\fR)
.VE
.sp
char *
\fBTcl_GetStringFromObj\fR(\fIobjPtr, lengthPtr\fR)
.sp
char *
\fBTcl_GetString\fR(\fIobjPtr\fR)
.VS 8.1.2
.sp
Tcl_UniChar *
\fBTcl_GetUnicode\fR(\fIobjPtr\fR)
.sp
Tcl_UniChar
\fBTcl_GetUniChar\fR(\fIobjPtr, index\fR)
.sp
int
\fBTcl_GetCharLength\fR(\fIobjPtr\fR)
.sp
Tcl_Obj *
\fBTcl_GetRange\fR(\fIobjPtr, first, last\fR)
.VE
.sp
void
\fBTcl_AppendToObj\fR(\fIobjPtr, bytes, length\fR)
.VS 8.1.2
.sp
void
\fBTcl_AppendUnicodeToObj\fR(\fIobjPtr, unicode, numChars\fR)
.VE
.sp
void
\fBTcl_AppendObjToObj\fR(\fIobjPtr, appendObjPtr\fR)
.sp
void
\fBTcl_AppendStringsToObj\fR(\fIobjPtr, string, string, ... \fB(char *) NULL\fR)
.sp
void
\fBTcl_AppendStringsToObjVA\fR(\fIobjPtr, argList\fR)
.sp
void
\fBTcl_SetObjLength\fR(\fIobjPtr, newLength\fR)
.sp
Tcl_Obj *
\fBTcl_ConcatObj\fR(\fIobjc, objv\fR)
.SH ARGUMENTS
.AS Tcl_Interp *appendObjPtr in/out
.AP char *bytes in
Points to the first byte of an array of bytes
used to set or append to a string object.
This byte array may contain embedded null bytes
unless \fIlength\fR is negative.
.AP int length in
The number of bytes to copy from \fIbytes\fR when
initializing, setting, or appending to a string object.
If negative, all bytes up to the first null are used.
.AP Tcl_UniChar *unicode in
Points to the first byte of an array of Unicode characters
used to set or append to a string object.
This byte array may contain embedded null characters
unless \fInumChars\fR is negative.
.VS 8.1.2
.AP int numChars in
The number of Unicode characters to copy from \fIunicode\fR when
initializing, setting, or appending to a string object.
If negative, all characters up to the first null character are used.
.AP int index in
The index of the Unicode character to return.
.AP int first in
The index of the first Unicode character in the Unicode range to be
returned as a new object.
.AP int last in
The index of the last Unicode character in the Unicode range to be
returned as a new object.
.VE
.AP Tcl_Obj *objPtr in/out
Points to an object to manipulate.

.AP Tcl_Obj *appendObjPtr in
The object to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR.

.AP int *lengthPtr out
If non-NULL, the location where \fBTcl_GetStringFromObj\fR will store
the the length of an object's string representation.
.AP char *string in
Null-terminated string value to append to \fIobjPtr\fR.
.AP va_list argList in
An argument list which must have been initialised using
78
79
80
81
82
83
84




85

86
87
88


89
90
91
92
93


94
95
96
97
98
99
100
101
102
103
104
105
106
107















108
109










110



111
112
113
114
115
116


117
118
119
120
121
122
123
124
.PP
The procedures described in this manual entry allow Tcl objects to
be manipulated as string values.  They use the internal representation
of the object to store additional information to make the string
manipulations more efficient.  In particular, they make a series of
append operations efficient by allocating extra storage space for the
string so that it doesn't have to be copied for each append.




.PP

\fBTcl_NewStringObj\fR and \fBTcl_SetStringObj\fR create a new object
or modify an existing object to hold a copy of
the string given by \fIbytes\fR and \fIlength\fR.


\fBTcl_NewStringObj\fR returns a pointer to a newly created object
with reference count zero.
Both procedures set the object to hold a copy of the specified string.
\fBTcl_SetStringObj\fR frees any old string representation
as well as any old internal representation of the object.


.PP
\fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR
return an object's string representation.
This is given by the returned byte pointer
and (for \fBTcl_GetStringFromObj\fR) length,
which is stored in \fIlengthPtr\fR if it is non-NULL.
If the object's string representation is invalid
(its byte pointer is NULL),
the string representation is regenerated from the
object's internal representation.
The storage referenced by the returned byte pointer
is owned by the object manager and should not be modified by the caller.
The procedure \fBTcl_GetString\fR is used in the common case
where the caller does not need the length of the string representation.















.PP
\fBTcl_AppendToObj\fR appends the data given by \fIbytes\fR and










\fIlength\fR to the object specified by \fIobjPtr\fR.  It does this



in a way that handles repeated calls relatively efficiently (it
overallocates the string space to avoid repeated reallocations
and copies of object's string value).
.VS
.PP
\fBTcl_AppendObjToObj\fR is similar to \fBTcl_AppendToObj\fR, but it


appends the string value of \fIappendObjPtr\fR to \fIobjPtr\fR.
.VE
.PP
\fBTcl_AppendStringsToObj\fR is similar to \fBTcl_AppendToObj\fR
except that it can be passed more than one value to append and
each value must be a null-terminated string (i.e. none of the
values may contain internal null characters).  Any number of
\fIstring\fR arguments may be provided, but the last argument







>
>
>
>

>

|
|
>
>
|
|
|
|
|
>
>

|
<
|
|
|
<
|
|
<
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
|
|
<


>
>
|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157

158
159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
.PP
The procedures described in this manual entry allow Tcl objects to
be manipulated as string values.  They use the internal representation
of the object to store additional information to make the string
manipulations more efficient.  In particular, they make a series of
append operations efficient by allocating extra storage space for the
string so that it doesn't have to be copied for each append.
.VS 8.1.2
Also, indexing and length computations are optimized because the
Unicode string representation is calculated and cached as needed.
.VE
.PP
.VS 8.1.2
\fBTcl_NewStringObj\fR and \fBTcl_SetStringObj\fR create a new object
or modify an existing object to hold a copy of the string given by
\fIbytes\fR and \fIlength\fR.  \fBTcl_NewUnicodeObj\fR and
\fBTcl_SetUnicodeObj\fR create a new object or modify an existing
object to hold a copy of the Unicode string given by \fIunicode\fR and
\fInumChars\fR.  \fBTcl_NewStringObj\fR and \fBTcl_NewUnicodeObj\fR
return a pointer to a newly created object with reference count zero.
All four procedures set the object to hold a copy of the specified
string.  \fBTcl_SetStringObj\fR and \fBTcl_SetUnicodeObj\fR free any
old string representation as well as any old internal representation
of the object.
.VE
.PP
\fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR return an object's

string representation.  This is given by the returned byte pointer and
(for \fBTcl_GetStringFromObj\fR) length, which is stored in
\fIlengthPtr\fR if it is non-NULL.  If the object's UTF string

representation is invalid (its byte pointer is NULL), the string
representation is regenerated from the object's internal

representation.  The storage referenced by the returned byte pointer
is owned by the object manager and should not be modified by the
caller.  The procedure \fBTcl_GetString\fR is used in the common case
where the caller does not need the length of the string
representation.
.PP
.VS 8.1.2
\fBTcl_GetUnicode\fR returns an object's value as a Unicode string.
\fBTcl_GetUniChar\fR returns the \fIindex\fR'th character in the
object's Unicode representation.
.PP
\fBTcl_GetRange\fR returns a newly created object comprised of the
characters between \fIfirst\fR and \fIlast\fR (inclusive) in the
object's Unicode representation.  If the object's Unicode
representation is invalid, the Unicode representation is regenerated
from the object's string representation.
.PP
\fBTcl_GetCharLength\fR returns the number of characters (as opposed
to bytes) in the string object.
.PP
\fBTcl_AppendToObj\fR appends the data given by \fIbytes\fR and
\fIlength\fR to the string representation of the object specified by
\fIobjPtr\fR.  If the object has an invalid string representation,
then an attempt is made to convert \fIbytes\fR is to the Unicode
format.  If the conversion is successful, then the converted form of
\fIbytes\fR is appended to the object's Unicode representation.
Otherwise, the object's Unicode representation is invalidated and
converted to the UTF format, and \fIbytes\fR is appended to the
object's new string representation.
.PP
\fBTcl_AppendUnicodeToObj\fR appends the Unicode string given by
\fIunicode\fR and \fInumChars\fR to the object specified by
\fIobjPtr\fR.  If the object has an invalid Unicode representation,
then \fIunicode\fR is converted to the UTF format and appended to the
object's string representation.  Appends are optimized to handle
repeated appends relatively efficiently (it overallocates the string
or Unicode space to avoid repeated reallocations and copies of
object's string value).

.PP
\fBTcl_AppendObjToObj\fR is similar to \fBTcl_AppendToObj\fR, but it
appends the string or Unicode value (whichever exists and is best
suited to be appended to \fIobjPtr\fR) of \fIappendObjPtr\fR to
\fIobjPtr\fR.
.VE
.PP
\fBTcl_AppendStringsToObj\fR is similar to \fBTcl_AppendToObj\fR
except that it can be passed more than one value to append and
each value must be a null-terminated string (i.e. none of the
values may contain internal null characters).  Any number of
\fIstring\fR arguments may be provided, but the last argument
154
155
156
157
158
159
160
161
newly-created object whose ref count is zero.

.SH "SEE ALSO"
Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount

.SH KEYWORDS
append, internal representation, object, object type, string object,
string type, string representation, concat, concatenate







|
239
240
241
242
243
244
245
246
newly-created object whose ref count is zero.

.SH "SEE ALSO"
Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount

.SH KEYWORDS
append, internal representation, object, object type, string object,
string type, string representation, concat, concatenate, unicode

Changes to generic/tcl.decls.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# tcl.decls --
#
#	This file contains the declarations for all supported public
#	functions that are exported by the Tcl library via the stubs table.
#	This file is used to generate the tclDecls.h, tclPlatDecls.h,
#	tclStub.c, and tclPlatStub.c files.
#	
#
# Copyright (c) 1998-1999 by Scriptics Corporation.
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# RCS: @(#) $Id: tcl.decls,v 1.15 1999/06/10 04:28:49 stanton Exp $

library tcl

# Define the tcl interface with several sub interfaces:
#     tclPlat	 - platform specific public
#     tclInt	 - generic private
#     tclPlatInt - platform specific private












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# tcl.decls --
#
#	This file contains the declarations for all supported public
#	functions that are exported by the Tcl library via the stubs table.
#	This file is used to generate the tclDecls.h, tclPlatDecls.h,
#	tclStub.c, and tclPlatStub.c files.
#	
#
# Copyright (c) 1998-1999 by Scriptics Corporation.
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# RCS: @(#) $Id: tcl.decls,v 1.16 1999/06/15 01:16:21 hershey Exp $

library tcl

# Define the tcl interface with several sub interfaces:
#     tclPlat	 - platform specific public
#     tclInt	 - generic private
#     tclPlatInt - platform specific private
1280
1281
1282
1283
1284
1285
1286


1287




















1288
1289
1290
1291
1292
1293
1294
declare 376 generic {
    int Tcl_RegExpMatchObj(Tcl_Interp *interp, Tcl_RegExp regexp, \
	    Tcl_Obj *objPtr, int offset, int nmatches, int flags)
}
declare 377 generic {
    void Tcl_RegExpGetInfo(Tcl_RegExp regexp, Tcl_RegExpInfo *infoPtr)
}
























##############################################################################

# Define the platform specific public Tcl interface.  These functions are
# only available on the designated platform.

interface tclPlat







>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
declare 376 generic {
    int Tcl_RegExpMatchObj(Tcl_Interp *interp, Tcl_RegExp regexp, \
	    Tcl_Obj *objPtr, int offset, int nmatches, int flags)
}
declare 377 generic {
    void Tcl_RegExpGetInfo(Tcl_RegExp regexp, Tcl_RegExpInfo *infoPtr)
}
declare 378 generic {
    Tcl_Obj * Tcl_NewUnicodeObj(Tcl_UniChar *unicode, int numChars)
}
declare 379 generic {
    void Tcl_SetUnicodeObj(Tcl_Obj *objPtr, Tcl_UniChar *unicode, \
	    int numChars)
}
declare 380 generic {
    int Tcl_GetCharLength (Tcl_Obj *objPtr)
}
declare 381 generic {
    Tcl_UniChar Tcl_GetUniChar (Tcl_Obj *objPtr, int index)
}
declare 382 generic {
    Tcl_UniChar * Tcl_GetUnicode (Tcl_Obj *objPtr)
}
declare 383 generic {
    Tcl_Obj * Tcl_GetRange (Tcl_Obj *objPtr, int first, int last)
}
declare 384 generic {
    void Tcl_AppendUnicodeToObj (register Tcl_Obj *objPtr, \
	    Tcl_UniChar *unicode, int length)
}

##############################################################################

# Define the platform specific public Tcl interface.  These functions are
# only available on the designated platform.

interface tclPlat

Changes to generic/tclCmdMZ.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclCmdMZ.c,v 1.14 1999/06/10 04:28:50 stanton Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include "tclCompile.h"
#include "tclRegexp.h"








|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclCmdMZ.c,v 1.15 1999/06/15 01:16:22 hershey Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include "tclCompile.h"
#include "tclRegexp.h"

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

	    objs[0] = Tcl_NewLongObj(start);
	    objs[1] = Tcl_NewLongObj(end);

	    newPtr = Tcl_NewListObj(2, objs);
	} else {
	    if (i <= info.nsubs) {
		newPtr = TclGetRangeFromObj(objPtr, info.matches[i].start,
			info.matches[i].end - 1);
	    } else {
		newPtr = Tcl_NewObj();
		
	    }
	}
	valuePtr = Tcl_ObjSetVar2(interp, varPtr, NULL, newPtr, 0);







|







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

	    objs[0] = Tcl_NewLongObj(start);
	    objs[1] = Tcl_NewLongObj(end);

	    newPtr = Tcl_NewListObj(2, objs);
	} else {
	    if (i <= info.nsubs) {
		newPtr = Tcl_GetRange(objPtr, info.matches[i].start,
			info.matches[i].end - 1);
	    } else {
		newPtr = Tcl_NewObj();
		
	    }
	}
	valuePtr = Tcl_ObjSetVar2(interp, varPtr, NULL, newPtr, 0);
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    }

    result = TCL_OK;
    resultPtr = Tcl_NewObj();
    Tcl_IncrRefCount(resultPtr);

    objPtr = objv[1];
    wlen = TclGetUnicodeLengthFromObj(objPtr);
    wstring = TclGetUnicodeFromObj(objPtr);
    subspec = Tcl_GetString(objv[2]);
    varPtr = objv[3];

    /*
     * The following loop is to handle multiple matches within the
     * same source string;  each iteration handles one match and its
     * corresponding substitution.  If "-all" hasn't been specified







|
|







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    }

    result = TCL_OK;
    resultPtr = Tcl_NewObj();
    Tcl_IncrRefCount(resultPtr);

    objPtr = objv[1];
    wlen = Tcl_GetCharLength(objPtr);
    wstring = Tcl_GetUnicode(objPtr);
    subspec = Tcl_GetString(objv[2]);
    varPtr = objv[3];

    /*
     * The following loop is to handle multiple matches within the
     * same source string;  each iteration handles one match and its
     * corresponding substitution.  If "-all" hasn't been specified
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	 * Copy the portion of the source string before the match to the
	 * result variable.
	 */

	Tcl_RegExpGetInfo(regExpr, &info);
	start = info.matches[0].start;
	end = info.matches[0].end;
	TclAppendUnicodeToObj(resultPtr, wstring + offset, start);

	/*
	 * Append the subSpec argument to the variable, making appropriate
	 * substitutions.  This code is a bit hairy because of the backslash
	 * conventions and because the code saves up ranges of characters in
	 * subSpec to reduce the number of calls to Tcl_SetVar.
	 */







|







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	 * Copy the portion of the source string before the match to the
	 * result variable.
	 */

	Tcl_RegExpGetInfo(regExpr, &info);
	start = info.matches[0].start;
	end = info.matches[0].end;
	Tcl_AppendUnicodeToObj(resultPtr, wstring + offset, start);

	/*
	 * Append the subSpec argument to the variable, making appropriate
	 * substitutions.  This code is a bit hairy because of the backslash
	 * conventions and because the code saves up ranges of characters in
	 * subSpec to reduce the number of calls to Tcl_SetVar.
	 */
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
	    }
	    if (firstChar != src) {
		Tcl_AppendToObj(resultPtr, firstChar, src - firstChar);
	    }
	    subStart = info.matches[index].start;
	    subEnd = info.matches[index].end;
	    if ((subStart >= 0) && (subEnd >= 0)) {
		TclAppendUnicodeToObj(resultPtr, wstring + offset + subStart,
			subEnd - subStart);
	    }
	    if (*src == '\\') {
		src++;
	    }
	    firstChar = src + 1;
	}
	if (firstChar != src) {
	    Tcl_AppendToObj(resultPtr, firstChar, src - firstChar);
	}
	if (end == 0) {
	    /*
	     * Always consume at least one character of the input string
	     * in order to prevent infinite loops.
	     */

	    TclAppendUnicodeToObj(resultPtr, wstring + offset, 1);
	    offset++;
	}
	offset += end;
	if (!all) {
	    break;
	}
    }

    /*
     * Copy the portion of the source string after the last match to the
     * result variable.
     */

    if ((offset < wlen) || (numMatches == 0)) {
	TclAppendUnicodeToObj(resultPtr, wstring + offset, wlen - offset);
    }
    if (Tcl_ObjSetVar2(interp, varPtr, NULL, resultPtr, 0) == NULL) {
	Tcl_AppendResult(interp, "couldn't set variable \"",
		Tcl_GetString(varPtr), "\"", (char *) NULL);
	result = TCL_ERROR;
    } else {
	/*







|
















|














|







464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
	    }
	    if (firstChar != src) {
		Tcl_AppendToObj(resultPtr, firstChar, src - firstChar);
	    }
	    subStart = info.matches[index].start;
	    subEnd = info.matches[index].end;
	    if ((subStart >= 0) && (subEnd >= 0)) {
		Tcl_AppendUnicodeToObj(resultPtr, wstring + offset + subStart,
			subEnd - subStart);
	    }
	    if (*src == '\\') {
		src++;
	    }
	    firstChar = src + 1;
	}
	if (firstChar != src) {
	    Tcl_AppendToObj(resultPtr, firstChar, src - firstChar);
	}
	if (end == 0) {
	    /*
	     * Always consume at least one character of the input string
	     * in order to prevent infinite loops.
	     */

	    Tcl_AppendUnicodeToObj(resultPtr, wstring + offset, 1);
	    offset++;
	}
	offset += end;
	if (!all) {
	    break;
	}
    }

    /*
     * Copy the portion of the source string after the last match to the
     * result variable.
     */

    if ((offset < wlen) || (numMatches == 0)) {
	Tcl_AppendUnicodeToObj(resultPtr, wstring + offset, wlen - offset);
    }
    if (Tcl_ObjSetVar2(interp, varPtr, NULL, resultPtr, 0) == NULL) {
	Tcl_AppendResult(interp, "couldn't set variable \"",
		Tcl_GetString(varPtr), "\"", (char *) NULL);
	result = TCL_ERROR;
    } else {
	/*
969
970
971
972
973
974
975

976
977


978
979
980
981
982
983
984
		}
		if (start >= utflen) {
		    goto str_first_done;
		} else if (start > 0) {
		    if (length2 == utflen) {
			/* no unicode chars */
			string2 += start;

		    } else {
			string2 = Tcl_UtfAtIndex(string2, start);


		    }
		}
	    }

	    if (length1 > 0) {
		end = string2 + length2 - length1 + 1;
		for (p = string2;  p < end;  p++) {







>

|
>
>







969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
		}
		if (start >= utflen) {
		    goto str_first_done;
		} else if (start > 0) {
		    if (length2 == utflen) {
			/* no unicode chars */
			string2 += start;
			length2 -= start;
		    } else {
			char *s = Tcl_UtfAtIndex(string2, start);
			length2 -= s - string2;
			string2 = s;
		    }
		}
	    }

	    if (length1 > 0) {
		end = string2 + length2 - length1 + 1;
		for (p = string2;  p < end;  p++) {
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
		string1 = Tcl_GetStringFromObj(objv[2], &length1);
		
		/*
		 * convert to Unicode internal rep to calulate what
		 * 'end' really means.
		 */

		length2 = TclGetUnicodeLengthFromObj(objv[2]);
    
		if (TclGetIntForIndex(interp, objv[3], length2 - 1,
			&index) != TCL_OK) {
		    return TCL_ERROR;
		}
		if ((index >= 0) && (index < length2)) {
		    unichar = TclGetUniCharFromObj(objv[2], index);
		    length2 = Tcl_UniCharToUtf((int)unichar, buf);
		    Tcl_SetStringObj(resultPtr, buf, length2);
		}
	    }
	    break;
	}
	case STR_IS: {







|






|







1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
		string1 = Tcl_GetStringFromObj(objv[2], &length1);
		
		/*
		 * convert to Unicode internal rep to calulate what
		 * 'end' really means.
		 */

		length2 = Tcl_GetCharLength(objv[2]);
    
		if (TclGetIntForIndex(interp, objv[3], length2 - 1,
			&index) != TCL_OK) {
		    return TCL_ERROR;
		}
		if ((index >= 0) && (index < length2)) {
		    unichar = Tcl_GetUniChar(objv[2], index);
		    length2 = Tcl_UniCharToUtf((int)unichar, buf);
		    Tcl_SetStringObj(resultPtr, buf, length2);
		}
	    }
	    break;
	}
	case STR_IS: {
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
		 */

		if (objv[2]->typePtr == &tclByteArrayType) {
		    (void) Tcl_GetByteArrayFromObj(objv[2], &length1);
		    Tcl_SetIntObj(resultPtr, length1);
		} else {
		    Tcl_SetIntObj(resultPtr,
			    TclGetUnicodeLengthFromObj(objv[2]));
		}
	    }
	    break;
	}
	case STR_MAP: {
	    int uselen, mapElemc, len, nocase = 0;
	    Tcl_Obj **mapElemv;







|







1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
		 */

		if (objv[2]->typePtr == &tclByteArrayType) {
		    (void) Tcl_GetByteArrayFromObj(objv[2], &length1);
		    Tcl_SetIntObj(resultPtr, length1);
		} else {
		    Tcl_SetIntObj(resultPtr,
			    Tcl_GetCharLength(objv[2]));
		}
	    }
	    break;
	}
	case STR_MAP: {
	    int uselen, mapElemc, len, nocase = 0;
	    Tcl_Obj **mapElemv;
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
		string1 = Tcl_GetStringFromObj(objv[2], &length1);
		
		/*
		 * Convert to Unicode internal rep to calulate length and
		 * create a result object.
		 */

		length2 = TclGetUnicodeLengthFromObj(objv[2]) - 1;
    
		if (TclGetIntForIndex(interp, objv[3], length2,
			&first) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (TclGetIntForIndex(interp, objv[4], length2,
			&last) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (first < 0) {
		    first = 0;
		}
		if (last >= length1 - 1) {
		    last = length1 - 1;
		}
		if (last >= first) {
		    resultPtr = TclGetRangeFromObj(objv[2], first, last);
		    Tcl_SetObjResult(interp, resultPtr);
		}
	    }
	    break;
	}
	case STR_REPEAT: {
	    int count;







|
















|







1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
		string1 = Tcl_GetStringFromObj(objv[2], &length1);
		
		/*
		 * Convert to Unicode internal rep to calulate length and
		 * create a result object.
		 */

		length2 = Tcl_GetCharLength(objv[2]) - 1;
    
		if (TclGetIntForIndex(interp, objv[3], length2,
			&first) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (TclGetIntForIndex(interp, objv[4], length2,
			&last) != TCL_OK) {
		    return TCL_ERROR;
		}
		if (first < 0) {
		    first = 0;
		}
		if (last >= length1 - 1) {
		    last = length1 - 1;
		}
		if (last >= first) {
		    resultPtr = Tcl_GetRange(objv[2], first, last);
		    Tcl_SetObjResult(interp, resultPtr);
		}
	    }
	    break;
	}
	case STR_REPEAT: {
	    int count;
1757
1758
1759
1760
1761
1762
1763

1764
1765
1766
1767
1768
1769
1770
		    length2 = Tcl_UtfToUpper(string2);
		} else {
		    length2 = Tcl_UtfToTitle(string2);
		}
		Tcl_SetStringObj(resultPtr, string1, start - string1);
		Tcl_AppendToObj(resultPtr, string2, length2);
		Tcl_AppendToObj(resultPtr, end, -1);

	    }
	    break;

	case STR_TRIM: {
	    Tcl_UniChar ch, trim;
	    register char *p, *end;
	    char *check, *checkEnd;







>







1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
		    length2 = Tcl_UtfToUpper(string2);
		} else {
		    length2 = Tcl_UtfToTitle(string2);
		}
		Tcl_SetStringObj(resultPtr, string1, start - string1);
		Tcl_AppendToObj(resultPtr, string2, length2);
		Tcl_AppendToObj(resultPtr, end, -1);
		ckfree(string2);
	    }
	    break;

	case STR_TRIM: {
	    Tcl_UniChar ch, trim;
	    register char *p, *end;
	    char *check, *checkEnd;

Changes to generic/tclDecls.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * tclDecls.h --
 *
 *	Declarations of functions in the platform independent public Tcl API.
 *
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclDecls.h,v 1.15 1999/06/10 04:28:50 stanton Exp $
 */

#ifndef _TCLDECLS
#define _TCLDECLS

/*
 * WARNING: This file is automatically generated by the tools/genStubs.tcl










|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * tclDecls.h --
 *
 *	Declarations of functions in the platform independent public Tcl API.
 *
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclDecls.h,v 1.16 1999/06/15 01:16:22 hershey Exp $
 */

#ifndef _TCLDECLS
#define _TCLDECLS

/*
 * WARNING: This file is automatically generated by the tools/genStubs.tcl
1171
1172
1173
1174
1175
1176
1177




















1178
1179
1180
1181
1182
1183
1184
/* 376 */
EXTERN int		Tcl_RegExpMatchObj _ANSI_ARGS_((Tcl_Interp * interp, 
				Tcl_RegExp regexp, Tcl_Obj * objPtr, 
				int offset, int nmatches, int flags));
/* 377 */
EXTERN void		Tcl_RegExpGetInfo _ANSI_ARGS_((Tcl_RegExp regexp, 
				Tcl_RegExpInfo * infoPtr));





















typedef struct TclStubHooks {
    struct TclPlatStubs *tclPlatStubs;
    struct TclIntStubs *tclIntStubs;
    struct TclIntPlatStubs *tclIntPlatStubs;
} TclStubHooks;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
/* 376 */
EXTERN int		Tcl_RegExpMatchObj _ANSI_ARGS_((Tcl_Interp * interp, 
				Tcl_RegExp regexp, Tcl_Obj * objPtr, 
				int offset, int nmatches, int flags));
/* 377 */
EXTERN void		Tcl_RegExpGetInfo _ANSI_ARGS_((Tcl_RegExp regexp, 
				Tcl_RegExpInfo * infoPtr));
/* 378 */
EXTERN Tcl_Obj *	Tcl_NewUnicodeObj _ANSI_ARGS_((Tcl_UniChar * unicode, 
				int numChars));
/* 379 */
EXTERN void		Tcl_SetUnicodeObj _ANSI_ARGS_((Tcl_Obj * objPtr, 
				Tcl_UniChar * unicode, int numChars));
/* 380 */
EXTERN int		Tcl_GetCharLength _ANSI_ARGS_((Tcl_Obj * objPtr));
/* 381 */
EXTERN Tcl_UniChar	Tcl_GetUniChar _ANSI_ARGS_((Tcl_Obj * objPtr, 
				int index));
/* 382 */
EXTERN Tcl_UniChar *	Tcl_GetUnicode _ANSI_ARGS_((Tcl_Obj * objPtr));
/* 383 */
EXTERN Tcl_Obj *	Tcl_GetRange _ANSI_ARGS_((Tcl_Obj * objPtr, 
				int first, int last));
/* 384 */
EXTERN void		Tcl_AppendUnicodeToObj _ANSI_ARGS_((
				register Tcl_Obj * objPtr, 
				Tcl_UniChar * unicode, int length));

typedef struct TclStubHooks {
    struct TclPlatStubs *tclPlatStubs;
    struct TclIntStubs *tclIntStubs;
    struct TclIntPlatStubs *tclIntPlatStubs;
} TclStubHooks;

1616
1617
1618
1619
1620
1621
1622







1623
1624
1625
1626
1627
1628
1629
    int (*tcl_StringCaseMatch) _ANSI_ARGS_((CONST char * str, CONST char * pattern, int nocase)); /* 371 */
    int (*tcl_UniCharIsControl) _ANSI_ARGS_((int ch)); /* 372 */
    int (*tcl_UniCharIsGraph) _ANSI_ARGS_((int ch)); /* 373 */
    int (*tcl_UniCharIsPrint) _ANSI_ARGS_((int ch)); /* 374 */
    int (*tcl_UniCharIsPunct) _ANSI_ARGS_((int ch)); /* 375 */
    int (*tcl_RegExpMatchObj) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_RegExp regexp, Tcl_Obj * objPtr, int offset, int nmatches, int flags)); /* 376 */
    void (*tcl_RegExpGetInfo) _ANSI_ARGS_((Tcl_RegExp regexp, Tcl_RegExpInfo * infoPtr)); /* 377 */







} TclStubs;

#ifdef __cplusplus
extern "C" {
#endif
extern TclStubs *tclStubsPtr;
#ifdef __cplusplus







>
>
>
>
>
>
>







1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
    int (*tcl_StringCaseMatch) _ANSI_ARGS_((CONST char * str, CONST char * pattern, int nocase)); /* 371 */
    int (*tcl_UniCharIsControl) _ANSI_ARGS_((int ch)); /* 372 */
    int (*tcl_UniCharIsGraph) _ANSI_ARGS_((int ch)); /* 373 */
    int (*tcl_UniCharIsPrint) _ANSI_ARGS_((int ch)); /* 374 */
    int (*tcl_UniCharIsPunct) _ANSI_ARGS_((int ch)); /* 375 */
    int (*tcl_RegExpMatchObj) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_RegExp regexp, Tcl_Obj * objPtr, int offset, int nmatches, int flags)); /* 376 */
    void (*tcl_RegExpGetInfo) _ANSI_ARGS_((Tcl_RegExp regexp, Tcl_RegExpInfo * infoPtr)); /* 377 */
    Tcl_Obj * (*tcl_NewUnicodeObj) _ANSI_ARGS_((Tcl_UniChar * unicode, int numChars)); /* 378 */
    void (*tcl_SetUnicodeObj) _ANSI_ARGS_((Tcl_Obj * objPtr, Tcl_UniChar * unicode, int numChars)); /* 379 */
    int (*tcl_GetCharLength) _ANSI_ARGS_((Tcl_Obj * objPtr)); /* 380 */
    Tcl_UniChar (*tcl_GetUniChar) _ANSI_ARGS_((Tcl_Obj * objPtr, int index)); /* 381 */
    Tcl_UniChar * (*tcl_GetUnicode) _ANSI_ARGS_((Tcl_Obj * objPtr)); /* 382 */
    Tcl_Obj * (*tcl_GetRange) _ANSI_ARGS_((Tcl_Obj * objPtr, int first, int last)); /* 383 */
    void (*tcl_AppendUnicodeToObj) _ANSI_ARGS_((register Tcl_Obj * objPtr, Tcl_UniChar * unicode, int length)); /* 384 */
} TclStubs;

#ifdef __cplusplus
extern "C" {
#endif
extern TclStubs *tclStubsPtr;
#ifdef __cplusplus
3164
3165
3166
3167
3168
3169
3170




























3171
3172
3173
3174
3175
3176
3177
#define Tcl_RegExpMatchObj \
	(tclStubsPtr->tcl_RegExpMatchObj) /* 376 */
#endif
#ifndef Tcl_RegExpGetInfo
#define Tcl_RegExpGetInfo \
	(tclStubsPtr->tcl_RegExpGetInfo) /* 377 */
#endif





























#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */

/* !END!: Do not edit above this line. */

#endif /* _TCLDECLS */








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
#define Tcl_RegExpMatchObj \
	(tclStubsPtr->tcl_RegExpMatchObj) /* 376 */
#endif
#ifndef Tcl_RegExpGetInfo
#define Tcl_RegExpGetInfo \
	(tclStubsPtr->tcl_RegExpGetInfo) /* 377 */
#endif
#ifndef Tcl_NewUnicodeObj
#define Tcl_NewUnicodeObj \
	(tclStubsPtr->tcl_NewUnicodeObj) /* 378 */
#endif
#ifndef Tcl_SetUnicodeObj
#define Tcl_SetUnicodeObj \
	(tclStubsPtr->tcl_SetUnicodeObj) /* 379 */
#endif
#ifndef Tcl_GetCharLength
#define Tcl_GetCharLength \
	(tclStubsPtr->tcl_GetCharLength) /* 380 */
#endif
#ifndef Tcl_GetUniChar
#define Tcl_GetUniChar \
	(tclStubsPtr->tcl_GetUniChar) /* 381 */
#endif
#ifndef Tcl_GetUnicode
#define Tcl_GetUnicode \
	(tclStubsPtr->tcl_GetUnicode) /* 382 */
#endif
#ifndef Tcl_GetRange
#define Tcl_GetRange \
	(tclStubsPtr->tcl_GetRange) /* 383 */
#endif
#ifndef Tcl_AppendUnicodeToObj
#define Tcl_AppendUnicodeToObj \
	(tclStubsPtr->tcl_AppendUnicodeToObj) /* 384 */
#endif

#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */

/* !END!: Do not edit above this line. */

#endif /* _TCLDECLS */

Changes to generic/tclInt.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * tclInt.h --
 *
 *	Declarations of things used internally by the Tcl interpreter.
 *
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1993-1997 Lucent Technologies.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclInt.h,v 1.32 1999/06/10 04:28:51 stanton Exp $
 */

#ifndef _TCLINT
#define _TCLINT

/*
 * Common include files needed by most of the Tcl source files are













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * tclInt.h --
 *
 *	Declarations of things used internally by the Tcl interpreter.
 *
 * Copyright (c) 1987-1993 The Regents of the University of California.
 * Copyright (c) 1993-1997 Lucent Technologies.
 * Copyright (c) 1994-1998 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclInt.h,v 1.33 1999/06/15 01:16:23 hershey Exp $
 */

#ifndef _TCLINT
#define _TCLINT

/*
 * Common include files needed by most of the Tcl source files are
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
extern Tcl_ObjType	tclByteArrayType;
extern Tcl_ObjType	tclByteCodeType;
extern Tcl_ObjType	tclDoubleType;
extern Tcl_ObjType	tclIntType;
extern Tcl_ObjType	tclListType;
extern Tcl_ObjType	tclProcBodyType;
extern Tcl_ObjType	tclStringType;
extern Tcl_ObjType	tclUnicodeType;

/*
 * The head of the list of free Tcl objects, and the total number of Tcl
 * objects ever allocated and freed.
 */

extern Tcl_Obj *	tclFreeObjList;







<







1505
1506
1507
1508
1509
1510
1511

1512
1513
1514
1515
1516
1517
1518
extern Tcl_ObjType	tclByteArrayType;
extern Tcl_ObjType	tclByteCodeType;
extern Tcl_ObjType	tclDoubleType;
extern Tcl_ObjType	tclIntType;
extern Tcl_ObjType	tclListType;
extern Tcl_ObjType	tclProcBodyType;
extern Tcl_ObjType	tclStringType;


/*
 * The head of the list of free Tcl objects, and the total number of Tcl
 * objects ever allocated and freed.
 */

extern Tcl_Obj *	tclFreeObjList;
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
 */

EXTERN int		TclAccess _ANSI_ARGS_((CONST char *path,
			    int mode));
EXTERN int		TclAccessDeleteProc _ANSI_ARGS_((TclAccessProc_ *proc));
EXTERN int		TclAccessInsertProc _ANSI_ARGS_((TclAccessProc_ *proc));
EXTERN void		TclAllocateFreeObjects _ANSI_ARGS_((void));
EXTERN Tcl_Obj *	TclAppendObjToUnicodeObj _ANSI_ARGS_((
	    		    register Tcl_Obj *targetObjPtr,
	    		    register Tcl_Obj *srcObjPtr));
EXTERN void		TclAppendUnicodeToObj _ANSI_ARGS_((
	    		    register Tcl_Obj *objPtr, Tcl_UniChar *unichars,
			    int length));
EXTERN int		TclArraySet _ANSI_ARGS_((Tcl_Interp *interp,
			    Tcl_Obj *arrayNameObj, Tcl_Obj *arrayElemObj));
EXTERN int		TclCleanupChildren _ANSI_ARGS_((Tcl_Interp *interp,
			    int numPids, Tcl_Pid *pidPtr,
			    Tcl_Channel errorChan));
EXTERN void		TclCleanupCommand _ANSI_ARGS_((Command *cmdPtr));
EXTERN int		TclCopyChannel _ANSI_ARGS_((Tcl_Interp *interp,







<
<
<
<
<
<







1538
1539
1540
1541
1542
1543
1544






1545
1546
1547
1548
1549
1550
1551
 */

EXTERN int		TclAccess _ANSI_ARGS_((CONST char *path,
			    int mode));
EXTERN int		TclAccessDeleteProc _ANSI_ARGS_((TclAccessProc_ *proc));
EXTERN int		TclAccessInsertProc _ANSI_ARGS_((TclAccessProc_ *proc));
EXTERN void		TclAllocateFreeObjects _ANSI_ARGS_((void));






EXTERN int		TclArraySet _ANSI_ARGS_((Tcl_Interp *interp,
			    Tcl_Obj *arrayNameObj, Tcl_Obj *arrayElemObj));
EXTERN int		TclCleanupChildren _ANSI_ARGS_((Tcl_Interp *interp,
			    int numPids, Tcl_Pid *pidPtr,
			    Tcl_Channel errorChan));
EXTERN void		TclCleanupCommand _ANSI_ARGS_((Command *cmdPtr));
EXTERN int		TclCopyChannel _ANSI_ARGS_((Tcl_Interp *interp,
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
			    Namespace **actualCxtPtrPtr,
			    char **simpleNamePtr));
EXTERN TclObjCmdProcType TclGetObjInterpProc _ANSI_ARGS_((void));
EXTERN int		TclGetOpenMode _ANSI_ARGS_((Tcl_Interp *interp,
			    char *string, int *seekFlagPtr));
EXTERN Tcl_Command	TclGetOriginalCommand _ANSI_ARGS_((
			    Tcl_Command command));
EXTERN Tcl_Obj*         TclGetRangeFromObj _ANSI_ARGS_((Tcl_Obj *objPtr,
			    int first, int last));
EXTERN Tcl_UniChar      TclGetUniCharFromObj _ANSI_ARGS_((Tcl_Obj *objPtr,
			    int index));
EXTERN Tcl_UniChar *    TclGetUnicodeFromObj _ANSI_ARGS_((Tcl_Obj *objPtr));
EXTERN int		TclGetUnicodeLengthFromObj _ANSI_ARGS_((
			    Tcl_Obj *objPtr));
EXTERN int		TclGlob _ANSI_ARGS_((Tcl_Interp *interp,
			    char *pattern, int noComplain));
EXTERN int		TclGlobalInvoke _ANSI_ARGS_((Tcl_Interp *interp,
			    int argc, char **argv, int flags));
EXTERN int		TclGuessPackageName _ANSI_ARGS_((char *fileName,
			    Tcl_DString *bufPtr));
EXTERN int		TclHideUnsafeCommands _ANSI_ARGS_((







<
<
<
<
<
<
<







1630
1631
1632
1633
1634
1635
1636







1637
1638
1639
1640
1641
1642
1643
			    Namespace **actualCxtPtrPtr,
			    char **simpleNamePtr));
EXTERN TclObjCmdProcType TclGetObjInterpProc _ANSI_ARGS_((void));
EXTERN int		TclGetOpenMode _ANSI_ARGS_((Tcl_Interp *interp,
			    char *string, int *seekFlagPtr));
EXTERN Tcl_Command	TclGetOriginalCommand _ANSI_ARGS_((
			    Tcl_Command command));







EXTERN int		TclGlob _ANSI_ARGS_((Tcl_Interp *interp,
			    char *pattern, int noComplain));
EXTERN int		TclGlobalInvoke _ANSI_ARGS_((Tcl_Interp *interp,
			    int argc, char **argv, int flags));
EXTERN int		TclGuessPackageName _ANSI_ARGS_((char *fileName,
			    Tcl_DString *bufPtr));
EXTERN int		TclHideUnsafeCommands _ANSI_ARGS_((
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
EXTERN Var *		TclLookupVar _ANSI_ARGS_((Tcl_Interp *interp,
			    char *part1, char *part2, int flags, char *msg,
			    int createPart1, int createPart2,
			    Var **arrayPtrPtr));
EXTERN int		TclMathInProgress _ANSI_ARGS_((void));
EXTERN int		TclNeedSpace _ANSI_ARGS_((char *start, char *end));
EXTERN Tcl_Obj *	TclNewProcBodyObj _ANSI_ARGS_((Proc *procPtr));
EXTERN Tcl_Obj *	TclNewUnicodeObj _ANSI_ARGS_((Tcl_UniChar *unichars,
			    int numChars));
EXTERN int		TclObjCommandComplete _ANSI_ARGS_((Tcl_Obj *cmdPtr));
EXTERN int		TclObjInterpProc _ANSI_ARGS_((ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *CONST objv[]));
EXTERN int		TclObjInvoke _ANSI_ARGS_((Tcl_Interp *interp,
			    int objc, Tcl_Obj *CONST objv[], int flags));
EXTERN int		TclObjInvokeGlobal _ANSI_ARGS_((Tcl_Interp *interp,







<
<







1677
1678
1679
1680
1681
1682
1683


1684
1685
1686
1687
1688
1689
1690
EXTERN Var *		TclLookupVar _ANSI_ARGS_((Tcl_Interp *interp,
			    char *part1, char *part2, int flags, char *msg,
			    int createPart1, int createPart2,
			    Var **arrayPtrPtr));
EXTERN int		TclMathInProgress _ANSI_ARGS_((void));
EXTERN int		TclNeedSpace _ANSI_ARGS_((char *start, char *end));
EXTERN Tcl_Obj *	TclNewProcBodyObj _ANSI_ARGS_((Proc *procPtr));


EXTERN int		TclObjCommandComplete _ANSI_ARGS_((Tcl_Obj *cmdPtr));
EXTERN int		TclObjInterpProc _ANSI_ARGS_((ClientData clientData,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *CONST objv[]));
EXTERN int		TclObjInvoke _ANSI_ARGS_((Tcl_Interp *interp,
			    int objc, Tcl_Obj *CONST objv[], int flags));
EXTERN int		TclObjInvokeGlobal _ANSI_ARGS_((Tcl_Interp *interp,

Changes to generic/tclObj.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tclObj.c --
 *
 *	This file contains Tcl object-related procedures that are used by
 * 	many Tcl commands.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.8 1999/06/08 02:59:25 hershey Exp $
 */

#include "tclInt.h"
#include "tclPort.h"

/*
 * Table of all object types.












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tclObj.c --
 *
 *	This file contains Tcl object-related procedures that are used by
 * 	many Tcl commands.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.9 1999/06/15 01:16:23 hershey Exp $
 */

#include "tclInt.h"
#include "tclPort.h"

/*
 * Table of all object types.
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    Tcl_RegisterObjType(&tclByteArrayType);
    Tcl_RegisterObjType(&tclDoubleType);
    Tcl_RegisterObjType(&tclIntType);
    Tcl_RegisterObjType(&tclStringType);
    Tcl_RegisterObjType(&tclListType);
    Tcl_RegisterObjType(&tclByteCodeType);
    Tcl_RegisterObjType(&tclProcBodyType);
    Tcl_RegisterObjType(&tclUnicodeType);

#ifdef TCL_COMPILE_STATS
    Tcl_MutexLock(&tclObjMutex);
    tclObjsAlloced = 0;
    tclObjsFreed = 0;
    Tcl_MutexUnlock(&tclObjMutex);
#endif







<







134
135
136
137
138
139
140

141
142
143
144
145
146
147
    Tcl_RegisterObjType(&tclByteArrayType);
    Tcl_RegisterObjType(&tclDoubleType);
    Tcl_RegisterObjType(&tclIntType);
    Tcl_RegisterObjType(&tclStringType);
    Tcl_RegisterObjType(&tclListType);
    Tcl_RegisterObjType(&tclByteCodeType);
    Tcl_RegisterObjType(&tclProcBodyType);


#ifdef TCL_COMPILE_STATS
    Tcl_MutexLock(&tclObjMutex);
    tclObjsAlloced = 0;
    tclObjsFreed = 0;
    Tcl_MutexUnlock(&tclObjMutex);
#endif

Changes to generic/tclRegexp.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tclRegexp.c --
 *
 *	This file contains the public interfaces to the Tcl regular
 *	expression mechanism.
 *
 * Copyright (c) 1998 by Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclRegexp.c,v 1.7 1999/06/10 04:28:51 stanton Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include "tclRegexp.h"

/*












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tclRegexp.c --
 *
 *	This file contains the public interfaces to the Tcl regular
 *	expression mechanism.
 *
 * Copyright (c) 1998 by Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclRegexp.c,v 1.8 1999/06/15 01:16:24 hershey Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include "tclRegexp.h"

/*
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
    /*
     * Bump the refcount before we do anything in case the object
     * was newly created.
     */

    Tcl_IncrRefCount(objPtr);

    udata = TclGetUnicodeFromObj(objPtr);
    length = TclGetUnicodeLengthFromObj(objPtr);

    /*
     * Save the target object so we can extract strings from it later.
     */

    regexpPtr->objPtr = objPtr;
    if (oldPtr) {







|
|







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
    /*
     * Bump the refcount before we do anything in case the object
     * was newly created.
     */

    Tcl_IncrRefCount(objPtr);

    udata = Tcl_GetUnicode(objPtr);
    length = Tcl_GetCharLength(objPtr);

    /*
     * Save the target object so we can extract strings from it later.
     */

    regexpPtr->objPtr = objPtr;
    if (oldPtr) {

Changes to generic/tclStringObj.c.

1
2
3
4
5
6
7
8
9
10
11
















12
13
14
15
16
17
18
19
20
21
22
23
24
25
26











27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45



































46
47
48
49
50
51
52
/* 
 * tclStringObj.c --
 *
 *	This file contains procedures that implement string operations
 *	on Tcl objects.  To do this efficiently (i.e. to allow many
 *	appends to be done to an object without constantly reallocating
 *	the space for the string representation) we overallocate the
 *	space for the string and use the internal representation to keep
 *	track of the extra space.  Objects with this internal
 *	representation are called "expandable string objects".
 *
















 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStringObj.c,v 1.7 1999/06/08 02:59:25 hershey Exp $
 */

#include "tclInt.h"

/*
 * Prototypes for procedures defined later in this file:
 */












static void		ConvertToStringType _ANSI_ARGS_((Tcl_Obj *objPtr));


static void		DupStringInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr,
			    Tcl_Obj *copyPtr));
static int		SetStringFromAny _ANSI_ARGS_((Tcl_Interp *interp,
			    Tcl_Obj *objPtr));
static void		UpdateStringOfString _ANSI_ARGS_((Tcl_Obj *objPtr));

/*
 * The structure below defines the string Tcl object type by means of
 * procedures that can be invoked by generic object code.
 */

Tcl_ObjType tclStringType = {
    "string",				/* name */
    (Tcl_FreeInternalRepProc *) NULL,	/* freeIntRepProc */
    DupStringInternalRep,		/* dupIntRepProc */
    UpdateStringOfString,		/* updateStringProc */
    SetStringFromAny			/* setFromAnyProc */
};




































/*
 *----------------------------------------------------------------------
 *
 * Tcl_NewStringObj --
 *
 *	This procedure is normally called when not debugging: i.e., when











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|








>
>
>
>
>
>
>
>
>
>
>
|
>
>













|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* 
 * tclStringObj.c --
 *
 *	This file contains procedures that implement string operations
 *	on Tcl objects.  To do this efficiently (i.e. to allow many
 *	appends to be done to an object without constantly reallocating
 *	the space for the string representation) we overallocate the
 *	space for the string and use the internal representation to keep
 *	track of the extra space.  Objects with this internal
 *	representation are called "expandable string objects".
 *
 * Since some string operations work with UTF strings and others require Unicode
 format, the string obeject type stores one or both formats.  If the object is
 created with a Unicode string, then UTF form is not stored until it is
 required by a string operation.  The string object always stores the number of
 characters, so if the object is created with a UTF string, we automatically
 convert it to unicode (as this costs little more than

A Unicode string
 * is an internationalized string.  Conceptually, a Unicode string is an
 * array of 16-bit quantities organized as a sequence of properly formed
 * UTF-8 characters.  There is a one-to-one map between Unicode and UTF
 * characters.  The Unicode ojbect is opitmized for the case where each UTF
 * char in a string is only one byte.  In this case, we store the value of
 * numChars, but we don't copy the bytes to the unicodeObj->chars.  Before
 * accessing obj->chars, check if unicodeObj->numChars == obj->length.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStringObj.c,v 1.8 1999/06/15 01:16:25 hershey Exp $
 */

#include "tclInt.h"

/*
 * Prototypes for procedures defined later in this file:
 */

static void		AppendUnicodeToUnicodeRep _ANSI_ARGS_((
    			    Tcl_Obj *objPtr, Tcl_UniChar *unicode,
			    int appendNumChars));
static void		AppendUnicodeToUtfRep _ANSI_ARGS_((
    			    Tcl_Obj *objPtr, Tcl_UniChar *unicode,
			    int numChars));
static void		AppendUtfToUnicodeRep _ANSI_ARGS_((Tcl_Obj *objPtr,
    			    char *bytes, int numBytes));
static void		AppendUtfToUtfRep _ANSI_ARGS_((Tcl_Obj *objPtr,
    			    char *bytes, int numBytes));

static void		FillUnicodeRep _ANSI_ARGS_((Tcl_Obj *objPtr));

static void		FreeStringInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
static void		DupStringInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr,
			    Tcl_Obj *copyPtr));
static int		SetStringFromAny _ANSI_ARGS_((Tcl_Interp *interp,
			    Tcl_Obj *objPtr));
static void		UpdateStringOfString _ANSI_ARGS_((Tcl_Obj *objPtr));

/*
 * The structure below defines the string Tcl object type by means of
 * procedures that can be invoked by generic object code.
 */

Tcl_ObjType tclStringType = {
    "string",				/* name */
    FreeStringInternalRep,		/* freeIntRepPro */
    DupStringInternalRep,		/* dupIntRepProc */
    UpdateStringOfString,		/* updateStringProc */
    SetStringFromAny			/* setFromAnyProc */
};

/*
 * The following structure is the internal rep for a String object.
 * It keeps track of how much memory has been used and how much has been
 * allocated for the Unicode and UTF string to enable growing and
 * shrinking of the UTF and Unicode reps of the String object with fewer
 * mallocs.  To optimize string length and indexing operations, this
 * structure also stores the number of characters (same of UTF and Unicode!)
 * once that value has been computede.
 */

typedef struct String {
    int numChars;		/* The number of chars in the string.
				 * -1 means this value has not been
				 * calculated. >= 0 means that there is a
				 * valid Unicode rep, or that the number
				 * of UTF bytes == the number of chars. */
    size_t allocated;		/* The amount of space actually allocated
				 * for the UTF string (minus 1 byte for
				 * the termination char). */
    size_t uallocated;		/* The amount of space actually allocated
				 * for the Unicode string. 0 means the
				 * Unicode string rep is invalid. */
    Tcl_UniChar unicode[2];	/* The array of Unicode chars.  The actual
				 * size of this field depends on the
				 * 'uallocated' field above. */
} String;

#define STRING_SIZE(len)	\
		((unsigned) (sizeof(String) + ((len-1) * sizeof(Tcl_UniChar))))
#define GET_STRING(objPtr) \
		((String *) (objPtr)->internalRep.otherValuePtr)
#define SET_STRING(objPtr, stringPtr) \
		(objPtr)->internalRep.otherValuePtr = (VOID *) (stringPtr)


/*
 *----------------------------------------------------------------------
 *
 * Tcl_NewStringObj --
 *
 *	This procedure is normally called when not debugging: i.e., when
176
177
178
179
180
181
182

































































































































































































































































































































183
184
185
186
187
188
189
				 * procedure; used for debugging. */
    int line;			/* Line number in the source file; used
				 * for debugging. */
{
    return Tcl_NewStringObj(bytes, length);
}
#endif /* TCL_MEM_DEBUG */


































































































































































































































































































































/*
 *----------------------------------------------------------------------
 *
 * Tcl_SetStringObj --
 *
 *	Modify an object to hold a string that is a copy of the bytes







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
				 * procedure; used for debugging. */
    int line;			/* Line number in the source file; used
				 * for debugging. */
{
    return Tcl_NewStringObj(bytes, length);
}
#endif /* TCL_MEM_DEBUG */

/*
 *---------------------------------------------------------------------------
 *
 * TclNewUnicodeObj --
 *
 *	This procedure is creates a new String object and initializes
 *	it from the given Utf String.  If the Utf String is the same size
 *	as the Unicode string, don't duplicate the data.
 *
 * Results:
 *	The newly created object is returned.  This object will have no
 *	initial string representation.  The returned object has a ref count
 *	of 0.
 *
 * Side effects:
 *	Memory allocated for new object and copy of Unicode argument.
 *
 *---------------------------------------------------------------------------
 */

Tcl_Obj *
Tcl_NewUnicodeObj(unicode, numChars)
    Tcl_UniChar *unicode;	/* The unicode string used to initialize
				 * the new object. */
    int numChars;		/* Number of characters in the unicode
				 * string. */
{
    Tcl_Obj *objPtr;
    String *stringPtr;
    int uallocated = (numChars + 1) * sizeof(Tcl_UniChar);

    /*
     * Create a new obj with an invalid string rep.
     */

    TclNewObj(objPtr);
    Tcl_InvalidateStringRep(objPtr);
    objPtr->typePtr = &tclStringType;

    stringPtr = (String *) ckalloc(STRING_SIZE(uallocated));
    stringPtr->numChars = numChars;
    stringPtr->uallocated = uallocated;
    stringPtr->allocated = 0;
    memcpy((VOID *) stringPtr->unicode, (VOID *) unicode,
	    (size_t) (numChars * sizeof(Tcl_UniChar)));
    stringPtr->unicode[numChars] = 0;
    SET_STRING(objPtr, stringPtr);
    return objPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_GetCharLength --
 *
 *	Get the length of the Unicode string from the Tcl object.
 *
 * Results:
 *	Pointer to unicode string representing the unicode object.
 *
 * Side effects:
 *	Frees old internal rep.  Allocates memory for new "String"
 *	internal rep.
 *
 *----------------------------------------------------------------------
 */

int
Tcl_GetCharLength(objPtr)
    Tcl_Obj *objPtr;	/* The String object to get the num chars of. */
{
    String *stringPtr;
    
    SetStringFromAny(NULL, objPtr);
    stringPtr = GET_STRING(objPtr);

/*     if (objPtr->bytes == NULL) { */
/* 	printf("called Tcl_GetCharLength with unicode str.\n"); */
/*     } else { */
/* 	printf("called Tcl_GetCharLength with str = %s\n", objPtr->bytes); */
/*     } */
    
    /*
     * If numChars is unknown, then calculate the number of characaters
     * while populating the Unicode string.
     */
    
    if (stringPtr->numChars == -1) {

	stringPtr->numChars = Tcl_NumUtfChars(objPtr->bytes, objPtr->length);

 	if (stringPtr->numChars == objPtr->length) {

	    /*
	     * Since we've just calucalated the number of chars, and all
	     * UTF chars are 1-byte long, we don't need to store the
	     * unicode string.
	     */
	    
	    stringPtr->uallocated = 0;

	} else {
    
	    /*
	     * Since we've just calucalated the number of chars, and not
	     * all UTF chars are 1-byte long, go ahead and populate the
	     * unicode string.
	     */

	    FillUnicodeRep(objPtr);

	    /*
	     * We need to fetch the pointer again because we have just
	     * reallocated the structure to make room for the Unicode data.
	     */
	    
	    stringPtr = GET_STRING(objPtr);
	}
    }
    return stringPtr->numChars;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_GetUniChar --
 *
 *	Get the index'th Unicode character from the String object.  The
 *	index is assumed to be in the appropriate range.
 *
 * Results:
 *	Returns the index'th Unicode character in the Object.
 *
 * Side effects:
 *	Fills unichar with the index'th Unicode character.
 *
 *----------------------------------------------------------------------
 */

Tcl_UniChar
Tcl_GetUniChar(objPtr, index)
    Tcl_Obj *objPtr;	/* The object to get the Unicode charater from. */
    int index;		/* Get the index'th Unicode character. */
{
    Tcl_UniChar unichar;
    String *stringPtr;
    
    SetStringFromAny(NULL, objPtr);
    stringPtr = GET_STRING(objPtr);

/*     if (objPtr->bytes == NULL) { */
/* 	printf("called Tcl_GetUniChar with unicode str.\n"); */
/*     } else { */
/* 	printf("called Tcl_GetUniChar with str = %s\n", objPtr->bytes); */
/*     } */
    
    if (stringPtr->numChars == -1) {

	/*
	 * We haven't yet calculated the length, so we don't have the
	 * Unicode str.  We need to know the number of chars before we
	 * can do indexing.
	 */

	Tcl_GetCharLength(objPtr);

	/*
	 * We need to fetch the pointer again because we may have just
	 * reallocated the structure.
	 */
	
	stringPtr = GET_STRING(objPtr);
    }
    if (stringPtr->uallocated == 0) {
	char *bytes;

	/*
	 * All of the characters in the Utf string are 1 byte chars,
	 * so we don't store the unicode char.  We get the Utf string
	 * and convert the index'th byte to a Unicode character.
	 */
	
	bytes = Tcl_GetString(objPtr);
	Tcl_UtfToUniChar(&bytes[index], &unichar);	
    } else {
	unichar = stringPtr->unicode[index];
    }
    return unichar;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_GetUnicode --
 *
 *	Get the index'th Unicode character from the String object.  If
 *	the object is not already a String object, it will be converted
 *	to one.  If the String object does not have a Unicode rep, then
 *	one is create from the UTF string format.
 *
 * Results:
 *	Returns a pointer to the object's internal Unicode string.
 *
 * Side effects:
 *	Converts the object to have the String internal rep.
 *
 *----------------------------------------------------------------------
 */

Tcl_UniChar *
Tcl_GetUnicode(objPtr)
    Tcl_Obj *objPtr;	/* The object to find the unicode string for. */
{
    String *stringPtr;
    
    SetStringFromAny(NULL, objPtr);
    stringPtr = GET_STRING(objPtr);
    
/*     if (objPtr->bytes == NULL) { */
/* 	printf("called Tcl_GetUnicode with unicode str.\n"); */
/*     } else { */
/* 	printf("called Tcl_GetUnicode with str = %s\n", objPtr->bytes); */
/*     } */
    
    if ((stringPtr->numChars == -1) || (stringPtr->uallocated == 0)) {

	/*
	 * We haven't yet calculated the length, or all of the characters
	 * in the Utf string are 1 byte chars (so we didn't store the
	 * unicode str).  Since this function must return a unicode string,
	 * and one has not yet been stored, force the Unicode to be
	 * calculated and stored now.
	 */

	FillUnicodeRep(objPtr);

	/*
	 * We need to fetch the pointer again because we have just
	 * reallocated the structure to make room for the Unicode data.
	 */
	
	stringPtr = GET_STRING(objPtr);
    }
    return stringPtr->unicode;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_GetRange --
 *
 *	Create a Tcl Object that contains the chars between first and last
 *	of the object indicated by "objPtr".  If the object is not already
 *	a String object, convert it to one.  The first and last indices
 *	are assumed to be in the appropriate range.
 *
 * Results:
 *	Returns a new Tcl Object of the String type.
 *
 * Side effects:
 *	Changes the internal rep of "objPtr" to the String type.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj*
Tcl_GetRange(objPtr, first, last)
   
 Tcl_Obj *objPtr;		/* The Tcl object to find the range of. */
    int first;			/* First index of the range. */
    int last;			/* Last index of the range. */
{
    Tcl_Obj *newObjPtr;		/* The Tcl object to find the range of. */
    String *stringPtr;
    
    SetStringFromAny(NULL, objPtr);
    stringPtr = GET_STRING(objPtr);

    if (stringPtr->numChars == -1) {
    
	/*
	 * We haven't yet calculated the length, so we don't have the
	 * Unicode str.  We need to know the number of chars before we
	 * can do indexing.
	 */

	Tcl_GetCharLength(objPtr);

	/*
	 * We need to fetch the pointer again because we may have just
	 * reallocated the structure.
	 */
	
	stringPtr = GET_STRING(objPtr);
    }

    if (stringPtr->numChars == objPtr->length) {
	char *str = Tcl_GetString(objPtr);

	/*
	 * All of the characters in the Utf string are 1 byte chars,
	 * so we don't store the unicode char.  Create a new string
	 * object containing the specified range of chars.
	 */
	
	newObjPtr = Tcl_NewStringObj(&str[first], last-first+1);

	/*
	 * Since we know the new string only has 1-byte chars, we
	 * can set it's numChars field.
	 */
	
/* 	stringPtr = GET_STRING(newObjPtr); */
/* 	stringPtr->numChars = last-first+1; */
    } else {
	newObjPtr = Tcl_NewUnicodeObj(stringPtr->unicode + first,
		last-first+1);
    }
    return newObjPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_SetStringObj --
 *
 *	Modify an object to hold a string that is a copy of the bytes
233
234
235
236
237
238
239

240
241
242
243
244
245
246
    objPtr->typePtr = NULL;

    Tcl_InvalidateStringRep(objPtr);
    if (length < 0) {
	length = (bytes? strlen(bytes) : 0);
    }
    TclInitStringRep(objPtr, bytes, length);

}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_SetObjLength --
 *







>







618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
    objPtr->typePtr = NULL;

    Tcl_InvalidateStringRep(objPtr);
    if (length < 0) {
	length = (bytes? strlen(bytes) : 0);
    }
    TclInitStringRep(objPtr, bytes, length);
/*     printf("called Tcl_SetStringObj with str = %s\n", objPtr->bytes); */
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_SetObjLength --
 *
268
269
270
271
272
273
274

275
276
277
278
279
280



281



282

283
284
285
286
287
288
289
290
291
292

293
294
295
296
297

298
299
300
301
302






















































303
304
305
306
307
308
309
    register Tcl_Obj *objPtr;	/* Pointer to object.  This object must
				 * not currently be shared. */
    register int length;	/* Number of bytes desired for string
				 * representation of object, not including
				 * terminating null byte. */
{
    char *new;


    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_SetObjLength called with shared object");
    }
    if (objPtr->typePtr != &tclStringType) {
	ConvertToStringType(objPtr);



    }



    

    if ((long)length > objPtr->internalRep.longValue) {
	/*
	 * Not enough space in current string. Reallocate the string
	 * space and free the old string.
	 */

	new = (char *) ckalloc((unsigned) (length+1));
	if (objPtr->bytes != NULL) {
	    memcpy((VOID *) new, (VOID *) objPtr->bytes,
		    (size_t) objPtr->length);

	    Tcl_InvalidateStringRep(objPtr);
	}
	objPtr->bytes = new;
	objPtr->internalRep.longValue = (long) length;
    }

    objPtr->length = length;
    if ((objPtr->bytes != NULL) && (objPtr->bytes != tclEmptyStringRep)) {
	objPtr->bytes[length] = 0;
    }
}























































/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendToObj --
 *
 *	This procedure appends a sequence of bytes to an object.







>




|
|
>
>
>
|
>
>
>
|
>
|









>



|

>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    register Tcl_Obj *objPtr;	/* Pointer to object.  This object must
				 * not currently be shared. */
    register int length;	/* Number of bytes desired for string
				 * representation of object, not including
				 * terminating null byte. */
{
    char *new;
    String *stringPtr;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_SetObjLength called with shared object");
    }
    SetStringFromAny(NULL, objPtr);
        
    /*
     * Invalidate the unicode data.
     */

    stringPtr = GET_STRING(objPtr);
    stringPtr->numChars = -1;
    stringPtr->uallocated = 0;

    if (length > stringPtr->allocated) {

	/*
	 * Not enough space in current string. Reallocate the string
	 * space and free the old string.
	 */

	new = (char *) ckalloc((unsigned) (length+1));
	if (objPtr->bytes != NULL) {
	    memcpy((VOID *) new, (VOID *) objPtr->bytes,
		    (size_t) objPtr->length);
/* 	    new[objPtr->length] = 0; */
	    Tcl_InvalidateStringRep(objPtr);
	}
	objPtr->bytes = new;
	stringPtr->allocated = length;
    }
    
    objPtr->length = length;
    if ((objPtr->bytes != NULL) && (objPtr->bytes != tclEmptyStringRep)) {
	objPtr->bytes[length] = 0;
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * TclSetUnicodeObj --
 *
 *	Modify an object to hold the Unicode string indicated by "unicode".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Memory allocated for new "String" internal rep.
 *
 *---------------------------------------------------------------------------
 */

void
Tcl_SetUnicodeObj(objPtr, unicode, numChars)
    Tcl_Obj *objPtr;		/* The object to set the string of. */
    Tcl_UniChar *unicode;	/* The unicode string used to initialize
				 * the object. */
    int numChars;		/* Number of characters in the unicode
				 * string. */
{
    Tcl_ObjType *typePtr;
    String *stringPtr;
    size_t uallocated = (numChars + 1) * sizeof(Tcl_UniChar);

    /*
     * Free the internal rep if one exists, and invalidate the string rep.
     */

    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc) != NULL) {
	(*typePtr->freeIntRepProc)(objPtr);
    }
    objPtr->typePtr = &tclStringType;

    /*
     * Allocate enough space for the String structure + Unicode string.
     */
	
    stringPtr = (String *) ckalloc(STRING_SIZE(uallocated));
    stringPtr->numChars = numChars;
    stringPtr->uallocated = uallocated;
    stringPtr->allocated = 0;
    memcpy((VOID *) stringPtr->unicode, (VOID *) unicode,
	    (size_t) (numChars * sizeof(Tcl_UniChar)));
    stringPtr->unicode[numChars] = 0;
    SET_STRING(objPtr, stringPtr);
    Tcl_InvalidateStringRep(objPtr);
    return;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendToObj --
 *
 *	This procedure appends a sequence of bytes to an object.
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340































































341
342
343
344
345
346
347
348
349
350
351
352
353
354


355





356
357

358

359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385






































386




































































































































































































































387
388
389
390
391
392
393
    register Tcl_Obj *objPtr;	/* Points to the object to append to. */
    char *bytes;		/* Points to the bytes to append to the
				 * object. */
    register int length;	/* The number of bytes to append from
				 * "bytes". If < 0, then append all bytes
				 * up to NULL byte. */
{
    int newLength, oldLength;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_AppendToObj called with shared object");
    }
    if (objPtr->typePtr != &tclStringType) {
	ConvertToStringType(objPtr);
    }
    if (length < 0) {
	length = (bytes? strlen(bytes) : 0);
    }































































    if (length == 0) {
	return;
    }
    oldLength = objPtr->length;
    newLength = length + oldLength;
    if ((long)newLength > objPtr->internalRep.longValue) {
	/*
	 * There isn't currently enough space in the string
	 * representation so allocate additional space.  In fact,
	 * overallocate so that there is room for future growth without
	 * having to reallocate again.
	 */

	Tcl_SetObjLength(objPtr, 2*newLength);


    }





    if (length > 0) {
	memcpy((VOID *) (objPtr->bytes + oldLength), (VOID *) bytes,

	       (size_t) length);

	objPtr->length = newLength;
	objPtr->bytes[objPtr->length] = 0;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendObjToObj --
 *
 *	This procedure appends the string rep of one object to another.

 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The string rep of appendObjPtr is appended to the string 
 *	representation of objPtr.
 *
 *----------------------------------------------------------------------
 */

void
Tcl_AppendObjToObj(objPtr, appendObjPtr)
    Tcl_Obj *objPtr;		/* Points to the object to append to. */
    Tcl_Obj *appendObjPtr;	/* Object to append. */
{






































    TclAppendObjToUnicodeObj(objPtr, appendObjPtr);




































































































































































































































}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendStringsToObjVA --
 *







|




|
|
|

|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|
|
|
|
|
|
<
<
|
|
|
>
>
|
>
>
>
>
>
|
|
>
|
>
|
<









>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862


863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
    register Tcl_Obj *objPtr;	/* Points to the object to append to. */
    char *bytes;		/* Points to the bytes to append to the
				 * object. */
    register int length;	/* The number of bytes to append from
				 * "bytes". If < 0, then append all bytes
				 * up to NULL byte. */
{
    String *stringPtr;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_AppendToObj called with shared object");
    }
    
    SetStringFromAny(NULL, objPtr);

    if (length < 0) {
	length = (bytes ? strlen(bytes) : 0);
    }
    if (length == 0) {
	return;
    }

    /*
     * TEMPORARY!!!  This is terribly inefficient, but it works, and Don
     * needs for me to check this stuff in ASAP.  -Melissa
     */
    
/*     printf("called Tcl_AppendToObj with str = %s\n", bytes); */
    UpdateStringOfString(objPtr);
    AppendUtfToUtfRep(objPtr, bytes, length);
    return;

    /*
     * If objPtr has a valid Unicode rep, then append the Unicode
     * conversion of "bytes" to the objPtr's Unicode rep, otherwise
     * append "bytes" to objPtr's string rep.
     */

    stringPtr = GET_STRING(objPtr);
    if (stringPtr->allocated > 0) {
	AppendUtfToUnicodeRep(objPtr, bytes, length);

	stringPtr = GET_STRING(objPtr);
/* 	printf(" ended Tcl_AppendToObj with %d unicode chars.\n", */
/* 		stringPtr->numChars); */
    } else {
	AppendUtfToUtfRep(objPtr, bytes, length);
/* 	printf(" ended Tcl_AppendToObj with str = %s\n", objPtr->bytes); */
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendUnicodeToObj --
 *
 *	This procedure appends a Unicode string to an object in the
 *	most efficient manner possible.  Length must be >= 0.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Invalidates the string rep and creates a new Unicode string.
 *
 *----------------------------------------------------------------------
 */

void
Tcl_AppendUnicodeToObj(objPtr, unicode, length)
    register Tcl_Obj *objPtr;	/* Points to the object to append to. */
    Tcl_UniChar *unicode;	/* The unicode string to append to the
			         * object. */
    int length;			/* Number of chars in "unicode". */
{
    String *stringPtr;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_AppendUnicodeToObj called with shared object");
    }

    if (length == 0) {
	return;
    }

    SetStringFromAny(NULL, objPtr);

    /*
     * TEMPORARY!!!  This is terribly inefficient, but it works, and Don
     * needs for me to check this stuff in ASAP.  -Melissa


     */
    
    UpdateStringOfString(objPtr);
    AppendUnicodeToUtfRep(objPtr, unicode, length);
    return;

    /*
     * If objPtr has a valid Unicode rep, then append the "unicode"
     * to the objPtr's Unicode rep, otherwise the UTF conversion of
     * "unicode" to objPtr's string rep.
     */

    stringPtr = GET_STRING(objPtr);
    if (stringPtr->allocated > 0) {
	AppendUnicodeToUnicodeRep(objPtr, unicode, length);
    } else {
	AppendUnicodeToUtfRep(objPtr, unicode, length);

    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendObjToObj --
 *
 *	This procedure appends the string rep of one object to another.
 *	"objPtr" cannot be a shared object.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The string rep of appendObjPtr is appended to the string 
 *	representation of objPtr.
 *
 *----------------------------------------------------------------------
 */

void
Tcl_AppendObjToObj(objPtr, appendObjPtr)
    Tcl_Obj *objPtr;		/* Points to the object to append to. */
    Tcl_Obj *appendObjPtr;	/* Object to append. */
{
    String *stringPtr;
    int length;
    char *bytes;

    SetStringFromAny(NULL, objPtr);

    /*
     * TEMPORARY!!!  This is terribly inefficient, but it works, and Don
     * needs for me to check this stuff in ASAP.  -Melissa
     */

    UpdateStringOfString(objPtr);
    bytes = Tcl_GetStringFromObj(appendObjPtr, &length);
    AppendUtfToUtfRep(objPtr, bytes, length);
    return;

    /*
     * If objPtr has a valid Unicode rep, then get a Unicode string
     * from appendObjPtr and append it.
     */

    stringPtr = GET_STRING(objPtr);
    if (stringPtr->allocated > 0) {
	
	/*
	 * If appendObjPtr is not of the "String" type, don't convert it.
	 */

	if (appendObjPtr->typePtr == &tclStringType) {
	    stringPtr = GET_STRING(appendObjPtr);
	    if ((stringPtr->numChars == -1)
		    || (stringPtr->uallocated == 0)) {
		
		/*
		 * If appendObjPtr is a string obj with no valide Unicode
		 * rep, then fill its unicode rep.
		 */

		FillUnicodeRep(appendObjPtr);
		stringPtr = GET_STRING(appendObjPtr);
	    }
	    AppendUnicodeToUnicodeRep(objPtr, stringPtr->unicode,
		    stringPtr->numChars);
	} else {
	    bytes = Tcl_GetStringFromObj(appendObjPtr, &length);
	    AppendUtfToUnicodeRep(objPtr, bytes, length);
	}
	return;
    }

    /*
     * Append to objPtr's UTF string rep.
     */

    bytes = Tcl_GetStringFromObj(appendObjPtr, &length);
    AppendUtfToUtfRep(objPtr, bytes, length);
}

/*
 *----------------------------------------------------------------------
 *
 * AppendUnicodeToUnicodeRep --
 *
 *	This procedure appends the contents of "unicode" to the Unicode
 *	rep of "objPtr".  objPtr must already have a valid Unicode rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	objPtr's internal rep is reallocated.
 *
 *----------------------------------------------------------------------
 */

static void
AppendUnicodeToUnicodeRep(objPtr, unicode, appendNumChars)
    Tcl_Obj *objPtr;	      /* Points to the object to append to. */
    Tcl_UniChar *unicode;     /* String to append. */
    int appendNumChars;	      /* Number of chars of "unicode" to append. */
{
    String *stringPtr;
    int numChars;
    size_t newSize;

    if (appendNumChars == 0) {
	return;
    }

    SetStringFromAny(NULL, objPtr);
    stringPtr = GET_STRING(objPtr);
    
    /*
     * Make the buffer big enough for the result.
     */

    numChars = stringPtr->numChars + appendNumChars;
    newSize = (numChars + 1) * sizeof(Tcl_UniChar);

    if (newSize > stringPtr->uallocated) {
	stringPtr->uallocated = newSize * 2;
	stringPtr = (String *) ckrealloc((char*)stringPtr,
		STRING_SIZE(stringPtr->uallocated));
	SET_STRING(objPtr, stringPtr);
    }

    /*
     * Copy the new string onto the end of the old string, then add the
     * trailing null.
     */

    memcpy((VOID*) (stringPtr->unicode + stringPtr->numChars), unicode,
	    appendNumChars * sizeof(Tcl_UniChar));
    stringPtr->unicode[numChars] = 0;
    stringPtr->numChars = numChars;

    SET_STRING(objPtr, stringPtr);
    Tcl_InvalidateStringRep(objPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * AppendUnicodeToUtfRep --
 *
 *	This procedure converts the contents of "unicode" to UTF and
 *	appends the UTF to the string rep of "objPtr".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	objPtr's internal rep is reallocated.
 *
 *----------------------------------------------------------------------
 */

static void
AppendUnicodeToUtfRep(objPtr, unicode, numChars)
    Tcl_Obj *objPtr;	      /* Points to the object to append to. */
    Tcl_UniChar *unicode;     /* String to convert to UTF. */
    int numChars;	      /* Number of chars of "unicode" to convert. */
{
    Tcl_DString dsPtr;
    int length = numChars * sizeof(Tcl_UniChar);
    char *bytes;
    
    if (numChars == 0) {
	return;
    }

    Tcl_DStringInit(&dsPtr);
    bytes = (char *)Tcl_UniCharToUtfDString(unicode, numChars, &dsPtr);
    AppendUtfToUtfRep(objPtr, bytes, Tcl_DStringLength(&dsPtr));
    Tcl_DStringFree(&dsPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * AppendUtfToUnicodeRep --
 *
 *	This procedure converts the contents of "bytes" to Unicode and
 *	appends the Unicode to the Unicode rep of "objPtr".  objPtr must
 *	already have a valid Unicode rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	objPtr's internal rep is reallocated.
 *
 *----------------------------------------------------------------------
 */

static void
AppendUtfToUnicodeRep(objPtr, bytes, numBytes)
    Tcl_Obj *objPtr;	/* Points to the object to append to. */
    char *bytes;		/* String to convert to Unicode. */
    int numBytes;	/* Number of bytes of "bytes" to convert. */
{
    Tcl_DString dsPtr;
    int numChars;
    Tcl_UniChar *unicode;

    if (numBytes < 0) {
	numBytes = (bytes ? strlen(bytes) : 0);
    }
    if (numBytes == 0) {
	return;
    }
    
    Tcl_DStringInit(&dsPtr);
    numChars = Tcl_NumUtfChars(bytes, numBytes);
    unicode = (Tcl_UniChar *)Tcl_UtfToUniCharDString(bytes, numBytes, &dsPtr);
    AppendUnicodeToUnicodeRep(objPtr, unicode, numChars);
    Tcl_DStringFree(&dsPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * AppendUtfToUtfRep --
 *
 *	This procedure appends "numBytes" bytes of "bytes" to the UTF string
 *	rep of "objPtr".  objPtr must already have a valid String rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	objPtr's internal rep is reallocated.
 *
 *----------------------------------------------------------------------
 */

static void
AppendUtfToUtfRep(objPtr, bytes, numBytes)
    Tcl_Obj *objPtr;	/* Points to the object to append to. */
    char *bytes;	/* String to append. */
    int numBytes;	/* Number of bytes of "bytes" to append. */
{
    String *stringPtr;
    int newLength, oldLength;

    if (numBytes < 0) {
	numBytes = (bytes ? strlen(bytes) : 0);
    }
    if (numBytes == 0) {
	return;
    }

    /*
     * Copy the new string onto the end of the old string, then add the
     * trailing null.
     */

    oldLength = objPtr->length;
    newLength = numBytes + oldLength;

    stringPtr = GET_STRING(objPtr);
    if (newLength > stringPtr->allocated) {

	/*
	 * There isn't currently enough space in the string
	 * representation so allocate additional space.  If the current
	 * string representation isn't empty (i.e. it looks like we're
	 * doing a series of appends) then overallocate the space so
	 * that we won't have to do as much reallocation in the future.
	 */

	Tcl_SetObjLength(objPtr,
		(oldLength == 0) ? newLength : 2*newLength);
    } else {

	/*
	 * Invalidate the unicode data.
	 */
	
	stringPtr->numChars = -1;
	stringPtr->uallocated = 0;
    }
    
    memcpy((VOID *) (objPtr->bytes + oldLength), (VOID *) bytes,
	    (size_t) numBytes);
    objPtr->bytes[newLength] = 0;
    objPtr->length = newLength;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppendStringsToObjVA --
 *
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
 */

void
Tcl_AppendStringsToObjVA (objPtr, argList)
    Tcl_Obj *objPtr;		/* Points to the object to append to. */
    va_list argList;		/* Variable argument list. */
{

    va_list tmpArgList;
    int newLength, oldLength;
    register char *string, *dst;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_AppendStringsToObj called with shared object");
    }
    if (objPtr->typePtr != &tclStringType) {
	ConvertToStringType(objPtr);
    }


    /*
     * Figure out how much space is needed for all the strings, and
     * expand the string representation if it isn't big enough. If no
     * bytes would be appended, just return.  Note that on some platforms
     * (notably OS/390) the argList is an array so we need to use memcpy.
     */







>







<
<
|
>







1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205


1206
1207
1208
1209
1210
1211
1212
1213
1214
 */

void
Tcl_AppendStringsToObjVA (objPtr, argList)
    Tcl_Obj *objPtr;		/* Points to the object to append to. */
    va_list argList;		/* Variable argument list. */
{
    String *stringPtr;
    va_list tmpArgList;
    int newLength, oldLength;
    register char *string, *dst;

    if (Tcl_IsShared(objPtr)) {
	panic("Tcl_AppendStringsToObj called with shared object");
    }



    SetStringFromAny(NULL, objPtr);

    /*
     * Figure out how much space is needed for all the strings, and
     * expand the string representation if it isn't big enough. If no
     * bytes would be appended, just return.  Note that on some platforms
     * (notably OS/390) the argList is an array so we need to use memcpy.
     */
436
437
438
439
440
441
442


443
444
445
446
447
448
449
450
	}
	newLength += strlen(string);
    }
    if (newLength == oldLength) {
	return;
    }



    if ((long)newLength > objPtr->internalRep.longValue) {
	/*
	 * There isn't currently enough space in the string
	 * representation so allocate additional space.  If the current
	 * string representation isn't empty (i.e. it looks like we're
	 * doing a series of appends) then overallocate the space so
	 * that we won't have to do as much reallocation in the future.
	 */







>
>
|







1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
	}
	newLength += strlen(string);
    }
    if (newLength == oldLength) {
	return;
    }

    stringPtr = GET_STRING(objPtr);
    if (newLength > stringPtr->allocated) {

	/*
	 * There isn't currently enough space in the string
	 * representation so allocate additional space.  If the current
	 * string representation isn't empty (i.e. it looks like we're
	 * doing a series of appends) then overallocate the space so
	 * that we won't have to do as much reallocation in the future.
	 */
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541



542
543



544
545


546






547




548
549



550
551
552
553


554
555

556
557
558
559
560
561
562

    objPtr = TCL_VARARGS_START(Tcl_Obj *,arg1,argList);
    Tcl_AppendStringsToObjVA(objPtr, argList);
    va_end(argList);
}

/*
 *----------------------------------------------------------------------
 *
 * ConvertToStringType --
 *
 *	This procedure converts the internal representation of an object
 *	to "expandable string" type.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Any old internal reputation for objPtr is freed and the
 *	internal representation is set to that for an expandable string
 *	(the field internalRep.longValue holds 1 less than the allocated
 *	length of objPtr's string representation).
 *
 *----------------------------------------------------------------------
 */

static void
ConvertToStringType(objPtr)
    register Tcl_Obj *objPtr;	/* Pointer to object.  Must have a
				 * typePtr that isn't &tclStringType. */
{
    if (objPtr->typePtr != NULL) {



	if (objPtr->bytes == NULL) {
	    objPtr->typePtr->updateStringProc(objPtr);



	}
	if (objPtr->typePtr->freeIntRepProc != NULL) {


	    objPtr->typePtr->freeIntRepProc(objPtr);






	}




    }
    objPtr->typePtr = &tclStringType;



    if (objPtr->bytes != NULL) {
	objPtr->internalRep.longValue = (long)objPtr->length;
    } else {
	objPtr->internalRep.longValue = 0;


	objPtr->length = 0;
    }

}

/*
 *----------------------------------------------------------------------
 *
 * DupStringInternalRep --
 *







|

|

|
|





|
<
<
<

|



|
|
<

|
>
>
>
|
|
>
>
>
|
|
>
>
|
>
>
>
>
>
>
|
>
>
>
>

|
>
>
>
|
|
<
|
>
>
|
|
>







1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316



1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369

    objPtr = TCL_VARARGS_START(Tcl_Obj *,arg1,argList);
    Tcl_AppendStringsToObjVA(objPtr, argList);
    va_end(argList);
}

/*
 *---------------------------------------------------------------------------
 *
 * FillUnicodeRep --
 *
 *	Populate the Unicode internal rep with the Unicode form of its string
 *	rep.  The object must alread have a "String" internal rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Reallocates the String internal rep.



 *
 *---------------------------------------------------------------------------
 */

static void
FillUnicodeRep(objPtr)
    Tcl_Obj *objPtr;	/* The object in which to fill the unicode rep. */

{
    String *stringPtr;
    size_t uallocated;
    char *src, *srcEnd;
    Tcl_UniChar *dst;
    src = objPtr->bytes;
    
    stringPtr = GET_STRING(objPtr);
    if (stringPtr->numChars == -1) {
	stringPtr->numChars = Tcl_NumUtfChars(src, objPtr->length);
    }

    uallocated = stringPtr->numChars * sizeof(Tcl_UniChar);
    if (uallocated > stringPtr->uallocated) {
    
	/*
	 * If not enought space has been allocated for the unicode rep,
	 * reallocate the internal rep object with double the amount of
	 * space needed, so the unicode string can grow without being
	 * reallocated.
	 */

	uallocated *= 2;
	stringPtr = (String *) ckrealloc((char*) stringPtr,
		STRING_SIZE(uallocated));
	stringPtr->uallocated = uallocated;
    }

    /*
     * Convert src to Unicode and store the coverted data in "unicode".
     */
    
    srcEnd = src + objPtr->length;

    for (dst = stringPtr->unicode; src < srcEnd; dst++) {
	src += Tcl_UtfToUniChar(src, dst);
    }
    *dst = 0;
    
    SET_STRING(objPtr, stringPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * DupStringInternalRep --
 *
577
578
579
580
581
582
583

























584
585
586
587
588
589

590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616




































617
618
619
620
621
622
623
624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
639
640











641

642

643




644


645



646
647




648

649
650

651





652
653
























DupStringInternalRep(srcPtr, copyPtr)
    register Tcl_Obj *srcPtr;	/* Object with internal rep to copy.  Must
				 * have an internal representation of type
				 * "expandable string". */
    register Tcl_Obj *copyPtr;	/* Object with internal rep to set.  Must
				 * not currently have an internal rep.*/
{

























    /*
     * Tricky point: the string value was copied by generic object
     * management code, so it doesn't contain any extra bytes that
     * might exist in the source object.
     */


    copyPtr->internalRep.longValue = (long)copyPtr->length;

    copyPtr->typePtr = &tclStringType;
}

/*
 *----------------------------------------------------------------------
 *
 * SetStringFromAny --
 *
 *	Create an internal representation of type "expandable string"
 *	for an object.
 *
 * Results:
 *	This operation always succeeds and returns TCL_OK.
 *
 * Side effects:
 *	This procedure does nothing; there is no advantage in converting
 *	the internal representation now, so we just defer it.
 *
 *----------------------------------------------------------------------
 */

static int
SetStringFromAny(interp, objPtr)
    Tcl_Interp *interp;		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr;		/* The object to convert. */
{




































    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateStringOfString --
 *
 *	Update the string representation for an object whose internal
 *	representation is "expandable string".
 *
 * Results:
 *	None.
 *
 * Side effects:

 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateStringOfString(objPtr)
    Tcl_Obj *objPtr;		/* Object with string rep to update. */
{











    /*

     * The string is almost always valid already, in which case there's

     * nothing for us to do. The only case we have to worry about is if




     * the object is totally null. In this case, set the string rep to


     * an empty string.



     */





    if (objPtr->bytes == NULL) {

	objPtr->bytes = tclEmptyStringRep;
	objPtr->length = 0;

    }





    return;
}































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
|
>








|
<





|
|









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|





>
|








>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
|
>
>
>
>
|
>
>
|
>
>
>
|

>
>
>
>
|
>
|
|
>
|
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
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
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
DupStringInternalRep(srcPtr, copyPtr)
    register Tcl_Obj *srcPtr;	/* Object with internal rep to copy.  Must
				 * have an internal representation of type
				 * "expandable string". */
    register Tcl_Obj *copyPtr;	/* Object with internal rep to set.  Must
				 * not currently have an internal rep.*/
{
    String *srcStringPtr = GET_STRING(srcPtr);
    String *copyStringPtr;
    
    /*
     * If the src obj is a string of 1-byte Utf chars, then copy the
     * string rep of the source object and create an "empty" Unicode
     * internal rep for the new object.  Otherwise, copy Unicode
     * internal rep, and invalidate the string rep of the new object.
     */
    
    if (srcStringPtr->numChars == srcPtr->length) {
	copyStringPtr = (String *) ckalloc(STRING_SIZE(0));
	copyStringPtr->uallocated = 0;
    } else {
	copyStringPtr = (String *) ckalloc(
	    STRING_SIZE(srcStringPtr->uallocated));
	copyStringPtr->uallocated = srcStringPtr->uallocated;

	memcpy((VOID *) copyStringPtr->unicode,
		(VOID *) srcStringPtr->unicode,
		(size_t) srcStringPtr->numChars * sizeof(Tcl_UniChar));
	copyStringPtr->unicode[srcStringPtr->numChars] = 0;
    }
    copyStringPtr->numChars = srcStringPtr->numChars;

    /*
     * Tricky point: the string value was copied by generic object
     * management code, so it doesn't contain any extra bytes that
     * might exist in the source object.
     */

    copyStringPtr->allocated = copyPtr->length;

    SET_STRING(copyPtr, copyStringPtr);
    copyPtr->typePtr = &tclStringType;
}

/*
 *----------------------------------------------------------------------
 *
 * SetStringFromAny --
 *
 *	Create an internal representation of type "String" for an object.

 *
 * Results:
 *	This operation always succeeds and returns TCL_OK.
 *
 * Side effects:
 *	Any old internal reputation for objPtr is freed and the
 *	internal representation is set to "String".
 *
 *----------------------------------------------------------------------
 */

static int
SetStringFromAny(interp, objPtr)
    Tcl_Interp *interp;		/* Used for error reporting if not NULL. */
    Tcl_Obj *objPtr;		/* The object to convert. */
{
    String *stringPtr;

    /*
     * The Unicode object is opitmized for the case where each UTF char
     * in a string is only one byte.  In this case, we store the value of
     * numChars, but we don't copy the bytes to the unicodeObj->unicode.
     */

    if (objPtr->typePtr != &tclStringType) {

	if (objPtr->typePtr != NULL) {
	    if (objPtr->bytes == NULL) {
		objPtr->typePtr->updateStringProc(objPtr);
	    }
	    if ((objPtr->typePtr->freeIntRepProc) != NULL) {
		(*objPtr->typePtr->freeIntRepProc)(objPtr);
	    }
	}
	objPtr->typePtr = &tclStringType;

	/*
	 * Allocate enough space for the basic String structure.
	 */

	stringPtr = (String *) ckalloc(STRING_SIZE(0));
	stringPtr->numChars = -1;
	stringPtr->uallocated = 0;

	if (objPtr->bytes != NULL) {
	    stringPtr->allocated = objPtr->length;	    
 	    objPtr->bytes[objPtr->length] = 0;
	} else {
	    objPtr->length = 0;
	}
	SET_STRING(objPtr, stringPtr);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateStringOfString --
 *
 *	Update the string representation for an object whose internal
 *	representation is "String".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The object's string may be set by converting its Unicode
 *	represention to UTF format.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateStringOfString(objPtr)
    Tcl_Obj *objPtr;		/* Object with string rep to update. */
{
    int i, length, size;
    Tcl_UniChar *unicode;
    char dummy[TCL_UTF_MAX];
    char *dst;
    String *stringPtr;

    stringPtr = GET_STRING(objPtr);
    if ((objPtr->bytes == NULL) || (stringPtr->allocated == 0)) {

	if (stringPtr->numChars <= 0) {

	    /*
	     * If there is no Unicode rep, or the string has 0 chars,
	     * then set the string rep to an empty string.
	     */

	    objPtr->bytes = tclEmptyStringRep;
	    objPtr->length = 0;
	    return;
	}

	unicode = stringPtr->unicode;
	length = stringPtr->numChars * sizeof(Tcl_UniChar);

	/*
	 * Translate the Unicode string to UTF.  "size" will hold the
	 * amount of space the UTF string needs.
	 */

	size = 0;
	for (i = 0; i < stringPtr->numChars; i++) {
	    size += Tcl_UniCharToUtf((int) unicode[i], dummy);
	}
	
	dst = (char *) ckalloc((unsigned) (size + 1));
	objPtr->bytes = dst;
	objPtr->length = size;
	stringPtr->allocated = size;

	for (i = 0; i < stringPtr->numChars; i++) {
	    dst += Tcl_UniCharToUtf(unicode[i], dst);
	}
	*dst = '\0';
    }
    return;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeStringInternalRep --
 *
 *	Deallocate the storage associated with a String data object's
 *	internal representation.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frees memory. 
 *
 *----------------------------------------------------------------------
 */

static void
FreeStringInternalRep(objPtr)
    Tcl_Obj *objPtr;		/* Object with internal rep to free. */
{
    ckfree((char *) GET_STRING(objPtr));
}

Changes to generic/tclStubInit.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* 
 * tclStubInit.c --
 *
 *	This file contains the initializers for the Tcl stub vectors.
 *
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStubInit.c,v 1.17 1999/06/10 04:28:51 stanton Exp $
 */

#include "tclInt.h"
#include "tclPort.h"

/*
 * Remove macros that will interfere with the definitions below.










|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* 
 * tclStubInit.c --
 *
 *	This file contains the initializers for the Tcl stub vectors.
 *
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclStubInit.c,v 1.18 1999/06/15 01:16:25 hershey Exp $
 */

#include "tclInt.h"
#include "tclPort.h"

/*
 * Remove macros that will interfere with the definitions below.
754
755
756
757
758
759
760







761
762
763
    Tcl_StringCaseMatch, /* 371 */
    Tcl_UniCharIsControl, /* 372 */
    Tcl_UniCharIsGraph, /* 373 */
    Tcl_UniCharIsPrint, /* 374 */
    Tcl_UniCharIsPunct, /* 375 */
    Tcl_RegExpMatchObj, /* 376 */
    Tcl_RegExpGetInfo, /* 377 */







};

/* !END!: Do not edit above this line. */







>
>
>
>
>
>
>



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
    Tcl_StringCaseMatch, /* 371 */
    Tcl_UniCharIsControl, /* 372 */
    Tcl_UniCharIsGraph, /* 373 */
    Tcl_UniCharIsPrint, /* 374 */
    Tcl_UniCharIsPunct, /* 375 */
    Tcl_RegExpMatchObj, /* 376 */
    Tcl_RegExpGetInfo, /* 377 */
    Tcl_NewUnicodeObj, /* 378 */
    Tcl_SetUnicodeObj, /* 379 */
    Tcl_GetCharLength, /* 380 */
    Tcl_GetUniChar, /* 381 */
    Tcl_GetUnicode, /* 382 */
    Tcl_GetRange, /* 383 */
    Tcl_AppendUnicodeToObj, /* 384 */
};

/* !END!: Do not edit above this line. */

Deleted generic/tclUnicodeObj.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
/* 
 * tclUnicodeObj.c --
 *
 *	This file contains the implementation of the Unicode internal
 *	representation of Tcl objects.
 *
 * Copyright (c) 1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclUnicodeObj.c,v 1.6 1999/06/10 19:14:54 hershey Exp $
 */

#include <math.h>
#include "tclInt.h"
#include "tclPort.h"

/*
 * Prototypes for local procedures defined in this file:
 */

static int		AllSingleByteChars _ANSI_ARGS_((Tcl_Obj *objPtr));
static void		AppendUniCharStrToObj _ANSI_ARGS_((Tcl_Obj *objPtr,
			    Tcl_UniChar *unichars, int numNewChars));	
static void		DupUnicodeInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
			    Tcl_Obj *copyPtr));
static void		FreeUnicodeInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
static void		UpdateStringOfUnicode _ANSI_ARGS_((Tcl_Obj *objPtr));
static void		SetOptUnicodeFromAny _ANSI_ARGS_((Tcl_Obj *objPtr,
			    int numChars));
static void		SetFullUnicodeFromAny _ANSI_ARGS_((Tcl_Obj *objPtr,
			    char *src, int numBytes, int numChars));
static int		SetUnicodeFromAny _ANSI_ARGS_((Tcl_Interp *interp,
			    Tcl_Obj *objPtr));

/*
 * The following object type represents a Unicode string.  A Unicode string
 * is an internationalized string.  Conceptually, a Unicode string is an
 * array of 16-bit quantities organized as a sequence of properly formed
 * UTF-8 characters.  There is a one-to-one map between Unicode and UTF
 * characters.  The Unicode ojbect is opitmized for the case where each UTF
 * char in a string is only one byte.  In this case, we store the value of
 * numChars, but we don't copy the bytes to the unicodeObj->chars.  Before
 * accessing obj->chars, check if unicodeObj->numChars == obj->length.
 */

Tcl_ObjType tclUnicodeType = {
    "unicode",
    FreeUnicodeInternalRep,
    DupUnicodeInternalRep,
    UpdateStringOfUnicode,
    SetUnicodeFromAny
};

/*
 * The following structure is the internal rep for a Unicode object.
 * Keeps track of how much memory has been used and how much has been
 * allocated for the Unicode to enable growing and shrinking of the
 * Unicode object with fewer mallocs.  
 */

typedef struct Unicode {
    int numChars;		/* The number of chars in the unicode
				 * string. */
    size_t allocated;		/* The amount of space actually allocated. */
    Tcl_UniChar chars[2];	/* The array of chars.  The actual size of
				 * this field depends on the 'allocated' field
				 * above. */
} Unicode;

#define UNICODE_SIZE(len)	\
		((unsigned) (sizeof(Unicode) - (sizeof(Tcl_UniChar)*2) + (len)))
#define GET_UNICODE(objPtr) \
		((Unicode *) (objPtr)->internalRep.otherValuePtr)
#define SET_UNICODE(objPtr, unicodePtr) \
		(objPtr)->internalRep.otherValuePtr = (VOID *) (unicodePtr)


/*
 *----------------------------------------------------------------------
 *
 * TclGetUnicodeFromObj --
 *
 *	Get the index'th Unicode character from the Unicode object.  If
 *	the object is not already a Unicode object, an attempt will be
 *	made to convert it to one.  The index is assumed to be in the
 *	appropriate range.
 *
 * Results:
 *	Returns a pointer to the object's internal unicode string.
 *
 * Side effects:
 *	Converts the object to have the Unicode internal rep.
 *
 *----------------------------------------------------------------------
 */

Tcl_UniChar *
TclGetUnicodeFromObj(objPtr)
    Tcl_Obj *objPtr;	/* The object to find the unicode string for. */
{
    Unicode *unicodePtr;
    int numBytes;
    char *src;
    
    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);
    
    if (unicodePtr->allocated == 0) {

	/*
	 * If all of the characters in the Utf string are 1 byte chars,
	 * we don't normally store the unicode str.  Since this
	 * function must return a unicode string, and one has not yet
	 * been stored, force the Unicode to be calculated and stored
	 * now.
	 */
	
	src = Tcl_GetStringFromObj(objPtr, &numBytes);
	SetFullUnicodeFromAny(objPtr, src, numBytes, unicodePtr->numChars);

	/*
	 * We need to fetch the pointer again because we have just
	 * reallocated the structure to make room for the Unicode data.
	 */
	
	unicodePtr = GET_UNICODE(objPtr);
    }
    return unicodePtr->chars;
}

/*
 *----------------------------------------------------------------------
 *
 * TclGetUnicodeLengthFromObj --
 *
 *	Get the length of the Unicode string from the Tcl object.  If
 *	the object is not already a Unicode object, an attempt will be
 *	made to convert it to one.
 *
 * Results:
 *	Pointer to unicode string representing the unicode object.
 *
 * Side effects:
 *	Frees old internal rep.  Allocates memory for new internal rep.
 *
 *----------------------------------------------------------------------
 */

int
TclGetUnicodeLengthFromObj(objPtr)
    Tcl_Obj *objPtr;		/* The Unicode object. */
{
    int length;
    Unicode *unicodePtr;
    
    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);

    length = unicodePtr->numChars;
    return length;
}

/*
 *----------------------------------------------------------------------
 *
 * TclGetUniCharFromObj --
 *
 *	Get the index'th Unicode character from the Unicode object.  If
 *	the object is not already a Unicode object, an attempt will be
 *	made to convert it to one.  The index is assumed to be in the
 *	appropriate range.
 *
 * Results:
 *	Returns the index'th Unicode character in the Object.
 *
 * Side effects:
 *	Fills unichar with the index'th Unicode character.
 *
 *----------------------------------------------------------------------
 */

Tcl_UniChar
TclGetUniCharFromObj(objPtr, index)
    Tcl_Obj *objPtr;		/* The Unicode object. */
    int index;			/* Get the index'th character. */
{
    Tcl_UniChar unichar;
    Unicode *unicodePtr;
    int length;
    
    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);
    length = objPtr->length;
    
    if (AllSingleByteChars(objPtr)) {
	int length;
	char *str;

	/*
	 * All of the characters in the Utf string are 1 byte chars,
	 * so we don't store the unicode char.  We get the Utf string
	 * and convert the index'th byte to a Unicode character.
	 */
	
	str = Tcl_GetStringFromObj(objPtr, &length);
	Tcl_UtfToUniChar(&str[index], &unichar);	
    } else {
	unichar = unicodePtr->chars[index];
    }
    return unichar;
}

/*
 *----------------------------------------------------------------------
 *
 * TclGetRangeFromObj --
 *
 *	Create a Tcl Object that contains the chars between first and last
 *	of the object indicated by "objPtr".  If the object is not already
 *	a Unicode object, an attempt will be made to convert it to one.
 *	The first and last indices are assumed to be in the appropriate
 *	range.
 *
 * Results:
 *	Returns a new Tcl Object of either "string" or "unicode" type,
 *	containing the range of chars.
 *
 * Side effects:
 *	Changes the internal rep of "objPtr" to unicode.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj*
TclGetRangeFromObj(objPtr, first, last)
   
 Tcl_Obj *objPtr;		/* The Tcl object to find the range of. */
    int first;			/* First index of the range. */
    int last;			/* Last index of the range. */
{
    Tcl_Obj *newObjPtr;		/* The Tcl object to find the range of. */
    Unicode *unicodePtr;
    int length;
    
    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);
    length = objPtr->length;
    
    if (unicodePtr->numChars != length) {
	newObjPtr = TclNewUnicodeObj(unicodePtr->chars + first, last-first+1);
    } else {
	int length;
	char *str;

	/*
	 * All of the characters in the Utf string are 1 byte chars,
	 * so we don't store the unicode char.  Create a new string
	 * object containing the specified range of chars.
	 */
	
	str = Tcl_GetStringFromObj(objPtr, &length);
	newObjPtr = Tcl_NewStringObj(&str[first], last-first+1);	
    }
    return newObjPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TclAppendObjToUnicodeObj --
 *
 *	This procedure appends the contents of "srcObjPtr" to the Unicode
 *	object "destPtr".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	If srcObjPtr doesn't have an internal rep, then it is given a
 *	Unicode internal rep.
 *
 *----------------------------------------------------------------------
 */

Tcl_Obj *
TclAppendObjToUnicodeObj(targetObjPtr, srcObjPtr)
    register Tcl_Obj *targetObjPtr;	/* Points to the object to
					 * append to. */
    register Tcl_Obj *srcObjPtr;	/* Points to the object to
					 * append from. */
{
    int numBytes, numChars;
    Tcl_Obj *resultObjPtr;
    char *utfSrcStr;
    Tcl_UniChar *unicharSrcStr;
    Unicode *unicodePtr;
    Tcl_DString dsPtr;
    
    /*
     * Duplicate the target if it is shared.
     * Change the result's internal rep to Unicode object.
     */
    
    if (Tcl_IsShared(targetObjPtr)) {
	resultObjPtr = Tcl_DuplicateObj(targetObjPtr);
    } else {
	resultObjPtr = targetObjPtr;
    }
    SetUnicodeFromAny(NULL, resultObjPtr);

    /*
     * Case where target chars are 1 byte long:
     * If src obj is of "string" or null type, then convert it to "unicode"
     * type.  Src objs of other types (such as int) are left in tact to keep
     * them from shimmering between types.  If the src obj is a unichar obj,
     * and all src chars are also 1 byte long, the src string is appended to
     * the target "unicode" obj, and the target obj maintains its "optimized"
     * status.
     */

    if (AllSingleByteChars(resultObjPtr)) {

	int length;
	char *stringRep;

	if (srcObjPtr->typePtr == &tclStringType
		|| srcObjPtr->typePtr == NULL) {
	    SetUnicodeFromAny(NULL, srcObjPtr);
	}

	stringRep = Tcl_GetStringFromObj(srcObjPtr, &length);
	Tcl_AppendToObj(resultObjPtr, stringRep, length);

	if ((srcObjPtr->typePtr == &tclUnicodeType)
		&& (AllSingleByteChars(srcObjPtr))) {
	    SetOptUnicodeFromAny(resultObjPtr, resultObjPtr->length);
	}
	return resultObjPtr;
    }

    /*
     * Extract a unicode string from "unicode" or "string" type objects.
     * Extract the utf string from non-unicode objects, and convert the
     * utf string to unichar string locally.
     * If the src obj is a "string" obj, convert it to "unicode" type.
     * Src objs of other types (such as int) are left in tact to keep
     * them from shimmering between types.
     */

    Tcl_DStringInit(&dsPtr);
    if (srcObjPtr->typePtr == &tclStringType || srcObjPtr->typePtr == NULL) {
	SetUnicodeFromAny(NULL, srcObjPtr);
    }
    if (srcObjPtr->typePtr == &tclUnicodeType) {
	if (AllSingleByteChars(srcObjPtr)) {

	    unicodePtr = GET_UNICODE(srcObjPtr);
	    numChars = unicodePtr->numChars;

	    utfSrcStr = Tcl_GetStringFromObj(srcObjPtr, &numBytes);
	    unicharSrcStr = (Tcl_UniChar *)Tcl_UtfToUniCharDString(utfSrcStr,
		    numBytes, &dsPtr);
	} else {
	    unicodePtr = GET_UNICODE(srcObjPtr);
	    numChars = unicodePtr->numChars;
	    unicharSrcStr = unicodePtr->chars;
	}
    } else {
	utfSrcStr = Tcl_GetStringFromObj(srcObjPtr, &numBytes);
	numChars = Tcl_NumUtfChars(utfSrcStr, numBytes);
	unicharSrcStr = (Tcl_UniChar *)Tcl_UtfToUniCharDString(utfSrcStr,
		numBytes, &dsPtr);
    }
    if (numChars == 0) {
	return resultObjPtr;
    }

    /*
     * Append the unichar src string to the result object.
     */

    AppendUniCharStrToObj(resultObjPtr, unicharSrcStr, numChars);
    Tcl_DStringFree(&dsPtr);
    return resultObjPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * AppendUniCharStrToObj --
 *
 *	This procedure appends the contents of "srcObjPtr" to the
 *	Unicode object "objPtr".
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	If srcObjPtr doesn't have an internal rep, then it is given a
 *	Unicode internal rep.
 *
 *----------------------------------------------------------------------
 */

static void
AppendUniCharStrToObj(objPtr, unichars, numNewChars)
    register Tcl_Obj *objPtr;	/* Points to the object to append to. */
    Tcl_UniChar *unichars;	/* The unicode string to append to the
			         * object. */
    int numNewChars;		/* Number of chars in "unichars". */
{
    Unicode *unicodePtr;
    int numChars;
    size_t numBytes;

    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);
    
    numChars = numNewChars + unicodePtr->numChars;
    numBytes = (numChars + 1) * sizeof(Tcl_UniChar);
    
    if (unicodePtr->allocated < numBytes) {
	int allocatedBytes = numBytes * 2;
    
	/*
	 * There isn't currently enough space in the Unicode
	 * representation so allocate additional space.  In fact,
	 * overallocate so that there is room for future growth without
	 * having to reallocate again.
	 */

	unicodePtr = (Unicode *) ckrealloc((char*) unicodePtr,
		UNICODE_SIZE(allocatedBytes));
	unicodePtr->allocated = allocatedBytes;	
	unicodePtr = SET_UNICODE(objPtr, unicodePtr);
    }
    memcpy((VOID *) (unicodePtr->chars + unicodePtr->numChars),
	    (VOID *) unichars, (size_t) numNewChars * sizeof(Tcl_UniChar));
    unicodePtr->chars[numChars] = 0;
    unicodePtr->numChars = numChars;

    /*
     * Invalidate the StringRep.
     */

    Tcl_InvalidateStringRep(objPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TclAppendUnicodeToObj --
 *
 *	This procedure appends a Unicode string to an object in the
 *	most efficient manner possible.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Invalidates the string rep and creates a new Unicode string.
 *
 *----------------------------------------------------------------------
 */

void
TclAppendUnicodeToObj(objPtr, unichars, length)
    register Tcl_Obj *objPtr;	/* Points to the object to append to. */
    Tcl_UniChar *unichars;	/* The unicode string to append to the
			         * object. */
    int length;			/* Number of chars in "unichars". */
{
    Unicode *unicodePtr;
    int numChars, i;
    size_t newSize;
    char *src;
    Tcl_UniChar *dst;

    if (Tcl_IsShared(objPtr)) {
	panic("TclAppendUnicodeToObj called with shared object");
    }

    SetUnicodeFromAny(NULL, objPtr);
    unicodePtr = GET_UNICODE(objPtr);
    
    /*
     * Make the buffer big enough for the result.
     */

    numChars = unicodePtr->numChars + length;
    newSize = (numChars + 1) * sizeof(Tcl_UniChar);

    if (newSize > unicodePtr->allocated) {
	int allocated = newSize * 2;
    
	unicodePtr = (Unicode *) ckrealloc((char*)unicodePtr,
		UNICODE_SIZE(allocated));

	if (unicodePtr->allocated == 0) {
	    /*
	     * If the original string was not in Unicode form, add it to the
	     * beginning of the buffer.
	     */

	    src = objPtr->bytes;
	    dst = unicodePtr->chars;
	    for (i = 0; i < unicodePtr->numChars; i++) {
		src += Tcl_UtfToUniChar(src, dst++);
	    }
	}
	unicodePtr->allocated = allocated;
    }

    /*
     * Copy the new string onto the end of the old string, then add the
     * trailing null.
     */

    memcpy((VOID*) (unicodePtr->chars + unicodePtr->numChars), unichars,
	    length * sizeof(Tcl_UniChar));
    unicodePtr->numChars = numChars;
    unicodePtr->chars[numChars] = 0;

    SET_UNICODE(objPtr, unicodePtr);

    Tcl_InvalidateStringRep(objPtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * TclNewUnicodeObj --
 *
 *	This procedure is creates a new Unicode object and initializes
 *	it from the given Utf String.  If the Utf String is the same size
 *	as the Unicode string, don't duplicate the data.
 *
 * Results:
 *	The newly created object is returned.  This object will have no
 *	initial string representation.  The returned object has a ref count
 *	of 0.
 *
 * Side effects:
 *	Memory allocated for new object and copy of Unicode argument.
 *
 *---------------------------------------------------------------------------
 */

Tcl_Obj *
TclNewUnicodeObj(unichars, numChars)
    Tcl_UniChar *unichars;	/* The unicode string used to initialize
				 * the new object. */
    int numChars;		/* Number of characters in the unicode
				 * string. */
{
    Tcl_Obj *objPtr;
    Unicode *unicodePtr;
    int numBytes, allocated;

    numBytes = numChars * sizeof(Tcl_UniChar);

    /*
     * Allocate extra space for the null character
     */

    allocated = numBytes + sizeof(Tcl_UniChar);
    
    TclNewObj(objPtr);
    objPtr->bytes = NULL;
    objPtr->typePtr = &tclUnicodeType;

    unicodePtr = (Unicode *) ckalloc(UNICODE_SIZE(allocated));
    unicodePtr->numChars = numChars;
    unicodePtr->allocated = allocated;
    memcpy((VOID *) unicodePtr->chars, (VOID *) unichars, (size_t) numBytes);
    unicodePtr->chars[numChars] = 0;
    SET_UNICODE(objPtr, unicodePtr);
    return objPtr;
}

/*
 *---------------------------------------------------------------------------
 *
 * TclAllSingleByteChars --
 *
 *	Initialize the internal representation of a Unicode Tcl_Obj
 *	to a copy of the internal representation of an existing Unicode
 *	object. 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates memory.
 *
 *---------------------------------------------------------------------------
 */

static int
AllSingleByteChars(objPtr)
    Tcl_Obj *objPtr;		/* Object whose char lengths to check. */
{
    Unicode *unicodePtr;
    int numBytes, numChars;

    unicodePtr = GET_UNICODE(objPtr);
    numChars = unicodePtr->numChars;
    numBytes = objPtr->length;

    if (numChars == numBytes) {
	return 1;
    } else {
	return 0;
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * DupUnicodeInternalRep --
 *
 *	Initialize the internal representation of a Unicode Tcl_Obj
 *	to a copy of the internal representation of an existing Unicode
 *	object. 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Allocates memory.
 *
 *---------------------------------------------------------------------------
 */

static void
DupUnicodeInternalRep(srcPtr, copyPtr)
    Tcl_Obj *srcPtr;		/* Object with internal rep to copy. */
    Tcl_Obj *copyPtr;		/* Object with internal rep to set. */
{
    Unicode *srcUnicodePtr = GET_UNICODE(srcPtr);
    Unicode *copyUnicodePtr;
    
    /*
     * If the src obj is a string of 1-byte Utf chars, then copy the
     * string rep of the source object and create an "empty" Unicode
     * internal rep for the new object.  Otherwise, copy Unicode
     * internal rep, and invalidate the string rep of the new object.
     */
    
    if (srcUnicodePtr->numChars == srcPtr->length) {
	copyUnicodePtr = (Unicode *) ckalloc(sizeof(Unicode));
	copyUnicodePtr->allocated = 0;
    } else {
	int allocated = srcUnicodePtr->allocated;

	copyUnicodePtr = (Unicode *) ckalloc(UNICODE_SIZE(allocated));

	copyUnicodePtr->allocated = allocated;
	memcpy((VOID *) copyUnicodePtr->chars,
		(VOID *) srcUnicodePtr->chars,
		(size_t) (srcUnicodePtr->numChars + 1) * sizeof(Tcl_UniChar));
    }
    copyUnicodePtr->numChars = srcUnicodePtr->numChars;
    SET_UNICODE(copyPtr, copyUnicodePtr);
    copyPtr->typePtr = &tclUnicodeType;
}

/*
 *---------------------------------------------------------------------------
 *
 * UpdateStringOfUnicode --
 *
 *	Update the string representation for a Unicode data object.
 *	Note: This procedure does not invalidate an existing old string rep
 *	so storage will be lost if this has not already been done. 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The object's string is set to a valid string that results from
 *	the Unicode-to-string conversion.
 *
 *	The object becomes a string object -- the internal rep is
 *	discarded and the typePtr becomes NULL.
 *
 *---------------------------------------------------------------------------
 */

static void
UpdateStringOfUnicode(objPtr)
    Tcl_Obj *objPtr;		/* Unicode object whose string rep to
				 * update. */
{
    int i, length, size;
    Tcl_UniChar *src;
    char dummy[TCL_UTF_MAX];
    char *dst;
    Unicode *unicodePtr;

    unicodePtr = GET_UNICODE(objPtr);
    src = unicodePtr->chars;
    length = unicodePtr->numChars * sizeof(Tcl_UniChar);

    /*
     * How much space will string rep need?
     */
     
    size = 0;
    for (i = 0; i < unicodePtr->numChars; i++) {
	size += Tcl_UniCharToUtf((int) src[i], dummy);
    }

    dst = (char *) ckalloc((unsigned) (size + 1));
    objPtr->bytes = dst;
    objPtr->length = size;

    for (i = 0; i < unicodePtr->numChars; i++) {
	dst += Tcl_UniCharToUtf(src[i], dst);
    }
    *dst = '\0';
}

/*
 *---------------------------------------------------------------------------
 *
 * SetOptUnicodeFromAny --
 *
 *	Generate the optimized Unicode internal rep from the string rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The Unicode ojbect is opitmized for the case where each UTF char in
 *	a string is only one byte.  In this case, we store the value of
 *	numChars, but we don't copy the bytes to the unicodeObj->chars.
 *	Before accessing obj->chars, check if all chars are 1 byte long.
 *
 *---------------------------------------------------------------------------
 */

static void
SetOptUnicodeFromAny(objPtr, numChars)
    Tcl_Obj *objPtr;		/* The object to convert to type Unicode. */
    int numChars;
{
    Tcl_ObjType *typePtr;
    Unicode *unicodePtr;

    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc) != NULL) {
	(*typePtr->freeIntRepProc)(objPtr);
    }
    objPtr->typePtr = &tclUnicodeType;

    /*
     * Allocate enough space for the basic Unicode structure.
     */

    unicodePtr = (Unicode *) ckalloc(sizeof(Unicode));
    unicodePtr->numChars = numChars;
    unicodePtr->allocated = 0;
    SET_UNICODE(objPtr, unicodePtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * SetFullUnicodeFromAny --
 *
 *	Generate the full (non-optimized) Unicode internal rep from the
 *	string rep.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The Unicode internal rep will contain a copy of the string "src" in
 *	unicode format.
 *
 *---------------------------------------------------------------------------
 */

static void
SetFullUnicodeFromAny(objPtr, src, numBytes, numChars)
    Tcl_Obj *objPtr;		/* The object to convert to type Unicode. */
    char *src;
    int numBytes;
    int numChars;
{
    Tcl_ObjType *typePtr;
    Unicode *unicodePtr;
    char *srcEnd;
    Tcl_UniChar *dst;
    size_t length = (numChars + 1) * sizeof(Tcl_UniChar);
    
    unicodePtr = (Unicode *) ckalloc(UNICODE_SIZE(length));
    srcEnd = src + numBytes;
	
    for (dst = unicodePtr->chars; src < srcEnd; dst++) {
	src += Tcl_UtfToUniChar(src, dst);
    }
    *dst = 0;

    unicodePtr->numChars = numChars;
    unicodePtr->allocated = length;
    
    typePtr = objPtr->typePtr;
    if ((typePtr != NULL) && (typePtr->freeIntRepProc) != NULL) {
	(*typePtr->freeIntRepProc)(objPtr);
    }
    objPtr->typePtr = &tclUnicodeType;
    SET_UNICODE(objPtr, unicodePtr);
}

/*
 *---------------------------------------------------------------------------
 *
 * SetUnicodeFromAny --
 *
 *	Generate the Unicode internal rep from the string rep.
 *
 * Results:
 *	The return value is always TCL_OK.
 *
 * Side effects:
 *	A Unicode object is stored as the internal rep of objPtr.  The Unicode
 *	object is opitmized for the case where each UTF char in a string is
 *	only one byte.  In this case, we store the value of numChars, but we
 *	don't copy the bytes to the unicodeObj->chars.  Before accessing
 *	obj->chars, check if all chars are 1 byte long.
 *
 *---------------------------------------------------------------------------
 */

static int
SetUnicodeFromAny(interp, objPtr)
    Tcl_Interp *interp;		/* Not used. */
    Tcl_Obj *objPtr;		/* The object to convert to type Unicode. */
{
    int numBytes, numChars;
    char *src;
    
    if (objPtr->typePtr != &tclUnicodeType) {
	src = Tcl_GetStringFromObj(objPtr, &numBytes);

	numChars = Tcl_NumUtfChars(src, numBytes);
	if (numChars == numBytes) {
	    SetOptUnicodeFromAny(objPtr, numChars);
	} else {
	    SetFullUnicodeFromAny(objPtr, src, numBytes, numChars);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeUnicodeInternalRep --
 *
 *	Deallocate the storage associated with a Unicode data object's
 *	internal representation.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frees memory. 
 *
 *----------------------------------------------------------------------
 */

static void
FreeUnicodeInternalRep(objPtr)
    Tcl_Obj *objPtr;		/* Object with internal rep to free. */
{
    ckfree((char *) GET_UNICODE(objPtr));
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Changes to tests/stringObj.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# Copyright (c) 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: stringObj.test,v 1.3 1999/04/16 00:47:35 stanton Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

if {[info commands testobj] == {}} {
    puts "This application hasn't been compiled with the \"testobj\""







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# Copyright (c) 1995-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: stringObj.test,v 1.4 1999/06/15 01:16:27 hershey Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

if {[info commands testobj] == {}} {
    puts "This application hasn't been compiled with the \"testobj\""
185
186
187
188
189
190
191



















































































































































































192
193
194
195
196
197
198
    teststringobj set 1 {}
    teststringobj append 1 abcde -1
    testobj duplicate 1 2
    list [teststringobj length 1] [teststringobj length2 1] \
	    [teststringobj length 2] [teststringobj length2 2] \
	    [teststringobj get 2]
} {5 10 5 5 abcde}




















































































































































































testobj freeallvars

# cleanup
::tcltest::cleanupTests
return








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
    teststringobj set 1 {}
    teststringobj append 1 abcde -1
    testobj duplicate 1 2
    list [teststringobj length 1] [teststringobj length2 1] \
	    [teststringobj length 2] [teststringobj length2 2] \
	    [teststringobj get 2]
} {5 10 5 5 abcde}

test unicode-1.1 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 0
} "a"
test unicode-1.2 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 3
} "d"
test unicode-1.3 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" end
} "i"
test unicode-1.4 {TclGetUniCharFromObj with mixed width chars} {
    string index "�a�b�c��d�" 0
} "�"
test unicode-1.5 {TclGetUniCharFromObj} {
    string index "�a�b�c��d�" 4
} "�"
test unicode-1.6 {TclGetUniCharFromObj} {
    string index "�a�b�c�d�" end
} "�"

test unicode-2.1 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "" 
} 0
test unicode-2.2 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "a"
} 1
test unicode-2.3 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "abcdef"
} 6
test unicode-2.4 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "�" 
} 1
test unicode-2.5 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "○○" 
} 6
test unicode-2.6 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "�a�b�c�d�" 
} 10

test unicode-3.1 {TclGetRangeFromObj with all byte-size chars} {testobj} {
    set x "abcdef"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bcde string none}

test unicode-3.2 {TclGetRangeFromObj with some mixed width chars} {testobj} {
    set x "abc��def"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bc��de string string}

test unicode-4.1 {UpdateStringOfUnicode} {testobj} {
    set x 2345
    list [string index $x end] [testobj objtype $x] [incr x] \
	    [testobj objtype $x]
} {5 string 2346 int}

test unicode-5.1 {SetUnicodeFromAny called with non-unicode obj} {testobj} {
    set x 2345
    list [incr x] [testobj objtype $x] [string index $x end] \
	    [testobj objtype $x]
} {2346 int 6 string}

test unicode-5.2 {SetUnicodeFromAny called with unicode obj} {testobj} {
    set x "abcdef"
    list [string length $x] [testobj objtype $x] \
	    [string length $x] [testobj objtype $x]
} {6 string 6 string}

test unicode-6.1 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x "���"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string string abc○ghi��� abc○ghi string string}

test unicode-6.2 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x "���"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string string abc○ghi��� abc○ghi string string}

test unicode-6.3 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcdefghijkl abcdefghi string string}

test unicode-6.4 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcdefghijkl abcdefghi string string}

test unicode-7.1 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    set y ���
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string none abc○ghi��� ��� string string}

test unicode-7.2 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {string abcï¿®ghiabcï¿®ghi string\
abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
string}

test unicode-7.3 {TclAppendObjToUnicodeObj, mixed src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y ���
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string none abcdefghi��� ��� string string}

test unicode-7.4 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string none abcdefghijkl jkl string string}

test unicode-7.5 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {string abcdefghiabcdefghi string abcdefghiabcdefghiabcdefghiabcdefghi\
string}

test unicode-7.6 {TclAppendObjToUnicodeObj, 1-byte src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string none abcï¿®ghijkl jkl string string}

test unicode-7.7 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    set y [expr {4 + 5}]
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [testobj objtype $x] [append x $y] [testobj objtype $x] \
	    [testobj objtype $y]
} {int int 209 string 2099 string int}

test unicode-7.8 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {int 2020 string 20202020 string}

test unicode-7.9 {TclAppendObjToUnicodeObj, integer src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string int abcdefghi9 9 string int}

test unicode-7.10 {TclAppendObjToUnicodeObj, integer src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {string int abcï¿®ghi9 9 string int}

testobj freeallvars

# cleanup
::tcltest::cleanupTests
return

Deleted tests/unicode.test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# This file tests the tclUnicode.c file. 
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: unicode.test,v 1.2 1999/06/08 02:59:30 hershey Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

# Some tests require the testobj command

set ::tcltest::testConfig(testobj) \
	[expr {[info commands testobj] != {}}]

test unicode-1.1 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 0
} "a"
test unicode-1.2 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" 3
} "d"
test unicode-1.3 {TclGetUniCharFromObj with byte-size chars} {
    string index "abcdefghi" end
} "i"
test unicode-1.4 {TclGetUniCharFromObj with mixed width chars} {
    string index "�a�b�c��d�" 0
} "�"
test unicode-1.5 {TclGetUniCharFromObj} {
    string index "�a�b�c��d�" 4
} "�"
test unicode-1.6 {TclGetUniCharFromObj} {
    string index "�a�b�c�d�" end
} "�"

test unicode-2.1 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "" 
} 0
test unicode-2.2 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "a"
} 1
test unicode-2.3 {TclGetUnicodeLengthFromObj with byte-size chars} {
    string length "abcdef"
} 6
test unicode-2.4 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "�" 
} 1
test unicode-2.5 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "○○" 
} 6
test unicode-2.6 {TclGetUnicodeLengthFromObj with mixed width chars} {
    string length "�a�b�c�d�" 
} 10

test unicode-3.1 {TclGetRangeFromObj with all byte-size chars} {testobj} {
    set x "abcdef"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bcde unicode none}

test unicode-3.2 {TclGetRangeFromObj with some mixed width chars} {testobj} {
    set x "abc��def"
    list [testobj objtype $x] [set y [string range $x 1 end-1]] \
	    [testobj objtype $x] [testobj objtype $y]
} {none bc��de unicode unicode}

test unicode-4.1 {UpdateStringOfUnicode} {testobj} {
    set x 2345
    list [string index $x end] [testobj objtype $x] [incr x] \
	    [testobj objtype $x]
} {5 unicode 2346 int}

test unicode-5.1 {SetUnicodeFromAny called with non-unicode obj} {testobj} {
    set x 2345
    list [incr x] [testobj objtype $x] [string index $x end] \
	    [testobj objtype $x]
} {2346 int 6 unicode}

test unicode-5.2 {SetUnicodeFromAny called with unicode obj} {testobj} {
    set x "abcdef"
    list [string length $x] [testobj objtype $x] \
	    [string length $x] [testobj objtype $x]
} {6 unicode 6 unicode}

test unicode-6.1 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x "���"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abc○ghi��� abc○ghi unicode unicode}

test unicode-6.2 {DupUnicodeInternalRep, mixed width chars} {testobj} {
    set x abcï¿®ghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x "���"] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abc○ghi��� abc○ghi unicode unicode}

test unicode-6.3 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    string length $x
    set y $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcdefghijkl abcdefghi unicode unicode}

test unicode-6.4 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
    set x abcdefghi
    set y $x
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode unicode abcdefghijkl abcdefghi unicode unicode}

test unicode-7.1 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    set y ���
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abc○ghi��� ��� unicode unicode}

test unicode-7.2 {TclAppendObjToUnicodeObj, mixed src & dest} {testobj} {
    set x abcï¿®ghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {unicode abcï¿®ghiabcï¿®ghi unicode\
abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
unicode}

test unicode-7.3 {TclAppendObjToUnicodeObj, mixed src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y ���
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcdefghi��� ��� string unicode}

test unicode-7.4 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcdefghijkl jkl unicode unicode}

test unicode-7.5 {TclAppendObjToUnicodeObj, 1-byte src & dest} {testobj} {
    set x abcdefghi
    string length $x
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {unicode abcdefghiabcdefghi unicode abcdefghiabcdefghiabcdefghiabcdefghi\
unicode}

test unicode-7.6 {TclAppendObjToUnicodeObj, 1-byte src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y jkl
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode none abcï¿®ghijkl jkl unicode unicode}

test unicode-7.7 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    set y [expr {4 + 5}]
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [testobj objtype $x] [append x $y] [testobj objtype $x] \
	    [testobj objtype $y]
} {int int 209 string 2099 string int}

test unicode-7.8 {TclAppendObjToUnicodeObj, integer src & dest} {testobj} {
    set x [expr {4 * 5}]
    list [testobj objtype $x] [append x $x] [testobj objtype $x] \
	    [append x $x] [testobj objtype $x]
} {int 2020 string 20202020 unicode}

test unicode-7.9 {TclAppendObjToUnicodeObj, integer src & 1-byte dest} {testobj} {
    set x abcdefghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode int abcdefghi9 9 string int}

test unicode-7.10 {TclAppendObjToUnicodeObj, integer src & mixed dest} {testobj} {
    set x abcï¿®ghi
    set y [expr {4 + 5}]
    string length $x
    list [testobj objtype $x] [testobj objtype $y] [append x $y] \
	    [set y] [testobj objtype $x] [testobj objtype $y]
} {unicode int abcï¿®ghi9 9 unicode int}

# cleanup
::tcltest::cleanupTests
return
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
























































































































































































































































































































































































































Changes to unix/Makefile.in.

1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
#
# This file is a Makefile for Tcl.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
# RCS: @(#) $Id: Makefile.in,v 1.29 1999/06/11 01:53:03 surles Exp $



# Current Tcl version;  used in various names.

VERSION 		= @TCL_VERSION@

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own







|
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# This file is a Makefile for Tcl.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
# RCS: @(#) $Id: Makefile.in,v 1.30 1999/06/15 01:16:28 hershey Exp $

# PURIFY =

# Current Tcl version;  used in various names.

VERSION 		= @TCL_VERSION@

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
219
220
221
222
223
224
225

226
227
228
229
230
231
232
TOOL_DIR =		$(TOP_DIR)/tools
UNIX_DIR = 		$(TOP_DIR)/unix
# Must be absolute because of the cd dltest $(DLTEST_DIR)/configure below.
DLTEST_DIR =		@TCL_SRC_DIR@/unix/dltest
# Must be absolute to so the corresponding tcltest's tcl_library is absolute.
TCL_BUILDTIME_LIBRARY=  @TCL_SRC_DIR@/library


CC =			@CC@

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------







>







221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
TOOL_DIR =		$(TOP_DIR)/tools
UNIX_DIR = 		$(TOP_DIR)/unix
# Must be absolute because of the cd dltest $(DLTEST_DIR)/configure below.
DLTEST_DIR =		@TCL_SRC_DIR@/unix/dltest
# Must be absolute to so the corresponding tcltest's tcl_library is absolute.
TCL_BUILDTIME_LIBRARY=  @TCL_SRC_DIR@/library

#CC =			purify @CC@
CC =			@CC@

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
	tclEnv.o tclEvent.o tclExecute.o tclFCmd.o tclFileName.o tclGet.o \
	tclHash.o tclHistory.o tclIndexObj.o tclInterp.o tclIO.o \
	tclIOCmd.o tclIOSock.o tclIOUtil.o tclLink.o tclListObj.o \
	tclLiteral.o tclLoad.o tclMain.o tclNamesp.o tclNotify.o \
	tclObj.o tclPanic.o tclParse.o tclParseExpr.o tclPipe.o \
	tclPkg.o tclPosixStr.o tclPreserve.o tclProc.o tclRegexp.o \
	tclResolve.o tclResult.o tclScan.o tclStringObj.o tclThread.o \
	tclStubInit.o tclStubLib.o tclTimer.o tclUnicodeObj.o tclUtf.o \
	tclUtil.o tclVar.o

STUB_LIB_OBJS = tclStubLib.o ${COMPAT_OBJS}

OBJS = ${GENERIC_OBJS} ${UNIX_OBJS} ${NOTIFY_OBJS} ${COMPAT_OBJS} @DL_OBJS@

TCL_DECLS = \
	$(GENERIC_DIR)/tcl.decls \







|
<







268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
	tclEnv.o tclEvent.o tclExecute.o tclFCmd.o tclFileName.o tclGet.o \
	tclHash.o tclHistory.o tclIndexObj.o tclInterp.o tclIO.o \
	tclIOCmd.o tclIOSock.o tclIOUtil.o tclLink.o tclListObj.o \
	tclLiteral.o tclLoad.o tclMain.o tclNamesp.o tclNotify.o \
	tclObj.o tclPanic.o tclParse.o tclParseExpr.o tclPipe.o \
	tclPkg.o tclPosixStr.o tclPreserve.o tclProc.o tclRegexp.o \
	tclResolve.o tclResult.o tclScan.o tclStringObj.o tclThread.o \
	tclStubInit.o tclStubLib.o tclTimer.o tclUtf.o tclUtil.o tclVar.o


STUB_LIB_OBJS = tclStubLib.o ${COMPAT_OBJS}

OBJS = ${GENERIC_OBJS} ${UNIX_OBJS} ${NOTIFY_OBJS} ${COMPAT_OBJS} @DL_OBJS@

TCL_DECLS = \
	$(GENERIC_DIR)/tcl.decls \
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
	$(GENERIC_DIR)/tclStubLib.c \
	$(GENERIC_DIR)/tclStringObj.c \
	$(GENERIC_DIR)/tclTest.c \
	$(GENERIC_DIR)/tclTestObj.c \
	$(GENERIC_DIR)/tclTestProcBodyObj.c \
	$(GENERIC_DIR)/tclThread.c \
	$(GENERIC_DIR)/tclTimer.c \
	$(GENERIC_DIR)/tclUnicodeObj.c \
	$(GENERIC_DIR)/tclUtil.c \
	$(GENERIC_DIR)/tclVar.c

STUB_SRCS = \
	$(GENERIC_DIR)/tclStubLib.c

UNIX_HDRS = \







<







349
350
351
352
353
354
355

356
357
358
359
360
361
362
	$(GENERIC_DIR)/tclStubLib.c \
	$(GENERIC_DIR)/tclStringObj.c \
	$(GENERIC_DIR)/tclTest.c \
	$(GENERIC_DIR)/tclTestObj.c \
	$(GENERIC_DIR)/tclTestProcBodyObj.c \
	$(GENERIC_DIR)/tclThread.c \
	$(GENERIC_DIR)/tclTimer.c \

	$(GENERIC_DIR)/tclUtil.c \
	$(GENERIC_DIR)/tclVar.c

STUB_SRCS = \
	$(GENERIC_DIR)/tclStubLib.c

UNIX_HDRS = \
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902

tclThread.o: $(GENERIC_DIR)/tclThread.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclThread.c

tclThreadTest.o: $(GENERIC_DIR)/tclThreadTest.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclThreadTest.c

tclUnicodeObj.o: $(GENERIC_DIR)/tclUnicodeObj.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclUnicodeObj.c

tclUnixChan.o: $(UNIX_DIR)/tclUnixChan.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclUnixChan.c

tclUnixEvent.o: $(UNIX_DIR)/tclUnixEvent.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclUnixEvent.c

tclUnixFCmd.o: $(UNIX_DIR)/tclUnixFCmd.c







<
<
<







887
888
889
890
891
892
893



894
895
896
897
898
899
900

tclThread.o: $(GENERIC_DIR)/tclThread.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclThread.c

tclThreadTest.o: $(GENERIC_DIR)/tclThreadTest.c
	$(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclThreadTest.c




tclUnixChan.o: $(UNIX_DIR)/tclUnixChan.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclUnixChan.c

tclUnixEvent.o: $(UNIX_DIR)/tclUnixEvent.c
	$(CC) -c $(CC_SWITCHES) $(UNIX_DIR)/tclUnixEvent.c

tclUnixFCmd.o: $(UNIX_DIR)/tclUnixFCmd.c

Changes to win/Makefile.in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
# This file is a Makefile for Tcl.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
# RCS: @(#) $Id: Makefile.in,v 1.6 1999/06/11 02:06:27 surles Exp $

VERSION = @TCL_VERSION@

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
# This file is a Makefile for Tcl.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
# RCS: @(#) $Id: Makefile.in,v 1.7 1999/06/15 01:16:29 hershey Exp $

VERSION = @TCL_VERSION@

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
	tclResult.$(OBJEXT) \
	tclScan.$(OBJEXT) \
	tclStringObj.$(OBJEXT) \
	tclStubInit.$(OBJEXT) \
	tclStubLib.$(OBJEXT) \
	tclThread.$(OBJEXT) \
	tclTimer.$(OBJEXT) \
	tclUnicodeObj.$(OBJEXT) \
	tclUtf.$(OBJEXT) \
	tclUtil.$(OBJEXT) \
	tclVar.$(OBJEXT)

WIN_OBJS = \
	tclWin32Dll.$(OBJEXT) \
	tclWinChan.$(OBJEXT) \







<







220
221
222
223
224
225
226

227
228
229
230
231
232
233
	tclResult.$(OBJEXT) \
	tclScan.$(OBJEXT) \
	tclStringObj.$(OBJEXT) \
	tclStubInit.$(OBJEXT) \
	tclStubLib.$(OBJEXT) \
	tclThread.$(OBJEXT) \
	tclTimer.$(OBJEXT) \

	tclUtf.$(OBJEXT) \
	tclUtil.$(OBJEXT) \
	tclVar.$(OBJEXT)

WIN_OBJS = \
	tclWin32Dll.$(OBJEXT) \
	tclWinChan.$(OBJEXT) \

Changes to win/makefile.vc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Visual C++ 2.x and 4.0 makefile
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# RCS: @(#) $Id: makefile.vc,v 1.35 1999/06/08 02:59:31 hershey Exp $

# Does not depend on the presence of any environment variables in
# order to compile tcl; all needed information is derived from 
# location of the compiler directories.

#
# Project directories








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Visual C++ 2.x and 4.0 makefile
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# RCS: @(#) $Id: makefile.vc,v 1.36 1999/06/15 01:16:29 hershey Exp $

# Does not depend on the presence of any environment variables in
# order to compile tcl; all needed information is derived from 
# location of the compiler directories.

#
# Project directories
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
	$(TMPDIR)\tclResult.obj \
	$(TMPDIR)\tclScan.obj \
	$(TMPDIR)\tclStringObj.obj \
	$(TMPDIR)\tclStubInit.obj \
	$(TMPDIR)\tclStubLib.obj \
	$(TMPDIR)\tclThread.obj \
	$(TMPDIR)\tclTimer.obj \
	$(TMPDIR)\tclUnicodeObj.obj \
	$(TMPDIR)\tclUtf.obj \
	$(TMPDIR)\tclUtil.obj \
	$(TMPDIR)\tclVar.obj \
	$(TMPDIR)\tclWin32Dll.obj \
	$(TMPDIR)\tclWinChan.obj \
	$(TMPDIR)\tclWinConsole.obj \
	$(TMPDIR)\tclWinSerial.obj \







<







182
183
184
185
186
187
188

189
190
191
192
193
194
195
	$(TMPDIR)\tclResult.obj \
	$(TMPDIR)\tclScan.obj \
	$(TMPDIR)\tclStringObj.obj \
	$(TMPDIR)\tclStubInit.obj \
	$(TMPDIR)\tclStubLib.obj \
	$(TMPDIR)\tclThread.obj \
	$(TMPDIR)\tclTimer.obj \

	$(TMPDIR)\tclUtf.obj \
	$(TMPDIR)\tclUtil.obj \
	$(TMPDIR)\tclVar.obj \
	$(TMPDIR)\tclWin32Dll.obj \
	$(TMPDIR)\tclWinChan.obj \
	$(TMPDIR)\tclWinConsole.obj \
	$(TMPDIR)\tclWinSerial.obj \