2 * (c) Oleg Puchinin 2006.
3 * graycardinalster@gmail.com
5 * 25/06/06 - Perl plugin for SilentBob.
13 #include <gclib/gclib.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
);
28 void pl_sub (struct tt_state_t
*tt
, int line
, char * d_out
, char ch
)
33 S
= strchr (d_out
, '(');
37 part1
= strchr (d_out
, ' ');
39 part2
= strchr (part1
, ':');
44 part2
= strip (part2
);
50 fprintf (ofile
, "%s:%s\t%s\t%i\n", part1
, part2
, tt
->fileName
, line
);
52 fprintf (ofile
, "%s\t%s\t%i\n", part1
, tt
->fileName
, line
);
55 void pl_package (struct tt_state_t
*tt
, int line
, char * d_out
, char ch
)
60 S
= strchr (d_out
, ' ');
67 ptr
= rindex (S
, ':');
70 fprintf (ofile
, "%s\t%s\t%i\n", ptr
, tt
->fileName
, line
);
72 fprintf (ofile
, "%s\t%s\t%i\n", S
, tt
->fileName
, line
);
75 void perl_make_tag (struct tt_state_t
*tt
, char * d_out
, char ch
)
79 line
= tt
->attachment
[ENV
->t_op_no
].pair_line
+1;
83 if ((ch
== '{') && (! strncmp (d_out
, "sub ", 4))) {
84 pl_sub (tt
, line
, d_out
, ch
);
88 if ((ch
== ';') && (! strncmp (d_out
, "package ", 8))) {
89 pl_package (tt
, line
, d_out
, ch
);
99 __perl_files (ENV
->tmp_files
);
100 d_array
= new DArray (32);
101 d_array
->from_file (ENV
->tmp_files
);
102 d_array
->foreach ((Dfunc_t
)chomp
);
104 for (i
= 0; i
< d_array
->get_size (); ++i
) {
105 if (! d_array
->get (i
))
108 perl_make_ctags (d_array
->get (i
), ofile
);
111 unlink (ENV
->tmp_files
);
112 d_array
->foreach (free
);
116 int perl_make_ctags (char * f_name
, FILE * of
)
119 char *d_ptr
,*d_out
; // for t_op2
121 struct tt_state_t
*tt
;
124 if (f_name
== NULL
) {
130 tt
= CNEW (tt_state_t
, 1);
131 memset (tt
, 0, sizeof (struct tt_state_t
));
132 tt
->fileName
= strdup (f_name
);
133 THE_FLY::fly_for_file (tt
);
138 ch
= t_op2 (&d_ptr
, &d_out
);
145 perl_make_tag (tt
, d_out
, ch
);
162 int perl_call_tags (char * f_name
)
164 printf ("Under construction.\n");
168 char perl_opt (DArray
* d_opts
, int * i
)
173 if (EQ (d_opts
->get (*i
), "--perl")) {
174 ENV
->language
= (char *) "Perl";
180 void __perl_files (char * f_name
)
183 sblib_find ("./", "*.pm", f_name
);
184 sblib_find ("./", "*.pl", f_name
);
185 sblib_find ("./", "*.ph", f_name
);
188 char perl_files_opt (DArray
* d_opts
, int * i
)
193 if (EQ (d_opts
->get (*i
), "--files") && EQ (ENV
->language
, "Perl")) {
194 __perl_files ((char *) "./perl_files");
201 void perl_plugin_short_info ()
203 printf ("Perl language support.");
207 void perl_plugin_long_info ()
209 printf ("Perl language support.\n");
210 printf ("Version: 1.0-rc1\n");
211 printf ("options: --perl --make-ctags\n");
214 void perl_files_short_info ()
216 printf ("Perl files.");
219 void perl_files_long_info ()
221 printf ("Perl files.\n");
222 printf ("Version: 1.0\n");
223 printf ("options: --perl --files\n");
226 DArray
* perl_init ()
230 struct mod_t
* mod_perlfiles
;
231 struct mod_t
* pm_lang
;
233 Ret
= new DArray (2);
234 pm
= CNEW (mod_t
, 1);
235 pm_lang
= CNEW (mod_t
, 1);
236 mod_perlfiles
= CNEW (mod_t
, 1);
238 memset (pm
, 0, sizeof (mod_t
));
239 memset (pm_lang
, 0, sizeof (mod_t
));
240 memset (mod_perlfiles
, 0, sizeof (mod_t
));
242 pm
->Version
= strdup ("0.1");
245 mod_perlfiles
->Version
= strdup ("1.0");
246 mod_perlfiles
->short_info
= perl_files_short_info
;
247 mod_perlfiles
->long_info
= perl_files_long_info
;
248 mod_perlfiles
->opt
= perl_files_opt
;
250 pm_lang
->Version
= strdup ("1.0-rc1");
251 pm_lang
->short_info
= perl_plugin_short_info
;
252 pm_lang
->long_info
= perl_plugin_long_info
;
253 pm_lang
->language
= strdup ("Perl");
254 pm_lang
->the
= THE_FLY::fly_for_file
;
255 pm_lang
->make_ctags
= perl_make_ctags
;
257 ENV
->listOptions
->add ("--perl");
258 ENV
->listOptions
->add ("--files");
260 Ret
->add (LPCHAR (pm
));
261 Ret
->add (LPCHAR (pm_lang
));
262 Ret
->add (LPCHAR (mod_perlfiles
));
267 DArray
* plugin_init (struct env_t
*env
)
272 // printf ("Perl module under construction.\n");