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 void ruby_tag (char * filename
, char * str
, int line
, FILE * of
)
72 S
= ruby_last_word (str
);
78 printf ("%s\t%s\t%d\n", S
, filename
, line
);
80 fprintf (of
, "%s\t%s\t%d\n", S
, filename
, line
);
83 void ruby_file (char * f_name
)
91 myfile
= fopen (f_name
, "r");
95 printf ("# %s\n", f_name
);
96 buf
= CNEW (char, 4096);
97 while (fgets (buf
, 4096, myfile
)) {
98 if (ruby_scan_line (buf
))
107 void __ruby_files (char * f_name
)
110 sblib_find ("./", "*.rb", f_name
);
119 __ruby_files (ENV
->tmp_files
);
120 d_array
= new DArray (32);
121 d_array
->from_file (ENV
->tmp_files
);
122 d_array
->foreach ((Dfunc_t
)chomp
);
124 for (i
= 0; i
< d_array
->get_size (); ++i
) {
125 if (! d_array
->get (i
))
128 ruby_ctags (d_array
->get (i
), ofile
);
131 unlink (ENV
->tmp_files
);
132 d_array
->foreach (free
);
136 int ruby_ctags (char * f_name
, FILE * of
)
148 myfile
= fopen (f_name
, "r");
152 buf
= CNEW (char, 4096);
153 while (fgets (buf
, 4096, myfile
)) {
155 if (ruby_scan_line (buf
))
156 ruby_tag (f_name
, buf
, line
, of
);
165 void ruby_short_info ()
167 printf ("Ruby language plugin.");
170 void ruby_long_info ()
172 printf ("Ruby plugin.\n");
173 printf ("Version: 1.0\n");
174 printf ("options: --ruby --files --file\n");
175 printf ("Usage: bob --ruby --files\n"
176 "\tbob ./ruby_files --ruby --make-ctags\n"
177 "\tbob <file> --ruby --file\n");
180 DArray
* plugin_init (struct env_t
*env
)
185 Ret
= new DArray (1);
186 plug
= CNEW (mod_t
, 1);
187 memset (plug
, 0, sizeof (mod_t
));
189 plug
->Version
= strdup ("1.0");
190 plug
->short_info
= ruby_short_info
;
191 plug
->long_info
= ruby_long_info
;
192 plug
->opt
= ruby_opt
;
193 plug
->opt2
= ruby_opt2
;
194 plug
->make_ctags
= ruby_ctags
;
195 plug
->language
= strdup ("Ruby");
196 plug
->file
= ruby_file
;
198 ENV
->listOptions
->add ( "--ruby");
199 ENV
->listOptions
->add ("--files");
201 Ret
->add (LPCHAR (plug
));