home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR41 / CBASE11.ZIP / BTKEYCMP.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  2KB  |  73 lines

  1. /*
  2.  *    Copyright (c) 1989-1992 Citadel Software, Inc.
  3.  *    All Rights Reserved
  4.  */
  5.  
  6. /* #ident    "@(#)btkeycmp.c    1.7 - 93/01/01" */
  7.  
  8. #include <port.h>
  9.  
  10. /* standard headers */
  11. #include <errno.h>
  12.  
  13. /* library headers */
  14. #include <blkio.h>
  15.  
  16. /* local headers */
  17. #include "btree_.h"
  18.  
  19. /*man---------------------------------------------------------------------------
  20. NAME
  21.      btkeycmp - compare btree keys
  22.  
  23. SYNOPSIS
  24.      #include <btree.h>
  25.  
  26.      int btkeycmp(btp, buf1, buf2)
  27.      btree_t *btp;
  28.      const void *buf1;
  29.      const void *buf2;
  30.  
  31. DESCRIPTION
  32.      The btkeycmp function compares the keys pointed to be buf1 and
  33.      buf2.  buf1 and buf2 must point to keys of the size stored in
  34.      btree btp.  The value returned will be less than, equal to, or
  35.      greater than 0, according as the key pointed to by buf1 is less
  36.      than, equal to, or greater than the key pointed to by buf2.
  37.  
  38.      btkeycmp will fail if one or more of the following is true:
  39.  
  40.      [EINVAL]       btp is not a valid btree pointer.
  41.      [EINVAL]       buf is the NULL pointer.
  42.  
  43. SEE ALSO
  44.      btsearch.
  45.  
  46. ------------------------------------------------------------------------------*/
  47. #ifdef AC_PROTO
  48. int btkeycmp(btree_t *btp, const void *buf1, const void *buf2)
  49. #else
  50. int btkeycmp(btp, buf1, buf2)
  51. btree_t *btp;
  52. const void *buf1;
  53. const void *buf2;
  54. #endif
  55. {
  56.     int    cmp    = 0;        /* result of key comparison */
  57.     int    fld    = 0;        /* field number */
  58.  
  59.     /* compare each field */
  60.     for (fld = 0; fld < btp->fldc; ++fld) {
  61.         cmp = (*btp->fldv[fld].cmp)((char *)buf1 + btp->fldv[fld].offset,
  62.             (char *)buf2 + btp->fldv[fld].offset, btp->fldv[fld].len);
  63.         if (cmp != 0) {
  64.             if (btp->fldv[fld].flags & BT_FDSC) {
  65.                 cmp = -cmp;
  66.             }
  67.             break;
  68.         }
  69.     }
  70.  
  71.     return cmp;
  72. }
  73.