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 bool cstr_eq(char* s1, char* s2)
61 return cstring.strcmp(s1, s2) == 0;
65 bool parse_bool(char* value)
69 return (cstdlib.atoi(value) != 0);
73 void process_option(char* opt_name, char* opt_value)
75 if (cstr_eq(opt_name, "verbose"))
76 options.verbose = cstdlib.atoi(opt_value);
77 else if (cstr_eq(opt_name, "log_file"))
78 cstring.strcpy(options.log_file.ptr, opt_value);
79 else if (cstr_eq(opt_name, "malloc_stats_file"))
80 cstring.strcpy(options.malloc_stats_file.ptr, opt_value);
81 else if (cstr_eq(opt_name, "collect_stats_file"))
82 cstring.strcpy(options.collect_stats_file.ptr, opt_value);
83 else if (cstr_eq(opt_name, "sentinel"))
84 options.sentinel = parse_bool(opt_value);
85 else if (cstr_eq(opt_name, "mem_stomp"))
86 options.mem_stomp = parse_bool(opt_value);
90 package void parse(char* opts_string)
92 char[MAX_OPT_LEN] opt_name;
93 char[MAX_OPT_LEN] opt_value;
94 char* curr = opt_name.ptr;
96 if (opts_string is null)
98 for (; *opts_string != '\0'; opts_string++)
100 char c = *opts_string;
101 if (i == MAX_OPT_LEN)
108 switch (*opts_string)
112 process_option(opt_name.ptr, opt_value.ptr);
120 curr = opt_value.ptr;
128 if (i == MAX_OPT_LEN)
131 process_option(opt_name.ptr, opt_value.ptr);
138 assert (verbose == 0);
139 assert (log_file[0] == '\0');
140 assert (sentinel == false);
141 assert (mem_stomp == false);
143 parse("mem_stomp=1:verbose=2");
145 assert (verbose == 2);
146 assert (log_file[0] == '\0');
147 assert (sentinel == false);
148 assert (mem_stomp == true);
150 parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=0");
152 assert (verbose == 1);
153 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
154 assert (sentinel == true);
155 assert (mem_stomp == false);
159 assert (verbose == 1);
160 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
161 assert (sentinel == true);
162 assert (mem_stomp == false);
167 // vim: set et sw=4 sts=4 :