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
)
32 if (! d_opts
|| ! pos
)
35 if (EQ (d_opts
->get (*pos
), "--ruby")) {
36 ENV
->language
= strdup ("Ruby");
40 if (EQ (d_opts
->get (*pos
), "--files")) {
48 char ruby_opt2 (DArray
* d_opts
, int * pos
)
53 bool ruby_scan_line (const char *S
)
59 ptr
= strchr (S
, '#');
63 if (strstr (S
, "class ") ||
64 strstr (S
, "module ") ||
71 char * ruby_last_word (char * op
)
78 if (*S
== '(' || *S
== '=' || *S
== '[' || *S
== '<')
89 S
= strchr (d_word
, ' ');
98 char * ruby_tag (char * filename
, char * str
, int line
, FILE * of
)
102 S
= ruby_last_word (str
);
108 printf ("%s\t%s\t%d\n", S
, filename
, line
);
110 fprintf (of
, "%s\t%s\t%d\n", S
, filename
, line
);
113 void ruby_file (char * f_name
)
121 myfile
= fopen (f_name
, "r");
125 printf ("# %s\n", f_name
);
126 buf
= CNEW (char, 4096);
127 while (fgets (buf
, 4096, myfile
)) {
128 if (ruby_scan_line (buf
))
137 void __ruby_files (char * f_name
)
140 sblib_find ("./", "*.rb", f_name
);
149 __ruby_files (ENV
->tmp_files
);
150 d_array
= new DArray (32);
151 d_array
->from_file (ENV
->tmp_files
);
152 d_array
->foreach ((Dfunc_t
)chomp
);
154 for (i
= 0; i
< d_array
->get_size (); ++i
) {
155 if (! d_array
->get (i
))
158 ruby_ctags (d_array
->get (i
), ofile
);
161 unlink (ENV
->tmp_files
);
162 d_array
->foreach (free
);
166 int ruby_ctags (char * f_name
, FILE * of
)
178 myfile
= fopen (f_name
, "r");
182 buf
= CNEW (char, 4096);
183 while (fgets (buf
, 4096, myfile
)) {
185 if (ruby_scan_line (buf
))
186 ruby_tag (f_name
, buf
, line
, of
);
195 void ruby_short_info ()
197 printf ("Ruby plugin.");
200 void ruby_long_info ()
202 printf ("Ruby plugin.\n");
203 printf ("Version: 1.0\n");
204 printf ("options: --ruby --files --file\n");
205 printf ("Usage: bob --ruby --files\n"
206 "\tbob ./ruby_files --ruby --make-ctags\n"
207 "\tbob <file> --ruby --file\n");
210 DArray
* plugin_init (struct env_t
*env
)
215 Ret
= new DArray (1);
216 plug
= CNEW (mod_t
, 1);
217 memset (plug
, 0, sizeof (mod_t
));
219 plug
->Version
= strdup ("1.0");
220 plug
->short_info
= ruby_short_info
;
221 plug
->long_info
= ruby_long_info
;
222 plug
->opt
= ruby_opt
;
223 plug
->opt2
= ruby_opt2
;
224 plug
->make_ctags
= ruby_ctags
;
225 plug
->language
= strdup ("Ruby");
226 plug
->file
= ruby_file
;
228 ENV
->listOptions
->add ( "--ruby");
229 ENV
->listOptions
->add ("--files");
231 Ret
->add (LPCHAR (plug
));