?? r2annote.c
字號:
/*====================================================================*/
/* UNIT : @(#)r2annote.c 2.5 - 08/04/99 */
/*====================================================================*/
/* PURPOSE: Traverse the Component List and annotate the source */
/* code immediately before the instrumented lines. */
/* */
/* SYSTEM : RECON II */
/* */
/* USED BY: main() */
/* */
/* HISTORY: */
/* VER DATE AUTHOR DESCRIPTION */
/* 1.00 23 Feb 93 L. Richard Created unit. */
/* 1.01 10 Mar 93 L. Richard Implemented gTALK. */
/* 1.02 26 Mar 93 L. Richard Modified algorythm so that '.out' */
/* is the extension for output files. */
/* 1.03 31 Mar 93 L. Richard Corrected output formatting. */
/* 1.04 31 Mar 93 L. Richard Corrected intermittent heap */
/* corruption problem. */
/* 1.05 5 Apr 93 L. Richard Added ASCII character recognition */
/* feature to switch output values. */
/* 1.06 30 Mar 97 L. Landry Added btree interface */
/* 2.2 31 Jan 98 W. Hall Made minor modifications to clean */
/* up some compiler warning issues. */
/* 2.3 20 Apr 98 A. Conwell Chgd loop traversal per TISK30 */
/* 2.4 6 Apr 99 D. Fralish Added Entry as per Tisk38 */
/*--------------------------------------------------------------------*/
/*==[ INTERFACE ]=====================================================*/
#include "r2.h"
#include "r2annote.h"
#include <stdio.h>
/*==[ PRIVATE IMPLEMENTATION ]========================================*/
#include "r2util.h"
/*==[ PUBLIC IMPLEMENTATION ]=========================================*/
/*--------------------------------------------------------------------*/
/* FUNCTION AnnotateSource */
/*--------------------------------------------------------------------*/
extern BOOL AnnotateSource(
char *type, /* Method flag */
STRING *symb, /* Annotation symbol */
STRING *anl_dir, /* Analyzer output directory */
COMPLIST *cl, /* Component list */
Tree *ptree /* Btree for source files */
)
{
FILE *src = NULL; /* Source buffer */
FILE *dest = NULL; /* Output buffer */
STRING line[ MAXLINE ]; /* Output filename */
STRING dname[ MAXPATH ]; /* Output filename */
STRING fname[ MAXFILE ]; /* Output file name */
STRING sname[ MAXPATH ]; /* Source filename */
COMPELEM *elem; /* Component element */
COMPNODE *node; /* Component 'pkg' for avl */
int lno; /* Source line number */
int ratio; /* Functionality ratio */
int index = 0; /* Current test file index */
char *temp; /* Returned File name */
int itemp; /* String length of temp */
/* Traverse the component list */
node=get_first_node(cl);
do
{
elem=(COMPELEM *)(node->key);
if (index != elem->Index)
{
/* New index encountered */
lno = 1;
/* Copy remainder of current file (if any) and clean up */
if (NULL != src)
{
while (NULL != fgets( line, MAXLINE+1, src ))
fprintf( dest, "%s", line );
fclose( src );
fclose( dest );
}
/* Find source pathname */
index = elem->Index;
/* Open source file */
temp = SeekOut(index, ptree); /* added interface to btree */
itemp = strlen(temp); /* to retreive filename */
strncpy(sname,temp,itemp-1);
sname[itemp-1]='\0';
if (NULL == (src = fopen( sname, "r" )))
AbortMsg( "Can not open source file." );
if (0 < gTALK)
printf( "R2Analyz: Source file = %s\n", sname );
/* Open output file */
SplitPath( sname, fname );
strncpy( dname, anl_dir, MAXLENGTH ); /* 1.04 [LHR] */
strcat( dname, fname );
strcat( dname, ".out" );
if (NULL == (dest = fopen( dname, "w" )))
AbortMsg( "Can not open analyze output file." );
if (0 < gTALK)
printf( "R2Analyz: Output file = %s\n", dname );
} /*if index*/
/* Copy source to output until instrumented line number */
while (lno < elem->Line)
{
if (NULL != fgets( line, MAXLINE+1, src ))
fprintf( dest, "%s", line );
lno++;
}
/* Write one line with all annotations for line "lno" of file "index"*/
fprintf( dest, "%s ", symb );
while ((elem->Index == index) &&
(elem->Line == lno) )
{
if ('D' == *type) /* 1.03 [LHR] */
ratio = 100;
else
{
ratio = 100 * elem->With / elem->Tot;
fprintf( dest, "%3d%% ", ratio );
}
if (('T' == elem->Cval) || ('F' == elem->Cval) || ('E' == elem->Cval))
fprintf( dest, "%c", elem->Cval );
else /*'S'*/
{
fprintf( dest, "%ld", elem->Sval );
if ((32 <= elem->Sval) && (elem->Sval < 127)) /* 1.06 [LHR] */
fprintf( dest, " ('%c')", (char)elem->Sval);
else if ((0 <= elem->Sval) && (elem->Sval < 32))
fprintf( dest, " (^%c)", (char)elem->Sval+64);
}
node=get_successor(node);
elem=(COMPELEM *)(node->key);
if (elem==NULL)
break;
if ((elem->Index == index) &&
(elem->Line == lno) ) /* Annotate on same line */
fprintf( dest, ", " );
} /* while( elem.Index == index) */
fprintf( dest, "\n" );
} while (node->key!=NULL); /*while not end of cl*/
/* Copy remainder of source file to output */
while (NULL != fgets( line, MAXLINE+1, src ))
fprintf( dest, "%s", line );
/* Clean up */
fclose( src );
fclose( dest );
DeleteCompList(&cl);
return( FALSE );
} /* AnnotateSource() */
/*====================================================================*/
/* EOF : r2annote.c */
/*====================================================================*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -