2 * (c) Oleg Puchinin 2008
3 * graycardinalster@gmail.com
11 #include <gclib/gclib.h>
12 #include <gclib/gclib_c.h>
17 extern "C" DArray
* plugin_init (struct env_t
*env
);
18 int ruby_ctags (char * f_name
, FILE * of
);
23 unlink ("./ruby_files");
24 sblib_find ("./", "*.rb", "./ruby_files");
27 char ruby_opt (DArray
* d_opts
, int * pos
)
29 if (! d_opts
|| ! pos
)
32 if (EQ (d_opts
->get (*pos
), "--ruby")) {
33 ENV
->language
= strdup ("Ruby");
37 if (EQ (d_opts
->get (*pos
), "--files")) {
45 char ruby_opt2 (DArray
* d_opts
, int * pos
)
50 bool ruby_scan_line (const char *S
)
56 ptr
= strchr (S
, '#');
60 if (strstr (S
, "class ") ||
61 strstr (S
, "module ") ||
68 char * ruby_last_word (char * op
)
75 if (*S
== '(' || *S
== '=' || *S
== '[' || *S
== '<')
86 S
= strchr (d_word
, ' ');
95 void ruby_tag (char * filename
, char * str
, int line
, FILE * of
)
99 S
= ruby_last_word (str
);
105 printf ("%s\t%s\t%d\n", S
, filename
, line
);
107 fprintf (of
, "%s\t%s\t%d\n", S
, filename
, line
);
110 void ruby_file (char * f_name
)
118 myfile
= fopen (f_name
, "r");
122 printf ("# %s\n", f_name
);
123 buf
= CNEW (char, 4096);
124 while (fgets (buf
, 4096, myfile
)) {
125 if (ruby_scan_line (buf
))
134 void __ruby_files (char * f_name
)
137 sblib_find ("./", "*.rb", f_name
);
146 __ruby_files (ENV
->tmp_files
);
147 d_array
= new DArray (32);
148 d_array
->from_file (ENV
->tmp_files
);
149 d_array
->foreach ((Dfunc_t
)chomp
);
151 for (i
= 0; i
< d_array
->get_size (); ++i
) {
152 if (! d_array
->get (i
))
155 ruby_ctags (d_array
->get (i
), ofile
);
158 unlink (ENV
->tmp_files
);
159 d_array
->foreach (free
);
163 int ruby_ctags (char * f_name
, FILE * of
)
175 myfile
= fopen (f_name
, "r");
179 buf
= CNEW (char, 4096);
180 while (fgets (buf
, 4096, myfile
)) {
182 if (ruby_scan_line (buf
))
183 ruby_tag (f_name
, buf
, line
, of
);
192 void ruby_short_info ()
194 printf ("Ruby plugin.");
197 void ruby_long_info ()
199 printf ("Ruby plugin.\n");
200 printf ("Version: 1.0\n");
201 printf ("options: --ruby --files --file\n");
202 printf ("Usage: bob --ruby --files\n"
203 "\tbob ./ruby_files --ruby --make-ctags\n"
204 "\tbob <file> --ruby --file\n");
207 DArray
* plugin_init (struct env_t
*env
)
212 Ret
= new DArray (1);
213 plug
= CNEW (mod_t
, 1);
214 memset (plug
, 0, sizeof (mod_t
));
216 plug
->Version
= strdup ("1.0");
217 plug
->short_info
= ruby_short_info
;
218 plug
->long_info
= ruby_long_info
;
219 plug
->opt
= ruby_opt
;
220 plug
->opt2
= ruby_opt2
;
221 plug
->make_ctags
= ruby_ctags
;
222 plug
->language
= strdup ("Ruby");
223 plug
->file
= ruby_file
;
225 ENV
->listOptions
->add ( "--ruby");
226 ENV
->listOptions
->add ("--files");
228 Ret
->add (LPCHAR (plug
));