📄 symbol.c
字号:
{ temp = listOfMatches->next; rtn_struct(symbolMatch,listOfMatches); listOfMatches = temp; } } /***************************************************************//* ClearBitString: Initializes the values of a bitmap to zero. *//***************************************************************/globle VOID ClearBitString(vTheBitMap,length) VOID *vTheBitMap; int length; { char *theBitMap = vTheBitMap; int i; for (i = 0; i < length; i++) theBitMap[i] = '\0'; } /*****************************************************************//* GetNextSymbolMatch: Finds the next symbol in the SymbolTable *//* which begins with a specified symbol. This function is used *//* to implement the command completion feature found in some *//* of the CLIPS machine specific interfaces. *//*****************************************************************/globle SYMBOL_HN *GetNextSymbolMatch(searchString,searchLength,prevSymbol, anywhere,commonPrefixLength) char *searchString; int searchLength; SYMBOL_HN *prevSymbol; int anywhere; int *commonPrefixLength; { register int i; SYMBOL_HN *hashPtr; int flag = CLIPS_TRUE; int prefixLength; /*==========================================*/ /* If we're looking anywhere in the string, */ /* then there's no common prefix length. */ /*==========================================*/ if (anywhere && (commonPrefixLength != NULL)) *commonPrefixLength = 0; /*========================================================*/ /* If we're starting the search from the beginning of the */ /* symbol table, the previous symbol argument is NULL. */ /*========================================================*/ if (prevSymbol == NULL) { i = 0; hashPtr = SymbolTable[0]; } /*==========================================*/ /* Otherwise start the search at the symbol */ /* after the last symbol found. */ /*==========================================*/ else { i = prevSymbol->bucket; hashPtr = prevSymbol->next; } /*==============================================*/ /* Search through all the symbol table buckets. */ /*==============================================*/ while (flag) { /*===================================*/ /* Search through all of the entries */ /* in the bucket being examined. */ /*===================================*/ for (; hashPtr != NULL; hashPtr = hashPtr->next) { /*================================================*/ /* Skip symbols that being with ( since these are */ /* typically symbols for internal use. Also skip */ /* any symbols that are marked ephemeral since */ /* these aren't in use. */ /*================================================*/ if ((hashPtr->contents[0] == '(') || (hashPtr->markedEphemeral)) { continue; } /*==================================================*/ /* Two types of matching can be performed: the type */ /* comparing just to the beginning of the string */ /* and the type which looks for the substring */ /* anywhere within the string being examined. */ /*==================================================*/ if (! anywhere) { /*=============================================*/ /* Determine the common prefix length between */ /* the previously found match (if available or */ /* the search string if not) and the symbol */ /* table entry. */ /*=============================================*/ if (prevSymbol != NULL) prefixLength = CommonPrefixLength(prevSymbol->contents,hashPtr->contents); else prefixLength = CommonPrefixLength(searchString,hashPtr->contents); /*===================================================*/ /* If the prefix length is greater than or equal to */ /* the length of the search string, then we've found */ /* a match. If this is the first match, the common */ /* prefix length is set to the length of the first */ /* match, otherwise the common prefix length is the */ /* smallest prefix length found among all matches. */ /*===================================================*/ if (prefixLength >= searchLength) { if (commonPrefixLength != NULL) { if (prevSymbol == NULL) *commonPrefixLength = strlen(hashPtr->contents); else if (prefixLength < *commonPrefixLength) *commonPrefixLength = prefixLength; } return(hashPtr); } } else { if (StringWithinString(hashPtr->contents,searchString) != NULL) { return(hashPtr); } } } /*=================================================*/ /* Move on to the next bucket in the symbol table. */ /*=================================================*/ if (++i >= SYMBOL_HASH_SIZE) flag = CLIPS_FALSE; else hashPtr = SymbolTable[i]; } /*=====================================*/ /* There are no more matching symbols. */ /*=====================================*/ return(NULL); } /**********************************************//* StringWithinString: Determines if a string *//* is contained within another string. *//**********************************************/static char *StringWithinString(cs,ct) char *cs, *ct; { register unsigned i,j,k; for (i = 0 ; cs[i] != '\0' ; i++) { for (j = i , k = 0 ; ct[k] != '\0' && cs[j] == ct[k] ; j++, k++) ; if ((ct[k] == '\0') && (k != 0)) return(cs + i); } return(NULL); }/************************************************//* CommonPrefixLength: Determines the length of *//* the maximumcommon prefix of two strings *//************************************************/static int CommonPrefixLength(cs,ct) char *cs,*ct; { register int i; for (i = 0 ; (cs[i] != '\0') && (ct[i] != '\0') ; i++) if (cs[i] != ct[i]) break; return(i); } #if BLOAD_AND_BSAVE || CONSTRUCT_COMPILER || BSAVE_INSTANCES/****************************************************************//* SetAtomicValueIndices: Sets the bucket values for hash table *//* entries with an index value that indicates the position of *//* the hash table in a hash table traversal (e.g. this is the *//* fifth entry in the hash table. *//****************************************************************/globle VOID SetAtomicValueIndices(setAll) int setAll; { unsigned int count; int i; SYMBOL_HN *symbolPtr, **symbolArray; FLOAT_HN *floatPtr, **floatArray; INTEGER_HN *integerPtr, **integerArray; BITMAP_HN *bitMapPtr, **bitMapArray; /*===================================*/ /* Set indices for the symbol table. */ /*===================================*/ count = 0; symbolArray = GetSymbolTable(); for (i = 0; i < SYMBOL_HASH_SIZE; i++) { for (symbolPtr = symbolArray[i]; symbolPtr != NULL; symbolPtr = symbolPtr->next) { if ((symbolPtr->neededSymbol == CLIPS_TRUE) || setAll) { symbolPtr->bucket = count++; } } } /*==================================*/ /* Set indices for the float table. */ /*==================================*/ count = 0; floatArray = GetFloatTable(); for (i = 0; i < FLOAT_HASH_SIZE; i++) { for (floatPtr = floatArray[i]; floatPtr != NULL; floatPtr = floatPtr->next) { if ((floatPtr->neededFloat == CLIPS_TRUE) || setAll) { floatPtr->bucket = count++; } } } /*====================================*/ /* Set indices for the integer table. */ /*====================================*/ count = 0; integerArray = GetIntegerTable(); for (i = 0; i < INTEGER_HASH_SIZE; i++) { for (integerPtr = integerArray[i]; integerPtr != NULL; integerPtr = integerPtr->next) { if ((integerPtr->neededInteger == CLIPS_TRUE) || setAll) { integerPtr->bucket = count++; } } } /*===================================*/ /* Set indices for the bitmap table. */ /*===================================*/ count = 0; bitMapArray = GetBitMapTable(); for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (bitMapPtr = bitMapArray[i]; bitMapPtr != NULL; bitMapPtr = bitMapPtr->next) { if ((bitMapPtr->neededBitMap == CLIPS_TRUE) || setAll) { bitMapPtr->bucket = count++; } } } }/***********************************************************************//* RestoreAtomicValueBuckets: Restores the bucket values of hash table *//* entries to the appropriate values. Normally called to undo the *//* effects of a call to the SetAtomicValueIndices function. *//***********************************************************************/globle VOID RestoreAtomicValueBuckets() { int i; SYMBOL_HN *symbolPtr, **symbolArray; FLOAT_HN *floatPtr, **floatArray; INTEGER_HN *integerPtr, **integerArray; BITMAP_HN *bitMapPtr, **bitMapArray; /*================================================*/ /* Restore the bucket values in the symbol table. */ /*================================================*/ symbolArray = GetSymbolTable(); for (i = 0; i < SYMBOL_HASH_SIZE; i++) { for (symbolPtr = symbolArray[i]; symbolPtr != NULL; symbolPtr = symbolPtr->next) { symbolPtr->bucket = i; } } /*===============================================*/ /* Restore the bucket values in the float table. */ /*===============================================*/ floatArray = GetFloatTable(); for (i = 0; i < FLOAT_HASH_SIZE; i++) { for (floatPtr = floatArray[i]; floatPtr != NULL; floatPtr = floatPtr->next) { floatPtr->bucket = i; } } /*=================================================*/ /* Restore the bucket values in the integer table. */ /*=================================================*/ integerArray = GetIntegerTable(); for (i = 0; i < INTEGER_HASH_SIZE; i++) { for (integerPtr = integerArray[i]; integerPtr != NULL; integerPtr = integerPtr->next) { integerPtr->bucket = i; } } /*================================================*/ /* Restore the bucket values in the bitmap table. */ /*================================================*/ bitMapArray = GetBitMapTable(); for (i = 0; i < BITMAP_HASH_SIZE; i++) { for (bitMapPtr = bitMapArray[i]; bitMapPtr != NULL; bitMapPtr = bitMapPtr->next) { bitMapPtr->bucket = i; } } }#endif /* BLOAD_AND_BSAVE || CONSTRUCT_COMPILER || BSAVE_INSTANCES */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -