Add very old versions (for history).
[opsoft_archive.git] / silentbob / silentbob-1.4.1 / src / main.cxx
blob60eb62ce0d156cd618251c7921bb9b62b41af7ff
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 #include <head.h>
8 #include <wit.h>
9 #include <base.h>
10 #include <the_tt.h>
11 #include <mod.h>
12 #include <dbg.h>
14 extern "C" struct env_t *ENV;
16 /* MAIN */
17 int main (int argc, char ** argv)
19 char * opt;
20 int n_files = 0;
21 DArray * d_opts;
22 int i;
24 sb_init ();
25 ENV->sb_cmd = sb_prname (argv[0]);
27 if (argc == 1 && !ENV->sb_cmd) {
28 usage ();
29 exit (0);
32 ENV->d_files = new EArray (128);
33 ENV->language = "C";
34 d_opts = new EArray (argc);
35 ENV->d_opts = d_opts;
36 for (i = 0; i < argc; i++)
37 d_opts->add (argv[i]);
39 for (i = 1; i < d_opts->get_size (); i++) {
40 opt = d_opts->get (i);
41 if (opt[0] != '-' && index (opt, '=')) {
42 setParam (opt);
43 continue;
46 if (opt[0] != '-') {
47 ENV->d_files->add (strdup (d_opts->get (i)));
48 continue;
51 if (! opts_funcs (d_opts, i))
52 continue;
54 if (! opts_settings (d_opts, i))
55 continue;
57 if (! opts_globals (d_opts, i))
58 continue;
60 if (modding_optparse (&i, 1))
61 continue;
63 /* if (d_opts->get (i)[0] == '-') {
64 fprintf (stderr, "unknown option : %s\n", d_opts->get (i));
65 exit (1);
66 }*/
67 } // for (i = 1; i < argc; i++)
69 n_files = ENV->d_files->get_size ();
71 for (i = 0; i < argc; i++)
72 modding_optparse (&i, 2);
74 if (NE (ENV->language, "C") && NE (ENV->language, "C++")) {
75 i = modding_start (ENV->sb_cmd);
76 exit (i);
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_globals:
116 bob_globals (ENV->d_files->get(i), ENV->d_global_type);
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_globals)
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 ("-");
132 else if (ENV->sb_cmd == cmd_give_structs && !n_files) {
133 got_structs ("-");
134 print_the_time (NULL);
135 exit (0);
138 if ((ENV->sb_cmd == cmd_globals || 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_globals:
145 bob_globals (d_buf, ENV->d_global_type);
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;