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

📄 instpars.c

📁 这是一个C程序分析工具
💻 C
字号:
/*===================================================================
    FILE   :   @(#)instpars.c	2.5  -  08/04/99
  ===================================================================*/
/*===================================================================
   PURPOSE: Parses C language source code.                            
                                                                           
   SYSTEM : RECON II                                                       
                                                                           
  -------------------------------------------------------------------*/

/*==[ INCLUDES ]=====================================================*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#include "r2.h"
#include "r2inst.h"
#include "instrmnt.h"
#include "instutil.h"
#include "vb_print.h"

/*==[ PRIVATE FUNCTIONS ]============================================*/
char GetFunction(char *Token);

/*===================================================================
   FUNCTION: ParseFunction                                                 
  ===================================================================
   PURPOSE : Looks for a function.                                         
                                                                           
   CALLS   : GetToken                                                      
             InstrumentStatements                                          
                                                                           
   USED BY : Main                                                          
                                                                           
   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file                               
   1.10  28 Feb 93 L. McCallie  Clear Token after instrumentation          
   1.11  22 Jan 98 B. Boone     Removed unused variable per Tisk 022 
   1.12  09 Mar 99 D. Fralish   Added call to InstrumentEntryPoint() 
                                per Tisk 038
  -------------------------------------------------------------------*/
char ParseFunction(void)
   {
   char ch;
   char Token[132];
   char Function[132];
   short BraceState = 0;

   *Token = '\0';
   while (EOF != (ch = GetFunction(Token)))
      {
      strcpy(Function, Token);
      vb_print(FUNCTION_LEVEL,"%d\tFunction: %s\n",
         gLineNumber,Function);
	  if(GetEntryPointFlag() != FALSE)
	  {
	     InstrumentEntryPoint();
	  }
      do {
         if ('}' == ch)
            {
            BraceState--;
            }
         if ('{' == ch)
            {
            BraceState++;
            }
         ch = GetToken(Token);
         if ('(' == ch)
            {
            InstrumentStatements(Function, Token);
            *Token = '\0';
            }
         }
      while ((EOF != ch) && (0 != BraceState));
      }
   return(ch);
   }

/*===================================================================
   FUNCTION: GetFunction                                                   
  ===================================================================
   PURPOSE : Reads tokens until a function is located.                     
                                                                           
   CALLS   : GetToken                                                      
                                                                           
   USED BY : ParseFunction                                                 
                                                                           
   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.
   1.10   9 Mar 99 D. Fralish   Modified state diagram implementation
                                to handle finding C++ functions per 
                                Tisk 38                              
  -------------------------------------------------------------------*/
char GetFunction(char *Token)
   {
   char ch;
   char lastchar = ' ';
   char Function[132];
   short state = 0;

   do {
      ch = GetToken(Token);
      switch (state)
         {
         case 1:
            if (')' == ch)
               state = 2;
            break;
         case 2:
            if ('{' == ch)
			{
               state = 3;
			}
			/* If we are instrumenting entry points for functions
			   then we must account for the possibility of being
			   in a list and not a function.  If the previous char
			   was a comma then reset the state to zero. */
			if (GetEntryPointFlag() != FALSE && lastchar == ',')
			{
				state = 0;
			}
            break;
         }
      if ('(' == ch)
         {
         if (0 == StatementType(Token))
            {
            strcpy(Function, Token);
            state = 1;
            }
         else
            state = 0;
         }
	     /*  If we are instrumenting entry points for functions then
		     we must account for false detection of functions in the
	    	 logic above.  If we encounter a semi-colon then we are
			 not declaring a function so reset the state to zero and
			 start looking again and skip preprocessor directives. */
		 if (GetEntryPointFlag() != FALSE)
		 {
		   if (';' == ch)
		   {
		     strcpy(Function, "");
		     state = 0;
		   }

           /* This line is a preprocessor directive, therefore is is
	          not a function - skip this line */
     	   if ('#' == ch)
		   {
		     ch = SkipPreprocessor(Token);
		     strcpy(Function, "");
		     state = 0;
		   }
		 }
		 lastchar = ch;
      } while (3 != state && EOF != ch);
   if (EOF == ch)
      *Token = '\0';
   else
      strcpy(Token, Function);
   return(ch);
   }

⌨️ 快捷键说明

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