Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
lists.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include "libavrdude.h"
+ Include dependency graph for lists.c:

Go to the source code of this file.

Classes

struct  LISTNODE
 
struct  NODEPOOL
 
struct  LIST
 

Macros

#define MAGIC   0xb05b05b0
 
#define CHECK_MAGIC   0 /* set to 1 to enable memory overwrite detection */
 
#define MALLOC(size, x)   malloc(size)
 
#define FREE   free
 
#define DEFAULT_POOLSIZE   512
 
#define CKMAGIC(p)
 
#define CKNPMAGIC(p)
 
#define CKLNMAGIC(p)
 
#define CKLMAGIC(p)
 

Typedefs

typedef struct LISTNODE LISTNODE
 
typedef struct NODEPOOL NODEPOOL
 
typedef struct LIST LIST
 

Functions

static int insert_ln (LIST *l, LISTNODE *ln, void *data_ptr)
 
static NODEPOOLnew_nodepool (LIST *l)
 
static LISTNODEget_listnode (LIST *l)
 
static int free_listnode (LIST *l, LISTNODE *ln)
 
LISTID lcreat (void *liststruct, int elements)
 
void ldestroy_cb (LISTID lid, void(*ucleanup)(void *data_ptr))
 
void ldestroy (LISTID lid)
 
int ladd (LISTID lid, void *p)
 
int laddo (LISTID lid, void *p, int(*compare)(const void *p1, const void *p2), LNODEID *firstdup)
 
int laddu (LISTID lid, void *p, int(*compare)(const void *p1, const void *p2))
 
LNODEID lfirst (LISTID lid)
 
LNODEID llast (LISTID lid)
 
LNODEID lnext (LNODEID lnid)
 
LNODEID lprev (LNODEID lnid)
 
voidldata (LNODEID lnid)
 
int lsize (LISTID lid)
 
LISTID lcat (LISTID lid1, LISTID lid2)
 
voidlget (LISTID lid)
 
voidlget_n (LISTID lid, unsigned int n)
 
LNODEID lget_ln (LISTID lid, unsigned int n)
 
int lins_n (LISTID lid, void *data_ptr, unsigned int n)
 
int lins_ln (LISTID lid, LNODEID lnid, void *data_ptr)
 
static voidremove_ln (LIST *l, LISTNODE *ln)
 
voidlrmv_d (LISTID lid, void *data_ptr)
 
voidlrmv_ln (LISTID lid, LNODEID lnid)
 
voidlrmv_n (LISTID lid, unsigned int n)
 
voidlrmv (LISTID lid)
 
voidlsrch (LISTID lid, void *p, int(*compare)(void *p1, void *p2))
 
void lsort (LISTID lid, int(*compare)(void *p1, void *p2))
 
int lprint (FILE *f, LISTID lid)
 

Class Documentation

◆ LISTNODE

struct LISTNODE
+ Collaboration diagram for LISTNODE:
Class Members
void * data
struct LISTNODE * next
struct LISTNODE * prev

◆ NODEPOOL

struct NODEPOOL
+ Collaboration diagram for NODEPOOL:
Class Members
struct NODEPOOL * chain_next
struct NODEPOOL * chain_prev

◆ LIST

struct LIST
+ Collaboration diagram for LIST:
Class Members
LISTNODE * bottom
short int free_on_close
int n_ln_pool
LISTNODE * next_ln
NODEPOOL * np_bottom
NODEPOOL * np_top
int num
short int poolsize
LISTNODE * top

Macro Definition Documentation

◆ CHECK_MAGIC

#define CHECK_MAGIC   0 /* set to 1 to enable memory overwrite detection */

◆ CKLMAGIC

#define CKLMAGIC (   p)

◆ CKLNMAGIC

#define CKLNMAGIC (   p)

◆ CKMAGIC

#define CKMAGIC (   p)

◆ CKNPMAGIC

#define CKNPMAGIC (   p)

◆ DEFAULT_POOLSIZE

#define DEFAULT_POOLSIZE   512

◆ FREE

#define FREE   free

◆ MAGIC

#define MAGIC   0xb05b05b0

◆ MALLOC

#define MALLOC (   size,
 
)    malloc(size)

Typedef Documentation

◆ LIST

typedef struct LIST LIST

◆ LISTNODE

typedef struct LISTNODE LISTNODE

◆ NODEPOOL

typedef struct NODEPOOL NODEPOOL

Function Documentation

◆ free_listnode()

