OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [DString.3] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: DString.3,v 1.1.1.1 2002-01-16 10:25:23 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tcl_DString 3 7.4 Tcl "Tcl Library Procedures"
12
.BS
13
.SH NAME
14
Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringSetLength, Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult \- manipulate dynamic strings
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
\fBTcl_DStringInit\fR(\fIdsPtr\fR)
20
.sp
21
char *
22
\fBTcl_DStringAppend\fR(\fIdsPtr, string, length\fR)
23
.sp
24
char *
25
\fBTcl_DStringAppendElement\fR(\fIdsPtr, string\fR)
26
.sp
27
\fBTcl_DStringStartSublist\fR(\fIdsPtr\fR)
28
.sp
29
\fBTcl_DStringEndSublist\fR(\fIdsPtr\fR)
30
.sp
31
int
32
\fBTcl_DStringLength\fR(\fIdsPtr\fR)
33
.sp
34
char *
35
\fBTcl_DStringValue\fR(\fIdsPtr\fR)
36
.sp
37
\fBTcl_DStringSetLength\fR(\fIdsPtr, newLength\fR)
38
.sp
39
\fBTcl_DStringFree\fR(\fIdsPtr\fR)
40
.sp
41
\fBTcl_DStringResult\fR(\fIinterp, dsPtr\fR)
42
.sp
43
\fBTcl_DStringGetResult\fR(\fIinterp, dsPtr\fR)
44
.SH ARGUMENTS
45
.AS Tcl_DString newLength
46
.AP Tcl_DString *dsPtr in/out
47
Pointer to structure that is used to manage a dynamic string.
48
.AP char *string in
49
Pointer to characters to add to dynamic string.
50
.AP int length in
51
Number of characters from string to add to dynamic string.  If -1,
52
add all characters up to null terminating character.
53
.AP int newLength in
54
New length for dynamic string, not including null terminating
55
character.
56
.AP Tcl_Interp *interp in/out
57
Interpreter whose result is to be set from or moved to the
58
dynamic string.
59
.BE
60
 
61
.SH DESCRIPTION
62
.PP
63
Dynamic strings provide a mechanism for building up arbitrarily long
64
strings by gradually appending information.  If the dynamic string is
65
short then there will be no memory allocation overhead;  as the string
66
gets larger, additional space will be allocated as needed.
67
.PP
68
\fBTcl_DStringInit\fR initializes a dynamic string to zero length.
69
The Tcl_DString structure must have been allocated by the caller.
70
No assumptions are made about the current state of the structure;
71
anything already in it is discarded.
72
If the structure has been used previously, \fBTcl_DStringFree\fR should
73
be called first to free up any memory allocated for the old
74
string.
75
.PP
76
\fBTcl_DStringAppend\fR adds new information to a dynamic string,
77
allocating more memory for the string if needed.
78
If \fIlength\fR is less than zero then everything in \fIstring\fR
79
is appended to the dynamic string;  otherwise \fIlength\fR
80
specifies the number of bytes to append.
81
\fBTcl_DStringAppend\fR returns a pointer to the characters of
82
the new string.  The string can also be retrieved from the
83
\fIstring\fR field of the Tcl_DString structure.
84
.PP
85
\fBTcl_DStringAppendElement\fR is similar to \fBTcl_DStringAppend\fR
86
except that it doesn't take a \fIlength\fR argument (it appends
87
all of \fIstring\fR) and it converts the string to a proper list element
88
before appending.
89
\fBTcl_DStringAppendElement\fR adds a separator space before the
90
new list element unless the new list element is the first in a
91
list or sub-list (i.e. either the current string is empty, or it
92
contains the single character ``{'', or the last two characters of
93
the current string are `` {'').
94
\fBTcl_DStringAppendElement\fR returns a pointer to the
95
characters of the new string.
96
.PP
97
\fBTcl_DStringStartSublist\fR and \fBTcl_DStringEndSublist\fR can be
98
used to create nested lists.
99
To append a list element that is itself a sublist, first
100
call \fBTcl_DStringStartSublist\fR, then call \fBTcl_DStringAppendElement\fR
101
for each of the elements in the sublist, then call
102
\fBTcl_DStringEndSublist\fR to end the sublist.
103
\fBTcl_DStringStartSublist\fR appends a space character if needed,
104
followed by an open brace;  \fBTcl_DStringEndSublist\fR appends
105
a close brace.
106
Lists can be nested to any depth.
107
.PP
108
\fBTcl_DStringLength\fR is a macro that returns the current length
109
of a dynamic string (not including the terminating null character).
110
\fBTcl_DStringValue\fR is a  macro that returns a pointer to the
111
current contents of a dynamic string.
112
.PP
113
.PP
114
\fBTcl_DStringSetLength\fR changes the length of a dynamic string.
115
If \fInewLength\fR is less than the string's current length, then
116
the string is truncated.
117
If \fInewLength\fR is greater than the string's current length,
118
then the string will become longer and new space will be allocated
119
for the string if needed.
120
However, \fBTcl_DStringSetLength\fR will not initialize the new
121
space except to provide a terminating null character;  it is up to the
122
caller to fill in the new space.
123
\fBTcl_DStringSetLength\fR does not free up the string's storage space
124
even if the string is truncated to zero length, so \fBTcl_DStringFree\fR
125
will still need to be called.
126
.PP
127
\fBTcl_DStringFree\fR should be called when you're finished using
128
the string.  It frees up any memory that was allocated for the string
129
and reinitializes the string's value to an empty string.
130
.PP
131
\fBTcl_DStringResult\fR sets the result of \fIinterp\fR to the value of
132
the dynamic string given by \fIdsPtr\fR.  It does this by moving
133
a pointer from \fIdsPtr\fR to \fIinterp->result\fR.
134
This saves the cost of allocating new memory and copying the string.
135
\fBTcl_DStringResult\fR also reinitializes the dynamic string to
136
an empty string.
137
.PP
138
\fBTcl_DStringGetResult\fR does the opposite of \fBTcl_DStringResult\fR.
139
It sets the value of \fIdsPtr\fR to the result of \fIinterp\fR and
140
it clears \fIinterp\fR's result.
141
If possible it does this by moving a pointer rather than by copying
142
the string.
143
 
144
.SH KEYWORDS
145
append, dynamic string, free, result

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.