2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 * 25/06/06 - Perl plugin for SilentBob.
17 #include "../the_tt.h"
18 #include "the_fly.hpp"
20 extern "C" DArray
* plugin_init (struct env_t
*env
);
21 void __perl_files (char * f_name
);
22 int perl_make_ctags (char * f_name
, FILE * of
);
23 char t_op2 (char ** d_in
, char ** d_prev
);
29 int perl_print_tags (char * f_name
)
35 void perl_file (DArray
* d_array
)
40 void pl_sub (struct tt_state_t
*tt
, int line
, char * d_out
, char ch
)
45 S
= strchr (d_out
, '(');
49 part1
= strchr (d_out
, ' ');
51 part2
= strchr (part1
, ':');
59 if (*stail (part2
) == ' ')
60 *stail (part2
) = '\0';
63 while (*stail (part1
) == ' ')
64 *stail (part1
) = '\0';
67 fprintf (ofile
, "%s:%s\t%s\t%i\n", part1
, part2
, tt
->d_file_name
, line
);
69 fprintf (ofile
, "%s\t%s\t%i\n", part1
, tt
->d_file_name
, line
);
72 void pl_package (struct tt_state_t
*tt
, int line
, char * d_out
, char ch
)
77 S
= strchr (d_out
, ' ');
82 while (*stail (d_out
) == ' ')
83 *stail (d_out
) = '\0';
85 ptr
= strchr_r (S
, ':');
88 fprintf (ofile
, "%s\t%s\t%i\n", ptr
, tt
->d_file_name
, line
);
90 fprintf (ofile
, "%s\t%s\t%i\n", S
, tt
->d_file_name
, line
);
93 void perl_make_tag (struct tt_state_t
*tt
, char * d_out
, char ch
)
97 line
= tt
->d_attachment
[ENV
->t_op_no
].pair_line
+1;
101 if (ch
== '{' && (! strncmp (d_out
, "sub ", 4))) {
102 pl_sub (tt
, line
, d_out
, ch
);
106 if (ch
== ';' && (! strncmp (d_out
, "package ", 8))) {
107 pl_package (tt
, line
, d_out
, ch
);
117 __perl_files (ENV
->tmp_files
);
118 d_array
= new DArray (32);
119 d_array
->from_file (ENV
->tmp_files
);
120 d_array
->foreach ((Dfunc_t
)chomp
);
122 for (i
= 0; i
< d_array
->get_size (); ++i
) {
123 if (! d_array
->get (i
))
126 perl_make_ctags (d_array
->get (i
), ofile
);
129 unlink (ENV
->tmp_files
);
130 d_array
->foreach (free
);
134 int perl_make_ctags (char * f_name
, FILE * of
)
137 char *d_ptr
,*d_out
; // for t_op2
139 struct tt_state_t
*tt
;
142 if (f_name
== NULL
) {
150 tt
= CNEW (tt_state_t
, 1);
151 bzero (tt
, sizeof (struct tt_state_t
));
152 tt
->d_file_name
= strdup (f_name
);
153 THE_FLY::fly_for_file (tt
);
154 //write (1, tt->d_output, tt->d_output_size);
156 d_out
= tt
->d_output
;
159 ch
= t_op2 (&d_ptr
, &d_out
);
166 perl_make_tag (tt
, d_out
, ch
);
182 int perl_call_tags (char * f_name
)
184 printf ("Jay online.\n");
188 char perl_opt (DArray
* d_opts
, int * i
)
193 if (EQ (d_opts
->get (*i
), "--perl")) {
194 ENV
->language
= "Perl";
200 void __perl_files (char * f_name
)
203 sblib_find ("./", "*.pm", f_name
);
204 sblib_find ("./", "*.pl", f_name
);
205 sblib_find ("./", "*.ph", f_name
);
208 char perl_files_opt (DArray
* d_opts
, int * i
)
213 unlink ("./perl_files");
214 if (EQ (d_opts
->get (*i
), "--files") && EQ (ENV
->language
, "Perl")) {
215 __perl_files ("./perl_files");
222 void perl_plugin_info ()
224 printf ("Perl support.\n");
225 printf ("Version: 1.0-rc1\n");
226 printf ("options: --perl --make-ctags\n");
229 void perl_files_info ()
231 printf ("Perl files.\n");
232 printf ("Version: 1.0\n");
233 printf ("options: --perl --files\n");
236 DArray
* perl_init ()
239 struct mod_feature
* pm
;
240 struct mod_feature
* mod_perlfiles
;
241 struct mod_language
* pm_lang
;
243 Ret
= new DArray (2);
244 pm
= CNEW (mod_feature
, 1);
245 pm_lang
= CNEW (mod_language
, 1);
246 mod_perlfiles
= CNEW (mod_feature
, 1);
248 bzero (pm
, sizeof (mod_feature
));
249 bzero (pm_lang
, sizeof (mod_language
));
250 bzero (mod_perlfiles
, sizeof (mod_feature
));
252 pm
->mod
.Type
= TYPE_FEATURE
;
253 pm
->mod
.Version
= strdup ("0.1");
256 mod_perlfiles
->mod
.Type
= TYPE_FEATURE
;
257 mod_perlfiles
->mod
.Version
= strdup ("1.0");
258 mod_perlfiles
->mod
.info
= perl_files_info
;
259 mod_perlfiles
->opt
= perl_files_opt
;
261 pm_lang
->mod
.Type
= TYPE_LANGUAGE
;
262 pm_lang
->mod
.Version
= strdup ("1.0-rc1");
263 pm_lang
->mod
.info
= perl_plugin_info
;
264 pm_lang
->language
= strdup ("Perl");
265 pm_lang
->the
= THE_FLY::fly_for_file
;
266 pm_lang
->print_tags
= perl_print_tags
;
267 pm_lang
->file
= perl_file
;
268 pm_lang
->make_ctags
= perl_make_ctags
;
270 Ret
->add (LPCHAR (pm
));
271 Ret
->add (LPCHAR (pm_lang
));
272 Ret
->add (LPCHAR (mod_perlfiles
));
277 DArray
* plugin_init (struct env_t
*env
)
283 // printf ("Perl module under construction.\n");