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;
57 package Options options;
60 bool cstr_eq(char* s1, char* s2)
62 return cstring.strcmp(s1, s2) == 0;
66 bool parse_bool(char* value)
70 return (cstdlib.atoi(value) != 0);
74 void process_option(char* opt_name, char* opt_value)
76 if (cstr_eq(opt_name, "verbose"))
77 options.verbose = cstdlib.atoi(opt_value);
78 else if (cstr_eq(opt_name, "log_file"))
79 cstring.strcpy(options.log_file.ptr, opt_value);
80 else if (cstr_eq(opt_name, "malloc_stats_file"))
81 cstring.strcpy(options.malloc_stats_file.ptr, opt_value);
82 else if (cstr_eq(opt_name, "collect_stats_file"))
83 cstring.strcpy(options.collect_stats_file.ptr, opt_value);
84 else if (cstr_eq(opt_name, "sentinel"))
85 options.sentinel = parse_bool(opt_value);
86 else if (cstr_eq(opt_name, "mem_stomp"))
87 options.mem_stomp = parse_bool(opt_value);
88 else if (cstr_eq(opt_name, "conservative"))
89 options.conservative = parse_bool(opt_value);
93 package void parse(char* opts_string)
95 char[MAX_OPT_LEN] opt_name;
97 char[MAX_OPT_LEN] opt_value;
99 char* curr = opt_name.ptr;
101 if (opts_string is null)
103 for (; *opts_string != '\0'; opts_string++)
105 char c = *opts_string;
106 if (i == MAX_OPT_LEN)
113 switch (*opts_string)
117 process_option(opt_name.ptr, opt_value.ptr);
125 curr = opt_value.ptr;
133 if (i == MAX_OPT_LEN)
136 process_option(opt_name.ptr, opt_value.ptr);
143 assert (verbose == 0);
144 assert (log_file[0] == '\0');
145 assert (sentinel == false);
146 assert (mem_stomp == false);
147 assert (conservative == false);
151 assert (verbose == 0);
152 assert (log_file[0] == '\0');
153 assert (sentinel == false);
154 assert (mem_stomp == true);
155 assert (conservative == false);
157 parse("mem_stomp=0:verbose=2:conservative");
159 assert (verbose == 2);
160 assert (log_file[0] == '\0');
161 assert (sentinel == false);
162 assert (mem_stomp == false);
163 assert (conservative == true);
165 parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=1");
167 assert (verbose == 1);
168 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
169 assert (sentinel == true);
170 assert (mem_stomp == true);
171 assert (conservative == true);
175 assert (verbose == 1);
176 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
177 assert (sentinel == true);
178 assert (mem_stomp == true);
179 assert (conservative == true);
184 // vim: set et sw=4 sts=4 :