#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libdB/db_Qsort.c $ %D% SwRI" #include "dbf.h" /******************** ** >FILE: db_Qsort.c ********************/ SDDAS_INT len; /***************************************************** ** Function: static int qcompare(char *s1, char *s2) ** ** char *s1 string to compare ** char *s2 string to compare ** ** Description: ** String compare on any character ** ** Retrun Values: ** ***************** *****************/ static int qcompare(const void *s1, const void *s2) { int k; for (k = 1; *(char *)s1 == *(char *)s2; s1++, s2++, k++) { if (k >= len) { return 0; } } return(*(char *)s1 - *(char *)s2); } /************************************************************************* ** Function: void db_Qsort(char *ndx, int NumRecs, int size, int KeyLen) ** ** char *ndx ** int NumRecs ** int size ** int KeyLen ** ** Description: ** Preform the sorting on the index array - use the UNIX quick sort. ** ** Return Values: ** ***************** *****************/ void db_Qsort(char *ndx, SDDAS_INT NumRecs, SDDAS_INT size, SDDAS_INT KeyLen) { /* quicker sort ! */ len = KeyLen; QSORT (ndx, NumRecs, size, qcompare); }