1*a1bf3f78SToomas Soome /* 2*a1bf3f78SToomas Soome * s e a r c h . c 3*a1bf3f78SToomas Soome * Forth Inspired Command Language 4*a1bf3f78SToomas Soome * ANS Forth SEARCH and SEARCH-EXT word-set written in C 5*a1bf3f78SToomas Soome * Author: John Sadler (john_sadler@alum.mit.edu) 6*a1bf3f78SToomas Soome * Created: 6 June 2000 7*a1bf3f78SToomas Soome * $Id: search.c,v 1.10 2010/08/12 13:57:22 asau Exp $ 8*a1bf3f78SToomas Soome */ 9*a1bf3f78SToomas Soome /* 10*a1bf3f78SToomas Soome * Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 11*a1bf3f78SToomas Soome * All rights reserved. 12*a1bf3f78SToomas Soome * 13*a1bf3f78SToomas Soome * Get the latest Ficl release at http://ficl.sourceforge.net 14*a1bf3f78SToomas Soome * 15*a1bf3f78SToomas Soome * I am interested in hearing from anyone who uses Ficl. If you have 16*a1bf3f78SToomas Soome * a problem, a success story, a defect, an enhancement request, or 17*a1bf3f78SToomas Soome * if you would like to contribute to the Ficl release, please 18*a1bf3f78SToomas Soome * contact me by email at the address above. 19*a1bf3f78SToomas Soome * 20*a1bf3f78SToomas Soome * L I C E N S E and D I S C L A I M E R 21*a1bf3f78SToomas Soome * 22*a1bf3f78SToomas Soome * Redistribution and use in source and binary forms, with or without 23*a1bf3f78SToomas Soome * modification, are permitted provided that the following conditions 24*a1bf3f78SToomas Soome * are met: 25*a1bf3f78SToomas Soome * 1. Redistributions of source code must retain the above copyright 26*a1bf3f78SToomas Soome * notice, this list of conditions and the following disclaimer. 27*a1bf3f78SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 28*a1bf3f78SToomas Soome * notice, this list of conditions and the following disclaimer in the 29*a1bf3f78SToomas Soome * documentation and/or other materials provided with the distribution. 30*a1bf3f78SToomas Soome * 31*a1bf3f78SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 32*a1bf3f78SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33*a1bf3f78SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34*a1bf3f78SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 35*a1bf3f78SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36*a1bf3f78SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37*a1bf3f78SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38*a1bf3f78SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39*a1bf3f78SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40*a1bf3f78SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41*a1bf3f78SToomas Soome * SUCH DAMAGE. 42*a1bf3f78SToomas Soome */ 43*a1bf3f78SToomas Soome 44*a1bf3f78SToomas Soome #include <string.h> 45*a1bf3f78SToomas Soome #include "ficl.h" 46*a1bf3f78SToomas Soome 47*a1bf3f78SToomas Soome /* 48*a1bf3f78SToomas Soome * d e f i n i t i o n s 49*a1bf3f78SToomas Soome * SEARCH ( -- ) 50*a1bf3f78SToomas Soome * Make the compilation word list the same as the first word list in the 51*a1bf3f78SToomas Soome * search order. Specifies that the names of subsequent definitions will 52*a1bf3f78SToomas Soome * be placed in the compilation word list. Subsequent changes in the search 53*a1bf3f78SToomas Soome * order will not affect the compilation word list. 54*a1bf3f78SToomas Soome */ 55*a1bf3f78SToomas Soome static void 56*a1bf3f78SToomas Soome ficlPrimitiveDefinitions(ficlVm *vm) 57*a1bf3f78SToomas Soome { 58*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 59*a1bf3f78SToomas Soome 60*a1bf3f78SToomas Soome FICL_VM_ASSERT(vm, dictionary); 61*a1bf3f78SToomas Soome if (dictionary->wordlistCount < 1) { 62*a1bf3f78SToomas Soome ficlVmThrowError(vm, "DEFINITIONS error - empty search order"); 63*a1bf3f78SToomas Soome } 64*a1bf3f78SToomas Soome 65*a1bf3f78SToomas Soome dictionary->compilationWordlist = 66*a1bf3f78SToomas Soome dictionary->wordlists[dictionary->wordlistCount-1]; 67*a1bf3f78SToomas Soome } 68*a1bf3f78SToomas Soome 69*a1bf3f78SToomas Soome /* 70*a1bf3f78SToomas Soome * f o r t h - w o r d l i s t 71*a1bf3f78SToomas Soome * SEARCH ( -- wid ) 72*a1bf3f78SToomas Soome * Return wid, the identifier of the word list that includes all standard 73*a1bf3f78SToomas Soome * words provided by the implementation. This word list is initially the 74*a1bf3f78SToomas Soome * compilation word list and is part of the initial search order. 75*a1bf3f78SToomas Soome */ 76*a1bf3f78SToomas Soome static void 77*a1bf3f78SToomas Soome ficlPrimitiveForthWordlist(ficlVm *vm) 78*a1bf3f78SToomas Soome { 79*a1bf3f78SToomas Soome ficlHash *hash = ficlVmGetDictionary(vm)->forthWordlist; 80*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, hash); 81*a1bf3f78SToomas Soome } 82*a1bf3f78SToomas Soome 83*a1bf3f78SToomas Soome 84*a1bf3f78SToomas Soome /* 85*a1bf3f78SToomas Soome * g e t - c u r r e n t 86*a1bf3f78SToomas Soome * SEARCH ( -- wid ) 87*a1bf3f78SToomas Soome * Return wid, the identifier of the compilation word list. 88*a1bf3f78SToomas Soome */ 89*a1bf3f78SToomas Soome static void 90*a1bf3f78SToomas Soome ficlPrimitiveGetCurrent(ficlVm *vm) 91*a1bf3f78SToomas Soome { 92*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 93*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 94*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, dictionary->compilationWordlist); 95*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 96*a1bf3f78SToomas Soome } 97*a1bf3f78SToomas Soome 98*a1bf3f78SToomas Soome /* 99*a1bf3f78SToomas Soome * g e t - o r d e r 100*a1bf3f78SToomas Soome * SEARCH ( -- widn ... wid1 n ) 101*a1bf3f78SToomas Soome * Returns the number of word lists n in the search order and the word list 102*a1bf3f78SToomas Soome * identifiers widn ... wid1 identifying these word lists. wid1 identifies 103*a1bf3f78SToomas Soome * the word list that is searched first, and widn the word list that is 104*a1bf3f78SToomas Soome * searched last. The search order is unaffected. 105*a1bf3f78SToomas Soome */ 106*a1bf3f78SToomas Soome static void 107*a1bf3f78SToomas Soome ficlPrimitiveGetOrder(ficlVm *vm) 108*a1bf3f78SToomas Soome { 109*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 110*a1bf3f78SToomas Soome int wordlistCount = dictionary->wordlistCount; 111*a1bf3f78SToomas Soome int i; 112*a1bf3f78SToomas Soome 113*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 114*a1bf3f78SToomas Soome for (i = 0; i < wordlistCount; i++) { 115*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, dictionary->wordlists[i]); 116*a1bf3f78SToomas Soome } 117*a1bf3f78SToomas Soome 118*a1bf3f78SToomas Soome ficlStackPushUnsigned(vm->dataStack, wordlistCount); 119*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 120*a1bf3f78SToomas Soome } 121*a1bf3f78SToomas Soome 122*a1bf3f78SToomas Soome /* 123*a1bf3f78SToomas Soome * s e a r c h - w o r d l i s t 124*a1bf3f78SToomas Soome * SEARCH ( c-addr u wid -- 0 | xt 1 | xt -1 ) 125*a1bf3f78SToomas Soome * Find the definition identified by the string c-addr u in the word list 126*a1bf3f78SToomas Soome * identified by wid. If the definition is not found, return zero. If the 127*a1bf3f78SToomas Soome * definition is found, return its execution token xt and one (1) if the 128*a1bf3f78SToomas Soome * definition is immediate, minus-one (-1) otherwise. 129*a1bf3f78SToomas Soome */ 130*a1bf3f78SToomas Soome static void 131*a1bf3f78SToomas Soome ficlPrimitiveSearchWordlist(ficlVm *vm) 132*a1bf3f78SToomas Soome { 133*a1bf3f78SToomas Soome ficlString name; 134*a1bf3f78SToomas Soome ficlUnsigned16 hashCode; 135*a1bf3f78SToomas Soome ficlWord *word; 136*a1bf3f78SToomas Soome ficlHash *hash = ficlStackPopPointer(vm->dataStack); 137*a1bf3f78SToomas Soome 138*a1bf3f78SToomas Soome name.length = (ficlUnsigned8)ficlStackPopUnsigned(vm->dataStack); 139*a1bf3f78SToomas Soome name.text = ficlStackPopPointer(vm->dataStack); 140*a1bf3f78SToomas Soome hashCode = ficlHashCode(name); 141*a1bf3f78SToomas Soome 142*a1bf3f78SToomas Soome ficlDictionaryLock(ficlVmGetDictionary(vm), FICL_TRUE); 143*a1bf3f78SToomas Soome word = ficlHashLookup(hash, name, hashCode); 144*a1bf3f78SToomas Soome ficlDictionaryLock(ficlVmGetDictionary(vm), FICL_FALSE); 145*a1bf3f78SToomas Soome 146*a1bf3f78SToomas Soome if (word) { 147*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, word); 148*a1bf3f78SToomas Soome ficlStackPushInteger(vm->dataStack, 149*a1bf3f78SToomas Soome (ficlWordIsImmediate(word) ? 1 : -1)); 150*a1bf3f78SToomas Soome } else { 151*a1bf3f78SToomas Soome ficlStackPushUnsigned(vm->dataStack, 0); 152*a1bf3f78SToomas Soome } 153*a1bf3f78SToomas Soome } 154*a1bf3f78SToomas Soome 155*a1bf3f78SToomas Soome /* 156*a1bf3f78SToomas Soome * s e t - c u r r e n t 157*a1bf3f78SToomas Soome * SEARCH ( wid -- ) 158*a1bf3f78SToomas Soome * Set the compilation word list to the word list identified by wid. 159*a1bf3f78SToomas Soome */ 160*a1bf3f78SToomas Soome static void 161*a1bf3f78SToomas Soome ficlPrimitiveSetCurrent(ficlVm *vm) 162*a1bf3f78SToomas Soome { 163*a1bf3f78SToomas Soome ficlHash *hash = ficlStackPopPointer(vm->dataStack); 164*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 165*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 166*a1bf3f78SToomas Soome dictionary->compilationWordlist = hash; 167*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 168*a1bf3f78SToomas Soome } 169*a1bf3f78SToomas Soome 170*a1bf3f78SToomas Soome /* 171*a1bf3f78SToomas Soome * s e t - o r d e r 172*a1bf3f78SToomas Soome * SEARCH ( widn ... wid1 n -- ) 173*a1bf3f78SToomas Soome * Set the search order to the word lists identified by widn ... wid1. 174*a1bf3f78SToomas Soome * Subsequently, word list wid1 will be searched first, and word list 175*a1bf3f78SToomas Soome * widn searched last. If n is zero, empty the search order. If n is minus 176*a1bf3f78SToomas Soome * one, set the search order to the implementation-defined minimum 177*a1bf3f78SToomas Soome * search order. The minimum search order shall include the words 178*a1bf3f78SToomas Soome * FORTH-WORDLIST and SET-ORDER. A system shall allow n to 179*a1bf3f78SToomas Soome * be at least eight. 180*a1bf3f78SToomas Soome */ 181*a1bf3f78SToomas Soome static void 182*a1bf3f78SToomas Soome ficlPrimitiveSetOrder(ficlVm *vm) 183*a1bf3f78SToomas Soome { 184*a1bf3f78SToomas Soome int i; 185*a1bf3f78SToomas Soome int wordlistCount = ficlStackPopInteger(vm->dataStack); 186*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 187*a1bf3f78SToomas Soome 188*a1bf3f78SToomas Soome if (wordlistCount > FICL_MAX_WORDLISTS) { 189*a1bf3f78SToomas Soome ficlVmThrowError(vm, 190*a1bf3f78SToomas Soome "set-order error: list would be too large"); 191*a1bf3f78SToomas Soome } 192*a1bf3f78SToomas Soome 193*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 194*a1bf3f78SToomas Soome 195*a1bf3f78SToomas Soome if (wordlistCount >= 0) { 196*a1bf3f78SToomas Soome dictionary->wordlistCount = wordlistCount; 197*a1bf3f78SToomas Soome for (i = wordlistCount-1; i >= 0; --i) { 198*a1bf3f78SToomas Soome dictionary->wordlists[i] = 199*a1bf3f78SToomas Soome ficlStackPopPointer(vm->dataStack); 200*a1bf3f78SToomas Soome } 201*a1bf3f78SToomas Soome } else { 202*a1bf3f78SToomas Soome ficlDictionaryResetSearchOrder(dictionary); 203*a1bf3f78SToomas Soome } 204*a1bf3f78SToomas Soome 205*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 206*a1bf3f78SToomas Soome } 207*a1bf3f78SToomas Soome 208*a1bf3f78SToomas Soome /* 209*a1bf3f78SToomas Soome * f i c l - w o r d l i s t 210*a1bf3f78SToomas Soome * SEARCH ( -- wid ) 211*a1bf3f78SToomas Soome * Create a new empty word list, returning its word list identifier wid. 212*a1bf3f78SToomas Soome * The new word list may be returned from a pool of preallocated word 213*a1bf3f78SToomas Soome * lists or may be dynamically allocated in data space. A system shall 214*a1bf3f78SToomas Soome * allow the creation of at least 8 new word lists in addition to any 215*a1bf3f78SToomas Soome * provided as part of the system. 216*a1bf3f78SToomas Soome * Notes: 217*a1bf3f78SToomas Soome * 1. Ficl creates a new single-list hash in the dictionary and returns 218*a1bf3f78SToomas Soome * its address. 219*a1bf3f78SToomas Soome * 2. ficl-wordlist takes an arg off the stack indicating the number of 220*a1bf3f78SToomas Soome * hash entries in the wordlist. Ficl 2.02 and later define WORDLIST as 221*a1bf3f78SToomas Soome * : wordlist 1 ficl-wordlist ; 222*a1bf3f78SToomas Soome */ 223*a1bf3f78SToomas Soome static void 224*a1bf3f78SToomas Soome ficlPrimitiveFiclWordlist(ficlVm *vm) 225*a1bf3f78SToomas Soome { 226*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 227*a1bf3f78SToomas Soome ficlHash *hash; 228*a1bf3f78SToomas Soome ficlUnsigned nBuckets; 229*a1bf3f78SToomas Soome 230*a1bf3f78SToomas Soome FICL_STACK_CHECK(vm->dataStack, 1, 1); 231*a1bf3f78SToomas Soome 232*a1bf3f78SToomas Soome nBuckets = ficlStackPopUnsigned(vm->dataStack); 233*a1bf3f78SToomas Soome hash = ficlDictionaryCreateWordlist(dictionary, nBuckets); 234*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, hash); 235*a1bf3f78SToomas Soome } 236*a1bf3f78SToomas Soome 237*a1bf3f78SToomas Soome /* 238*a1bf3f78SToomas Soome * S E A R C H > 239*a1bf3f78SToomas Soome * Ficl ( -- wid ) 240*a1bf3f78SToomas Soome * Pop wid off the search order. Error if the search order is empty 241*a1bf3f78SToomas Soome */ 242*a1bf3f78SToomas Soome static void 243*a1bf3f78SToomas Soome ficlPrimitiveSearchPop(ficlVm *vm) 244*a1bf3f78SToomas Soome { 245*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 246*a1bf3f78SToomas Soome int wordlistCount; 247*a1bf3f78SToomas Soome 248*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 249*a1bf3f78SToomas Soome wordlistCount = dictionary->wordlistCount; 250*a1bf3f78SToomas Soome if (wordlistCount == 0) { 251*a1bf3f78SToomas Soome ficlVmThrowError(vm, "search> error: empty search order"); 252*a1bf3f78SToomas Soome } 253*a1bf3f78SToomas Soome ficlStackPushPointer(vm->dataStack, 254*a1bf3f78SToomas Soome dictionary->wordlists[--dictionary->wordlistCount]); 255*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 256*a1bf3f78SToomas Soome } 257*a1bf3f78SToomas Soome 258*a1bf3f78SToomas Soome /* 259*a1bf3f78SToomas Soome * > S E A R C H 260*a1bf3f78SToomas Soome * Ficl ( wid -- ) 261*a1bf3f78SToomas Soome * Push wid onto the search order. Error if the search order is full. 262*a1bf3f78SToomas Soome */ 263*a1bf3f78SToomas Soome static void 264*a1bf3f78SToomas Soome ficlPrimitiveSearchPush(ficlVm *vm) 265*a1bf3f78SToomas Soome { 266*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm); 267*a1bf3f78SToomas Soome 268*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE); 269*a1bf3f78SToomas Soome if (dictionary->wordlistCount > FICL_MAX_WORDLISTS) { 270*a1bf3f78SToomas Soome ficlVmThrowError(vm, ">search error: search order overflow"); 271*a1bf3f78SToomas Soome } 272*a1bf3f78SToomas Soome dictionary->wordlists[dictionary->wordlistCount++] = 273*a1bf3f78SToomas Soome ficlStackPopPointer(vm->dataStack); 274*a1bf3f78SToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE); 275*a1bf3f78SToomas Soome } 276*a1bf3f78SToomas Soome 277*a1bf3f78SToomas Soome /* 278*a1bf3f78SToomas Soome * W I D - G E T - N A M E 279*a1bf3f78SToomas Soome * Ficl ( wid -- c-addr u ) 280*a1bf3f78SToomas Soome * Get wid's (optional) name and push onto stack as a counted string 281*a1bf3f78SToomas Soome */ 282*a1bf3f78SToomas Soome static void 283*a1bf3f78SToomas Soome ficlPrimitiveWidGetName(ficlVm *vm) 284*a1bf3f78SToomas Soome { 285*a1bf3f78SToomas Soome ficlHash *hash; 286*a1bf3f78SToomas Soome char *name; 287*a1bf3f78SToomas Soome ficlInteger length; 288*a1bf3f78SToomas Soome ficlCell c; 289*a1bf3f78SToomas Soome 290*a1bf3f78SToomas Soome hash = ficlVmPop(vm).p; 291*a1bf3f78SToomas Soome name = hash->name; 292*a1bf3f78SToomas Soome 293*a1bf3f78SToomas Soome if (name != NULL) 294*a1bf3f78SToomas Soome length = strlen(name); 295*a1bf3f78SToomas Soome else 296*a1bf3f78SToomas Soome length = 0; 297*a1bf3f78SToomas Soome 298*a1bf3f78SToomas Soome c.p = name; 299*a1bf3f78SToomas Soome ficlVmPush(vm, c); 300*a1bf3f78SToomas Soome 301*a1bf3f78SToomas Soome c.i = length; 302*a1bf3f78SToomas Soome ficlVmPush(vm, c); 303*a1bf3f78SToomas Soome } 304*a1bf3f78SToomas Soome 305*a1bf3f78SToomas Soome /* 306*a1bf3f78SToomas Soome * W I D - S E T - N A M E 307*a1bf3f78SToomas Soome * Ficl ( wid c-addr -- ) 308*a1bf3f78SToomas Soome * Set wid's name pointer to the \0 terminated string address supplied 309*a1bf3f78SToomas Soome */ 310*a1bf3f78SToomas Soome static void 311*a1bf3f78SToomas Soome ficlPrimitiveWidSetName(ficlVm *vm) 312*a1bf3f78SToomas Soome { 313*a1bf3f78SToomas Soome char *name = (char *)ficlVmPop(vm).p; 314*a1bf3f78SToomas Soome ficlHash *hash = ficlVmPop(vm).p; 315*a1bf3f78SToomas Soome hash->name = name; 316*a1bf3f78SToomas Soome } 317*a1bf3f78SToomas Soome 318*a1bf3f78SToomas Soome /* 319*a1bf3f78SToomas Soome * setParentWid 320*a1bf3f78SToomas Soome * Ficl 321*a1bf3f78SToomas Soome * setparentwid ( parent-wid wid -- ) 322*a1bf3f78SToomas Soome * Set WID's link field to the parent-wid. search-wordlist will 323*a1bf3f78SToomas Soome * iterate through all the links when finding words in the child wid. 324*a1bf3f78SToomas Soome */ 325*a1bf3f78SToomas Soome static void 326*a1bf3f78SToomas Soome ficlPrimitiveSetParentWid(ficlVm *vm) 327*a1bf3f78SToomas Soome { 328*a1bf3f78SToomas Soome ficlHash *parent, *child; 329*a1bf3f78SToomas Soome 330*a1bf3f78SToomas Soome FICL_STACK_CHECK(vm->dataStack, 2, 0); 331*a1bf3f78SToomas Soome 332*a1bf3f78SToomas Soome child = (ficlHash *)ficlStackPopPointer(vm->dataStack); 333*a1bf3f78SToomas Soome parent = (ficlHash *)ficlStackPopPointer(vm->dataStack); 334*a1bf3f78SToomas Soome 335*a1bf3f78SToomas Soome child->link = parent; 336*a1bf3f78SToomas Soome } 337*a1bf3f78SToomas Soome 338*a1bf3f78SToomas Soome /* 339*a1bf3f78SToomas Soome * f i c l C o m p i l e S e a r c h 340*a1bf3f78SToomas Soome * Builds the primitive wordset and the environment-query namespace. 341*a1bf3f78SToomas Soome */ 342*a1bf3f78SToomas Soome void 343*a1bf3f78SToomas Soome ficlSystemCompileSearch(ficlSystem *system) 344*a1bf3f78SToomas Soome { 345*a1bf3f78SToomas Soome ficlDictionary *dictionary = ficlSystemGetDictionary(system); 346*a1bf3f78SToomas Soome ficlDictionary *environment = ficlSystemGetEnvironment(system); 347*a1bf3f78SToomas Soome 348*a1bf3f78SToomas Soome FICL_SYSTEM_ASSERT(system, dictionary); 349*a1bf3f78SToomas Soome FICL_SYSTEM_ASSERT(system, environment); 350*a1bf3f78SToomas Soome 351*a1bf3f78SToomas Soome /* 352*a1bf3f78SToomas Soome * optional SEARCH-ORDER word set 353*a1bf3f78SToomas Soome */ 354*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, ">search", 355*a1bf3f78SToomas Soome ficlPrimitiveSearchPush, FICL_WORD_DEFAULT); 356*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "search>", 357*a1bf3f78SToomas Soome ficlPrimitiveSearchPop, FICL_WORD_DEFAULT); 358*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "definitions", 359*a1bf3f78SToomas Soome ficlPrimitiveDefinitions, FICL_WORD_DEFAULT); 360*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "forth-wordlist", 361*a1bf3f78SToomas Soome ficlPrimitiveForthWordlist, FICL_WORD_DEFAULT); 362*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "get-current", 363*a1bf3f78SToomas Soome ficlPrimitiveGetCurrent, FICL_WORD_DEFAULT); 364*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "get-order", 365*a1bf3f78SToomas Soome ficlPrimitiveGetOrder, FICL_WORD_DEFAULT); 366*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "search-wordlist", 367*a1bf3f78SToomas Soome ficlPrimitiveSearchWordlist, FICL_WORD_DEFAULT); 368*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "set-current", 369*a1bf3f78SToomas Soome ficlPrimitiveSetCurrent, FICL_WORD_DEFAULT); 370*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "set-order", 371*a1bf3f78SToomas Soome ficlPrimitiveSetOrder, FICL_WORD_DEFAULT); 372*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "ficl-wordlist", 373*a1bf3f78SToomas Soome ficlPrimitiveFiclWordlist, FICL_WORD_DEFAULT); 374*a1bf3f78SToomas Soome 375*a1bf3f78SToomas Soome /* 376*a1bf3f78SToomas Soome * Set SEARCH environment query values 377*a1bf3f78SToomas Soome */ 378*a1bf3f78SToomas Soome ficlDictionarySetConstant(environment, "search-order", FICL_TRUE); 379*a1bf3f78SToomas Soome ficlDictionarySetConstant(environment, "search-order-ext", FICL_TRUE); 380*a1bf3f78SToomas Soome ficlDictionarySetConstant(environment, "wordlists", FICL_MAX_WORDLISTS); 381*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "wid-get-name", 382*a1bf3f78SToomas Soome ficlPrimitiveWidGetName, FICL_WORD_DEFAULT); 383*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "wid-set-name", 384*a1bf3f78SToomas Soome ficlPrimitiveWidSetName, FICL_WORD_DEFAULT); 385*a1bf3f78SToomas Soome ficlDictionarySetPrimitive(dictionary, "wid-set-super", 386*a1bf3f78SToomas Soome ficlPrimitiveSetParentWid, FICL_WORD_DEFAULT); 387*a1bf3f78SToomas Soome } 388