📄 sysdep.c
字号:
#else
#if ! VAX_VMS
EnvPrintRouter(theEnv,WDIALOG,
"System function not fully defined for this system.\n");
#endif
#endif
/*==================================================*/
/* Return the string buffer containing the command. */
/*==================================================*/
rm(theEnv,commandBuffer,bufferMaximum);
return;
}
#if VAX_VMS
/*************************************************/
/* VMSSystem: Implements system command for VMS. */
/*************************************************/
globle void VMSSystem(
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 non-portable */
/* features. Currently, the only non-portable feature */
/* requiring initialization is the interrupt handler */
/* which allows execution to be halted. */
/***********************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void InitializeNonportableFeatures(
void *theEnv)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
#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
SystemDependentData(theEnv)->OldCtrlC = getvect(0x23);
SystemDependentData(theEnv)->OldBreak = getvect(0x1b);
setvect(0x23,CatchCtrlC);
setvect(0x1b,CatchCtrlC);
atexit(RestoreInterruptVectors);
#endif
#if IBM_MSC || IBM_ICB
SystemDependentData(theEnv)->OldCtrlC = _dos_getvect(0x23);
SystemDependentData(theEnv)->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 */
/* machines. 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(
int sgnl)
{
#if ALLOW_ENVIRONMENT_GLOBALS
SetHaltExecution(GetCurrentEnvironment(),TRUE);
CloseAllBatchSources(GetCurrentEnvironment());
#endif
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()
{
#if ALLOW_ENVIRONMENT_GLOBALS
SetHaltExecution(GetCurrentEnvironment(),TRUE);
CloseAllBatchSources(GetCurrentEnvironment());
#endif
}
/**************************************************************/
/* RestoreInterruptVectors: IBM Microsoft C and Borland Turbo */
/* C specific function for restoring interrupt vectors. */
/**************************************************************/
static void RestoreInterruptVectors()
{
#if ALLOW_ENVIRONMENT_GLOBALS
void *theEnv;
theEnv = GetCurrentEnvironment();
#if IBM_TBC
setvect(0x23,SystemDependentData(theEnv)->OldCtrlC);
setvect(0x1b,SystemDependentData(theEnv)->OldBreak);
#else
_dos_setvect(0x23,SystemDependentData(theEnv)->OldCtrlC);
_dos_setvect(0x1b,SystemDependentData(theEnv)->OldBreak);
#endif
#endif
}
#endif
#if IBM_ZTC || IBM_SC
/***********************************************/
/* CatchCtrlC: IBM Zortech C specific function */
/* to allow control-c interrupts. */
/***********************************************/
static void _cdecl CatchCtrlC()
{
#if ALLOW_ENVIRONMENT_GLOBALS
SetHaltExecution(GetCurrentEnvironment(),TRUE);
CloseAllBatchSources(GetCurrentEnvironment());
#endif
}
#endif
#if IBM_ICB
/*************************************************/
/* CatchCtrlC: IBM Intel C Code Builder specific */
/* function to allow control-c interrupts. */
/*************************************************/
static void CatchCtrlC()
{
#if ALLOW_ENVIRONMENT_GLOBALS
_XSTACK *sf; /* Real-mode interrupt handler stack frame. */
sf = (_XSTACK *) _get_stk_frame(); /* Get pointer to V86 _XSTACK frame. */
SetHaltExecution(GetCurrentEnvironment(),TRUE); /* Terminate execution and */
CloseAllBatchSources(GetCurrentEnvironment()); /* return to the command prompt. */
sf->opts |= _STK_NOINT; /* Set _ST_NOINT to prevent V86 call. */
#endif
}
/********************************************************/
/* RestoreInterruptVectors: IBM Intel C Code Builder */
/* specific function for restoring interrupt vectors. */
/********************************************************/
static void RestoreInterruptVectors()
{
#if ALLOW_ENVIRONMENT_GLOBALS
void *theEnv;
theEnv = GetCurrentEnvironment();
_dos_setvect(0x23,SystemDependentData(theEnv)->OldCtrlC);
_dos_setvect(0x1b,SystemDependentData(theEnv)->OldBreak);
#endif
}
#endif
#endif
/**************************************/
/* GENEXIT: A generic exit function. */
/**************************************/
globle void genexit(
int num)
{
exit(num);
}
/******************************************************/
/* genrand: Generic random number generator function. */
/******************************************************/
int genrand()
{
return(rand());
}
/**********************************************************************/
/* genseed: Generic function for seeding the random number generator. */
/**********************************************************************/
globle void genseed(
int seed)
{
srand((unsigned) seed);
}
/*********************************************/
/* gengetcwd: Generic function for returning */
/* the current directory. */
/*********************************************/
#if IBM_TBC
#pragma argsused
#endif
globle char *gengetcwd(
char *buffer,
int buflength)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
return(getcwd(buffer,buflength));
#endif
if (buffer != NULL)
{ buffer[0] = 0; }
return(buffer);
}
/****************************************************/
/* genremove: Generic function for removing a file. */
/****************************************************/
globle int genremove(
char *fileName)
{
if (remove(fileName)) return(FALSE);
return(TRUE);
}
/****************************************************/
/* genrename: Generic function for renaming a file. */
/****************************************************/
globle int genrename(
char *oldFileName,
char *newFileName)
{
if (rename(oldFileName,newFileName)) return(FALSE);
return(TRUE);
}
/**************************************/
/* EnvSetBeforeOpenFunction: Sets the */
/* value of BeforeOpenFunction. */
/**************************************/
globle int (*EnvSetBeforeOpenFunction(void *theEnv,
int (*theFunction)(void *)))(void *)
{
int (*tempFunction)(void *);
tempFunction = SystemDependentData(theEnv)->BeforeOpenFunction;
SystemDependentData(theEnv)->BeforeOpenFunction = theFunction;
return(tempFunction);
}
/*************************************/
/* EnvSetAfterOpenFunction: Sets the */
/* value of AfterOpenFunction. */
/*************************************/
globle int (*EnvSetAfterOpenFunction(void *theEnv,
int (*theFunction)(void *)))(void *)
{
int (*tempFunction)(void *);
tempFunction = SystemDependentData(theEnv)->AfterOpenFunction;
SystemDependentData(theEnv)->AfterOpenFunction = theFunction;
return(tempFunction);
}
/*********************************************/
/* GenOpen: Trap routine for opening a file. */
/*********************************************/
globle FILE *GenOpen(
void *theEnv,
char *fileName,
char *accessType)
{
FILE *theFile;
if (strlen(fileName) > FILENAME_MAX)
{ return(NULL); }
if (SystemDependentData(theEnv)->BeforeOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->BeforeOpenFunction)(theEnv); }
theFile = fopen(fileName,accessType);
if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }
return theFile;
}
/**********************************************/
/* GenClose: Trap routine for closing a file. */
/**********************************************/
globle int GenClose(
void *theEnv,
FILE *theFile)
{
int rv;
if (SystemDependentData(theEnv)->BeforeOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->BeforeOpenFunction)(theEnv); }
rv = fclose(theFile);
if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }
return rv;
}
/************************************************************/
/* GenOpenReadBinary: Generic and machine specific code for */
/* opening a file for binary access. Only one file may be */
/* open at a time when using this function since the file */
/* pointer is stored in a global variable. */
/************************************************************/
globle int GenOpenReadBinary(
void *theEnv,
char *funcName,
char *fileName)
{
if (SystemDependentData(theEnv)->BeforeOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->BeforeOpenFunction)(theEnv); }
#if IBM_TBC || IBM_MSC || IBM_ICB
SystemDependentData(theEnv)->BinaryFileHandle = open(fileName,O_RDONLY | O_BINARY);
if (SystemDependentData(theEnv)->BinaryFileHandle == -1)
{
if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }
OpenErrorMessage(theEnv,funcName,fileName);
return(FALSE);
}
#endif
#if (! IBM_TBC) && (! IBM_MSC) && (! IBM_ICB)
if ((SystemDependentData(theEnv)->BinaryFP = fopen(fileName,"rb")) == NULL)
{
if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }
OpenErrorMessage(theEnv,funcName,fileName);
return(FALSE);
}
#endif
if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)
{ (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }
return(TRUE);
}
/***********************************************/
/* GenReadBinary: Generic and machine specific */
/* code for reading from a file. */
/***********************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -