📄 sysdep.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 05/17/06 */
/* */
/* SYSTEM DEPENDENT MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Isolation of system dependent routines. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* Brian L. Donnell */
/* */
/* Revision History: */
/* 6.23: Modified GenOpen to check the file length */
/* against the system constant FILENAME_MAX. */
/* */
/* 6.24: Support for run-time programs directly passing */
/* the hash tables for initialization. */
/* */
/* Made gensystem functional for Xcode. */
/* */
/* Added BeforeOpenFunction and AfterOpenFunction */
/* hooks. */
/* */
/* Added environment parameter to GenClose. */
/* Added environment parameter to GenOpen. */
/* */
/* Updated UNIX_V gentime functionality. */
/* */
/*************************************************************/
#define _SYSDEP_SOURCE_
#include "setup.h"
#include <stdio.h>
#define _STDIO_INCLUDED_
#include <string.h>
#include <stdlib.h>
#include <time.h>
#if VAX_VMS
#include timeb
#include <descrip.h>
#include <ssdef.h>
#include <stsdef.h>
#include signal
extern int LIB$SPAWN();
#endif
#if MAC
#if MAC_MCW || MAC_XCD
#include <Carbon/Carbon.h>
#endif
#define kTwoPower32 (4294967296.0) /* 2^32 */
#if MAC_MCW || MAC_XCD
#include <strings.h>
#endif
#endif
#if MAC_MCW || IBM_MCW || MAC_XCD
#include <unistd.h>
#endif
#if IBM_ICB
#include <i32.h>
#include <stk.h>
#include <sys\types.h>
#include <sys\timeb.h>
#include <io.h>
#include <fcntl.h>
#include <limits.h>
#include <process.h>
#endif
#if IBM_MSC
#include <sys\types.h>
#include <sys\timeb.h>
#include <io.h>
#include <fcntl.h>
#include <limits.h>
#include <process.h>
#endif
#if IBM_TBC
#include <bios.h>
#include <io.h>
#include <fcntl.h>
#include <limits.h>
#endif
#if IBM_MCW
#include <io.h>
#include <limits.h>
#endif
#if IBM_ZTC || IBM_SC
#include <time.h>
#include <controlc.h>
#include <io.h>
#include <fcntl.h>
#include <limits.h>
#include <process.h>
#endif
#if UNIX_7 || IBM_GCC
#include <sys/types.h>
#include <sys/timeb.h>
#include <signal.h>
#endif
#if UNIX_V
#include <sys/types.h>
#include <sys/time.h>
#include <sys/times.h>
#include <unistd.h>
#include <signal.h>
#endif
#include "argacces.h"
#include "bmathfun.h"
#include "commline.h"
#include "conscomp.h"
#include "constrnt.h"
#include "constrct.h"
#include "cstrcpsr.h"
#include "emathfun.h"
#include "envrnmnt.h"
#include "filecom.h"
#include "iofun.h"
#include "memalloc.h"
#include "miscfun.h"
#include "multifld.h"
#include "multifun.h"
#include "parsefun.h"
#include "prccode.h"
#include "prdctfun.h"
#include "proflfun.h"
#include "prcdrfun.h"
#include "router.h"
#include "sortfun.h"
#include "strngfun.h"
#include "textpro.h"
#include "utility.h"
#include "watch.h"
#include "sysdep.h"
#if DEFFACTS_CONSTRUCT
#include "dffctdef.h"
#endif
#if DEFRULE_CONSTRUCT
#include "ruledef.h"
#endif
#if DEFGENERIC_CONSTRUCT
#include "genrccom.h"
#endif
#if DEFFUNCTION_CONSTRUCT
#include "dffnxfun.h"
#endif
#if DEFGLOBAL_CONSTRUCT
#include "globldef.h"
#endif
#if DEFTEMPLATE_CONSTRUCT
#include "tmpltdef.h"
#endif
#if OBJECT_SYSTEM
#include "classini.h"
#endif
#include "moduldef.h"
#if EMACS_EDITOR
#include "ed.h"
#endif
#if DEVELOPER
#include "developr.h"
#endif
/***************/
/* DEFINITIONS */
/***************/
#define NO_SWITCH 0
#define BATCH_SWITCH 1
#define BATCH_STAR_SWITCH 2
#define LOAD_SWITCH 3
/********************/
/* ENVIRONMENT DATA */
/********************/
#define SYSTEM_DEPENDENT_DATA 58
struct systemDependentData
{
void (*RedrawScreenFunction)(void *);
void (*PauseEnvFunction)(void *);
void (*ContinueEnvFunction)(void *,int);
#if ! WINDOW_INTERFACE
#if IBM_TBC
void interrupt (*OldCtrlC)(void);
void interrupt (*OldBreak)(void);
#endif
#if IBM_MSC
void (interrupt *OldCtrlC)(void);
void (interrupt *OldBreak)(void);
#endif
#if IBM_ICB
#pragma interrupt (OldCtrlC,OldBreak)
void (*OldCtrlC)(void);
void (*OldBreak)(void);
#endif
#endif
#if IBM_TBC || IBM_MSC || IBM_ICB /* || IBM_MCW || IBM_ZTC */
int BinaryFileHandle;
#endif
#if (! IBM_TBC) && (! IBM_MSC) && (! IBM_ICB) /* && (! IBM_MCW) && (! IBM_ZTC) */
FILE *BinaryFP;
#endif
int (*BeforeOpenFunction)(void *);
int (*AfterOpenFunction)(void *);
};
#define SystemDependentData(theEnv) ((struct systemDependentData *) GetEnvironmentData(theEnv,SYSTEM_DEPENDENT_DATA))
/****************************************/
/* GLOBAL EXTERNAL FUNCTION DEFINITIONS */
/****************************************/
extern void UserFunctions(void);
extern void EnvUserFunctions(void *);
/***************************************/
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
/***************************************/
static void InitializeSystemDependentData(void *);
static void SystemFunctionDefinitions(void *);
static void InitializeKeywords(void *);
static void InitializeNonportableFeatures(void *);
#if (VAX_VMS || UNIX_V || UNIX_7 || IBM_GCC) && (! WINDOW_INTERFACE)
static void CatchCtrlC(int);
#endif
#if (IBM_TBC || IBM_MSC) && (! WINDOW_INTERFACE)
static void interrupt CatchCtrlC(void);
static void RestoreInterruptVectors(void);
#endif
#if IBM_ICB && (! WINDOW_INTERFACE)
#pragma interrupt (CatchCtrlC)
static void CatchCtrlC(void);
static void RestoreInterruptVectors(void);
#endif
#if (IBM_ZTC || IBM_SC) && (! WINDOW_INTERFACE)
static void _cdecl CatchCtrlC(void);
#endif
#if MAC && (! WINDOW_INTERFACE)
static void CallSystemTask(void);
#endif
/********************************************************/
/* InitializeSystemDependentData: Allocates environment */
/* data for system dependent routines. */
/********************************************************/
static void InitializeSystemDependentData(
void *theEnv)
{
AllocateEnvironmentData(theEnv,SYSTEM_DEPENDENT_DATA,sizeof(struct systemDependentData),NULL);
}
/**************************************************/
/* InitializeEnvironment: Performs initialization */
/* of the KB environment. */
/**************************************************/
#if (! ENVIRONMENT_API_ONLY) && ALLOW_ENVIRONMENT_GLOBALS
globle void InitializeEnvironment()
{
if (GetCurrentEnvironment() == NULL)
{ CreateEnvironment(); }
}
#endif
/*****************************************************/
/* EnvInitializeEnvironment: Performs initialization */
/* of the KB environment. */
/*****************************************************/
globle void EnvInitializeEnvironment(
void *vtheEnvironment,
struct symbolHashNode **symbolTable,
struct floatHashNode **floatTable,
struct integerHashNode **integerTable,
struct bitMapHashNode **bitmapTable)
{
struct environmentData *theEnvironment = (struct environmentData *) vtheEnvironment;
/*================================================*/
/* Don't allow the initialization to occur twice. */
/*================================================*/
if (theEnvironment->initialized) return;
/*================================*/
/* Initialize the memory manager. */
/*================================*/
InitializeMemory(theEnvironment);
/*===================================================*/
/* Initialize environment data for various features. */
/*===================================================*/
InitializeCommandLineData(theEnvironment);
#if CONSTRUCT_COMPILER && (! RUN_TIME)
InitializeConstructCompilerData(theEnvironment);
#endif
InitializeConstructData(theEnvironment);
InitializeEvaluationData(theEnvironment);
InitializeExternalFunctionData(theEnvironment);
InitializeMultifieldData(theEnvironment);
InitializePrettyPrintData(theEnvironment);
InitializePrintUtilityData(theEnvironment);
InitializeScannerData(theEnvironment);
InitializeSystemDependentData(theEnvironment);
InitializeUserDataData(theEnvironment);
InitializeUtilityData(theEnvironment);
#if DEBUGGING_FUNCTIONS
InitializeWatchData(theEnvironment);
#endif
/*===============================================*/
/* Initialize the hash tables for atomic values. */
/*===============================================*/
InitializeAtomTables(theEnvironment,symbolTable,floatTable,integerTable,bitmapTable);
/*=========================================*/
/* Initialize file and string I/O routers. */
/*=========================================*/
InitializeDefaultRouters(theEnvironment);
/*=========================================================*/
/* Initialize some system dependent features such as time. */
/*=========================================================*/
InitializeNonportableFeatures(theEnvironment);
/*=============================================*/
/* Register system and user defined functions. */
/*=============================================*/
SystemFunctionDefinitions(theEnvironment);
UserFunctions();
EnvUserFunctions(theEnvironment);
/*====================================*/
/* Initialize the constraint manager. */
/*====================================*/
InitializeConstraints(theEnvironment);
/*==========================================*/
/* Initialize the expression hash table and */
/* pointers to specific functions. */
/*==========================================*/
InitExpressionData(theEnvironment);
/*===================================*/
/* Initialize the construct manager. */
/*===================================*/
#if ! RUN_TIME
InitializeConstructs(theEnvironment);
#endif
/*=====================================*/
/* Initialize the defmodule construct. */
/*=====================================*/
AllocateDefmoduleGlobals(theEnvironment);
/*===================================*/
/* Initialize the defrule construct. */
/*===================================*/
#if DEFRULE_CONSTRUCT
InitializeDefrules(theEnvironment);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -