| 1 |
/* File: queryexe.c |
| 2 |
* Author: Jean Thierry-Mieg ([email protected]) |
| 3 |
* Copyright (C) J Thierry-Mieg and R Durbin, 1991 |
| 4 |
* ------------------------------------------------------------------- |
| 5 |
* Acedb is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt |
| 19 |
* ------------------------------------------------------------------- |
| 20 |
* This file is part of the ACEDB genome database package, written by |
| 21 |
* Richard Durbin (MRC LMB, UK) [email protected], and |
| 22 |
* Jean Thierry-Mieg (CRBM du CNRS, France) [email protected] |
| 23 |
* |
| 24 |
* Description: |
| 25 |
* Used anywhere for non interactive executions. |
| 26 |
* Exported functions: |
| 27 |
query, queryKey, queryGrep |
| 28 |
* HISTORY: |
| 29 |
* Last edited: Jul 9 11:34 2003 (rnc) |
| 30 |
* * Oct 7 20:06 1993 (mieg): Introduced set operations {} delimited |
| 31 |
* * Oct 5 20:06 1993 (mieg): Introduced arithmetic operations [] delimited |
| 32 |
* * Nov 18 15:17 1992 (mieg): Changed # precedence and pushpop sub-objs |
| 33 |
* * May 26 17:21 1992 (mieg): queryIsA for dynamic subclass system |
| 34 |
* Created: Tue Nov 5 16:53:55 1991 (mieg) |
| 35 |
*------------------------------------------------------------------- |
| 36 |
*/ |
| 37 |
|
| 38 |
|
| 39 |
/* $Id: queryexe.c,v 1.122 2004/01/03 23:26:08 mieg Exp $ */ |
| 40 |
|
| 41 |
#include "acedb.h" |
| 42 |
#include "keyset.h" |
| 43 |
#include "a.h" |
| 44 |
#include "bs.h" |
| 45 |
#include "lex.h" |
| 46 |
#include "pick.h" |
| 47 |
#include "whooks/sysclass.h" |
| 48 |
#include "whooks/systags.h" |
| 49 |
#include "mytime.h" |
| 50 |
#include "client.h" |
| 51 |
#include "bindex.h" |
| 52 |
#include "bitset.h" |
| 53 |
#include "utils.h" /* for lexstrcmp */ |
| 54 |
|
| 55 |
extern KEYSET cacheKeySet (void) ; |
| 56 |
|
| 57 |
/* Query operators, the reordering loop stops on TAG */ |
| 58 |
typedef enum { /* 0 */ NULLQOP, SUBQUERY, SUBEXP, NAMEDSET, |
| 59 |
/* 4 */ TEXT, CALCUL, NUMBER, TIME, TAG, |
| 60 |
/* 9 */ FINALPIPE, PIPEQUERY, WHERE, |
| 61 |
/* 12 */ FIND, FROM, FOLLOW_TAG, WEBQUERY, NEIGHBOURS, GREP, EXPAND, |
| 62 |
/* 19 */ OR, XOR, AND, NOT, |
| 63 |
/* 23 */ SETELSE, SETDEFINE, SETOR, SETXOR, SETAND, SETMINUS, |
| 64 |
/* 29 */ COMPOSITE_TAG, IS, |
| 65 |
/* 31 */ LT, LE, GT, GE, NEQ, EQ, LIKE, |
| 66 |
/* 38 */ PLUS, MINUS, MULTIPLY, DIVIDE, |
| 67 |
/* 42 */ COUNT, AVG, SUM, MIN, MAX, CLASS, VECTOR_TAG |
| 68 |
/* 49 */ } QOP ; |
| 69 |
|
| 70 |
char *qName[] = { |
| 71 |
/* 0 */ "NULLQOP", "SUBQUERY", "SUBEXP", "NAMEDSET", |
| 72 |
/* 4 */ "TEXT", "CALCUL", "NUMBER", "TIME", "TAG", |
| 73 |
/* 9 */ "FINALPIPE", "PIPEQUERY", "WHERE", |
| 74 |
/* 12 */ "FIND", "FROM", "FOLLOW", "WEBQUERY", "NEIGHBOURS","GREP", "EXPAND", |
| 75 |
/* 19 */ "OR", "XOR", "AND", "NOT", |
| 76 |
/* 23 */ "SETELSE", "SETDEFINE", "SETOR", "SETXOR", "SETAND", "SETMINUS", |
| 77 |
/* 29 */ "COMPOSITE_TAG", "IS", |
| 78 |
/* 31 */ "LT", "LE", "GT", "GE", "NEQ", "EQ", "LIKE", |
| 79 |
/* 38 */ "PLUS", "MINUS", "MULTIPLY", "DIVIDE", |
| 80 |
/* 42 */ "COUNT", "AVG", "SUM", "MIN", "MAX", "CLASS", "VECTOR_TAG" |
| 81 |
/* 49 */ } ; |
| 82 |
|
| 83 |
/* RD added numbers to help when debugging */ |
| 84 |
|
| 85 |
typedef struct conditionNode *CDT; |
| 86 |
struct conditionNode |
| 87 |
{ QOP qop ; |
| 88 |
CDT up, left, right ; /* tree structure */ |
| 89 |
union { KEY tag ; KEY classe ; float x ; Array a ; } n ; |
| 90 |
int mark ; /* mark in the associated stack */ |
| 91 |
} ; |
| 92 |
|
| 93 |
#define CONDITION_DEFINED |
| 94 |
static void* MAGIC ; |
| 95 |
typedef struct condition |
| 96 |
{ void* magic; /* == &MAGIC */ |
| 97 |
Stack stack ; |
| 98 |
CDT cdt ; |
| 99 |
} *COND ; |
| 100 |
|
| 101 |
COND queryFindCond = 0 ; |
| 102 |
#include "query.h" |
| 103 |
|
| 104 |
BITSET_MAKE_BITFIELD /* define bitField for bitset.h ops */ |
| 105 |
|
| 106 |
static BOOL doInterrupt ; |
| 107 |
static BOOL doPushPopSubObj = TRUE ; |
| 108 |
static Stack subObjMarks = 0 ; |
| 109 |
static BOOL fuzzy ; |
| 110 |
static Array subQ = 0 ; /* Array of subQuery results */ |
| 111 |
static KEYSET queryExecute (KEYSET oldSet, CDT cdt, Stack stack) ; |
| 112 |
static BOOL checkParentheses (char *text) ; |
| 113 |
static void querySetTextName (char *tname) ; |
| 114 |
|
| 115 |
/* mieg, july 2003, |
| 116 |
* webquery is an addition to the query language registered from acembly |
| 117 |
* with this system, tace compiles ok and the word 'webquery' |
| 118 |
* is tokenised as an operator if and only if the function is registered |
| 119 |
*/ |
| 120 |
static WEBQUERYFUNC webQueryFunc = 0 ; |
| 121 |
BOOL queryRegisterWebQuery (WEBQUERYFUNC f) |
| 122 |
{ webQueryFunc = f ; return TRUE ; } |
| 123 |
|
| 124 |
/**********/ |
| 125 |
|
| 126 |
static BOOL isNumber(QOP qop) |
| 127 |
{ |
| 128 |
switch (qop) |
| 129 |
{ |
| 130 |
case CALCUL: |
| 131 |
case NUMBER: |
| 132 |
case TIME: |
| 133 |
case PLUS: |
| 134 |
case MINUS: |
| 135 |
case MULTIPLY: |
| 136 |
case DIVIDE: |
| 137 |
case COUNT: |
| 138 |
case AVG: |
| 139 |
case SUM: |
| 140 |
case MIN: |
| 141 |
case MAX: |
| 142 |
return TRUE ; |
| 143 |
default: break ; |
| 144 |
} |
| 145 |
return FALSE ; |
| 146 |
} |
| 147 |
|
| 148 |
/**********/ |
| 149 |
|
| 150 |
static BOOL isLocatorOp (QOP qop) |
| 151 |
{ |
| 152 |
switch (qop) |
| 153 |
{ |
| 154 |
case TAG: |
| 155 |
case COMPOSITE_TAG: /* example:: Int #type */ |
| 156 |
return TRUE ; /* a tag or composite tag is necessarilly unique */ |
| 157 |
case VECTOR_TAG: /* example:: tag:2 */ |
| 158 |
return FALSE ; /* should be true if we could handle ALL matches |
| 159 |
not just the first one */ |
| 160 |
default: break ; |
| 161 |
} |
| 162 |
return FALSE ; |
| 163 |
} |
| 164 |
|
| 165 |
/**************************************************************/ |
| 166 |
|
| 167 |
/* Manage CDT allocation |
| 168 |
hope they speed things up/prevent fragmentation |
| 169 |
in any case, they will help monitoring memory usage |
| 170 |
NB they must be paired. |
| 171 |
*/ |
| 172 |
|
| 173 |
static Stack freeCDTstack = 0 ; |
| 174 |
static int nCDTused = 0, nCDTalloc = 0 ; /* useful for debug */ |
| 175 |
|
| 176 |
static CDT CDTalloc (void) /* self managed calloc */ |
| 177 |
{ |
| 178 |
static int blocSize = 512 ; |
| 179 |
CDT p ; |
| 180 |
int i ; |
| 181 |
|
| 182 |
nCDTalloc++ ; |
| 183 |
|
| 184 |
if (!freeCDTstack) |
| 185 |
freeCDTstack = stackCreate (4*blocSize) ; |
| 186 |
if (stackEmpty (freeCDTstack)) |
| 187 |
{ p = (CDT) messalloc (blocSize * sizeof (struct conditionNode)) ; |
| 188 |
for (i = blocSize ; i-- ; ++p) |
| 189 |
push (freeCDTstack,p,CDT) ; |
| 190 |
/* printf ("Adding %d to CDT free list\n",blocSize) ; */ |
| 191 |
blocSize *= 2 ; |
| 192 |
} |
| 193 |
p = pop (freeCDTstack,CDT) ; |
| 194 |
memset (p, 0, sizeof (struct conditionNode)) ; |
| 195 |
++nCDTused ; |
| 196 |
return p ; |
| 197 |
} |
| 198 |
|
| 199 |
static void CDTfree (CDT cdt) |
| 200 |
{ |
| 201 |
push (freeCDTstack,cdt,CDT) ; |
| 202 |
--nCDTused ; |
| 203 |
} |
| 204 |
|
| 205 |
void CDTstatus (int *used, int *alloc) |
| 206 |
{ *used = nCDTused ; *alloc = nCDTalloc ; |
| 207 |
} |
| 208 |
|
| 209 |
/**************************************************************/ |
| 210 |
|
| 211 |
/* Manage COND allocation |
| 212 |
hope they speed things up/prevent fragmentation |
| 213 |
in any case, they will help monitoring memory usage |
| 214 |
NB they must be paired. |
| 215 |
*/ |
| 216 |
|
| 217 |
static Stack freeCONDstack = 0 ; |
| 218 |
static int nCONDused = 0, nCONDalloc = 0 ; /* useful for debug */ |
| 219 |
|
| 220 |
static COND CONDalloc (void) /* self managed calloc */ |
| 221 |
{ |
| 222 |
static int blocSize = 512 ; |
| 223 |
COND p ; |
| 224 |
int i ; |
| 225 |
|
| 226 |
nCONDalloc++ ; |
| 227 |
|
| 228 |
if (!freeCONDstack) |
| 229 |
freeCONDstack = stackCreate (4*blocSize) ; |
| 230 |
if (stackEmpty (freeCONDstack)) |
| 231 |
{ |
| 232 |
p = (COND) messalloc (blocSize * sizeof (struct condition)) ; |
| 233 |
for (i = blocSize ; i-- ; ++p) |
| 234 |
push (freeCONDstack,p,COND) ; |
| 235 |
/* printf ("Adding %d to COND free list\n",blocSize) ; */ |
| 236 |
blocSize *= 2 ; |
| 237 |
} |
| 238 |
p = pop (freeCONDstack,COND) ; |
| 239 |
memset (p, 0, sizeof (struct condition)) ; |
| 240 |
p->magic = &MAGIC ; |
| 241 |
++nCONDused ; |
| 242 |
return p ; |
| 243 |
} |
| 244 |
|
| 245 |
static void CONDfree (COND cond) |
| 246 |
{ cond->magic = 0 ; |
| 247 |
push (freeCONDstack,cond,COND) ; |
| 248 |
--nCONDused ; |
| 249 |
} |
| 250 |
|
| 251 |
void CONDstatus (int *used, int *alloc) |
| 252 |
{ *used = nCONDused ; *alloc = nCONDalloc ; |
| 253 |
} |
| 254 |
|
| 255 |
/**************************************************************/ |
| 256 |
/* Recursively destroys a tree of conditions */ |
| 257 |
|
| 258 |
static void cdtDestroy(CDT c) |
| 259 |
{ |
| 260 |
if (c) |
| 261 |
{ |
| 262 |
if (c->left) |
| 263 |
cdtDestroy(c->left) ; |
| 264 |
if (c->right) |
| 265 |
cdtDestroy(c->right) ; |
| 266 |
c->left = c->right = 0 ; /* stops eventual loop */ |
| 267 |
CDTfree(c) ; |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
/**************************************************************/ |
| 272 |
/* Call with 0 if you want to rescan the same text */ |
| 273 |
/* itemizes a text considering quotes and nested parentheses */ |
| 274 |
static QOP cdtItem(char *text, char **item, int context) |
| 275 |
{ |
| 276 |
static char *previousText = 0 , *cp , backup = 0 ; |
| 277 |
int np = 0 , ncb ; |
| 278 |
static QOP qop = 0 ; |
| 279 |
|
| 280 |
*item = 0 ; |
| 281 |
if (!text || (previousText != text)) |
| 282 |
{ cp = text ; previousText = text ; qop = 0; } |
| 283 |
else |
| 284 |
{ |
| 285 |
*cp = backup ; |
| 286 |
switch (qop) |
| 287 |
{ /*skip the former end delimiter */ |
| 288 |
case SUBEXP: case SUBQUERY: case TEXT: case CALCUL: |
| 289 |
if (*cp) |
| 290 |
cp++ ; |
| 291 |
break ; |
| 292 |
default: |
| 293 |
break ; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
qop = 0 ; |
| 298 |
if (!text) |
| 299 |
return 0 ; |
| 300 |
|
| 301 |
while (TRUE) switch(*cp) |
| 302 |
{ |
| 303 |
case 0: |
| 304 |
goto done ; |
| 305 |
|
| 306 |
case '(': |
| 307 |
if (qop) |
| 308 |
goto done ; |
| 309 |
*item = ++cp ; /* inside the parenthese */ |
| 310 |
np = 1 ; |
| 311 |
while (np) |
| 312 |
switch (*cp++) |
| 313 |
{ |
| 314 |
case 0: |
| 315 |
messout("Unbalanced parenthesis:\n %s",text) ; |
| 316 |
return NULLQOP ; |
| 317 |
case '(': |
| 318 |
np++ ; |
| 319 |
break ; |
| 320 |
case ')': |
| 321 |
np--; |
| 322 |
break ; |
| 323 |
} |
| 324 |
cp-- ; /* The paranthesis will be masked */ |
| 325 |
qop = SUBEXP ; |
| 326 |
goto done ; |
| 327 |
|
| 328 |
case '{': |
| 329 |
if (qop) |
| 330 |
goto done ; |
| 331 |
*item = ++cp ; /* inside the parenthese */ |
| 332 |
ncb = 1 ; |
| 333 |
while (ncb) |
| 334 |
switch (*cp++) |
| 335 |
{ |
| 336 |
case 0: |
| 337 |
messout ("Unbalanced curly bracket:\n %s",text) ; |
| 338 |
return NULLQOP ; |
| 339 |
case '{': |
| 340 |
ncb++ ; |
| 341 |
break ; |
| 342 |
case '}': |
| 343 |
ncb--; |
| 344 |
break ; |
| 345 |
} |
| 346 |
cp-- ; /* The paranthesis will be masked */ |
| 347 |
qop = SUBQUERY ; |
| 348 |
goto done ; |
| 349 |
|
| 350 |
case '[': |
| 351 |
if (qop) |
| 352 |
goto done ; |
| 353 |
*item = ++cp ; /* inside the parenthese */ |
| 354 |
ncb = 1 ; |
| 355 |
while (ncb) |
| 356 |
switch (*cp++) |
| 357 |
{ |
| 358 |
case 0: |
| 359 |
messout ("Unbalanced square bracket:\n %s",text) ; |
| 360 |
return NULLQOP ; |
| 361 |
case '[': |
| 362 |
ncb++ ; |
| 363 |
break ; |
| 364 |
case ']': |
| 365 |
ncb--; |
| 366 |
break ; |
| 367 |
} |
| 368 |
cp-- ; /* The paranthesis will be masked */ |
| 369 |
qop = CALCUL ; |
| 370 |
goto done ; |
| 371 |
|
| 372 |
case '\"': |
| 373 |
if (qop) |
| 374 |
goto done ; |
| 375 |
*item = ++cp ; |
| 376 |
while (*cp && !(*cp == '\"' && *(cp - 1) != '\\')) cp++ ; |
| 377 |
if (!*cp) |
| 378 |
{ messout("Unbalanced double quote:\n %s",text) ; |
| 379 |
return NULLQOP ; |
| 380 |
} |
| 381 |
/* The final double quote will be masked */ |
| 382 |
qop = TEXT ; |
| 383 |
goto done ; |
| 384 |
|
| 385 |
case ')': |
| 386 |
messout("Unexpected closing parenthesis:\n %s",text) ; |
| 387 |
return NULLQOP ; |
| 388 |
|
| 389 |
case '}': |
| 390 |
messout("Unexpected closing curly bracket:\n %s",text) ; |
| 391 |
return NULLQOP ; |
| 392 |
|
| 393 |
case ']': |
| 394 |
messout("Unexpected closing square bracket:\n %s",text) ; |
| 395 |
return NULLQOP ; |
| 396 |
|
| 397 |
case ' ': case '\t': case '\n': case ',' : |
| 398 |
if (qop) |
| 399 |
goto done ; |
| 400 |
cp++ ; /* otherwise ignore */ |
| 401 |
break ; |
| 402 |
|
| 403 |
case '!': |
| 404 |
if (qop) |
| 405 |
goto done ; |
| 406 |
cp++ ; |
| 407 |
if (*cp == '=') |
| 408 |
{ cp++ ; |
| 409 |
qop = NEQ ; |
| 410 |
} |
| 411 |
else |
| 412 |
qop = NOT ; |
| 413 |
goto done ; |
| 414 |
|
| 415 |
case ';': |
| 416 |
if (qop) |
| 417 |
goto done ; |
| 418 |
cp++ ; |
| 419 |
qop = PIPEQUERY ; |
| 420 |
goto done ; |
| 421 |
|
| 422 |
case '~': |
| 423 |
if (qop) |
| 424 |
goto done ; |
| 425 |
cp++ ; |
| 426 |
qop = LIKE ; |
| 427 |
goto done ; |
| 428 |
|
| 429 |
case '^': |
| 430 |
if (qop) |
| 431 |
goto done ; |
| 432 |
cp++ ; |
| 433 |
qop = XOR ; |
| 434 |
goto done ; |
| 435 |
|
| 436 |
case '<': |
| 437 |
if (qop) |
| 438 |
goto done ; |
| 439 |
cp++ ; |
| 440 |
if (*cp == '=') |
| 441 |
{ cp++ ; |
| 442 |
qop = LE ; |
| 443 |
} |
| 444 |
else |
| 445 |
qop = LT ; |
| 446 |
goto done ; |
| 447 |
|
| 448 |
case '>': /* Multiple meaning, >Tag with nothing on the left |
| 449 |
means FOLLOW tag */ |
| 450 |
if (qop) |
| 451 |
goto done ; |
| 452 |
cp++ ; |
| 453 |
if (*cp == '=') |
| 454 |
{ cp++ ; |
| 455 |
qop = GE ; |
| 456 |
} |
| 457 |
else if (*cp == '$') |
| 458 |
{ cp++ ; |
| 459 |
qop = FROM ; |
| 460 |
} |
| 461 |
else if (*cp == '?') |
| 462 |
{ cp++ ; |
| 463 |
qop = FIND ; |
| 464 |
} |
| 465 |
else |
| 466 |
qop = GT ; |
| 467 |
goto done ; |
| 468 |
|
| 469 |
case '$': /* Set operations */ |
| 470 |
if (qop) |
| 471 |
goto done ; |
| 472 |
cp++ ; |
| 473 |
if (*cp == '&') |
| 474 |
{ cp++ ; |
| 475 |
qop = SETAND ; |
| 476 |
} |
| 477 |
else if (*cp == '|') |
| 478 |
{ cp++ ; |
| 479 |
qop = SETOR ; |
| 480 |
} |
| 481 |
else if (*cp == '^') |
| 482 |
{ cp++ ; |
| 483 |
qop = SETXOR ; |
| 484 |
} |
| 485 |
else if (*cp == '-') |
| 486 |
{ cp++ ; |
| 487 |
qop = SETMINUS ; |
| 488 |
} |
| 489 |
else if (*cp == '/') |
| 490 |
{ cp++ ; |
| 491 |
qop = SETELSE ; |
| 492 |
} |
| 493 |
else if (*cp == '=') |
| 494 |
{ cp++ ; |
| 495 |
qop = SETDEFINE ; |
| 496 |
} |
| 497 |
|
| 498 |
if (qop) /* recognised set operator */ |
| 499 |
goto done ; |
| 500 |
/* otherwise interpreted as a named set */ |
| 501 |
if (!*item) |
| 502 |
{ qop = NAMEDSET ; /* to be reexamined when the word is complete */ |
| 503 |
*item = cp - 1 ; |
| 504 |
} |
| 505 |
break ; |
| 506 |
|
| 507 |
case '=': /* I treat = and == the same way */ |
| 508 |
if (qop) |
| 509 |
goto done ; |
| 510 |
cp++ ; |
| 511 |
if (*cp == '=') |
| 512 |
{ cp++ ; |
| 513 |
} |
| 514 |
qop = EQ; |
| 515 |
goto done ; |
| 516 |
|
| 517 |
case '&': /* I treat & and && the same way */ |
| 518 |
if (qop) |
| 519 |
goto done ; |
| 520 |
cp++ ; |
| 521 |
if (*cp == '&') |
| 522 |
{ cp++ ; |
| 523 |
} |
| 524 |
qop = AND ; |
| 525 |
goto done ; |
| 526 |
|
| 527 |
case '|': /* I treat | and || the same way */ |
| 528 |
if (qop) |
| 529 |
goto done ; |
| 530 |
cp++ ; |
| 531 |
if (*cp == '|') |
| 532 |
{ cp++ ; |
| 533 |
} |
| 534 |
qop = OR ; |
| 535 |
goto done ; |
| 536 |
|
| 537 |
case '#': |
| 538 |
if (qop) |
| 539 |
goto done ; |
| 540 |
cp++ ; |
| 541 |
qop = COMPOSITE_TAG ; |
| 542 |
goto done ; |
| 543 |
|
| 544 |
case ':': |
| 545 |
if (qop) |
| 546 |
goto done ; |
| 547 |
cp++ ; |
| 548 |
qop = VECTOR_TAG ; |
| 549 |
goto done ; |
| 550 |
|
| 551 |
case '+': case '-': case '*': case '/': |
| 552 |
if (context == CALCUL) |
| 553 |
switch (*cp) |
| 554 |
{ |
| 555 |
case '+': |
| 556 |
case '-': |
| 557 |
if (qop) |
| 558 |
goto done ; |
| 559 |
{ |
| 560 |
char *cq = cp ; |
| 561 |
int signe = 1 ; |
| 562 |
while (*cq) |
| 563 |
switch (*cq++) |
| 564 |
{ |
| 565 |
case '+': |
| 566 |
cp = cq ; |
| 567 |
continue ; |
| 568 |
case '-': |
| 569 |
signe = - signe ; |
| 570 |
cp = cq ; |
| 571 |
continue ; |
| 572 |
case ' ': |
| 573 |
continue ; |
| 574 |
default: |
| 575 |
goto signDone ; |
| 576 |
break ; |
| 577 |
} |
| 578 |
signDone: |
| 579 |
qop = (signe == 1 ? PLUS : MINUS) ; |
| 580 |
} |
| 581 |
goto done ; |
| 582 |
|
| 583 |
case '*': |
| 584 |
if (qop) |
| 585 |
goto done ; |
| 586 |
cp++ ; |
| 587 |
qop = MULTIPLY ; |
| 588 |
goto done ; |
| 589 |
|
| 590 |
case '/': |
| 591 |
if (qop) |
| 592 |
goto done ; |
| 593 |
cp++ ; |
| 594 |
qop = DIVIDE ; |
| 595 |
goto done ; |
| 596 |
|
| 597 |
} |
| 598 |
else ; /* ATTENTION: else fall thru onto default */ |
| 599 |
|
| 600 |
default: |
| 601 |
if (!*item) |
| 602 |
{ qop = TAG ; /* to be reexamined when the word is complete */ |
| 603 |
*item = cp ; |
| 604 |
} |
| 605 |
cp++ ; |
| 606 |
break ; |
| 607 |
} |
| 608 |
done: |
| 609 |
backup = *cp ; |
| 610 |
*cp = 0 ; |
| 611 |
return qop ; |
| 612 |
} |
| 613 |
|
| 614 |
/**************************************************************/ |
| 615 |
/**************************************************************/ |
| 616 |
/* Recursive construction of a tree of conditions */ |
| 617 |
/**************************************************************/ |
| 618 |
|
| 619 |
static KEY goodClass(KEY classe) |
| 620 |
{ |
| 621 |
KEY subClass = classe ; unsigned char c ; |
| 622 |
|
| 623 |
if (pickIsComposite(classe)) |
| 624 |
return classe; |
| 625 |
|
| 626 |
if (!pickIsA(&classe, &c)) |
| 627 |
return 0 ; |
| 628 |
|
| 629 |
return c ? subClass : classe ; /* return super class only if mask == 0 */ |
| 630 |
} |
| 631 |
|
| 632 |
/* Scans the cdt Tree |
| 633 |
looking for the occurence of a query operator |
| 634 |
in order of increasing priority |
| 635 |
*/ |
| 636 |
static BOOL cdtReorder(CDT *top, Stack s) |
| 637 |
{ |
| 638 |
CDT c, cc, new, ca, cb, cr, cl ; |
| 639 |
QOP q ; |
| 640 |
BOOL applyLeft, applyRight, setWhere ; |
| 641 |
|
| 642 |
/* Progressivelly transform the linear |
| 643 |
expression into a tree by moving every recogised |
| 644 |
expression in the left branch of as SUBEXP |
| 645 |
*/ |
| 646 |
|
| 647 |
/* A leading GT is a follow */ |
| 648 |
c = *top ; |
| 649 |
if (!c) |
| 650 |
return FALSE; |
| 651 |
while (c) |
| 652 |
{ |
| 653 |
if (c->qop == GT && |
| 654 |
(!c->up || |
| 655 |
c->up->qop == PIPEQUERY || |
| 656 |
(c->up->qop == SUBQUERY && c == c->up->left) |
| 657 |
)) |
| 658 |
c->qop = FOLLOW_TAG ; |
| 659 |
c = c->right ; |
| 660 |
} |
| 661 |
|
| 662 |
c = *top ; |
| 663 |
while(c) |
| 664 |
{ |
| 665 |
if (c->left) |
| 666 |
if (!cdtReorder(&(c->left), s)) |
| 667 |
return FALSE ; |
| 668 |
c = c->right ; |
| 669 |
} |
| 670 |
|
| 671 |
/* Now we reorder the d1 side recursively |
| 672 |
* We find highest operator and make of it a subexpression |
| 673 |
* In case of equality I work left to right as usual |
| 674 |
* i.e. the rightest binds more strongly |
| 675 |
* |
| 676 |
* This is wrong for MINUS which is not associative |
| 677 |
* so i change to leftest binds more strongly for MINUS |
| 678 |
*/ |
| 679 |
|
| 680 |
while (TRUE) |
| 681 |
{ |
| 682 |
cc = c = *top ; |
| 683 |
q = c->qop ; |
| 684 |
while(c->right) |
| 685 |
{ |
| 686 |
c = c->right ; |
| 687 |
/* if (c->qop >=q) rightest of given precedence */ |
| 688 |
if (c->qop > q || /* leftest of given precedence */ |
| 689 |
(q != MINUS && q == c->qop)) /* rightest if ! MINUS */ |
| 690 |
{ q = c->qop ; |
| 691 |
cc = c ; |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
if (q <= FOLLOW_TAG) /* only one of those between any pair of ;; */ |
| 696 |
{ int n = 0 ; |
| 697 |
c = cc ; |
| 698 |
while (c) |
| 699 |
{ switch (c->qop) |
| 700 |
{ |
| 701 |
case PIPEQUERY: |
| 702 |
n = 0 ; break ; |
| 703 |
case FIND: case FOLLOW_TAG: case FROM: |
| 704 |
if (n) |
| 705 |
{ messerror("Two occurences of FIND/FOLLOW/FROM in %s", |
| 706 |
stackText(s, (*top)->mark)) ; |
| 707 |
return FALSE ; |
| 708 |
} |
| 709 |
break ; |
| 710 |
default: break ; |
| 711 |
} |
| 712 |
c = c->up ; |
| 713 |
/* c = c->right ; leftest of given */ |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
if (q <= PIPEQUERY ) /* was <= TAG || ((q <= FOLLOW_TAG) && cc->right)) */ |
| 718 |
{ /* now search for PIPEQUERY */ |
| 719 |
c = *top ; cc = 0 ; |
| 720 |
while(c) |
| 721 |
{ |
| 722 |
if (c->qop == PIPEQUERY) /* rightest of given precedence */ |
| 723 |
{ cc = c ; q = PIPEQUERY ;} |
| 724 |
c = c->right ; |
| 725 |
} |
| 726 |
if (!cc) break ; |
| 727 |
} |
| 728 |
|
| 729 |
setWhere = FALSE ; |
| 730 |
applyLeft = FALSE ; applyRight = TRUE ; /* default is unary */ |
| 731 |
if (q == NEIGHBOURS) /* Solitary operator */ |
| 732 |
{ cc->qop = NEIGHBOURS ; |
| 733 |
setWhere = TRUE ; |
| 734 |
applyRight = FALSE ; |
| 735 |
} |
| 736 |
else if (q == GREP) /* Unary operator */ |
| 737 |
{ char *cp ; |
| 738 |
if (!cc->right) |
| 739 |
{ messerror("Nothing to the right of %s: %s", |
| 740 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 741 |
return FALSE ; |
| 742 |
} |
| 743 |
cp = stackText(s,cc->right->mark) ; |
| 744 |
while (*cp=='*' || *cp == '?') cp++ ; |
| 745 |
if (strlen(cp) < 3) |
| 746 |
{ messout("The text to the right of GREP should have at least 3 characters %s: %s", |
| 747 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 748 |
return FALSE ; |
| 749 |
} |
| 750 |
} |
| 751 |
else if (q == WEBQUERY) /* Unary operator */ |
| 752 |
{ char *cp ; |
| 753 |
if (! webQueryFunc) |
| 754 |
{ |
| 755 |
messout ("WEBQUERY is not available in this version of acedb, sorry") ; |
| 756 |
return FALSE ; |
| 757 |
} |
| 758 |
if (!cc->right) |
| 759 |
{ |
| 760 |
messout ("Nothing to the right of %s: %s", |
| 761 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 762 |
return FALSE ; |
| 763 |
} |
| 764 |
cp = stackText(s,cc->right->mark) ; |
| 765 |
while (*cp=='*' || *cp == '?') cp++ ; |
| 766 |
if (strlen(cp) < 3) |
| 767 |
{ |
| 768 |
messout("The text to the right of WEBQUERY should have at least 3 characters %s: %s", |
| 769 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 770 |
return FALSE ; |
| 771 |
} |
| 772 |
} |
| 773 |
else if (q == NOT) /* Unary operator */ |
| 774 |
{ if (!cc->right) |
| 775 |
{ messout("Nothing to the right of %s: %s", |
| 776 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 777 |
return FALSE ; |
| 778 |
} |
| 779 |
} |
| 780 |
else if (q == IS) /* Unary operator */ |
| 781 |
{ if (!cc->right) |
| 782 |
{ messerror("Nothing to the right of %s: %s", |
| 783 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 784 |
return FALSE ; |
| 785 |
} |
| 786 |
if (cc->right->qop != TEXT && |
| 787 |
cc->right->qop < LT && |
| 788 |
cc->right->qop > LIKE) |
| 789 |
{ messout("IS must be followed by a text or a comparator: %s", |
| 790 |
stackText(s,cc->right->mark)) ; |
| 791 |
return FALSE ; |
| 792 |
} |
| 793 |
} |
| 794 |
else if (q == CLASS) |
| 795 |
{ if (!cc->right) |
| 796 |
{ messerror("Nothing to the right of %s: %s", |
| 797 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 798 |
return FALSE ; |
| 799 |
} |
| 800 |
cr = cc->right ; |
| 801 |
ca = cc->up ; cb = cr->right ; |
| 802 |
|
| 803 |
{ /* Autocomplete to a Class */ |
| 804 |
KEY classe = 0; |
| 805 |
|
| 806 |
if (lexword2key(stackText(s,cr->mark), &classe, _VClass)) |
| 807 |
{ |
| 808 |
cr->n.classe = goodClass(classe) ; |
| 809 |
cr->qop = CLASS ; |
| 810 |
} |
| 811 |
else |
| 812 |
while (lexNext(_VClass,&classe)) |
| 813 |
if (pickMatch |
| 814 |
(name(classe), |
| 815 |
stackText(s,cr->mark) )) |
| 816 |
{ |
| 817 |
cr->n.classe = goodClass(classe) ; |
| 818 |
if (strcasecmp(stackText(s,cr->mark), |
| 819 |
name(classe))) |
| 820 |
messout("Autocompleting CLASS %s to CLASS %s", |
| 821 |
stackText(s,cr->mark), |
| 822 |
name(classe)) ; |
| 823 |
|
| 824 |
break ; |
| 825 |
} |
| 826 |
if (!classe) |
| 827 |
{ messout( "CLASS <class> Missing or unrecognised <class> at %s: %s ", |
| 828 |
qName[cc->qop], stackText(s,cr->mark)) ; |
| 829 |
return FALSE ; |
| 830 |
} |
| 831 |
} |
| 832 |
/* now transform it into a subexp */ |
| 833 |
|
| 834 |
if (cr->qop != CLASS) |
| 835 |
{ messout( "Missing or unrecognised Class after %s: %s", |
| 836 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 837 |
return FALSE ; |
| 838 |
} |
| 839 |
} |
| 840 |
else if (q == FIND ) /* FIND Class */ |
| 841 |
{ if (!cc->right) |
| 842 |
{ messerror("Nothing to the right of %s: %s", |
| 843 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 844 |
return FALSE ; |
| 845 |
} |
| 846 |
cr = cc->right ; |
| 847 |
ca = cc->up ; cb = cr->right ; |
| 848 |
|
| 849 |
{ /* Autocomplete to a Class */ |
| 850 |
KEY classe = 0; |
| 851 |
|
| 852 |
if (lexword2key(stackText(s,cr->mark), &classe, _VClass)) |
| 853 |
{ |
| 854 |
cr->n.classe = goodClass(classe) ; |
| 855 |
cr->qop = CLASS ; |
| 856 |
} |
| 857 |
else |
| 858 |
while (lexNext(_VClass,&classe)) |
| 859 |
if (pickMatch |
| 860 |
(name(classe), |
| 861 |
stackText(s,cr->mark) )) |
| 862 |
{ cr->qop = CLASS ; |
| 863 |
cr->n.classe = goodClass(classe) ; |
| 864 |
if (strcasecmp (stackText(s,cr->mark),name(classe))) |
| 865 |
messout("Autocompleting FIND %s to FIND %s", |
| 866 |
stackText(s,cr->mark), |
| 867 |
name(classe)) ; |
| 868 |
break ; |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
if (cr->qop != CLASS) |
| 873 |
{ messout( "Missing or unrecognised Class #%s# after FIND", |
| 874 |
stackText(s,cr->mark)) ; |
| 875 |
return FALSE ; |
| 876 |
} |
| 877 |
if (cr->left) |
| 878 |
{ messout( "Sorry, parsing error after a FIND in: %s", |
| 879 |
stackText(s, cc->mark)) ; |
| 880 |
return FALSE ; |
| 881 |
} |
| 882 |
setWhere = TRUE ; |
| 883 |
} |
| 884 |
else if (q == EXPAND) /* EXPAND a keyset, may 15 2003, */ |
| 885 |
{ |
| 886 |
applyRight = FALSE ; |
| 887 |
} |
| 888 |
else if (q == FOLLOW_TAG) /* FOLLOW tag */ |
| 889 |
{ |
| 890 |
if (!cc->right || |
| 891 |
(cc->right && cc->right->qop == PIPEQUERY)) |
| 892 |
{ |
| 893 |
messerror("Nothing to the right of %s: %s", |
| 894 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 895 |
return FALSE ; |
| 896 |
} |
| 897 |
else |
| 898 |
{ |
| 899 |
cr = cc->right ; |
| 900 |
ca = cc->up ; cb = cr->right ; |
| 901 |
|
| 902 |
if (cr->qop == TEXT) |
| 903 |
{ /* Autocomplete to a tag */ |
| 904 |
KEY t = 0; |
| 905 |
while(lexNext(0,&t)) |
| 906 |
if (pickMatch(name(t), |
| 907 |
stackText(s,cr->mark))) |
| 908 |
{ cr->qop = TAG ; |
| 909 |
cr->n.tag = t ; |
| 910 |
if (strcasecmp (stackText(s,cr->mark),name(t))) |
| 911 |
messout("Autocompleting >%s to >%s", |
| 912 |
stackText(s,cr->mark), |
| 913 |
name(t)) ; |
| 914 |
break ; |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
if (!isLocatorOp (cr->qop) && |
| 919 |
!(cr->qop == SUBEXP && |
| 920 |
cr->left && isLocatorOp (cr->left->qop))) |
| 921 |
{ messout("Sorry, unrecognized expression to the right of %s: %s\n%s%s", |
| 922 |
qName[cc->qop], stackText(s, cc->mark), |
| 923 |
"// Should be FOLLOW tag or FOLLOW tag#tag\n", |
| 924 |
"// Please use table maker for more complex operations\n") ; |
| 925 |
return FALSE ; |
| 926 |
} |
| 927 |
setWhere = TRUE ; |
| 928 |
} |
| 929 |
} |
| 930 |
else if (q == COUNT || q == AVG || q == SUM || q == MIN || q == MAX) |
| 931 |
/* COUNT <locator> */ |
| 932 |
{ cr = cc->right ; |
| 933 |
if (!cr) |
| 934 |
{ |
| 935 |
messerror("Nothing to the right of %s: %s", |
| 936 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 937 |
return FALSE ; |
| 938 |
} |
| 939 |
if (cr->qop == TEXT) |
| 940 |
{ /* Autocomplete to a tag */ |
| 941 |
KEY t = 0; |
| 942 |
while(lexNext(0,&t)) |
| 943 |
if (pickMatch(name(t), |
| 944 |
stackText(s,cr->mark))) |
| 945 |
{ cr->qop = TAG ; |
| 946 |
cr->n.tag = t ; |
| 947 |
if (strcasecmp (stackText(s,cr->mark),name(t))) |
| 948 |
messout("Autocompleting ... %s to ... %s", |
| 949 |
stackText(s,cr->mark), |
| 950 |
name(t)) ; |
| 951 |
break ; |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
if (cr->qop != TAG && cr->qop != SUBEXP && |
| 956 |
!(cc->qop == COUNT && cr->qop == SUBQUERY)) |
| 957 |
{ messout( "Unrecognised expression after %s: %s", |
| 958 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 959 |
return FALSE ; |
| 960 |
} |
| 961 |
} |
| 962 |
else if (q == PIPEQUERY) /* optionally binary operator */ |
| 963 |
{ |
| 964 |
if (cc->left) /* was buried automatically */ |
| 965 |
{ |
| 966 |
new = CDTalloc() ; |
| 967 |
new->left = cc->left ; new->right = cc->right ; new->up = cc ; |
| 968 |
cc->left = new ; cc->right = 0 ; |
| 969 |
if (new->left) new->left->up = new ; |
| 970 |
if (new->right) new->right->up = new ; |
| 971 |
new->qop = cc->qop ; cc->qop = SUBEXP ; |
| 972 |
continue ; |
| 973 |
} |
| 974 |
if (cc->up && cc->up->qop != PIPEQUERY) |
| 975 |
applyLeft = TRUE ; |
| 976 |
} |
| 977 |
|
| 978 |
else if (cc->qop == PLUS || cc->qop == MINUS) /* optionally unary */ |
| 979 |
{ |
| 980 |
if (cc->up && |
| 981 |
cc->up->qop != PIPEQUERY && |
| 982 |
cc->up->qop != PLUS && |
| 983 |
cc->up->qop != MINUS && |
| 984 |
cc != cc->up->left) /* buried as a () or {} or [] */ |
| 985 |
applyLeft = TRUE ; |
| 986 |
|
| 987 |
if (!cc->right || cc->right->qop == PIPEQUERY) |
| 988 |
{ messout("Missing expression to the right of %s: %s", |
| 989 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 990 |
return FALSE ; |
| 991 |
} |
| 992 |
} |
| 993 |
else /* binary operator */ |
| 994 |
{ |
| 995 |
if (cc->up && cc->up->qop != PIPEQUERY && |
| 996 |
cc != cc->up->left) /* buried as a () or {} or [] */ |
| 997 |
applyLeft = TRUE ; |
| 998 |
else |
| 999 |
{ messout("Missing expression to the left of %s: %s", |
| 1000 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 1001 |
return FALSE ; |
| 1002 |
} |
| 1003 |
|
| 1004 |
if (!cc->right || cc->right->qop == PIPEQUERY) |
| 1005 |
{ messout("Missing expression to the right of %s: %s", |
| 1006 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 1007 |
return FALSE ; |
| 1008 |
} |
| 1009 |
if (cc->qop == VECTOR_TAG && /* FOLLOW tag */ |
| 1010 |
cc->right->qop != NUMBER) |
| 1011 |
{ |
| 1012 |
messout("Sorry, unrecognized expression to the left of %s: %s\n", |
| 1013 |
qName[cc->qop], stackText(s, cc->mark), |
| 1014 |
"// Should be tag:number#tag\n", |
| 1015 |
"// Please use table maker for more complex operations\n") ; |
| 1016 |
/* doInterrupt = TRUE ; */ |
| 1017 |
return FALSE ; |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
/* turn it into a SUBEXP */ |
| 1023 |
|
| 1024 |
new = CDTalloc() ; |
| 1025 |
|
| 1026 |
cl = cr = ca = cb = 0 ; |
| 1027 |
if (applyRight) |
| 1028 |
{ |
| 1029 |
cr = cc->right ; |
| 1030 |
if (cr) |
| 1031 |
{ |
| 1032 |
cb = cr ? cr->right : 0 ; |
| 1033 |
new->right = cr ; cr->up = new ; cr->right = 0 ; |
| 1034 |
cc->right = cb ; if (cb) cb->up = cc ; |
| 1035 |
} |
| 1036 |
|
| 1037 |
} |
| 1038 |
if (applyLeft) |
| 1039 |
{ |
| 1040 |
cl = cc->up ; |
| 1041 |
if (*top == cl) |
| 1042 |
*top = cc ; |
| 1043 |
if (cl) |
| 1044 |
{ |
| 1045 |
ca = cl->up ; |
| 1046 |
new->left = cl ; cl->up = new ; cl->right = 0 ; |
| 1047 |
|
| 1048 |
if (ca) /* possibly alreay points on cc */ |
| 1049 |
{ |
| 1050 |
if (ca->left == cl) |
| 1051 |
ca->left = cc ; |
| 1052 |
else if (ca->right == cl) |
| 1053 |
ca->right = cc ; |
| 1054 |
} |
| 1055 |
cc->up = ca; |
| 1056 |
} |
| 1057 |
|
| 1058 |
} |
| 1059 |
|
| 1060 |
|
| 1061 |
new->qop = cc->qop ; |
| 1062 |
new->up = cc ; |
| 1063 |
if (cc->left) |
| 1064 |
{ messout("Sorry, kernel error while parsing %s: %s" , |
| 1065 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 1066 |
return FALSE ; |
| 1067 |
} |
| 1068 |
cc->left = new ; |
| 1069 |
cc->qop = setWhere ? PIPEQUERY : SUBEXP ; |
| 1070 |
} |
| 1071 |
return TRUE ; |
| 1072 |
} |
| 1073 |
|
| 1074 |
/***********************/ |
| 1075 |
|
| 1076 |
/* construct a chain of all operators at a given level */ |
| 1077 |
static CDT cdtConstructLevel(char *text, Stack s, int context) |
| 1078 |
{ |
| 1079 |
CDT cdt = 0, top = 0, next ; |
| 1080 |
char dummy ; |
| 1081 |
char *item, *cp ; |
| 1082 |
QOP qop ; |
| 1083 |
KEY tag; |
| 1084 |
float x ; |
| 1085 |
|
| 1086 |
if (!text || !*text) |
| 1087 |
return 0 ; |
| 1088 |
cdtItem(0,&item, context) ; |
| 1089 |
while ((qop = cdtItem(text, &item, context))) |
| 1090 |
{ |
| 1091 |
next = CDTalloc() ; |
| 1092 |
if (!top) |
| 1093 |
top = next ; |
| 1094 |
if (cdt) |
| 1095 |
cdt->right = next ; |
| 1096 |
next->up = cdt ; |
| 1097 |
cdt = next ; |
| 1098 |
cdt->qop = qop ; |
| 1099 |
switch(qop) |
| 1100 |
{ |
| 1101 |
case TAG: |
| 1102 |
if (!strcasecmp(item,"FOLLOW")) |
| 1103 |
{ cdt->qop = FOLLOW_TAG ; |
| 1104 |
break ; |
| 1105 |
} |
| 1106 |
if (!strcasecmp(item,"EXPAND")) |
| 1107 |
{ cdt->qop = EXPAND ; |
| 1108 |
break ; |
| 1109 |
} |
| 1110 |
else if (!strcasecmp(item,"FIND")) |
| 1111 |
{ cdt->qop = FIND ; |
| 1112 |
break ; |
| 1113 |
} |
| 1114 |
else if (!strcasecmp(item,"FROM")) |
| 1115 |
{ cdt->qop = FROM ; |
| 1116 |
break ; |
| 1117 |
} |
| 1118 |
else if (!strcasecmp(item,"WHERE")) |
| 1119 |
{ cdt->qop = PIPEQUERY ; /* synonym of WHERE */ |
| 1120 |
break ; |
| 1121 |
} |
| 1122 |
else if (!strcmp(item,"NEQ")) |
| 1123 |
{ cdt->qop = NEQ ; |
| 1124 |
break ; |
| 1125 |
} |
| 1126 |
else if (!strcmp(item,"LIKE")) |
| 1127 |
{ cdt->qop = LIKE ; |
| 1128 |
break ; |
| 1129 |
} |
| 1130 |
else if (!strcmp(item,"AND")) |
| 1131 |
{ cdt->qop = AND ; |
| 1132 |
break ; |
| 1133 |
} |
| 1134 |
else if (!strcmp(item,"OR")) |
| 1135 |
{ cdt->qop = OR ; |
| 1136 |
break ; |
| 1137 |
} |
| 1138 |
else if (!strcmp(item,"NOT")) |
| 1139 |
{ cdt->qop = NOT ; |
| 1140 |
break ; |
| 1141 |
} |
| 1142 |
else if (!strcmp(item,"CLASS")) |
| 1143 |
{ cdt->qop = CLASS ; |
| 1144 |
break ; |
| 1145 |
} |
| 1146 |
else if (!strcmp(item,"IS") || !strcmp(item,"Is") || |
| 1147 |
!strcmp(item, "SELF") || !strcmp(item, "Self")) |
| 1148 |
{ cdt->qop = IS ; |
| 1149 |
break ; |
| 1150 |
} |
| 1151 |
else if (!strcmp(item,"COUNT")) |
| 1152 |
{ cdt->qop = COUNT ; |
| 1153 |
break ; |
| 1154 |
} |
| 1155 |
else if (!strcmp(item,"AVG")) |
| 1156 |
{ cdt->qop = AVG ; |
| 1157 |
break ; |
| 1158 |
} |
| 1159 |
else if (!strcmp(item,"MIN")) |
| 1160 |
{ cdt->qop = MIN ; |
| 1161 |
break ; |
| 1162 |
} |
| 1163 |
else if (!strcmp(item,"MAX")) |
| 1164 |
{ cdt->qop = MAX ; |
| 1165 |
break ; |
| 1166 |
} |
| 1167 |
else if (!strcmp(item,"SUM")) |
| 1168 |
{ cdt->qop = SUM ; |
| 1169 |
break ; |
| 1170 |
} |
| 1171 |
else if (!strcmp(item,"XOR")) |
| 1172 |
{ cdt->qop = XOR ; |
| 1173 |
break ; |
| 1174 |
} |
| 1175 |
else if (!strcmp(item,"SETOR")) |
| 1176 |
{ cdt->qop = SETOR ; |
| 1177 |
break ; |
| 1178 |
} |
| 1179 |
else if (!strcmp(item,"SETXOR")) |
| 1180 |
{ cdt->qop = SETXOR ; |
| 1181 |
break ; |
| 1182 |
} |
| 1183 |
else if (!strcmp(item,"SETAND")) |
| 1184 |
{ cdt->qop = SETAND ; |
| 1185 |
break ; |
| 1186 |
} |
| 1187 |
else if (!strcmp(item,"SETMINUS")) |
| 1188 |
{ cdt->qop = SETMINUS ; |
| 1189 |
break ; |
| 1190 |
} |
| 1191 |
else if (!strcmp(item,"SETELSE")) |
| 1192 |
{ cdt->qop = SETELSE ; |
| 1193 |
break ; |
| 1194 |
} |
| 1195 |
else if (!strcmp(item,"SETDEFINE")) |
| 1196 |
{ cdt->qop = SETDEFINE ; |
| 1197 |
break ; |
| 1198 |
} |
| 1199 |
else if (!strcasecmp(item,"NEIGHBOURS")) |
| 1200 |
{ cdt->qop = NEIGHBOURS ; |
| 1201 |
break ; |
| 1202 |
} |
| 1203 |
else if (!strcasecmp(item,"GREP")) |
| 1204 |
{ cdt->qop = GREP ; |
| 1205 |
break ; |
| 1206 |
} |
| 1207 |
else if (webQueryFunc && !strcasecmp(item,"WEBQUERY")) |
| 1208 |
{ cdt->qop = WEBQUERY ; |
| 1209 |
break ; |
| 1210 |
} |
| 1211 |
else if (!strcmp(item,"GE")) |
| 1212 |
{ cdt->qop = GE ; |
| 1213 |
break ; |
| 1214 |
} |
| 1215 |
else if (!strcmp(item,"GT")) |
| 1216 |
{ cdt->qop = GT ; |
| 1217 |
break ; |
| 1218 |
} |
| 1219 |
else if (!strcmp(item,"LE")) |
| 1220 |
{ cdt->qop = LE ; |
| 1221 |
break ; |
| 1222 |
} |
| 1223 |
else if (!strcmp(item,"LT")) |
| 1224 |
{ cdt->qop = LT ; |
| 1225 |
break ; |
| 1226 |
} |
| 1227 |
else if (!strcmp(item,"NEXT")) |
| 1228 |
{ cdt->n.tag = _bsRight ; |
| 1229 |
break ; |
| 1230 |
} |
| 1231 |
else if (!strcmp(item,"HERE")) |
| 1232 |
{ cdt->n.tag = _bsHere ; |
| 1233 |
break ; |
| 1234 |
} |
| 1235 |
/* NOTE: the order of the next two clauses is important, |
| 1236 |
we need to recognise numbers in preference to tagnames. |
| 1237 |
Tagnames which are valid numbers are illegal and flagged, |
| 1238 |
but the read-models process on a models.wrm file |
| 1239 |
with them can still put tags with names like "10" |
| 1240 |
into class zero. Hence we don't look for tags |
| 1241 |
until after we've looked from numbers. |
| 1242 |
*/ |
| 1243 |
else if (sscanf (item,"%f%c",&x,&dummy) == 1) |
| 1244 |
/* dummy trick checks no unmatched characters */ |
| 1245 |
{ cdt->qop = NUMBER; |
| 1246 |
cdt->n.x = x ; |
| 1247 |
/* fall through to match 1967 with a _Text 1967 */ |
| 1248 |
} |
| 1249 |
else if (lexword2key(item, &tag, _VSystem)) |
| 1250 |
{ cdt->n.tag = tag ; |
| 1251 |
/* fall through to match tag with a _Text */ |
| 1252 |
} |
| 1253 |
else |
| 1254 |
{ cdt->qop = TEXT; |
| 1255 |
/* fall through */ |
| 1256 |
} |
| 1257 |
case TEXT: |
| 1258 |
cdt->mark = stackMark(s) ; |
| 1259 |
if ((cp = freeunprotect(item))) |
| 1260 |
pushText(s,cp) ; |
| 1261 |
break ; |
| 1262 |
|
| 1263 |
case SUBEXP : case NAMEDSET : case CALCUL: case SUBQUERY: |
| 1264 |
cdt->mark = stackMark(s) ; |
| 1265 |
pushText(s,item) ; |
| 1266 |
break ; |
| 1267 |
default: |
| 1268 |
break ; |
| 1269 |
} |
| 1270 |
} |
| 1271 |
return top ; |
| 1272 |
} |
| 1273 |
|
| 1274 |
/***********************/ |
| 1275 |
/* Expands subexpressions presented in parenthesis to the scanner */ |
| 1276 |
|
| 1277 |
static BOOL cdtExpand(CDT cdt, Stack s, int context) ; |
| 1278 |
|
| 1279 |
static CDT cdtConstructExpand(char *text, Stack s, int context) |
| 1280 |
{ |
| 1281 |
CDT cdt = cdtConstructLevel(text,s, context) ; |
| 1282 |
cdtExpand(cdt,s, context) ; |
| 1283 |
return cdt ; |
| 1284 |
} |
| 1285 |
|
| 1286 |
static BOOL cdtExpand(CDT cc, Stack s, int context) |
| 1287 |
{ |
| 1288 |
while(cc) |
| 1289 |
{ |
| 1290 |
if (cc->qop == SUBEXP || cc->qop == SUBQUERY || cc->qop == CALCUL) |
| 1291 |
{ cc->left = cdtConstructExpand(stackText(s,cc->mark), s, |
| 1292 |
cc->qop == CALCUL ? CALCUL : |
| 1293 |
cc->qop == SUBQUERY ? 0 : context) ; |
| 1294 |
if (cc->left) cc->left->up = cc ; |
| 1295 |
} |
| 1296 |
cc = cc->right ; |
| 1297 |
} |
| 1298 |
return TRUE ; |
| 1299 |
} |
| 1300 |
|
| 1301 |
/**********/ |
| 1302 |
|
| 1303 |
static CDT cdtRemoveSubExp(Stack s, CDT cc, BOOL *problemp) |
| 1304 |
{ |
| 1305 |
if (cc->left) |
| 1306 |
cc->left = cdtRemoveSubExp(s, cc->left, problemp) ; |
| 1307 |
if (cc->right) |
| 1308 |
cc->right = cdtRemoveSubExp(s, cc->right, problemp) ; |
| 1309 |
|
| 1310 |
if (cc->qop == VECTOR_TAG ) /* FOLLOW tag */ |
| 1311 |
{ |
| 1312 |
if (!cc->right) |
| 1313 |
{ *problemp = TRUE ; |
| 1314 |
messerror("Nothing to the right of %s: %s", |
| 1315 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 1316 |
return cc ; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if (!cc->left) |
| 1320 |
{ *problemp = TRUE ; |
| 1321 |
messerror("Nothing to the left of %s: %s", |
| 1322 |
qName[cc->qop], stackText(s, cc->mark)) ; |
| 1323 |
return cc ; |
| 1324 |
} |
| 1325 |
if (cc->right->qop != NUMBER || |
| 1326 |
!isLocatorOp (cc->left->qop)) |
| 1327 |
{ *problemp = TRUE ; |
| 1328 |
messout("Sorry, unrecognized expression around %s: %s\n", |
| 1329 |
qName[cc->qop], stackText(s, cc->mark), |
| 1330 |
"// Should be tag:number\n", |
| 1331 |
"// Please use table maker for more complex operations\n") ; |
| 1332 |
return FALSE ; |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
if (cc->qop != SUBEXP) |
| 1337 |
return cc ; |
| 1338 |
|
| 1339 |
if (cc->right) |
| 1340 |
{ *problemp = TRUE ; |
| 1341 |
messout("Warning: Please reformulate your query, the () are bizare in %s", stackText(s,0)) ; |
| 1342 |
return cc ; |
| 1343 |
} |
| 1344 |
if (cc->left) |
| 1345 |
{ CDT cl = cc->left ; |
| 1346 |
cc->left->up = cc->up ; |
| 1347 |
CDTfree(cc) ; |
| 1348 |
return cl ; |
| 1349 |
} |
| 1350 |
return cc ; |
| 1351 |
} |
| 1352 |
|
| 1353 |
/**********/ |
| 1354 |
/* Destruction */ |
| 1355 |
void condDestroy(COND cond) |
| 1356 |
{ |
| 1357 |
if (cond && cond->magic == &MAGIC) |
| 1358 |
{ stackDestroy (cond->stack) ; |
| 1359 |
cdtDestroy(cond->cdt) ; |
| 1360 |
CONDfree(cond) ; |
| 1361 |
cond = 0 ; |
| 1362 |
} |
| 1363 |
if (cond && cond->magic != &MAGIC) |
| 1364 |
invokeDebugger() ; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/**********/ |
| 1368 |
/* Initialisation part */ |
| 1369 |
BOOL condConstruct(char *text, COND* cdp) |
| 1370 |
{ |
| 1371 |
COND cond = 0 ; |
| 1372 |
|
| 1373 |
while(*text == ' ') |
| 1374 |
text++ ; |
| 1375 |
if (!text || !*text || !checkParentheses (text)) |
| 1376 |
return FALSE ; |
| 1377 |
|
| 1378 |
cond = CONDalloc() ; |
| 1379 |
|
| 1380 |
cond->stack = stackCreate(12*strlen(text)) ; /* wild big guess */ |
| 1381 |
pushText(cond->stack,text) ; |
| 1382 |
cond->cdt = cdtConstructLevel(text, cond->stack, 0) ; |
| 1383 |
if ( cdtExpand(cond->cdt,cond->stack, 0) |
| 1384 |
&& cdtReorder(&(cond->cdt),cond->stack) ) |
| 1385 |
{ BOOL problem = FALSE ; |
| 1386 |
/* cdtDump(cond->stack, cond->cdt, 0, FALSE) ; */ |
| 1387 |
cond->cdt = cdtRemoveSubExp(cond->stack, cond->cdt, &problem) ; |
| 1388 |
if (problem) |
| 1389 |
{ |
| 1390 |
condDestroy(cond) ; |
| 1391 |
*cdp = 0 ; |
| 1392 |
return FALSE ; |
| 1393 |
} |
| 1394 |
*cdp = cond ; |
| 1395 |
return TRUE ; |
| 1396 |
} |
| 1397 |
else |
| 1398 |
{ condDestroy(cond) ; |
| 1399 |
*cdp = 0 ; |
| 1400 |
return FALSE ; |
| 1401 |
} |
| 1402 |
} |
| 1403 |
|
| 1404 |
/**********/ |
| 1405 |
/* Number comparisons */ |
| 1406 |
static BOOL condCheck (float x, QOP qop, float y) |
| 1407 |
{ |
| 1408 |
double delta = x - y , d2 = x * y ; |
| 1409 |
BOOL egaux = FALSE ; |
| 1410 |
if ( |
| 1411 |
(x == 0 && y == 0) || |
| 1412 |
(delta * delta < d2 * .25e-12) |
| 1413 |
) |
| 1414 |
egaux = TRUE ; |
| 1415 |
|
| 1416 |
switch(qop) |
| 1417 |
{ |
| 1418 |
case LIKE: |
| 1419 |
if ( |
| 1420 |
(x == 0 && y == 0) || |
| 1421 |
(delta * delta < d2 * .25e-2) /* 5% error rate */ |
| 1422 |
) |
| 1423 |
return TRUE ; |
| 1424 |
return FALSE ; |
| 1425 |
case EQ: |
| 1426 |
return egaux ; |
| 1427 |
case NEQ: |
| 1428 |
return !egaux ; |
| 1429 |
case LE: |
| 1430 |
return egaux || delta < 0 ; |
| 1431 |
case LT: |
| 1432 |
return !egaux && delta < 0 ; |
| 1433 |
case GE: |
| 1434 |
return egaux || delta > 0 ; |
| 1435 |
case GT: |
| 1436 |
return !egaux && delta > 0 ; ; |
| 1437 |
default: |
| 1438 |
messcrash("Unknown operator %d in condCheck.",qop) ; |
| 1439 |
} |
| 1440 |
return FALSE ; /* for compiler happiness */ |
| 1441 |
} |
| 1442 |
/**********/ |
| 1443 |
/* Date comparisons remplacement de condCheckDate |
| 1444 |
par timeComparison mhmp 22.10.98 */ |
| 1445 |
|
| 1446 |
/**********/ |
| 1447 |
/* Time comparisons |
| 1448 |
suppress that, because nearly anything is a date |
| 1449 |
so it creates havoc in untyped string comparisons |
| 1450 |
|
| 1451 |
static BOOL condCheckTime (char *cp, QOP qop, char *cq) |
| 1452 |
{ float x, y ; |
| 1453 |
if ((x = (float) timeParse(cp)) && |
| 1454 |
(y = (float) timeParse(cq))) |
| 1455 |
return condCheck (x, qop, y) ; |
| 1456 |
else |
| 1457 |
return FALSE ; |
| 1458 |
} |
| 1459 |
*/ |
| 1460 |
/* String comparisons */ |
| 1461 |
static BOOL condCheckText (char *cp, QOP qop, char *cq) |
| 1462 |
{ |
| 1463 |
switch(qop) |
| 1464 |
{ |
| 1465 |
case EQ: |
| 1466 |
return pickMatch(cp, cq) ? TRUE : FALSE ; |
| 1467 |
case LIKE: |
| 1468 |
return regExpMatch(cp, cq) ? TRUE : FALSE ; |
| 1469 |
case NEQ: |
| 1470 |
return !pickMatch(cp, cq) ? TRUE : FALSE ; |
| 1471 |
case LE: |
| 1472 |
return lexstrcmp(cp,cq) <= 0 ? TRUE : FALSE ; |
| 1473 |
case LT: |
| 1474 |
return lexstrcmp(cp,cq) < 0 ? TRUE : FALSE ; |
| 1475 |
case GE: |
| 1476 |
return lexstrcmp(cp,cq) >= 0 ? TRUE : FALSE ; |
| 1477 |
case GT: |
| 1478 |
return lexstrcmp(cp,cq) > 0 ? TRUE : FALSE ; |
| 1479 |
default: |
| 1480 |
messcrash("Unknown operator %d in condCheckText.",qop) ; |
| 1481 |
} |
| 1482 |
return FALSE ; /* for compiler happiness */ |
| 1483 |
} |
| 1484 |
|
| 1485 |
/*******************************/ |
| 1486 |
static BOOL writeMess = TRUE ; |
| 1487 |
static char* myName = 0 ; |
| 1488 |
static void querySetTextName (char *cp) |
| 1489 |
{ |
| 1490 |
messfree(myName) ; |
| 1491 |
if (cp) myName = strnew (cp, 0) ; |
| 1492 |
} |
| 1493 |
|
| 1494 |
static BOOL myNextName(KEY key, char **cpp) |
| 1495 |
{ |
| 1496 |
if (key <= _LastC) |
| 1497 |
{ |
| 1498 |
if (*cpp) |
| 1499 |
return FALSE ; |
| 1500 |
else |
| 1501 |
{ *cpp = myName ; return myName ? TRUE : FALSE ; } |
| 1502 |
} |
| 1503 |
return nextName (key, cpp) ; |
| 1504 |
} |
| 1505 |
|
| 1506 |
/************************************************************************/ |
| 1507 |
|
| 1508 |
static BindexFindResult condMatch(Stack s, KEY key, OBJ* objp, CDT cdt) |
| 1509 |
{ |
| 1510 |
KEY k ; BindexFindResult found ; |
| 1511 |
char *cp ; float f ; int i = 0 ; mytime_t tm ; |
| 1512 |
/* QOP oper ; mhmp 22.10.98 */ |
| 1513 |
|
| 1514 |
if (fuzzy && (*objp)) return BINDEX_TAG_UNCLEAR ; /* obj already open, use true search */ |
| 1515 |
if (cdt) |
| 1516 |
switch (cdt->qop) |
| 1517 |
{ |
| 1518 |
case FOLLOW_TAG: |
| 1519 |
messout("Internal error : condMatch should not parse FOLLOW") ; |
| 1520 |
return BINDEX_TAG_ABSENT ; |
| 1521 |
case WHERE: |
| 1522 |
messout("Internal error : condMatch should not parse WHERE") ; |
| 1523 |
return BINDEX_TAG_ABSENT ; |
| 1524 |
case FIND: |
| 1525 |
messout("Internal error : condMatch should not parse FIND") ; |
| 1526 |
return BINDEX_TAG_ABSENT ; |
| 1527 |
case FROM: |
| 1528 |
messout("Sorry: set operation FROM not yet implemented") ; |
| 1529 |
return BINDEX_TAG_ABSENT ; |
| 1530 |
case SUBQUERY: |
| 1531 |
case NAMEDSET: case SETDEFINE: case NEIGHBOURS: |
| 1532 |
case SETOR: case SETAND: case SETXOR: case SETMINUS: case SETELSE: |
| 1533 |
messout("Internal error : condMatch should not parse a SET operation") ; |
| 1534 |
return BINDEX_TAG_ABSENT ; |
| 1535 |
case OR: |
| 1536 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1537 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1538 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1539 |
{ |
| 1540 |
case BINDEX_TAG_ABSENT: |
| 1541 |
return condMatch(s,key,objp, cdt->right) ; |
| 1542 |
case BINDEX_TAG_UNCLEAR: |
| 1543 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1544 |
{ |
| 1545 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_UNCLEAR ; |
| 1546 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1547 |
case BINDEX_TAG_PRESENT: return BINDEX_TAG_PRESENT ; |
| 1548 |
} |
| 1549 |
case BINDEX_TAG_PRESENT: |
| 1550 |
return BINDEX_TAG_PRESENT ; |
| 1551 |
} |
| 1552 |
|
| 1553 |
case AND: |
| 1554 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1555 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1556 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1557 |
{ |
| 1558 |
case BINDEX_TAG_ABSENT: |
| 1559 |
return BINDEX_TAG_ABSENT ; |
| 1560 |
case BINDEX_TAG_UNCLEAR: |
| 1561 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1562 |
{ |
| 1563 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1564 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1565 |
case BINDEX_TAG_PRESENT: return BINDEX_TAG_UNCLEAR ; |
| 1566 |
} |
| 1567 |
case BINDEX_TAG_PRESENT: |
| 1568 |
return condMatch(s,key,objp, cdt->right) ; |
| 1569 |
} |
| 1570 |
|
| 1571 |
case XOR: |
| 1572 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1573 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1574 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1575 |
{ |
| 1576 |
case BINDEX_TAG_ABSENT: |
| 1577 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1578 |
{ |
| 1579 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1580 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1581 |
case BINDEX_TAG_PRESENT: return BINDEX_TAG_PRESENT ; |
| 1582 |
} |
| 1583 |
case BINDEX_TAG_UNCLEAR: |
| 1584 |
return BINDEX_TAG_UNCLEAR ; |
| 1585 |
case BINDEX_TAG_PRESENT: |
| 1586 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1587 |
{ |
| 1588 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_PRESENT ; |
| 1589 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1590 |
case BINDEX_TAG_PRESENT: return BINDEX_TAG_ABSENT ; |
| 1591 |
} |
| 1592 |
} |
| 1593 |
|
| 1594 |
case NOT: |
| 1595 |
if (!cdt->right) |
| 1596 |
{ |
| 1597 |
messout("Internal error : condMatch should not parse NOT with nothing to the right") ; |
| 1598 |
return BINDEX_TAG_ABSENT ; |
| 1599 |
} |
| 1600 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1601 |
{ |
| 1602 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_PRESENT ; |
| 1603 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1604 |
case BINDEX_TAG_PRESENT: return BINDEX_TAG_ABSENT ; |
| 1605 |
} |
| 1606 |
|
| 1607 |
case SUBEXP: |
| 1608 |
if (!cdt->left) |
| 1609 |
{ |
| 1610 |
messout("Internal error : condMatch should not parse a subexp with nothing to the left") ; |
| 1611 |
return BINDEX_TAG_ABSENT ; |
| 1612 |
} |
| 1613 |
if (cdt->right) /* juxtaposition understood as AND */ |
| 1614 |
{ |
| 1615 |
messout ("Internal error : missing operator at %s: %s", |
| 1616 |
qName[cdt->qop], stackText(s, cdt->mark)) ; |
| 1617 |
return BINDEX_TAG_ABSENT ; |
| 1618 |
} |
| 1619 |
return condMatch(s,key,objp, cdt->left) ; |
| 1620 |
|
| 1621 |
case CALCUL: |
| 1622 |
if (!cdt->left) |
| 1623 |
return BINDEX_TAG_ABSENT ; |
| 1624 |
if (cdt->right) /* meaningless juxtaposition */ |
| 1625 |
return BINDEX_TAG_ABSENT ; |
| 1626 |
|
| 1627 |
if (isNumber(cdt->left->qop)) |
| 1628 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1629 |
{ |
| 1630 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1631 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR; |
| 1632 |
case BINDEX_TAG_PRESENT: cdt->n.x = cdt->left->n.x ; return BINDEX_TAG_PRESENT ; |
| 1633 |
} |
| 1634 |
else if (isLocatorOp (cdt->left->qop)) |
| 1635 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1636 |
{ |
| 1637 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1638 |
case BINDEX_TAG_UNCLEAR: break ; |
| 1639 |
case BINDEX_TAG_PRESENT: break ; /* we still have to look inside the object */ |
| 1640 |
} |
| 1641 |
else |
| 1642 |
return BINDEX_TAG_ABSENT ; /* not a number, not a locator => meaningless */ |
| 1643 |
|
| 1644 |
if (fuzzy) return BINDEX_TAG_UNCLEAR ; /* quit fuzzy analysis */ |
| 1645 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1646 |
return BINDEX_TAG_ABSENT ; |
| 1647 |
|
| 1648 |
if (condMatch(s,key,objp, cdt->left) && |
| 1649 |
bsGetKeyTags(*objp, cdt->left->qop == VECTOR_TAG ? _bsHere : _bsRight, &k)) |
| 1650 |
{ float x ; |
| 1651 |
if (k == _Int && bsGetData(*objp, _bsHere, k, &i)) |
| 1652 |
x = i ; |
| 1653 |
else if (k == _Float && bsGetData(*objp, _bsHere, k, &f)) |
| 1654 |
x = f ; |
| 1655 |
else if (k == _DateType && bsGetData(*objp, _bsHere, k, &tm)) |
| 1656 |
x = tm ; |
| 1657 |
else if (k <= _LastC && bsGetData(*objp, _bsHere, k, &cp) && |
| 1658 |
(x = (float) atof(cp))) ; |
| 1659 |
else |
| 1660 |
return BINDEX_TAG_ABSENT ; |
| 1661 |
cdt->n.x = x ; |
| 1662 |
return BINDEX_TAG_PRESENT ; |
| 1663 |
} |
| 1664 |
return BINDEX_TAG_ABSENT ; |
| 1665 |
|
| 1666 |
case PLUS: case MINUS: case MULTIPLY: case DIVIDE: |
| 1667 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1668 |
if ((cdt->left && !isNumber (cdt->left->qop)) || |
| 1669 |
!isNumber (cdt->right->qop)) |
| 1670 |
return BINDEX_TAG_ABSENT ; |
| 1671 |
|
| 1672 |
if (cdt->left) switch (condMatch(s,key,objp, cdt->left)) |
| 1673 |
{ |
| 1674 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1675 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR ; |
| 1676 |
case BINDEX_TAG_PRESENT: break ; |
| 1677 |
} |
| 1678 |
|
| 1679 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1680 |
{ |
| 1681 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1682 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR ; |
| 1683 |
case BINDEX_TAG_PRESENT: break ; |
| 1684 |
} |
| 1685 |
|
| 1686 |
switch (cdt->qop) |
| 1687 |
{ |
| 1688 |
case PLUS: |
| 1689 |
cdt->n.x = (cdt->left ? cdt->left->n.x : 0 ) + cdt->right->n.x ; |
| 1690 |
break ; |
| 1691 |
case MINUS: |
| 1692 |
cdt->n.x = (cdt->left ? cdt->left->n.x : 0 ) - cdt->right->n.x ; |
| 1693 |
break ; |
| 1694 |
/* case MULTIPLY DIVIDE are actually tested to have a cdt->left */ |
| 1695 |
case MULTIPLY: |
| 1696 |
cdt->n.x = (cdt->left ? cdt->left->n.x : 1 ) * cdt->right->n.x ; |
| 1697 |
break ; |
| 1698 |
case DIVIDE: |
| 1699 |
if (! cdt->right->n.x) |
| 1700 |
return BINDEX_TAG_ABSENT ; |
| 1701 |
cdt->n.x = (cdt->left ? cdt->left->n.x : 1 ) / cdt->right->n.x ; |
| 1702 |
break ; |
| 1703 |
default: break ; |
| 1704 |
} |
| 1705 |
return BINDEX_TAG_PRESENT ; |
| 1706 |
|
| 1707 |
case EQ: |
| 1708 |
case NEQ: case LT: case LE: case GT: case GE: case LIKE: |
| 1709 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1710 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1711 |
if (cdt->left->qop == IS ) |
| 1712 |
{ |
| 1713 |
cp = 0 ; |
| 1714 |
found = BINDEX_TAG_ABSENT ; |
| 1715 |
while (myNextName(key,&cp)) |
| 1716 |
if (condCheckText(cp, cdt->qop, stackText(s,cdt->right->mark))) |
| 1717 |
{ found = BINDEX_TAG_PRESENT ; break ; } |
| 1718 |
return found ; |
| 1719 |
} |
| 1720 |
|
| 1721 |
/* = tag means = text_value of tag, so fail is no problem */ |
| 1722 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1723 |
{ |
| 1724 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1725 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR ; |
| 1726 |
case BINDEX_TAG_PRESENT: break ; |
| 1727 |
} |
| 1728 |
|
| 1729 |
switch (condMatch(s,key,objp, cdt->right)) |
| 1730 |
{ |
| 1731 |
case BINDEX_TAG_ABSENT: |
| 1732 |
if (cdt->right->qop != TAG) return BINDEX_TAG_ABSENT ; |
| 1733 |
else break ; |
| 1734 |
case BINDEX_TAG_UNCLEAR: |
| 1735 |
if (cdt->right->qop != TAG) return BINDEX_TAG_UNCLEAR ; |
| 1736 |
else break ; |
| 1737 |
case BINDEX_TAG_PRESENT: break ; |
| 1738 |
} |
| 1739 |
|
| 1740 |
if (isNumber (cdt->left->qop) && |
| 1741 |
isNumber (cdt->right->qop)) |
| 1742 |
return |
| 1743 |
condCheck(cdt->left->n.x,cdt->qop,cdt->right->n.x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1744 |
|
| 1745 |
if (cdt->left->qop == TEXT || class(key) < _LastN) |
| 1746 |
return |
| 1747 |
condCheckText(stackText(s,cdt->left->mark), cdt->qop, |
| 1748 |
stackText(s,cdt->right->mark)) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1749 |
|
| 1750 |
|
| 1751 |
if (cdt->left->n.tag != _bsRight && |
| 1752 |
cdt->left->n.tag != _bsHere && |
| 1753 |
cdt->left->n.tag < lexMax(0) && |
| 1754 |
(!*objp && !bIndexFind(key,cdt->left->n.tag))) /* if *objp, i may be in a subobj */ |
| 1755 |
return BINDEX_TAG_ABSENT ; |
| 1756 |
|
| 1757 |
if (fuzzy) return BINDEX_TAG_UNCLEAR ; |
| 1758 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1759 |
return BINDEX_TAG_ABSENT ; |
| 1760 |
|
| 1761 |
/* RD handle _bsRight separately, else takes two steps right, |
| 1762 |
one from condMatch and one here |
| 1763 |
-- this is an ugly fix: the condMatch calls above should return |
| 1764 |
values, which are compared here. i.e. the recursive process |
| 1765 |
should deal in values, not BOOLs |
| 1766 |
*/ |
| 1767 |
|
| 1768 |
if ((cdt->left->n.tag == _bsRight && bsGetKeyTags(*objp, _bsHere, &k)) || |
| 1769 |
(cdt->left->n.tag < lexMax(0) && bsGetKeyTags(*objp, cdt->left->n.tag,&k)) ) |
| 1770 |
do |
| 1771 |
{ if (k == _Int) |
| 1772 |
{ if (isNumber(cdt->right->qop) && |
| 1773 |
bsGetData(*objp, _bsHere, k, &i) && |
| 1774 |
condCheck((float) i,cdt->qop,cdt->right->n.x)) |
| 1775 |
return BINDEX_TAG_PRESENT ; |
| 1776 |
} |
| 1777 |
else if (k == _Float) |
| 1778 |
{ if (isNumber(cdt->right->qop) && |
| 1779 |
bsGetData(*objp, _bsHere, k, &f) && |
| 1780 |
condCheck(f,cdt->qop,cdt->right->n.x)) |
| 1781 |
return BINDEX_TAG_PRESENT ; |
| 1782 |
} |
| 1783 |
else if (k == _DateType) |
| 1784 |
{ mytime_t x ; /* et suppression des (float) pour x et tm */ |
| 1785 |
if ( (x = timeParse(stackText(s,cdt->right->mark))) && |
| 1786 |
bsGetData(*objp, _bsHere, k, &tm) ) |
| 1787 |
switch (cdt->qop) /* mhmp 22.10.98 */ |
| 1788 |
{ |
| 1789 |
case EQ: |
| 1790 |
return timeComparison (0, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1791 |
case NEQ: |
| 1792 |
return !timeComparison (0, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1793 |
case LT: |
| 1794 |
return timeComparison (-1, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1795 |
case GE: |
| 1796 |
return !timeComparison (-1, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1797 |
case GT: |
| 1798 |
return timeComparison (1, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT; |
| 1799 |
case LE: |
| 1800 |
return !timeComparison (1, tm, x) ? BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 1801 |
default: |
| 1802 |
if (!x && writeMess) |
| 1803 |
{ messout ("Sorry - not a good date") ; |
| 1804 |
writeMess = FALSE ; |
| 1805 |
} |
| 1806 |
return BINDEX_TAG_ABSENT ; |
| 1807 |
} |
| 1808 |
} |
| 1809 |
else if (k <= _LastC) |
| 1810 |
{ if (bsGetData(*objp, _bsHere, k, &cp)) |
| 1811 |
{ if (isNumber(cdt->right->qop)) |
| 1812 |
{ float xx ; |
| 1813 |
if (sscanf(cp, "%f",&xx) && |
| 1814 |
condCheck(xx,cdt->qop,cdt->right->n.x)) |
| 1815 |
return BINDEX_TAG_PRESENT ; |
| 1816 |
} |
| 1817 |
if (condCheckText(cp,cdt->qop, |
| 1818 |
stackText(s,cdt->right->mark))) |
| 1819 |
return BINDEX_TAG_PRESENT ; |
| 1820 |
} |
| 1821 |
} |
| 1822 |
else /* ordinary Key */ |
| 1823 |
{ cp = 0 ; |
| 1824 |
while (nextName(k, &cp)) |
| 1825 |
{ if (isNumber(cdt->right->qop)) |
| 1826 |
{ float xx ; |
| 1827 |
if (sscanf(cp, "%f",&xx) && |
| 1828 |
condCheck(xx,cdt->qop,cdt->right->n.x)) |
| 1829 |
return BINDEX_TAG_PRESENT ; |
| 1830 |
} |
| 1831 |
if (condCheckText(cp,cdt->qop, |
| 1832 |
stackText(s,cdt->right->mark))) |
| 1833 |
return BINDEX_TAG_PRESENT ; |
| 1834 |
} |
| 1835 |
} |
| 1836 |
} while (bsGetKeyTags(*objp,_bsDown, &k)) ; /* do while construct */ |
| 1837 |
return BINDEX_TAG_ABSENT ; |
| 1838 |
|
| 1839 |
case COMPOSITE_TAG: |
| 1840 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1841 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1842 |
|
| 1843 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1844 |
{ |
| 1845 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1846 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR ; |
| 1847 |
case BINDEX_TAG_PRESENT: break ; |
| 1848 |
} |
| 1849 |
|
| 1850 |
if (fuzzy) return BINDEX_TAG_UNCLEAR ; |
| 1851 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1852 |
return BINDEX_TAG_ABSENT ; |
| 1853 |
if (doPushPopSubObj) |
| 1854 |
push(subObjMarks,bsMark(*objp,0), BSMARK) ; |
| 1855 |
i = 0 ; |
| 1856 |
if (bsPushObj(*objp)) |
| 1857 |
i = condMatch(s,key,objp, cdt->right) ; |
| 1858 |
if (doPushPopSubObj) |
| 1859 |
bsGoto(*objp,pop(subObjMarks,BSMARK)) ; |
| 1860 |
|
| 1861 |
return i ; |
| 1862 |
|
| 1863 |
case VECTOR_TAG: |
| 1864 |
if (!cdt->left) return BINDEX_TAG_ABSENT ; |
| 1865 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1866 |
switch (condMatch(s,key,objp, cdt->left)) |
| 1867 |
{ |
| 1868 |
case BINDEX_TAG_ABSENT: return BINDEX_TAG_ABSENT ; |
| 1869 |
case BINDEX_TAG_UNCLEAR: return BINDEX_TAG_UNCLEAR ; |
| 1870 |
case BINDEX_TAG_PRESENT: break ; |
| 1871 |
} |
| 1872 |
|
| 1873 |
if (fuzzy) return BINDEX_TAG_UNCLEAR ; |
| 1874 |
|
| 1875 |
if (!isNumber(cdt->right->qop)) |
| 1876 |
return BINDEX_TAG_ABSENT ; |
| 1877 |
cdt->n.tag = _bsHere ; |
| 1878 |
i = cdt->right->n.x ; |
| 1879 |
if (i < 0) |
| 1880 |
return BINDEX_TAG_ABSENT ; |
| 1881 |
if (fuzzy) |
| 1882 |
return BINDEX_TAG_UNCLEAR ; |
| 1883 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1884 |
return BINDEX_TAG_ABSENT ; |
| 1885 |
while (i--) |
| 1886 |
if (!bsFindTag(*objp,_bsRight)) |
| 1887 |
return BINDEX_TAG_ABSENT ; |
| 1888 |
return BINDEX_TAG_PRESENT ; |
| 1889 |
|
| 1890 |
case TAG: |
| 1891 |
/* if !fuzzy, i need to position */ |
| 1892 |
if (fuzzy) |
| 1893 |
return bIndexFind(key,cdt->n.tag) ; |
| 1894 |
|
| 1895 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1896 |
return BINDEX_TAG_ABSENT ; |
| 1897 |
if (!bsFindTag(*objp,cdt->n.tag)) |
| 1898 |
return BINDEX_TAG_ABSENT ; |
| 1899 |
if (cdt->right) /* big blue, interpreted as big AND blue */ |
| 1900 |
return condMatch(s,key,objp, cdt->right) ; |
| 1901 |
return BINDEX_TAG_PRESENT ; |
| 1902 |
|
| 1903 |
case COUNT: |
| 1904 |
if (!cdt->right) |
| 1905 |
return BINDEX_TAG_ABSENT ; |
| 1906 |
if (fuzzy && cdt->right && cdt->right->qop == TAG && |
| 1907 |
bIndexFind(key,cdt->right->n.tag) == BINDEX_TAG_ABSENT) |
| 1908 |
return BINDEX_TAG_ABSENT ; |
| 1909 |
if (fuzzy) |
| 1910 |
return BINDEX_TAG_UNCLEAR ; |
| 1911 |
if (cdt->right && cdt->right->qop == SUBQUERY) |
| 1912 |
{ Array aa = queryKey (key, stackText(s,cdt->right->mark)) ; |
| 1913 |
cdt->n.x = aa ? keySetMax (aa) : 0 ; |
| 1914 |
keySetDestroy (aa) ; |
| 1915 |
return BINDEX_TAG_PRESENT ; |
| 1916 |
} |
| 1917 |
/* |
| 1918 |
{ Array aa = keySetCreate (), bb = 0 ; |
| 1919 |
keySet(aa, 0) = key ; |
| 1920 |
bb = queryExecute (aa, cdt->right, s) ; |
| 1921 |
cdt->n.x = bb ? keySetMax (bb) : 0 ; |
| 1922 |
if (aa != bb) keySetDestroy(bb) ; |
| 1923 |
return TRUE ; |
| 1924 |
} |
| 1925 |
*/ |
| 1926 |
if ( |
| 1927 |
!condMatch(s,key,objp, cdt->right) || |
| 1928 |
(!*objp && !((*objp = bsCreate(key)))) |
| 1929 |
) |
| 1930 |
return BINDEX_TAG_ABSENT ; |
| 1931 |
if (!bsGetKeyTags(*objp,_bsRight, &k) ) |
| 1932 |
{ cdt->n.x = 0 ; |
| 1933 |
return BINDEX_TAG_PRESENT ; |
| 1934 |
} |
| 1935 |
i = 0 ; |
| 1936 |
do |
| 1937 |
{ |
| 1938 |
if (class(k) != _VComment) i++ ; |
| 1939 |
} while(bsGetKeyTags(*objp,_bsDown, &k)) ; |
| 1940 |
|
| 1941 |
cdt->n.x = (float) i ; |
| 1942 |
return BINDEX_TAG_PRESENT ; |
| 1943 |
|
| 1944 |
case AVG: case SUM: case MIN: case MAX: |
| 1945 |
if (!cdt->right) return BINDEX_TAG_ABSENT ; |
| 1946 |
if (!*objp && !bIndexFind(key,cdt->right->n.tag)) |
| 1947 |
return BINDEX_TAG_ABSENT ; |
| 1948 |
if (!bsIsTagInObj (*objp, key, cdt->right->n.tag)) |
| 1949 |
return BINDEX_TAG_ABSENT ; |
| 1950 |
if (fuzzy) |
| 1951 |
return BINDEX_TAG_UNCLEAR ; |
| 1952 |
if (!*objp && !(*objp = bsCreate(key))) |
| 1953 |
return BINDEX_TAG_ABSENT ; |
| 1954 |
if (!bsGetKeyTags(*objp, cdt->right->n.tag,&k)) |
| 1955 |
return BINDEX_TAG_ABSENT ; |
| 1956 |
|
| 1957 |
{ float x, sum = 0, min = 0, max = 0 ; |
| 1958 |
int nn = 0 ; |
| 1959 |
do |
| 1960 |
{ |
| 1961 |
if (k == _Int && bsGetData(*objp, _bsHere, k, &i)) |
| 1962 |
x = i ; |
| 1963 |
else if (k == _Float && bsGetData(*objp, _bsHere, k, &f)) |
| 1964 |
x = f ; |
| 1965 |
else if (k == _DateType && bsGetData(*objp, _bsHere, k, &tm)) |
| 1966 |
x = tm ; |
| 1967 |
else if (k <= _LastC && bsGetData(*objp, _bsHere, k, &cp) && (x = (float) atof(cp))) ; |
| 1968 |
else |
| 1969 |
continue ; |
| 1970 |
|
| 1971 |
if (!nn++) |
| 1972 |
min = max = sum = x ; |
| 1973 |
else |
| 1974 |
{ if (x < min) min = x ; |
| 1975 |
if (x > max) max = x ; |
| 1976 |
sum += x ; |
| 1977 |
} |
| 1978 |
} while(bsGetKeyTags(*objp,_bsDown, &k)) ; |
| 1979 |
|
| 1980 |
if (!nn) |
| 1981 |
return BINDEX_TAG_ABSENT ; |
| 1982 |
switch(cdt->qop) |
| 1983 |
{ |
| 1984 |
case SUM: |
| 1985 |
cdt->n.x = sum ; |
| 1986 |
break ; |
| 1987 |
case AVG: |
| 1988 |
cdt->n.x = sum/nn ; |
| 1989 |
break ; |
| 1990 |
case MIN: |
| 1991 |
cdt->n.x = min ; |
| 1992 |
break ; |
| 1993 |
case MAX: |
| 1994 |
cdt->n.x = max ; |
| 1995 |
break ; |
| 1996 |
default: break ; |
| 1997 |
} |
| 1998 |
return BINDEX_TAG_PRESENT ; |
| 1999 |
} |
| 2000 |
|
| 2001 |
case TEXT: |
| 2002 |
case NUMBER: |
| 2003 |
case TIME: |
| 2004 |
if (cdt->up) |
| 2005 |
switch (cdt->up->qop) |
| 2006 |
{ |
| 2007 |
case FIND: case FOLLOW_TAG: case FROM: case WHERE: |
| 2008 |
case PIPEQUERY: case SUBQUERY: |
| 2009 |
case AND: case OR: case XOR: case NOT: |
| 2010 |
case TEXT: case NUMBER: case TIME: case TAG: |
| 2011 |
/* leftmost text or logical operator or |
| 2012 |
* FIND Author a* will be recognised as a name selection |
| 2013 |
* FOLLOW Author a* will be recognisewd as a name selection |
| 2014 |
*/ |
| 2015 |
break; |
| 2016 |
default: |
| 2017 |
if (cdt->right) |
| 2018 |
return condMatch(s,key,objp, cdt->right) ; /* check the rest of the expression */ |
| 2019 |
return BINDEX_TAG_PRESENT ; |
| 2020 |
} |
| 2021 |
|
| 2022 |
cp = 0 ; |
| 2023 |
found = BINDEX_TAG_ABSENT ; |
| 2024 |
while (myNextName(key,&cp)) |
| 2025 |
if (pickMatchCaseSensitive (cp, stackText(s,cdt->mark), |
| 2026 |
pickCaseSensitive (key))) |
| 2027 |
{ found = BINDEX_TAG_PRESENT ; break ; } |
| 2028 |
if (found && cdt->right) |
| 2029 |
{ |
| 2030 |
/* messout("Interpolating AND just right of %s: %s", |
| 2031 |
qName[cdt->qop], stackText(s, cdt->mark)) ; */ |
| 2032 |
return condMatch(s,key,objp, cdt->right) ; /* check the rest of the expression */ |
| 2033 |
} |
| 2034 |
return found ; |
| 2035 |
|
| 2036 |
case IS: /* matches to text to its right */ |
| 2037 |
if (!cdt->right) |
| 2038 |
return BINDEX_TAG_ABSENT ; |
| 2039 |
cp = 0 ; |
| 2040 |
found = BINDEX_TAG_ABSENT ; |
| 2041 |
while (myNextName(key,&cp)) |
| 2042 |
if (pickMatchCaseSensitive(cp, stackText(s,cdt->right->mark), |
| 2043 |
pickCaseSensitive (key))) |
| 2044 |
{ found = BINDEX_TAG_PRESENT ; break ; } |
| 2045 |
return found ; |
| 2046 |
|
| 2047 |
case CLASS: |
| 2048 |
if (!cdt->right) |
| 2049 |
return BINDEX_TAG_ABSENT ; |
| 2050 |
{ |
| 2051 |
Array a = pickIsComposite(cdt->right->n.classe); |
| 2052 |
int j; |
| 2053 |
|
| 2054 |
if (!a) |
| 2055 |
return |
| 2056 |
lexIsInClass(key, cdt->right->n.classe) ? |
| 2057 |
BINDEX_TAG_PRESENT : BINDEX_TAG_ABSENT ; |
| 2058 |
|
| 2059 |
for (j=0; j <arrayMax(a); j++) |
| 2060 |
if (lexIsInClass(key, array(a, j, KEY))) |
| 2061 |
return BINDEX_TAG_PRESENT; |
| 2062 |
|
| 2063 |
return BINDEX_TAG_ABSENT ; |
| 2064 |
} |
| 2065 |
|
| 2066 |
case FINALPIPE: |
| 2067 |
return BINDEX_TAG_PRESENT ; |
| 2068 |
|
| 2069 |
case GREP: /* should not happen inside a query */ |
| 2070 |
return BINDEX_TAG_ABSENT ; |
| 2071 |
|
| 2072 |
case WEBQUERY: /* should not happen inside a query */ |
| 2073 |
return BINDEX_TAG_ABSENT ; |
| 2074 |
|
| 2075 |
case PIPEQUERY: |
| 2076 |
return condMatch(s,key,objp, cdt->right) ; /* check the rest of the expression */ |
| 2077 |
|
| 2078 |
default: |
| 2079 |
messout("Confusion in condMatch at: %s: %s", |
| 2080 |
qName[cdt->qop], stackText(s, cdt->mark)) ; |
| 2081 |
return BINDEX_TAG_ABSENT ; |
| 2082 |
} |
| 2083 |
return BINDEX_TAG_ABSENT ; /* for compiler happiness */ |
| 2084 |
} |
| 2085 |
|
| 2086 |
/***********************************************************/ |
| 2087 |
/* printf since for debugging */ |
| 2088 |
static void cdtDump(Stack s, CDT cdt, int level, BOOL isLeft) |
| 2089 |
{ |
| 2090 |
int i = level ; |
| 2091 |
if (!cdt) |
| 2092 |
{ printf("\n cdtDumping NULL \n") ; |
| 2093 |
return ; |
| 2094 |
} |
| 2095 |
while(i--) |
| 2096 |
printf("\t") ; |
| 2097 |
printf(isLeft ? "< " : "> ") ; |
| 2098 |
printf("%s:", qName[cdt->qop]) ; |
| 2099 |
if (cdt->qop == TAG && cdt->n.tag) |
| 2100 |
printf(" tag = %s ", name(cdt->n.tag) ); |
| 2101 |
else if (cdt->qop == CLASS && cdt->n.classe) |
| 2102 |
printf(" class = %s ", name(cdt->n.classe)) ; |
| 2103 |
if ( cdt->mark) |
| 2104 |
printf(" cp = %s ", stackText(s, cdt->mark)) ; |
| 2105 |
printf("\n") ; |
| 2106 |
if (cdt->left) |
| 2107 |
cdtDump(s,cdt->left, level + 1, TRUE) ; |
| 2108 |
if (cdt->right) |
| 2109 |
cdtDump(s,cdt->right, level + 1, FALSE) ; |
| 2110 |
} |
| 2111 |
|
| 2112 |
/**********************************************************/ |
| 2113 |
|
| 2114 |
static BOOL condFMatch(Stack s, KEY key, OBJ* objp, CDT cdt) |
| 2115 |
{ |
| 2116 |
if (bIndexVersion(-1) && !(*objp) ) |
| 2117 |
{ |
| 2118 |
fuzzy = TRUE ; |
| 2119 |
switch (condMatch(s,key,objp,cdt)) |
| 2120 |
{ |
| 2121 |
case BINDEX_TAG_ABSENT: fuzzy = FALSE ; return FALSE ; |
| 2122 |
case BINDEX_TAG_UNCLEAR: fuzzy = FALSE ; break ; |
| 2123 |
case BINDEX_TAG_PRESENT: fuzzy = FALSE ; |
| 2124 |
if (doPushPopSubObj) return TRUE ; |
| 2125 |
else break ; /* because we want to position in the object */ |
| 2126 |
} |
| 2127 |
} |
| 2128 |
|
| 2129 |
switch (condMatch(s,key,objp,cdt)) |
| 2130 |
{ |
| 2131 |
case BINDEX_TAG_ABSENT: return FALSE ; |
| 2132 |
case BINDEX_TAG_UNCLEAR: messcrash ("inconsistency in condFMatch") ; |
| 2133 |
case BINDEX_TAG_PRESENT: return TRUE ; |
| 2134 |
} |
| 2135 |
return FALSE ; |
| 2136 |
} |
| 2137 |
|
| 2138 |
/**********************************************************/ |
| 2139 |
/* Works en place */ |
| 2140 |
static void queryFilter (KEYSET ks, CDT cdt, Stack stack) |
| 2141 |
/* NOTE: oldSet is destroyed here */ |
| 2142 |
{ |
| 2143 |
register int i = 0, imax, j = 0 ; |
| 2144 |
KEY k ; |
| 2145 |
OBJ obj = 0 ; /* created if needed by condMatch */ |
| 2146 |
|
| 2147 |
if (!ks) |
| 2148 |
messcrash ("query filter received a null ks") ; |
| 2149 |
|
| 2150 |
subObjMarks = stackReCreate(subObjMarks, 8) ; |
| 2151 |
imax = keySetMax(ks) ; |
| 2152 |
/* works on a single object at a time */ |
| 2153 |
for(i=0; !doInterrupt && i<imax; i++) |
| 2154 |
{ |
| 2155 |
k = keySet(ks,i) ; |
| 2156 |
if (i && (!(i%10)) && messIsInterruptCalled()) |
| 2157 |
{ |
| 2158 |
doInterrupt = TRUE ; |
| 2159 |
break ; |
| 2160 |
} |
| 2161 |
|
| 2162 |
obj = 0 ; |
| 2163 |
if (condFMatch(stack, k, &obj, cdt)) |
| 2164 |
keySet(ks,j++) = k ; /* Keeps set sorted as a subset */ |
| 2165 |
if (obj) |
| 2166 |
bsDestroy(obj) ; |
| 2167 |
} |
| 2168 |
|
| 2169 |
keySetMax (ks) = j ; |
| 2170 |
} |
| 2171 |
|
| 2172 |
/**********************************************************/ |
| 2173 |
|
| 2174 |
static KEYSET querySetOperation (KEYSET oldSet, CDT cdt, Stack stack) |
| 2175 |
/* NOTE: oldSet is destroyed in here or by functions called in here */ |
| 2176 |
{ |
| 2177 |
KEYSET aa = 0, bb = 0, cc = 0; |
| 2178 |
|
| 2179 |
switch (cdt->qop) |
| 2180 |
{ |
| 2181 |
case SUBQUERY: |
| 2182 |
if (cdt->left) |
| 2183 |
{ |
| 2184 |
#ifdef DEBUG |
| 2185 |
int id = oldSet ? oldSet->id : 0 ; |
| 2186 |
#endif |
| 2187 |
KEYSET newSet = |
| 2188 |
queryExecute(oldSet, cdt->left, stack); /* destroys oldSet */ |
| 2189 |
#ifdef DEBUG |
| 2190 |
if (oldSet && oldSet->magic == ARRAY_MAGIC && oldSet->magic == id && newSet->id != id) |
| 2191 |
messcrash ("querySetOperation(): case SUBQUERY:\n" |
| 2192 |
" oldSet should have been destroyed!"); |
| 2193 |
#endif |
| 2194 |
return newSet ; |
| 2195 |
} |
| 2196 |
else |
| 2197 |
{ |
| 2198 |
keySetDestroy (oldSet); |
| 2199 |
return keySetCreate () ; |
| 2200 |
} |
| 2201 |
|
| 2202 |
case SETDEFINE: |
| 2203 |
keySetDestroy (oldSet); |
| 2204 |
return keySetCreate () ; |
| 2205 |
|
| 2206 |
case PIPEQUERY: |
| 2207 |
case WHERE: |
| 2208 |
{ |
| 2209 |
aa = 0; |
| 2210 |
cc = oldSet ; |
| 2211 |
|
| 2212 |
if (cdt->left) |
| 2213 |
{ |
| 2214 |
#ifdef DEBUG |
| 2215 |
int id = cc ? cc->id : 0 ; |
| 2216 |
#endif |
| 2217 |
aa = queryExecute(cc, cdt->left, stack) ; /* destroys cc */ |
| 2218 |
#ifdef DEBUG |
| 2219 |
if (cc && cc->magic == ARRAY_MAGIC && cc->id == id && aa->id != id) |
| 2220 |
messcrash ("querySetOperation(): case WHERE left:\n" |
| 2221 |
" cc should have been destroyed!"); |
| 2222 |
#endif |
| 2223 |
cc = aa ; |
| 2224 |
} |
| 2225 |
|
| 2226 |
if (cdt->right) |
| 2227 |
{ |
| 2228 |
#ifdef DEBUG |
| 2229 |
int id = cc ? cc->id : 0 ; |
| 2230 |
#endif |
| 2231 |
aa = queryExecute(cc, cdt->right, stack) ; /* destroys cc */ |
| 2232 |
#ifdef DEBUG |
| 2233 |
if (cc && cc->magic == ARRAY_MAGIC && cc->id == id && aa->id != id) |
| 2234 |
messcrash ("querySetOperation(): case WHERE right:\n" |
| 2235 |
" cc should have been destroyed!"); |
| 2236 |
#endif |
| 2237 |
cc = aa ; |
| 2238 |
} |
| 2239 |
return cc ; |
| 2240 |
} |
| 2241 |
break; |
| 2242 |
|
| 2243 |
default: |
| 2244 |
/* evaluate the left and right query and then combine |
| 2245 |
the two sets according to the set-operator */ |
| 2246 |
{ |
| 2247 |
KEYSET oldSet1 = oldSet; /* gets destroyed by first call */ |
| 2248 |
KEYSET oldSet2 = keySetCopy(oldSet); /* gets destroyed by 2nd call */ |
| 2249 |
#ifdef DEBUG |
| 2250 |
int id1 = oldSet1 ? oldSet1->id : 0 ; |
| 2251 |
int id2 = oldSet2 ? oldSet2->id : 0 ; |
| 2252 |
#endif |
| 2253 |
|
| 2254 |
aa = queryExecute(oldSet1, cdt->left, stack) ; /* destroys oldSet */ |
| 2255 |
if (cdt->qop == SETELSE && |
| 2256 |
keySetMax (aa)) |
| 2257 |
{ |
| 2258 |
keySetDestroy (oldSet2) ; |
| 2259 |
return aa ; |
| 2260 |
} |
| 2261 |
bb = queryExecute(oldSet2, cdt->right, stack) ; /* destroys oldSet's copy */ |
| 2262 |
|
| 2263 |
#ifdef DEBUG |
| 2264 |
if (oldSet1 && oldSet1->magic == ARRAY_MAGIC && oldSet1->id == id1 && aa->id != id1) |
| 2265 |
messcrash ("querySetOperation(): case default:\n" |
| 2266 |
" oldSet should have been destroyed!"); |
| 2267 |
if (oldSet2 && oldSet2->magic == ARRAY_MAGIC && oldSet2->id == id2 && bb->id != id2) |
| 2268 |
messcrash ("querySetOperation(): case default:\n" |
| 2269 |
" oldSet's copy should have been destroyed!"); |
| 2270 |
#endif |
| 2271 |
|
| 2272 |
switch (cdt->qop) |
| 2273 |
{ |
| 2274 |
case SETOR: |
| 2275 |
cc = keySetOR(aa, bb) ; |
| 2276 |
break ; |
| 2277 |
case SETXOR: |
| 2278 |
cc = keySetXOR(aa, bb) ; |
| 2279 |
break ; |
| 2280 |
case SETAND: |
| 2281 |
cc = keySetAND(aa, bb) ; |
| 2282 |
break ; |
| 2283 |
case SETMINUS: |
| 2284 |
cc = keySetMINUS(aa, bb) ; |
| 2285 |
break ; |
| 2286 |
case SETELSE: |
| 2287 |
cc = keySetOR (aa, bb) ; |
| 2288 |
break ; |
| 2289 |
default: break ; |
| 2290 |
} |
| 2291 |
keySetDestroy(aa) ; |
| 2292 |
keySetDestroy(bb) ; |
| 2293 |
return cc ; |
| 2294 |
} |
| 2295 |
} |
| 2296 |
} |
| 2297 |
|
| 2298 |
/**********************************************************/ |
| 2299 |
/* Works en place */ |
| 2300 |
static KEYSET queryFrom(CDT cdt, Stack stack) |
| 2301 |
{ |
| 2302 |
messout("Sorry Named Sets are not yet implemented, please complain") ; |
| 2303 |
return keySetCreate() ; |
| 2304 |
} |
| 2305 |
|
| 2306 |
/***********************************/ |
| 2307 |
|
| 2308 |
static KEYSET queryExpand(KEYSET oldSet, CDT cdt, Stack stack) |
| 2309 |
{ |
| 2310 |
KEYSET s = keySetCreate() ; |
| 2311 |
KEY k , k2 ; |
| 2312 |
int i , imax = oldSet ? keySetMax(oldSet) : 0 , j = 0 ; |
| 2313 |
OBJ obj = 0 ; |
| 2314 |
QOP qop = cdt->right->qop ; |
| 2315 |
KEY tag = qop == TAG ? cdt->right->n.tag : 0 ; |
| 2316 |
subObjMarks = stackReCreate(subObjMarks, 8) ; |
| 2317 |
|
| 2318 |
for(i=0;i<imax;i++) |
| 2319 |
{ |
| 2320 |
k = keySet(oldSet,i) ; |
| 2321 |
if (i && (!(i%10)) && messIsInterruptCalled()) |
| 2322 |
{ |
| 2323 |
doInterrupt = TRUE ; |
| 2324 |
break ; |
| 2325 |
} |
| 2326 |
|
| 2327 |
if (tag) |
| 2328 |
{ |
| 2329 |
if (bIndexFind(k,tag) && |
| 2330 |
bsIsTagInObj (0, k, tag) && /* open only if tag in model */ |
| 2331 |
(obj = bsCreate(k))) |
| 2332 |
{ |
| 2333 |
if (bsGetKey(obj,tag,&k2)) |
| 2334 |
{ |
| 2335 |
if (class(k2)) |
| 2336 |
keySet(s, j++) = k2 ; |
| 2337 |
while(bsGetKey(obj,_bsDown,&k2)) |
| 2338 |
if (class(k2)) |
| 2339 |
keySet(s, j++) = k2 ; |
| 2340 |
} |
| 2341 |
bsDestroy(obj) ; |
| 2342 |
} |
| 2343 |
} |
| 2344 |
else /* locate, then get right column */ |
| 2345 |
{ |
| 2346 |
BOOL old = doPushPopSubObj ; |
| 2347 |
obj = 0 ; |
| 2348 |
doPushPopSubObj = FALSE ; |
| 2349 |
|
| 2350 |
if (condFMatch(stack, k, &obj, cdt->right) && |
| 2351 |
obj && |
| 2352 |
bsGetKey(obj,_bsRight,&k2)) |
| 2353 |
{ |
| 2354 |
do |
| 2355 |
{ |
| 2356 |
if (class(k2)) |
| 2357 |
keySet(s, j++) = k2 ; |
| 2358 |
} while (bsGetKey(obj,_bsDown,&k2)) ; /* do-while */ |
| 2359 |
} |
| 2360 |
bsDestroy(obj) ; |
| 2361 |
doPushPopSubObj = old ; |
| 2362 |
} |
| 2363 |
} |
| 2364 |
keySetSort (s) ; |
| 2365 |
keySetCompress(s) ; |
| 2366 |
if (cdt->left) |
| 2367 |
queryFilter(s, cdt->left, stack) ; |
| 2368 |
|
| 2369 |
keySetDestroy(oldSet); |
| 2370 |
|
| 2371 |
return s ; |
| 2372 |
} /* queryExpand */ |
| 2373 |
|
| 2374 |
/***********************************/ |
| 2375 |
/* OR the content of each keyset obj into the result */ |
| 2376 |
static KEYSET queryExpandKeysets (KEYSET oldSet, CDT cdt, Stack stack) |
| 2377 |
{ |
| 2378 |
KEYSET s = keySetCreate(), ks = 0 ; |
| 2379 |
KEY k ; |
| 2380 |
int i , imax = oldSet ? keySetMax(oldSet) : 0 , i1, j = 0 ; |
| 2381 |
|
| 2382 |
for(i=0;i<imax;i++) |
| 2383 |
{ |
| 2384 |
k = keySet(oldSet,i) ; |
| 2385 |
if (class (k) != _VKeySet) |
| 2386 |
continue ; |
| 2387 |
|
| 2388 |
if (i && (!(i%10)) && messIsInterruptCalled()) |
| 2389 |
{ |
| 2390 |
doInterrupt = TRUE ; |
| 2391 |
break ; |
| 2392 |
} |
| 2393 |
|
| 2394 |
ks = arrayGet (k, KEY, "k") ; |
| 2395 |
if (ks) |
| 2396 |
{ |
| 2397 |
for (i1 = 0 ; i1 < keySetMax(ks) ; i1++) |
| 2398 |
keySet(s, j++) = keySet(ks, i1) ; |
| 2399 |
} |
| 2400 |
keySetDestroy (ks) ; |
| 2401 |
} |
| 2402 |
|
| 2403 |
keySetSort (s) ; |
| 2404 |
keySetCompress(s) ; |
| 2405 |
|
| 2406 |
keySetDestroy(oldSet); |
| 2407 |
|
| 2408 |
return s ; |
| 2409 |
} /* queryExpandKeysets */ |
| 2410 |
|
| 2411 |
/***********************************/ |
| 2412 |
|
| 2413 |
static KEYSET queryClass(CDT cdt, Stack stack) |
| 2414 |
{ |
| 2415 |
KEYSET s = keySetCreate() ; |
| 2416 |
char *cp ; |
| 2417 |
KEY k = 0 ; /* primes lexanext */ |
| 2418 |
KEY t = cdt->right->n.classe ; int i = 0 ; |
| 2419 |
Array a = pickIsComposite(t); |
| 2420 |
|
| 2421 |
/* deal with composite classes */ |
| 2422 |
if (a) |
| 2423 |
{ |
| 2424 |
int j; |
| 2425 |
|
| 2426 |
for (j=0; j <arrayMax(a); j++) |
| 2427 |
{ |
| 2428 |
k = 0; |
| 2429 |
while(lexNext(array(a, j, KEY) ,&k)) |
| 2430 |
keySet(s,i++) = k ; |
| 2431 |
} |
| 2432 |
|
| 2433 |
keySetSort (s) ; |
| 2434 |
keySetCompress(s) ; |
| 2435 |
|
| 2436 |
if (cdt->left) |
| 2437 |
queryFilter(s, cdt->left, stack) ; |
| 2438 |
|
| 2439 |
return s ; |
| 2440 |
} |
| 2441 |
else if (t == _VText) |
| 2442 |
{ |
| 2443 |
CDT c = cdt->up ; |
| 2444 |
|
| 2445 |
if (!c || !c->right || c->right->qop != TEXT) |
| 2446 |
{ |
| 2447 |
messout ("FIND Text should be followed by a Text, try to \"double quote it\"") ; |
| 2448 |
return s ; |
| 2449 |
} |
| 2450 |
cp = stackText(stack, c->right->mark) ; |
| 2451 |
if (strlen(cp) < 3 ) |
| 2452 |
{ |
| 2453 |
messout ("FIND Text should be followed by at least 3 characters") ; |
| 2454 |
return s ; |
| 2455 |
} |
| 2456 |
i = stackMark(stack) ; |
| 2457 |
pushText(stack, "*") ; |
| 2458 |
catText(stack, cp) ; |
| 2459 |
catText(stack, "*") ; |
| 2460 |
|
| 2461 |
keySetDestroy(s) ; |
| 2462 |
return |
| 2463 |
queryGrep(0, stackText(stack,i)) ; |
| 2464 |
} |
| 2465 |
|
| 2466 |
|
| 2467 |
while(lexNext(t,&k)) |
| 2468 |
keySet(s,i++) = k ; |
| 2469 |
|
| 2470 |
/* keySetSort(s) ; keysetCompress not needed */ |
| 2471 |
if (cdt->left) |
| 2472 |
queryFilter(s, cdt->left, stack) ; |
| 2473 |
|
| 2474 |
return s ; |
| 2475 |
} |
| 2476 |
|
| 2477 |
/**********************************************************/ |
| 2478 |
|
| 2479 |
static KEYSET queryExecute (KEYSET oldSet, CDT cdt, Stack stack) |
| 2480 |
/* NOTE: oldSet is destroyed in here or by functions called in here */ |
| 2481 |
{ |
| 2482 |
CDT cc = cdt ; |
| 2483 |
|
| 2484 |
while(cc->qop == SUBEXP && cc->right) |
| 2485 |
cc = cc->right ; |
| 2486 |
|
| 2487 |
switch(cc->qop) /* was cdt->qop */ |
| 2488 |
{ |
| 2489 |
case FOLLOW_TAG: |
| 2490 |
if (cc->right && isLocatorOp (cc->right->qop)) |
| 2491 |
return queryExpand(oldSet, cc, stack); /* destroys oldSet */ |
| 2492 |
break ; |
| 2493 |
|
| 2494 |
case EXPAND: |
| 2495 |
return queryExpandKeysets (oldSet, cc, stack); /* destroys oldSet */ |
| 2496 |
break ; |
| 2497 |
|
| 2498 |
case NEIGHBOURS: |
| 2499 |
return keySetNeighbours(oldSet); /* destroys oldSet */ |
| 2500 |
break ; |
| 2501 |
|
| 2502 |
case GREP: |
| 2503 |
if (cc->right) |
| 2504 |
{ |
| 2505 |
char *cp ; |
| 2506 |
int i = stackMark(stack) ; |
| 2507 |
cp = stackText(stack,cc->right->mark) ; |
| 2508 |
if (strlen(cp) >= 3) |
| 2509 |
{ |
| 2510 |
KEYSET grepKs ; |
| 2511 |
pushText(stack,"*") ; |
| 2512 |
catText(stack,cp) ; |
| 2513 |
catText(stack,"*") ; |
| 2514 |
grepKs = queryGrep (oldSet, stackText(stack,i)) ; |
| 2515 |
keySetDestroy (oldSet); |
| 2516 |
return grepKs ; |
| 2517 |
} |
| 2518 |
} |
| 2519 |
keySetDestroy (oldSet); |
| 2520 |
return keySetCreate() ; |
| 2521 |
break ; |
| 2522 |
|
| 2523 |
case WEBQUERY: |
| 2524 |
if (cc->right && webQueryFunc) |
| 2525 |
{ |
| 2526 |
char *cp ; |
| 2527 |
cp = stackText(stack,cc->right->mark) ; |
| 2528 |
if (strlen(cp) >= 3) |
| 2529 |
{ |
| 2530 |
KEYSET webKs ; |
| 2531 |
webKs = webQueryFunc (oldSet, cp) ; |
| 2532 |
keySetDestroy (oldSet); |
| 2533 |
return webKs ; |
| 2534 |
} |
| 2535 |
} |
| 2536 |
keySetDestroy (oldSet); |
| 2537 |
return keySetCreate() ; |
| 2538 |
break ; |
| 2539 |
|
| 2540 |
case FIND: |
| 2541 |
keySetDestroy (oldSet); |
| 2542 |
|
| 2543 |
if (cc->right && cc->right->qop == CLASS) |
| 2544 |
{ /* fishy acec patch J&V4D oct 2001 */ |
| 2545 |
/* treat the specaile case :: query find Sequence IS \"T28A11\" */ |
| 2546 |
CDT cc1 = 0 ; |
| 2547 |
|
| 2548 |
if (cc->up && cc->up->qop == PIPEQUERY && |
| 2549 |
cc->up->right && |
| 2550 |
( |
| 2551 |
( |
| 2552 |
cc->up->right->qop == IS && |
| 2553 |
cc->up->right->right && cc->up->right->right->qop == TEXT && |
| 2554 |
cc->up->right->right->mark && cc->up->right->right->mark < stackMark (stack) && |
| 2555 |
(cc1 = cc->up->right->right) |
| 2556 |
) || |
| 2557 |
( |
| 2558 |
cc->up->right->qop == TEXT && |
| 2559 |
cc->up->right->mark && cc->up->right->mark < stackMark (stack) && |
| 2560 |
(cc1 = cc->up->right) |
| 2561 |
) |
| 2562 |
) |
| 2563 |
) |
| 2564 |
{ |
| 2565 |
KEY dummy = 0 ; |
| 2566 |
KEYSET ks = keySetCreate () ; |
| 2567 |
char * cp = stackText(stack,cc1->mark) ; |
| 2568 |
if (lexword2key (cp, &dummy, cc->right->n.classe)) |
| 2569 |
{ |
| 2570 |
keySet (ks, 0) = dummy ; |
| 2571 |
return ks ; /* success */ |
| 2572 |
} |
| 2573 |
while (*cp && *cp != '*' && *cp != '?') cp++ ; |
| 2574 |
if (!*cp) return ks ; /* no wild char, we are done */ |
| 2575 |
|
| 2576 |
keySetDestroy (ks) ; |
| 2577 |
/* fall thru on general case */ |
| 2578 |
} |
| 2579 |
|
| 2580 |
return queryClass(cc, stack) ; |
| 2581 |
} |
| 2582 |
|
| 2583 |
return keySetCreate() ; |
| 2584 |
break ; |
| 2585 |
|
| 2586 |
case FROM: |
| 2587 |
keySetDestroy (oldSet); |
| 2588 |
|
| 2589 |
if (cc->right && cc->right->qop == NAMEDSET) |
| 2590 |
return queryFrom(cc, stack) ; |
| 2591 |
break ; |
| 2592 |
|
| 2593 |
case PIPEQUERY: |
| 2594 |
case SUBQUERY: |
| 2595 |
case WHERE: |
| 2596 |
case SETAND: |
| 2597 |
case SETOR: |
| 2598 |
case SETXOR: |
| 2599 |
case SETMINUS: |
| 2600 |
case SETDEFINE: |
| 2601 |
case SETELSE: |
| 2602 |
return querySetOperation(oldSet, cc, stack) ; |
| 2603 |
|
| 2604 |
case NAMEDSET: |
| 2605 |
keySetDestroy (oldSet); |
| 2606 |
|
| 2607 |
messout("NAMEDSET not yet coded, please complain, sorry") ; |
| 2608 |
return keySetCreate () ; |
| 2609 |
|
| 2610 |
default: |
| 2611 |
if (oldSet) |
| 2612 |
{ |
| 2613 |
queryFilter(oldSet, cc, stack) ; |
| 2614 |
return oldSet ; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
return keySetCreate() ; |
| 2618 |
} |
| 2619 |
|
| 2620 |
/**********************************************************/ |
| 2621 |
/* Hopefully clear local error message on easy errors */ |
| 2622 |
|
| 2623 |
static BOOL checkParentheses (char *text) |
| 2624 |
{ |
| 2625 |
static Stack bra = 0 ; |
| 2626 |
char c, old, hold, *cp = text ; |
| 2627 |
BOOL tt = FALSE ; |
| 2628 |
|
| 2629 |
bra = stackReCreate (bra, 40) ; |
| 2630 |
while ((c = *cp++)) |
| 2631 |
{ |
| 2632 |
if (c == '\\') |
| 2633 |
{ if (*cp) cp++ ; /* jump protected char */ |
| 2634 |
continue ; |
| 2635 |
} |
| 2636 |
if (c == '\"') tt = !tt ; |
| 2637 |
if (!tt) |
| 2638 |
switch (c) |
| 2639 |
{ |
| 2640 |
case '{': push (bra, '}', char) ; break ; |
| 2641 |
case '[': push (bra, ']', char) ; break ; |
| 2642 |
case '(': push (bra, ')', char) ; break ; |
| 2643 |
case '}': case ']': case ')': |
| 2644 |
if (stackEmpty (bra)) |
| 2645 |
{ hold = *cp ; *cp = 0 ; |
| 2646 |
messout ("Unbalanced %c in:\n %s", c, text) ; |
| 2647 |
*cp = hold ; |
| 2648 |
return FALSE ; |
| 2649 |
} |
| 2650 |
old = pop (bra, char) ; |
| 2651 |
if (old != c) |
| 2652 |
{ hold = *cp ; *cp = 0 ; |
| 2653 |
messout ("Mismatched %c in:\n %s", c, text) ; |
| 2654 |
*cp = hold ; |
| 2655 |
return FALSE ; |
| 2656 |
} |
| 2657 |
break ; |
| 2658 |
} |
| 2659 |
} |
| 2660 |
|
| 2661 |
if (!stackEmpty (bra)) |
| 2662 |
{ messout ("Missing final %c in:\n %s", pop(bra, char), text) ; |
| 2663 |
return FALSE ; |
| 2664 |
} |
| 2665 |
if (tt) |
| 2666 |
{ messout ("Missing final \" in:\n %s", text) ; |
| 2667 |
return FALSE ; |
| 2668 |
} |
| 2669 |
return TRUE ; |
| 2670 |
} |
| 2671 |
|
| 2672 |
/**********************************************************/ |
| 2673 |
|
| 2674 |
static KEYSET querySingleCommand (KEYSET oldSet, char *text) |
| 2675 |
/* NOTE: this destroys oldSet */ |
| 2676 |
{ COND cond = 0 ; |
| 2677 |
KEYSET newSet = 0 ; |
| 2678 |
|
| 2679 |
if (condConstruct (text, &cond)) |
| 2680 |
{ |
| 2681 |
#ifdef DEBUG |
| 2682 |
int id = oldSet ? oldSet->id : 0 ; |
| 2683 |
#endif |
| 2684 |
newSet = queryExecute (oldSet, /* NOTE: destroys oldSet */ |
| 2685 |
cond->cdt, cond->stack); |
| 2686 |
#ifdef DEBUG |
| 2687 |
if (oldSet && oldSet->magic == ARRAY_MAGIC && oldSet->id == id && newSet->id != id) |
| 2688 |
messcrash ("querySingleCommand():\n" |
| 2689 |
" oldSet should have been destroyed!"); |
| 2690 |
#endif |
| 2691 |
condDestroy (cond) ; |
| 2692 |
} |
| 2693 |
else |
| 2694 |
keySetDestroy(oldSet); |
| 2695 |
|
| 2696 |
return newSet ; |
| 2697 |
} |
| 2698 |
|
| 2699 |
/**********************************************************/ |
| 2700 |
KEYSET oldSetForServer = 0 ; |
| 2701 |
/* Can process several command separated by semi columns */ |
| 2702 |
KEYSET queryParametrized (KEYSET oldSet, char *text, char* parms) |
| 2703 |
{ |
| 2704 |
KEYSET newSet = 0, runningSet = 0 ; |
| 2705 |
static Stack myText = 0 , runningText = 0 ; |
| 2706 |
int m, mine ; |
| 2707 |
char *cp ; |
| 2708 |
|
| 2709 |
static int subQueryLevel = 0 ; |
| 2710 |
if (externalServer) |
| 2711 |
{ |
| 2712 |
/* ignore parms, i think they are never used */ |
| 2713 |
oldSetForServer = oldSet ; |
| 2714 |
cp = strnew (text,0) ; /* stabilize text, it may be a messprintf */ |
| 2715 |
newSet = externalServer (-1, cp, 0, FALSE) ; |
| 2716 |
messfree(cp) ; |
| 2717 |
return newSet ; |
| 2718 |
/* -1 means export oldset to server for evaluation */ |
| 2719 |
} |
| 2720 |
|
| 2721 |
|
| 2722 |
/* oldSet belongs to calling routine */ |
| 2723 |
runningSet = keySetExists(oldSet) ? keySetCopy(oldSet) : 0 ; |
| 2724 |
|
| 2725 |
if (!subQueryLevel++) |
| 2726 |
{ doInterrupt = FALSE ; |
| 2727 |
subQ = arrayReCreate(subQ, 8, Array) ; |
| 2728 |
myText = stackReCreate(myText, 80) ; |
| 2729 |
} |
| 2730 |
|
| 2731 |
m = stackMark(myText) ; |
| 2732 |
if (text) |
| 2733 |
pushText(myText, text) ; |
| 2734 |
mine = freesettext (stackText(myText, m),parms) ; |
| 2735 |
freespecial ("\n\t/%\\@") ; /* No subshells ($ removed) */ |
| 2736 |
while (!doInterrupt && freecard(mine)) |
| 2737 |
{ |
| 2738 |
if ((cp = freepos()) && *cp) |
| 2739 |
{ |
| 2740 |
#ifdef DEBUG |
| 2741 |
int id = runningSet ? runningSet->id : 0 ; |
| 2742 |
#endif |
| 2743 |
runningText = stackReCreate(runningText, 80) ; |
| 2744 |
pushText(runningText, cp) ; |
| 2745 |
|
| 2746 |
newSet = |
| 2747 |
querySingleCommand(runningSet, /* destroys runningSet */ |
| 2748 |
stackText(runningText,0)) ; |
| 2749 |
|
| 2750 |
#ifdef DEBUG |
| 2751 |
if (newSet->id != id && |
| 2752 |
runningSet && runningSet->magic == ARRAY_MAGIC && |
| 2753 |
runningSet->id == id) |
| 2754 |
messcrash("queryParametrized() - " |
| 2755 |
"runningSet should have been destroyed by " |
| 2756 |
"querySingleCommand()!\n"); |
| 2757 |
#endif |
| 2758 |
|
| 2759 |
runningSet = newSet ; |
| 2760 |
} |
| 2761 |
} |
| 2762 |
while (freecard (mine)) ; /* if interrupted */ |
| 2763 |
if (!newSet) /* happens in case text = 0, |
| 2764 |
or when, the query was incorrect |
| 2765 |
(e.g. a messerror in cdtReorder) */ |
| 2766 |
newSet = keySetCreate() ; |
| 2767 |
if (!--subQueryLevel) |
| 2768 |
{ m = arrayMax(subQ) ; |
| 2769 |
while(m--) |
| 2770 |
arrayDestroy(arr(subQ,m,Array)) ; |
| 2771 |
arrayDestroy(subQ) ; |
| 2772 |
} |
| 2773 |
return newSet ; |
| 2774 |
} |
| 2775 |
|
| 2776 |
/***************************************************************************/ |
| 2777 |
/* filter text applied to a single key */ |
| 2778 |
/* avoids having to create s each time */ |
| 2779 |
KEYSET queryKeyParametrized (KEY key, char *text, char *parms) |
| 2780 |
{ |
| 2781 |
static KEYSET s = 0 ; |
| 2782 |
if (!s) |
| 2783 |
s = arrayCreate(1,KEY) ; |
| 2784 |
keySet(s,0) = key ; |
| 2785 |
return queryParametrized (s, text, parms) ; |
| 2786 |
} |
| 2787 |
|
| 2788 |
/***************************************************************************/ |
| 2789 |
/* runs on the client, never on server */ |
| 2790 |
|
| 2791 |
KEYSET queryLocalParametrized (KEYSET ks1, char *text, char *parms) |
| 2792 |
{ |
| 2793 |
KEYSET ks = 0 ; |
| 2794 |
KEYSET (*myExternalServer) (KEY key, char *query, char *grep, BOOL getNeighbours) ; |
| 2795 |
|
| 2796 |
myExternalServer = externalServer ; |
| 2797 |
if (externalServer) |
| 2798 |
externalServer (-2,0,0,0) ; /* disable */ |
| 2799 |
ks = queryParametrized (ks1, text, parms) ; |
| 2800 |
if (myExternalServer) |
| 2801 |
myExternalServer (-3,0,0,0) ; /* reenable */ |
| 2802 |
return ks ; |
| 2803 |
} |
| 2804 |
|
| 2805 |
/**********************************************************************/ |
| 2806 |
|
| 2807 |
/* Search all the X classes and all visible names */ |
| 2808 |
|
| 2809 |
KEYSET queryGrep(KEYSET oldSet, char *text) |
| 2810 |
{ |
| 2811 |
KEY k, k1 ; |
| 2812 |
int t, n ; |
| 2813 |
OBJ obj ; |
| 2814 |
char *buffer = 0, *cp, *cq, cc ; |
| 2815 |
KEYSET resultKs = 0, autoKs = 0, namedKs = 0 ; |
| 2816 |
|
| 2817 |
/* clean up spaces except if \ protected */ |
| 2818 |
{ |
| 2819 |
cq = buffer = messalloc (strlen(text) + 1) ; |
| 2820 |
cp = text ; |
| 2821 |
while ((cc = *cp++)) |
| 2822 |
switch (cc) |
| 2823 |
{ |
| 2824 |
case '\\': |
| 2825 |
if (*cp) /* read the char following the \ */ |
| 2826 |
*cq++ = *cp++ ; |
| 2827 |
break ; |
| 2828 |
case ' ': |
| 2829 |
*cq++ = '*' ; |
| 2830 |
break ; |
| 2831 |
default: |
| 2832 |
*cq++ = cc ; |
| 2833 |
break ; |
| 2834 |
} |
| 2835 |
} |
| 2836 |
|
| 2837 |
|
| 2838 |
/* collect is autoKs the autoXrefed classes */ |
| 2839 |
autoKs = keySetCreate() ; n = 0 ; |
| 2840 |
t = 256 ; |
| 2841 |
while(!doInterrupt && t--) |
| 2842 |
{ |
| 2843 |
|
| 2844 |
if (pickXref(t)) /* pick all cross referenced objects */ |
| 2845 |
{ for (k = 0 ; lexNext (t,&k) ;) |
| 2846 |
{ cp = 0 ; |
| 2847 |
cp = name(k) ; |
| 2848 |
|
| 2849 |
if (messIsInterruptCalled()) |
| 2850 |
{ doInterrupt = TRUE ; |
| 2851 |
break ; |
| 2852 |
} |
| 2853 |
|
| 2854 |
if (pickMatch (cp, buffer)) |
| 2855 |
{ if (bIndexFind(k,_Quoted_in) && (obj = bsCreate(k))) |
| 2856 |
{ |
| 2857 |
if (bsGetKey (obj, _Quoted_in, &k1)) |
| 2858 |
do keySet(autoKs,n++) = k1 ; |
| 2859 |
while (bsGetKey (obj, _bsDown, &k1)) ; |
| 2860 |
bsDestroy(obj); |
| 2861 |
} |
| 2862 |
} |
| 2863 |
} |
| 2864 |
} |
| 2865 |
} |
| 2866 |
if (n > 1) |
| 2867 |
{ |
| 2868 |
keySetSort(autoKs) ; |
| 2869 |
keySetCompress(autoKs) ; |
| 2870 |
} |
| 2871 |
|
| 2872 |
namedKs = keySetCreate () ; n = 0 ; |
| 2873 |
if (oldSet) |
| 2874 |
{ |
| 2875 |
/* collect the oldSetNames fitting the template */ |
| 2876 |
for (t = 0 ; !doInterrupt && t < keySetMax(oldSet) ; t++) |
| 2877 |
{ |
| 2878 |
k = keySet(oldSet, t); /* pick matching objects in old only */ |
| 2879 |
cp = 0 ; |
| 2880 |
while (nextName(k, &cp)) |
| 2881 |
if (pickMatch (cp, buffer)) |
| 2882 |
keySet(namedKs, n++) = k ; /* pick Self */ |
| 2883 |
} |
| 2884 |
} |
| 2885 |
else |
| 2886 |
{ |
| 2887 |
/* collect any name fitting the template */ |
| 2888 |
int i ; |
| 2889 |
t = 256 ; |
| 2890 |
while(!doInterrupt && t--) /* pick matching objects everywhere */ |
| 2891 |
if (!pickXref(t)) |
| 2892 |
for (k = i = 0 ; !doInterrupt && lexNext (t,&k) ; i++) |
| 2893 |
{ |
| 2894 |
|
| 2895 |
if (i && (!(i%10)) && messIsInterruptCalled()) |
| 2896 |
{ doInterrupt = TRUE ; |
| 2897 |
break ; |
| 2898 |
} |
| 2899 |
|
| 2900 |
cp = 0 ; |
| 2901 |
while (nextName(k, &cp)) |
| 2902 |
if (pickMatch (cp, buffer)) |
| 2903 |
keySet(namedKs, n++) = k ; /* pick Self */ |
| 2904 |
} |
| 2905 |
} |
| 2906 |
|
| 2907 |
if (n > 1) |
| 2908 |
{ |
| 2909 |
keySetSort(namedKs) ; |
| 2910 |
keySetCompress(namedKs) ; |
| 2911 |
} |
| 2912 |
|
| 2913 |
if (externalServer) /* merge with objects from the server */ |
| 2914 |
{ |
| 2915 |
KEYSET tmp = autoKs ; |
| 2916 |
KEYSET externalKs = externalServer (0, 0, buffer,FALSE) ; |
| 2917 |
autoKs = keySetOR (tmp, externalKs) ; |
| 2918 |
|
| 2919 |
keySetDestroy (externalKs) ; |
| 2920 |
keySetDestroy (tmp) ; |
| 2921 |
} |
| 2922 |
|
| 2923 |
if (oldSet) /* all that needed to catch the ?Text refered by old */ |
| 2924 |
{ |
| 2925 |
KEYSET tmp = autoKs ; |
| 2926 |
|
| 2927 |
autoKs = keySetAND (oldSet, tmp) ; |
| 2928 |
keySetDestroy (tmp) ; |
| 2929 |
} |
| 2930 |
|
| 2931 |
resultKs = keySetOR (namedKs, autoKs) ; |
| 2932 |
keySetDestroy (autoKs) ; |
| 2933 |
keySetDestroy (namedKs) ; |
| 2934 |
/* DO NOT keySetDestroy (oldSet), it belongs to the calling routine */ |
| 2935 |
messfree(buffer); |
| 2936 |
|
| 2937 |
return resultKs ; |
| 2938 |
} |
| 2939 |
|
| 2940 |
/*********************************************************/ |
| 2941 |
/* checks the syntax of a query */ |
| 2942 |
BOOL condCheckSyntax(char *cp) |
| 2943 |
{ COND cond ; |
| 2944 |
|
| 2945 |
if (cp && |
| 2946 |
condConstruct (cp, &cond)) |
| 2947 |
{ condDestroy(cond) ; return TRUE ; } |
| 2948 |
else |
| 2949 |
return FALSE ; |
| 2950 |
} |
| 2951 |
|
| 2952 |
/*********************************************************/ |
| 2953 |
/* Checks values of filters on object */ |
| 2954 |
unsigned char queryIsA(OBJ obj, KEY key, Array a, BitSet bb) |
| 2955 |
{ COND *condp = a && arrayMax(a) ? arrp(a,0,COND) : 0 ; |
| 2956 |
int i = a ? arrayMax(a) : 0 ; |
| 2957 |
unsigned char mask = 0 ; |
| 2958 |
unsigned int m1 ; |
| 2959 |
OBJ oldObj = obj ; |
| 2960 |
|
| 2961 |
if (!i) return mask ; |
| 2962 |
|
| 2963 |
subObjMarks = stackReCreate(subObjMarks, 8) ; |
| 2964 |
|
| 2965 |
for (i = 0 ; i < arrayMax(a) ; i++) |
| 2966 |
{ if (obj) |
| 2967 |
bsGoto (obj, 0) ; /* RD 960913 IMPORTANT: reset model to root */ |
| 2968 |
if (condFMatch((*condp)->stack, key, &obj, (*condp)->cdt)) |
| 2969 |
bitSet (bb, i) ; |
| 2970 |
condp++ ; |
| 2971 |
} |
| 2972 |
if (!oldObj && obj) /* locally created */ |
| 2973 |
bsDestroy (obj) ; |
| 2974 |
m1 = arrayMax(bb) ? arr (bb, 0, unsigned int) : 0 ; |
| 2975 |
mask = (unsigned char) (m1 & 0xff) ; /* extract lowest byte */ |
| 2976 |
return mask ; |
| 2977 |
} |
| 2978 |
|
| 2979 |
/*********************************************************/ |
| 2980 |
/* Checks validity of a query if !key, or if key belongs to subclass */ |
| 2981 |
BOOL queryIsAInit (Stack s, Array a) |
| 2982 |
{ COND cond ; |
| 2983 |
char *cp ; |
| 2984 |
int n = 0 ; |
| 2985 |
|
| 2986 |
stackCursor(s, 0) ; |
| 2987 |
if (stackNextText(s)) |
| 2988 |
while ((cp = stackNextText(s))) |
| 2989 |
{ if (cp && |
| 2990 |
condConstruct (cp, &cond)) |
| 2991 |
array(a, n++, COND) = cond ; |
| 2992 |
else |
| 2993 |
messcrash ("Bad condition %s in subclass definition ", cp) ; |
| 2994 |
} |
| 2995 |
return TRUE ; |
| 2996 |
} |
| 2997 |
|
| 2998 |
/*********************************************************/ |
| 2999 |
/* Checks validity of a query if !key, or if key belongs to subclass */ |
| 3000 |
BOOL constraintsInit (Stack s, Array a) |
| 3001 |
{ COND cond ; |
| 3002 |
char *cp ; |
| 3003 |
int n = 0 ; |
| 3004 |
|
| 3005 |
stackCursor(s, 0) ; |
| 3006 |
if (stackNextText(s)) |
| 3007 |
while ((cp = stackNextText(s))) |
| 3008 |
{ if (cp && |
| 3009 |
condConstruct (cp, &cond)) |
| 3010 |
array(a, n++, COND) = cond ; |
| 3011 |
else |
| 3012 |
messcrash ("Bad condition %s in constraint definition ", cp) ; |
| 3013 |
} |
| 3014 |
return TRUE ; |
| 3015 |
} |
| 3016 |
|
| 3017 |
/*********************************************************/ |
| 3018 |
|
| 3019 |
BOOL queryFind (OBJ obj, KEY key, char *cp) |
| 3020 |
{ |
| 3021 |
static COND cond = 0 ; |
| 3022 |
BOOL result ; |
| 3023 |
|
| 3024 |
/* if !cp, i use again the same condition */ |
| 3025 |
if (cp) /* construct cond */ |
| 3026 |
{ if (cond) |
| 3027 |
{ condDestroy(cond) ; |
| 3028 |
cond = 0 ; |
| 3029 |
} |
| 3030 |
if ( !condConstruct (cp, &cond)) |
| 3031 |
return FALSE ; |
| 3032 |
} |
| 3033 |
else |
| 3034 |
if (!cond) |
| 3035 |
messcrash ("First call to queryFind must give a query text") ; |
| 3036 |
|
| 3037 |
queryFindCond = cond ; |
| 3038 |
if (!key) |
| 3039 |
return TRUE ; |
| 3040 |
|
| 3041 |
doPushPopSubObj = FALSE ; |
| 3042 |
result = condFMatch(cond->stack, key, (OBJ*)(&obj), cond->cdt) ; |
| 3043 |
doPushPopSubObj = TRUE ; |
| 3044 |
|
| 3045 |
return result ; |
| 3046 |
} |
| 3047 |
|
| 3048 |
/*********************************************************/ |
| 3049 |
|
| 3050 |
BOOL queryFind2 (OBJ *objp, KEY key, char *cp) |
| 3051 |
{ |
| 3052 |
static COND cond = 0 ; |
| 3053 |
BOOL result ; |
| 3054 |
/* if !cp, i use again the same condition */ |
| 3055 |
if (cp) /* construct cond */ |
| 3056 |
{ if (cond) |
| 3057 |
{ condDestroy(cond) ; |
| 3058 |
cond = 0 ; |
| 3059 |
} |
| 3060 |
if (!condConstruct (cp, &cond)) |
| 3061 |
return FALSE ; |
| 3062 |
} |
| 3063 |
else |
| 3064 |
if (!cond) |
| 3065 |
messcrash ("First call to queryFind2 must give a query text") ; |
| 3066 |
|
| 3067 |
if (!key) |
| 3068 |
return FALSE ; /* not same as above ! */ |
| 3069 |
|
| 3070 |
doPushPopSubObj = FALSE ; |
| 3071 |
result = |
| 3072 |
condFMatch(cond->stack, key, objp, cond->cdt) ; |
| 3073 |
doPushPopSubObj = TRUE ; |
| 3074 |
|
| 3075 |
return result ; |
| 3076 |
} |
| 3077 |
|
| 3078 |
BOOL queryFind21 (OBJ *objp, KEY key, char *cp, char *tname) |
| 3079 |
{ |
| 3080 |
querySetTextName (tname) ; |
| 3081 |
return queryFind2 (objp,key,cp) ; |
| 3082 |
} |
| 3083 |
|
| 3084 |
/*********************************************************/ |
| 3085 |
|
| 3086 |
BOOL queryFind3 (COND cond, OBJ *objp, KEY key) |
| 3087 |
{ BOOL result ; |
| 3088 |
|
| 3089 |
if (!key || !cond) |
| 3090 |
return TRUE ; |
| 3091 |
doPushPopSubObj = FALSE ; |
| 3092 |
result = |
| 3093 |
condFMatch(cond->stack, key, objp, cond->cdt) ; |
| 3094 |
doPushPopSubObj = TRUE ; |
| 3095 |
|
| 3096 |
return result ; |
| 3097 |
} |
| 3098 |
|
| 3099 |
BOOL queryFind31 (COND cond, OBJ *objp, KEY key, char *tname) |
| 3100 |
{ |
| 3101 |
querySetTextName (tname) ; |
| 3102 |
return queryFind3 (cond, objp, key) ; |
| 3103 |
} |
| 3104 |
|
| 3105 |
/*********************************************************/ |
| 3106 |
/* |
| 3107 |
void cdtTest(void) |
| 3108 |
{ COND cond ; |
| 3109 |
char * cp ; |
| 3110 |
while(messPrompt("Test queryScan : ", "", "t") ) |
| 3111 |
if (cp = freeword() && |
| 3112 |
condConstruct(cp,&cond) ) |
| 3113 |
{ |
| 3114 |
cdtDump(cond->stack, cond->cdt, 0, FALSE) ; |
| 3115 |
condDestroy(cond) ; |
| 3116 |
} |
| 3117 |
} |
| 3118 |
*/ |
| 3119 |
/*********************************************************/ |
| 3120 |
/*********************************************************/ |
| 3121 |
|
| 3122 |
BOOL queryCalcul (char *buf, int *ip, float *fp) |
| 3123 |
{ |
| 3124 |
BOOL ok = FALSE ; |
| 3125 |
OBJ obj = 0 ; |
| 3126 |
COND cond = 0 ; |
| 3127 |
CDT cdt = 0 ; |
| 3128 |
|
| 3129 |
if (!ip && !fp) |
| 3130 |
messcrash ("queryCalcul received 2 void pointers") ; |
| 3131 |
|
| 3132 |
if (condCheckSyntax (buf)) |
| 3133 |
{ |
| 3134 |
if (condConstruct (buf, &cond)) |
| 3135 |
{ |
| 3136 |
cdt = cond->cdt ; |
| 3137 |
if (cdt->qop == CALCUL && condMatch(cond->stack,0,&obj, cdt)) |
| 3138 |
{ |
| 3139 |
if (ip) |
| 3140 |
{ |
| 3141 |
*ip = cdt->n.x ; |
| 3142 |
} |
| 3143 |
else if (fp) |
| 3144 |
{ |
| 3145 |
*fp = cdt->n.x ; |
| 3146 |
} |
| 3147 |
ok = TRUE ; |
| 3148 |
} |
| 3149 |
} |
| 3150 |
} |
| 3151 |
condDestroy (cond) ; |
| 3152 |
return ok ; |
| 3153 |
} |
| 3154 |
|
| 3155 |
/*********************************************************/ |
| 3156 |
/*********************************************************/ |
| 3157 |
|
| 3158 |
BOOL queryCheckConstraints (OBJ obj, KEY key, void *v) |
| 3159 |
{ |
| 3160 |
COND cond = (COND) v ; |
| 3161 |
|
| 3162 |
return |
| 3163 |
condFMatch(cond->stack, key, &obj, cond->cdt) ; |
| 3164 |
} |
| 3165 |
|
| 3166 |
/*********************************************************/ |
| 3167 |
|
| 3168 |
void queryClearConstraints (void) |
| 3169 |
{ COND cond ; |
| 3170 |
int i = 256 ; |
| 3171 |
|
| 3172 |
while (i--) |
| 3173 |
if ((cond = pickList [i].constraints)) |
| 3174 |
{ condDestroy (cond) ; |
| 3175 |
pickList [i].constraints = 0 ; |
| 3176 |
} |
| 3177 |
} |
| 3178 |
|
| 3179 |
/*********************************************************/ |
| 3180 |
|
| 3181 |
BOOL queryConstraintsInit (char *text, int classe) |
| 3182 |
{ COND cond ; |
| 3183 |
|
| 3184 |
if (condConstruct (text, &cond)) |
| 3185 |
{ pickList [classe].constraints = cond ; |
| 3186 |
return TRUE ; |
| 3187 |
} |
| 3188 |
return FALSE ; |
| 3189 |
} |
| 3190 |
|
| 3191 |
/*********************************************************/ |
| 3192 |
/*********************************************************/ |
| 3193 |
|
| 3194 |
|
| 3195 |
|