⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symbol.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
     {      *numberOfMatches = *numberOfMatches + 1;      temp = get_struct(theEnv,symbolMatch);      temp->match = hashPtr;      temp->next = reply;      reply = temp;     }   return(reply);  }/*********************************************************//* ReturnSymbolMatches: Returns a set of symbol matches. *//*********************************************************/globle void ReturnSymbolMatches(  void *theEnv,  struct symbolMatch *listOfMatches)  {   struct symbolMatch *temp;   while (listOfMatches != NULL)     {      temp = listOfMatches->next;      rtn_struct(theEnv,symbolMatch,listOfMatches);      listOfMatches = temp;     }  }/***************************************************************//* ClearBitString: Initializes the values of a bitmap to zero. *//***************************************************************/globle void ClearBitString(  void *vTheBitMap,  unsigned length)  {   char *theBitMap = (char *) vTheBitMap;   unsigned 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 machine specific interfaces.                         *//*****************************************************************/globle SYMBOL_HN *GetNextSymbolMatch(  void *theEnv,  char *searchString,  size_t searchLength,  SYMBOL_HN *prevSymbol,  int anywhere,  size_t *commonPrefixLength)  {   register unsigned long i;   SYMBOL_HN *hashPtr;   int flag = TRUE;   size_t 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 = SymbolData(theEnv)->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 = FALSE;      else hashPtr = SymbolData(theEnv)->SymbolTable[i];     }   /*=====================================*/   /* There are no more matching symbols. */   /*=====================================*/   return(NULL);  }/**********************************************//* StringWithinString: Determines if a string *//*   is contained within another string.      *//**********************************************/static char *StringWithinString(  char *cs,  char *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 size_t CommonPrefixLength(  char *cs,  char *ct)  {   register unsigned 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(  void *theEnv,  int setAll)  {   unsigned long count;   unsigned long 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(theEnv);   for (i = 0; i < SYMBOL_HASH_SIZE; i++)     {      for (symbolPtr = symbolArray[i];           symbolPtr != NULL;           symbolPtr = symbolPtr->next)        {         if ((symbolPtr->neededSymbol == TRUE) || setAll)           {            symbolPtr->bucket = count++;            if (symbolPtr->bucket != (count - 1))              { SystemError(theEnv,"SYMBOL",667); }           }        }     }   /*==================================*/   /* Set indices for the float table. */   /*==================================*/   count = 0;   floatArray = GetFloatTable(theEnv);   for (i = 0; i < FLOAT_HASH_SIZE; i++)     {      for (floatPtr = floatArray[i];           floatPtr != NULL;           floatPtr = floatPtr->next)        {         if ((floatPtr->neededFloat == TRUE) || setAll)           {            floatPtr->bucket = count++;            if (floatPtr->bucket != (count - 1))              { SystemError(theEnv,"SYMBOL",668); }           }        }     }   /*====================================*/   /* Set indices for the integer table. */   /*====================================*/   count = 0;   integerArray = GetIntegerTable(theEnv);   for (i = 0; i < INTEGER_HASH_SIZE; i++)     {      for (integerPtr = integerArray[i];           integerPtr != NULL;           integerPtr = integerPtr->next)        {         if ((integerPtr->neededInteger == TRUE) || setAll)           {            integerPtr->bucket = count++;            if (integerPtr->bucket != (count - 1))              { SystemError(theEnv,"SYMBOL",669); }           }        }     }   /*===================================*/   /* Set indices for the bitmap table. */   /*===================================*/   count = 0;   bitMapArray = GetBitMapTable(theEnv);   for (i = 0; i < BITMAP_HASH_SIZE; i++)     {      for (bitMapPtr = bitMapArray[i];           bitMapPtr != NULL;           bitMapPtr = bitMapPtr->next)        {         if ((bitMapPtr->neededBitMap == TRUE) || setAll)           {            bitMapPtr->bucket = count++;            if (bitMapPtr->bucket != (count - 1))              { SystemError(theEnv,"SYMBOL",670); }           }        }     }  }/***********************************************************************//* 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(  void *theEnv)  {   unsigned long 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(theEnv);   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(theEnv);   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(theEnv);   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(theEnv);   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 + -