static int free_listnode ( LIST l,
LISTNODE ln 
)
static
374{
375 CKLMAGIC(l);
376
377 /*--------------------------------------------------
378 | insert the list node at the head of the list of
379 | free list nodes.
380 --------------------------------------------------*/
381 ln->prev = NULL;
382 ln->data = NULL;
383 ln->next = l->next_ln;
384 l->next_ln = ln;
385
386 CKLMAGIC(l);
387
388 return 0;
389}
LISTNODE * next_ln
Definition lists.c:96
void * data
Definition lists.c:67
struct LISTNODE * prev
Definition lists.c:66
struct LISTNODE * next
Definition lists.c:65
#define CKLMAGIC(p)
Definition lists.c:125

References CKLMAGIC, LISTNODE::data, LISTNODE::next, LIST::next_ln, and LISTNODE::prev.

Referenced by remove_ln().

+ Here is the caller graph for this function:

◆ get_listnode()

static LISTNODE * get_listnode ( LIST l)
static
292{
293 LISTNODE * ln;
294 NODEPOOL * np;
295
296 CKLMAGIC(l);
297
298 if (l->next_ln == NULL) {
299 /*--------------------------------------------------
300 | allocate a new node pool and chain to the others
301 --------------------------------------------------*/
302 np = new_nodepool(l);
303 if (np == NULL) {
304 CKLMAGIC(l);
305 return NULL;
306 }
307
308 if (l->np_top == NULL) {
309 /*--------------------------------------------------
310 | this is the first node pool for this list,
311 | directly assign to the top and bottom.
312 --------------------------------------------------*/
313 l->np_top = np;
314 l->np_bottom = np;
315 np->chain_next = NULL;
316 np->chain_prev = NULL;
317 }
318 else {
319 /*--------------------------------------------------
320 | this is an additional node pool, add it to the
321 | chain.
322 --------------------------------------------------*/
323 np->chain_next = NULL;
324 np->chain_prev = l->np_bottom;
325 l->np_bottom->chain_next = np;
326 l->np_bottom = np;
327 }
328
329 /*--------------------------------------------------
330 | set the list's pointer to the next available
331 | list node to the first list node in this new
332 | pool.
333 --------------------------------------------------*/
334 l->next_ln = (LISTNODE *)&np[1];
335
336 CKMAGIC(np);
337 }
338
339 /*--------------------------------------------------
340 | get the next available list node, set the list's
341 | next available list node to the next one in the
342 | list.
343 --------------------------------------------------*/
344 ln = l->next_ln;
345 l->next_ln = ln->next;
346
347 CKMAGIC(ln);
348
349 /*--------------------------------------------------
350 | initialize the new list node and return
351 --------------------------------------------------*/
352 ln->next = NULL;
353 ln->prev = NULL;
354 ln->data = NULL;
355
356 CKLMAGIC(l);
357
358 return ln;
359}
NODEPOOL * np_bottom
Definition lists.c:98
struct NODEPOOL * chain_next
Definition lists.c:78
struct NODEPOOL * chain_prev
Definition lists.c:79
static NODEPOOL * new_nodepool(LIST *l)
Definition lists.c:205
NODEPOOL * np_top
Definition lists.c:97
#define CKMAGIC(p)
Definition lists.c:119
Definition lists.c:61
Definition lists.c:74

References NODEPOOL::chain_next, NODEPOOL::chain_prev, CKLMAGIC, CKMAGIC, LISTNODE::data, new_nodepool(), LISTNODE::next, LIST::next_ln, LIST::np_bottom, LIST::np_top, and LISTNODE::prev.

Referenced by insert_ln(), and ladd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert_ln()

static int insert_ln ( LIST l,
LISTNODE ln,
void data_ptr 
)
static
879{
880 LISTNODE * lnptr;
881
882 CKLMAGIC(l);
883
884 if (ln==NULL) {
885 ladd ( l, data_ptr );
886 CKLMAGIC(l);
887 return 0;
888 }
889
890 lnptr = get_listnode(l);
891 if (lnptr == NULL) {
892#ifdef BOS
893 breakpoint();
894#endif
895 return -1;
896 }
897
898 CKMAGIC(lnptr);
899
900 lnptr->data = data_ptr;
901
902 if (ln==l->top) {
903 /*------------------------------
904 | insert before the list head
905 ------------------------------*/
906 lnptr->next = ln;
907 lnptr->prev = NULL;
908 ln->prev = lnptr;
909 l->top = lnptr;
910 }
911 else if (ln==NULL) {
912 /*-----------------
913 | list was empty
914 -----------------*/
915 lnptr->next = NULL;
916 lnptr->prev = l->bottom;
917 l->bottom->next = lnptr;
918 l->bottom = lnptr;
919 }
920 else {
921 /*-----------------------------------
922 | insert in the middle of the list
923 -----------------------------------*/
924 lnptr->next = ln;
925 lnptr->prev = ln->prev;
926 lnptr->next->prev = lnptr;
927 lnptr->prev->next = lnptr;
928 }
929
930 l->num++;
931
932 CKLMAGIC(l);
933
934 return 0;
935}
int ladd(LISTID lid, void *p)
Definition lists.c:547
static LISTNODE * get_listnode(LIST *l)
Definition lists.c:291
LISTNODE * top
Definition lists.c:94
LISTNODE * bottom
Definition lists.c:95
int num
Definition lists.c:90

