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

📄 sysdep.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*=============================*/   /* Initialization is complete. */   /*=============================*/      alreadyInitialized = CLIPS_TRUE;  }/********************************************//* SetRedrawFunction: Redraws the screen if *//*   clipswin is main or does nothing.      *//********************************************/globle VOID SetRedrawFunction(theFunction)  VOID (*theFunction)(VOID_ARG);  {   RedrawScreenFunction = theFunction;  }/**************************************************//* SetPauseEnvFunction: Puts terminal in a normal *//*   state if clipswin is main or does nothing.   *//**************************************************/globle VOID SetPauseEnvFunction(theFunction)  VOID (*theFunction)(VOID_ARG);  {   PauseEnvFunction = theFunction;  }/**************************************************************//* SetContinueEnvFunction: Returns terminal to special screen *//*   interface state if clipswin is main or does nothing.     *//**************************************************************/globle VOID SetContinueEnvFunction(theFunction)#if ANSI_COMPILER   void (*theFunction)(int);#else   VOID (*theFunction)();#endif  {   ContinueEnvFunction = theFunction;  }/*************************************************//* RerouteStdin: Processes the -f, -f2, and -l   *//*   options available on machines which support *//*   argc and arv command line options.          *//*************************************************/globle VOID RerouteStdin(argc,argv)int argc;char *argv[];  {   int i;   int theSwitch = NO_SWITCH;   /*======================================*/   /* If there aren't enough arguments for */   /* the -f argument, then return.        */   /*======================================*/      if (argc < 3)     { return; }   /*=====================================*/   /* If argv was not passed then return. */   /*=====================================*/      if (argv == NULL) return;   /*=============================================*/   /* Process each of the command line arguments. */   /*=============================================*/      for (i = 1 ; i < argc ; i++)     {      if (strcmp(argv[i],"-f") == 0) theSwitch = BATCH_SWITCH;#if ! RUN_TIME      else if (strcmp(argv[i],"-f2") == 0) theSwitch = BATCH_STAR_SWITCH;      else if (strcmp(argv[i],"-l") == 0) theSwitch = LOAD_SWITCH;#endif      else if (theSwitch == NO_SWITCH)        {         PrintErrorID("SYSDEP",2,CLIPS_FALSE);         PrintCLIPS(WERROR,"Invalid option\n");        }              if (i > (argc-1))        {         PrintErrorID("SYSDEP",1,CLIPS_FALSE);         PrintCLIPS(WERROR,"No file found for ");                  switch(theSwitch)           {            case BATCH_SWITCH:               PrintCLIPS(WERROR,"-f");               break;                        case BATCH_STAR_SWITCH:               PrintCLIPS(WERROR,"-f2");               break;                        case LOAD_SWITCH:               PrintCLIPS(WERROR,"-l");           }                    PrintCLIPS(WERROR," option\n");         return;        }              switch(theSwitch)        {         case BATCH_SWITCH:            OpenBatch(argv[++i],CLIPS_TRUE);            break;#if ! RUN_TIME                     case BATCH_STAR_SWITCH:            BatchStar(argv[++i]);            break;           case LOAD_SWITCH:            Load(argv[++i]);            break;#endif        }     }  }#if ! RUN_TIME/**************************************************//* SystemFunctionDefinitions: Sets up definitions *//*   of system defined functions.                 *//**************************************************/static VOID SystemFunctionDefinitions()  {   ProceduralFunctionDefinitions();   MiscFunctionDefinitions();   IOFunctionDefinitions();   PredicateFunctionDefinitions();   BasicMathFunctionDefinitions();   FileCommandDefinitions();   #if DEBUGGING_FUNCTIONS   WatchFunctionDefinitions();#endif#if MULTIFIELD_FUNCTIONS   MultifieldFunctionDefinitions();#endif#if STRING_FUNCTIONS   StringFunctionDefinitions();#endif#if EX_MATH   ExtendedMathFunctionDefinitions();#endif#if CLP_TEXTPRO || CLP_HELP   HelpFunctionDefinitions();#endif#if EMACS_EDITOR   EditorFunctionDefinition();#endif#if CONSTRUCT_COMPILER   ConstructsToCCommandDefinition();#endif  }#endif/**********************************************************//* gentime: A function to return a floating point number  *//*   which indicates the present time. Used internally by *//*   CLIPS for timing rule firings and debugging.         *//**********************************************************/globle double gentime()  {#if   VAX_VMS || IBM_MSC ||  UNIX_7 || IBM_ICB || IBM_GCC   double sec, msec;   int temp;   struct timeb time_pointer;   ftime(&time_pointer);   temp = (int) time_pointer.time;   temp = temp - ((temp/10000) * 10000);   sec  = (double) temp;   msec = (double) time_pointer.millitm;   return(sec + (msec / 1000.0));#endif#if   UNIX_V   long t_int;   double t;   struct tms buf;   t_int = times(&buf);   t = (double) t_int / 60.0;    /* t = (double) t_int / sysconf(_SC_CLK_TCK); */   return(t);#endif#if   MAC   UnsignedWide result;      Microseconds(&result);      return(((((double) result.hi) * kTwoPower32) + result.lo) / 1000000.0);#endif#if   IBM_TBC#if ! WINDOW_INTERFACE   unsigned long int result;   result = biostime(0,(long int) 0);   return((double) result / 18.2);#else   unsigned long int result;   result = GetTickCount();   return((double) result / 1000.0);#endif#endif#if   IBM_ZTC || IBM_SC   return((double) time(NULL));#endif#if GENERIC   return(0.0);#endif  }/*****************************************************//* gensystem: Generic routine for passing a string   *//*   representing a command to the operating system. *//*****************************************************/globle VOID gensystem()  {   char *commandBuffer = NULL;   int bufferPosition = 0;   int bufferMaximum = 0;   int numa, i;   DATA_OBJECT tempValue;   char *theString;   /*===========================================*/   /* Check for the corret number of arguments. */   /*===========================================*/      if ((numa = ArgCountCheck("system",AT_LEAST,1)) == -1) return;   /*============================================================*/   /* Concatenate the arguments together to form a single string */   /* containing the command to be sent to the operating system. */   /*============================================================*/      for (i = 1 ; i <= numa; i++)     {      RtnUnknown(i,&tempValue);      if ((GetType(tempValue) != STRING) &&          (GetType(tempValue) != SYMBOL))        {         SetHaltExecution(CLIPS_TRUE);         SetEvaluationError(CLIPS_TRUE);         ExpectedTypeError2("system",i);         return;        }     theString = DOToString(tempValue);     commandBuffer = AppendToString(theString,commandBuffer,&bufferPosition,&bufferMaximum);    }   if (commandBuffer == NULL) return;   /*=======================================*/   /* Execute the operating system command. */   /*=======================================*/   #if VAX_VMS   if (PauseEnvFunction != NULL) (*PauseEnvFunction)();   VMSSystem(commandBuffer);   putchar('\n');   if (ContinueEnvFunction != NULL) (*ContinueEnvFunction)(1);   if (RedrawScreenFunction != NULL) (*RedrawScreenFunction)();#endif#if   UNIX_7 || UNIX_V || IBM_MSC || IBM_TBC || IBM_ICB || IBM_ZTC || IBM_SC || IBM_GCC   if (PauseEnvFunction != NULL) (*PauseEnvFunction)();   system(commandBuffer);   if (ContinueEnvFunction != NULL) (*ContinueEnvFunction)(1);   if (RedrawScreenFunction != NULL) (*RedrawScreenFunction)();#else#if ! VAX_VMS   PrintCLIPS(WDIALOG,            "System function not fully defined for this system.\n");#endif#endif   /*==================================================*/   /* Return the string buffer containing the command. */   /*==================================================*/      rm(commandBuffer,bufferMaximum);   return;  }#if   VAX_VMS/*************************************************//* VMSSystem: Implements system command for VMS. *//*************************************************/globle VOID VMSSystem(cmd)  char *cmd;  {   long status, complcode;   struct dsc$descriptor_s cmd_desc;   cmd_desc.dsc$w_length = strlen(cmd);   cmd_desc.dsc$a_pointer = cmd;   cmd_desc.dsc$b_class = DSC$K_CLASS_S;   cmd_desc.dsc$b_dtype = DSC$K_DTYPE_T;   status = LIB$SPAWN(&cmd_desc,0,0,0,0,0,&complcode,0,0,0);  }  #endif/*****************************************************************//* InitializeNonportableFeatures: Initializes the non-portable   *//*   features of CLIPS. Currently, the only non-portable feature *//*   requiring initialization is the interrupt handler which     *//*   allows CLIPS execution to be halted.                        *//*****************************************************************/static VOID InitializeNonportableFeatures()  {#if ! WINDOW_INTERFACE#if MAC   AddPeriodicFunction("systemtask",CallSystemTask,0);#endif#if VAX_VMS || UNIX_V || UNIX_7 || IBM_GCC   signal(SIGINT,CatchCtrlC);#endif#if IBM_TBC   OldCtrlC = getvect(0x23);   OldBreak = getvect(0x1b);   setvect(0x23,CatchCtrlC);   setvect(0x1b,CatchCtrlC);   atexit(RestoreInterruptVectors);#endif#if IBM_MSC || IBM_ICB   OldCtrlC = _dos_getvect(0x23);   OldBreak = _dos_getvect(0x1b);   _dos_setvect(0x23,CatchCtrlC);   _dos_setvect(0x1b,CatchCtrlC);   atexit(RestoreInterruptVectors);#endif#if IBM_ZTC || IBM_SC   _controlc_handler = CatchCtrlC;   controlc_open();#endif#endif  }  /*************************************************************//* Functions For Handling Control C Interrupt: The following *//*   functions handle interrupt processing for several of    *//*   the machines on which CLIPS runs. For the Macintosh,    *//*   control-c is not handle, but a function is provided to  *//*   call periodically which calls SystemTask (allowing      *//*   periodic tasks to be handled by the operating system).  *//*************************************************************/#if ! WINDOW_INTERFACE#if MAC/************************************************************//* CallSystemTask: Macintosh specific function which allows *//*   periodic tasks to be handled by the operating system.  *//************************************************************/static VOID CallSystemTask()  {   static unsigned long int lastCall;   if (TickCount() < (lastCall + 10)) return;   SystemTask();   lastCall = TickCount();   return;  }#endif#if   VAX_VMS || UNIX_V || UNIX_7 || IBM_GCC/**********************************************//* CatchCtrlC: VMS and UNIX specific function *//*   to allow control-c interrupts.           *//**********************************************/static VOID CatchCtrlC(sgnl)  int sgnl;  {   SetHaltExecution(CLIPS_TRUE);   CloseAllBatchSources();   signal(SIGINT,CatchCtrlC);  }#endif#if   IBM_TBC || IBM_MSC/******************************************************//* CatchCtrlC: IBM Microsoft C and Borland Turbo C    *//*   specific function to allow control-c interrupts. *//******************************************************/static VOID interrupt CatchCtrlC()  {   SetHaltExecution(CLIPS_TRUE);   CloseAllBatchSources();  }/**************************************************************//* RestoreInterruptVectors: IBM Microsoft C and Borland Turbo *//*   C specific function for restoring interrupt vectors.     *//**************************************************************/static VOID RestoreInterruptVectors()  {#if IBM_TBC   setvect(0x23,OldCtrlC);   setvect(0x1b,OldBreak);#else   _dos_setvect(0x23,OldCtrlC);   _dos_setvect(0x1b,OldBreak);#endif  }#endif#if IBM_ZTC || IBM_SC/***********************************************//* CatchCtrlC: IBM Zortech C specific function *//*   to allow control-c interrupts.            *//***********************************************/static void _cdecl CatchCtrlC()  {   SetHaltExecution(CLIPS_TRUE);   CloseAllBatchSources();  }#endif#if   IBM_ICB/*************************************************//* CatchCtrlC: IBM Intel C Code Builder specific *//*   function to allow control-c interrupts.     *//*************************************************/static VOID CatchCtrlC()  {   _XSTACK *sf;                        /* Real-mode interrupt handler stack frame. */      sf = (_XSTACK *) _get_stk_frame();  /* Get pointer to V86 _XSTACK frame. */   SetHaltExecution(CLIPS_TRUE);       /* Terminate CLIPS operations and */   CloseAllBatchSources();             /* return to CLIPS prompt.        */   sf->opts |= _STK_NOINT;             /* Set _ST_NOINT to prevent V86 call. */  }  

⌨️ 快捷键说明

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