char[MAX_OPT_LEN] collect_stats_file = "";
bool sentinel = false;
bool mem_stomp = false;
+ bool conservative = false;
+ bool fork = true;
}
package Options options;
+bool cstr_eq(char* s1, char* s2)
+{
+ return cstring.strcmp(s1, s2) == 0;
+}
+
+
+bool parse_bool(char* value)
+{
+ if (value[0] == '\0')
+ return true;
+ return (cstdlib.atoi(value) != 0);
+}
+
+
void process_option(char* opt_name, char* opt_value)
{
- if (cstring.strcmp(opt_name, "verbose") == 0)
- {
+ if (cstr_eq(opt_name, "verbose"))
options.verbose = cstdlib.atoi(opt_value);
- }
- else if (cstring.strcmp(opt_name, "log_file") == 0)
- {
+ else if (cstr_eq(opt_name, "log_file"))
cstring.strcpy(options.log_file.ptr, opt_value);
- }
- else if (cstring.strcmp(opt_name, "malloc_stats_file") == 0)
- {
+ else if (cstr_eq(opt_name, "malloc_stats_file"))
cstring.strcpy(options.malloc_stats_file.ptr, opt_value);
- }
- else if (cstring.strcmp(opt_name, "collect_stats_file") == 0)
- {
+ else if (cstr_eq(opt_name, "collect_stats_file"))
cstring.strcpy(options.collect_stats_file.ptr, opt_value);
- }
- else if (cstring.strcmp(opt_name, "sentinel") == 0)
- {
- if (opt_value[0] == '\0')
- options.sentinel = true;
- else
- options.sentinel = (cstdlib.atoi(opt_value) != 0);
- }
- else if (cstring.strcmp(opt_name, "mem_stomp") == 0)
- {
- if (opt_value[0] == '\0')
- options.mem_stomp = true;
- else
- options.mem_stomp = (cstdlib.atoi(opt_value) != 0);
- }
+ else if (cstr_eq(opt_name, "sentinel"))
+ options.sentinel = parse_bool(opt_value);
+ else if (cstr_eq(opt_name, "mem_stomp"))
+ options.mem_stomp = parse_bool(opt_value);
+ else if (cstr_eq(opt_name, "conservative"))
+ options.conservative = parse_bool(opt_value);
+ else if (cstr_eq(opt_name, "no_fork"))
+ options.fork = !parse_bool(opt_value);
}
package void parse(char* opts_string)
{
char[MAX_OPT_LEN] opt_name;
+ opt_name[0] = '\0';
char[MAX_OPT_LEN] opt_value;
+ opt_value[0] = '\0';
char* curr = opt_name.ptr;
size_t i = 0;
if (opts_string is null)
assert (log_file[0] == '\0');
assert (sentinel == false);
assert (mem_stomp == false);
+ assert (conservative == false);
+ assert (fork == true);
}
- parse("mem_stomp=1:verbose=2");
+ parse("mem_stomp");
with (options) {
- assert (verbose == 2);
+ assert (verbose == 0);
assert (log_file[0] == '\0');
assert (sentinel == false);
assert (mem_stomp == true);
+ assert (conservative == false);
+ assert (fork == true);
+ }
+ parse("mem_stomp=0:verbose=2:conservative:no_fork=10");
+ with (options) {
+ assert (verbose == 2);
+ assert (log_file[0] == '\0');
+ assert (sentinel == false);
+ assert (mem_stomp == false);
+ assert (conservative == true);
+ assert (fork == false);
}
- parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=0");
+ parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=1");
with (options) {
assert (verbose == 1);
assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
assert (sentinel == true);
- assert (mem_stomp == false);
+ assert (mem_stomp == true);
+ assert (conservative == true);
+ assert (fork == false);
}
parse(null);
with (options) {
assert (verbose == 1);
assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
assert (sentinel == true);
- assert (mem_stomp == false);
+ assert (mem_stomp == true);
+ assert (conservative == true);
+ assert (fork == false);
+ }
+ parse("");
+ with (options) {
+ assert (verbose == 1);
+ assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
+ assert (sentinel == true);
+ assert (mem_stomp == true);
+ assert (conservative == true);
+ assert (fork == false);
+ }
+ parse(":");
+ with (options) {
+ assert (verbose == 1);
+ assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
+ assert (sentinel == true);
+ assert (mem_stomp == true);
+ assert (conservative == true);
+ assert (fork == false);
+ }
+ parse("::::");
+ with (options) {
+ assert (verbose == 1);
+ assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0);
+ assert (sentinel == true);
+ assert (mem_stomp == true);
+ assert (conservative == true);
+ assert (fork == false);
}
}