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 | #include "extern.h" |
31 | |
32 | PUBLIC char * |
33 | DmStrJoin( src, data, n, fr ) |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | char *src; |
43 | char *data; |
44 | int n; |
45 | int fr; |
46 | { |
47 | char *t; |
48 | int l; |
49 | int flag = FALSE0; |
50 | |
51 | DB_ENTER( "DmStrJoin" ); |
52 | |
53 | if( src == NIL(char)((char*)((void*)0)) ) { src = ""; flag = TRUE1; } |
54 | if( data == NIL(char)((char*)((void*)0)) ) data = ""; |
55 | DB_PRINT( "str", ("Joining [%s] [%s] %d", src, data, n) ); |
56 | |
57 | if( n == -1 ) n = strlen( data ); |
58 | |
59 | l = strlen( src ) + n + 1; |
60 | if( (t = MALLOC( l, char )(char*) malloc((unsigned int)(l)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0)) ) No_ram(); |
61 | |
62 | strcpy( t, src ); |
63 | if (n) strncat( t, data, n ); |
64 | t[ l-1 ] = '\0'; |
65 | |
66 | if( !flag && fr ) FREE( src )free((char*)(src)); |
67 | |
68 | DB_PRINT( "str", ("Result [%s]", t) ); |
69 | DB_RETURN( t )return (t); |
70 | } |
71 | |
72 | |
73 | |
74 | |
75 | PUBLIC char * |
76 | DmStrAdd( src, data, fr ) |
77 | |
78 | |
79 | |
80 | |
81 | char *src; |
82 | char *data; |
83 | int fr; |
84 | { |
85 | char *t; |
86 | int l; |
87 | int sflag; |
88 | int dflag; |
89 | |
90 | DB_ENTER( "DmStrAdd" ); |
91 | |
92 | sflag = dflag = fr; |
93 | |
94 | if( src == NIL(char)((char*)((void*)0)) ) { src = ""; sflag = FALSE0; } |
95 | if( data == NIL(char)((char*)((void*)0)) ) { data = ""; dflag = FALSE0; } |
96 | DB_PRINT( "str", ("Adding [%s] [%s] %d", src, data, fr) ); |
97 | |
98 | l = strlen(src) + strlen(data) + 1; |
99 | if( *src ) l++; |
100 | |
101 | if( (t = MALLOC( l, char )(char*) malloc((unsigned int)(l)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0)) ) No_ram(); |
102 | |
103 | strcpy( t, src ); |
104 | |
105 | if( *data ) |
106 | { |
107 | if( *src ) strcat( t, " " ); |
108 | strcat( t, data ); |
109 | } |
110 | |
111 | if( sflag ) FREE( src )free((char*)(src)); |
112 | if( dflag ) FREE( data )free((char*)(data)); |
113 | |
114 | DB_PRINT( "str", ("Result [%s]", t) ); |
115 | DB_RETURN( t )return (t); |
116 | } |
117 | |
118 | |
119 | |
120 | PUBLIC char * |
121 | DmStrApp( src1, src2 ) |
122 | |
123 | |
124 | |
125 | |
126 | char *src1; |
127 | char *src2; |
128 | { |
129 | src2 = DmStrAdd( src1, src2, FALSE0 ); |
130 | if( src1 != NIL(char)((char*)((void*)0)) ) FREE( src1 )free((char*)(src1)); |
131 | return( src2 ); |
132 | } |
133 | |
134 | |
135 | PUBLIC char * |
136 | DmStrDup( str ) |
137 | |
138 | char *str; |
139 | { |
140 | char *t; |
141 | |
142 | if( str == NIL(char)((char*)((void*)0)) ) return( NIL(char)((char*)((void*)0)) ); |
143 | |
144 | if( (t = MALLOC( strlen( str )+1, char )(char*) malloc((unsigned int)(strlen( str )+1)*(size_t)sizeof (char))) == NIL(char)((char*)((void*)0)) ) No_ram(); |
145 | strcpy( t, str ); |
146 | |
147 | return( t ); |
148 | } |
149 | |
150 | |
151 | |
152 | PUBLIC char * |
153 | DmStrDup2( str ) |
154 | |
155 | |
156 | |
157 | |
158 | char *str; |
159 | { |
160 | char *t; |
161 | size_t size; |
162 | size_t alloced; |
163 | char *tmp; |
164 | char *dest; |
165 | int seen_equal = 0; |
166 | |
167 | if(str == NIL(char)((char*)((void*)0))) return(NIL(char)((char*)((void*)0))); |
| |
168 | size = strlen(str) + 1; |
169 | alloced = size + 2; |
170 | |
171 | for(tmp = str; *tmp; tmp++) |
| 2 | | Loop condition is true. Entering loop body | |
|
| 4 | | Loop condition is false. Execution continues on line 175 | |
|
172 | if(*tmp == '"') |
| |
173 | alloced++; |
174 | |
175 | if((t = MALLOC(alloced, char)(char*) malloc((unsigned int)(alloced)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0))) No_ram(); |
| |
176 | |
177 | for(tmp = str, dest = t; *tmp; tmp++, dest++) { |
| 6 | | Null pointer value stored to 'dest' | |
|
| 7 | | Loop condition is true. Entering loop body | |
|
178 | if(*tmp == '=' && !seen_equal) { |
179 | seen_equal = 1; |
180 | *dest++ = *tmp; |
181 | *dest = '"'; |
182 | continue; |
183 | } |
184 | if(*tmp == '"') |
| |
185 | *dest++ = '\\'; |
186 | *dest = *tmp; |
| 9 | | Dereference of null pointer (loaded from variable 'dest') |
|
187 | } |
188 | |
189 | if(!seen_equal) |
190 | Fatal("DmStrDup2 invoked without argument of form x=y\n"); |
191 | |
192 | *dest++ = '"'; |
193 | *dest = 0; |
194 | |
195 | return t; |
196 | } |
197 | |
198 | |
199 | |
200 | PUBLIC char * |
201 | DmStrPbrk( s1, s2 ) |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | char *s1; |
208 | char *s2; |
209 | { |
210 | register char *t; |
211 | |
212 | if( s1 == NIL(char)((char*)((void*)0)) || s2 == NIL(char)((char*)((void*)0)) ) return( "" ); |
213 | |
214 | for( t=s1; *t && (strchr( s2, *t ) == NIL(char)((char*)((void*)0))); t++ ); |
215 | return( t ); |
216 | } |
217 | |
218 | |
219 | |
220 | |
221 | PUBLIC char * |
222 | DmStrSpn( s1, s2 ) |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | char *s1; |
229 | char *s2; |
230 | { |
231 | register char *t; |
232 | |
233 | if( s1 == NIL(char)((char*)((void*)0)) || s2 == NIL(char)((char*)((void*)0)) ) return( "" ); |
234 | |
235 | for( t=s1; *t && (strchr( s2, *t ) != NIL(char)((char*)((void*)0))); t++ ); |
236 | return( t ); |
237 | } |
238 | |
239 | |
240 | |
241 | |
242 | PUBLIC char * |
243 | DmStrStr( s1, s2 ) |
244 | |
245 | char *s1; |
246 | char *s2; |
247 | { |
248 | register char *s; |
249 | register char *p; |
250 | register char *r; |
251 | |
252 | if( s1 != NIL(char)((char*)((void*)0)) && s2 != NIL(char)((char*)((void*)0)) ) |
253 | for( s=s1; *s; s++ ) |
254 | if( *s == *s2 ) |
255 | { |
256 | for( r=s+1, p = s2+1; *p && (*r == *p); r++, p++ ); |
257 | if( !*p ) return( s ); |
258 | } |
259 | |
260 | return( NIL(char)((char*)((void*)0)) ); |
261 | } |
262 | |
263 | |
264 | |
265 | PUBLIC char * |
266 | DmSubStr( s, e ) |
267 | |
268 | |
269 | |
270 | |
271 | |
272 | char *s; |
273 | char *e; |
274 | { |
275 | char save; |
276 | int len = e-s; |
277 | |
278 | if( len < 0 || len > strlen(s) ) |
279 | Fatal( "Internal Error: SubStr fails consistency test" ); |
280 | |
281 | save = *e; |
282 | *e = '\0'; |
283 | s = DmStrDup( s ); |
284 | *e = save; |
285 | |
286 | return( s ); |
287 | } |
288 | |
289 | |
290 | |
291 | #ifndef HAVE_STRLWR |
292 | char * |
293 | strlwr(char *s) |
294 | { |
295 | char *p; |
296 | for(p=s; *p; p++ ) |
297 | *p = tolower(*p); |
298 | return s; |
299 | } |
300 | #endif |