-- init_compile_env
[silentbob2.git] / src / options.cxx
blob062d707ff48f1d46888ce3668277ec3ce045afaa
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
5 */
7 #include <head.h>
8 #include <wit.h>
9 #include <mod.h>
11 void dumpOptions ()
13 char * S;
14 ENV->listOptions->first ();
15 while ((S = ENV->listOptions->get ())) {
16 printf ("%s ", S);
17 ENV->listOptions->next ();
19 printf ("\n");
22 int bob_options (DArray * d_opts, int & i)
24 char * opt;
25 int argc;
27 if (! d_opts)
28 return -1;
30 opt = d_opts->get (i);
31 argc = d_opts->get_size ();
33 if (opt[0] != '-') {
34 ENV->d_files->add (strdup (opt));
35 return 0;
38 if (EQ (opt, "--help") || EQ (opt, "-h")) {
39 usage ();
40 exit (0);
43 if (EQ (opt, "-V") || EQ (opt, "--version")) {
44 printf ("Silent Bob 2.0\n");
45 exit (0);
48 if (EQ (opt, "--perl")) {
49 ENV->language = strdup ("Perl");
50 return 0;
53 if (EQ (opt, "--file")) {
54 ENV->sb_cmd = cmd_file;
55 return 0;
58 if (EQ (opt, "--files")) {
59 if (builtin_language ()) {
60 ENV->sb_cmd = cmd_files;
61 return 0;
63 return -1;
66 if (EQ (opt, "--the-tt")) {
67 ENV->sb_cmd = cmd_the_tt;
68 return 0;
71 if (EQ (opt, "--structs")) {
72 ENV->sb_cmd = cmd_give_structs;
73 return 0;
76 if (EQ (opt, "--indent")) {
77 ENV->sb_cmd = cmd_indent;
78 return 0;
81 if (EQ (opt, "--tags")) {
82 ENV->sb_cmd = cmd_tags;
83 return 0;
86 if (EQ (opt, "--make-ctags") ||
87 EQ (opt, "-c")) {
88 ENV->sb_cmd = cmd_makectags;
89 return 0;
92 if (EQ (opt, "--call-tags") ||
93 EQ (opt, "-ct")) {
94 SB_FLSET (SB_FLTAGSTYLE);
95 ENV->sb_cmd = cmd_call_tags;
96 return 0;
99 if (EQ (opt, "--cgrep")) {
100 if (++i >= d_opts->get_size ())
101 return 0;
103 ENV->sb_cmd = cmd_cgrep;
104 ENV->cgrep_exp = d_opts->get (i);
105 return 0;
108 if (EQ (opt, "--tags")) {
109 ENV->sb_cmd = cmd_tags;
110 return 0;
113 if (EQ (opt, "-i")) {
114 tags_interactive ();
115 exit (0);
118 if (EQ (opt, "--cfiles") ||
119 EQ (opt, "-f")) {
120 bob_cfiles ();
121 exit (0);
124 if (EQ (opt, "--time-test"))
125 Dtimer ();
127 if (EQ (opt, "--plugins-viewer")) {
128 plugins_viewer ();
129 exit (0);
132 if (EQ (opt, "--options")) {
133 dumpOptions ();
134 exit (0);
137 if (EQ (opt, "--verbose")) {
138 SB_FLSET (SB_FLVERBOSE);
139 return 0;
142 if (EQ (opt, "-u")) {
143 SB_FLSET (SB_FLRTREE);
144 return 0;
147 if (EQ (opt, "--linear") ||
148 EQ (opt, "-l")) {
149 SB_FLSET (SB_FLLINEAR);
150 return 0;
153 if (EQ (opt, "-C") && i < argc) {
154 ++i;
155 chdir (d_opts->get (i));
156 return 0;
159 if (EQ (opt, "--linux")) {
160 chdir ("/usr/src/linux");
161 return 0;
164 if (EQ (opt, "--debug")) {
165 SB_FLSET (SB_FLDEBUG);
166 return 0;
169 if (EQ (opt, "--simulate")) {
170 Dtimer ();
171 SB_FLSET (SB_FLSIMULATE);
172 return 0;
175 if (EQ (opt, "--no-links")) {
176 SB_FLSET (SB_FLNOLINKS);
177 return 0;
180 if (EQ (opt, "-a") || EQ (opt, "--all")) {
181 SB_FLSET (SB_FLALL);
182 return 0;
185 if (EQ (opt, "--test") || EQ (opt, "-t")) {
186 SB_FLSET (SB_FLTEST);
187 return 0;
190 if (EQ (opt, "--ctags-append")) {
191 SB_FLSET (SB_FLCTAGSAPPEND);
192 return 0;
195 if (EQ (opt, "-A")) {
196 if (++i >= argc)
197 return 0;
199 ENV->cgrep_A = atoi (d_opts->get (i));
200 return 0;
203 if (EQ (opt, "-B")) {
204 if (++i >= argc)
205 return 0;
207 ENV->cgrep_B = atoi (d_opts->get (i));
208 return 0;
211 if (EQ (opt, "-j")) {
212 if (++i >= argc)
213 return 0;
214 ENV->max_proc = atoi (d_opts->get (i));
215 return 0;
218 if (EQ (opt, "--tag-style") || EQ (opt, "-ts")) {
219 SB_FLSET (SB_FLTAGSTYLE);
220 return 0;
223 if (EQ (opt, "-L") && ((i+1) < argc)) {
224 ++i;
225 ENV->d_files->from_file (d_opts->get (i));
226 ENV->d_files->foreach ((Dfunc_t) chomp);
227 return 0;
230 if (EQ (opt, "--depth")) {
231 if (++i >= argc)
232 return 0;
234 ENV->d_depth = atoi (d_opts->get (i));
235 return 0;
238 if (EQ (opt, "-fn")) {
239 SB_FLSET (SB_FLFNAMES);
240 return 0;
243 if (EQ (opt, "--lang")) {
244 if (++i >= argc)
245 return 0;
247 ENV->language = strdup (d_opts->get (i));
248 if (EQ (ENV->language, "cpp") ||
249 EQ (ENV->language, "cxx") ||
250 EQ (ENV->language, "c++")) {
251 delete ENV->language;
252 ENV->language = strdup ("C++");
253 SB_FLSET (SB_FLCPP);
255 return 0;
258 if (EQ (opt, "--thread")) {
259 SB_FLSET (SB_FLTHREAD);
260 return 0;
263 return -1;