cflow : cflow 支持生成流程图的文件类型为: asm, c, yacc, lex
其生成的流程图支持两种模式:顺序(从main 开始) 与 逆序
针对个单个文件:
xrand.c
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <unistd.h>
-
-
typedef struct _display_info{
-
char res[512];
-
struct _display_info *next;
-
}Display_info;
-
-
void data_parse(char *buf, char *resdata)
-
{
-
char res[16];
-
char *split = "@";
-
-
printf(" len: %d\t %s", strlen(buf), buf);
-
int i = 0, j = 0, k = 0;
-
int isblank = 1;
-
int changed = 0;
-
-
memset(res, 0, sizeof(res));
-
for (i=0; i< strlen(buf); i++) {
-
if (buf[i] == ' ') {
-
isblank = 1;
-
if (changed) {
-
changed = 0;
-
k++;
-
printf("res: %s\n", res);
-
if (k > 1) //第一获取的为分辨率
-
res[4] = 0; //只要精确到小点后1位
-
strcat(resdata, res);
-
strcat(resdata, split);
-
memset(res, 0, sizeof(res));
-
}
-
continue;
-
}
-
-
if (buf[i] == '\n') {
-
if (changed) {
-
changed = 0;
-
k++;
-
printf("res: %s\n", res);
-
if (k > 1) //第一获取的为分辨率
-
res[4] = 0; //只要精确到小点后1位
-
strcat(resdata, res);
-
strcat(resdata, split);
-
memset(res, 0, sizeof(res));
-
}
-
continue;
-
}
-
-
if (buf[i] != ' ') {
-
if (isblank) {
-
j = i;
-
isblank = 0;
-
changed = 1;
-
}
-
res[i-j] = buf[i];
-
}
-
}
-
-
}
-
-
void get_randr(Display_info **list)
-
{
-
char *cmd = "xrandr";
-
char *mode = "r";
-
FILE *fp = NULL;
-
char buf[512];
-
// char res[512];
-
-
Display_info *node = NULL;
-
Display_info *head = NULL;
-
Display_info *tmp = NULL;
-
-
fp = popen(cmd, mode);
-
if (!fp) {
-
perror("popen error:");
-
return ;
-
}
-
-
memset(buf, 0, sizeof(buf));
-
while(fgets(buf, sizeof(buf), fp)) {
-
if (isblank(buf[0])) {
-
node = (Display_info *)malloc(sizeof(Display_info));
-
if(!node) {
-
perror("malloc failure");
-
}
-
-
memset(node->res, 0, sizeof(node->res));
-
node->next = NULL;
-
data_parse(buf, node->res);
-
node->res[strlen(node->res) -1] = 0;
-
printf("resdata:%s\n", node->res);
-
memset(buf, 0, sizeof(buf));
-
-
if (!head) {
-
head = node;
-
tmp = head;
-
} else {
-
tmp->next = node;
-
tmp = tmp->next;
-
}
-
}
-
-
}
-
-
*list = head;
-
}
-
-
-
int main(int argc, char *argv)
-
{
-
Display_info *list = NULL;
-
-
get_randr(&list);
-
while (list) {
-
printf("main:%s\n",list->res);
-
list = list->next;
-
}
-
-
-
return 0;
-
}
cflow 输出内容及格式是可配制的 ,详见:
-
$ cflow xrandr.c
-
main() <int main (int argc, char *argv) at xrandr.c:112>:
-
get_randr() <void get_randr (Display_info **list) at xrandr.c:64>:
-
popen()
-
perror()
-
memset()
-
fgets()
-
isblank()
-
malloc()
-
data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>:
-
printf()
-
strlen()
-
memset()
-
strcat()
-
strlen()
-
printf()
-
printf()
-
-
$ cflow --tree xrandr.c
-
+-main() <int main (int argc, char *argv) at xrandr.c:112>
-
+-get_randr() <void get_randr (Display_info **list) at xrandr.c:64>
-
| +-popen()
-
| +-perror()
-
| +-memset()
-
| +-fgets()
-
| +-isblank()
-
| +-malloc()
-
| +-data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>
-
| | +-printf()
-
| | +-strlen()
-
| | +-memset()
-
| | \-strcat()
-
| +-strlen()
-
| \-printf()
-
\-printf()
-
-
$ cflow --tree -f posix xrandr.c
-
1 +-main: int (int argc, char *argv), <xrandr.c 112>
-
2 +-get_randr: void (Display_info **list), <xrandr.c 64>
-
3 | +-popen: <>
-
4 | +-perror: <>
-
5 | +-memset: <>
-
6 | +-fgets: <>
-
7 | +-isblank: <>
-
8 | +-malloc: <>
-
9 | +-data_parse: void (char *buf, char *resdata), <xrandr.c 11>
-
10 | | +-printf: <>
-
11 | | +-strlen: <>
-
12 | | +-memset: <>
-
13 | | \-strcat: <>
-
14 | +-strlen: <>
-
15 | \-printf: <>
-
16 \-printf: <>
-
-
$ cflow --tree -f gnu --number xrandr.c
-
1 +-main() <int main (int argc, char *argv) at xrandr.c:112>
-
2 +-get_randr() <void get_randr (Display_info **list) at xrandr.c:64>
-
3 | +-popen()
-
4 | +-perror()
-
5 | +-memset()
-
6 | +-fgets()
-
7 | +-isblank()
-
8 | +-malloc()
-
9 | +-data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>
-
10 | | +-printf()
-
11 | | +-strlen()
-
12 | | +-memset()
-
13 | | \-strcat()
-
14 | +-strlen()
-
15 | \-printf()
-
16 \-printf()
多文件模式,即在makefile 中使用 cflow。详见:
Makefile(clfow 专用)
-
CFLOW_FLAGS= --tree --number
-
-
SRC=$(wildcard *.c)
-
program_CFLOW_INPUT=$(SRC)
-
-
program.cflow: $(program_CFLOW_INPUT) cflow.rc
-
CFLOWRC=cflow.rc \
-
cflow -o $@ $(CFLOW_FLAGS) $(DEFS) \
-
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-
$(CPPFLAGS) \
-
$(program_CFLOW_INPUT)
在与Makefile 文件相同的目录下touch cflow.rc
执行 make 后, 生成 program.cflow
查看program.cflow
-
$ cat program.cflow
-
1 +-main() <int main (int argc, char *argv[]) at yuv2jpg.c:190>
-
2 +-malloc()
-
3 +-perror()
-
4 +-init_video() <int init_video (pVd vd, char *device_name, int capture_type, int pic_format, int height, int width) at capture.c:264>
-
5 | +-init_config() <int init_config (pVd vd, char *device_name, int capture_type, int pic_format, int height, int width) at capture.c:117>
-
6 | | +-assert()
-
7 | | +-open_video() <int open_video (char *device_name) at capture.c:33>
-
8 | | | +-open()
-
9 | | | \-perror()
-
10 | | +-get_video_cap() <int get_video_cap (pVd vd) at capture.c:54>
-
11 | | | +-ioctl()
-
12 | | | \-perror()
-
13 | | \-get_video_support_format() <void get_video_support_format (pVd vd) at capture.c:85>
-
14 | | +-memset()
-
15 | | +-ioctl()
-
16 | | \-debug_p()
-
17 | \-set_video() <int set_video (pVd vd) at capture.c:215>
-
18 | +-ioctl()
-
19 | +-perror()
-
20 | +-malloc()
-
21 | +-debug_p()
-
22 | +-memset()
-
23 | \-set_mmap_space() <int set_mmap_space (pVd vd) at capture.c:155>
-
24 | +-ioctl()
-
25 | +-perror()
-
26 | +-memset()
-
27 | +-mmap()
-
28 | \-debug_p()
-
29 +-capture_video() <int capture_video (pVd vd) at capture.c:448>
-
30 | +-mmap_mode() <int mmap_mode (pVd vd) at capture.c:369>
-
31 | | +-enable_video() <int enable_video (pVd vd) at capture.c:292>
-
32 | | | +-ioctl()
-
33 | | | \-perror()
-
34 | | +-perror()
-
35 | | +-memset()
-
36 | | +-ioctl()
-
37 | | +-debug_p()
-
38 | | \-memcpy()
-
39 | \-read_mode() <int read_mode (pVd vd) at capture.c:345>
-
40 | +-read()
-
41 | +-perror()
-
42 | \-debug_p()
-
43 +-write_file() <int write_file (FILE *fp, unsigned char *buf, int size) at yuv2jpg.c:100>
-
44 | +-debug_p()
-
45 | +-assert()
-
46 | +-fopen()
-
47 | +-fprintf()
-
48 | +-fwrite()
-
49 | \-fclose()
-
50 +-open_file() <FILE *open_file (char *filename, char *mode) at yuv2jpg.c:28>
-
51 | +-fopen()
-
52 | \-perror()
-
53 +-yuv422_to_jpeg() <int yuv422_to_jpeg (unsigned char *data, int image_width, int image_height, FILE *fp, int quality) at yuv2jpg.c:123>
-
54 | +-jpeg_std_error()
-
55 | +-jpeg_create_compress()
-
56 | +-jpeg_stdio_dest()
-
57 | +-jpeg_set_defaults()
-
58 | +-jpeg_set_quality()
-
59 | +-jpeg_start_compress()
-
60 | +-memcpy()
-
61 | +-jpeg_write_raw_data()
-
62 | +-jpeg_finish_compress()
-
63 | \-jpeg_destroy_compress()
-
64 +-close_video() <void close_video (pVd vd) at capture.c:468>
-
65 | +-disable_video() <int disable_video (pVd vd) at capture.c:319>
-
66 | | +-ioctl()
-
67 | | \-perror()
-
68 | +-debug_p()
-
69 | +-munmap()
-
70 | +-free()
-
71 | \-close()
-
72 +-free()
-
73 +-get_file_size() <long get_file_size (FILE *fp) at yuv2jpg.c:50>
-
74 | +-fseek()
-
75 | +-ftell()
-
76 | \-debug_p()
-
77 +-exit()
-
78 \-read_file() <int read_file (FILE *fp, unsigned char *buf) at yuv2jpg.c:76>
-
79 +-fread()
-
80 \-debug_p()
阅读(3692) | 评论(0) | 转发(0) |