cmpkeys.c
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:3k
源码类别:

SQL Server

开发平台:

Unix_Linux

  1. /*
  2.  * cmpkeys.c  - keys comparision
  3.  *              Kernel of GNU SQL-server  
  4.  *
  5.  * This file is a part of GNU SQL Server
  6.  *
  7.  *  Copyright (c) 1996, 1997, Free Software Foundation, Inc
  8.  *  Developed at the Institute of System Programming
  9.  *  This file is written by  Vera Ponomarenko
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation; either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program; if not, write to the Free Software
  23.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  *
  25.  *  Contacts:   gss@ispras.ru
  26.  *
  27.  */
  28. /* $Id: cmpkeys.c,v 1.246 1997/04/10 06:57:28 vera Exp $ */
  29. #include "destrn.h"
  30. #include "strml.h"
  31. #include "fdcltrn.h"
  32. int
  33. cmpkeys (u2_t kn, u2_t * afn, struct des_field *df, char *pk1, char *pk2)
  34. {
  35.   u2_t kk, k, n1, n2;
  36.   char *k1, *kval1, *k2, *kval2;
  37.   i4_t v;
  38.   if (pk1 == NULL)
  39.     return (1); /* The first is absent */
  40.   if (pk2 == NULL)
  41.     return (-1); /* The second is absent */
  42.   k1 = kval1 = pk1 + scscal (pk1);
  43.   k2 = kval2 = pk2 + scscal (pk2);
  44.   for (kk = 0; kk < kn && pk1 < k1 && pk2 < k2; pk1++, pk2++)
  45.     for (k = 0; k < 7 && kk < kn; kk++, k++)
  46.       if ((*pk1 & BITVL(k)) != 0)
  47. {
  48.   if ((*pk2 & BITVL(k)) != 0)
  49.     { /* both are defined */
  50.       switch ((df + afn[kk])->field_type)
  51. {
  52. case T1B:
  53.   if ((v = f1b (kval1, kval2, size1b, size1b)) != 0)
  54.     return (v);
  55.   kval1++;
  56.   kval2++;
  57.   break;
  58. case T2B:
  59.   if ((v = f2b (kval1, kval2, size2b, size2b)) != 0)
  60.     return (v);
  61.   kval1 += size2b;
  62.   kval2 += size2b;
  63.   break;
  64. case T4B:
  65.   if ((v = f4b (kval1, kval2, size4b, size4b)) != 0)
  66.     return (v);
  67.   kval1 += size4b;
  68.   kval2 += size4b;
  69.   break;
  70. case TFLOAT:
  71.   if ((v = flcmp (kval1, kval2, size4b, size4b)) != 0)
  72.     return (v);
  73.   kval1 += size4b;
  74.   kval2 += size4b;
  75.   break;
  76. case TFL:
  77.   n1 = t2bunpack (kval1);
  78.   kval1 += size2b;
  79.   n2 = t2bunpack (kval2);
  80.   kval2 += size2b;
  81.   if ((v = ffloat (kval1, kval2, n1, n2)) != 0)
  82.     return (v);
  83.   kval1 += n1;
  84.   kval2 += n2;
  85.   break;
  86. case TCH:
  87.   n1 = t2bunpack (kval1);
  88.   kval1 += size2b;
  89.   n2 = t2bunpack (kval2);
  90.   kval2 += size2b;
  91.   if ((v = chcmp (kval1, kval2, n1, n2)) != 0)
  92.     return (v);
  93.   kval1 += n1;
  94.   kval2 += n2;
  95.   break;
  96. default:
  97.   printf ("TRN.cmpkeys: This data type is incorrect");
  98.   break;
  99. }
  100.     }
  101.   else
  102.     return (-1); /* The second isn't defined */
  103. }
  104.       else if ((*pk2 & BITVL(k)) != 0)
  105. return (1); /* The first isn't defined */
  106.   if (kk < kn)
  107.     {
  108.       if (pk1 == k1)
  109. {
  110.   if (pk2 == k2)
  111.     return (0);
  112.   else
  113.     return (1);
  114. }
  115.       else
  116. return (-1);
  117.     }
  118.   return (0);
  119. }
  120. int
  121. cmp2keys (u2_t type, char *pk1, char *pk2)
  122. {
  123.   switch (type)
  124.     {
  125.     case T2B:
  126.       return (f2b (pk1, pk2, size2b, size2b));
  127.       break;
  128.     case T4B:
  129.       return (f4b (pk1, pk2, size4b, size4b));
  130.       break;
  131.     default:
  132.       printf ("TRN.cmp2keys: This data type is incorrect");
  133.       break;
  134.     }
  135.   return (0);
  136. }