a33a45f42d7695360b4089b9c30ae6ced16d1c9e
3 import coccilib
.coccigui
4 import coccilib
.coccigui
.coccigui
5 from threading
import Thread
, Lock
7 from copy
import deepcopy
10 """In order to implement an output class for use with Coccinelle,
11 one can inherit from this class and overload register_match with
12 the same number of arguments.
14 include_match will be overwritten by inheriting from your actual
15 class, and thus if your class is a.b.C then Coccinelle will create
16 a Python class "class Coccinelle(a.b.C)" that hooks include_match
17 into the O'Caml internals.
19 def include_match(self
, b
):
22 def register_match(self
, include
, messages
):
25 def combine(self
, meta_variable
, locations
):
26 nmv
= deepcopy(meta_variable
)
27 nloc
= [deepcopy(loc
) for loc
in locations
]
28 nmv
.location
= nloc
[0]
36 def print_main(self
, p
) :
37 print "* TODO [[view:%s::face=ovl-face1::linb=%s::colb=%s::cole=%s][%s::%s]]" % (p
[0].file,p
[0].line
,p
[0].column
,p
[0].column_end
,p
[0].file,p
[0].line
)
39 def print_sec(self
, msg
, p
) :
40 print "[[view:%s::face=ovl-face2::linb=%s::colb=%s::cole=%s][%s]]" % (p
[0].file,p
[0].line
,p
[0].column
,p
[0].column_end
,msg
)
42 class Console(Output
):
46 def register_match(self
, include
, messages
):
47 self
.include_match(include
)
49 for variable
, message
in messages
:
50 print "%s:%s:%s: %s - %s" % (variable
.location
.file, variable
.location
.line
, variable
.location
.column
, message
, variable
)
52 class GtkRunner(Thread
):
58 def add_row(self
, cocci
, l
):
59 for i
in xrange(0, len(l
)):
60 l
[i
] = (l
[i
][1], l
[i
][0].location
.file, l
[i
][0].location
.line
, l
[i
][0].location
.column
)
64 self
.rows
.append((cocci
, l
))
71 return len(self
.rows
) > 0
78 return self
.rows
.pop(0)
84 cocci
, l
= self
.get_row()
85 self
.gui
.add_result(cocci
, l
)
86 gobject
.timeout_add(1000, self
.update
)
89 self
.gui
= coccilib
.coccigui
.coccigui
.pycocci()
90 globals()['gtk_sock'] = self
.gui
91 gobject
.timeout_add(1000, self
.update
)
93 gtk
.gdk
.threads_init()
94 gtk
.gdk
.threads_enter()
98 gtk
.gdk
.threads_leave()
100 globals().pop('gtk_thread')
101 globals().pop('gtk_sock')
104 def check_availability(self
):
105 if not globals().has_key('gtk_sock'):
107 globals()['gtk_thread'] = t
108 globals()['gtk_thread'].start()
111 def register_match(self
, include
, messages
):
112 self
.check_availability()
114 self
.include_match(include
)
116 globals()['gtk_thread'].add_row(self
.cocci_file
, messages
)
119 self
.check_availability()
121 globals()['gtk_thread'].join()