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

📄 r2protos.c

📁 这是一个C程序分析工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/*-------------------------------------------------------------------------*/
/*  If r2tmp.dat exists, read the path name to the trace file and the      */
/*  user-supplied comment.  Check for paths and strings that are too long. */
/*-------------------------------------------------------------------------*/
   else {
      fgets(gFilePath, BUF_SIZE, TmpData);
      if (0 != strlen(gFilePath)) {
         i = 0;
         while(('\0' != gFilePath[i]) && ('\n' != gFilePath[i]))
            i++;
         gFilePath[i] = '\0';
      }
      if (strlen(gFilePath) > MAXLENGTH)
         R2Err(NullFilePath, -1, "Trace file name too long.");
      fgets(TestDesc, BUF_SIZE, TmpData);
      i = 0;
      while(('\0' != TestDesc[i]) && ('\n' != TestDesc[i]))
         i++;
      TestDesc[i] = '\0';
      fclose(TmpData);
   }

   if (strlen(TestDesc) > MAXDIR)
      R2Err(NullFilePath, -1, "Recon test description too long.");

   gCurrentTrace = R2Open(gFilePath);
   if (0 > fprintf(gCurrentTrace->tracefile,"#%s\n",TestDesc))
      R2Err(NullFilePath, -1, "Error writing description to trace file.");

/*-------------------------------------------------------------------------*/
/* Intialize the contents of the trace file before returning.              */
/*-------------------------------------------------------------------------*/
#ifdef MIN_TRACE
      for (i = 0; i < MAX_SOURCE_FILES; i++)
         gCurrentTrace->filePath[i]   = NULL;

      gCurrentTrace->SwitchList = NULL;
      gCurrentTrace->TrueList   = NULL;
      gCurrentTrace->FalseList  = NULL;
	  gCurrentTrace->EntryList  = NULL;
      gCurrentTrace->TrueListEntries   = 0;
      gCurrentTrace->FalseListEntries  = 0;
	  gCurrentTrace->EntryListEntries  = 0;
      gCurrentTrace->SwitchListEntries = 0;
#endif

      return gCurrentTrace;
}

/*=========================================================================*/
/* FUNCTION: R2Open                                                        */
/*=========================================================================*/
/* PURPOSE : Opens a trace file.                                           */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : None                                                          */
/*                                                                         */
/* USED BY : R2True, R2False, R2Switch, R2Close                            */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 1.00   6 Feb 93 L. McCallie  Create file.                               */
/* 1.10  28 Feb 93 L. McCallie  Create testid.r2t at output directory      */
/* 2.00  23 Mar 97 J. Ward      Moved much of the functionality into       */
/*                              r2OpenDefaulFile per Tisk 17               */
/*-------------------------------------------------------------------------*/
R2TRACE_PTR R2Open(char *r2newfile)
{
	gCurrentTrace->tracefile = fopen(r2newfile,"w");
	if (NULL == gCurrentTrace->tracefile) {
		fprintf(stderr,"\nCould not open trace file %s.\n", r2newfile);
		exit(EXIT_FAILURE);
	}

	gCurrentTrace->r2status = R2OPEN;
	return gCurrentTrace;
}

#ifdef MESSAGE_Q
/*=========================================================================*/
/* FUNCTION: OpenDefaultMessageQ                                           */
/*=========================================================================*/
/* PURPOSE : Open a message queue when the message que option is being     */
/*           exercised.                                                    */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2Err                                                         */
/*                                                                         */
/* USED BY : R2True, R2False, R2Switch                                     */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 2.00  21 Mar 97 J. Ward      Open a Unix message queue.  This function  */
/*                              currently does not work for unkown reasons */
/*-------------------------------------------------------------------------*/
R2TRACE_PTR r2OpenDefaultMessageQ(void)
{
time_t start_time, curr_time;
unsigned int i;

/*-------------------------------------------------------------------------*/
/* Wait 5 seconds to let the queue get going.                              */
/*-------------------------------------------------------------------------*/
  time(&start_time);
  curr_time = start_time;
  while(difftime(time(&curr_time), start_time) < 2.0)
           ;

  if ((gCurrentTrace->MessageQueueId = msgget(MESSAGE_Q_ID, 0666)) < 0)
      R2Err(NullFilePath, -1, "Could not open message queue.");

  gCurrentTrace->r2status = R2OPEN;

/*-------------------------------------------------------------------------*/
/* Intialize the contents of the trace file before returning.              */
/*-------------------------------------------------------------------------*/
#ifdef MIN_TRACE
      for (i = 0; i < MAX_SOURCE_FILES; i++)
         gCurrentTrace->filePath[i]   = NULL;

      gCurrentTrace->SwitchList = NULL;
      gCurrentTrace->TrueList   = NULL;
      gCurrentTrace->FalseList  = NULL;
	  gCurrentTrace->EntryList  = NULL;
      gCurrentTrace->TrueListEntries   = 0;
      gCurrentTrace->FalseListEntries  = 0;
	  gCurrentTrace->EntryListEntries  = 0;
      gCurrentTrace->SwitchListEntries = 0;
#endif

  return gCurrentTrace;
}
#endif

