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 bool sentinel = false;
51 bool mem_stomp = false;
54 package Options options;
57 void process_option(char* opt_name, char* opt_value)
59 if (cstring.strcmp(opt_name, "verbose") == 0)
61 options.verbose = cstdlib.atoi(opt_value);
63 else if (cstring.strcmp(opt_name, "log_file") == 0)
65 cstring.strcpy(options.log_file.ptr, opt_value);
67 else if (cstring.strcmp(opt_name, "sentinel") == 0)
69 if (opt_value[0] == '\0')
70 options.sentinel = true;
72 options.sentinel = (cstdlib.atoi(opt_value) != 0);
74 else if (cstring.strcmp(opt_name, "mem_stomp") == 0)
76 if (opt_value[0] == '\0')
77 options.mem_stomp = true;
79 options.mem_stomp = (cstdlib.atoi(opt_value) != 0);
84 package void parse(char* opts_string)
86 char[MAX_OPT_LEN] opt_name;
87 char[MAX_OPT_LEN] opt_value;
88 char* curr = opt_name.ptr;
90 if (opts_string is null)
92 for (; *opts_string != '\0'; opts_string++)
94 char c = *opts_string;
102 switch (*opts_string)
106 process_option(opt_name.ptr, opt_value.ptr);
114 curr = opt_value.ptr;
122 if (i == MAX_OPT_LEN)
125 process_option(opt_name.ptr, opt_value.ptr);
132 assert (verbose == 0);
133 assert (log_file[0] == '\0');
134 assert (sentinel == false);
135 assert (mem_stomp == false);
137 parse("mem_stomp=1:verbose=2");
139 assert (verbose == 2);
140 assert (log_file[0] == '\0');
141 assert (sentinel == false);
142 assert (mem_stomp == true);
144 parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=0");
146 assert (verbose == 1);
147 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
148 assert (sentinel == true);
149 assert (mem_stomp == false);
153 assert (verbose == 1);
154 assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
155 assert (sentinel == true);
156 assert (mem_stomp == false);
161 // vim: set et sw=4 sts=4 :