codegraph 0.7.8 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/codegraph +118 -158
- data/gemspec +1 -1
- data/lib/codegraph.rb +4 -14
- metadata +3 -3
data/bin/codegraph
CHANGED
@@ -1,175 +1,135 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "codegraph"
|
3
|
-
require "
|
3
|
+
require "optparse"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
# Which options are availabile ------------------------------------------------
|
6
|
+
# Default settings
|
7
|
+
$options = {
|
8
|
+
:files => [],
|
9
|
+
:mode => nil,
|
10
|
+
:output => "",
|
11
|
+
:function => "",
|
12
|
+
:depth => nil,
|
13
|
+
:adds => [],
|
14
|
+
:excludes => [],
|
15
|
+
:debug => false
|
16
|
+
}
|
17
|
+
def parse(args)
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: codegraph [options]"
|
20
|
+
opts.on("-y", "--debug","Work in debuging mode") do |debug|
|
21
|
+
$options[:debug] = debug
|
22
|
+
end
|
23
|
+
opts.on( "-a","--add f1,f2,f3",Array,"Add function for scanning") do |adds|
|
24
|
+
$options[:adds] = adds
|
25
|
+
end
|
26
|
+
opts.on("-f", "--function FUNCTION") do |func|
|
27
|
+
$options[:function] = func
|
28
|
+
$options[:mode] = 'single'
|
29
|
+
end
|
30
|
+
opts.on( "-s","--show-body","Display function body") do |show|
|
31
|
+
$options[:mode] = 'show'
|
32
|
+
end
|
33
|
+
opts.on("-u", "--upper-funx FUNCTION") do |func|
|
34
|
+
$options[:function] = func
|
35
|
+
$options[:mode] = 'upper'
|
36
|
+
end
|
37
|
+
opts.on("-8", "--8-funx FUNCTION") do |func|
|
38
|
+
$options[:function] = func
|
39
|
+
$options[:mode] = 8
|
40
|
+
end
|
41
|
+
opts.on("-F", "--file-list file0,file1,file3", Array,"List of files (alternative \"file0 file1 file3\")") do |filelist|
|
42
|
+
filelist.each do |filedesc|
|
43
|
+
unless File.exist?(filedesc)
|
44
|
+
$options[:files] << Dir.glob(File.expand_path(filedesc))
|
45
|
+
else
|
46
|
+
$options[:files] = filelist
|
47
|
+
end
|
48
|
+
end
|
49
|
+
$options[:files].flatten!
|
50
|
+
end
|
51
|
+
opts.on("-d", "--depth DEPTH","Set the maximum depth of the graph") do |depth|
|
52
|
+
$options[:depth] = depth
|
53
|
+
end
|
54
|
+
opts.on("-p", "--to-ps FILE", "Write Postscripts output file") do |ofile|
|
55
|
+
$options[:ofile] = ofile
|
56
|
+
$options[:output] = 'ps'
|
57
|
+
end
|
58
|
+
opts.on("-S", "--to-svg FILE", "Write Scalable Vector Graphic output file") do |ofile|
|
59
|
+
$options[:ofile] = ofile
|
60
|
+
$options[:output] = 'svg'
|
61
|
+
end
|
62
|
+
opts.on("-P", "--to-png FILE", "Write Portable Network Graphic output file") do |ofile|
|
63
|
+
$options[:ofile] = ofile
|
64
|
+
$options[:output] = 'png'
|
65
|
+
end
|
66
|
+
opts.on("-J", "--to-jpg FILE", "Write JPEG output file") do |ofile|
|
67
|
+
$options[:ofile] = ofile
|
68
|
+
$options[:output] = 'jpg'
|
69
|
+
end
|
70
|
+
opts.on("-D", "--to-dot FILE", "Write dot output file") do |ofile|
|
71
|
+
$options[:ofile] = ofile
|
72
|
+
$options[:output] = 'dot'
|
73
|
+
end
|
74
|
+
opts.on("-T", "--to-txt","Write to stdout") do
|
75
|
+
$options[:output] = 'txt'
|
76
|
+
end
|
77
|
+
opts.on("-V", "--version","Print version") do
|
78
|
+
puts Codegraph::VERSION
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
opts.on_tail("-h", "--help","Showthis message") do
|
82
|
+
puts opts
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
end.parse(args)
|
15
86
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
scan for all funx, which depends (in)directly
|
22
|
-
<funcname> AND which call <funcname>
|
23
|
-
(in)directly
|
24
|
-
|
25
|
-
--depth, -d <integer>
|
26
|
-
Set maximal Graph depth
|
27
|
-
|
28
|
-
--to-ps, -p <filename>
|
29
|
-
create a postscript file from the graph
|
30
|
-
|
31
|
-
--to-svg, -S <filename>
|
32
|
-
create a SVG file from the graph
|
33
|
-
|
34
|
-
--to-png, -P <filename>
|
35
|
-
create a PNG file from the graph
|
36
|
-
|
37
|
-
--to-jpg, -J <filename>
|
38
|
-
create a JPG file from the graph
|
39
|
-
|
40
|
-
--to-dot, -D <filename>
|
41
|
-
creates a <filename>.dot-file
|
42
|
-
|
43
|
-
--to-txt, -T
|
44
|
-
writes the relations to stdout
|
45
|
-
END
|
87
|
+
if $options[:files].flatten.empty?
|
88
|
+
warn 'Please use -F do define input files! Use -h for further help.'
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
$options
|
46
92
|
end
|
47
|
-
|
48
|
-
options
|
49
|
-
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
50
|
-
["--debug", "-y", GetoptLong::NO_ARGUMENT],
|
51
|
-
# ["--add", "-a", GetoptLong::REQUIRED_ARGUMENT],
|
52
|
-
["--function", "-f", GetoptLong::REQUIRED_ARGUMENT],
|
53
|
-
# ["--show-body", "-s", GetoptLong::REQUIRED_ARGUMENT],
|
54
|
-
["--upper-funx", "-u", GetoptLong::REQUIRED_ARGUMENT],
|
55
|
-
["--8-funx", "-8", GetoptLong::REQUIRED_ARGUMENT],
|
56
|
-
["--file-list", "-F", GetoptLong::REQUIRED_ARGUMENT],
|
57
|
-
["--depth", "-d", GetoptLong::REQUIRED_ARGUMENT],
|
58
|
-
["--to-ps", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
59
|
-
["--to-svg", "-S", GetoptLong::REQUIRED_ARGUMENT],
|
60
|
-
["--to-png", "-P", GetoptLong::REQUIRED_ARGUMENT],
|
61
|
-
["--to-jpg", "-J", GetoptLong::REQUIRED_ARGUMENT],
|
62
|
-
["--to-dot", "-D", GetoptLong::REQUIRED_ARGUMENT],
|
63
|
-
["--to-txt", "-T", GetoptLong::NO_ARGUMENT]
|
93
|
+
options = parse(ARGV)
|
94
|
+
pp options if $options[:debug]
|
64
95
|
# ["--exclude", "-x", GetoptLong::REQUIRED_ARGUMENT],
|
65
|
-
)
|
66
|
-
options.ordering = GetoptLong::RETURN_IN_ORDER
|
67
|
-
# Default values --------------------------------------------------------------
|
68
|
-
filelist = ""
|
69
|
-
mode = "multiple"
|
70
|
-
output = ""
|
71
|
-
internal = false
|
72
|
-
filename = ""
|
73
|
-
dotfile = ""
|
74
|
-
function = ""
|
75
|
-
depth = nil
|
76
|
-
adds = Array.new
|
77
|
-
excludes = Array.new
|
78
|
-
files = Array.new
|
79
|
-
debug = false
|
80
|
-
# option parsing --------------------------------------------------------------
|
81
|
-
options.each do |opt, arg|
|
82
|
-
case opt
|
83
|
-
when "--file-list"
|
84
|
-
filelist = arg
|
85
|
-
files = Dir.glob(filelist.split(' '))
|
86
|
-
when "--function"
|
87
|
-
mode = "single"
|
88
|
-
function = arg
|
89
|
-
when "--show-body"
|
90
|
-
mode = "show"
|
91
|
-
function = arg
|
92
|
-
when "--upper-funx"
|
93
|
-
mode = "upper"
|
94
|
-
function = arg
|
95
|
-
when "--8-funx"
|
96
|
-
mode = 8
|
97
|
-
function = arg
|
98
|
-
when "--depth"
|
99
|
-
depth = arg.to_i
|
100
|
-
when "--to-ps"
|
101
|
-
output = "ps"
|
102
|
-
filename = arg
|
103
|
-
when "--to-svg"
|
104
|
-
output = "svg"
|
105
|
-
filename = arg
|
106
|
-
when "--to-png"
|
107
|
-
output = "png"
|
108
|
-
filename = arg
|
109
|
-
when "--to-jpg"
|
110
|
-
output = "jpg"
|
111
|
-
filename = arg
|
112
|
-
when "--to-dot"
|
113
|
-
output = "dot"
|
114
|
-
filename = arg
|
115
|
-
when "--to-txt"
|
116
|
-
output = "txt"
|
117
|
-
when "--add"
|
118
|
-
adds = arg.split(/ /)
|
119
|
-
when "--exclude"
|
120
|
-
excludes = arg.split(/ /)
|
121
|
-
when "--debug"
|
122
|
-
debug = true
|
123
|
-
else
|
124
|
-
show_usage
|
125
|
-
exit
|
126
|
-
end
|
127
|
-
end
|
128
|
-
options.terminate
|
129
|
-
# script controlling ----------------------------------------------------------
|
130
|
-
# Is the filelist correct?
|
131
|
-
if files.size == 0
|
132
|
-
puts 'Please use --file-list "<list>"'
|
133
|
-
show_usage
|
134
|
-
exit
|
135
|
-
end
|
136
|
-
|
96
|
+
#)
|
137
97
|
# What kind of graph should be generated?
|
138
|
-
case mode
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
98
|
+
case $options[:mode]
|
99
|
+
when "upper"
|
100
|
+
g = UpperFunctionGraph.new($options[:function])
|
101
|
+
when "single","show"
|
102
|
+
g = SingleFunctionGraph.new($options[:function])
|
103
|
+
when 8
|
104
|
+
g = EightFunctionGraph.new($options[:function])
|
105
|
+
else
|
106
|
+
g = FunctionGraph.new
|
147
107
|
end
|
148
108
|
|
149
109
|
# Set debug mode
|
150
|
-
g.debug = debug
|
110
|
+
g.debug = $options[:debug]
|
151
111
|
|
152
|
-
# Include
|
153
|
-
g.adds = adds
|
112
|
+
# Include additional functions?
|
113
|
+
g.adds = $options[:adds]
|
154
114
|
|
155
115
|
# Creates the Knodes/Edges of the graph
|
156
|
-
g.fill(files
|
116
|
+
g.fill($options[:files],$options[:excludes])
|
157
117
|
|
158
118
|
# Remove edges
|
159
|
-
g.limit(depth) if depth
|
119
|
+
g.limit($options[:depth]) if $options[:depth]
|
160
120
|
|
161
121
|
# What sort of output should be created?
|
162
|
-
case output
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
122
|
+
case $options[:output]
|
123
|
+
when "ps", "svg", "png", "jpg"
|
124
|
+
g.to_type($options[:filename],$options[:output])
|
125
|
+
when "dot"
|
126
|
+
g.to_dot($options[:filename])
|
127
|
+
when "txt"
|
128
|
+
g.to_txt
|
129
|
+
else
|
130
|
+
if $options[:mode] == "show"
|
131
|
+
puts g.display_functionbody($options[:function])
|
132
|
+
else
|
133
|
+
g.display
|
134
|
+
end
|
135
|
+
end
|
data/gemspec
CHANGED
data/lib/codegraph.rb
CHANGED
@@ -6,6 +6,10 @@ require 'rgl/traversal'
|
|
6
6
|
require 'thread'
|
7
7
|
require 'asciify'
|
8
8
|
|
9
|
+
module Codegraph
|
10
|
+
VERSION = '0.7.11'
|
11
|
+
end
|
12
|
+
|
9
13
|
class FunctionGraph < RGL::DirectedAdjacencyGraph
|
10
14
|
attr_accessor :funx, :adds, :excludes, :debug
|
11
15
|
|
@@ -19,20 +23,6 @@ class FunctionGraph < RGL::DirectedAdjacencyGraph
|
|
19
23
|
'label' => '',
|
20
24
|
'fontsize' => '12'}
|
21
25
|
|
22
|
-
# Hash of supported langs and the ctags marker for functions
|
23
|
-
Types = {"php" => "f",
|
24
|
-
"perl" => "s",
|
25
|
-
"c" => "f",
|
26
|
-
"f" => "fs",
|
27
|
-
"sh" => "f"}
|
28
|
-
|
29
|
-
# Hash of how ctags calls function for each lang
|
30
|
-
Funx = {"php" => "function",
|
31
|
-
"perl" => "subroutine",
|
32
|
-
"c" => "function",
|
33
|
-
"f" => "subroutine",
|
34
|
-
"sh" => "function"}
|
35
|
-
|
36
26
|
@@home = `echo $HOME`.chomp
|
37
27
|
@@codehomedir = "#{@@home}/.codegraph"
|
38
28
|
@@matchBeforFuncName = '[^A-z0-9_]\s*'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 11
|
9
|
+
version: 0.7.11
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ralf Mueller
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-02-14 14:51:03 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|