/*=========================================================================*/
/* FUNCTION: ValidateInput                                                 */
/*=========================================================================*/
/* PURPOSE : Validates the file name, line number, and switch value        */
/*           Parameter switchValue is reserved for future use.             */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2Err                                                         */
/*                                                                         */
/* USED BY : R2True, R2False, R2Switch                                     */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* ?.??  09 Mar 95 C. Casey     Create ValidateInput                       */
/* 2.00  23 Mar 97 J. Ward      Added checks for file name length per      */
/*                              Tisk 17.                                   */
/*-------------------------------------------------------------------------*/
static void ValidateInput(char *R2srcfile_ptr, int Line, int switchValue)
{
   if (strlen(R2srcfile_ptr) < 1)
      R2Err(R2srcfile_ptr, Line, "Source file name not available.");
   if (strlen(R2srcfile_ptr) > MAXPATH)
      R2Err(R2srcfile_ptr, Line, "Source file name too long.");
   if (Line > MAX_LINE_NUMBER)
      R2Err(R2srcfile_ptr, Line, "Line number too large.");
   if (Line < 0)
      R2Err(R2srcfile_ptr, Line, "Line number less than zero.");
}

/*=========================================================================*/
/* FUNCTION: WriteTrace                                                    */
/*=========================================================================*/
/* PURPOSE : Write the string TraceData to either the trace file or the    */
/*           message queue.  Returns one of:                               */
/*                           NO_ERR - successful                           */
/*                           FILE_ERROR - write to trace file failed       */
/*                           QUEUE_ERROR - write to message queue failed   */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : None                                                          */
/*                                                                         */
/* USED BY : R2True, R2False, R2Switch, OutputTFList, OutputSwitchValues  */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* 2.00  23 Mar 97   J. Ward    Standardized header                        */
/*-------------------------------------------------------------------------*/
static int WriteTrace(char *TraceData)
{
#ifndef MESSAGE_Q
	int checkprint;
	checkprint = fprintf(gCurrentTrace->tracefile, TraceData);
	if ((0 > checkprint) || (MAX_CHARS < checkprint))
		return FILE_ERR;
#else
	struct msgbuffer sendbuf;

	strcpy(sendbuf.mtext,TraceData);
	sendbuf.mtype = 1;
      if (msgsnd(gCurrentTrace->MessageQueueId, &sendbuf,
                                   strlen(sendbuf.mtext) +1, 0) < 0)
		return QUEUE_ERR;
#endif

	return NO_ERR;
}

/*=========================================================================*/
/* FUNCTION: R2Err                                                         */
/*=========================================================================*/
/* PURPOSE : Prints an error message and quits the program                 */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : None                                                          */
/*                                                                         */
/* USED BY : R2Open, R2Close, R2True, R2False, R2Switch, SwitchListAdd,    */
/*           OutputSwitchList, FreeSwitchList, SwitchValueListAdd,         */
/*           OutputSwitchValues, FreeSwitchValues, TFListBitSet,           */
/*           OutputTFList                                                  */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* ?.??  24 Feb 95 C. Casey     Create R2Err                               */
/* 2.00  23 Mar 97 J. Ward      Modified to write file name instead of     */
/*                              file index in the error message per Tisk 17*/
/*-------------------------------------------------------------------------*/
static void R2Err(char *FilePath, int Line, char *ErrMessage)
{
   fprintf(stderr, "\n  r2protos.c:");
   if ((FilePath == NULL) && (Line < 0))
       fprintf(stderr,"The following error occurred in Recon:\n");
   else {
     fprintf(stderr, "The following error occurred in file ");
     fprintf(stderr, "%s at line %d.\n", FilePath, Line);
   }
   fprintf(stderr, "%s\n",ErrMessage);

   exit(EXIT_FAILURE);
}

#ifdef MIN_TRACE
/*=========================================================================*/
/* FUNCTION: TFListBitSet                                                 */
/*=========================================================================*/
/* PURPOSE : Set bits in True/False Array corresponding to file and line   */
/*           number.                                                       */
/*                                                                         */
/* SYSTEM  : RECON II                                                      */
/*                                                                         */
/* CALLS   : R2Err                                                         */
/*                                                                         */
/* USED BY : R2True, R2False                                               */
/*                                                                         */
/* HISTORY :                                                               */
/* VER   DATE         AUTHOR    DESCRIPTION                                */
/* ?.??  09 Mar 95 C. Casey     Create TFListBitSet                       */
/* 2.00  23 Mar 97 J. Ward      Modified to use new TFListADT linked list */
/*                              for Tisk 17.                               */
/*-------------------------------------------------------------------------*/
static TFListADT *TFListBitSet(TFListADT *head, int Index, int Line,
                                                         int *ListEntries)
{
   int JumpValue, i;
   TFListADT *NewEntry;
   TFListADT *TempEntry;

/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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