be4311c07e14feb728abc6425ee606ffaa611a58 markd Fri Jan 22 06:46:58 2021 -0800 merge with master diff --git src/lib/common.c src/lib/common.c index 99474c2..68c27bc 100644 --- src/lib/common.c +++ src/lib/common.c @@ -122,30 +122,45 @@ void reverseStrings(char **a, int length) /* Reverse the order of the char* array. */ { int halfLen = (length>>1); char **end = a+length; char *c; while (--halfLen >= 0) { c = *a; *a++ = *--end; *end = c; } } +static int stringCmp(const void *va, const void *vb) +/* Compare function to sort array of strings. */ +{ +char **a = (char **)va; +char **b = (char **)vb; +return strcmp(*a, *b); +} + +void sortStrings(char **array, int count) +/* Sort array using strcmp */ +{ +if (count > 1) + qsort(array, count, sizeof(array[0]), stringCmp); +} + /* Swap buffers a and b. */ void swapBytes(char *a, char *b, int length) { char c; int i; for (i=0; i<length; ++i) { c = a[i]; a[i] = b[i]; b[i] = c; } } @@ -438,30 +453,31 @@ for (i=list;i;i=i->next) if (i->val == target) return i; return NULL; } struct slUnsigned *slUnsignedNew(unsigned x) /* Return a new int. */ { struct slUnsigned *a; AllocVar(a); a->val = x; return a; } + static int doubleCmp(const void *va, const void *vb) /* Compare function to sort array of doubles. */ { const double *a = va; const double *b = vb; double diff = *a - *b; if (diff < 0) return -1; else if (diff > 0) return 1; else return 0; } void doubleSort(int count, double *array)