| 1 |
/* File: picksubs.c |
| 2 |
* Author: Jean Thierry-Mieg ([email protected]) |
| 3 |
* Copyright (C) J Thierry-Mieg and R Durbin, 1992 |
| 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 |
* Exported functions: |
| 26 |
pickInit |
| 27 |
must be called once at start of program. |
| 28 |
pickWord2Class() |
| 29 |
returns a class number |
| 30 |
pickMatch matches a name to a template |
| 31 |
accepts the wild char * (anything) and ? (single character). |
| 32 |
|
| 33 |
* HISTORY: |
| 34 |
* Last edited: Feb 10 15:49 2004 (edgrif) |
| 35 |
* * Sep 28 14:53 1992 (mieg): a fix because one tag has a - rather than _ |
| 36 |
* * Apr 2 13:41 1992 (mieg): Simplified customization by defining |
| 37 |
the new wspec files (sys)options and displays. |
| 38 |
* Created: Thu Apr 2 13:41:10 1992 (mieg) |
| 39 |
*------------------------------------------------------------------- |
| 40 |
*/ |
| 41 |
|
| 42 |
#include <ctype.h> |
| 43 |
#include "acedb.h" |
| 44 |
#include "aceio.h" |
| 45 |
#include "pick.h" |
| 46 |
#include "lex.h" |
| 47 |
#include "session.h" |
| 48 |
#include "bs.h" |
| 49 |
#include "query.h" |
| 50 |
#include "whooks/systags.h" |
| 51 |
#include "whooks/sysclass.h" |
| 52 |
#include "whooks/tags.h" |
| 53 |
#include "dbpath.h" |
| 54 |
#include "utils.h" |
| 55 |
|
| 56 |
|
| 57 |
/******************************************************************/ |
| 58 |
|
| 59 |
extern BOOL READING_MODELS ; |
| 60 |
|
| 61 |
|
| 62 |
/******************************************************************/ |
| 63 |
|
| 64 |
typedef struct { KEY mainClasse ; unsigned char mask ; } CLASS_MASK ; |
| 65 |
|
| 66 |
|
| 67 |
/******************************************************************/ |
| 68 |
|
| 69 |
FREEOPT pickVocList[256] = { {0, "Choose from"}} ; |
| 70 |
PICKLIST pickList[256] ; |
| 71 |
|
| 72 |
|
| 73 |
/******************************************************************/ |
| 74 |
|
| 75 |
static Stack pickStack = NULL ; |
| 76 |
static Array clA = NULL ; |
| 77 |
static Array classMasks = NULL ; |
| 78 |
static Array classComposite = NULL ; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
/********************************************/ |
| 83 |
|
| 84 |
char *className(KEY kk) |
| 85 |
{ |
| 86 |
return stackText(pickStack, pickList[class(kk)].name) ; |
| 87 |
} |
| 88 |
|
| 89 |
/********************************************/ |
| 90 |
|
| 91 |
char *pickClass2Word (int classe) |
| 92 |
{ |
| 93 |
return className(KEYMAKE(classe,0)) ; |
| 94 |
} |
| 95 |
|
| 96 |
/********************************************/ |
| 97 |
|
| 98 |
int superClass (KEY cl) |
| 99 |
{ |
| 100 |
pickIsA (&cl, 0) ; |
| 101 |
|
| 102 |
return cl ; |
| 103 |
} |
| 104 |
|
| 105 |
/********************************************/ |
| 106 |
|
| 107 |
/* Given the key that equates to "?<model>" (e.g. "?Sequence") |
| 108 |
* as found in the model for a class, return the class, returns 0 on failure. |
| 109 |
* Seems surprising this doesn't already exist, perhaps it does and I just |
| 110 |
* couldn't find it. */ |
| 111 |
int classModel2Class(KEY class_model_key) |
| 112 |
{ |
| 113 |
int class = 0 ; |
| 114 |
char *class_name ; |
| 115 |
|
| 116 |
class_name = name(class_model_key) ; |
| 117 |
if (*class_name == '?') |
| 118 |
{ |
| 119 |
class_name++ ; |
| 120 |
class = pickWord2Class(class_name) ; |
| 121 |
} |
| 122 |
|
| 123 |
return class ; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
/********************************************/ |
| 128 |
Array pickIsComposite(KEY classe) |
| 129 |
{ |
| 130 |
int c; |
| 131 |
|
| 132 |
if (classe > 256) |
| 133 |
{ |
| 134 |
if (class(classe) != _VClass) |
| 135 |
messcrash("Non-class passed to pickIsComposite"); |
| 136 |
c = KEYKEY(classe); |
| 137 |
} |
| 138 |
else |
| 139 |
c = classe; |
| 140 |
|
| 141 |
return array(classComposite, c, Array); |
| 142 |
} |
| 143 |
|
| 144 |
BOOL pickBelongsToComposite(KEY classe, KEY key) |
| 145 |
{ |
| 146 |
Array a = pickIsComposite(classe); |
| 147 |
int i; |
| 148 |
|
| 149 |
if (classe > 256) |
| 150 |
classe = KEYKEY(classe); |
| 151 |
|
| 152 |
if (!a) |
| 153 |
return classe == class(key) ; |
| 154 |
|
| 155 |
for (i = 0 ; i < arrayMax(a) ; i++) |
| 156 |
{ |
| 157 |
if (KEYKEY(array(a, i, KEY)) == class(key)) |
| 158 |
return TRUE; |
| 159 |
} |
| 160 |
|
| 161 |
return FALSE; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
/********************************************/ |
| 167 |
|
| 168 |
BOOL pickIsA (KEY *classp, unsigned char *maskp) |
| 169 |
{ |
| 170 |
KEY key ; |
| 171 |
|
| 172 |
if (maskp) *maskp = 0x00 ; /* Normal situation */ |
| 173 |
if (*classp > 256) |
| 174 |
{ |
| 175 |
#ifdef OLDJUNK |
| 176 |
if ((obj = bsCreate(*classp))) |
| 177 |
{ |
| 178 |
if (bsGetData (obj,_Belongs_to_class, _Int, &topClass)) |
| 179 |
{ n = 0 ; |
| 180 |
bsGetData (obj,_Mask, _Int, &n) ; |
| 181 |
*maskp = (unsigned char) n ; |
| 182 |
*classp = topClass ; |
| 183 |
} |
| 184 |
bsDestroy(obj) ; |
| 185 |
} |
| 186 |
#endif |
| 187 |
if (class(*classp) == _VClass && classMasks && |
| 188 |
(key = KEYKEY (*classp)) && key < arrayMax(classMasks)) |
| 189 |
{ |
| 190 |
if (maskp) *maskp = arr(classMasks, key, CLASS_MASK).mask ; |
| 191 |
*classp = arr(classMasks, key, CLASS_MASK).mainClasse ; |
| 192 |
return TRUE ; |
| 193 |
} |
| 194 |
*classp = 0 ; |
| 195 |
return FALSE ; |
| 196 |
} |
| 197 |
|
| 198 |
return TRUE ; |
| 199 |
} |
| 200 |
|
| 201 |
/******************************************************************/ |
| 202 |
|
| 203 |
static void pickGetClassNames(void) |
| 204 |
{ |
| 205 |
int k , v ; |
| 206 |
KEY key = 0 ; |
| 207 |
|
| 208 |
pickStack = stackCreate(200) ; |
| 209 |
pushText(pickStack,"System") ; /* prevents name = 0 */ |
| 210 |
|
| 211 |
|
| 212 |
clA = arrayCreate(20, int) ; |
| 213 |
v = 0 ; |
| 214 |
|
| 215 |
while(lexNext (_VMainClasses, &key)) |
| 216 |
{ k = KEYKEY(key) ; |
| 217 |
if (*name(key) != '_') |
| 218 |
pickList[k].name = stackMark(pickStack) ; |
| 219 |
pushText(pickStack, name(key) ); |
| 220 |
array(clA, v++, int) = k ; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
/******************************************************************/ |
| 225 |
|
| 226 |
static KEYSET classAppearance = 0 ; |
| 227 |
static FREEOPT classOptions[] = |
| 228 |
{ |
| 229 |
{13, "class options"}, |
| 230 |
{'h', "Hidden"}, |
| 231 |
{'v', "Visible"}, |
| 232 |
{'a', "Array"}, |
| 233 |
{'b', "Btree"}, |
| 234 |
{'x', "XREF"}, |
| 235 |
{'d', "Display"}, |
| 236 |
{'t', "Title"}, |
| 237 |
{'s', "Symbol"}, |
| 238 |
{'r', "Rename"}, |
| 239 |
{'c', "CaseSensitive"}, |
| 240 |
{'p', "Protected"}, |
| 241 |
{'S', "Sybase"}, |
| 242 |
{'k', "Known"} |
| 243 |
} ; |
| 244 |
|
| 245 |
int pickMakeClass (char* cp) |
| 246 |
{ |
| 247 |
KEY key, model, class, classeKey ; |
| 248 |
int k, k1 ; |
| 249 |
|
| 250 |
|
| 251 |
lexaddkey (cp, &key, _VMainClasses) ; k = KEYKEY (key) ; |
| 252 |
lexaddkey (cp, &classeKey, _VClass) ; k1 = KEYKEY (classeKey) ; |
| 253 |
|
| 254 |
if (!classMasks) classMasks = arrayCreate (128, CLASS_MASK) ; |
| 255 |
array (classMasks, k1, CLASS_MASK).mainClasse = k ; |
| 256 |
|
| 257 |
if (!classComposite) classComposite = arrayCreate (128, Array) ; |
| 258 |
array (classComposite, k1, Array) = NULL ; |
| 259 |
|
| 260 |
if (_VModel) |
| 261 |
{ |
| 262 |
#ifdef ACEDB4 |
| 263 |
lexaddkey (messprintf("?%s", name(key)), &model, _VModel) ; |
| 264 |
#else |
| 265 |
lexaddkey (messprintf("#%s", name(key)), &model, _VModel) ; |
| 266 |
#endif |
| 267 |
pickList[k].model = model ; |
| 268 |
} |
| 269 |
|
| 270 |
if (!pickList[k].name || !pickList[k].classe || |
| 271 |
strcmp(stackText(pickStack, pickList[k].name),cp)) |
| 272 |
{ pickList[k].name = stackMark(pickStack) ; |
| 273 |
pushText(pickStack, cp) ; |
| 274 |
lexaddkey(cp, &class, _VClass) ; |
| 275 |
lexAlias(class, cp, FALSE, FALSE) ; /* rename it to fix case */ |
| 276 |
|
| 277 |
pickList[k].type = 'B' ; /* default is B */ |
| 278 |
pickList[k].visible = 'v' ; /* for B default is visible */ |
| 279 |
/* attention, model.c redeclares them as V */ |
| 280 |
|
| 281 |
pickList[k].classe = classeKey ; |
| 282 |
} |
| 283 |
|
| 284 |
/* all B classes should be listed in _VModel with the constructed types */ |
| 285 |
|
| 286 |
return k ; |
| 287 |
} /* pickMakeClass */ |
| 288 |
|
| 289 |
/******************************************************************/ |
| 290 |
|
| 291 |
void pickGetClassProperties (BOOL readDisplayTypeOK) |
| 292 |
{ |
| 293 |
int k, nc, i ; |
| 294 |
char *cp, *filename ; |
| 295 |
ACEIN options_in; |
| 296 |
KEY tag , option, dummy ; |
| 297 |
static displayOK = FALSE; |
| 298 |
|
| 299 |
if (readDisplayTypeOK) |
| 300 |
displayOK = TRUE; |
| 301 |
|
| 302 |
filename = dbPathStrictFilName("wspec", "options","wrm", "r", 0); |
| 303 |
if (!filename) |
| 304 |
messExit("Cannot find Class definition file wspec/options.wrm") ; |
| 305 |
|
| 306 |
options_in = aceInCreateFromFile (filename, "r", "", 0); |
| 307 |
messfree(filename); |
| 308 |
|
| 309 |
if (!options_in) |
| 310 |
/* shouldn't really fail after the sessionFilName-check */ |
| 311 |
messExit("Cannot open database without Class definition file!") ; |
| 312 |
|
| 313 |
|
| 314 |
if (!classAppearance) |
| 315 |
{ nc = 0 ; classAppearance = keySetCreate() ; } |
| 316 |
else |
| 317 |
nc = keySetMax(classAppearance) ; |
| 318 |
|
| 319 |
aceInSpecial (options_in, "\n/\t\\"); |
| 320 |
while (aceInCard(options_in)) |
| 321 |
if ((cp = aceInWord(options_in)) && *cp++ == '_' && *cp++ == 'V') |
| 322 |
{ |
| 323 |
if(!*cp) |
| 324 |
messExit("Error in wspec/options.wrm at line %d : " |
| 325 |
"Isolated _V token, please specify a class", |
| 326 |
aceInStreamLine(options_in)) ; |
| 327 |
|
| 328 |
if (!strcmp (cp, "System")) |
| 329 |
k = 0 ; |
| 330 |
else if (!lexword2key(cp, &dummy, _VMainClasses)) |
| 331 |
continue ; /* disregard option of classes without models */ |
| 332 |
else |
| 333 |
k = pickMakeClass (cp) ; |
| 334 |
|
| 335 |
for (i = 0 ; i < nc ; ++i) |
| 336 |
if (keySet(classAppearance, i) == k) |
| 337 |
break ; |
| 338 |
if (i == nc) /* not found */ |
| 339 |
keySet(classAppearance, nc++) = k ; |
| 340 |
|
| 341 |
while (TRUE) |
| 342 |
{ |
| 343 |
aceInNext (options_in) ; |
| 344 |
if (!aceInStep(options_in, '-')) |
| 345 |
{ |
| 346 |
if ((cp = aceInWord(options_in))) |
| 347 |
messExit ("Error in wspec/options.wrm at line %d : " |
| 348 |
"no hyphen '-' at start of option %s", |
| 349 |
aceInStreamLine(options_in), |
| 350 |
aceInPos(options_in)) ; |
| 351 |
else |
| 352 |
break ; |
| 353 |
} |
| 354 |
|
| 355 |
if (!aceInKey(options_in, &option, classOptions)) |
| 356 |
messExit("Error in wspec/options.wrm at line %d : " |
| 357 |
"unknown option %s", |
| 358 |
aceInStreamLine(options_in), |
| 359 |
aceInPos(options_in)) ; |
| 360 |
|
| 361 |
switch (option) |
| 362 |
{ |
| 363 |
case 'h': |
| 364 |
pickList[k].visible = 'H' ; /* default is visible */ |
| 365 |
break ; |
| 366 |
case 'v': |
| 367 |
pickList[k].visible = 'V' ; /* default is visible */ |
| 368 |
break ; |
| 369 |
case 'a': |
| 370 |
pickList[k].type = 'A' ; |
| 371 |
break ; |
| 372 |
case 'b': |
| 373 |
pickList[k].type = 'B' ; |
| 374 |
break ; |
| 375 |
case 'x': |
| 376 |
pickList[k].Xref = TRUE ; |
| 377 |
pickList[k].visible = 'H' ; |
| 378 |
pickList[k].type = 'B' ; |
| 379 |
break ; |
| 380 |
case 'd': /* Display type */ |
| 381 |
aceInNext(options_in) ; |
| 382 |
cp = aceInWord(options_in) ; |
| 383 |
if (displayOK) |
| 384 |
{ |
| 385 |
if (!lexword2key (cp, &(pickList[k].displayKey), _VDisplay)) |
| 386 |
messExit ("Error in wspec/options.wrm at line %d : " |
| 387 |
"Bad display type %s", |
| 388 |
aceInStreamLine(options_in), cp) ; |
| 389 |
} |
| 390 |
break ; |
| 391 |
case 't': |
| 392 |
/* Tag for Name expansion */ |
| 393 |
pickList[k].tag = 0 ; |
| 394 |
if ((cp = aceInWord(options_in))) |
| 395 |
{ |
| 396 |
lexaddkey(cp, &tag, _VSystem) ; |
| 397 |
pickList[k].tag = tag ; |
| 398 |
} |
| 399 |
break ; |
| 400 |
case 's': |
| 401 |
/* Tag for Symbol in maps */ |
| 402 |
pickList[k].symbol = 0 ; |
| 403 |
if ((cp = aceInWord(options_in))) |
| 404 |
{ |
| 405 |
lexaddkey(cp, &tag, _VSystem) ; |
| 406 |
pickList[k].symbol = tag ; |
| 407 |
} |
| 408 |
break ; |
| 409 |
case 'r': /* other class name */ |
| 410 |
if ((cp = aceInWord(options_in))) |
| 411 |
{ |
| 412 |
if (!pickList[k].alias) /* Always keep the compilation value */ |
| 413 |
pickList[k].alias = pickList[k].name ; |
| 414 |
pickList[k].name = stackMark(pickStack) ; |
| 415 |
pushText(pickStack, cp) ; |
| 416 |
} |
| 417 |
break ; |
| 418 |
case 'c': |
| 419 |
pickList[k].isCaseSensitive = TRUE ; |
| 420 |
break ; |
| 421 |
case 'p': |
| 422 |
pickList[k].protected = TRUE ; |
| 423 |
break ; |
| 424 |
case 'S': |
| 425 |
pickList[k].sybase = TRUE ; |
| 426 |
break ; |
| 427 |
case 'k': |
| 428 |
pickList[k].known = TRUE ; |
| 429 |
break ; |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
aceInDestroy (options_in); |
| 434 |
|
| 435 |
return; |
| 436 |
} /* pickGetClassProperties */ |
| 437 |
|
| 438 |
/******************************************************************/ |
| 439 |
/* called from whooks/sysclass.c */ |
| 440 |
void pickSetClassOption (char *nom, char type, char v, |
| 441 |
BOOL protected, BOOL private) |
| 442 |
{ |
| 443 |
int i, k, nc ; |
| 444 |
|
| 445 |
if (!classAppearance) |
| 446 |
{ nc = 0 ; classAppearance = keySetCreate() ; } |
| 447 |
else |
| 448 |
nc = keySetMax(classAppearance) ; |
| 449 |
|
| 450 |
if (!strcmp (nom, "System")) |
| 451 |
k = 0 ; |
| 452 |
else |
| 453 |
k = pickMakeClass (nom) ; |
| 454 |
|
| 455 |
for (i = 0 ; i < nc ; ++i) |
| 456 |
if (keySet(classAppearance, i) == k) |
| 457 |
break ; |
| 458 |
if (i == nc) /* not found */ |
| 459 |
keySet(classAppearance, nc++) = k ; |
| 460 |
|
| 461 |
if (!pickList[k].visible || pickList[k].visible == freelower(pickList[k].visible)) |
| 462 |
pickList[k].visible = v ; |
| 463 |
pickList[k].type = type ; |
| 464 |
if (type == 'X') |
| 465 |
{ pickList[k].Xref = TRUE ; |
| 466 |
pickList[k].type = 'B' ; |
| 467 |
pickList[k].isCaseSensitive = TRUE ; |
| 468 |
} |
| 469 |
|
| 470 |
pickList[k].protected = protected ; /* do not parse */ |
| 471 |
pickList[k].private = private ; /* do not dump */ |
| 472 |
#ifdef ACEDB4 |
| 473 |
lexaddkey (messprintf("?%s", nom), &pickList[k].model, _VModel) ; |
| 474 |
#else |
| 475 |
if (pickList[k].type == 'B') |
| 476 |
lexaddkey (messprintf("#%s", nom), &pickList[k].model, _VModel) ; |
| 477 |
#endif |
| 478 |
lexaddkey (nom, &pickList[k].classe, _VClass) ; |
| 479 |
|
| 480 |
return; |
| 481 |
} /* pickSetClassOption */ |
| 482 |
|
| 483 |
void pickSetClassDisplayType (char *nom, char *displayName) |
| 484 |
{ |
| 485 |
KEY key; |
| 486 |
int k; |
| 487 |
|
| 488 |
if (!strcmp (nom, "System")) |
| 489 |
k = 0 ; |
| 490 |
else |
| 491 |
{ |
| 492 |
if (!lexword2key (nom, &key, _VMainClasses)) |
| 493 |
messcrash("pickSetClassDispType() - bad class name %s", nom); |
| 494 |
k = KEYKEY (key) ; |
| 495 |
} |
| 496 |
|
| 497 |
/* this function needs to be called after the main display types |
| 498 |
* have been initialised (only displays with a DisplayFunc should be |
| 499 |
* present in the class 'Display' at this point - see displayInit) */ |
| 500 |
/* If it's called before the display types are initialised |
| 501 |
(and it is, from getNewModels on startup with no database, |
| 502 |
it now fails silently - srk */ |
| 503 |
lexword2key(displayName, &(pickList[k].displayKey), _VDisplay); |
| 504 |
|
| 505 |
return; |
| 506 |
} /* pickSetClassDisplayType */ |
| 507 |
|
| 508 |
/******************************************************************/ |
| 509 |
|
| 510 |
/* Try name, then alias = compilation name */ |
| 511 |
int pickWord2Class(char *word) /* returns class of word */ |
| 512 |
{ |
| 513 |
register int i = 256 ; |
| 514 |
#ifdef ACEDB4 |
| 515 |
while(--i && lexstrcmp(word,stackText(pickStack, pickList[i].name))) ; |
| 516 |
if (!i) |
| 517 |
{ i = 256 ; |
| 518 |
while(--i && |
| 519 |
lexstrcmp(word, stackText(pickStack, pickList[i].alias))); |
| 520 |
} |
| 521 |
#else |
| 522 |
if (!lexstrcmp(word,"System")) |
| 523 |
i = 0 ; |
| 524 |
else |
| 525 |
while (--i && lexstrcmp(word,className(i <<24))) ; |
| 526 |
#endif |
| 527 |
return i ; |
| 528 |
} /* pickWord2Class */ |
| 529 |
|
| 530 |
/*******************************************************************/ |
| 531 |
/*******************************************************************/ |
| 532 |
|
| 533 |
/* match to template with wildcards. Authorized wildchars are * ? # |
| 534 |
? represents any single char |
| 535 |
* represents any set of chars |
| 536 |
case sensitive. Example: *Nc*DE# fits abcaNchjDE23 |
| 537 |
|
| 538 |
returns 0 if not found |
| 539 |
1 + pos of first sigificant match (i.e. not a *) if found |
| 540 |
*/ |
| 541 |
|
| 542 |
static int doPickMatch (char *cp, char *tp, BOOL caseSensitive) |
| 543 |
{ |
| 544 |
char *c=cp, *t=tp; |
| 545 |
char *ts = 0, *cs = 0, *s = 0 ; |
| 546 |
int star=0; |
| 547 |
|
| 548 |
while (TRUE) |
| 549 |
switch(*t) |
| 550 |
{ |
| 551 |
case '\0': |
| 552 |
/* |
| 553 |
return (!*c ? ( s ? 1 + (s - cp) : 1) : 0) ; |
| 554 |
*/ |
| 555 |
if(!*c) |
| 556 |
return ( s ? 1 + (s - cp) : 1) ; |
| 557 |
if (!star) |
| 558 |
return 0 ; |
| 559 |
/* else not success yet go back in template */ |
| 560 |
t=ts; c=cs+1; |
| 561 |
if(ts == tp) s = 0 ; |
| 562 |
break ; |
| 563 |
case '?': |
| 564 |
if (!*c) |
| 565 |
return 0 ; |
| 566 |
if(!s) s = c ; |
| 567 |
t++ ; c++ ; |
| 568 |
break; |
| 569 |
case '*': |
| 570 |
ts=t; |
| 571 |
while( *t == '?' || *t == '*') |
| 572 |
t++; |
| 573 |
if (!*t) |
| 574 |
return s ? 1 + (s-cp) : 1 ; |
| 575 |
if (!caseSensitive) |
| 576 |
{ |
| 577 |
while (freeupper(*c) != freeupper(*t)) |
| 578 |
if(*c) |
| 579 |
c++; |
| 580 |
else |
| 581 |
return 0 ; |
| 582 |
} |
| 583 |
else |
| 584 |
{ |
| 585 |
while (*c != *t) |
| 586 |
if(*c) |
| 587 |
c++; |
| 588 |
else |
| 589 |
return 0 ; |
| 590 |
} |
| 591 |
star=1; |
| 592 |
cs=c; |
| 593 |
if(!s) s = c ; |
| 594 |
break; |
| 595 |
default: |
| 596 |
if (!caseSensitive) |
| 597 |
{ |
| 598 |
if (freeupper(*t++) != freeupper(*c++)) |
| 599 |
{ if(!star) |
| 600 |
return 0 ; |
| 601 |
t=ts; c=cs+1; |
| 602 |
if(ts == tp) s = 0 ; |
| 603 |
} |
| 604 |
else |
| 605 |
if(!s) s = c - 1 ; |
| 606 |
} |
| 607 |
else |
| 608 |
{ |
| 609 |
if (*t++ != *c++) |
| 610 |
{ if(!star) |
| 611 |
return 0 ; |
| 612 |
t=ts; c=cs+1; |
| 613 |
if(ts == tp) s = 0 ; |
| 614 |
} |
| 615 |
else |
| 616 |
if(!s) s = c - 1 ; |
| 617 |
} |
| 618 |
break; |
| 619 |
} |
| 620 |
} /* pickMatch */ |
| 621 |
|
| 622 |
int pickMatch (char *cp,char *tp) |
| 623 |
{ return doPickMatch (cp,tp,FALSE) ; } |
| 624 |
int pickMatchCaseSensitive (char *cp,char *tp, BOOL caseSensitive) |
| 625 |
{ return doPickMatch (cp,tp,caseSensitive) ; } |
| 626 |
|
| 627 |
/**************************************************************/ |
| 628 |
|
| 629 |
static void pickDefaultProperties(void) |
| 630 |
{ |
| 631 |
int j, k ; |
| 632 |
|
| 633 |
/* clA is used to have the Visible Class in main menu in |
| 634 |
* same order as they appear in classes.wrm. |
| 635 |
*/ |
| 636 |
for (j = 0 ; j < arrayMax(clA) ; j++) |
| 637 |
{ k = array(clA, j, int) ; |
| 638 |
if (pickList[k].name) |
| 639 |
{ |
| 640 |
if (!pickList[k].type) /* default is B */ |
| 641 |
pickList[k].type = 'B' ; |
| 642 |
#ifdef JUNK |
| 643 |
/* too early, .model is not yet established */ |
| 644 |
if (!pickList[k].visible) |
| 645 |
{ |
| 646 |
if (pickList[k].type == 'B' && /* for B default is visible */ |
| 647 |
iskey(pickList[k].model)==2) /* iff the model exists */ |
| 648 |
pickList[k].visible = 'v' ; |
| 649 |
else |
| 650 |
pickList[k].visible = 'h' ; /* for A default is hidden */ |
| 651 |
} |
| 652 |
#endif |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
arrayDestroy(clA); |
| 657 |
|
| 658 |
return; |
| 659 |
} /* pickDefaultProperties */ |
| 660 |
|
| 661 |
/******************************************************************/ |
| 662 |
|
| 663 |
void pickRegisterConstraints (void) |
| 664 |
{ OBJ obj ; |
| 665 |
Stack s = 0 ; |
| 666 |
char *cp ; |
| 667 |
KEY key = 0 ; |
| 668 |
KEY mainClasse = 0 ; |
| 669 |
|
| 670 |
while (lexNext (_VClass, &key)) |
| 671 |
{ |
| 672 |
mainClasse = 0 ; |
| 673 |
if ((obj = bsCreate (key))) |
| 674 |
{ if (bsGetData (obj, _Constraints, _Text, &cp)) |
| 675 |
{ if (!s) |
| 676 |
s = stackCreate (50) ; |
| 677 |
pushText (s, messprintf ("(%s)", cp)) ; |
| 678 |
while (bsGetData (obj, _bsDown, _Text, &cp)) |
| 679 |
catText (s, messprintf ("AND ( %s )", cp)) ; |
| 680 |
mainClasse = key ; |
| 681 |
pickIsA (&mainClasse, 0) ; |
| 682 |
} |
| 683 |
bsDestroy (obj) ; |
| 684 |
} |
| 685 |
if (s && stackMark (s) && mainClasse && |
| 686 |
!queryConstraintsInit (stackText(s,0), mainClasse)) |
| 687 |
messExit ("Syntax error in wspec/constraints.wrm, class %s\n: %s\n", |
| 688 |
pickClass2Word (mainClasse), stackText(s,0)) ; |
| 689 |
if (s) stackClear (s) ; |
| 690 |
} |
| 691 |
stackDestroy (s) ; |
| 692 |
} /* pickRegisterConstraints */ |
| 693 |
|
| 694 |
/********************************************************/ |
| 695 |
/******************* Public Routine *********************/ |
| 696 |
/********************************************************/ |
| 697 |
|
| 698 |
/* pickPreInit is a duplicate of pickInit |
| 699 |
it could certainly be simplified but this works like that |
| 700 |
so i don t care (mieg, oct 18,94) |
| 701 |
*/ |
| 702 |
|
| 703 |
|
| 704 |
void pickPreInit(void) |
| 705 |
{ |
| 706 |
BOOL old = READING_MODELS ; |
| 707 |
register int k ; |
| 708 |
|
| 709 |
READING_MODELS = TRUE ; |
| 710 |
|
| 711 |
k = 256 ; |
| 712 |
while(k--) |
| 713 |
pickList[k].type = 0; |
| 714 |
pickList[_VGlobal].type = 'A' ; |
| 715 |
pickList[_VVoc].type = 'A' ; |
| 716 |
|
| 717 |
sysClassInit () ; |
| 718 |
pickList[_VClass].type = 'B' ; /* needed for pickMakeClass() to work */ |
| 719 |
pickList[_VDisplay].type = 'B' ; |
| 720 |
classInit () ; |
| 721 |
|
| 722 |
pickGetClassNames() ; |
| 723 |
|
| 724 |
pickMakeClass ("Session") ; |
| 725 |
|
| 726 |
pickGetClassProperties(FALSE) ; /* options.wrm */ |
| 727 |
sysClassOptions() ; |
| 728 |
|
| 729 |
pickDefaultProperties() ; |
| 730 |
|
| 731 |
READING_MODELS = old ; |
| 732 |
|
| 733 |
return; |
| 734 |
} /* pickPreInit */ |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
void pickInit(void) |
| 739 |
{ |
| 740 |
BOOL old = READING_MODELS ; |
| 741 |
register int k ; |
| 742 |
|
| 743 |
READING_MODELS = TRUE ; |
| 744 |
|
| 745 |
if (classAppearance) |
| 746 |
keySetReCreate(classAppearance); |
| 747 |
|
| 748 |
k = 256 ; |
| 749 |
while(k--) |
| 750 |
{ pickList[k].type = 0; |
| 751 |
pickList[k].name = 0; |
| 752 |
pickList[k].alias = 0; |
| 753 |
pickList[k].visible = 0; |
| 754 |
pickList[k].mask = 0; |
| 755 |
pickList[k].model = 0; |
| 756 |
pickList[k].displayKey = 0; |
| 757 |
pickList[k].protected = 0; |
| 758 |
pickList[k].Xref = FALSE; |
| 759 |
} |
| 760 |
pickList[_VGlobal].type = 'A' ; |
| 761 |
pickList[_VVoc].type = 'A' ; |
| 762 |
|
| 763 |
sysClassInit () ; |
| 764 |
pickList[_VClass].type = 'B' ; /* needed for pickMakeClass() to work */ |
| 765 |
pickList[_VDisplay].type = 'B' ; |
| 766 |
classInit () ; |
| 767 |
|
| 768 |
pickGetClassNames() ; |
| 769 |
|
| 770 |
pickGetClassProperties(FALSE) ; |
| 771 |
sysClassOptions() ; |
| 772 |
|
| 773 |
pickDefaultProperties() ; |
| 774 |
pickRegisterConstraints () ; |
| 775 |
|
| 776 |
READING_MODELS = old ; |
| 777 |
|
| 778 |
return; |
| 779 |
} /* pickInit */ |
| 780 |
|
| 781 |
/******************************************/ |
| 782 |
|
| 783 |
|
| 784 |
/********************************************************/ |
| 785 |
|
| 786 |
static void pickCheckClassDefinitions(void) |
| 787 |
{ |
| 788 |
KEY metaClass = 0, _Buried ; |
| 789 |
int n = 256 ; |
| 790 |
OBJ obj; |
| 791 |
|
| 792 |
#ifdef ACEDB4 |
| 793 |
if (iskey(KEYMAKE(_VClass,0)) != 2) |
| 794 |
return ; /* i.e. the Class model does not yet exists */ |
| 795 |
#else |
| 796 |
if (!lexword2key("#Class", &metaClass, _VModel)) |
| 797 |
return ; /* i.e. the Class model does not yet exists */ |
| 798 |
#endif |
| 799 |
lexaddkey ("Buried", &_Buried, 0) ; |
| 800 |
while (n--) |
| 801 |
{ if (!pickList[n].name) |
| 802 |
continue ; |
| 803 |
|
| 804 |
lexaddkey(pickClass2Word(n), &metaClass, _VClass) ; |
| 805 |
obj = bsUpdate(metaClass) ; |
| 806 |
|
| 807 |
/* too early, .model is not yet esatablished */ |
| 808 |
if (!pickList[n].visible) |
| 809 |
{ |
| 810 |
if (pickList[n].type == 'B' && /* for B default is visible */ |
| 811 |
iskey(pickList[n].model)) /* iff the model exists */ |
| 812 |
pickList[n].visible = 'v' ; |
| 813 |
else |
| 814 |
pickList[n].visible = 'h' ; /* for A default is hidden */ |
| 815 |
} |
| 816 |
|
| 817 |
if (freelower(pickList[n].visible) == 'v') |
| 818 |
bsAddTag(obj, _Visible) ; |
| 819 |
else if (pickList[n].visible == 'H') |
| 820 |
bsAddTag(obj, _Hidden) ; /* show in the triangle */ |
| 821 |
else |
| 822 |
bsAddTag(obj, _Buried) ; /* show nowhere */ |
| 823 |
|
| 824 |
#ifdef ACEDB4 |
| 825 |
/* KLUDGE, mieg sept 96 |
| 826 |
there is clearly a bug here, |
| 827 |
consisder a subclass sub of class c |
| 828 |
sub should not have an entry in pickList and mainclasses |
| 829 |
furthermore, without the kludge, Belongs to class |
| 830 |
is reset in each newe session to sub then to c |
| 831 |
implying always some locked obj, which imply |
| 832 |
taht cache 1 has to get write access silently |
| 833 |
to prevent complete locking |
| 834 |
|
| 835 |
this kludge avoids the problem, but the code |
| 836 |
is not clean as we know in this area |
| 837 |
*/ |
| 838 |
if (!bsFindTag(obj, _Is_a_subclass_of)) /* KLUDGE */ |
| 839 |
/* compiled_as is used in bindex.c before sep 1998 |
| 840 |
* Belongs_to_class is used in pickIsA before sep 1998 |
| 841 |
* it is therefore essential to position them correctly |
| 842 |
* untill ACEDB5 |
| 843 |
*/ |
| 844 |
{ |
| 845 |
bsAddData(obj, _Compiled_as, _Text, |
| 846 |
stackText(pickStack, |
| 847 |
pickList[n].alias ? pickList[n].alias : pickList[n].name |
| 848 |
)) ; |
| 849 |
bsAddData(obj, _bsRight, _Int, &n) ; |
| 850 |
bsAddData(obj, _Belongs_to_class, _Int, &n) ; |
| 851 |
} |
| 852 |
#endif |
| 853 |
bsSave(obj) ; |
| 854 |
} |
| 855 |
} /* pickCheckClassDefinitions */ |
| 856 |
|
| 857 |
/**********************************************************************/ |
| 858 |
|
| 859 |
static void pickRegisterClassMasks(void) |
| 860 |
{ |
| 861 |
KEY key = 0 ; |
| 862 |
int n, k ; |
| 863 |
OBJ obj = 0 ; |
| 864 |
|
| 865 |
while (lexNext(_VClass, &key)) |
| 866 |
{ |
| 867 |
obj = bsCreate (key) ; |
| 868 |
k = KEYKEY (key) ; |
| 869 |
|
| 870 |
if (obj) |
| 871 |
{ |
| 872 |
if (bsGetData(obj, _Belongs_to_class, _Int, &n)) |
| 873 |
array(classMasks, k, CLASS_MASK).mainClasse = n ; |
| 874 |
|
| 875 |
if (bsGetData (obj, _Mask, _Int, &n)) |
| 876 |
array(classMasks, k, CLASS_MASK).mask = n ; |
| 877 |
|
| 878 |
/* The "Composite_of" tag is bound to be followed by several class keys, |
| 879 |
* otherwise what's the point in using it ! So copy them across into |
| 880 |
* an array of keys, _note_ that the bsFlatten array will not do as it is |
| 881 |
* a union of among other things a pointer which may be 8 bytes. */ |
| 882 |
if (bsFindTag(obj, str2tag("Composite_of"))) |
| 883 |
{ |
| 884 |
Array units = arrayCreate(10, BSunit) ; |
| 885 |
|
| 886 |
if (bsFlatten(obj, 1, units)) |
| 887 |
{ |
| 888 |
int i ; |
| 889 |
Array keys ; |
| 890 |
|
| 891 |
keys = arrayCreate(10, KEY) ; |
| 892 |
|
| 893 |
for (i = 0 ; i < arrayMax(units) ; i++) |
| 894 |
{ |
| 895 |
BSunit *u ; |
| 896 |
|
| 897 |
u = arrayp(units, i, BSunit) ; |
| 898 |
|
| 899 |
array(keys, i, KEY) = u[0].k ; |
| 900 |
} |
| 901 |
|
| 902 |
array(classComposite, k, Array) = keys ; |
| 903 |
|
| 904 |
/* Do not make any real objects in this class */ |
| 905 |
pickList[k].protected = TRUE ; |
| 906 |
} |
| 907 |
|
| 908 |
arrayDestroy(units) ; |
| 909 |
} |
| 910 |
|
| 911 |
bsDestroy (obj) ; |
| 912 |
} |
| 913 |
} |
| 914 |
} /* pickRegisterClassMasks */ |
| 915 |
|
| 916 |
/**********************************************************************/ |
| 917 |
void pickVisibility(void) |
| 918 |
{ KEY *classp, metaClass ; |
| 919 |
OBJ obj ; |
| 920 |
KEYSET subclasses = query(0, ">?Class Is_a_subclass_of") ; |
| 921 |
int v = 0, i ; |
| 922 |
|
| 923 |
i= keySetMax(classAppearance) ; |
| 924 |
if(!i) |
| 925 |
return ; |
| 926 |
|
| 927 |
|
| 928 |
classp = arrp(classAppearance,0,KEY) - 1 ; |
| 929 |
while(classp++, i--) |
| 930 |
if (lexword2key(pickClass2Word(*classp), &metaClass, _VClass) && |
| 931 |
( obj = bsCreate(metaClass)) ) |
| 932 |
{ if (bsFindTag(obj, _Visible)) |
| 933 |
{ |
| 934 |
v++ ; |
| 935 |
pickVocList[v].text = name(metaClass) ; |
| 936 |
pickVocList[v].key = metaClass ; |
| 937 |
} |
| 938 |
|
| 939 |
bsDestroy(obj) ; |
| 940 |
if (v >= 254) |
| 941 |
break ; |
| 942 |
} |
| 943 |
|
| 944 |
i= keySetMax(subclasses) ; |
| 945 |
|
| 946 |
classp = arrp(subclasses,0,KEY) - 1 ; |
| 947 |
while(classp++, i--) |
| 948 |
if ((obj = bsCreate(*classp))) |
| 949 |
{ if (bsFindTag(obj, _Visible)) |
| 950 |
{ |
| 951 |
v++ ; |
| 952 |
pickVocList[v].text = name(*classp) ; |
| 953 |
pickVocList[v].key = *classp ; |
| 954 |
} |
| 955 |
|
| 956 |
bsDestroy(obj) ; |
| 957 |
if (v >= 254) |
| 958 |
break ; |
| 959 |
} |
| 960 |
|
| 961 |
keySetDestroy(subclasses) ; |
| 962 |
pickVocList[0].key = v ; |
| 963 |
pickVocList[0].text = "Choose a class" ; |
| 964 |
if (v < 1) |
| 965 |
messout("This database has no visible class.\n" |
| 966 |
"Most probably, you should study and edit\n" |
| 967 |
"the files wspec/options.wrm and wspec/models.wrm,\n", |
| 968 |
"then use the option Read-Models from main menu.") ; |
| 969 |
} |
| 970 |
|
| 971 |
/********************************************************/ |
| 972 |
|
| 973 |
void pickCheckConsistency(void) |
| 974 |
{ |
| 975 |
extern BOOL classSortAll(void) ; |
| 976 |
|
| 977 |
pickCheckClassDefinitions() ; |
| 978 |
pickRegisterClassMasks () ; |
| 979 |
pickVisibility() ; |
| 980 |
classSortAll() ; |
| 981 |
} /* pickCheckConsistency */ |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
/********************* eof ***********************************/ |