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

📄 sysdep.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* 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#endifstatic 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   SystemDependentData(theEnv)->OldCtrlC = _dos_getvect(0x23);   SystemDependentData(theEnv)->OldBreak = _dos_getvect(0x1b);   _dos_setvect(0x23,CatchCtrlC);   _dos_setvect(0x1b,CatchCtrlC);   atexit(RestoreInterruptVectors);#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#endif/**************************************//* genexit:  A generic exit function. *//**************************************/globle void genexit(  void *theEnv,  int num)  {   if (SystemDependentData(theEnv)->jmpBuffer != NULL)     { longjmp(*SystemDependentData(theEnv)->jmpBuffer,1); }        exit(num);  }/**************************************//* SetJmpBuffer: *//**************************************/globle void SetJmpBuffer(  void *theEnv,  jmp_buf *theJmpBuffer)  {   SystemDependentData(theEnv)->jmpBuffer = theJmpBuffer;  }  /******************************************//* genstrcpy: Generic genstrcpy function. *//******************************************/char *genstrcpy(  char *dest,  const char *src)  {   return strcpy(dest,src);  }/********************************************//* genstrncpy: Generic genstrncpy function. *//********************************************/char *genstrncpy(  char *dest,  const char *src,  size_t n)  {   return strncpy(dest,src,n);  }  /******************************************//* genstrcat: Generic genstrcat function. *//******************************************/char *genstrcat(  char *dest,  const char *src)  {   return strcat(dest,src);  }/********************************************//* genstrncat: Generic genstrncat function. *//********************************************/char *genstrncat(  char *dest,  const char *src,  size_t n)  {   return strncat(dest,src,n);  }  /*****************************************//* gensprintf: Generic sprintf function. *//*****************************************/int gensprintf(  char *buffer,  const char *restrictStr,  ...)  {   va_list args;   int rv;      va_start(args,restrictStr);      rv = vsprintf(buffer,restrictStr,args);      va_end(args);      return rv;  }  /******************************************************//* 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#endifgloble 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 (SystemDependentData(theEnv)->BeforeOpenFunction != NULL)     { (*SystemDependentData(theEnv)->BeforeOpenFunction)(theEnv); }#if IBM_MSC   fopen_s(&theFile,fileName,accessType);#else   theFile = fopen(fileName,accessType);#endif      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#if IBM_MSC   SystemDependentData(theEnv)->BinaryFileHandle = _open(fileName,O_RDONLY | O_BINARY);#else   SystemDependentData(theEnv)->BinaryFileHandle = open(fileName,O_RDONLY | O_BINARY);#endif   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)   if ((SystemDependentData(theEnv)->BinaryFP = fopen(fileName,"rb")) == NULL)     {      if (SystemDependentData(theEnv)->AfterOpenFunction != NULL)        { (*SystemDependentData(theEnv)->AfterOpenFunction)(theEnv); }      OpenErrorMessage(theEnv,funcName,fileName);      return(FALSE);     }#endif

⌨️ 快捷键说明

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