References LIST::bottom, CKLMAGIC, CKMAGIC, LISTNODE::data, get_listnode(), ladd(), LISTNODE::next, LIST::num, LISTNODE::prev, and LIST::top.

Referenced by laddo(), laddu(), lins_ln(), and lins_n().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ladd()

int ladd ( LISTID  lid,
void p 
)
548{
549 LIST * l;
550 LISTNODE *lnptr;
551
552 l = (LIST *)lid;
553
554 CKLMAGIC(l);
555
556 lnptr = get_listnode(l);
557 if (lnptr==NULL) {
558#ifdef BOS
559 breakpoint();
560#endif
561 return -1;
562 }
563
564 CKMAGIC(lnptr);
565
566 lnptr->data = p;
567
568 if (l->top == NULL) {
569 l->top = lnptr;
570 l->bottom = lnptr;
571 lnptr->next = NULL;
572 lnptr->prev = NULL;
573 }
574 else {
575 lnptr->prev = l->bottom;
576 lnptr->next = NULL;
577 l->bottom->next = lnptr;
578 l->bottom = lnptr;
579 }
580 l->num++;
581
582 CKLMAGIC(l);
583
584 return 0;
585}
Definition lists.c:86

References LIST::bottom, CKLMAGIC, CKMAGIC, LISTNODE::data, get_listnode(), LISTNODE::next, LIST::num, LISTNODE::prev, and LIST::top.

