2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
11 #include "../the_tt.h"
12 #include "../sblib/wit.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
, '(');
30 if (*stail (ptr
) == ' ')
33 S
= strchr (ptr
, ' ');
37 void python_tag (tt_state_t
* tt
, char *ptr
, char ch
, int type
, FILE *of
)
39 int line
= tt
->d_attachment
[ENV
->t_op_no
].pair_line
+1;
41 while (*ptr
== ' ' || *ptr
== '\t')
44 if (type
& GLOBAL_TYPE_CLASS
) {
45 if (! strncmp (ptr
, "def ", 4)) {
46 ptr
= py_prepare (ptr
);
51 if (type
& GLOBAL_TYPE_FUNCTION
) {
52 if (! strncmp (ptr
, "class ", 6)) {
53 ptr
= py_prepare (ptr
);
60 fprintf (of
, "%s\t%s\t%i\n", ptr
, tt
->d_file_name
, line
);
69 unlink (ENV
->tmp_files
);
70 sblib_find ("./", "*.py", ENV
->tmp_files
);
71 d_array
= ENV
->d_files
;
72 d_array
->from_file (ENV
->tmp_files
);
73 unlink (ENV
->tmp_files
);
74 d_array
->foreach ((Dfunc_t
)chomp
);
77 void python_ctags_foreach (FILE * of
)
80 DArray
* d_array
= ENV
->d_files
;
81 for (i
= 0; i
< d_array
->get_size (); ++i
) {
82 if (! d_array
->get (i
))
85 python_ctags (d_array
->get (i
), of
);
86 free (d_array
->get (i
));
90 int python_ctags (char * f_name
, FILE * of
)
93 char *d_ptr
,*d_out
; // for t_op2
94 struct tt_state_t
*tt
;
98 python_ctags_foreach (of
);
104 tt
= CNEW (tt_state_t
, 1);
105 bzero (tt
, sizeof (struct tt_state_t
));
106 tt
->d_file_name
= strdup (f_name
);
107 PYTHON::py_tt_file (tt
);
109 d_out
= tt
->d_output
;
112 ch
= PYTHON::t_op (&d_ptr
, &d_out
);
118 python_tag (tt
, d_out
, ch
, GLOBAL_TYPE_FUNCTION
| GLOBAL_TYPE_CLASS
, of
);
125 void pyc_one (char * f_name
)
129 char *d_ptr
,*d_out
; // for t_op2
130 struct tt_state_t
*tt
;
132 tt
= CNEW (tt_state_t
, 1);
133 bzero (tt
, sizeof (struct tt_state_t
));
134 tt
->d_file_name
= strdup (f_name
);
135 PYTHON::py_tt_file (tt
);
137 d_out
= tt
->d_output
;
140 ch
= PYTHON::t_op (&d_ptr
, &d_out
);
146 while (*S
== ' ' || *S
== '\t')
149 if (! strncmp (S
, "class ", 6))
150 printf ("%s\n", py_prepare (S
));
160 if (! ENV
->d_files
->get_size ())
163 for (i
= 0; i
< ENV
->d_files
->get_size (); ++i
)
164 pyc_one (ENV
->d_files
->get (i
));
169 char py_opt (DArray
* d_opts
, int * i
)
174 if (EQ (d_opts
->get (*i
), "--python")) {
175 ENV
->language
= strdup ("Python");
179 if (EQ (d_opts
->get (*i
), "--files") && EQ (ENV
->language
, "Python")) {
180 sblib_find ("./", "*.py", "./python_files");
187 char py_opt2 (DArray
* d_opts
, int * i
)
189 if (EQ (ENV
->language
, "Python") && EQ (d_opts
->get (*i
), "--class")) {
198 printf ("Python plugin.\n");
199 printf ("Version: 1.0\n");
200 printf ("options: --python [--files | --make-ctags | --class ]\n");
203 DArray
* plugin_init (struct env_t
*env
)
205 struct mod_feature
* pm
;
206 struct mod_language
* pm_lang
;
209 pm
= CNEW (mod_feature
, 1);
210 pm_lang
= CNEW (mod_language
, 1);
212 bzero (pm
, sizeof (struct mod_feature
));
213 bzero (pm_lang
, sizeof (struct mod_language
));
214 pm_lang
->mod
.Version
= strdup ("1.0");
215 pm_lang
->mod
.Type
= TYPE_LANGUAGE
;
216 pm_lang
->the
= PYTHON::py_tt_file
;
217 pm_lang
->make_ctags
= python_ctags
;
218 pm_lang
->language
= strdup ("Python");
220 pm
->mod
.Version
= strdup ("1.0");
223 pm
->mod
.Type
= TYPE_FEATURE
;
224 pm
->mod
.info
= py_info
;
226 Ret
= new DArray (2);
227 Ret
->add (LPCHAR (pm
));
228 Ret
->add (LPCHAR (pm_lang
));