cmpkey.c
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:4k
- /* cmpkey.c - Comparision of keys
- * Kernel of GNU SQL-server. Sorter
- *
- * This file is a part of GNU SQL Server
- *
- * Copyright (c) 1996, 1997, Free Software Foundation, Inc
- * Developed at the Institute of System Programming
- * This file is written by Vera Ponomarenko
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Contacts: gss@ispras.ru
- *
- */
- /* $Id: cmpkey.c,v 1.245 1997/03/31 03:46:38 kml Exp $ */
- #include "dessrt.h"
- #include "pupsi.h"
- #include "f1f2decl.h"
- #include "fdclsrt.h"
- extern char *nonsense;
- extern u2_t kn;
- int
- cmpkey (u2_t *afn, struct des_field *df, char *drctn, char *pk1, char *pk2)
- {
- i4_t d, kk, k, v;
- char *k1, *kval1, *k2, *kval2;
- u2_t n1, n2;
- if (pk1 == nonsense)
- return (1); /* The first is absent */
- if (pk2 == nonsense)
- return (-1); /* The second is absent */
- pk1 += size2b + tidsize;
- pk2 += size2b + tidsize;
- k1 = kval1 = pk1 + scscal (pk1);
- k2 = kval2 = pk2 + scscal (pk2);
- if (*drctn == GROW)
- d = 1;
- else
- d = -1;
- v = 0;
- for (kk = 0, k = 0; kk < kn && pk1 < k1 && pk2 < k2; kk++, k++)
- {
- if (k == 7)
- {
- k = 0;
- pk1++;
- if (pk1 >= k1)
- break;
- pk2++;
- if (pk2 >= k2)
- break;
- }
- if (*drctn++ == GROW)
- d = 1;
- else
- d = -1;
- if ((*pk1 & BITVL(k)) != 0)
- {
- if ((*pk2 & BITVL(k)) != 0)
- { /* both are defined */
- switch ((df + afn[kk])->field_type)
- {
- case T1B:
- if ((v = f1b (kval1, kval2, size1b, size1b)) != 0)
- return (v * d);
- kval1++;
- kval2++;
- break;
- case T2B:
- if ((v = f2b (kval1, kval2, size2b, size2b)) != 0)
- return (v * d);
- kval1 += size2b;
- kval2 += size2b;
- break;
- case T4B:
- if ((v = f4b (kval1, kval2, size4b, size4b)) != 0)
- return (v * d);
- kval1 += size4b;
- kval2 += size4b;
- break;
- case TFLOAT:
- if ((v = flcmp (kval1, kval2, size4b, size4b)) != 0)
- return (v * d);
- kval1 += size4b;
- kval2 += size4b;
- break;
- case TFL:
- n1 = t2bunpack (kval1);
- kval1 += size2b;
- n2 = t2bunpack (kval2);
- kval2 += size2b;
- if ((v = ffloat (kval1, kval2, n1, n2)) != 0)
- return (v * d);
- kval1 += n1;
- kval2 += n2;
- break;
- case TCH:
- n1 = t2bunpack (kval1);
- kval1 += size2b;
- n2 = t2bunpack (kval2);
- kval2 += size2b;
- if ((v = chcmp (kval1, kval2, n1, n2)) != 0)
- return (v * d);
- kval1 += n1;
- kval2 += n2;
- break;
- default:
- perror ("SRT.cmpkey: This data type doesn't exist");
- break;
- }
- }
- else
- return (-1); /* The second not defined */
- }
- else if ((*pk2 & BITVL(k)) != 0)
- return (1); /*The first isn't defined */
- }
- if (kk < kn)
- {
- if (pk1 == k1)
- {
- if (pk2 == k2)
- return (0);
- else
- return (1);
- }
- else
- return (-1);
- }
- return (0);
- }
- u2_t
- scscal (char *a)
- {
- char *c;
- for (c = a; (*a & EOSC) == 0; a++);
- return (a + 1 - c);
- }