Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1156535
  • 博文数量: 290
  • 博客积分: 3468
  • 博客等级: 中校
  • 技术积分: 3461
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-28 22:21
文章分类

全部博文(290)

文章存档

2016年(13)

2015年(3)

2014年(42)

2013年(67)

2012年(90)

2011年(75)

分类: C/C++

2013-11-13 11:42:02

cflow : http://www.gnu.org/software/cflow/

cflow 支持生成流程图的文件类型为: asm, c, yacc, lex
其生成的流程图支持两种模式:顺序(从main 开始) 与 逆序

针对个单个文件:
xrand.c 

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>

  5. typedef struct _display_info{
  6.     char res[512];
  7.     struct _display_info *next;
  8. }Display_info;

  9. void data_parse(char *buf, char *resdata)
  10. {
  11.     char res[16];
  12.     char *split = "@";

  13.     printf(" len: %d\t %s", strlen(buf), buf);
  14.     int i = 0, j = 0, k = 0;
  15.     int isblank = 1;
  16.     int changed = 0;

  17.     memset(res, 0, sizeof(res));
  18.     for (i=0; i< strlen(buf); i++) {
  19.         if (buf[i] == ' ') {
  20.             isblank = 1;
  21.             if (changed) {
  22.                 changed = 0;
  23.                 k++;
  24.                 printf("res: %s\n", res);
  25.                 if (k > 1) //第一获取的为分辨率
  26.                     res[4] = 0; //只要精确到小点后1位
  27.                 strcat(resdata, res);
  28.                 strcat(resdata, split);
  29.                 memset(res, 0, sizeof(res));
  30.             }
  31.             continue;
  32.         }

  33.         if (buf[i] == '\n') {
  34.             if (changed) {
  35.                 changed = 0;
  36.                 k++;
  37.                 printf("res: %s\n", res);
  38.                 if (k > 1) //第一获取的为分辨率
  39.                     res[4] = 0; //只要精确到小点后1位
  40.                 strcat(resdata, res);
  41.                 strcat(resdata, split);
  42.                 memset(res, 0, sizeof(res));
  43.             }
  44.             continue;
  45.         }

  46.         if (buf[i] != ' ') {
  47.             if (isblank) {
  48.                 j = i;
  49.                 isblank = 0;
  50.                 changed = 1;
  51.             }
  52.             res[i-j] = buf[i];
  53.         }
  54.     }

  55. }

  56. void get_randr(Display_info **list)
  57. {
  58.     char *cmd = "xrandr";
  59.     char *mode = "r";
  60.     FILE *fp = NULL;
  61.     char buf[512];
  62. //    char res[512];

  63.     Display_info *node = NULL;
  64.     Display_info *head = NULL;
  65.     Display_info *tmp = NULL;

  66.     fp = popen(cmd, mode);
  67.     if (!fp) {
  68.         perror("popen error:");
  69.         return ;
  70.     }

  71.     memset(buf, 0, sizeof(buf));
  72.     while(fgets(buf, sizeof(buf), fp)) {
  73.         if (isblank(buf[0])) {
  74.             node = (Display_info *)malloc(sizeof(Display_info));
  75.             if(!node) {
  76.                 perror("malloc failure");
  77.             }

  78.             memset(node->res, 0, sizeof(node->res));
  79.             node->next = NULL;
  80.             data_parse(buf, node->res);
  81.             node->res[strlen(node->res) -1] = 0;
  82.             printf("resdata:%s\n", node->res);
  83.             memset(buf, 0, sizeof(buf));

  84.             if (!head) {
  85.                 head = node;
  86.                 tmp = head;
  87.             } else {
  88.                 tmp->next = node;
  89.                 tmp = tmp->next;
  90.             }
  91.         }

  92.     }

  93.     *list = head;
  94. }


  95. int main(int argc, char *argv)
  96. {
  97.     Display_info *list = NULL;

  98.     get_randr(&list);
  99.     while (list) {
  100.         printf("main:%s\n",list->res);
  101.         list = list->next;
  102.     }


  103.     return 0;
  104. }

