Exemple #1
0
static GModule *ekg2_dlopen(const char *name) {
	/* RTLD_LAZY is bad flag, because code can SEGV on executing undefined symbols...
	 *	it's better to fail earlier than later with SIGSEGV
	 *
	 * RTLD_GLOBAL is bad flag also, because we have no need to export symbols to another plugns
	 *	we should do it by queries... Yeah, I know it was used for example in perl && irc plugin.
	 *	But we cannot do it. Because if we load irc before sim plugin. Than we'll have unresolved symbols
	 *	even if we load sim plugin later.
	 */
	/*
	 * RTLD_GLOBAL is required by perl and python plugins...
	 *	need investigation. [XXX]
	 */
	GModule *tmp = g_module_open(name, 0);

	if (!tmp) {
		char *errstr = ekg_recode_from_locale(g_module_error());
		debug_warn("[plugin] could not be loaded: %s %s\n", name, errstr);
		g_free(errstr);
	} else {
		debug_ok("[plugin] loaded: %s\n", name);
	}
	return tmp;
}
Exemple #2
0
/*
 * ui_readline_loop()
 *
 * g³ówna pêtla programu. wczytuje dane z klawiatury w miêdzyczasie
 * obs³uguj±c sieæ i takie tam.
 */
int ui_readline_loop(void)
{
	char *line = my_readline();
	char *rline = line; /* for freeing */
	gchar *out, *p;
	gint len;

	if (!line) {
		/* Ctrl-D handler */
		if (window_current->id == 0) {			/* debug window */
			window_switch(1);
		} else if (window_current->id == 1) {		/* status window */
			if (config_ctrld_quits)	{
				return 0;
			} else {
				printf("\n");
			}
		} else if (window_current->id > 1) {		/* query window */
			window_kill(window_current);
		}
		return 1;
	}

	len = strlen(line);
	if (G_LIKELY(len > 0)) {
		if (G_UNLIKELY(line[len - 1] == '\\')) {
			/* multi line handler */
			GString *s = g_string_new_len(line, len-1);
			
			free(line);

			no_prompt = 1;
			rl_bind_key(9, rl_insert);

			while ((line = my_readline())) {
				if (!strcmp(line, "."))
					break;
				g_string_append(s, line);
				g_string_append_len(s, "\r\n", 2); /* XXX */
				free(line);
			}

			rl_bind_key(9, rl_complete);
			no_prompt = 0;

			if (line) {
				g_string_free(s, TRUE);
				free(line);
				return 1;
			}

			line = g_string_free(s, FALSE);
		}
		
		/* if no empty line and we save duplicate lines, add it to history */
		if (config_history_savedups || !history_length || strcmp(line, history_get(history_length)->line))
			add_history(line);
	}

	pager_lines = 0;

	/* now we can definitely recode */
	out = ekg_recode_from_locale(line);
	if (G_LIKELY(line == rline))
		free(rline); /* allocd by readline */
	else
		g_free(line); /* allocd by us */

	/* omit leading whitespace */
	for (p = out; g_unichar_isspace(g_utf8_get_char(p)); p = g_utf8_next_char(p));
	if (*p || config_send_white_lines)
		command_exec(window_current->target, window_current->session, out, 0);

	pager_lines = -1;

	g_free(out);
	return 1;
}