|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
" ^2 ^7 r7 j: L% M: L'GNU cflow' analyzes a collection of C source files and prints a graph charting control flow within the program. It can produce both direct and inverted flowgraphs for C sources, or optionally generate a cross-reference listing. It implements either POSIX or GNU (extended) output formats. Input files can optionally be preprocessed before analyzing. The package also provides an Emacs major mode, so users can examine the produced flowcharts in Emacs.+ l; C7 W( x# g v6 I
! r* V* _+ q) X
An example to use cflow
7 L: @! E5 c, a' |" B0 j3 ?source code:
9 d$ V9 L, l- j# Q /* whoami.c - a simple implementation of whoami utility */
/ l p8 N) V, Z5 Y, [# x! S+ `: { #include <pwd.h>
' z" [# N9 @7 c$ L+ l. q; ~- X+ S #include <sys/types.h>' r- O2 E0 t, u' j' b
#include <stdio.h>
0 o& E% Y! R' ^1 g/ y #include <stdlib.h>3 {+ ~2 I9 j: Q: T0 U _+ ]
2 \5 k3 ]5 _0 [7 V4 p int
8 L# d6 z: a' B* w8 X' x- \/ k4 Z/ o# \ who_am_i (void)
' L8 z6 [) e5 f) ]& w, X/ Y4 g; G {
6 y8 O! \4 [2 y/ A; n struct passwd *pw;
( K" U8 d! m& ]( \9 _# W char *user = NULL;
: U5 ~$ R7 K# c( F+ F 6 r$ p! h& P4 m/ b. z+ s. X
pw = getpwuid (geteuid ());5 ~8 a5 c$ w7 d0 H y
if (pw)$ z: G$ |4 h- g: `* t
user = pw->pw_name;0 R+ ?( h# P! `) i; n6 z4 {9 @
else if ((user = getenv ("USER")) == NULL)& o8 `# o% U4 k
{
( s+ E: x' i9 s5 n fprintf (stderr, "I don't know!\n");. `# e3 X) r+ V# h2 m! u1 q/ W
return 1;# o8 A( F: z9 }/ g, k2 x
}
) |8 g6 O% V. F' P6 ?! r printf ("%s\n", user);
6 `7 T) Y4 X. k1 ^9 Z9 n8 A return 0;1 p7 p2 |1 \4 T0 _: T& k
}
: `6 W* H4 W) u- z: r3 Z: u. L9 \
0 g7 q& y* W7 Y6 K) q int' s, D: ]1 @5 f, t
main (int argc, char **argv)* t+ c; V3 ]& C0 I8 I
{
( p0 o& m; t4 s; a* o( }5 c8 J if (argc > 1)8 a: w, x% _) O. o" R3 W# b( H
{
) B ?1 {) q% V/ L fprintf (stderr, "usage: whoami\n");
0 N* @, v( M+ F5 U4 I v return 1;
" @! |5 ?* k. d& d- b) d( o/ ~' E' \7 b }: j& \1 D# ^ L' |7 ^# ]% ]7 ]: A5 P/ \
return who_am_i ();! b$ z) L1 e) j% j% m$ y( C8 O
}. }3 P! d% ?& ^/ D: G7 y4 I8 {
Running cflow produces the following output:! \9 j7 y. p4 A$ J7 G
" H- o! k0 ?3 P) V
$ cflow whoami.c/ \) x ]7 r& _: |* W- m, u
main() <int main (int argc,char **argv) at whoami.c:26>:/ _$ ]) C8 ]" z, q7 K0 Y4 E
fprintf()6 r) ]/ ]+ {1 i* W, j% i
who_am_i() <int who_am_i (void) at whoami.c:8>:, c; F; ]" f, I& Q
getpwuid()
0 P7 ~2 |3 s; P* X% i geteuid()
2 ?( }7 Y8 K0 k0 \# n: G getenv()# x; o; B/ `) L, C$ O
fprintf()2 t6 p# Y" e9 |; ~
printf() |
|