cflow 输出内容及格式是可配制的 ,详见:http://www.gnu.org/software/cflow/manual/cflow.html

点击(此处)折叠或打开

  1. $ cflow xrandr.c
  2. main() <int main (int argc, char *argv) at xrandr.c:112>:
  3.     get_randr() <void get_randr (Display_info **list) at xrandr.c:64>:
  4.         popen()
  5.         perror()
  6.         memset()
  7.         fgets()
  8.         isblank()
  9.         malloc()
  10.         data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>:
  11.             printf()
  12.             strlen()
  13.             memset()
  14.             strcat()
  15.         strlen()
  16.         printf()
  17.     printf()

  18. $ cflow --tree xrandr.c
  19. +-main() <int main (int argc, char *argv) at xrandr.c:112>
  20.   +-get_randr() <void get_randr (Display_info **list) at xrandr.c:64>
  21.   | +-popen()
  22.   | +-perror()
  23.   | +-memset()
  24.   | +-fgets()
  25.   | +-isblank()
  26.   | +-malloc()
  27.   | +-data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>
  28.   | | +-printf()
  29.   | | +-strlen()
  30.   | | +-memset()
  31.   | | \-strcat()
  32.   | +-strlen()
  33.   | \-printf()
  34.   \-printf()

  35. $ cflow --tree -f posix xrandr.c
  36.     1 +-main: int (int argc, char *argv), <xrandr.c 112>
  37.     2 +-get_randr: void (Display_info **list), <xrandr.c 64>
  38.     3 | +-popen: <>
  39.     4 | +-perror: <>
  40.     5 | +-memset: <>
  41.     6 | +-fgets: <>
  42.     7 | +-isblank: <>
  43.     8 | +-malloc: <>
  44.     9 | +-data_parse: void (char *buf, char *resdata), <xrandr.c 11>
  45.    10 | | +-printf: <>
  46.    11 | | +-strlen: <>
  47.    12 | | +-memset: <>
  48.    13 | | \-strcat: <>
  49.    14 | +-strlen: <>
  50.    15 | \-printf: <>
  51.    16 \-printf: <>

  52. $ cflow --tree -f gnu --number xrandr.c
  53.     1 +-main() <int main (int argc, char *argv) at xrandr.c:112>
  54.     2 +-get_randr() <void get_randr (Display_info **list) at xrandr.c:64>
  55.     3 | +-popen()
  56.     4 | +-perror()
  57.     5 | +-memset()
  58.     6 | +-fgets()
  59.     7 | +-isblank()
  60.     8 | +-malloc()
  61.     9 | +-data_parse() <void data_parse (char *buf, char *resdata) at xrandr.c:11>
  62.    10 | | +-printf()
  63.    11 | | +-strlen()
  64.    12 | | +-memset()
  65.    13 | | \-strcat()
  66.    14 | +-strlen()
  67.    15 | \-printf()
  68.    16 \-printf()

多文件模式,即在makefile 中使用 cflow。详见:http://www.gnu.org/software/cflow/manual/cflow.html#Makefiles
Makefile(clfow 专用)


点击(此处)折叠或打开

  1. CFLOW_FLAGS= --tree --number

  2. SRC=$(wildcard *.c)
  3. program_CFLOW_INPUT=$(SRC)

  4. program.cflow: $(program_CFLOW_INPUT) cflow.rc
  5.     CFLOWRC=cflow.rc \
  6.         cflow -o $@ $(CFLOW_FLAGS) $(DEFS) \
  7.         $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
  8.         $(CPPFLAGS) \
  9.         $(program_CFLOW_INPUT)
在与Makefile 文件相同的目录下touch cflow.rc
执行 make 后, 生成 program.cflow 

查看program.cflow

