FOSSology  4.4.0
Open Source License Compliance by Open Source Software
list.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2006-2013 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 /* Equivalent to core nomos v1.10 */
7 
20 #include "nomos.h"
21 #include "list.h"
22 #include "util.h"
23 
24 #define DFL_STARTSIZE 100
25 
26 static int strCompare(item_t *, item_t *);
27 static int strIcaseCompare(item_t *, item_t *);
28 static int strCompareBasename(item_t *, item_t *);
29 static int valCompareDsc(item_t *, item_t *);
30 static int valCompareAsc(item_t *, item_t *);
31 static int bufCompare(item_t *, item_t *);
32 static void listDoubleSize(list_t *);
33 static void listValidate(list_t *, int);
34 
35 #if defined(PROC_TRACE) || defined(LIST_DEBUG)
36 static void listDebugDetails();
37 #endif /* PROC_TRACE || LIST_DEBUG */
38 
54 void listInit(list_t *l, int size, char *label) {
55 
56 #ifdef PROC_TRACE
57  traceFunc("== listInit(%p, %d, \"%s\")\n", l, size, label);
58 #endif /* PROC_TRACE */
59 
60  if (l == NULL_LIST) {
61  LOG_FATAL("listInit: List @ %p is NULL", l)
62  Bail(-__LINE__);
63  }
64  if (label == NULL_STR) {
65  LOG_FATAL("no name for list @ %p", l)
66  Bail(-__LINE__);
67  }
68  if (strlen(label) > sizeof(l->name)) {
69  LOG_FATAL("List name \"%s\" too long", label)
70  Bail(-__LINE__);
71  }
72  if (l->name != label) (void) strcpy(l->name, label);
73  if (size == 0) {
74 #ifdef LIST_DEBUG
75  printf("LIST: (%p) initialize %s to %d elements\n", l,
76  l->name, DFL_STARTSIZE);
77 #endif /* LIST_DEBUG */
78  l->size = DFL_STARTSIZE; /* default start */
79  l->items = (item_t *)memAlloc(l->size*(int)sizeof(item_t),
80  l->name);
81  }
82 #ifdef QA_CHECKS
83  else if (size != l->size) {
84  Assert(NO, "%s: specified reset size %d != list size %d",
85  l->name, size, l->size);
86  }
87 #endif /* QA_CHECKS */
88  else {
89 #ifdef LIST_DEBUG
90  printf("LIST: reset %d elements in \"%s\" (%d bytes)\n",
91  l->size, l->name, l->size*sizeof(item_t));
92 #endif /* LIST_DEBUG */
93  memset(l->items, 0, l->size*sizeof(item_t));
94  }
95  l->used = 0;
96  l->ix = -1;
97  l->sorted = UNSORTED;
98  return;
99 }
100 
106 void listClear(list_t *l, int deallocFlag) {
107  item_t *p;
108  int i;
109 
110 #if defined(PROC_TRACE) /* || defined(UNPACK_DEBUG) */
111  traceFunc("== listClear(%p, %s)\n", l,
112  deallocFlag ? "DEALLOC" : "NOTOUCH");
113  listDebugDetails(l);
114 #endif /* PROC_TRACE || UNPACK_DEBUG */
115 
116  if (l == NULL_LIST) {
117 #ifdef LIST_DEBUG
118  printf("%% clear NULL list\n");
119 #endif /* LIST_DEBUG */
120  return;
121  }
122 
123  if (l->size == 0) {
124 #ifdef LIST_DEBUG
125  printf("%% clear empty list \"%s\"\n", l->name);
126 #endif /* LIST_DEBUG */
127  return;
128  }
129 #ifdef LIST_DEBUG
130  listDump(l, YES);
131 #endif /* LIST_DEBUG */
132 
133 #ifdef GLOBAL_DEBUG
134  if (gl.MEM_DEEBUG) {
135  printf("... used %d size %d ix %d sorted %d items %p\n",
136  l->used, l->size, l->ix, l->sorted, l->items);
137  }
138 #endif /* GLOBAL_DEBUG */
139  if (l->used) {
140  if (l->items == NULL_ITEM) {
141  Assert(NO, "%s: used/size %d/%d with null data",
142  l->name, l->used, l->size);
143  }
144 #ifdef LIST_DEBUG
145  printf("LIST: clearing %s, used entries == %d\n", l->name,
146  l->used);
147 #endif /* LIST_DEBUG */
148 #ifdef GLOBAL_DEBUG
149  if (gl.MEM_DEEBUG) {
150  printf("LIST: clearing %s, used entries == %d\n",
151  l->name, l->used);
152  }
153 #endif /* GLOBAL_DEBUG */
154  for (p = l->items, i = 0; i < l->used; i++, p++) {
155  if (p->str != NULL_STR) {
156 #ifdef GLOBAL_DEBUG
157  if (gl.MEM_DEEBUG) {
158  printf("FREE %p items[%d].str %p\n",
159  l, i, p->str);
160  }
161 #endif /* GLOBAL_DEBUG */
162  memFree((void *) p->str, MTAG_LISTKEY);
163  p->str = NULL_STR;
164  }
165  if (p->buf != NULL_STR) {
166 #ifdef GLOBAL_DEBUG
167  if (gl.MEM_DEEBUG) {
168  printf("... FREE %p items[%d].buf %p\n",
169  l, i, p->buf);
170  }
171 #endif /* GLOBAL_DEBUG */
172  memFree((void *) p->buf, MTAG_LISTBUF);
173  p->buf = NULL_STR;
174  }
175  p->buf = NULL_STR;
176  p->val = p->val2 = p->val3 = 0;
177  }
178 #ifdef GLOBAL_DEBUG
179  if (gl.MEM_DEEBUG) {
180  printf("INIT %s...\n", l->name);
181  }
182 #endif /* GLOBAL_DEBUG */
183  listInit(l, l->size, l->name);
184  }
185 #ifdef GLOBAL_DEBUG
186  if (gl.MEM_DEEBUG) {
187  printf("... dealloc %p \"items\" %p\n", l, l->items);
188  }
189 #endif /* GLOBAL_DEBUG */
190  if (deallocFlag && l->size) {
191  memFree(l->items, "list items");
192  l->size = 0;
193  }
194 #ifdef GLOBAL_DEBUG
195  if (gl.MEM_DEEBUG) {
196  printf("LIST: %s is cleared!\n", l->name);
197  }
198 #endif /* GLOBAL_DEBUG */
199  return;
200 }
201 
207 void listValidate(list_t *l, int appendFlag) {
208  if (l == NULL_LIST) {
209  LOG_FATAL("listValidate: null list!")
210  Bail(-__LINE__);
211  }
217  if (l->size == 0) {
218  LOG_FATAL("List (%s) @ %p not initialized", l->name, l)
219  Bail(-__LINE__);
220  }
221  if (l->items == NULL_ITEM) {
222  Assert(NO, "List (%s) @ %p has no data", l->name, l);
223  }
224  if (appendFlag) {
225  if (l->size == l->used) {
226  listDoubleSize(l);
227  }
228  }
229  return;
230 }
231 
232 
246 item_t *listGetItem(list_t *l, char *s) {
247  item_t *p;
248  int i;
249  int x;
250 
251 #ifdef PROC_TRACE
252  traceFunc("== listGetItem(%p, \"%s\")\n", l, s);
253  listDebugDetails(l);
254 #endif /* PROC_TRACE */
255 
256  listValidate(l, YES); /* assume/setup for an 'add' */
257  if (s == NULL_STR) {
258  Assert(NO, "listGetItem: Null string to insert!");
259  }
260  if (l->sorted && l->sorted != SORT_BY_NAME) {
261  LOG_FATAL("%s is sorted other than by-name (%d)", l->name, l->sorted)
262  Bail(-__LINE__);
263  }
264  else if (l->used == 0) {
265  l->sorted = SORT_BY_NAME;
266  }
267  /*
268  * Now we KNOW we have at least one opening in the list; see if the
269  * requested string already exists in the list
270  */
275  for (p = l->items, i = 0; i < l->used; i++, p++) {
276 #ifdef LIST_DEBUG
277  printf("%p: check i = %d, used = %d, size = %d\n", l, i, l->used,
278  l->size);
279 #endif /* LIST_DEBUG */
280  if ((x = strcmp(s, p->str)) == 0) {
281  return (p);
282  }
283  else if (x < 0) { /* e.g., not in list */
284  break; /* add new list entry */
285  }
286  } /* for */
287 #ifdef LIST_DEBUG
288  printf("listGetItem: new entry @%d (size %d, max %d)\n", i,
289  l->used, l->size);
290 #endif /* LIST_DEBUG */
291  if (i != l->used) { /* make room in 'middle' of list */
292  (void) memmove(l->items+i+1, l->items+i, (l->used-i)*sizeof(*p));
293  }
294  (l->used)++;
295  p->str = copyString(s, MTAG_SORTKEY);
296  p->buf = NULL_STR;
297  p->val = 0;
298  p->val2 = 0;
299  p->val3 = 0;
300 #ifdef LIST_DEBUG
301  printf("ADDING: insert %s @%d, \"used\" now == %d, Cache (listDump):\n",
302  p->str, i, l->used);
303  listDump(l, NO);
304 #endif /* LIST_DEBUG */
305  return (p);
306 }
307 
314 item_t *listAppend(list_t *l, char *s) {
315  item_t *p; /* computed return value */
316 
317 #ifdef PROC_TRACE
318  traceFunc("== listAppend(%p, \"%s\")\n", l, s);
319  listDebugDetails(l);
320 #endif /* PROC_TRACE */
321 
322  listValidate(l, YES);
323  if (s == NULL_STR) {
324  Assert(NO, "listAppend: Null string to insert!");
325  }
326  /*
327  * Now we know we have a valid list with enough room to add one more
328  * element; simply insert it at the end, increment the 'used' counter
329  * and get outta Dodge.
330  */
331  p = &l->items[l->used++];
333  p->buf = NULL_STR;
334  p->val = p->val2 = p->val3 = 0;
335  return (p);
336 }
337 
338 #ifdef notdef
347 /*
348  CDB -- From comment above, we could probably get rid of this. #ifdef'd
349  out for now.
350  */
351 item_t *listLookupName(list_t *l, char *s)
352 {
353  item_t *p; /* computed return value */
354  int i;
355  int match;
356 
357 #if defined(PROC_TRACE)
358 #ifdef PROC_TRACE_SWITCH
359  if (gl.ptswitch) {
360 #endif /* PROC_TRACE_SWITCH */
361  printf("== listLookupName(%p, \"%s\")\n", l, s);
362  listDebugDetails(l);
363 #ifdef PROC_TRACE_SWITCH
364  }
365 #endif /* PROC_TRACE_SWITCH */
366 #endif /* PROC_TRACE */
367 
368 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
369  listValidate(l, NO);
370  if (s == NULL_STR) {
371  Assert(NO, "lookupName: Null key for lookup!");
372  return(NULL_ITEM);
373  }
374 #endif /* QA_CHECKS || LIST_DEBUG */
375  /*
376  * Now we know we have a valid list with enough room to add one more
377  * element; simply insert it at the end, increment the 'used' counter
378  * and get outta Dodge.
379  */
380  if (l->sorted != SORT_BY_NAME && l->sorted != 0) {
381  LOG_FATAL("Improper sort-type %d for %s name-lookup", l->sorted, l->name)
382  Bail(-__LINE__);
383  }
384  /*
385  * Walk through the sorted-by-name list and exit when we're done.
386  * This function could be called during a loop (while(listIterate(&list)))
387  * and we DON'T want to mess up the 'ix' field for this list!
388  */
389  for (i = 0; i < l->used; i++) {
390  if (l->items[i].str == NULL_STR) {
391  Assert(NO, "%s[%d] is NULL!", l->name, i);
392  continue;
393  }
394  match = strcmp(s, l->items[i].str);
395  if (match == 0) {
396  return(&(l->items[i]));
397  }
398  else if (match < 0) { /* e.g., cannnot be in list */
399  break;
400  }
401  }
402  return(NULL_ITEM);
403 }
404 #endif /* notdef */
405 
406 #ifdef notdef
407 /*
408  * Look up an element in a list based on it's alias (buf) value and
409  * return NULL if not found.
410  *****
411  * NOTE: the list MUST be of sort-type SORT_BY_ALIAS for this to be valid.
412  *****
413  * This is a general-purpose utility; often it's required to look up a
414  * specific value based on an item's alias.
415  */
416 item_t *listLookupAlias(list_t *l, char *s)
417 {
418  item_t *p; /* computed return value */
419  int i;
420  int x;
421 
422 #if defined(PROC_TRACE)
423 #ifdef PROC_TRACE_SWITCH
424  if (gl.ptswitch) {
425 #endif /* PROC_TRACE_SWITCH */
426  printf("== listLookupAlias(%p, \"%s\")\n", l, s);
427  listDebugDetails(l);
428 #ifdef PROC_TRACE_SWITCH
429  }
430 #endif /* PROC_TRACE_SWITCH */
431 #endif /* PROC_TRACE */
432 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
433  listValidate(l, NO);
434  if (s == NULL_STR) {
435  Assert(NO, "lookupAlias: Null key for lookup!");
436  }
437 #endif /* QA_CHECKS || LIST_DEBUG */
438  /*
439  * Now we know we have a valid list with enough room to add one more
440  * element; simply insert it at the end, increment the 'used' counter
441  * and get outta Dodge.
442  */
443  if (l->sorted != SORT_BY_ALIAS) {
444  LOG_FATAL("Improper sort-type %d for %s alias-lookup", l->sorted, l->name)
445  Bail(-__LINE__);
446  }
447  /*
448  * Walk through the sorted-by-alias list and exit when we're done.
449  * Do NOT use listIterate() or we could mess up the 'ix' field!
450  */
451  for (i = 0, p = l->items; i < l->used; i++, p++) {
452  if (p->buf == NULL_STR) {
453  Assert(NO, "%s[%d] is NULL!", l->name, i);
454  continue;
455  }
456  if ((x = strcmp(s, p->buf)) == 0) {
457  return(p);
458  }
459  else if (x < 0) { /* e.g., not in list */
460  break;
461  }
462  }
463  return(NULL_ITEM);
464 }
465 #endif /* notdef */
466 
478 
479  item_t *p;
480 
481 #ifdef LIST_DEBUG /* was PROC_TRACE */
482  traceFunc("== listIterate(%p) -- %s (ix %d, used %d)\n", l, l->name,
483  l->ix, l->used);
484  listDebugDetails(l);
485 #endif /* LIST_DEBUG, oh-so-formerly-PROC_TRACE */
486 
487 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
488  listValidate(l, NO);
489  if (l->used == 0) { /* empty list? */
490  return(NULL_ITEM);
491  }
492 #endif /* QA_CHECKS || LIST_DEBUG */
493  l->ix++;
494 
495  if (l->ix == l->used) {
496 #ifdef LIST_DEBUG
497  Assert(NO, "End-of-list: %s", l->name);
498 #endif /* LIST_DEBUG */
499  l->ix = -1;
500  return (NULL_ITEM);
501  } else if ((l->ix > l->used) || (l->ix < 0)) {
502  LOG_FATAL("Index %d out of bounds (%d) on %s", l->ix, l->used, l->name)
503  Bail(-__LINE__);
504  }
505  p = l->items+(l->ix);
506  return (p);
507 }
508 
514 
515 #ifdef LIST_DEBUG /* was PROC_TRACE */
516  traceFunc("== listIterationReset(%p) -- %s (ix %d, used %d)\n", l, l->name,
517  l->ix, l->used);
518  listDebugDetails(l);
519 #endif /* LIST_DEBUG, oh-so-formerly-PROC_TRACE */
520 
521 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
522  listValidate(l, NO);
523 #endif /* QA_CHECKS || LIST_DEBUG */
524 
525  l->ix = -1; /* reset index for listIterate() */
526  return;
527 }
528 
537 int listDelete(list_t *l, item_t *p) {
538  int index;
539  item_t *base;
540 
541 #if defined(PROC_TRACE)
542  traceFunc("== listDelete(%p, %p)\n", l, p);
543  listDebugDetails(l);
544 #endif /* PROC_TRACE */
545 
546 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
547  listValidate(l, NO);
548 #endif /* QA_CHECKS || LIST_DEBUG */
549  if ((base = l->items) == NULL_ITEM) {
550  Assert(NO, "%s: empty list", l->name);
551  return (0);
552  }
553  if ((index = p-base) >= l->used) {
554  Assert(NO, "%s[%d] is out of range", l->name, p-(l->items));
555  return (0);
556  }
557 #ifdef LIST_DEBUG
558  printf("DEBUG: listDelete: delete index %d (used %d, size %d)\n",
559  index, l->used, l->size);
560 #endif /* LIST_DEBUG */
561  /*
562  * If anything was allocated, delete it.
563  */
564  if (p->str != NULL_STR) {
565  memFree(p->str, MTAG_LISTKEY);
566  }
567  if (p->buf != NULL_STR) {
568  memFree(p->buf, MTAG_LISTBUF);
569  }
570  /*
571  * move everything up (e.g., from index+1 to index, index+2 to index+1)
572  */
573  if (index+1 < l->used) {
574  (void) memmove(l->items+index, l->items+index+1, (size_t)((l->used
575  -index)*sizeof(item_t)));
576  }
577  l->used--; /* ... then just ignore it now */
578  return (1);
579 }
580 
588 static void listDoubleSize(list_t *l) {
589  int sz;
590  item_t *newptr;
591 
592 #if defined(PROC_TRACE)
593  traceFunc("== listDoubleSize(%p) -- %s\n", l, l->name);
594  listDebugDetails(l);
595 #endif /* PROC_TRACE */
596 
597  sz = (size_t) (l->used * (int)sizeof(item_t));
598 #ifdef LIST_DEBUG
599  printf("LIST: %s FULL (%d) @ addr %p! -- %d -> %d\n", l->name,
600  l->used, l, sz, sz * 2);
601 #endif /* LIST_DEBUG */
602 #ifdef MEMSTATS
603  printf("... DOUBLE \"%s\" (%d -> %d) => %d slots\n", l->name, sz, sz * 2,
604  (sz * 2)/sizeof(item_t));
605 #endif /* MEMSTATS */
606 
607  newptr = (item_t *)memAlloc(sz * 2, MTAG_DOUBLED);
608  memcpy((void *) newptr, (void *) l->items, sz);
609  if (l->items != newptr) {
610 #ifdef LIST_DEBUG
611  printf("LIST: old %p new %p\n", l->items, newptr);
612 #endif /* LIST_DEBUG */
613  memFree(l->items, MTAG_TOOSMALL);
614  l->items = newptr;
615  }
616  l->size *= 2;
617 
618  return;
619 }
620 
631 void listSort(list_t *l, int sortType) {
632 
633  int (*f)() = 0;
634 
635 #ifdef PROC_TRACE
636  char *fName;
637 #ifdef PROC_TRACE_SWITCH
638  if (gl.ptswitch) {
639 #endif /* PROC_TRACE_SWITCH */
640  printf("== listSort(%p, %d", l, sortType);
641  switch (sortType) {
642  case SORT_BY_NAME:
643  printf("(NAME)");
644  break;
645  case SORT_BY_COUNT_DSC:
646  printf("(COUNT_DSC)");
647  break;
648  case SORT_BY_COUNT_ASC:
649  printf("(COUNT_ASC)");
650  break;
651  case SORT_BY_ALIAS:
652  printf("(ALIAS)");
653  break;
654  case SORT_BY_BASENAME:
655  printf("(BASENAME)");
656  break;
657  default:
658  printf("(***)");
659  break;
660  }
661  printf(")\n");
662  listDebugDetails(l);
663 #ifdef PROC_TRACE_SWITCH
664  }
665 #endif /* PROC_TRACE_SWITCH */
666 #endif /* PROC_TRACE */
667 
668  if (sortType == SORT_BY_BASENAME) { /* special case */
669  l->sorted = SORT_BY_NAME;
670  } else {
671  l->sorted = sortType;
672  }
673 
674  if (l->used == 0) {
675 #ifdef LIST_DEBUG
676  LOG_WARNING("\"%s\" is empty", l->name);
677 #endif /* LIST_DEBUG */
678  return;
679  }
680 
681  switch (sortType) {
682 #ifdef QA_CHECKS
683  case UNSORTED:
684  LOG_FATAL("Sort-spec == UNSORTED")
685  Bail(-__LINE__);
686  break;
687 #endif /* QA_CHECKS */
688  case SORT_BY_NAME_ICASE:
689  f = strIcaseCompare;
690 #ifdef PROC_TRACE
691  fName = "strIcaseCompare";
692 #endif /* PROC_TRACE */
693  break;
694  case SORT_BY_NAME:
695  f = strCompare;
696 #ifdef PROC_TRACE
697  fName = "strCompare";
698 #endif /* PROC_TRACE */
699  break;
700  case SORT_BY_COUNT_DSC:
701  f = valCompareDsc;
702 #ifdef PROC_TRACE
703  fName = "valCompareDsc";
704 #endif /* PROC_TRACE */
705  break;
706  case SORT_BY_COUNT_ASC:
707  f = valCompareAsc;
708 #ifdef PROC_TRACE
709  fName = "valCompareAsc";
710 #endif /* PROC_TRACE */
711  break;
712  case SORT_BY_ALIAS:
713 #ifdef PROC_TRACE
714  fName = "bufCompare";
715 #endif /* PROC_TRACE */
716  f = bufCompare;
717  break;
718  case SORT_BY_BASENAME:
719 #ifdef PROC_TRACE
720  fName = "strCompareBasename";
721 #endif /* PROC_TRACE */
722  f = strCompareBasename;
723  sortType = SORT_BY_NAME;
724  break;
725  default:
726  LOG_FATAL("Invalid sort-spec %d", sortType)
727  Bail(-__LINE__);
728  }
729 
730 #ifdef PROC_TRACE
731  traceFunc("=> invoking qsort(): callback is %s()\n", fName);
732 #endif /* PROC_TRACE */
733 
734  qsort(l->items, (size_t) l->used, sizeof(item_t), f);
735  return;
736 }
737 
742 static int strIcaseCompare(item_t *p1, item_t *p2) {
743  int ret;
744 
745  ret = strcasecmp(p1->str, p2->str);
746  return (ret ? ret : valCompareDsc(p1, p2));
747 }
748 
753 static int strCompare(item_t *p1, item_t *p2) {
754  int ret;
755 
756  ret = strcmp(p1->str, p2->str);
757  return (ret ? ret : valCompareDsc(p1, p2));
758 }
759 
764 static int strCompareBasename(item_t *p1, item_t *p2) {
765  int ret;
766 
767  ret = strcmp(pathBasename(p1->str), pathBasename(p2->str));
768  return (ret ? ret : strCompare(p1, p2));
769 }
770 
775 static int valCompareAsc(item_t *p1, item_t *p2) {
776  return (p1->val - p2->val);
777 }
778 
783 static int valCompareDsc(item_t *p1, item_t *p2) {
784  return (p2->val - p1->val);
785 }
786 
791 static int bufCompare(item_t *p1, item_t *p2) {
792  int ret = strcmp(p1->buf, p2->buf);
793  return (ret ? ret : valCompareDsc(p1, p2));
794 }
795 
800 int listCount(list_t *l) {
801  int i;
802  int total;
803 
804 #ifdef PROC_TRACE
805  traceFunc("== listCount(%p)\n", l);
806  listDebugDetails(l);
807 #endif /* PROC_TRACE */
808 
809 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
810  listValidate(l, NO);
811 #endif /* QA_CHECKS || LIST_DEBUG */
812  total = 0;
813  for (i = 0; i < l->used; i++) {
814  if (l->items[i].val > 0) {
815  total += l->items[i].val; /* sum POSITIVE 'val' values */
816  }
817  }
818  return (total);
819 }
820 
829 void listDump(list_t *l, int verbose) {
830  item_t *p;
831  int i;
832  int max = (verbose ? l->size : l->used);
833 
834 #ifdef PROC_TRACE
835  traceFunc("== listDump(%p, %d)\n", l, verbose);
836  listDebugDetails(l);
837 #endif /* PROC_TRACE */
838 
839  /*MD: why should an empty list be fatal? Just return....? */
840  if (l == NULL_LIST) {
841  LOG_FATAL("NULL list passed to listDump()")
842  Bail(-__LINE__);
843  }
844  if (l->used == 0) {
845 #if defined(LIST_DEBUG) || defined(UNPACK_DEBUG) || defined(REPORT_DEBUG)
846  LOG_WARNING("%s is empty", l->name);
847 #endif /* LIST_DEBUG || UNPACK_DEBUG || REPORT_DEBUG */
848  return;
849  }
850  if (verbose < 0) {
851  printf("** %s (size %d, used %d, ix %d, sort %d desc %d) == %lu\n",
852  l->name, l->size, l->used, l->ix, l->sorted, l->desc,
853  (unsigned long)sizeof(item_t));
854  return;
855  }
856  if (verbose || max) {
857  printf("Contents of %s:\n", l->name);
858  printf(" ... @%p (size %d, used %d, ix %d, sort %d desc %d)\n", l,
859  l->size, l->used, l->ix, l->sorted, l->desc);
860  }
861  /*
862  * Brute-force a walk through the list contents. This function could
863  * be called during a loop (while(listIterate(&list))) and we CANNOT
864  * mess with the 'ix' field for this list as listIterate() does!
865  */
866  for (i = 0; i < l->used; i++) {
867  p = &(l->items[i]);
868  if (verbose) {
869  printf("[%c] ", (i < l->used ? 'x' : ' '));
870  }
871  printf("#%03d: str %p buf %p (val %d, val2 %d val3 %d)\n", i, p->str,
872  p->buf, p->val, p->val2, p->val3);
873  if (i < l->used) {
874  printf(" str: \"%s\"\n", p->str);
875  if (p->buf != NULL_STR) {
876  printf(" ... buf: \"%s\"\n", (char *)p->buf);
877  }
878  }
879  }
880  return;
881 } /* listDump */
882 
883 #if defined(PROC_TRACE) || defined(LIST_DEBUG)
884 void listDebugDetails(list_t *l)
885 {
886  if (l != NULL_LIST && l->size) {
887  printf("... %p is %s\n", l, l->name ? l->name : "No-name");
888  }
889  return;
890 }
891 #endif /* PROC_TRACE || LIST_DEBUG */
int verbose
The verbose flag for the cli.
Definition: fo_cli.c:38
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
Definition: libfossagent.c:295
static int valCompareDsc(item_t *, item_t *)
Definition: list.c:783
static int valCompareAsc(item_t *, item_t *)
Definition: list.c:775
static int strIcaseCompare(item_t *, item_t *)
Definition: list.c:742
void listDump(list_t *l, int verbose)
print the passed in list
Definition: list.c:829
static void listValidate(list_t *, int)
Validate list.
Definition: list.c:207
int listDelete(list_t *l, item_t *p)
Delete an item from list.
Definition: list.c:537
item_t * listGetItem(list_t *l, char *s)
get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist.
Definition: list.c:246
void listIterationReset(list_t *l)
Rest list ix to -1.
Definition: list.c:513
void listInit(list_t *l, int size, char *label)
intialize a list, if the list is not empty, empty it (initialize it to zero's).
Definition: list.c:54
int listCount(list_t *l)
Definition: list.c:800
item_t * listAppend(list_t *l, char *s)
Utility list that isn't sorted - faster for unpacking archives and maintaining lists of files (we onl...
Definition: list.c:314
static void listDoubleSize(list_t *)
Double the size of list.
Definition: list.c:588
item_t * listIterate(list_t *l)
return a pointer to listitem, returns a NULL_ITEM when no more items to return.
Definition: list.c:477
static int bufCompare(item_t *, item_t *)
Definition: list.c:791
void listSort(list_t *l, int sortType)
Sort the list as per the sortType passed.
Definition: list.c:631
void listClear(list_t *l, int deallocFlag)
Destroy list_t.
Definition: list.c:106
static int strCompare(item_t *, item_t *)
Definition: list.c:753
static int strCompareBasename(item_t *, item_t *)
Definition: list.c:764
char * pathBasename(char *path)
Get the basename from a file path.
Definition: util.c:615
char * copyString(char *s, char *label)
Create a copy of a string.
Definition: util.c:593
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
Definition: util.c:1395
Nomos header file.
#define NULL_ITEM
NULL item.
Definition: nomos.h:231
#define NULL_LIST
NULL list.
Definition: nomos.h:232
#define memFree(x, y)
Definition: nomos.h:531
#define NULL_STR
NULL string.
Definition: nomos.h:235
#define YES
Definition: nomos.h:175
#define NO
Definition: nomos.h:171
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:533
#define MTAG_UNSORTKEY
Definition: nomos.h:473
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308
int desc
Definition: nomos.h:316
int size
Definition: nomos.h:311
item_t * items
Definition: nomos.h:317
int used
Definition: nomos.h:310
int sorted
Definition: nomos.h:313
char name[64]
Definition: nomos.h:309
int ix
Definition: nomos.h:312
tricky data structure used for a list of 'items'
Definition: nomos.h:274
void * buf
Definition: nomos.h:279
char * str
Definition: nomos.h:278
Store the results of a regex match.
Definition: scanners.hpp:28