2 * This module contains the options managemente code of the garbage collector.
4 * Copyright: Copyright (C) 2010 Leandro Lucarella <http://www.llucax.com.ar/>
7 * License: Boost Software License - Version 1.0 - August 17th, 2003
9 * Permission is hereby granted, free of charge, to any person or organization
10 * obtaining a copy of the software and accompanying documentation covered by
11 * this license (the "Software") to use, reproduce, display, distribute,
12 * execute, and transmit the Software, and to prepare derivative works of the
13 * Software, and to permit third-parties to whom the Software is furnished to
14 * do so, all subject to the following:
16 * The copyright notices in the Software and this entire statement, including
17 * the above license grant, this restriction and the following disclaimer,
18 * must be included in all copies of the Software, in whole or in part, and
19 * all derivative works of the Software, unless such copies or derivative
20 * works are solely in the form of machine-executable object code generated by
21 * a source language processor.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
26 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
27 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 * DEALINGS IN THE SOFTWARE.
31 * Authors: Leandro Lucarella
34 module rt.gc.cdgc.opts;
36 import cstdlib = tango.stdc.stdlib;
37 import cstring = tango.stdc.string;
43 const MAX_OPT_LEN = 256;
49 char[MAX_OPT_LEN] log_file = "";
50 char[MAX_OPT_LEN] malloc_stats_file = "";
51 char[MAX_OPT_LEN] collect_stats_file = "";
52 bool sentinel = false;
53 bool mem_stomp = false;
54 bool conservative = false;
58 package Options options;
61 bool cstr_eq(char* s1, char* s2)
63 return cstring.strcmp(s1, s2) == 0;
67 bool parse_bool(char* value)
71 return (cstdlib.atoi(value) != 0);
75 void process_option(char* opt_name, char* opt_value)
77 if (cstr_eq(opt_name, "verbose"))
78 options.verbose = cstdlib.atoi(opt_value);
79 else if (cstr_eq(opt_name, "log_file"))
80 cstring.strcpy(options.log_file.ptr, opt_value);
81 else if (cstr_eq(opt_name, "malloc_stats_file"))
82 cstring.strcpy(options.malloc_stats_file.ptr, opt_value);
83 else if (cstr_eq(opt_name, "collect_stats_file"))
84 cstring.strcpy(options.collect_stats_file.ptr, opt_value);
85 else if (cstr_eq(opt_name, "sentinel"))
86 options.sentinel = parse_bool(opt_value);
87 else if (cstr_eq(opt_name, "mem_stomp"))
88 options.mem_stomp = parse_bool(opt_value);
89 else if (cstr_eq(opt_name, "conservative"))
90 options.conservative = parse_bool(opt_value);
91 else if (cstr_eq(opt_name, "no_fork"))
92 options.fork = !parse_bool(opt_value);
96 package void parse(char* opts_string)
98 char[MAX_OPT_LEN] opt_name;
100 char[MAX_OPT_LEN] opt_value;
102 char* curr = opt_name.ptr;
104 if (opts_string is null)
106 for (; *opts_string != '\0'; opts_string++)
108 char c = *opts_string;
109 if (i == MAX_OPT_LEN)
116 switch (*opts_string)
120 process_option(opt_name.ptr, opt_value.ptr);
128 curr = opt_value.ptr;
136 if (i == MAX_OPT_LEN)
139 process_option(opt_name.ptr, opt_value.ptr);
146 assert (verbose == 0);
147 assert (log_file[0] == '\0');
148 assert (sentinel == false);
149 assert (mem_stomp == false);
150 assert (conservative == false);
151 assert (fork == true);
155 assert (verbose == 0);
156 assert (log_file[0] == '\0');
157 assert (sentinel == false);
158 assert (mem_stomp == true);
159 assert (conservative == false);
160 assert (fork == true);
162 parse("mem_stomp=0:verbose=2:conservative:no_fork=10");
164 assert (verbose == 2);
165 assert (log_file[0] == '\0');
166 assert (sentinel == false);
167 assert (mem_stomp == false);
168 assert (conservative == true);
169 assert (fork == false);
171 parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=1");
173 assert (verbose == 1);
174 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
175 assert (sentinel == true);
176 assert (mem_stomp == true);
177 assert (conservative == true);
178 assert (fork == false);
182 assert (verbose == 1);
183 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
184 assert (sentinel == true);
185 assert (mem_stomp == true);
186 assert (conservative == true);
187 assert (fork == false);
191 assert (verbose == 1);
192 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
193 assert (sentinel == true);
194 assert (mem_stomp == true);
195 assert (conservative == true);
196 assert (fork == false);
200 assert (verbose == 1);
201 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
202 assert (sentinel == true);
203 assert (mem_stomp == true);
204 assert (conservative == true);
205 assert (fork == false);
209 assert (verbose == 1);
210 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
211 assert (sentinel == true);
212 assert (mem_stomp == true);
213 assert (conservative == true);
214 assert (fork == false);
219 // vim: set et sw=4 sts=4 :