commline.c

来自「clips源代码」· C语言 代码 · 共 997 行 · 第 1/3 页

C
997
字号
    if (CommandLineData(theEnv)->AfterPromptFunction != NULL)      { (*CommandLineData(theEnv)->AfterPromptFunction)(theEnv); }   }/*****************************************//* PrintBanner: Prints the CLIPS banner. *//*****************************************/globle void PrintBanner(   void *theEnv)   {    EnvPrintRouter(theEnv,WPROMPT,CommandLineData(theEnv)->BannerString);   }/************************************************//* SetAfterPromptFunction: Replaces the current *//*   value of AfterPromptFunction.              *//************************************************/globle void SetAfterPromptFunction(  void *theEnv,  int (*funptr)(void *))  {   CommandLineData(theEnv)->AfterPromptFunction = funptr;  }/***********************************************************//* SetBeforeCommandExecutionFunction: Replaces the current *//*   value of BeforeCommandExecutionFunction.              *//***********************************************************/globle void SetBeforeCommandExecutionFunction(  void *theEnv,  int (*funptr)(void *))  {   CommandLineData(theEnv)->BeforeCommandExecutionFunction = funptr;  }  /************************************************//* RouteCommand: Processes a completed command. *//************************************************/globle intBool RouteCommand(  void *theEnv,  char *command,  int printResult)  {   DATA_OBJECT result;   struct expr *top;   char *commandName;   struct token theToken;   if (command == NULL)     { return(0); }   /*========================================*/   /* Open a string input source and get the */   /* first token from that source.          */   /*========================================*/   OpenStringSource(theEnv,"command",command,0);   GetToken(theEnv,"command",&theToken);   /*=====================*/   /* Evaluate constants. */   /*=====================*/   if ((theToken.type == SYMBOL) || (theToken.type == STRING) ||       (theToken.type == FLOAT) || (theToken.type == INTEGER) ||       (theToken.type == INSTANCE_NAME))     {      CloseStringSource(theEnv,"command");      if (printResult)        {         PrintAtom(theEnv,"stdout",theToken.type,theToken.value);         EnvPrintRouter(theEnv,"stdout","\n");        }      return(1);     }   /*============================*/   /* Evaluate global variables. */   /*============================*/   if (theToken.type == GBL_VARIABLE)     {      CloseStringSource(theEnv,"command");      top = GenConstant(theEnv,theToken.type,theToken.value);      EvaluateExpression(theEnv,top,&result);      rtn_struct(theEnv,expr,top);      if (printResult)        {         PrintDataObject(theEnv,"stdout",&result);         EnvPrintRouter(theEnv,"stdout","\n");        }      return(1);     }   /*========================================================*/   /* If the next token isn't the beginning left parenthesis */   /* of a command or construct, then whatever was entered   */   /* cannot be evaluated at the command prompt.             */   /*========================================================*/   if (theToken.type != LPAREN)     {      PrintErrorID(theEnv,"COMMLINE",1,FALSE);      EnvPrintRouter(theEnv,WERROR,"Expected a '(', constant, or global variable\n");      CloseStringSource(theEnv,"command");      return(0);     }   /*===========================================================*/   /* The next token must be a function name or construct type. */   /*===========================================================*/   GetToken(theEnv,"command",&theToken);   if (theToken.type != SYMBOL)     {      PrintErrorID(theEnv,"COMMLINE",2,FALSE);      EnvPrintRouter(theEnv,WERROR,"Expected a command.\n");      CloseStringSource(theEnv,"command");      return(0);     }   commandName = ValueToString(theToken.value);   /*======================*/   /* Evaluate constructs. */   /*======================*/#if (! RUN_TIME) && (! BLOAD_ONLY)   {    int errorFlag;    errorFlag = ParseConstruct(theEnv,commandName,"command");    if (errorFlag != -1)      {       CloseStringSource(theEnv,"command");       if (errorFlag == 1)         {          EnvPrintRouter(theEnv,WERROR,"\nERROR:\n");          PrintInChunks(theEnv,WERROR,GetPPBuffer(theEnv));          EnvPrintRouter(theEnv,WERROR,"\n");         }       DestroyPPBuffer(theEnv);       return(errorFlag);      }   }#endif   /*========================*/   /* Parse a function call. */   /*========================*/   CommandLineData(theEnv)->ParsingTopLevelCommand = TRUE;   top = Function2Parse(theEnv,"command",commandName);   CommandLineData(theEnv)->ParsingTopLevelCommand = FALSE;   ClearParsedBindNames(theEnv);   /*================================*/   /* Close the string input source. */   /*================================*/   CloseStringSource(theEnv,"command");   /*=========================*/   /* Evaluate function call. */   /*=========================*/   if (top == NULL) return(0);      ExpressionInstall(theEnv,top);      CommandLineData(theEnv)->EvaluatingTopLevelCommand = TRUE;   CommandLineData(theEnv)->CurrentCommand = top;   EvaluateExpression(theEnv,top,&result);   CommandLineData(theEnv)->CurrentCommand = NULL;   CommandLineData(theEnv)->EvaluatingTopLevelCommand = FALSE;      ExpressionDeinstall(theEnv,top);   ReturnExpression(theEnv,top);      if ((result.type != RVOID) && printResult)     {      PrintDataObject(theEnv,"stdout",&result);      EnvPrintRouter(theEnv,"stdout","\n");     }   return(1);  }/*****************************************************************//* DefaultGetNextEvent: Default event-handling function. Handles *//*   only keyboard events by first calling GetcRouter to get a   *//*   character and then calling ExpandCommandString to add the   *//*   character to the CommandString.                             *//*****************************************************************/static int DefaultGetNextEvent(  void *theEnv)  {   int inchar;   inchar = EnvGetcRouter(theEnv,"stdin");   if (inchar == EOF) inchar = '\n';   ExpandCommandString(theEnv,(char) inchar);      return 0;  }/*************************************//* SetEventFunction: Replaces the    *//*   current value of EventFunction. *//*************************************/globle int (*SetEventFunction(void *theEnv,int (*theFunction)(void *)))(void *)  {   int (*tmp_ptr)(void *);   tmp_ptr = CommandLineData(theEnv)->EventFunction;   CommandLineData(theEnv)->EventFunction = theFunction;   return(tmp_ptr);  }/****************************************//* TopLevelCommand: Indicates whether a *//*   top-level command is being parsed. *//****************************************/globle intBool TopLevelCommand(  void *theEnv)  {   return(CommandLineData(theEnv)->ParsingTopLevelCommand);  }/***********************************************************//* GetCommandCompletionString: Returns the last token in a *//*   string if it is a valid token for command completion. *//***********************************************************/globle char *GetCommandCompletionString(  void *theEnv,  char *theString,  size_t maxPosition)  {   struct token lastToken;   struct token theToken;   char lastChar;   char *rs;   size_t length;   /*=========================*/   /* Get the command string. */   /*=========================*/   if (theString == NULL) return("");   /*=========================================================================*/   /* If the last character in the command string is a space, character       */   /* return, or quotation mark, then the command completion can be anything. */   /*=========================================================================*/   lastChar = theString[maxPosition - 1];   if ((lastChar == ' ') || (lastChar == '"') ||       (lastChar == '\t') || (lastChar == '\f') ||       (lastChar == '\n') || (lastChar == '\r'))     { return(""); }   /*============================================*/   /* Find the last token in the command string. */   /*============================================*/   OpenTextSource(theEnv,"CommandCompletion",theString,0,maxPosition);   ScannerData(theEnv)->IgnoreCompletionErrors = TRUE;   GetToken(theEnv,"CommandCompletion",&theToken);   CopyToken(&lastToken,&theToken);   while (theToken.type != STOP)     {      CopyToken(&lastToken,&theToken);      GetToken(theEnv,"CommandCompletion",&theToken);     }   CloseStringSource(theEnv,"CommandCompletion");   ScannerData(theEnv)->IgnoreCompletionErrors = FALSE;   /*===============================================*/   /* Determine if the last token can be completed. */   /*===============================================*/   if (lastToken.type == SYMBOL)     {      rs = ValueToString(lastToken.value);      if (rs[0] == '[') return (&rs[1]);      return(ValueToString(lastToken.value));     }   else if (lastToken.type == SF_VARIABLE)     { return(ValueToString(lastToken.value)); }   else if (lastToken.type == MF_VARIABLE)     { return(ValueToString(lastToken.value)); }   else if ((lastToken.type == GBL_VARIABLE) || (lastToken.type == MF_GBL_VARIABLE) ||            (lastToken.type == INSTANCE_NAME))     { return(NULL); }   else if (lastToken.type == STRING)     {      length = strlen(ValueToString(lastToken.value));      return(GetCommandCompletionString(theEnv,ValueToString(lastToken.value),length));     }   else if ((lastToken.type == FLOAT) || (lastToken.type == INTEGER))     { return(NULL); }   return("");  }/****************************************************************//* SetHaltCommandLoopBatch: Sets the HaltCommandLoopBatch flag. *//****************************************************************/globle void SetHaltCommandLoopBatch(  void *theEnv,  int value)  {    CommandLineData(theEnv)->HaltCommandLoopBatch = value;   }/*******************************************************************//* GetHaltCommandLoopBatch: Returns the HaltCommandLoopBatch flag. *//*******************************************************************/globle int GetHaltCommandLoopBatch(  void *theEnv)  {   return(CommandLineData(theEnv)->HaltCommandLoopBatch);  }#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?