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

📄 filecom.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* OpenStringBatch: Opens a string source for batch processing.  *//*   The memory allocated for the argument stringName must be    *//*   deallocated by the user. The memory allocated for theString *//*   will be deallocated by the batch routines when batch        *//*   processing for the  string is completed.                    *//*****************************************************************/globle int OpenStringBatch(  void *theEnv,  char *stringName,  char *theString,  int placeAtEnd)  {   if (OpenStringSource(theEnv,stringName,theString,0) == 0)     { return(0); }   if (FileCommandData(theEnv)->TopOfBatchList == NULL)     {      EnvAddRouter(theEnv,"batch", 20,                 FindBatch, NULL,                 GetcBatch, UngetcBatch,                 ExitBatch);     }   AddBatch(theEnv,placeAtEnd,(void *) stringName,STRING_BATCH,theString);   return(1);  }/*******************************************************//* AddBatch: Creates the batch file data structure and *//*   adds it to the list of opened batch files.        *//*******************************************************/static void AddBatch(  void *theEnv,  int placeAtEnd,  void *theSource,  int type,  char *theString)  {   struct batchEntry *bptr;   /*=========================*/   /* Create the batch entry. */   /*=========================*/   bptr = get_struct(theEnv,batchEntry);   bptr->batchType = type;   bptr->inputSource = theSource;   bptr->theString = theString;   bptr->next = NULL;   /*============================*/   /* Add the entry to the list. */   /*============================*/   if (FileCommandData(theEnv)->TopOfBatchList == NULL)     {      FileCommandData(theEnv)->TopOfBatchList = bptr;      FileCommandData(theEnv)->BottomOfBatchList = bptr;      FileCommandData(theEnv)->BatchType = type;      FileCommandData(theEnv)->BatchSource = theSource;      FileCommandData(theEnv)->BatchCurrentPosition = 0;     }   else if (placeAtEnd == FALSE)     {      bptr->next = FileCommandData(theEnv)->TopOfBatchList;      FileCommandData(theEnv)->TopOfBatchList = bptr;      FileCommandData(theEnv)->BatchType = type;      FileCommandData(theEnv)->BatchSource = theSource;      FileCommandData(theEnv)->BatchCurrentPosition = 0;     }   else     {      FileCommandData(theEnv)->BottomOfBatchList->next = bptr;      FileCommandData(theEnv)->BottomOfBatchList = bptr;     }  }/******************************************************************//* RemoveBatch: Removes the top entry on the list of batch files. *//******************************************************************/globle int RemoveBatch(  void *theEnv)  {   struct batchEntry *bptr;   int rv;   if (FileCommandData(theEnv)->TopOfBatchList == NULL) return(FALSE);   /*==================================================*/   /* Close the source from which batch input is read. */   /*==================================================*/   if (FileCommandData(theEnv)->TopOfBatchList->batchType == FILE_BATCH)     { GenClose(theEnv,(FILE *) FileCommandData(theEnv)->TopOfBatchList->inputSource); }   else     {      CloseStringSource(theEnv,(char *) FileCommandData(theEnv)->TopOfBatchList->inputSource);      rm(theEnv,FileCommandData(theEnv)->TopOfBatchList->theString,strlen(FileCommandData(theEnv)->TopOfBatchList->theString) + 1);     }   /*=================================*/   /* Remove the entry from the list. */   /*=================================*/   bptr = FileCommandData(theEnv)->TopOfBatchList;   FileCommandData(theEnv)->TopOfBatchList = FileCommandData(theEnv)->TopOfBatchList->next;   rtn_struct(theEnv,batchEntry,bptr);   /*========================================================*/   /* If there are no batch files remaining to be processed, */   /* then free the space used by the batch buffer.          */   /*========================================================*/   if (FileCommandData(theEnv)->TopOfBatchList == NULL)     {      FileCommandData(theEnv)->BottomOfBatchList = NULL;      FileCommandData(theEnv)->BatchSource = NULL;      if (FileCommandData(theEnv)->BatchBuffer != NULL)        {         rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition);         FileCommandData(theEnv)->BatchBuffer = NULL;        }      FileCommandData(theEnv)->BatchCurrentPosition = 0;      FileCommandData(theEnv)->BatchMaximumPosition = 0;      rv = 0;     }   /*===========================================*/   /* Otherwise move on to the next batch file. */   /*===========================================*/   else     {      FileCommandData(theEnv)->BatchType = FileCommandData(theEnv)->TopOfBatchList->batchType;      FileCommandData(theEnv)->BatchSource = FileCommandData(theEnv)->TopOfBatchList->inputSource;      FileCommandData(theEnv)->BatchCurrentPosition = 0;      rv = 1;     }   /*====================================================*/   /* Return TRUE if a batch file if there are remaining */   /* batch files to be processed, otherwise FALSE.      */   /*====================================================*/   return(rv);  }/****************************************//* BatchActive: Returns TRUE if a batch *//*   file is open, otherwise FALSE.     *//****************************************/globle intBool BatchActive(  void *theEnv)  {   if (FileCommandData(theEnv)->TopOfBatchList != NULL) return(TRUE);   return(FALSE);  }/******************************************************//* CloseAllBatchSources: Closes all open batch files. *//******************************************************/globle void CloseAllBatchSources(  void *theEnv)  {      /*================================================*/   /* Free the batch buffer if it contains anything. */   /*================================================*/   if (FileCommandData(theEnv)->BatchBuffer != NULL)     {      if (FileCommandData(theEnv)->BatchCurrentPosition > 0) EnvPrintRouter(theEnv,"stdout",(char *) FileCommandData(theEnv)->BatchBuffer);      rm(theEnv,FileCommandData(theEnv)->BatchBuffer,FileCommandData(theEnv)->BatchMaximumPosition);      FileCommandData(theEnv)->BatchBuffer = NULL;      FileCommandData(theEnv)->BatchCurrentPosition = 0;      FileCommandData(theEnv)->BatchMaximumPosition = 0;     }   /*==========================*/   /* Delete the batch router. */   /*==========================*/   EnvDeleteRouter(theEnv,"batch");   /*=====================================*/   /* Close each of the open batch files. */   /*=====================================*/   while (RemoveBatch(theEnv))     { /* Do Nothing */ }  }/******************************************//* BatchStarCommand: H/L access routine   *//*   for the batch* command.              *//******************************************/globle int BatchStarCommand(  void *theEnv)  {   char *fileName;   if (EnvArgCountCheck(theEnv,"batch*",EXACTLY,1) == -1) return(FALSE);   if ((fileName = GetFileName(theEnv,"batch*",1)) == NULL) return(FALSE);   return(EnvBatchStar(theEnv,fileName));  }#if ! RUN_TIME/**********************************************************//* EnvBatchStar: C access routine for the batch* command. *//**********************************************************/globle int EnvBatchStar(  void *theEnv,  char *fileName)  {   int inchar;   FILE *theFile;   char *theString = NULL;   size_t position = 0;   size_t maxChars = 0;   /*======================*/   /* Open the batch file. */   /*======================*/   theFile = GenOpen(theEnv,fileName,"r");   if (theFile == NULL)     {      OpenErrorMessage(theEnv,"batch",fileName);      return(FALSE);     }   /*========================*/   /* Reset the error state. */   /*========================*/   SetHaltExecution(theEnv,FALSE);   SetEvaluationError(theEnv,FALSE);   /*=============================================*/   /* Evaluate commands from the file one by one. */   /*=============================================*/   while ((inchar = getc(theFile)) != EOF)     {      theString = ExpandStringWithChar(theEnv,inchar,theString,&position,                                       &maxChars,maxChars+80);      if (CompleteCommand(theString) != 0)        {         FlushPPBuffer(theEnv);         SetPPBufferStatus(theEnv,OFF);         RouteCommand(theEnv,theString,FALSE);         FlushPPBuffer(theEnv);         SetHaltExecution(theEnv,FALSE);         SetEvaluationError(theEnv,FALSE);         FlushBindList(theEnv);               genfree(theEnv,theString,(unsigned) maxChars);         theString = NULL;         maxChars = 0;         position = 0;        }           }   if (theString != NULL)     { genfree(theEnv,theString,(unsigned) maxChars); }        /*=======================*/   /* Close the batch file. */   /*=======================*/   GenClose(theEnv,theFile);   return(TRUE);  }#else/**************************************************//* EnvBatchStar: This is the non-functional stub  *//*   provided for use with a run-time version.    *//**************************************************/globle int EnvBatchStar(  void *theEnv,  char *fileName)  {#if (MAC_MCW || IBM_MCW) && RUN_TIME#pragma unused(fileName)#endif   PrintErrorID(theEnv,"FILECOM",1,FALSE);   EnvPrintRouter(theEnv,WERROR,"Function batch* does not work in run time modules.\n");   return(FALSE);  }#endif/***********************************************************//* LoadCommand: H/L access routine for the load command.   *//***********************************************************/globle int LoadCommand(  void *theEnv)  {#if (! BLOAD_ONLY) && (! RUN_TIME)   char *theFileName;   int rv;   if (EnvArgCountCheck(theEnv,"load",EXACTLY,1) == -1) return(FALSE);   if ((theFileName = GetFileName(theEnv,"load",1)) == NULL) return(FALSE);   SetPrintWhileLoading(theEnv,TRUE);   if ((rv = EnvLoad(theEnv,theFileName)) == FALSE)     {      SetPrintWhileLoading(theEnv,FALSE);      OpenErrorMessage(theEnv,"load",theFileName);      return(FALSE);     }   SetPrintWhileLoading(theEnv,FALSE);   if (rv == -1) return(FALSE);   return(TRUE);#else   EnvPrintRouter(theEnv,WDIALOG,"Load is not available in this environment\n");   return(FALSE);#endif  }/****************************************************************//* LoadStarCommand: H/L access routine for the load* command.   *//****************************************************************/globle int LoadStarCommand(  void *theEnv)  {#if (! BLOAD_ONLY) && (! RUN_TIME)   char *theFileName;   int rv;   if (EnvArgCountCheck(theEnv,"load*",EXACTLY,1) == -1) return(FALSE);   if ((theFileName = GetFileName(theEnv,"load*",1)) == NULL) return(FALSE);   if ((rv = EnvLoad(theEnv,theFileName)) == FALSE)     {      OpenErrorMessage(theEnv,"load*",theFileName);      return(FALSE);     }   if (rv == -1) return(FALSE);   return(TRUE);#else   EnvPrintRouter(theEnv,WDIALOG,"Load* is not available in this environment\n");   return(FALSE);#endif  }#if DEBUGGING_FUNCTIONS/***********************************************************//* SaveCommand: H/L access routine for the save command.   *//***********************************************************/globle int SaveCommand(  void *theEnv)  {#if (! BLOAD_ONLY) && (! RUN_TIME)   char *theFileName;   if (EnvArgCountCheck(theEnv,"save",EXACTLY,1) == -1) return(FALSE);   if ((theFileName = GetFileName(theEnv,"save",1)) == NULL) return(FALSE);   if (EnvSave(theEnv,theFileName) == FALSE)     {      OpenErrorMessage(theEnv,"save",theFileName);      return(FALSE);     }   return(TRUE);#else   EnvPrintRouter(theEnv,WDIALOG,"Save is not available in this environment\n");   return(FALSE);#endif  }#endif

⌨️ 快捷键说明

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