+ Fixes
[opsoft.git] / silentbob / src / main.cxx
blob667181a20c0320b7b124e391af4fb1fc1fe8b57b
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 /* MAIN */
16 int main (int argc, char ** argv)
18 char * opt;
19 int n_files = 0;
20 DArray * d_opts;
21 int i;
23 sb_init ();
25 ENV->sb_cmd = sb_prname (argv[0]);
26 if (argc == 1 && !ENV->sb_cmd) {
27 usage ();
28 exit (0);
31 ENV->d_files = new EArray (128);
32 d_opts = new EArray (argc);
33 ENV->d_opts = d_opts;
34 for (i = 0; i < argc; i++)
35 d_opts->add (argv[i]);
37 for (i = 1; i < d_opts->get_size (); i++) {
38 opt = d_opts->get (i);
39 if (opt[0] != '-' && index (opt, '=')) {
40 setParam (opt);
41 continue;
44 if (opt[0] != '-') {
45 ENV->d_files->add (strdup (d_opts->get (i)));
46 continue;
49 if (! opts_funcs (d_opts, i))
50 continue;
52 if (! opts_settings (d_opts, i))
53 continue;
55 if (! opts_kinds (d_opts, i))
56 continue;
58 if (d_opts->get (i)[0] == '-' && !validOption (d_opts->get(i))) {
59 fprintf (stderr, "unknown option : %s\n", d_opts->get (i));
60 exit (1);
63 modding_optparse (&i, 1);
64 } // for (i = 1; i < argc; i++)
66 n_files = ENV->d_files->get_size ();
67 for (i = 0; i < argc; i++)
68 modding_optparse (&i, 2);
70 if (NE (ENV->language, "C") && NE (ENV->language, "C++")) {
71 i = modding_start (ENV->sb_cmd);
72 exit (i);
75 if (SB_FLGET (SB_FLCPP))
76 ENV->d_kinds &= OT::Class | OT::Struct | OT::Function
77 | OT::Namespace | OT::Define;
79 switch (ENV->sb_cmd) {
80 case cmd_makectags:
81 make_ctags (ENV->d_files);
82 break;
83 case cmd_indent:
84 nogui_indent ();
85 break;
86 case cmd_cgrep:
87 cgrep::cgrep (ENV->d_files);
88 break;
89 case cmd_call_tags:
90 call_tags (ENV->d_files);
91 goto out;
92 case cmd_tags:
93 tags (ENV->d_files, NULL);
94 goto out;
97 if (ENV->sb_cmd == cmd_makectags ||
98 ENV->sb_cmd == cmd_indent ||
99 ENV->sb_cmd == cmd_cgrep) {
100 print_the_time (NULL);
101 exit (0);
104 for (i = 0; i < n_files; i++) {
105 switch (ENV->sb_cmd) {
106 case cmd_file:
107 flist_main (ENV->d_files->get (i));
108 break;
109 case cmd_the_tt:
110 THE_TT::the_tt_main (ENV->d_files->get(i));
111 break;
112 case cmd_give_structs:
113 got_structs (ENV->d_files->get (i));
114 break;
115 case cmd_kinds:
116 kindsFile (ENV->d_files->get(i), ENV->d_kinds);
117 break;
121 if (ENV->sb_cmd == cmd_file ||
122 ENV->sb_cmd == cmd_the_tt ||
123 ENV->sb_cmd == cmd_give_structs ||
124 ENV->sb_cmd == cmd_kinds)
125 goto out;
128 ENV->sb_cmd = ENV->sb_cmd;
130 if (ENV->sb_cmd == cmd_the_tt && !n_files) // THE_TT for stdin
131 THE_TT::the_tt_main ((char *) "-");
132 else if (ENV->sb_cmd == cmd_give_structs && !n_files) {
133 got_structs ((char *) "-");
134 print_the_time (NULL);
135 exit (0);
138 if ((ENV->sb_cmd == cmd_kinds || ENV->sb_cmd == cmd_file) && !n_files) {
139 char d_buf[1024];
141 while (fgets (d_buf, 1023, stdin)) {
142 chomp (d_buf);
143 switch (ENV->sb_cmd) {
144 case cmd_kinds:
145 kindsFile (d_buf, ENV->d_kinds);
146 break;
147 case cmd_file:
148 flist_main (d_buf);
149 break;
154 if (!SB_FLGET (SB_FLRTREE))
155 call_tree (ENV->d_files->get (0), 0);
156 else
157 reverse_calltree (ENV->d_files->get (0));
159 out:
160 print_the_time (NULL);
162 if (ENV->immune_list)
163 delete ENV->immune_list;
165 ENV->d_files->foreach (free);
166 delete ENV->d_files;
167 fflush (stdout);
169 return EXIT_SUCCESS;