37 #define DFL_STARTSIZE 100 48 #if defined(PROC_TRACE) || defined(LIST_DEBUG) 49 static void listDebugDetails();
70 traceFunc(
"== listInit(%p, %d, \"%s\")\n", l, size, label);
74 LOG_FATAL(
"listInit: List @ %p is NULL", l)
78 LOG_FATAL(
"no name for list @ %p", l)
81 if (strlen(label) >
sizeof(l->
name)) {
82 LOG_FATAL(
"List name \"%s\" too long", label)
85 if (l->
name != label) (void) strcpy(l->
name, label);
88 printf(
"LIST: (%p) initialize %s to %d elements\n", l,
89 l->
name, DFL_STARTSIZE);
91 l->
size = DFL_STARTSIZE;
96 else if (size != l->
size) {
97 Assert(
NO,
"%s: specified reset size %d != list size %d",
103 printf(
"LIST: reset %d elements in \"%s\" (%d bytes)\n",
123 #if defined(PROC_TRACE) 124 traceFunc(
"== listClear(%p, %s)\n", l,
125 deallocFlag ?
"DEALLOC" :
"NOTOUCH");
131 printf(
"%% clear NULL list\n");
138 printf(
"%% clear empty list \"%s\"\n", l->
name);
148 printf(
"... used %d size %d ix %d sorted %d items %p\n",
154 Assert(
NO,
"%s: used/size %d/%d with null data",
158 printf(
"LIST: clearing %s, used entries == %d\n", l->
name,
163 printf(
"LIST: clearing %s, used entries == %d\n",
167 for (p = l->
items, i = 0; i < l->used; i++, p++) {
171 printf(
"FREE %p items[%d].str %p\n",
181 printf(
"... FREE %p items[%d].buf %p\n",
189 p->val = p->val2 = p->val3 = 0;
193 printf(
"INIT %s...\n", l->
name);
200 printf(
"... dealloc %p \"items\" %p\n", l, l->
items);
203 if (deallocFlag && l->
size) {
209 printf(
"LIST: %s is cleared!\n", l->
name);
222 LOG_FATAL(
"listValidate: null list!")
231 LOG_FATAL(
"List (%s) @ %p not initialized", l->
name, l)
265 traceFunc(
"== listGetItem(%p, \"%s\")\n", l, s);
271 Assert(
NO,
"listGetItem: Null string to insert!");
274 LOG_FATAL(
"%s is sorted other than by-name (%d)", l->
name, l->
sorted)
277 else if (l->
used == 0) {
288 for (p = l->
items, i = 0; i < l->used; i++, p++) {
290 printf(
"%p: check i = %d, used = %d, size = %d\n", l, i, l->
used,
293 if ((x = strcmp(s, p->
str)) == 0) {
301 printf(
"listGetItem: new entry @%d (size %d, max %d)\n", i,
314 printf(
"ADDING: insert %s @%d, \"used\" now == %d, Cache (listDump):\n",
331 traceFunc(
"== listAppend(%p, \"%s\")\n", l, s);
337 Assert(
NO,
"listAppend: Null string to insert!");
347 p->val = p->val2 = p->val3 = 0;
370 #if defined(PROC_TRACE) 371 #ifdef PROC_TRACE_SWITCH 374 printf(
"== listLookupName(%p, \"%s\")\n", l, s);
376 #ifdef PROC_TRACE_SWITCH 381 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 384 Assert(
NO,
"lookupName: Null key for lookup!");
394 LOG_FATAL(
"Improper sort-type %d for %s name-lookup", l->
sorted, l->
name)
402 for (i = 0; i < l->
used; i++) {
409 return(&(l->
items[i]));
411 else if (match < 0) {
435 #if defined(PROC_TRACE) 436 #ifdef PROC_TRACE_SWITCH 439 printf(
"== listLookupAlias(%p, \"%s\")\n", l, s);
441 #ifdef PROC_TRACE_SWITCH 445 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 448 Assert(
NO,
"lookupAlias: Null key for lookup!");
456 if (l->
sorted != SORT_BY_ALIAS) {
457 LOG_FATAL(
"Improper sort-type %d for %s alias-lookup", l->
sorted, l->
name)
464 for (i = 0, p = l->
items; i < l->used; i++, p++) {
469 if ((x = strcmp(s, p->
buf)) == 0) {
495 traceFunc(
"== listIterate(%p) -- %s (ix %d, used %d)\n", l, l->
name,
500 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 514 }
else if ((l->
ix > l->
used) || (l->
ix < 0)) {
515 LOG_FATAL(
"Index %d out of bounds (%d) on %s", l->
ix, l->
used, l->
name)
529 traceFunc(
"== listIterationReset(%p) -- %s (ix %d, used %d)\n", l, l->
name,
534 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 554 #if defined(PROC_TRACE) 555 traceFunc(
"== listDelete(%p, %p)\n", l, p);
559 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 566 if ((index = p-base) >= l->
used) {
571 printf(
"DEBUG: listDelete: delete index %d (used %d, size %d)\n",
586 if (index+1 < l->
used) {
587 (void) memmove(l->
items+index, l->
items+index+1, (
size_t)((l->
used 605 #if defined(PROC_TRACE) 606 traceFunc(
"== listDoubleSize(%p) -- %s\n", l, l->
name);
610 sz = (size_t) (l->
used * (
int)
sizeof(
item_t));
612 printf(
"LIST: %s FULL (%d) @ addr %p! -- %d -> %d\n", l->
name,
613 l->
used, l, sz, sz * 2);
616 printf(
"... DOUBLE \"%s\" (%d -> %d) => %d slots\n", l->
name, sz, sz * 2,
620 newptr = (
item_t *)memAlloc(sz * 2, MTAG_DOUBLED);
621 memcpy((
void *) newptr, (
void *) l->
items, sz);
622 if (l->
items != newptr) {
624 printf(
"LIST: old %p new %p\n", l->
items, newptr);
650 #ifdef PROC_TRACE_SWITCH 653 printf(
"== listSort(%p, %d", l, sortType);
658 case SORT_BY_COUNT_DSC:
659 printf(
"(COUNT_DSC)");
661 case SORT_BY_COUNT_ASC:
662 printf(
"(COUNT_ASC)");
667 case SORT_BY_BASENAME:
668 printf(
"(BASENAME)");
676 #ifdef PROC_TRACE_SWITCH 681 if (sortType == SORT_BY_BASENAME) {
689 LOG_WARNING(
"\"%s\" is empty", l->
name);
697 LOG_FATAL(
"Sort-spec == UNSORTED")
701 case SORT_BY_NAME_ICASE:
704 fName =
"strIcaseCompare";
710 fName =
"strCompare";
713 case SORT_BY_COUNT_DSC:
716 fName =
"valCompareDsc";
719 case SORT_BY_COUNT_ASC:
722 fName =
"valCompareAsc";
727 fName =
"bufCompare";
731 case SORT_BY_BASENAME:
733 fName =
"strCompareBasename";
736 sortType = SORT_BY_NAME;
739 LOG_FATAL(
"Invalid sort-spec %d", sortType)
744 traceFunc(
"=> invoking qsort(): callback is %s()\n", fName);
758 ret = strcasecmp(p1->
str, p2->
str);
769 ret = strcmp(p1->
str, p2->
str);
789 return (p1->val - p2->val);
797 return (p2->val - p1->val);
805 int ret = strcmp(p1->
buf, p2->
buf);
818 traceFunc(
"== listCount(%p)\n", l);
822 #if defined(QA_CHECKS) || defined(LIST_DEBUG) 826 for (i = 0; i < l->
used; i++) {
827 if (l->
items[i].val > 0) {
828 total += l->
items[i].val;
848 traceFunc(
"== listDump(%p, %d)\n", l, verbose);
854 LOG_FATAL(
"NULL list passed to listDump()")
858 #if defined(LIST_DEBUG) || defined(UNPACK_DEBUG) || defined(REPORT_DEBUG) 859 LOG_WARNING(
"%s is empty", l->
name);
864 printf(
"** %s (size %d, used %d, ix %d, sort %d desc %d) == %lu\n",
866 (
unsigned long)
sizeof(
item_t));
869 if (verbose || max) {
870 printf(
"Contents of %s:\n", l->
name);
871 printf(
" ... @%p (size %d, used %d, ix %d, sort %d desc %d)\n", l,
879 for (i = 0; i < l->
used; i++) {
882 printf(
"[%c] ", (i < l->used ?
'x' :
' '));
884 printf(
"#%03d: str %p buf %p (val %d, val2 %d val3 %d)\n", i, p->
str,
885 p->
buf, p->val, p->val2, p->val3);
887 printf(
" str: \"%s\"\n", p->
str);
889 printf(
" ... buf: \"%s\"\n", (
char *)p->
buf);
896 #if defined(PROC_TRACE) || defined(LIST_DEBUG) 897 void listDebugDetails(
list_t *l)
900 printf(
"... %p is %s\n", l, l->
name ? l->
name :
"No-name");
static int strCompareBasename(item_t *, item_t *)
Store the results of a regex match.
tricky data structure used for a list of 'items'
#define NULL_LIST
NULL list.
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...
static int strCompare(item_t *, item_t *)
int s
The socket that the CLI will use to communicate.
void Bail(int exitval)
Close connections and exit.
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).
static int valCompareDsc(item_t *, item_t *)
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...
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
char * copyString(char *s, char *label)
Create a copy of a string.
char * pathBasename(char *path)
Get the basename from a file path.
int listDelete(list_t *l, item_t *p)
Delete an item from list.
static int valCompareAsc(item_t *, item_t *)
int verbose
The verbose flag for the cli.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
void listIterationReset(list_t *l)
Rest list ix to -1.
void listSort(list_t *l, int sortType)
Sort the list as per the sortType passed.
#define NULL_STR
NULL string.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
static int strIcaseCompare(item_t *, item_t *)
static int bufCompare(item_t *, item_t *)
static void listDoubleSize(list_t *)
Double the size of list.
void listDump(list_t *l, int verbose)
print the passed in list
void listClear(list_t *l, int deallocFlag)
Destroy list_t.
#define NULL_ITEM
NULL item.
item_t * listIterate(list_t *l)
return a pointer to listitem, returns a NULL_ITEM when no more items to return.
static void listValidate(list_t *, int)
Validate list.