Beispiel #1
0
int get_opts(int argc, char *argv[], struct wldbg_options *opts)
{
	int n = 1;
	for (; n < argc; ++n) {
		/* separator */
		if (strcmp("--", argv[n]) == 0) {
			++n;
			break;
		}

		/* options */
		if (is_prefix_of("--", argv[n])) {
			if (!set_opt(argv[n] + 2, opts))
				return -1;
		} else if (is_prefix_of("-", argv[n])) {
			/* -g is a synonym for objinfo */
			if (argv[n][1] == 'g' && argv[n][2] == 0) {
				/* objinfo */
				set_opt("objinfo", opts);
				continue;
			}

			if (!set_opt(argv[n] + 1, opts))
				return -1;
		} else
			break;
	}

	dbg("Passes or programs are starting at %d\n", n);
	/* return how many options we have */
	return n;
}
Beispiel #2
0
/* Flush the entire registry to disk.  We rely on the fact that
   RegFlushKey() flushes an entire hive, which is arguably a bit of an
   implementation detail, but it is documented behaviour, so we should
   be okay. */
static void
flush_registry(void)
{
    HKEY hivelist_key;
    LONG err;
    DWORD idx;
    char value_name[16384];
    DWORD s;

    err = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                       HIVELIST_KEY,
                       0,
                       KEY_QUERY_VALUE,
                       &hivelist_key);
    if (err != ERROR_SUCCESS) {
        SetLastError(err);
        xs_win_err(1, &xs_render_error_msgbox,
                   "opening hive list in HKLM\\%s",
                   HIVELIST_KEY);
    }

    for (idx = 0; ; idx++) {
        s = ARRAYSIZE(value_name);
        err = RegEnumValue(hivelist_key,
                           idx,
                           value_name,
                           &s,
                           NULL,
                           NULL,
                           NULL,
                           NULL);
        if (err == ERROR_NO_MORE_ITEMS)
            break;
        if (err != ERROR_SUCCESS) {
            SetLastError(err);
            xs_win_err(1, &xs_render_error_msgbox,
                       "enumerating HKLM\\%s", HIVELIST_KEY);
        }

        if (is_prefix_of("\\REGISTRY\\MACHINE\\", value_name)) {
            flush_this_key(HKEY_LOCAL_MACHINE,
                           value_name + strlen("\\REGISTRY\\MACHINE\\"));
        } else if (is_prefix_of("\\REGISTRY\\USER\\", value_name)) {
            flush_this_key(HKEY_USERS,
                           value_name + strlen("\\REGISTRY\\USER\\"));
        } else {
            /* Don't know how to parse this registry hive.  Oh well,
             * just ignore it and hope for the best. */
            xs_win_err(1, &xs_render_error_msgbox,
                       "strange value %s", value_name);
        }
    }

    RegCloseKey(hivelist_key);
}
Beispiel #3
0
static bool is_trace_class_set_core(std::vector<name> const & cs, name const & n) {
    for (name const & p : cs) {
        if (is_prefix_of(p, n)) {
            return true;
        }
    }
    return false;
}
Container trim_token_left(const Container& token, const Container& xs)
{
    auto result = xs;
    while (is_prefix_of(token, result))
    {
        result = get_segment(size_of_cont(token), size_of_cont(result), result);
    }
    return result;
}
Beispiel #5
0
std::vector<name> get_namespace_completion_candidates(environment const & env) {
    std::vector<name> ret;
    scope_mng_ext const & ext = get_extension(env);
    ext.m_namespace_set.for_each([&](name const & ns) {
        ret.push_back(ns);
        for (auto const & open_ns : ext.m_namespaces)
            if (open_ns != ns && is_prefix_of(open_ns, ns))
                ret.push_back(ns.replace_prefix(open_ns, {}));
    });
    return ret;
}
Beispiel #6
0
static int
set_opt(const char *arg, struct wldbg_options *opts)
{
	int match = 0;

	if (*arg == '\0') {
		fprintf(stderr, "Error: empty option\n");
		return 0;
	}

	if (is_prefix_of(arg, "help")) {
		return 0;
	} else if (is_prefix_of(arg, "interactive")) {
		dbg("Command line option: interactive\n");
		opts->interactive = 1;
		match = 1;
	} else if (is_prefix_of(arg, "server-mode")) {
		dbg("Command line option: server-mode\n");
		opts->server_mode = 1;
		match = 1;
	} else if (is_prefix_of(arg, "pass-whole-buffer")) {
		dbg("Command line option: pass-whole-buffer\n");
		opts->pass_whole_buffer = 1;
		match = 1;
	} else if (is_prefix_of(arg, "objinfo")) {
		dbg("Command line option: objinfo\n");
		opts->objinfo = 1;
		match = 1;
	}

	if (!match) {
		fprintf(stderr, "Ignoring unknown option: %s\n", arg);
	}

	return 1;
}
Beispiel #7
0
scope_trace_env::scope_trace_env(environment const & env, io_state const & ios) {
    m_enable_sz  = get_enabled_trace_classes().size();
    m_disable_sz = get_disabled_trace_classes().size();
    m_old_env    = g_env;
    m_old_ios    = g_ios;
    g_env        = const_cast<environment*>(&env);
    g_ios        = const_cast<io_state*>(&ios);
    options const & opts = ios.get_options();
    name trace("trace");
    opts.for_each([&](name const & n) {
            if (is_prefix_of(trace, n)) {
                name cls        = n.replace_prefix(trace, name());
                if (opts.get_bool(n, false))
                    enable_trace_class(cls);
                else
                    disable_trace_class(cls);
            }
        });
}
Beispiel #8
0
Tag ascii_to_Tag(InputIterator pos, InputIterator end)
{
    if (pos == end) return Tag_0;
    switch (*pos++) {
        case 'a':
            if (pos == end) return TAG_a;
            switch (*pos++) {
                case 'b':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("br", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_abbr;
                case 'c':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ronym", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_acronym;
                case 'd':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("dress", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_address;
                case 'p':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("plet", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_applet;
                case 'r':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ea", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_area;
            }
            return Tag_0;
        case 'b':
            if (pos == end) return TAG_b;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("se", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_base;
                    if (!is_prefix_of("font", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_basefont;
                case 'd':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'o') return Tag_0;
                    if (pos == end) return TAG_bdo;
                case 'i':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'g') return Tag_0;
                    if (pos == end) return TAG_big;
                case 'l':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ockquote", pos, end)) return Tag_0;
                    std::advance(pos, 8);
                    if (pos == end) return TAG_blockquote;
                case 'o':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("dy", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_body;
                case 'r':
                    if (pos == end) return TAG_br;
                case 'u':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("tton", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_button;
            }
            return Tag_0;
        case 'c':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ption", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_caption;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("nter", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_center;
                case 'i':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("te", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_cite;
                case 'o':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'd':
                            if (pos == end) return Tag_0;
                            if (*pos++ != 'e') return Tag_0;
                            if (pos == end) return TAG_code;
                        case 'l':
                            if (pos == end) return TAG_col;
                            if (!is_prefix_of("group", pos, end)) return Tag_0;
                            std::advance(pos, 5);
                            if (pos == end) return TAG_colgroup;
                    }
                    return Tag_0;
            }
            return Tag_0;
        case 'd':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'd':
                    if (pos == end) return TAG_dd;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'l') return Tag_0;
                    if (pos == end) return TAG_del;
                case 'f':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'n') return Tag_0;
                    if (pos == end) return TAG_dfn;
                case 'i':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'r':
                            if (pos == end) return TAG_dir;
                        case 'v':
                            if (pos == end) return TAG_div;
                    }
                    return Tag_0;
                case 'l':
                    if (pos == end) return TAG_dl;
                case 't':
                    if (pos == end) return TAG_dt;
            }
            return Tag_0;
        case 'e':
            if (pos == end) return Tag_0;
            if (*pos++ != 'm') return Tag_0;
            if (pos == end) return TAG_em;
        case 'f':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'i':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("eldset", pos, end)) return Tag_0;
                    std::advance(pos, 6);
                    if (pos == end) return TAG_fieldset;
                case 'o':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'n':
                            if (pos == end) return Tag_0;
                            if (*pos++ != 't') return Tag_0;
                            if (pos == end) return TAG_font;
                        case 'r':
                            if (pos == end) return Tag_0;
                            if (*pos++ != 'm') return Tag_0;
                            if (pos == end) return TAG_form;
                    }
                    return Tag_0;
                case 'r':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ame", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_frame;
                    if (!is_prefix_of("set", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_frameset;
            }
            return Tag_0;
        case 'h':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case '1':
                    if (pos == end) return TAG_h1;
                case '2':
                    if (pos == end) return TAG_h2;
                case '3':
                    if (pos == end) return TAG_h3;
                case '4':
                    if (pos == end) return TAG_h4;
                case '5':
                    if (pos == end) return TAG_h5;
                case '6':
                    if (pos == end) return TAG_h6;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ad", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_head;
                case 'r':
                    if (pos == end) return TAG_hr;
                case 't':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ml", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_html;
            }
            return Tag_0;
        case 'i':
            if (pos == end) return TAG_i;
            switch (*pos++) {
                case 'f':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("rame", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_iframe;
                case 'm':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'g') return Tag_0;
                    if (pos == end) return TAG_img;
                case 'n':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'p':
                            if (pos == end) return Tag_0;
                            if (!is_prefix_of("ut", pos, end)) return Tag_0;
                            std::advance(pos, 2);
                            if (pos == end) return TAG_input;
                        case 's':
                            if (pos == end) return TAG_ins;
                    }
                    return Tag_0;
                case 's':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("index", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_isindex;
            }
            return Tag_0;
        case 'k':
            if (pos == end) return Tag_0;
            if (!is_prefix_of("bd", pos, end)) return Tag_0;
            std::advance(pos, 2);
            if (pos == end) return TAG_kbd;
        case 'l':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("bel", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_label;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("gend", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_legend;
                case 'i':
                    if (pos == end) return TAG_li;
                    if (!is_prefix_of("nk", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_link;
            }
            return Tag_0;
        case 'm':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'p') return Tag_0;
                    if (pos == end) return TAG_map;
                case 'e':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'n':
                            if (pos == end) return Tag_0;
                            if (*pos++ != 'u') return Tag_0;
                            if (pos == end) return TAG_menu;
                        case 't':
                            if (pos == end) return Tag_0;
                            if (*pos++ != 'a') return Tag_0;
                            if (pos == end) return TAG_meta;
                    }
                    return Tag_0;
            }
            return Tag_0;
        case 'n':
            if (pos == end) return Tag_0;
            if (*pos++ != 'o') return Tag_0;
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'f':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("rames", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_noframes;
                case 's':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("cript", pos, end)) return Tag_0;
                    std::advance(pos, 5);
                    if (pos == end) return TAG_noscript;
            }
            return Tag_0;
        case 'o':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'b':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ject", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_object;
                case 'l':
                    if (pos == end) return TAG_ol;
                case 'p':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 't') return Tag_0;
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'g':
                            if (pos == end) return Tag_0;
                            if (!is_prefix_of("roup", pos, end)) return Tag_0;
                            std::advance(pos, 4);
                            if (pos == end) return TAG_optgroup;
                        case 'i':
                            if (pos == end) return Tag_0;
                            if (!is_prefix_of("on", pos, end)) return Tag_0;
                            std::advance(pos, 2);
                            if (pos == end) return TAG_option;
                    }
                    return Tag_0;
            }
            return Tag_0;
        case 'p':
            if (pos == end) return TAG_p;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ram", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_param;
                case 'r':
                    if (pos == end) return Tag_0;
                    if (*pos++ != 'e') return Tag_0;
                    if (pos == end) return TAG_pre;
            }
            return Tag_0;
        case 'q':
            if (pos == end) return TAG_q;
        case 's':
            if (pos == end) return TAG_s;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("mp", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_samp;
                case 'c':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ript", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_script;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("lect", pos, end)) return Tag_0;
                    std::advance(pos, 4);
                    if (pos == end) return TAG_select;
                case 'm':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("all", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_small;
                case 'p':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("an", pos, end)) return Tag_0;
                    std::advance(pos, 2);
                    if (pos == end) return TAG_span;
                case 't':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'r':
                            if (pos == end) return Tag_0;
                            switch (*pos++) {
                                case 'i':
                                    if (pos == end) return Tag_0;
                                    if (!is_prefix_of("ke", pos, end)) return Tag_0;
                                    std::advance(pos, 2);
                                    if (pos == end) return TAG_strike;
                                case 'o':
                                    if (pos == end) return Tag_0;
                                    if (!is_prefix_of("ng", pos, end)) return Tag_0;
                                    std::advance(pos, 2);
                                    if (pos == end) return TAG_strong;
                            }
                            return Tag_0;
                        case 'y':
                            if (pos == end) return Tag_0;
                            if (!is_prefix_of("le", pos, end)) return Tag_0;
                            std::advance(pos, 2);
                            if (pos == end) return TAG_style;
                    }
                    return Tag_0;
                case 'u':
                    if (pos == end) return Tag_0;
                    switch (*pos++) {
                        case 'b':
                            if (pos == end) return TAG_sub;
                        case 'p':
                            if (pos == end) return TAG_sup;
                    }
                    return Tag_0;
            }
            return Tag_0;
        case 't':
            if (pos == end) return Tag_0;
            switch (*pos++) {
                case 'a':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ble", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_table;
                case 'b':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("ody", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_tbody;
                case 'd':
                    if (pos == end) return TAG_td;
                case 'e':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("xtarea", pos, end)) return Tag_0;
                    std::advance(pos, 6);
                    if (pos == end) return TAG_textarea;
                case 'f':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("oot", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_tfoot;
                case 'h':
                    if (pos == end) return TAG_th;
                    if (!is_prefix_of("ead", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_thead;
                case 'i':
                    if (pos == end) return Tag_0;
                    if (!is_prefix_of("tle", pos, end)) return Tag_0;
                    std::advance(pos, 3);
                    if (pos == end) return TAG_title;
                case 'r':
                    if (pos == end) return TAG_tr;
                case 't':
                    if (pos == end) return TAG_tt;
            }
            return Tag_0;
        case 'u':
            if (pos == end) return TAG_u;
            if (*pos++ != 'l') return Tag_0;
            if (pos == end) return TAG_ul;
        case 'v':
            if (pos == end) return Tag_0;
            if (!is_prefix_of("ar", pos, end)) return Tag_0;
            std::advance(pos, 2);
            if (pos == end) return TAG_var;
    }
    return Tag_0;
}