4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * C++ Demangler Source Code
47 * This code emulates the C++ String package
54 * This function will expand the space
55 * available to a String so that more data
56 * can be appended to it
63 int sz
= s
->sg
.max
* 2;
66 if ((ns
= (String
*)malloc(sz
+ sizeof (StringGuts
) + 1)) == NULL
)
68 (void) memcpy(ns
, s
, s
->sg
.max
+ sizeof (StringGuts
) + 1);
71 if ((ns
= (String
*)realloc(s
, sz
+ sizeof (StringGuts
) + 1)) == NULL
)
79 * This function will expand the space
80 * available to a String so that more data
81 * can be prepended to it.
89 while (s
->sg
.end
+ n
> s
->sg
.max
)
93 assert(s
->sg
.end
>= s
->sg
.start
);
94 (void) memmove(s
->data
+ n
, s
->data
, s
->sg
.end
- s
->sg
.start
);
98 for (i
= s
->sg
.end
- 1; i
>= s
->sg
.start
; i
--)
99 s
->data
[i
+n
] = s
->data
[i
];
104 s
->data
[s
->sg
.end
] = 0;
109 * This function will prepend c
117 return (nprep_String(c
, s
, ID_NAME_MAX
));
121 * This function will prepend the
122 * first n characters of c to s
125 nprep_String(c
, s
, n
)
134 if (len
> s
->sg
.start
)
135 s
= ror(s
, len
- s
->sg
.start
);
137 (void) memcpy(s
->data
+ s
->sg
.start
, c
, len
);
142 * This function will append
150 return (napp_String(s
, c
, ID_NAME_MAX
));
154 * This function will append the
155 * first n characters of c to s
158 napp_String(String
*s
, const char *c
, int n
)
165 catlen
= s
->sg
.end
+ len
;
166 while (catlen
> s
->sg
.max
)
168 (void) memcpy(s
->data
+ s
->sg
.end
, c
, len
);
170 s
->data
[s
->sg
.end
] = '\0';
175 * This function initializes a
176 * String. It returns its argument if
177 * its argument is non-zero.
178 * This prevents the same string
179 * from being re-initialized.
187 s
= (String
*)malloc(STRING_START
+ sizeof (StringGuts
) + 1);
190 s
->sg
.start
= s
->sg
.end
= STRING_START
/2;
191 s
->sg
.max
= STRING_START
;
192 s
->data
[s
->sg
.end
] = '\0';
205 * This function copies
207 * Used for initialization.
214 int len
= strlen(c
)*2;
215 while (len
> s
->sg
.max
)
217 s
->sg
.start
= s
->sg
.end
= s
->sg
.max
/ 2;
218 s
= app_String(s
, c
);
223 * Chop n characters off the end of a string.
224 * Return the truncated string.
227 trunc_String(String
*s
, int n
)
229 assert(n
<= s
->sg
.end
- s
->sg
.start
);
231 s
->data
[s
->sg
.end
] = '\0';