Referenced by avr_dup_part(), avrdude_main(), insert_ln(), jtag3_open_common(), laddo(), laddu(), lcat(), lins_n(), pgm_dup(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ laddo()

int laddo ( LISTID  lid,
void p,
int(*)(const void *p1, const void *p2)  compare,
LNODEID firstdup 
)
601{
602 LIST * l;
603 LISTNODE * ln;
604 int dup, cmp;
605
606 l = (LIST *)lid;
607
608 CKLMAGIC(l);
609
610 dup = 0;
611 ln = l->top;
612
613 while (ln!=NULL) {
614 CKMAGIC(ln);
615 cmp = compare(p,ln->data);
616 if (cmp == 0) {
617 dup = 1;
618 if (firstdup)
619 *firstdup = ln;
620 }
621 if (cmp < 0) {
622 insert_ln(l,ln,p);
623 CKLMAGIC(l);
624 return dup;
625 }
626 else {
627 ln = ln->next;
628 }
629 }
630
631 ladd(l,p);
632
633 CKLMAGIC(l);
634
635 return dup;
636}
static int insert_ln(LIST *l, LISTNODE *ln, void *data_ptr)
Definition lists.c:878

References CKLMAGIC, CKMAGIC, LISTNODE::data, insert_ln(), ladd(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ laddu()

int laddu ( LISTID  lid,
void p,
int(*)(const void *p1, const void *p2)  compare 
)
649{
650 LIST * l;
651 LISTNODE * ln;
652 int cmp;
653
654 l = (LIST *)lid;
655
656 CKLMAGIC(l);
657
658 ln = l->top;
659
660 while (ln!=NULL) {
661 CKMAGIC(ln);
662 cmp = compare(p,ln->data);
663 if (cmp == 0) {
664 CKLMAGIC(l);
665 return 0;
666 }
667 if (cmp < 0) {
668 insert_ln(l,ln,p);
669 CKLMAGIC(l);
670 return 1;
671 }
672 else {
673 ln = ln->next;
674 }
675 }
676
677 ladd(l,p);
678
679 CKLMAGIC(l);
680
681 return 1;
682}

References CKLMAGIC, CKMAGIC, LISTNODE::data, insert_ln(), ladd(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lcat()

LISTID lcat ( LISTID  lid1,
LISTID  lid2 
)
744{
745 CKLMAGIC(((LIST *)lid1));
746 CKLMAGIC(((LIST *)lid2));
747 while (lsize(lid2)) {
748 ladd ( lid1, lrmv_n(lid2,1) );
749 }
750
751 CKLMAGIC(((LIST *)lid1));
752 CKLMAGIC(((LIST *)lid2));
753
754 return lid1;
755}
int lsize(LISTID lid)
Definition lists.c:729
void * lrmv_n(LISTID lid, unsigned int n)
Definition lists.c:1186

References CKLMAGIC, ladd(), lrmv_n(), and lsize().

+ Here is the call graph for this function:

◆ lcreat()

LISTID lcreat ( void liststruct,
int  elements 
)
411{
412 LIST * l;
413
414 if (liststruct == NULL) {
415 /*--------------------------------------------------
416 allocate memory for the list itself
417 --------------------------------------------------*/
418 l = (LIST *) MALLOC ( sizeof(LIST), "list struct" );
419 if (l == NULL) {
420 return NULL;
421 }
422 l->free_on_close = 1;
423 }
424 else {
425 /*-----------------------------------------------------------------
426 use the memory given to us for the list structure
427 -----------------------------------------------------------------*/
428 l = liststruct;
429 l->free_on_close = 0;
430 }
431
432 /*--------------------------------------------------
433 | initialize the list
434 --------------------------------------------------*/
435#if CHECK_MAGIC
436 l->magic1 = MAGIC;
437 l->magic2 = MAGIC;
438#endif
439 l->top = NULL;
440 l->bottom = NULL;
441 l->num = 0;
442
443 if (elements == 0) {
445 }
446 else {
447 l->poolsize = (short)(elements*sizeof(LISTNODE)+sizeof(NODEPOOL));
448 }
449
450 l->n_ln_pool = (l->poolsize-sizeof(NODEPOOL))/sizeof(LISTNODE);
451
452 if (l->n_ln_pool < 5) {
453 if (!liststruct) {
454 FREE(l);
455 }
456 return NULL;
457 }
458
459 l->np_top = NULL;
460 l->np_bottom = NULL;
461 l->next_ln = NULL;
462
463 CKLMAGIC(l);
464
465 return (LISTID)l;
466}
void * LISTID
Definition libavrdude.h:63
short int poolsize
Definition lists.c:92
short int free_on_close
Definition lists.c:91
#define MALLOC(size, x)
Definition lists.c:53
int n_ln_pool
Definition lists.c:93
#define MAGIC
Definition lists.c:45
#define FREE
Definition lists.c:54
#define DEFAULT_POOLSIZE
Definition lists.c:106

References LIST::bottom, CKLMAGIC, DEFAULT_POOLSIZE, FREE, LIST::free_on_close, MAGIC, MALLOC, LIST::n_ln_pool, LIST::next_ln, LIST::np_bottom, LIST::np_top, LIST::num, LIST::poolsize, and LIST::top.

Referenced by avr_new_part(), avrdude_main(), init_config(), pgm_dup(), pgm_new(), and yyparse().

+ Here is the caller graph for this function:

◆ ldata()

◆ ldestroy()

void ldestroy ( LISTID  lid)
510{
511 LIST * l;
512 NODEPOOL * p1, * p2;
513
514 l = (LIST *)lid;
515
516 CKLMAGIC(l);
517
518 /*--------------------------------------------------
519 | free each node pool - start at the first node
520 | pool and free each successive until there are
521 | no more.
522 --------------------------------------------------*/
523 p1 = l->np_top;
524 while (p1 != NULL) {
525 p2 = p1->chain_next;
526 FREE(p1);
527 p1 = p2;
528 }
529
530 /*--------------------------------------------------
531 | now free the memory occupied by the list itself
532 --------------------------------------------------*/
533 if (l->free_on_close) {
534 FREE ( l );
535 }
536}

References NODEPOOL::chain_next, CKLMAGIC, FREE, LIST::free_on_close, and LIST::np_top.

Referenced by cleanup_main(), and ldestroy_cb().

+ Here is the caller graph for this function:

◆ ldestroy_cb()

void ldestroy_cb ( LISTID  lid,
void(*)(void *data_ptr)  ucleanup 
)
481{
482 LIST * l;
483 LISTNODE * ln;
484
485 l = (LIST *)lid;
486
487 CKLMAGIC(l);
488
489 ln = l->top;
490 while (ln != NULL) {
491 ucleanup ( ln->data );
492 ln = ln->next;
493 }
494
495 ldestroy ( l );
496}
void ldestroy(LISTID lid)
Definition lists.c:509

References CKLMAGIC, LISTNODE::data, ldestroy(), LISTNODE::next, and LIST::top.

Referenced by avr_free_part(), cleanup_config(), cleanup_main(), pgm_free(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lfirst()

◆ lget()

void * lget ( LISTID  lid)
767{
768 LIST * l;
769 LISTNODE * p;
770
771 l = (LIST *)lid;
772
773 CKLMAGIC(l);
774
775 p = l->bottom;
776
777 if (p == NULL) {
778 CKLMAGIC(l);
779 return NULL;
780 }
781 else {
782 CKLMAGIC(l);
783 return p->data;
784 }
785}

References LIST::bottom, CKLMAGIC, and LISTNODE::data.

◆ lget_ln()

LNODEID lget_ln ( LISTID  lid,
unsigned int  n 
)
838{
839 int i;
840 LIST * l;
841 LISTNODE * ln;
842
843 l = (LIST *)lid;
844
845 CKLMAGIC(l);
846
847 if ((n < 1) || (n > (unsigned)lsize(l))) {
848 return NULL;
849 }
850
851 ln = l->top;
852 i = 1;
853 while (i!=n) {
854 CKMAGIC(ln);
855 ln = ln->next;
856 i++;
857 }
858
859 CKLMAGIC(l);
860 return (LNODEID)ln;
861}
void * LNODEID
Definition libavrdude.h:64

References CKLMAGIC, CKMAGIC, lsize(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lget_n()

void * lget_n ( LISTID  lid,
unsigned int  n 
)
797{
798 int i;
799 LIST * l;
800 LISTNODE * ln;
801
802 l = (LIST *)lid;
803
804 CKLMAGIC(l);
805
806 if ((n < 1) || (n > (unsigned)lsize(l))) {
807 return NULL;
808 }
809
810 ln = l->top;
811 i = 1;
812 while (ln && (i!=n)) {
813 CKMAGIC(ln);
814 ln = ln->next;
815 i++;
816 }
817
818 if (ln) {
819 CKLMAGIC(l);
820 return ln->data;
821 }
822 else {
823 CKLMAGIC(l);
824 return NULL;
825 }
826}

References CKLMAGIC, CKMAGIC, LISTNODE::data, lsize(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lins_ln()

int lins_ln ( LISTID  lid,
LNODEID  lnid,
void data_ptr 
)
995{
996 LIST * l;
997 LISTNODE * ln;
998 LISTNODE * ln_ptr;
999
1000 l = (LIST *)lid;
1001 ln = (LISTNODE *)lnid;
1002
1003 CKLMAGIC(l);
1004
1005 CKMAGIC(ln);
1006
1007 /*-----------------------------------------
1008 | validate that ln is indeed in the list
1009 -----------------------------------------*/
1010 ln_ptr = l->top;
1011 while ((ln_ptr!=NULL)&&(ln_ptr!=ln)) {
1012 CKMAGIC(ln_ptr);
1013 ln_ptr = ln_ptr->next;
1014 }
1015
1016 if (ln_ptr == NULL) {
1017 CKLMAGIC(l);
1018 return -1;
1019 }
1020
1021 CKLMAGIC(l);
1022
1023 /*--------------------------------
1024 | insert the data into the list
1025 --------------------------------*/
1026 return insert_ln ( l, ln, data_ptr );
1027}

References CKLMAGIC, CKMAGIC, insert_ln(), LISTNODE::next, and LIST::top.

+ Here is the call graph for this function:

◆ lins_n()

int lins_n ( LISTID  lid,
void data_ptr,
unsigned int  n 
)
946{
947 int i;
948 LIST * l;
949 LISTNODE * ln;
950
951 l = (LIST *)lid;
952
953 CKLMAGIC(l);
954
955 if ((n < 1) || (n > (unsigned)(l->num+1))) {
956 return -1;
957 }
958
959 if (l->num == 0) {
960 return ladd ( lid, data_ptr );
961 }
962
963 /*----------------------------------
964 | locate the nth item in the list
965 ----------------------------------*/
966 ln = l->top;
967 i = 1;
968 while (ln && (i!=n)) {
969 CKMAGIC(ln);
970 ln = ln->next;
971 i++;
972 }
973
974 if (!ln) {
975 CKLMAGIC(l);
976 return -1;
977 }
978
979 CKLMAGIC(l);
980
981 /*-----------------------------------------
982 | insert before the nth item in the list
983 -----------------------------------------*/
984 return insert_ln ( l, ln, data_ptr );
985}

References CKLMAGIC, CKMAGIC, insert_ln(), ladd(), LISTNODE::next, LIST::num, and LIST::top.

+ Here is the call graph for this function:

◆ llast()

LNODEID llast ( LISTID  lid)
697{
698 CKLMAGIC(((LIST *)lid));
699 return ((LIST *)lid)->bottom;
700}

References CKLMAGIC.

◆ lnext()

◆ lprev()

LNODEID lprev ( LNODEID  lnid)
713{
714 CKMAGIC(((LISTNODE *)lnid));
715 return ((LISTNODE *)lnid)->prev;
716}

References CKMAGIC.

Referenced by Slic3r::take_ccw_limited(), and Slic3r::take_cw_limited().

+ Here is the caller graph for this function:

◆ lprint()

int lprint ( FILE *  f,
LISTID  lid 
)
1321{
1322 LIST * l;
1323 LISTNODE * ln;
1324 NODEPOOL * np;
1325 int count;
1326
1327 l = (LIST *)lid;
1328
1329 fprintf ( f, "list id %p internal data structures:\n",
1330 lid );
1331#if CHECK_MAGIC
1332 if ((l->magic1 != MAGIC) || (l->magic2 != MAGIC)) {
1333 fprintf ( f, " *** WARNING: LIST MAGIC IS CORRUPT ***\n" );
1334 }
1335 fprintf ( f,
1336 " magic1=0x%08x\n"
1337 " magic2=0x%08x\n",
1338 l->magic1, l->magic2 );
1339#endif
1340 fprintf ( f, " num f pool n_ln top bottom next_ln np_top np_bottom\n" );
1341 fprintf ( f, " ---- - ---- ---- ---------- ---------- ---------- ---------- ----------\n" );
1342 fprintf ( f, " %4d %1d %4d %4d %10p %10p %10p %10p %10p\n",
1343 l->num, l->free_on_close, l->poolsize, l->n_ln_pool,
1344 l->top, l->bottom,
1345 l->next_ln, l->np_top, l->np_bottom );
1346
1347
1348 fprintf ( f,
1349 " node pools:\n"
1350 " idx np magic1 next prev magic2\n"
1351 " ---- ---------- ---------- ---------- ---------- ----------\n" );
1352 count = 0;
1353 np = l->np_top;
1354 while (np != NULL) {
1355 count++;
1356 fprintf ( f, " %4d %10p 0x%08x %10p %10p 0x%08x\n",
1357 count, np,
1358#if CHECK_MAGIC
1359 np->magic1,
1360#else
1361 0,
1362#endif
1363 np->chain_next, np->chain_prev,
1364#if CHECK_MAGIC
1365 np->magic2
1366#else
1367 0
1368#endif
1369 );
1370 np = np->chain_next;
1371 }
1372
1373 if (f) {
1374 fprintf ( f,
1375 " list elements:\n"
1376 " n ln magic1 next prev data magic2\n"
1377 " ---- ---------- ---------- ---------- ---------- ---------- ----------\n" );
1378 count = 0;
1379 ln = l->top;
1380 while (ln != NULL) {
1381 count++;
1382 fprintf ( f, " %4d %10p %10x %10p %10p %10p %10x\n",
1383 count, ln,
1384#if CHECK_MAGIC
1385 ln->magic1,
1386#else
1387 0,
1388#endif
1389 ln->next, ln->prev, ln->data,
1390#if CHECK_MAGIC
1391 ln->magic2
1392#else
1393 0
1394#endif
1395 );
1396 ln = lnext(ln);
1397 }
1398 if (count != l->num) {
1399 fprintf ( f,
1400 " *** list count is not correct\n"
1401 " *** list id indicates %d, counted items = %d\n",
1402 l->num, count );
1403 }
1404 }
1405
1406 return 0;
1407}
LNODEID lnext(LNODEID lnid)
Definition lists.c:704
#define CHECK_MAGIC
Definition lists.c:47
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12

References LIST::bottom, NODEPOOL::chain_next, NODEPOOL::chain_prev, CHECK_MAGIC, LISTNODE::data, LIST::free_on_close, lnext(), MAGIC, LIST::n_ln_pool, LISTNODE::next, LIST::next_ln, LIST::np_bottom, LIST::np_top, LIST::num, LIST::poolsize, LISTNODE::prev, and LIST::top.

+ Here is the call graph for this function:

◆ lrmv()

void * lrmv ( LISTID  lid)
1227{
1228 LIST * l;
1229 LISTNODE * p;
1230
1231 l = (LIST *)lid;
1232
1233 CKLMAGIC(l);
1234
1235 p = l->bottom;
1236
1237 if (p == NULL) {
1238 CKLMAGIC(l);
1239 return NULL;
1240 }
1241 else {
1242 CKLMAGIC(l);
1243 return remove_ln ( l, p );
1244 }
1245}
static void * remove_ln(LIST *l, LISTNODE *ln)
Definition lists.c:1042

References LIST::bottom, CKLMAGIC, and remove_ln().

+ Here is the call graph for this function:

◆ lrmv_d()

void * lrmv_d ( LISTID  lid,
void data_ptr 
)
1112{
1113 LIST * l;
1114 LISTNODE * ln;
1115 int i;
1116
1117 l = (LIST *)lid;
1118
1119 CKLMAGIC(l);
1120
1121 i = 0;
1122 ln = l->top;
1123 while (ln && (ln->data != data_ptr)) {
1124 i++;
1125 CKMAGIC(ln);
1126 ln = ln->next;
1127 }
1128
1129 if (ln == NULL) {
1130 CKLMAGIC(l);
1131 return NULL;
1132 }
1133 else {
1134 CKLMAGIC(l);
1135 return remove_ln ( l, ln );
1136 }
1137}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, remove_ln(), and LIST::top.

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lrmv_ln()

void * lrmv_ln ( LISTID  lid,
LNODEID  lnid 
)
1149{
1150 LIST * l;
1151 LISTNODE * ln;
1152 LISTNODE * p;
1153
1154 l = (LIST *)lid;
1155 ln = (LISTNODE *)lnid;
1156
1157 CKLMAGIC(l);
1158
1159 CKMAGIC(ln);
1160
1161 p = l->top;
1162 while ((p!=NULL)&&(p!=ln)) {
1163 CKMAGIC(p);
1164 p = p->next;
1165 }
1166
1167 if (p==NULL) {
1168 CKLMAGIC(l);
1169 return NULL;
1170 }
1171 else {
1172 CKLMAGIC(l);
1173 return remove_ln ( l, p );
1174 }
1175}

References CKLMAGIC, CKMAGIC, LISTNODE::next, remove_ln(), and LIST::top.

+ Here is the call graph for this function:

◆ lrmv_n()

void * lrmv_n ( LISTID  lid,
unsigned int  n 
)
1187{
1188 int i;
1189 LIST * l;
1190 LISTNODE * ln;
1191
1192 l = (LIST *)lid;
1193
1194 CKLMAGIC(l);
1195
1196 if ((n < 1) || (n > (unsigned)l->num)) {
1197 return NULL;
1198 }
1199
1200 ln = l->top;
1201 i = 1;
1202 while (ln && (i!=n)) {
1203 CKMAGIC(ln);
1204 ln = ln->next;
1205 i++;
1206 }
1207
1208 if (ln) {
1209 CKLMAGIC(l);
1210 return remove_ln ( l, ln );
1211 }
1212 else {
1213 CKLMAGIC(l);
1214 return NULL;
1215 }
1216}

References CKLMAGIC, CKMAGIC, LISTNODE::next, LIST::num, remove_ln(), and LIST::top.

Referenced by assign_pin_list(), lcat(), parse_cmdbits(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lsize()

int lsize ( LISTID  lid)
730{
731 CKLMAGIC(((LIST *)lid));
732 return ((LIST *)lid)->num;
733}

References CKLMAGIC.

Referenced by assign_pin_list(), avrdude_main(), lcat(), lget_ln(), lget_n(), parse_cmdbits(), and yyparse().

+ Here is the caller graph for this function:

◆ lsort()

void lsort ( LISTID  lid,
int(*)(void *p1, void *p2)  compare 
)
1290{
1291 LIST * l;
1292 LISTNODE * lt; /* this */
1293 LISTNODE * ln; /* next */
1294 int unsorted = 1;
1295
1296 l = (LIST *)lid;
1297
1298 CKLMAGIC(l);
1299
1300 while(unsorted){
1301 lt = l->top;
1302 unsorted = 0;
1303 while (lt!=NULL) {
1304 CKMAGIC(lt);
1305 ln = lt->next;
1306 if (ln!= NULL && compare(lt->data,ln->data) > 0) {
1307 void * p = ln->data;
1308 ln->data = lt->data;
1309 lt->data = p;
1310 unsorted = 1;
1311 }
1312 lt = ln;
1313 }
1314 }
1315
1316 CKLMAGIC(l);
1317}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, and LIST::top.

Referenced by sort_avrparts(), and sort_programmers().

+ Here is the caller graph for this function:

◆ lsrch()

void * lsrch ( LISTID  lid,
void p,
int(*)(void *p1, void *p2)  compare 
)
1257{
1258 LIST * l;
1259 LISTNODE * ln;
1260
1261 l = (LIST *)lid;
1262
1263 CKLMAGIC(l);
1264
1265 ln = l->top;
1266
1267 while (ln!=NULL) {
1268 CKMAGIC(ln);
1269 if (compare(p,ln->data) == 0) {
1270 CKLMAGIC(l);
1271 return ln->data;
1272 }
1273 else {
1274 ln = ln->next;
1275 }
1276 }
1277
1278 CKLMAGIC(l);
1279 return NULL;
1280}

References CKLMAGIC, CKMAGIC, LISTNODE::data, LISTNODE::next, and LIST::top.

◆ new_nodepool()

static NODEPOOL * new_nodepool ( LIST l)
static
206{
207 NODEPOOL * np;
208 LISTNODE * ln;
209 int i;
210
211 CKLMAGIC(l);
212
213 /*--------------------------------------------------
214 | get a block of memory for the new pool
215 --------------------------------------------------*/
216 np = (NODEPOOL *) MALLOC ( l->poolsize, "list node pool" );
217 if (np == NULL) {
218 return NULL;
219 }
220
221 /*--------------------------------------------------
222 | initialize the chaining information at the
223 | beginning of the pool.
224 --------------------------------------------------*/
225#if CHECK_MAGIC
226 np->magic1 = MAGIC;
227#endif
228 np->chain_next = NULL;
229 np->chain_prev = NULL;
230#if CHECK_MAGIC
231 np->magic2 = MAGIC;
232#endif
233
234 /*--------------------------------------------------
235 | initialize all the list nodes within the node
236 | pool, which begin just after the NODEPOOL
237 | structure at the beginning of the memory block
238 --------------------------------------------------*/
239 ln = (LISTNODE *) (&np[1]);
240
241#if CHECK_MAGIC
242 ln[0].magic1 = MAGIC;
243#endif
244 ln[0].data = NULL;
245 ln[0].next = &ln[1];
246 ln[0].prev = NULL;
247#if CHECK_MAGIC
248 ln[0].magic2 = MAGIC;
249#endif
250
251 for (i=1; i<l->n_ln_pool-1; i++) {
252#if CHECK_MAGIC
253 ln[i].magic1 = MAGIC;
254#endif
255 ln[i].data = NULL;
256 ln[i].next = &ln[i+1];
257 ln[i].prev = &ln[i-1];
258#if CHECK_MAGIC
259 ln[i].magic2 = MAGIC;
260#endif
261 }
262
263#if CHECK_MAGIC
264 ln[l->n_ln_pool-1].magic1 = MAGIC;
265#endif
266 ln[l->n_ln_pool-1].data = NULL;
267 ln[l->n_ln_pool-1].next = NULL;
268 ln[l->n_ln_pool-1].prev = &ln[l->n_ln_pool-2];
269#if CHECK_MAGIC
270 ln[l->n_ln_pool-1].magic2 = MAGIC;
271#endif
272
273 CKMAGIC(np);
274
275 CKLMAGIC(l);
276
277 return np;
278}

References NODEPOOL::chain_next, NODEPOOL::chain_prev, CKLMAGIC, CKMAGIC, LISTNODE::data, MAGIC, MALLOC, LIST::n_ln_pool, LISTNODE::next, LIST::poolsize, and LISTNODE::prev.

Referenced by get_listnode().

+ Here is the caller graph for this function:

◆ remove_ln()

static void * remove_ln ( LIST l,
LISTNODE ln 
)
static
1043{
1044 void * r;
1045
1046 CKLMAGIC(l);
1047
1048 CKMAGIC(ln);
1049
1050 if (ln==l->top) {
1051 /*------------------------------
1052 | remove the head of the list
1053 ------------------------------*/
1054 l->top = ln->next;
1055 if (l->top != NULL) {
1056 l->top->prev = NULL;
1057 }
1058 else {
1059 /*----------------------------------------
1060 | this was the only item in the list
1061 ----------------------------------------*/
1062 l->bottom = NULL;
1063 }
1064 }
1065 else if (ln==l->bottom) {
1066 /*------------------------------
1067 | remove the tail of the list
1068 ------------------------------*/
1069 l->bottom = ln->prev;
1070 if (l->bottom != NULL) {
1071 l->bottom->next = NULL;
1072 }
1073 }
1074 else {
1075 /*-------------------------------------
1076 | remove from the middle of the list
1077 -------------------------------------*/
1078 ln->prev->next = ln->next;
1079 ln->next->prev = ln->prev;
1080 }
1081
1082 /*-----------------------------
1083 | prepare to return the data
1084 -----------------------------*/
1085 r = ln->data;
1086
1087 /*-----------------------------------------------
1088 | free the listnode for re-use
1089 -----------------------------------------------*/
1090 free_listnode(l,ln);
1091
1092 /*------------------------------------
1093 | adjust the item count of the list
1094 ------------------------------------*/
1095 l->num--;
1096
1097 CKLMAGIC(l);
1098
1099 return r;
1100}
static int free_listnode(LIST *l, LISTNODE *ln)
Definition lists.c:373

References LIST::bottom, CKLMAGIC, CKMAGIC, LISTNODE::data, free_listnode(), LISTNODE::next, LIST::num, LISTNODE::prev, and LIST::top.

Referenced by lrmv(), lrmv_d(), lrmv_ln(), and lrmv_n().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: