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;
56 package Options options;
59 void process_option(char* opt_name, char* opt_value)
61 if (cstring.strcmp(opt_name, "verbose") == 0)
63 options.verbose = cstdlib.atoi(opt_value);
65 else if (cstring.strcmp(opt_name, "log_file") == 0)
67 cstring.strcpy(options.log_file.ptr, opt_value);
69 else if (cstring.strcmp(opt_name, "malloc_stats_file") == 0)
71 cstring.strcpy(options.malloc_stats_file.ptr, opt_value);
73 else if (cstring.strcmp(opt_name, "collect_stats_file") == 0)
75 cstring.strcpy(options.collect_stats_file.ptr, opt_value);
77 else if (cstring.strcmp(opt_name, "sentinel") == 0)
79 if (opt_value[0] == '\0')
80 options.sentinel = true;
82 options.sentinel = (cstdlib.atoi(opt_value) != 0);
84 else if (cstring.strcmp(opt_name, "mem_stomp") == 0)
86 if (opt_value[0] == '\0')
87 options.mem_stomp = true;
89 options.mem_stomp = (cstdlib.atoi(opt_value) != 0);
94 package void parse(char* opts_string)
96 char[MAX_OPT_LEN] opt_name;
97 char[MAX_OPT_LEN] opt_value;
98 char* curr = opt_name.ptr;
100 if (opts_string is null)
102 for (; *opts_string != '\0'; opts_string++)
104 char c = *opts_string;
105 if (i == MAX_OPT_LEN)
112 switch (*opts_string)
116 process_option(opt_name.ptr, opt_value.ptr);
124 curr = opt_value.ptr;
132 if (i == MAX_OPT_LEN)
135 process_option(opt_name.ptr, opt_value.ptr);
142 assert (verbose == 0);
143 assert (log_file[0] == '\0');
144 assert (sentinel == false);
145 assert (mem_stomp == false);
147 parse("mem_stomp=1:verbose=2");
149 assert (verbose == 2);
150 assert (log_file[0] == '\0');
151 assert (sentinel == false);
152 assert (mem_stomp == true);
154 parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=0");
156 assert (verbose == 1);
157 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
158 assert (sentinel == true);
159 assert (mem_stomp == false);
163 assert (verbose == 1);
164 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
165 assert (sentinel == true);
166 assert (mem_stomp == false);
171 // vim: set et sw=4 sts=4 :