点击(此处)折叠或打开

  1. $ cat program.cflow
  2.     1 +-main() <int main (int argc, char *argv[]) at yuv2jpg.c:190>
  3.     2 +-malloc()
  4.     3 +-perror()
  5.     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>
  6.     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>
  7.     6 | | +-assert()
  8.     7 | | +-open_video() <int open_video (char *device_name) at capture.c:33>
  9.     8 | | | +-open()
  10.     9 | | | \-perror()
  11.    10 | | +-get_video_cap() <int get_video_cap (pVd vd) at capture.c:54>
  12.    11 | | | +-ioctl()
  13.    12 | | | \-perror()
  14.    13 | | \-get_video_support_format() <void get_video_support_format (pVd vd) at capture.c:85>
  15.    14 | | +-memset()
  16.    15 | | +-ioctl()
  17.    16 | | \-debug_p()
  18.    17 | \-set_video() <int set_video (pVd vd) at capture.c:215>
  19.    18 | +-ioctl()
  20.    19 | +-perror()
  21.    20 | +-malloc()
  22.    21 | +-debug_p()
  23.    22 | +-memset()
  24.    23 | \-set_mmap_space() <int set_mmap_space (pVd vd) at capture.c:155>
  25.    24 | +-ioctl()
  26.    25 | +-perror()
  27.    26 | +-memset()
  28.    27 | +-mmap()
  29.    28 | \-debug_p()
  30.    29 +-capture_video() <int capture_video (pVd vd) at capture.c:448>
  31.    30 | +-mmap_mode() <int mmap_mode (pVd vd) at capture.c:369>
  32.    31 | | +-enable_video() <int enable_video (pVd vd) at capture.c:292>
  33.    32 | | | +-ioctl()
  34.    33 | | | \-perror()
  35.    34 | | +-perror()
  36.    35 | | +-memset()
  37.    36 | | +-ioctl()
  38.    37 | | +-debug_p()
  39.    38 | | \-memcpy()
  40.    39 | \-read_mode() <int read_mode (pVd vd) at capture.c:345>
  41.    40 | +-read()
  42.    41 | +-perror()
  43.    42 | \-debug_p()
  44.    43 +-write_file() <int write_file (FILE *fp, unsigned char *buf, int size) at yuv2jpg.c:100>
  45.    44 | +-debug_p()
  46.    45 | +-assert()
  47.    46 | +-fopen()
  48.    47 | +-fprintf()
  49.    48 | +-fwrite()
  50.    49 | \-fclose()
  51.    50 +-open_file() <FILE *open_file (char *filename, char *mode) at yuv2jpg.c:28>
  52.    51 | +-fopen()
  53.    52 | \-perror()
  54.    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>
  55.    54 | +-jpeg_std_error()
  56.    55 | +-jpeg_create_compress()
  57.    56 | +-jpeg_stdio_dest()
  58.    57 | +-jpeg_set_defaults()
  59.    58 | +-jpeg_set_quality()
  60.    59 | +-jpeg_start_compress()
  61.    60 | +-memcpy()
  62.    61 | +-jpeg_write_raw_data()
  63.    62 | +-jpeg_finish_compress()
  64.    63 | \-jpeg_destroy_compress()
  65.    64 +-close_video() <void close_video (pVd vd) at capture.c:468>
  66.    65 | +-disable_video() <int disable_video (pVd vd) at capture.c:319>
  67.    66 | | +-ioctl()
  68.    67 | | \-perror()
  69.    68 | +-debug_p()
  70.    69 | +-munmap()
  71.    70 | +-free()
  72.    71 | \-close()
  73.    72 +-free()
  74.    73 +-get_file_size() <long get_file_size (FILE *fp) at yuv2jpg.c:50>
  75.    74 | +-fseek()
  76.    75 | +-ftell()
  77.    76 | \-debug_p()
  78.    77 +-exit()
  79.    78 \-read_file() <int read_file (FILE *fp, unsigned char *buf) at yuv2jpg.c:76>
  80.    79 +-fread()
  81.    80 \-debug_p()




阅读(1376) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~