2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
13 extern "C" struct env_t
*ENV
;
16 int sb_prname (char *arg
)
20 d_ptr
= arg
+ strlen (arg
);
23 while (*d_ptr
!= '\\' &&
30 if (EQ (d_ptr
, "tags"))
32 else if (EQ (d_ptr
, "the_tt"))
34 else if (EQ (d_ptr
, "gc_indent"))
36 else if (EQ (d_ptr
, "structs"))
37 i_cmd
= cmd_give_structs
;
43 int main (int argc
, char ** argv
)
45 int d_global_type
= GLOBAL_TYPE_VARIABLE
;
51 char * exp
= NULL
; // for cgrep
54 i_cmd
= sb_prname (argv
[0]);
56 if (argc
== 1 && !i_cmd
) {
61 d_files
= new EArray (32);
62 ENV
->d_files
= d_files
;
64 d_opts
= new EArray (argc
);
66 for (i
= 0; i
< argc
; i
++)
67 d_opts
->add (argv
[i
]);
69 for (i
= 1; i
< d_opts
->get_size (); i
++) {
70 if (d_opts
->get (i
)[0] != '-') {
72 d_files
->add (strdup (d_opts
->get (i
)));
76 if (EQ (d_opts
->get (i
), "--help") || EQ (d_opts
->get (i
), "-h")) {
81 if (EQ (d_opts
->get (i
), "-u")) {
82 SB_FLSET (SB_FLRTREE
);
86 if (EQ (d_opts
->get (i
), "--verbose")) {
87 SB_FLSET (SB_FLVERBOSE
);
91 if (EQ (d_opts
->get (i
), "--linear") || EQ (d_opts
->get (i
), "-l")) {
92 SB_FLSET (SB_FLLINEAR
);
96 if (EQ (d_opts
->get (i
), "-C") && i
< argc
) {
98 chdir (d_opts
->get (i
));
102 if (EQ (d_opts
->get (i
), "--linux")) {
103 chdir ("/usr/src/linux");
107 if (EQ (d_opts
->get (i
), "--file")) {
112 if (EQ (d_opts
->get (i
), "--the-tt")) {
117 if (EQ (d_opts
->get (i
), "--give-structs")) {
118 i_cmd
= cmd_give_structs
;
122 if (EQ (d_opts
->get (i
), "--no-links")) {
123 SB_FLSET (SB_FLNOLINKS
);
127 if (EQ (d_opts
->get (i
), "--indent")) {
132 if (EQ (d_opts
->get (i
), "--tags")) {
137 if (EQ (d_opts
->get (i
), "--debug")) {
138 fclose (ENV
->d_stream_dbg
);
139 ENV
->d_stream_dbg
= fdopen (fileno (stderr
), "w");
143 if (EQ (d_opts
->get (i
), "--globals")) {
144 d_global_type
= GLOBAL_TYPE_TYPEDEF
|
145 GLOBAL_TYPE_VARIABLE
|
147 GLOBAL_TYPE_FUNCTION
|
150 GLOBAL_TYPE_NAMESPACE
;
155 if (EQ (d_opts
->get (i
), "--globals-typedef")) {
157 d_global_type
= GLOBAL_TYPE_TYPEDEF
;
161 if (EQ (d_opts
->get (i
), "--globals-extern")) {
163 d_global_type
= GLOBAL_TYPE_EXTERN
;
167 if (EQ (d_opts
->get (i
), "--globals-function")) {
169 d_global_type
= GLOBAL_TYPE_FUNCTION
;
173 if (EQ (d_opts
->get (i
), "--globals-struct")) {
175 d_global_type
= GLOBAL_TYPE_STRUCT
;
179 if (EQ (d_opts
->get (i
), "--globals-variable")) {
181 d_global_type
= GLOBAL_TYPE_VARIABLE
;
185 if (EQ (d_opts
->get (i
), "--globals-define")) {
187 d_global_type
= GLOBAL_TYPE_DEFINE
;
191 if (EQ (d_opts
->get (i
), "--time-test")) {
196 if (EQ (d_opts
->get (i
), "--simulate")) {
198 SB_FLSET (SB_FLSIMULATE
);
202 if (EQ (d_opts
->get (i
), "--make-ctags")) {
203 i_cmd
= cmd_makectags
;
207 if (EQ (d_opts
->get (i
), "--tag-style") || EQ (d_opts
->get (i
), "-ts")) {
208 SB_FLSET (SB_FLTAGSTYLE
);
212 if (EQ (d_opts
->get (i
), "-L") && (i
+1) < argc
) {
214 d_files
->from_file (d_opts
->get (i
));
215 d_files
->foreach ((Dfunc_t
) chomp
);
216 n_files
= d_files
->get_size ();
220 if (EQ (d_opts
->get (i
), "-V") || EQ (d_opts
->get (i
), "--version")) {
225 if (EQ (d_opts
->get (i
), "--call-tags") || EQ (d_opts
->get (i
), "-ct")) {
226 SB_FLSET (SB_FLTAGSTYLE
);
227 i_cmd
= cmd_call_tags
;
231 if (EQ (d_opts
->get (i
), "--depth")) {
235 ENV
->d_depth
= atoi (d_opts
->get (i
));
239 if (EQ (d_opts
->get (i
), "-fn")) {
240 SB_FLSET (SB_FLFNAMES
);
244 if (EQ (d_opts
->get (i
), "--cgrep")) {
249 exp
= d_opts
->get (i
);
252 if (EQ (d_opts
->get (i
), "-a") || EQ (d_opts
->get (i
), "--all")) {
257 if (EQ (d_opts
->get (i
), "--test") || EQ (d_opts
->get (i
), "-t")) {
258 SB_FLSET (SB_FLTEST
);
262 if (EQ (d_opts
->get (i
), "--ctags-append")) {
263 SB_FLSET (SB_FLCTAGSAPPEND
);
267 if (EQ (d_opts
->get (i
), "-A")) {
271 ENV
->cgrep_A
= atoi (d_opts
->get (i
));
275 if (EQ (d_opts
->get (i
), "-B")) {
279 ENV
->cgrep_B
= atoi (d_opts
->get (i
));
283 if (EQ (d_opts
->get (i
), "--plugins-info")) {
288 if (EQ (d_opts
->get (i
), "--tags")) {
293 if (modding_optparse (&i
, 1))
296 /* if (d_opts->get (i)[0] == '-') {
297 fprintf (stderr, "unknown option : %s\n", d_opts->get (i));
300 } // for (i = 1; i < argc; i++)
302 for (i
= 0; i
< argc
; i
++)
303 modding_optparse (&i
, 2);
305 if (NE (ENV
->language
, "C")) {
306 i
= modding_start (i_cmd
);
312 make_ctags (d_files
);
318 cgrep (d_files
, exp
);
324 tags (d_files
, NULL
);
329 if (i_cmd
== cmd_makectags
||
330 i_cmd
== cmd_indent
||
331 i_cmd
== cmd_cgrep
) {
336 for (i
= 0; i
< n_files
; i
++) {
339 flist_main (d_files
->get (i
));
342 THE_TT::the_tt_main (d_files
->get(i
));
344 case cmd_give_structs
:
345 got_structs (d_files
->get (i
));
348 globals (d_files
->get(i
), d_global_type
);
355 if (i_cmd
== cmd_the_tt
&& !n_files
) // THE_TT for stdin
356 THE_TT::the_tt_main ("-");
357 else if (i_cmd
== cmd_give_structs
&& !n_files
) {
363 if ((i_cmd
== cmd_globals
|| i_cmd
== cmd_file
) && !n_files
) {
366 while (fgets (d_buf
, 1023, stdin
)) {
370 globals (d_buf
, d_global_type
);
379 if (i_cmd
== cmd_file
||
380 i_cmd
== cmd_the_tt
||
381 i_cmd
== cmd_give_structs
||
382 i_cmd
== cmd_globals
)
385 if (!SB_FLGET (SB_FLRTREE
))
386 call_tree (d_files
->get (0));
388 reverse_calltree (d_files
->get (0));
393 if (ENV
->immune_list
)
394 delete ENV
->immune_list
;
396 d_files
->foreach (free
);