Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: third_party/libxml/src/list.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/libxml2-config.cmake.in ('k') | third_party/libxml/src/ltmain.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * list.c: lists handling implementation 2 * list.c: lists handling implementation
3 * 3 *
4 * Copyright (C) 2000 Gary Pennington and Daniel Veillard. 4 * Copyright (C) 2000 Gary Pennington and Daniel Veillard.
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 /** 88 /**
89 * xmlListLowerSearch: 89 * xmlListLowerSearch:
90 * @l: a list 90 * @l: a list
91 * @data: a data 91 * @data: a data
92 * 92 *
93 * Search data in the ordered list walking from the beginning 93 * Search data in the ordered list walking from the beginning
94 * 94 *
95 * Returns the link containing the data or NULL 95 * Returns the link containing the data or NULL
96 */ 96 */
97 static xmlLinkPtr 97 static xmlLinkPtr
98 xmlListLowerSearch(xmlListPtr l, void *data) 98 xmlListLowerSearch(xmlListPtr l, void *data)
99 { 99 {
100 xmlLinkPtr lk; 100 xmlLinkPtr lk;
101 101
102 if (l == NULL) 102 if (l == NULL)
103 return(NULL); 103 return(NULL);
104 for(lk = l->sentinel->next;lk != l->sentinel && l->linkCompare(lk->data, dat a) <0 ;lk = lk->next); 104 for(lk = l->sentinel->next;lk != l->sentinel && l->linkCompare(lk->data, dat a) <0 ;lk = lk->next);
105 return lk; 105 return lk;
106 } 106 }
107 107
108 /** 108 /**
109 * xmlListHigherSearch: 109 * xmlListHigherSearch:
110 * @l: a list 110 * @l: a list
111 * @data: a data 111 * @data: a data
112 * 112 *
113 * Search data in the ordered list walking backward from the end 113 * Search data in the ordered list walking backward from the end
114 * 114 *
115 * Returns the link containing the data or NULL 115 * Returns the link containing the data or NULL
116 */ 116 */
117 static xmlLinkPtr 117 static xmlLinkPtr
118 xmlListHigherSearch(xmlListPtr l, void *data) 118 xmlListHigherSearch(xmlListPtr l, void *data)
119 { 119 {
120 xmlLinkPtr lk; 120 xmlLinkPtr lk;
121 121
122 if (l == NULL) 122 if (l == NULL)
123 return(NULL); 123 return(NULL);
124 for(lk = l->sentinel->prev;lk != l->sentinel && l->linkCompare(lk->data, dat a) >0 ;lk = lk->prev); 124 for(lk = l->sentinel->prev;lk != l->sentinel && l->linkCompare(lk->data, dat a) >0 ;lk = lk->prev);
125 return lk; 125 return lk;
126 } 126 }
127 127
128 /** 128 /**
129 * xmlListSearch: 129 * xmlListSearch:
130 * @l: a list 130 * @l: a list
131 * @data: a data 131 * @data: a data
132 * 132 *
133 * Search data in the list 133 * Search data in the list
134 * 134 *
135 * Returns the link containing the data or NULL 135 * Returns the link containing the data or NULL
136 */ 136 */
137 static xmlLinkPtr 137 static xmlLinkPtr
138 xmlListLinkSearch(xmlListPtr l, void *data) 138 xmlListLinkSearch(xmlListPtr l, void *data)
139 { 139 {
140 xmlLinkPtr lk; 140 xmlLinkPtr lk;
141 if (l == NULL) 141 if (l == NULL)
142 return(NULL); 142 return(NULL);
143 lk = xmlListLowerSearch(l, data); 143 lk = xmlListLowerSearch(l, data);
144 if (lk == l->sentinel) 144 if (lk == l->sentinel)
145 return NULL; 145 return NULL;
146 else { 146 else {
147 if (l->linkCompare(lk->data, data) ==0) 147 if (l->linkCompare(lk->data, data) ==0)
148 return lk; 148 return lk;
149 return NULL; 149 return NULL;
150 } 150 }
151 } 151 }
152 152
153 /** 153 /**
154 * xmlListLinkReverseSearch: 154 * xmlListLinkReverseSearch:
155 * @l: a list 155 * @l: a list
156 * @data: a data 156 * @data: a data
157 * 157 *
158 * Search data in the list processing backward 158 * Search data in the list processing backward
159 * 159 *
160 * Returns the link containing the data or NULL 160 * Returns the link containing the data or NULL
161 */ 161 */
162 static xmlLinkPtr 162 static xmlLinkPtr
163 xmlListLinkReverseSearch(xmlListPtr l, void *data) 163 xmlListLinkReverseSearch(xmlListPtr l, void *data)
164 { 164 {
165 xmlLinkPtr lk; 165 xmlLinkPtr lk;
166 if (l == NULL) 166 if (l == NULL)
167 return(NULL); 167 return(NULL);
168 lk = xmlListHigherSearch(l, data); 168 lk = xmlListHigherSearch(l, data);
169 if (lk == l->sentinel) 169 if (lk == l->sentinel)
170 return NULL; 170 return NULL;
171 else { 171 else {
172 if (l->linkCompare(lk->data, data) ==0) 172 if (l->linkCompare(lk->data, data) ==0)
173 return lk; 173 return lk;
174 return NULL; 174 return NULL;
175 } 175 }
176 } 176 }
177 177
178 /** 178 /**
179 * xmlListCreate: 179 * xmlListCreate:
180 * @deallocator: an optional deallocator function 180 * @deallocator: an optional deallocator function
181 * @compare: an optional comparison function 181 * @compare: an optional comparison function
182 * 182 *
183 * Create a new list 183 * Create a new list
184 * 184 *
185 * Returns the new list or NULL in case of error 185 * Returns the new list or NULL in case of error
186 */ 186 */
187 xmlListPtr 187 xmlListPtr
188 xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare) 188 xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare)
189 { 189 {
190 xmlListPtr l; 190 xmlListPtr l;
191 if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList)))) { 191 if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList)))) {
192 xmlGenericError(xmlGenericErrorContext, 192 xmlGenericError(xmlGenericErrorContext,
193 "Cannot initialize memory for list"); 193 "Cannot initialize memory for list");
194 return (NULL); 194 return (NULL);
195 } 195 }
196 /* Initialize the list to NULL */ 196 /* Initialize the list to NULL */
197 memset(l, 0, sizeof(xmlList)); 197 memset(l, 0, sizeof(xmlList));
198 198
199 /* Add the sentinel */ 199 /* Add the sentinel */
200 if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { 200 if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) {
201 xmlGenericError(xmlGenericErrorContext, 201 xmlGenericError(xmlGenericErrorContext,
202 "Cannot initialize memory for sentinel"); 202 "Cannot initialize memory for sentinel");
203 xmlFree(l); 203 xmlFree(l);
204 return (NULL); 204 return (NULL);
205 } 205 }
206 l->sentinel->next = l->sentinel; 206 l->sentinel->next = l->sentinel;
207 l->sentinel->prev = l->sentinel; 207 l->sentinel->prev = l->sentinel;
208 l->sentinel->data = NULL; 208 l->sentinel->data = NULL;
209 209
210 /* If there is a link deallocator, use it */ 210 /* If there is a link deallocator, use it */
211 if (deallocator != NULL) 211 if (deallocator != NULL)
212 l->linkDeallocator = deallocator; 212 l->linkDeallocator = deallocator;
213 /* If there is a link comparator, use it */ 213 /* If there is a link comparator, use it */
214 if (compare != NULL) 214 if (compare != NULL)
215 l->linkCompare = compare; 215 l->linkCompare = compare;
216 else /* Use our own */ 216 else /* Use our own */
217 l->linkCompare = xmlLinkCompare; 217 l->linkCompare = xmlLinkCompare;
218 return l; 218 return l;
219 } 219 }
220 220
221 /** 221 /**
222 * xmlListSearch: 222 * xmlListSearch:
223 * @l: a list 223 * @l: a list
224 * @data: a search value 224 * @data: a search value
225 * 225 *
226 * Search the list for an existing value of @data 226 * Search the list for an existing value of @data
227 * 227 *
228 * Returns the value associated to @data or NULL in case of error 228 * Returns the value associated to @data or NULL in case of error
229 */ 229 */
230 void * 230 void *
231 xmlListSearch(xmlListPtr l, void *data) 231 xmlListSearch(xmlListPtr l, void *data)
232 { 232 {
233 xmlLinkPtr lk; 233 xmlLinkPtr lk;
234 if (l == NULL) 234 if (l == NULL)
235 return(NULL); 235 return(NULL);
236 lk = xmlListLinkSearch(l, data); 236 lk = xmlListLinkSearch(l, data);
237 if (lk) 237 if (lk)
238 return (lk->data); 238 return (lk->data);
239 return NULL; 239 return NULL;
240 } 240 }
241 241
242 /** 242 /**
243 * xmlListReverseSearch: 243 * xmlListReverseSearch:
244 * @l: a list 244 * @l: a list
245 * @data: a search value 245 * @data: a search value
246 * 246 *
247 * Search the list in reverse order for an existing value of @data 247 * Search the list in reverse order for an existing value of @data
248 * 248 *
249 * Returns the value associated to @data or NULL in case of error 249 * Returns the value associated to @data or NULL in case of error
250 */ 250 */
251 void * 251 void *
252 xmlListReverseSearch(xmlListPtr l, void *data) 252 xmlListReverseSearch(xmlListPtr l, void *data)
253 { 253 {
254 xmlLinkPtr lk; 254 xmlLinkPtr lk;
255 if (l == NULL) 255 if (l == NULL)
256 return(NULL); 256 return(NULL);
257 lk = xmlListLinkReverseSearch(l, data); 257 lk = xmlListLinkReverseSearch(l, data);
258 if (lk) 258 if (lk)
259 return (lk->data); 259 return (lk->data);
260 return NULL; 260 return NULL;
261 } 261 }
262 262
263 /** 263 /**
264 * xmlListInsert: 264 * xmlListInsert:
265 * @l: a list 265 * @l: a list
266 * @data: the data 266 * @data: the data
267 * 267 *
268 * Insert data in the ordered list at the beginning for this value 268 * Insert data in the ordered list at the beginning for this value
269 * 269 *
270 * Returns 0 in case of success, 1 in case of failure 270 * Returns 0 in case of success, 1 in case of failure
271 */ 271 */
272 int 272 int
273 xmlListInsert(xmlListPtr l, void *data) 273 xmlListInsert(xmlListPtr l, void *data)
274 { 274 {
275 xmlLinkPtr lkPlace, lkNew; 275 xmlLinkPtr lkPlace, lkNew;
276 276
277 if (l == NULL) 277 if (l == NULL)
278 return(1); 278 return(1);
279 lkPlace = xmlListLowerSearch(l, data); 279 lkPlace = xmlListLowerSearch(l, data);
280 /* Add the new link */ 280 /* Add the new link */
281 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); 281 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
282 if (lkNew == NULL) { 282 if (lkNew == NULL) {
283 xmlGenericError(xmlGenericErrorContext, 283 xmlGenericError(xmlGenericErrorContext,
284 "Cannot initialize memory for new link"); 284 "Cannot initialize memory for new link");
285 return (1); 285 return (1);
286 } 286 }
287 lkNew->data = data; 287 lkNew->data = data;
288 lkPlace = lkPlace->prev; 288 lkPlace = lkPlace->prev;
289 lkNew->next = lkPlace->next; 289 lkNew->next = lkPlace->next;
290 (lkPlace->next)->prev = lkNew; 290 (lkPlace->next)->prev = lkNew;
291 lkPlace->next = lkNew; 291 lkPlace->next = lkNew;
292 lkNew->prev = lkPlace; 292 lkNew->prev = lkPlace;
293 return 0; 293 return 0;
294 } 294 }
295 295
296 /** 296 /**
297 * xmlListAppend: 297 * xmlListAppend:
298 * @l: a list 298 * @l: a list
299 * @data: the data 299 * @data: the data
300 * 300 *
301 * Insert data in the ordered list at the end for this value 301 * Insert data in the ordered list at the end for this value
302 * 302 *
303 * Returns 0 in case of success, 1 in case of failure 303 * Returns 0 in case of success, 1 in case of failure
304 */ 304 */
305 int xmlListAppend(xmlListPtr l, void *data) 305 int xmlListAppend(xmlListPtr l, void *data)
306 { 306 {
307 xmlLinkPtr lkPlace, lkNew; 307 xmlLinkPtr lkPlace, lkNew;
308 308
309 if (l == NULL) 309 if (l == NULL)
310 return(1); 310 return(1);
311 lkPlace = xmlListHigherSearch(l, data); 311 lkPlace = xmlListHigherSearch(l, data);
312 /* Add the new link */ 312 /* Add the new link */
313 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); 313 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
314 if (lkNew == NULL) { 314 if (lkNew == NULL) {
315 xmlGenericError(xmlGenericErrorContext, 315 xmlGenericError(xmlGenericErrorContext,
316 "Cannot initialize memory for new link"); 316 "Cannot initialize memory for new link");
317 return (1); 317 return (1);
318 } 318 }
319 lkNew->data = data; 319 lkNew->data = data;
320 lkNew->next = lkPlace->next; 320 lkNew->next = lkPlace->next;
321 (lkPlace->next)->prev = lkNew; 321 (lkPlace->next)->prev = lkNew;
322 lkPlace->next = lkNew; 322 lkPlace->next = lkNew;
323 lkNew->prev = lkPlace; 323 lkNew->prev = lkPlace;
324 return 0; 324 return 0;
325 } 325 }
(...skipping 20 matching lines...) Expand all
346 * @data: list data 346 * @data: list data
347 * 347 *
348 * Remove the first instance associated to data in the list 348 * Remove the first instance associated to data in the list
349 * 349 *
350 * Returns 1 if a deallocation occured, or 0 if not found 350 * Returns 1 if a deallocation occured, or 0 if not found
351 */ 351 */
352 int 352 int
353 xmlListRemoveFirst(xmlListPtr l, void *data) 353 xmlListRemoveFirst(xmlListPtr l, void *data)
354 { 354 {
355 xmlLinkPtr lk; 355 xmlLinkPtr lk;
356 356
357 if (l == NULL) 357 if (l == NULL)
358 return(0); 358 return(0);
359 /*Find the first instance of this data */ 359 /*Find the first instance of this data */
360 lk = xmlListLinkSearch(l, data); 360 lk = xmlListLinkSearch(l, data);
361 if (lk != NULL) { 361 if (lk != NULL) {
362 xmlLinkDeallocator(l, lk); 362 xmlLinkDeallocator(l, lk);
363 return 1; 363 return 1;
364 } 364 }
365 return 0; 365 return 0;
366 } 366 }
367 367
368 /** 368 /**
369 * xmlListRemoveLast: 369 * xmlListRemoveLast:
370 * @l: a list 370 * @l: a list
371 * @data: list data 371 * @data: list data
372 * 372 *
373 * Remove the last instance associated to data in the list 373 * Remove the last instance associated to data in the list
374 * 374 *
375 * Returns 1 if a deallocation occured, or 0 if not found 375 * Returns 1 if a deallocation occured, or 0 if not found
376 */ 376 */
377 int 377 int
378 xmlListRemoveLast(xmlListPtr l, void *data) 378 xmlListRemoveLast(xmlListPtr l, void *data)
379 { 379 {
380 xmlLinkPtr lk; 380 xmlLinkPtr lk;
381 381
382 if (l == NULL) 382 if (l == NULL)
383 return(0); 383 return(0);
384 /*Find the last instance of this data */ 384 /*Find the last instance of this data */
385 lk = xmlListLinkReverseSearch(l, data); 385 lk = xmlListLinkReverseSearch(l, data);
386 if (lk != NULL) { 386 if (lk != NULL) {
387 xmlLinkDeallocator(l, lk); 387 xmlLinkDeallocator(l, lk);
388 return 1; 388 return 1;
389 } 389 }
390 return 0; 390 return 0;
391 } 391 }
392 392
393 /** 393 /**
394 * xmlListRemoveAll: 394 * xmlListRemoveAll:
395 * @l: a list 395 * @l: a list
396 * @data: list data 396 * @data: list data
397 * 397 *
398 * Remove the all instance associated to data in the list 398 * Remove the all instance associated to data in the list
399 * 399 *
400 * Returns the number of deallocation, or 0 if not found 400 * Returns the number of deallocation, or 0 if not found
401 */ 401 */
402 int 402 int
403 xmlListRemoveAll(xmlListPtr l, void *data) 403 xmlListRemoveAll(xmlListPtr l, void *data)
404 { 404 {
405 int count=0; 405 int count=0;
406 406
407 if (l == NULL) 407 if (l == NULL)
408 return(0); 408 return(0);
409 409
410 while(xmlListRemoveFirst(l, data)) 410 while(xmlListRemoveFirst(l, data))
411 count++; 411 count++;
412 return count; 412 return count;
413 } 413 }
414 414
415 /** 415 /**
416 * xmlListClear: 416 * xmlListClear:
417 * @l: a list 417 * @l: a list
418 * 418 *
419 * Remove the all data in the list 419 * Remove the all data in the list
420 */ 420 */
421 void 421 void
422 xmlListClear(xmlListPtr l) 422 xmlListClear(xmlListPtr l)
423 { 423 {
424 xmlLinkPtr lk; 424 xmlLinkPtr lk;
425 425
426 if (l == NULL) 426 if (l == NULL)
427 return; 427 return;
428 lk = l->sentinel->next; 428 lk = l->sentinel->next;
429 while(lk != l->sentinel) { 429 while(lk != l->sentinel) {
430 xmlLinkPtr next = lk->next; 430 xmlLinkPtr next = lk->next;
431 431
432 xmlLinkDeallocator(l, lk); 432 xmlLinkDeallocator(l, lk);
433 lk = next; 433 lk = next;
434 } 434 }
435 } 435 }
(...skipping 15 matching lines...) Expand all
451 } 451 }
452 452
453 /** 453 /**
454 * xmlListFront: 454 * xmlListFront:
455 * @l: a list 455 * @l: a list
456 * 456 *
457 * Get the first element in the list 457 * Get the first element in the list
458 * 458 *
459 * Returns the first element in the list, or NULL 459 * Returns the first element in the list, or NULL
460 */ 460 */
461 xmlLinkPtr 461 xmlLinkPtr
462 xmlListFront(xmlListPtr l) 462 xmlListFront(xmlListPtr l)
463 { 463 {
464 if (l == NULL) 464 if (l == NULL)
465 return(NULL); 465 return(NULL);
466 return (l->sentinel->next); 466 return (l->sentinel->next);
467 } 467 }
468 468
469 /** 469 /**
470 * xmlListEnd: 470 * xmlListEnd:
471 * @l: a list 471 * @l: a list
472 * 472 *
473 * Get the last element in the list 473 * Get the last element in the list
474 * 474 *
475 * Returns the last element in the list, or NULL 475 * Returns the last element in the list, or NULL
476 */ 476 */
477 xmlLinkPtr 477 xmlLinkPtr
478 xmlListEnd(xmlListPtr l) 478 xmlListEnd(xmlListPtr l)
479 { 479 {
480 if (l == NULL) 480 if (l == NULL)
481 return(NULL); 481 return(NULL);
482 return (l->sentinel->prev); 482 return (l->sentinel->prev);
483 } 483 }
484 484
485 /** 485 /**
486 * xmlListSize: 486 * xmlListSize:
487 * @l: a list 487 * @l: a list
488 * 488 *
489 * Get the number of elements in the list 489 * Get the number of elements in the list
490 * 490 *
491 * Returns the number of elements in the list or -1 in case of error 491 * Returns the number of elements in the list or -1 in case of error
492 */ 492 */
493 int 493 int
494 xmlListSize(xmlListPtr l) 494 xmlListSize(xmlListPtr l)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 /** 532 /**
533 * xmlListPushFront: 533 * xmlListPushFront:
534 * @l: a list 534 * @l: a list
535 * @data: new data 535 * @data: new data
536 * 536 *
537 * add the new data at the beginning of the list 537 * add the new data at the beginning of the list
538 * 538 *
539 * Returns 1 if successful, 0 otherwise 539 * Returns 1 if successful, 0 otherwise
540 */ 540 */
541 int 541 int
542 xmlListPushFront(xmlListPtr l, void *data) 542 xmlListPushFront(xmlListPtr l, void *data)
543 { 543 {
544 xmlLinkPtr lkPlace, lkNew; 544 xmlLinkPtr lkPlace, lkNew;
545 545
546 if (l == NULL) 546 if (l == NULL)
547 return(0); 547 return(0);
548 lkPlace = l->sentinel; 548 lkPlace = l->sentinel;
549 /* Add the new link */ 549 /* Add the new link */
550 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); 550 lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
551 if (lkNew == NULL) { 551 if (lkNew == NULL) {
552 xmlGenericError(xmlGenericErrorContext, 552 xmlGenericError(xmlGenericErrorContext,
553 "Cannot initialize memory for new link"); 553 "Cannot initialize memory for new link");
554 return (0); 554 return (0);
555 } 555 }
556 lkNew->data = data; 556 lkNew->data = data;
557 lkNew->next = lkPlace->next; 557 lkNew->next = lkPlace->next;
558 (lkPlace->next)->prev = lkNew; 558 (lkPlace->next)->prev = lkNew;
559 lkPlace->next = lkNew; 559 lkPlace->next = lkNew;
560 lkNew->prev = lkPlace; 560 lkNew->prev = lkPlace;
561 return 1; 561 return 1;
562 } 562 }
563 563
564 /** 564 /**
565 * xmlListPushBack: 565 * xmlListPushBack:
566 * @l: a list 566 * @l: a list
567 * @data: new data 567 * @data: new data
568 * 568 *
569 * add the new data at the end of the list 569 * add the new data at the end of the list
570 * 570 *
571 * Returns 1 if successful, 0 otherwise 571 * Returns 1 if successful, 0 otherwise
572 */ 572 */
573 int 573 int
574 xmlListPushBack(xmlListPtr l, void *data) 574 xmlListPushBack(xmlListPtr l, void *data)
575 { 575 {
576 xmlLinkPtr lkPlace, lkNew; 576 xmlLinkPtr lkPlace, lkNew;
577 577
578 if (l == NULL) 578 if (l == NULL)
579 return(0); 579 return(0);
580 lkPlace = l->sentinel->prev; 580 lkPlace = l->sentinel->prev;
581 /* Add the new link */ 581 /* Add the new link */
582 if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { 582 if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) {
583 xmlGenericError(xmlGenericErrorContext, 583 xmlGenericError(xmlGenericErrorContext,
584 "Cannot initialize memory for new link"); 584 "Cannot initialize memory for new link");
585 return (0); 585 return (0);
586 } 586 }
587 lkNew->data = data; 587 lkNew->data = data;
588 lkNew->next = lkPlace->next; 588 lkNew->next = lkPlace->next;
589 (lkPlace->next)->prev = lkNew; 589 (lkPlace->next)->prev = lkNew;
590 lkPlace->next = lkNew; 590 lkPlace->next = lkNew;
591 lkNew->prev = lkPlace; 591 lkNew->prev = lkPlace;
592 return 1; 592 return 1;
593 } 593 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 /** 636 /**
637 * xmlListSort: 637 * xmlListSort:
638 * @l: a list 638 * @l: a list
639 * 639 *
640 * Sort all the elements in the list 640 * Sort all the elements in the list
641 */ 641 */
642 void 642 void
643 xmlListSort(xmlListPtr l) 643 xmlListSort(xmlListPtr l)
644 { 644 {
645 xmlListPtr lTemp; 645 xmlListPtr lTemp;
646 646
647 if (l == NULL) 647 if (l == NULL)
648 return; 648 return;
649 if(xmlListEmpty(l)) 649 if(xmlListEmpty(l))
650 return; 650 return;
651 651
652 /* I think that the real answer is to implement quicksort, the 652 /* I think that the real answer is to implement quicksort, the
653 * alternative is to implement some list copying procedure which 653 * alternative is to implement some list copying procedure which
654 * would be based on a list copy followed by a clear followed by 654 * would be based on a list copy followed by a clear followed by
655 * an insert. This is slow... 655 * an insert. This is slow...
656 */ 656 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 { 718 {
719 xmlListCopy(l1, l2); 719 xmlListCopy(l1, l2);
720 xmlListClear(l2); 720 xmlListClear(l2);
721 } 721 }
722 722
723 /** 723 /**
724 * xmlListDup: 724 * xmlListDup:
725 * @old: the list 725 * @old: the list
726 * 726 *
727 * Duplicate the list 727 * Duplicate the list
728 * 728 *
729 * Returns a new copy of the list or NULL in case of error 729 * Returns a new copy of the list or NULL in case of error
730 */ 730 */
731 xmlListPtr 731 xmlListPtr
732 xmlListDup(const xmlListPtr old) 732 xmlListDup(const xmlListPtr old)
733 { 733 {
734 xmlListPtr cur; 734 xmlListPtr cur;
735 735
736 if (old == NULL) 736 if (old == NULL)
737 return(NULL); 737 return(NULL);
738 /* Hmmm, how to best deal with allocation issues when copying 738 /* Hmmm, how to best deal with allocation issues when copying
739 * lists. If there is a de-allocator, should responsibility lie with 739 * lists. If there is a de-allocator, should responsibility lie with
740 * the new list or the old list. Surely not both. I'll arbitrarily 740 * the new list or the old list. Surely not both. I'll arbitrarily
741 * set it to be the old list for the time being whilst I work out 741 * set it to be the old list for the time being whilst I work out
742 * the answer 742 * the answer
743 */ 743 */
744 if (NULL ==(cur = xmlListCreate(NULL, old->linkCompare))) 744 if (NULL ==(cur = xmlListCreate(NULL, old->linkCompare)))
745 return (NULL); 745 return (NULL);
746 if (0 != xmlListCopy(cur, old)) 746 if (0 != xmlListCopy(cur, old))
747 return NULL; 747 return NULL;
748 return cur; 748 return cur;
749 } 749 }
750 750
751 /** 751 /**
752 * xmlListCopy: 752 * xmlListCopy:
753 * @cur: the new list 753 * @cur: the new list
754 * @old: the old list 754 * @old: the old list
755 * 755 *
756 * Move all the element from the old list in the new list 756 * Move all the element from the old list in the new list
757 * 757 *
758 * Returns 0 in case of success 1 in case of error 758 * Returns 0 in case of success 1 in case of error
759 */ 759 */
760 int 760 int
761 xmlListCopy(xmlListPtr cur, const xmlListPtr old) 761 xmlListCopy(xmlListPtr cur, const xmlListPtr old)
762 { 762 {
763 /* Walk the old tree and insert the data into the new one */ 763 /* Walk the old tree and insert the data into the new one */
764 xmlLinkPtr lk; 764 xmlLinkPtr lk;
765 765
766 if ((old == NULL) || (cur == NULL)) 766 if ((old == NULL) || (cur == NULL))
767 return(1); 767 return(1);
768 for(lk = old->sentinel->next; lk != old->sentinel; lk = lk->next) { 768 for(lk = old->sentinel->next; lk != old->sentinel; lk = lk->next) {
769 if (0 !=xmlListInsert(cur, lk->data)) { 769 if (0 !=xmlListInsert(cur, lk->data)) {
770 xmlListDelete(cur); 770 xmlListDelete(cur);
771 return (1); 771 return (1);
772 } 772 }
773 } 773 }
774 return (0); 774 return (0);
775 } 775 }
776 /* xmlListUnique() */ 776 /* xmlListUnique() */
777 /* xmlListSwap */ 777 /* xmlListSwap */
778 #define bottom_list 778 #define bottom_list
779 #include "elfgcchack.h" 779 #include "elfgcchack.h"
OLDNEW
« no previous file with comments | « third_party/libxml/src/libxml2-config.cmake.in ('k') | third_party/libxml/src/ltmain.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698