cflow2dot.pl 显示C源码函数调用图的。

软件和网站开发以及相关技术探讨
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

cflow2dot.pl 显示C源码函数调用图的。

#1

帖子 eexpress » 2010-10-18 16:52

放一个tar算了。
附件
cflow2dot.tar.gz
cflow2dot.pl xxxx.c yyyy.c
(84.41 KiB) 已下载 150 次
cflow2dot.png
x.png
● 鸣学
xihe
帖子: 28
注册时间: 2007-03-07 19:07

Re: cflow2dot.pl

#2

帖子 xihe » 2010-10-18 17:00

出来一堆错误,生成的图根本不准确。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl

#3

帖子 eexpress » 2010-10-18 18:20

my @color=qw(#eecc80 #ccee80 #80ccee #eecc80 #80eecc);
print "digraph G {\n";
print "node [peripheries=2 style=filled color=\"#eecc80\" fontname=\"Vera Sans YuanTi Mono\"];\nrankdir=LR;\nmain[shape=box];\nedge [color=\"sienna\" fontcolor=\"green\"];\n";
foreach (@in){
chomp;
/^ */;my $n=length($&)/4;
s/^ *//; s/\(\)\s*//;
print "node [color=\"$color[$n-1]\"];\n";
print "edge [color=\"$color[$n-1]\"];\n";

if(/>:$/){
加了3句。分支带不同颜色。

嘛错误?
☛ cflow2dot.pl habak.c xcore.c |dot -Tpng -o ~/x.png
附件
Screenshot-3.png
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl

#4

帖子 eexpress » 2010-10-18 18:59

代码: 全选

☛ dog cflow2dot.pl 
if(! -x "/usr/bin/cflow"){print "\'cflow\' not installed.\n"; exit;}
$_=join " ",@ARGV;
my @in=`/usr/bin/cflow $_`;
my @index;
my @commet;
my @color=qw(#eecc80 #ccee80 #80ccee #eecc80 #80eecc);
my $tmpdot="/tmp/cflow.dot";
my $tmppng="/tmp/cflow.png";
open FILE,'>',$tmpdot;  select FILE;
print "digraph G {\n";
print "node [peripheries=2 style=filled color=\"#eecc80\" fontname=\"Vera Sans YuanTi Mono\"];\nrankdir=LR;\nmain[shape=box];\nedge [color=\"sienna\" fontcolor=\"green\"];\n";
foreach (@in){
chomp;
/^ */;my $n=length($&)/4;
s/^ *//; s/\(\)\s*//;
print "node [color=\"$color[$n-1]\"];\nedge [color=\"$color[$n-1]\"];\n";
if(/>:$/){
s/(<.*>).*$//; push @commet,$1;
push @index,$_;
if($n ne 0){
print "$index[$n-1]->$_;\n";
}
}
else{
print "$index[$n-1]->$_;\n";
}
}
print "}\n";
select STDOUT; print "dot output to $tmpdot.\n";
if(-x "/usr/bin/dot"){
`dot -Tpng $tmpdot -o $tmppng`;
print "png output to $tmppng";
if(-x "/usr/bin/eog"){`eog $tmppng`;}
}
else{print "\'dot\' not installed.\n"}
● 鸣学
头像
ChenFengyuan
帖子: 770
注册时间: 2008-03-23 0:39

Re: cflow2dot.pl 显示C源码函数调用图的。

#5

帖子 ChenFengyuan » 2010-10-18 20:56

mark :em11
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#6

帖子 eexpress » 2010-10-19 8:59

睡觉冥想,发现逻辑错误。马上修改。

代码: 全选

#push @index,$_;
$index[$n]=$_;
● 鸣学
头像
leeaman
帖子: 30702
注册时间: 2007-02-02 18:14
系统: debian sid

Re: cflow2dot.pl 显示C源码函数调用图的。

#7

帖子 leeaman » 2010-10-19 9:51

呵呵,这个倒是超赞的东西,有空写个hello world试试效果哈
醉了星星,醉月亮●●●●●The Long Way To Go(*^_^*)
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#8

帖子 eexpress » 2010-10-19 10:20

去掉冗余的线
dot图,干净很多。
还是perl强啊。一行处理,搞定去掉重复的关系行,并跳过dot设置语法。

代码: 全选

open FILE,'<',$tmpdot; @in=<FILE>;close FILE;
my @unique=grep {! $count{$_}++ || ! /->/ } @in;
open FILE,'>',$tmpdot; print FILE @unique;close FILE;
cflow2dot.pl.去掉冗余的线.tar.xz
(772 Bytes) 已下载 114 次
btw: 需要c++的,可以自己写一个cppflow。反正cflow的输出格式,很简单的。
● cflow habak.c
main() <int main (int argc,char *argv[]) at habak.c:166>:
srand()
time()
initXconnection()
getenv()
malloc()
strlen()
strcpy()
strcat()
print_help() <void print_help (int rc) at habak.c:99>:
printf()
exit()
strcmp()
.....
附件
cflow2dot.pl.tar.xz
颜色和形状分类版本。程序结构更好。
(776 Bytes) 已下载 109 次
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#9

帖子 eexpress » 2010-10-21 15:34

附件
cflow2dot.1.0.pl.tar
(10 KiB) 已下载 142 次
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#10

帖子 eexpress » 2010-11-05 9:16

脚本居然马上被维护者发现了。

现在对方给出了补丁,谁愿意测试的。猴急的第一个补丁。
This should give a first draft. You can apply this to the latest release with:

frans@linux-u4jm:~/Projects/cflow-1.3> patch -p1 < cflow.patch

when I do it I get an error in src/cflow.h but you can easily add that patch by hand just add this function prototype somewhere in the file.

int dot_output_handler(cflow_output_command cmd,
FILE *outfile, int line,
void *data, void *handler_data);


This will give you an new option '-f dot'. you can test it with

frans@linux-u4jm:~/Projects/cflow-1.3> ./src/cflow -f dot src/*.c | dot -Tpng -o cflow.png

or what ever you found funny to run it on.


/Frans
附件
cflow.patch.tar.xz
(1.82 KiB) 已下载 122 次
● 鸣学
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: cflow2dot.pl 显示C源码函数调用图的。

#11

帖子 BigSnake.NET » 2010-11-05 20:55

doxygen 用的那个叫什么来着
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#12

帖子 eexpress » 2010-11-05 21:08

doxygen 没试过。要那么麻烦的写注释,不爽。
● 鸣学
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: cflow2dot.pl 显示C源码函数调用图的。

#13

帖子 xiooli » 2010-11-05 21:40

BigSnake.NET 写了:doxygen 用的那个叫什么来着
pic?
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: cflow2dot.pl 显示C源码函数调用图的。

#14

帖子 eexpress » 2012-04-29 19:22

发表于 : 2010-10-18 16:52

回顾下。Perl多强壮。没再动过,今天刚好又用到。
● 鸣学
回复