24 #define DFL_STARTSIZE 100
35 #if defined(PROC_TRACE) || defined(LIST_DEBUG)
36 static void listDebugDetails();
57 traceFunc(
"== listInit(%p, %d, \"%s\")\n", l, size, label);
61 LOG_FATAL(
"listInit: List @ %p is NULL", l)
65 LOG_FATAL(
"no name for list @ %p", l)
68 if (strlen(label) >
sizeof(l->
name)) {
69 LOG_FATAL(
"List name \"%s\" too long", label)
72 if (l->
name != label) (void) strcpy(l->
name, label);
75 printf(
"LIST: (%p) initialize %s to %d elements\n", l,
76 l->
name, DFL_STARTSIZE);
78 l->
size = DFL_STARTSIZE;
83 else if (size != l->
size) {
84 Assert(
NO,
"%s: specified reset size %d != list size %d",
90 printf(
"LIST: reset %d elements in \"%s\" (%d bytes)\n",
110 #if defined(PROC_TRACE)
111 traceFunc(
"== listClear(%p, %s)\n", l,
112 deallocFlag ?
"DEALLOC" :
"NOTOUCH");
118 printf(
"%% clear NULL list\n");
125 printf(
"%% clear empty list \"%s\"\n", l->
name);
135 printf(
"... used %d size %d ix %d sorted %d items %p\n",
141 Assert(
NO,
"%s: used/size %d/%d with null data",
145 printf(
"LIST: clearing %s, used entries == %d\n", l->
name,
150 printf(
"LIST: clearing %s, used entries == %d\n",
154 for (p = l->
items, i = 0; i < l->used; i++, p++) {
158 printf(
"FREE %p items[%d].str %p\n",
168 printf(
"... FREE %p items[%d].buf %p\n",
176 p->val = p->val2 = p->val3 = 0;
180 printf(
"INIT %s...\n", l->
name);
187 printf(
"... dealloc %p \"items\" %p\n", l, l->
items);
190 if (deallocFlag && l->
size) {
196 printf(
"LIST: %s is cleared!\n", l->
name);
209 LOG_FATAL(
"listValidate: null list!")
218 LOG_FATAL(
"List (%s) @ %p not initialized", l->
name, l)
252 traceFunc(
"== listGetItem(%p, \"%s\")\n", l,
s);
258 Assert(
NO,
"listGetItem: Null string to insert!");
261 LOG_FATAL(
"%s is sorted other than by-name (%d)", l->
name, l->
sorted)
264 else if (l->
used == 0) {
275 for (p = l->
items, i = 0; i < l->used; i++, p++) {
277 printf(
"%p: check i = %d, used = %d, size = %d\n", l, i, l->
used,
280 if ((x = strcmp(
s, p->
str)) == 0) {
288 printf(
"listGetItem: new entry @%d (size %d, max %d)\n", i,
301 printf(
"ADDING: insert %s @%d, \"used\" now == %d, Cache (listDump):\n",
318 traceFunc(
"== listAppend(%p, \"%s\")\n", l,
s);
324 Assert(
NO,
"listAppend: Null string to insert!");
334 p->val = p->val2 = p->val3 = 0;
357 #if defined(PROC_TRACE)
358 #ifdef PROC_TRACE_SWITCH
361 printf(
"== listLookupName(%p, \"%s\")\n", l,
s);
363 #ifdef PROC_TRACE_SWITCH
368 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
371 Assert(
NO,
"lookupName: Null key for lookup!");
381 LOG_FATAL(
"Improper sort-type %d for %s name-lookup", l->
sorted, l->
name)
389 for (i = 0; i < l->used; i++) {
396 return(&(l->
items[i]));
398 else if (
match < 0) {
422 #if defined(PROC_TRACE)
423 #ifdef PROC_TRACE_SWITCH
426 printf(
"== listLookupAlias(%p, \"%s\")\n", l,
s);
428 #ifdef PROC_TRACE_SWITCH
432 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
435 Assert(
NO,
"lookupAlias: Null key for lookup!");
443 if (l->
sorted != SORT_BY_ALIAS) {
444 LOG_FATAL(
"Improper sort-type %d for %s alias-lookup", l->
sorted, l->
name)
451 for (i = 0, p = l->items; i < l->used; i++, p++) {
456 if ((x = strcmp(
s, p->
buf)) == 0) {
482 traceFunc(
"== listIterate(%p) -- %s (ix %d, used %d)\n", l, l->
name,
487 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
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)
516 traceFunc(
"== listIterationReset(%p) -- %s (ix %d, used %d)\n", l, l->
name,
521 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
541 #if defined(PROC_TRACE)
542 traceFunc(
"== listDelete(%p, %p)\n", l, p);
546 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
553 if ((index = p-base) >= l->
used) {
558 printf(
"DEBUG: listDelete: delete index %d (used %d, size %d)\n",
573 if (index+1 < l->
used) {
574 (void) memmove(l->
items+index, l->
items+index+1, (
size_t)((l->
used
592 #if defined(PROC_TRACE)
593 traceFunc(
"== listDoubleSize(%p) -- %s\n", l, l->
name);
597 sz = (size_t) (l->
used * (
int)
sizeof(
item_t));
599 printf(
"LIST: %s FULL (%d) @ addr %p! -- %d -> %d\n", l->
name,
600 l->
used, l, sz, sz * 2);
603 printf(
"... DOUBLE \"%s\" (%d -> %d) => %d slots\n", l->
name, sz, sz * 2,
607 newptr = (
item_t *)memAlloc(sz * 2, MTAG_DOUBLED);
608 memcpy((
void *) newptr, (
void *) l->
items, sz);
609 if (l->
items != newptr) {
611 printf(
"LIST: old %p new %p\n", l->
items, newptr);
637 #ifdef PROC_TRACE_SWITCH
640 printf(
"== listSort(%p, %d", l, sortType);
645 case SORT_BY_COUNT_DSC:
646 printf(
"(COUNT_DSC)");
648 case SORT_BY_COUNT_ASC:
649 printf(
"(COUNT_ASC)");
654 case SORT_BY_BASENAME:
655 printf(
"(BASENAME)");
663 #ifdef PROC_TRACE_SWITCH
668 if (sortType == SORT_BY_BASENAME) {
676 LOG_WARNING(
"\"%s\" is empty", l->
name);
684 LOG_FATAL(
"Sort-spec == UNSORTED")
688 case SORT_BY_NAME_ICASE:
691 fName =
"strIcaseCompare";
697 fName =
"strCompare";
700 case SORT_BY_COUNT_DSC:
703 fName =
"valCompareDsc";
706 case SORT_BY_COUNT_ASC:
709 fName =
"valCompareAsc";
714 fName =
"bufCompare";
718 case SORT_BY_BASENAME:
720 fName =
"strCompareBasename";
723 sortType = SORT_BY_NAME;
726 LOG_FATAL(
"Invalid sort-spec %d", sortType)
731 traceFunc(
"=> invoking qsort(): callback is %s()\n", fName);
745 ret = strcasecmp(p1->
str, p2->
str);
756 ret = strcmp(p1->
str, p2->
str);
776 return (p1->val - p2->val);
784 return (p2->val - p1->val);
792 int ret = strcmp(p1->
buf, p2->
buf);
805 traceFunc(
"== listCount(%p)\n", l);
809 #if defined(QA_CHECKS) || defined(LIST_DEBUG)
813 for (i = 0; i < l->
used; i++) {
814 if (l->
items[i].val > 0) {
815 total += l->
items[i].val;
835 traceFunc(
"== listDump(%p, %d)\n", l,
verbose);
841 LOG_FATAL(
"NULL list passed to listDump()")
845 #if defined(LIST_DEBUG) || defined(UNPACK_DEBUG) || defined(REPORT_DEBUG)
846 LOG_WARNING(
"%s is empty", l->
name);
851 printf(
"** %s (size %d, used %d, ix %d, sort %d desc %d) == %lu\n",
853 (
unsigned long)
sizeof(
item_t));
857 printf(
"Contents of %s:\n", l->
name);
858 printf(
" ... @%p (size %d, used %d, ix %d, sort %d desc %d)\n", l,
866 for (i = 0; i < l->
used; i++) {
869 printf(
"[%c] ", (i < l->used ?
'x' :
' '));
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);
874 printf(
" str: \"%s\"\n", p->
str);
876 printf(
" ... buf: \"%s\"\n", (
char *)p->
buf);
883 #if defined(PROC_TRACE) || defined(LIST_DEBUG)
884 void listDebugDetails(
list_t *l)
887 printf(
"... %p is %s\n", l, l->
name ? l->
name :
"No-name");
int verbose
The verbose flag for the cli.
int s
The socket that the CLI will use to communicate.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
static int valCompareDsc(item_t *, item_t *)
static int valCompareAsc(item_t *, item_t *)
static int strIcaseCompare(item_t *, item_t *)
void listDump(list_t *l, int verbose)
print the passed in list
static void listValidate(list_t *, int)
Validate list.
int listDelete(list_t *l, item_t *p)
Delete an item from list.
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 listIterationReset(list_t *l)
Rest list ix to -1.
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).
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 void listDoubleSize(list_t *)
Double the size of list.
item_t * listIterate(list_t *l)
return a pointer to listitem, returns a NULL_ITEM when no more items to return.
static int bufCompare(item_t *, item_t *)
void listSort(list_t *l, int sortType)
Sort the list as per the sortType passed.
void listClear(list_t *l, int deallocFlag)
Destroy list_t.
static int strCompare(item_t *, item_t *)
static int strCompareBasename(item_t *, item_t *)
char * pathBasename(char *path)
Get the basename from a file path.
char * copyString(char *s, char *label)
Create a copy of a string.
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
#define NULL_ITEM
NULL item.
#define NULL_LIST
NULL list.
#define NULL_STR
NULL string.
void Bail(int exitval)
Close connections and exit.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
tricky data structure used for a list of 'items'
Store the results of a regex match.