2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
7 #include <gclib/gclib.h>
14 extern "C" DArray
* plugin_init (struct env_t
*env
);
15 int python_ctags (char * f_name
, FILE * of
);
18 char * py_tt_file (struct tt_state_t
* tt
);
19 char t_op (char ** d_in
, char ** d_prev
);
22 char * py_prepare (char *ptr
)
26 S
= strchr (ptr
, '(');
31 S
= strchr (ptr
, ' ');
35 void python_tag (tt_state_t
* tt
, char *ptr
, char ch
, int type
, FILE *of
)
37 int line
= tt
->attachment
[ENV
->t_op_no
].pair_line
+1;
39 while (*ptr
== ' ' || *ptr
== '\t')
42 if (type
& OT::Class
) {
43 if (! strncmp (ptr
, "def ", 4)) {
44 ptr
= py_prepare (ptr
);
49 if (type
& OT::Function
) {
50 if (! strncmp (ptr
, "class ", 6)) {
51 ptr
= py_prepare (ptr
);
58 fprintf (of
, "%s\t%s\t%i\n", ptr
, tt
->fileName
, line
);
65 unlink (ENV
->tmp_files
);
66 sblib_find ("./", "*.py", ENV
->tmp_files
);
67 d_array
= ENV
->d_files
;
68 d_array
->from_file (ENV
->tmp_files
);
69 unlink (ENV
->tmp_files
);
70 d_array
->foreach ((Dfunc_t
)chomp
);
73 void python_ctags_foreach (FILE * of
)
76 DArray
* d_array
= ENV
->d_files
;
77 for (i
= 0; i
< d_array
->get_size (); ++i
) {
78 if (! d_array
->get (i
))
81 python_ctags (d_array
->get (i
), of
);
82 free (d_array
->get (i
));
86 int python_ctags (char * f_name
, FILE * of
)
89 char *d_ptr
,*d_out
; // for t_op2
90 struct tt_state_t
*tt
;
94 python_ctags_foreach (of
);
100 tt
= CNEW (tt_state_t
, 1);
101 memset (tt
, 0, sizeof (struct tt_state_t
));
102 tt
->fileName
= strdup (f_name
);
103 PYTHON::py_tt_file (tt
);
108 ch
= PYTHON::t_op (&d_ptr
, &d_out
);
114 python_tag (tt
, d_out
, ch
, OT::Function
| OT::Class
, of
);
121 void pyc_one (char * f_name
)
125 char *d_ptr
,*d_out
; // for t_op2
126 struct tt_state_t
*tt
;
128 tt
= CNEW (tt_state_t
, 1);
129 memset (tt
, 0, sizeof (struct tt_state_t
));
130 tt
->fileName
= strdup (f_name
);
131 PYTHON::py_tt_file (tt
);
136 ch
= PYTHON::t_op (&d_ptr
, &d_out
);
142 while (*S
== ' ' || *S
== '\t')
145 if (! strncmp (S
, "class ", 6))
146 printf ("%s\n", py_prepare (S
));
156 if (! ENV
->d_files
->get_size ())
159 for (i
= 0; i
< ENV
->d_files
->get_size (); ++i
)
160 pyc_one (ENV
->d_files
->get (i
));
165 char py_opt (DArray
* d_opts
, int * i
)
170 if (EQ (d_opts
->get (*i
), "--python")) {
171 ENV
->language
= strdup ("Python");
175 if (EQ (d_opts
->get (*i
), "--files") && EQ (ENV
->language
, "Python")) {
176 unlink ("./python_files");
177 sblib_find ("./", "*.py", "./python_files");
184 char py_opt2 (DArray
* d_opts
, int * i
)
186 if (EQ (ENV
->language
, "Python") && EQ (d_opts
->get (*i
), "--class")) {
193 void py_short_info ()
195 printf ("Python plugin.");
200 printf ("Python plugin.\n");
201 printf ("Version: 1.0\n");
202 printf ("options: --python [--files | --make-ctags | --class ]\n");
205 DArray
* plugin_init (struct env_t
*env
)
208 struct mod_t
* pm_lang
;
211 pm
= CNEW (mod_t
, 1);
212 pm_lang
= CNEW (mod_t
, 1);
214 memset (pm
, 0, sizeof (struct mod_t
));
215 memset (pm_lang
, 0, sizeof (struct mod_t
));
217 pm_lang
->Version
= strdup ("1.0");
218 pm_lang
->the
= PYTHON::py_tt_file
;
219 pm_lang
->make_ctags
= python_ctags
;
220 pm_lang
->language
= strdup ("Python");
222 pm
->Version
= strdup ("1.0");
225 pm
->short_info
= py_short_info
;
226 pm
->long_info
= py_long_info
;
228 ENV
->listOptions
->add ( "--python");
229 ENV
->listOptions
->add ( "--files");
230 ENV
->listOptions
->add ( "--class");
232 Ret
= new DArray (2);
233 Ret
->add (LPCHAR (pm
));
234 Ret
->add (LPCHAR (pm_lang
));