summaryrefslogtreecommitdiffstats
path: root/qtruby/bin/rbqtapi
blob: 4540b3c65d47fc64a4ad7edaf503dace3aa5004e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env ruby1.8

# Note: this program is part of qtruby and makes use of its internal functions.
#       You should not rely on those in your own programs.

require 'getopts'
getopts('r:hvimp')

case File.basename $0
when "rbqtapi"
   require 'Qt'
when "rbkdeapi"
   require 'Korundum'
end

if $OPT_v
    # TODO add and use version number #{Qt::VERSION}
    print "qtruby using Qt-#{Qt::version}\n"
    exit 0 
elsif $OPT_h
    print $usage
    exit 0
end

if $OPT_m
    while 1
        line = STDIN.readline.chomp
        line.gsub!(/^Q(?=[A-Z])/,'Qt::')
        line.gsub!(/^K/,'KDE::') unless line =~ /^(KDE)|(KIO)|(KParts)|(KNS)/
        classid = Qt::Internal::find_pclassid($_)
        puts "__START__"
        if classid
            a = Qt::Internal::findAllMethods(classid)
            ids = (a.keys.sort.map{|k|a[k]}).flatten
            candidates = Qt::dumpCandidates(ids)
            sup = []
            Qt::Internal::getAllParents(classid, sup)
            sup.each {
                |sup_item|
                a = Qt::Internal::findAllMethods(sup_item)
                ids = (a.keys.sort.map{|k|a[k]}).flatten
                candidates << Qt::Internal::dumpCandidates(ids)
            }
            candidates.gsub("\t","") # erm. whats the "s" mean on s/\t//gs ?
            print candidates
        end
        puts "__END__"
    end
end

search_string = ARGV[0] ? ARGV[0].dup : nil
search_string.gsub!(/^Q(?=[A-Z])/,'Qt::') if search_string
# search_string.gsub!(/^K(?=[^D][^E])/,'KDE::') if search_string
search_string.gsub!(/^K/,'KDE::') unless search_string.nil? or search_string =~ /^(KDE)|(KIO)|(KParts)|(KNS)/
classid = search_string ? Qt::Internal::find_pclassid(search_string) : 1
if classid == 0
    puts "Class #{search_string} not found"
    exit 1
end
regexp = nil
regexp = ( $OPT_i ? Regexp.new($OPT_r, Regexp::IGNORECASE) : Regexp.new($OPT_r) ) if $OPT_r
candidates = ""
while true
    a = Qt::Internal::findAllMethods(classid)
    break if a.nil? 
    ids = (a.keys.sort.map{|k|a[k]}).flatten
    candidates = Qt::Internal::dumpCandidates(ids)
    if $OPT_p and !search_string.empty? and classid
	sup = []
        Qt::Internal::getAllParents(classid, sup)
	sup.each {
	    |sup_item|
            a = Qt::Internal::findAllMethods(sup_item)
            ids = (a.keys.sort.map{|k|a[k]}).flatten
            candidates << Qt::Internal::dumpCandidates(ids)
        }
    end
    if regexp
	candidates.split("\n").each {
	    |candidate|
	    puts candidate if candidate =~ regexp
	}
    else
	print candidates
    end
    break unless search_string.nil?
    classid += 1
end

BEGIN {
$usage = <<USAGE
rbqtapi - a qtruby introspection tool\t(c) Germain Garand 2003 <germain\@ebooksfrance.org>

usage: rbqtapi [-r <re>] [<class>]

options:
\t-r <re> : find all functions matching regular expression/keyword <re>
\t-i : together with -r, performs a case insensitive search
\t-p : display also inherited methods for <class>.
\t-v : print qtruby and Qt versions
\t-h : print this help message
USAGE
}