-- init_compile_env
[silentbob2.git] / src / main.cxx
blob068b645470ecf16cf1e707b7a2bb7229ec5f91c4
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 #include <head.h>
8 #include <wit.h>
9 #include <the_tt.h>
10 #include <mod.h>
11 #include <dbg.h>
13 extern "C" struct env_t *ENV;
15 void gop_log ()
17 FILE * f;
19 f = fopen ("./gop.log", "a");
20 fprintf (f, "Files: %i\n", ENV->d_files->get_size ());
21 fclose (f);
24 /* MAIN */
25 int main (int argc, char ** argv)
27 char * opt;
28 int n_files = 0;
29 DArray * d_opts;
30 int i;
32 sb_init ();
34 ENV->sb_cmd = sb_prname (argv[0]);
35 if (argc == 1 && !ENV->sb_cmd) {
36 usage ();
37 exit (0);
40 ENV->d_files = new EArray (128);
41 d_opts = new EArray (argc);
42 ENV->d_opts = d_opts;
43 for (i = 0; i < argc; i++)
44 d_opts->add (argv[i]);
46 for (i = 1; i < d_opts->get_size (); i++) {
47 opt = d_opts->get (i);
48 if (opt[0] != '-' && index (opt, '=')) {
49 setParam (opt);
50 continue;
53 if (opt[0] != '-') {
54 ENV->d_files->add (strdup (d_opts->get (i)));
55 continue;
58 if (! bob_options (d_opts, i))
59 continue;
61 if (! opts_kinds (d_opts, i))
62 continue;
64 if (d_opts->get (i)[0] == '-' && !validOption (d_opts->get(i))) {
65 fprintf (stderr, "unknown option : %s\n", d_opts->get (i));
66 exit (1);
69 modding_optparse (&i, 1);
70 } // for (i = 1; i < argc; i++)
72 n_files = ENV->d_files->get_size ();
73 for (i = 0; i < argc; i++)
74 modding_optparse (&i, 2);
76 if (NE (ENV->language, "C") && NE (ENV->language, "C++")) {
77 i = modding_start (ENV->sb_cmd);
78 exit (i);
81 if (SB_FLGET (SB_FLCPP))
82 ENV->d_kinds &= OT::Class | OT::Struct | OT::Function
83 | OT::Namespace | OT::Define;
85 switch (ENV->sb_cmd) {
86 case cmd_makectags:
87 make_ctags (ENV->d_files);
88 break;
89 case cmd_indent:
90 nogui_indent ();
91 break;
92 case cmd_cgrep:
93 cgrep::cgrep (ENV->d_files);
94 break;
95 case cmd_call_tags:
96 call_tags (ENV->d_files);
97 goto out;
98 case cmd_tags:
99 tags (ENV->d_files, NULL);
100 goto out;
103 if (ENV->sb_cmd == cmd_makectags ||
104 ENV->sb_cmd == cmd_indent ||
105 ENV->sb_cmd == cmd_cgrep) {
106 print_the_time (NULL);
107 exit (0);
110 for (i = 0; i < n_files; i++) {
111 switch (ENV->sb_cmd) {
112 case cmd_file:
113 flist_main (ENV->d_files->get (i));
114 break;
115 case cmd_the_tt:
116 THE_TT::the_tt_main (ENV->d_files->get(i));
117 break;
118 case cmd_give_structs:
119 got_structs (ENV->d_files->get (i));
120 break;
121 case cmd_kinds:
122 kindsFile (ENV->d_files->get(i), ENV->d_kinds);
123 break;
127 if (ENV->sb_cmd == cmd_file ||
128 ENV->sb_cmd == cmd_the_tt ||
129 ENV->sb_cmd == cmd_give_structs ||
130 ENV->sb_cmd == cmd_kinds)
131 goto out;
133 ENV->sb_cmd = ENV->sb_cmd;
135 if (ENV->sb_cmd == cmd_the_tt && !n_files) // THE_TT for stdin
136 THE_TT::the_tt_main ((char *) "-");
137 else if (ENV->sb_cmd == cmd_give_structs && !n_files) {
138 got_structs ((char *) "-");
139 print_the_time (NULL);
140 exit (0);
143 if ((ENV->sb_cmd == cmd_kinds || ENV->sb_cmd == cmd_file) && !n_files) {
144 char d_buf[1024];
146 while (fgets (d_buf, 1023, stdin)) {
147 chomp (d_buf);
148 switch (ENV->sb_cmd) {
149 case cmd_kinds:
150 kindsFile (d_buf, ENV->d_kinds);
151 break;
152 case cmd_file:
153 flist_main (d_buf);
154 break;
159 if (!SB_FLGET (SB_FLRTREE))
160 call_tree (ENV->d_files->get (0), 0);
161 else
162 reverse_calltree (ENV->d_files->get (0));
164 out:
165 print_the_time (NULL);
167 if (ENV->immune_list)
168 delete ENV->immune_list;
170 ENV->d_files->foreach (free);
171 delete ENV->d_files;
172 fflush (stdout);
174 return EXIT_SUCCESS;