Ejemplo n.º 1
0
gboolean xa_rpm_extract(XArchive *archive,GSList *files)
{
	gchar *command = NULL,*e_filename = NULL;
	GSList *list = NULL,*_files = NULL;
	GString *names = g_string_new("");
	gboolean result = FALSE;

	_files = files;
	while (_files)
	{
		e_filename  = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend (names,e_filename);
		g_string_prepend_c (names,' ');
		_files = _files->next;
	}
	g_slist_foreach(files,(GFunc)g_free,NULL);
	g_slist_free(files);
	
	chdir (archive->extraction_path);
	command = g_strconcat ( "sh -c \"cpio -id" , names->str," < ",archive->tmp,"/file.cpio\"",NULL);

	g_string_free(names,TRUE);
	list = g_slist_append(list,command);
	result = xa_run_command (archive,list);
	return result;
}
Ejemplo n.º 2
0
void xa_tar_delete (XArchive *archive,GSList *files)
{
	gchar *e_filename,*command = NULL;
	GSList *_files,*list = NULL;
	GString *names = g_string_new("");

	_files = files;
	while (_files)
	{
		e_filename  = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend (names,e_filename);
		g_string_prepend_c (names,' ');
		_files = _files->next;
	}
	g_slist_foreach(files,(GFunc)g_free,NULL);
	g_slist_free(files);

	if (is_tar_compressed(archive->type))
		xa_add_delete_bzip2_gzip_lzma_compressed_tar(names,archive,0);
	else
	{
		command = g_strconcat (tar, " --delete -vf ",archive->escaped_path," ",names->str,NULL);
		list = g_slist_append(list,command);
		xa_run_command (archive,list);
		if (archive->status == XA_ARCHIVESTATUS_DELETE)
			xa_reload_archive_content(archive);
	}
}
Ejemplo n.º 3
0
gboolean xa_deb_extract(XArchive *archive,GSList *files)
{
	gchar *command;
	GSList *list = NULL,*_files = NULL;
	GString *names = g_string_new("");
	gboolean result = FALSE;

	_files = files;
	while (_files)
	{
		g_string_prepend (names,(gchar*)_files->data);
		g_string_prepend_c (names,' ');
		_files = _files->next;
	}
	g_slist_foreach(files,(GFunc)g_free,NULL);
	g_slist_free(files);

	chdir (archive->extraction_path);
	command = g_strconcat ("ar x ",archive->escaped_path," ",names->str,NULL);
	if (command != NULL)
	{
		g_string_free(names,FALSE);
		list = g_slist_append(list,command);
		result = xa_run_command (archive,list);
	}
	return result;
}
Ejemplo n.º 4
0
void xa_7zip_delete (XArchive *archive,GSList *names)
{
	gchar *command,*exe,*e_filename = NULL;
	GSList *list = NULL,*_names;
	GString *files = g_string_new("");

	if (sevenzr)
		exe = "7zr d ";
	if (sevenza)
		exe = "7za d ";

 	_names = names;
 	while (_names)
	{
		e_filename  = xa_escape_filename((gchar*)_names->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend (files,e_filename);
		g_string_prepend_c (files,' ');
		_names = _names->next;
	}
	g_slist_foreach(names,(GFunc)g_free,NULL);
	g_slist_free(names);
	command = g_strconcat (exe,archive->escaped_path," ",files->str,NULL);
	g_string_free(files,TRUE);
	list = g_slist_append(list,command);

	xa_run_command (archive,list);
	if (archive->status == XA_ARCHIVESTATUS_DELETE)
		xa_reload_archive_content(archive);
}
Ejemplo n.º 5
0
/* return the aligned text */
static char *get_alignment(const char *text, int align, int flags, char pad)
{
	GString *str;
	char *ret;

	g_return_val_if_fail(text != NULL, NULL);

	str = g_string_new(text);

	/* cut */
	if ((flags & ALIGN_CUT) && align > 0 && str->len > align)
		g_string_truncate(str, align);

	/* add pad characters */
	while (str->len < align) {
		if (flags & ALIGN_RIGHT)
			g_string_prepend_c(str, pad);
		else
			g_string_append_c(str, pad);
	}

	ret = str->str;
        g_string_free(str, FALSE);
	return ret;
}
Ejemplo n.º 6
0
gboolean xa_7zip_extract(XArchive *archive,GSList *files)
{
	gchar *command,*e_filename = NULL;
	GSList *list = NULL,*_files = NULL;
	GString *names = g_string_new("");
	gboolean result = FALSE;

	_files = files;
	while (_files)
	{
		e_filename  = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend (names,e_filename);
		g_string_prepend_c (names,' ');
		_files = _files->next;
	}
	g_slist_foreach(_files,(GFunc)g_free,NULL);
	g_slist_free(_files);

	if (archive->passwd != NULL)
		command = g_strconcat ("7za " , archive->full_path ? "x" : "e",
								" -p",archive->passwd,
								archive->overwrite ? " -aoa" : " -aos",
								" -bd ",
								archive->escaped_path,names->str , " -o",archive->extraction_path,NULL);
	else
		command = g_strconcat ( "7za " , archive->full_path ? "x" : "e",
								archive->overwrite ? " -aoa" : " -aos",
								" -bd ",
								archive->escaped_path,names->str , " -o",archive->extraction_path,NULL);
	g_string_free(names,TRUE);
	list = g_slist_append(list,command);

	result = xa_run_command (archive,list);
	return result;
}
Ejemplo n.º 7
0
static char *
variable_completion_function (const char *text, int state, input_complete_t flags)
{
    static char **env_p;
    static unsigned int isbrace;
    static size_t varlen;
    const char *p = NULL;

    (void) flags;
    SHOW_C_CTX ("variable_completion_function");

    if (state == 0)
    {                           /* Initialization stuff */
        isbrace = (text[1] == '{') ? 1 : 0;
        varlen = strlen (text + 1 + isbrace);
        env_p = environ;
    }

    while (*env_p)
    {
        p = strchr (*env_p, '=');
        if (p && ((size_t) (p - *env_p) >= varlen) && !strncmp (text + 1 + isbrace, *env_p, varlen))
            break;
        env_p++;
    }

    if (*env_p == NULL)
        return NULL;

    {
        GString *temp;

        temp = g_string_new_len (*env_p, p - *env_p);

        if (isbrace != 0)
        {
            g_string_prepend_c (temp, '{');
            g_string_append_c (temp, '}');
        }
        g_string_prepend_c (temp, '$');

        env_p++;

        return g_string_free (temp, FALSE);
    }
}
int main (int argc, char **argv)
{
	RsvgDimensionData dimensions;
	RsvgHandle *logo_handle;
	cairo_surface_t *surface;
	GError *error = NULL;
	cairo_t *cr;
	cairo_status_t status;
	char *input, *size, *output;
	GString *layer;
	char *layer_name;
	int h, w;

	g_type_init ();

	input = argv[1];
	size = argv[2];
	layer = g_string_new (argv[3]);
	g_string_ascii_down (layer);
	g_string_prepend_c (layer, '#');
	output = argv[4];

	if (sscanf (size, "%dx%d", &w, &h) != 2) {
		g_warning ("Couldn't parse size '%s'", size);
		return 1;
	}

	logo_handle = rsvg_handle_new_from_file (input, &error);
	if (!logo_handle) {
		g_warning ("Couldn't open '%s': %s", input, error->message);
		g_error_free (error);
		return 1;
	}

	surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w, h);
	cr = cairo_create (surface);

	rsvg_handle_get_dimensions (logo_handle, &dimensions);
	cairo_scale (cr,
		     (double) w / dimensions.width,
		     (double) h / dimensions.height);

	layer_name = g_string_free (layer, FALSE);
	rsvg_handle_render_cairo_sub (logo_handle, cr, "#background");
//	rsvg_handle_render_cairo_sub (logo_handle, cr, "#base");
	rsvg_handle_render_cairo_sub (logo_handle, cr, layer_name);

	status = cairo_surface_write_to_png (surface, output);
	if (status != CAIRO_STATUS_SUCCESS) {
		g_warning ("Couldn't write output '%s': %s", output, cairo_status_to_string (status));
		return 1;
	}

	g_free (layer_name);
	cairo_destroy (cr);

	return 0;
}
Ejemplo n.º 9
0
static char *
pref_full_name(struct purple_pref *pref)
{
	GString *name;
	struct purple_pref *parent;

	if(!pref)
		return NULL;

	if(pref == &prefs)
		return g_strdup("/");

	name = g_string_new(pref->name);
	parent = pref->parent;

	for(parent = pref->parent; parent && parent->name; parent = parent->parent) {
		name = g_string_prepend_c(name, '/');
		name = g_string_prepend(name, parent->name);
	}
	name = g_string_prepend_c(name, '/');
	return g_string_free(name, FALSE);
}
Ejemplo n.º 10
0
Archivo: native.c Proyecto: Cobinja/cjs
static GjsNativeModule *
lookup_native_module(JSContext  *context,
                     JSObject   *parent,
                     const char *name,
                     gboolean    is_definition)
{
    GjsNativeModule *native_module;
    GString *module_id;

    module_id = g_string_new(name);
    while (parent != NULL) {
        char *name;
        jsval tmp;

        name = get_module_name(context, parent, &tmp);
        if (name != NULL) {
            g_string_prepend_c(module_id, '.');
            g_string_prepend(module_id, name);
            g_free(name);
        }

        /* Move up to parent */
        parent = module_get_parent(context, parent);
    }

    if (is_definition)
        gjs_debug(GJS_DEBUG_NATIVE,
                  "Defining native module '%s'",
                  module_id->str);

    if (modules != NULL)
        native_module = g_hash_table_lookup(modules, module_id->str);
    else
        native_module = NULL;

    if (native_module == NULL) {
        if (is_definition) {
            gjs_throw(context,
                      "No native module '%s' has registered itself",
                      module_id->str);
        }
        g_string_free(module_id, TRUE);
        return NULL;
    }

    g_string_free(module_id, TRUE);

    return native_module;
}
Ejemplo n.º 11
0
gboolean xa_extract_tar_without_directories (gchar *string,XArchive *archive,gchar *files_to_extract)
{
	gchar *command = NULL, *e_filename = NULL;
	GSList *list = NULL;
	GSList *files = NULL;
	GString *names = g_string_new("");
	gboolean result;

	result = xa_create_temp_directory (archive);
	if (!result)
		return FALSE;

	if (strlen(files_to_extract) == 0)
	{
		gtk_tree_model_foreach(GTK_TREE_MODEL(archive->liststore),(GtkTreeModelForeachFunc) xa_concat_filenames,&files);

		while (files)
		{
			e_filename = xa_escape_filename((gchar*)files->data,"$'`\"\\!?* ()[]&|:;<>#");
			g_string_prepend_c (names,' ');
			g_string_prepend (names,e_filename);
			files = files->next;
		}
		g_slist_foreach(files,(GFunc)g_free,NULL);
		g_slist_free(files);
		files_to_extract = names->str;
	}
	
	command = g_strconcat (string, archive->escaped_path,
										#ifdef __FreeBSD__
											archive->overwrite ? " " : " -k",
										#else
											archive->overwrite ? " --overwrite" : " --keep-old-files",
											" --no-wildcards ",
										#endif
										archive->tar_touch ? " --touch" : "",
										"-C ",archive->tmp," ",files_to_extract,NULL);
	list = g_slist_append(list,command);
	if (strstr(files_to_extract,"/") || strcmp(archive->tmp,archive->extraction_path) != 0)
	{
		archive->working_dir = g_strdup(archive->tmp);
		command = g_strconcat ("mv -f ",files_to_extract," ",archive->extraction_path,NULL);
		list = g_slist_append(list,command);
	}
	g_string_free(names,TRUE);
	return xa_run_command (archive,list);
}
Ejemplo n.º 12
0
gboolean xa_arj_extract(XArchive *archive,GSList *files)
{
	gchar *command,*e_filename = NULL;
	GSList *list	= NULL,*_files = NULL;
	GString *names  = g_string_new("");
	gboolean result = FALSE;

	_files = files;
	while (_files)
	{
		e_filename  = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend (names,e_filename);
		g_string_prepend_c (names,' ');
		_files = _files->next;
	}
	g_slist_foreach(_files,(GFunc)g_free,NULL);
	g_slist_free(_files);

	if (archive->passwd != NULL)
		command = g_strconcat ( "arj ",archive->full_path ? "x" : "e",
								" -g",archive->passwd,
								archive->overwrite ? "" : " -n" ,
								" -i " ,
								archive->freshen ? "-f " : "" ,
								archive->update ? "-u " : " ",
								"-y ",
								archive->escaped_path , " ",archive->extraction_path,names->str,NULL);
	else
	{
		if (unarj)
			command = g_strconcat ( "sh -c \"cd ", archive->extraction_path,
								" && unarj ", archive->full_path ? "x" : "e", " ",
								archive->escaped_path, "\"", NULL );
		else
			command = g_strconcat ( "arj ",archive->full_path ? "x" : "e",
								archive->overwrite ? "" : " -n" ,
								" -i " , archive->freshen ? "-f " : "",
								archive->update ? "-u " : " ",
								"-y ",
								archive->escaped_path , " ",archive->extraction_path,names->str,NULL);
	}
	g_string_free(names,TRUE);
	list = g_slist_append(list,command);

	result = xa_run_command (archive,list);
	return result;
}
Ejemplo n.º 13
0
Archivo: utilunix.c Proyecto: artzub/mc
char *
mc_build_filename (const char *first_element, ...)
{
    va_list args;
    const char *element = first_element;
    GString *path;
    char *ret;

    if (element == NULL)
        return NULL;

    path = g_string_new ("");
    va_start (args, first_element);

    do
    {
        char *tmp_element;
        size_t len;
        const char *start;

        tmp_element = g_strdup (element);

        element = va_arg (args, char *);

        canonicalize_pathname (tmp_element);
        len = strlen (tmp_element);
        start = (tmp_element[0] == PATH_SEP) ? tmp_element + 1 : tmp_element;

        g_string_append (path, start);
        if (tmp_element[len - 1] != PATH_SEP && element != NULL)
            g_string_append_c (path, PATH_SEP);

        g_free (tmp_element);
    }
    while (element != NULL);

    va_end (args);

    g_string_prepend_c (path, PATH_SEP);

    ret = g_string_free (path, FALSE);
    canonicalize_pathname (ret);

    return ret;
}
Ejemplo n.º 14
0
Archivo: glob.c Proyecto: CTU-OSP/mc
void
mc_search__cond_struct_new_init_glob (const char *charset, mc_search_t * lc_mc_search,
                                      mc_search_cond_t * mc_search_cond)
{
    GString *tmp;

    tmp = mc_search__glob_translate_to_regex (mc_search_cond->str);
    g_string_free (mc_search_cond->str, TRUE);

    if (lc_mc_search->is_entire_line)
    {
        g_string_prepend_c (tmp, '^');
        g_string_append_c (tmp, '$');
    }
    mc_search_cond->str = tmp;

    mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
}
Ejemplo n.º 15
0
/**
 * as_utils_dns_to_rdns:
 *
 * Create a reverse-DNS ID based on a preexisting URL.
 */
gchar*
as_utils_dns_to_rdns (const gchar *url, const gchar *suffix)
{
	g_autofree gchar *tmp = NULL;
	gchar *pos = NULL;
	GString *new_cid = NULL;
	g_auto(GStrv) parts = NULL;
	guint i;

	tmp = g_strstr_len (url, -1, "://");
	if (tmp == NULL)
		tmp = g_strdup (url);
	else
		tmp = g_strdup (tmp + 3);

	pos = g_strstr_len (tmp, -1, "/");
	if (pos != NULL)
		pos[0] = '\0';

	parts = g_strsplit (tmp, ".", -1);
	if (parts == NULL)
		return NULL;

	new_cid = g_string_new (suffix);
	for (i = 0; parts[i] != NULL; i++) {
		if (g_strcmp0 (parts[i], "www") != 0) {
			g_string_prepend_c (new_cid, '.');
			g_string_prepend (new_cid, parts[i]);
		}
	}

	if (suffix == NULL)
		g_string_truncate (new_cid, new_cid->len - 1);

	return g_string_free (new_cid, FALSE);
}
Ejemplo n.º 16
0
/**
 * gsf_outfile_open_pkg_relate:
 * @child: #GsfOutfileOpenPkg
 * @parent: #GsfOutfileOpenPkg
 * @type: target type
 *
 * Create a relationship between @child and @parent of @type.
 *
 * Returns: (transfer none): the relID which the caller does not own
 * 	but will live as long as @parent.
 **/
char const *
gsf_outfile_open_pkg_relate (GsfOutfileOpenPkg *child,
			     GsfOutfileOpenPkg *parent,
			     char const *type)
{
	GString *path;
	int up = -1;
	GsfOutfile *child_dir, *parent_dir;

	/* Calculate the path from @child to @parent */
	parent_dir = parent->is_dir ? GSF_OUTFILE (parent)
		: gsf_output_container (GSF_OUTPUT (parent));
	do {
		up++;
		child_dir  = GSF_OUTFILE (child);
		while (NULL != (child_dir = gsf_output_container (GSF_OUTPUT (child_dir))))
		       if (child_dir == parent_dir)
			       goto found; /* break out of both loops */
	} while (NULL != (parent_dir = gsf_output_container (GSF_OUTPUT (parent_dir))));

found:
	/* yes prepend is slow, this will never be preformance critical */
	path = g_string_new (gsf_output_name (GSF_OUTPUT (child)));
	child_dir  = GSF_OUTFILE (child);
	while (NULL != (child_dir = gsf_output_container (GSF_OUTPUT (child_dir))) &&
	       NULL != gsf_output_name (GSF_OUTPUT (child_dir)) &&
	       child_dir != parent_dir) {
		g_string_prepend_c (path, '/');
		g_string_prepend (path, gsf_output_name (GSF_OUTPUT (child_dir)));
	}
	while (up--)
		g_string_prepend (path, "../");

	return gsf_outfile_open_pkg_create_rel (parent,
		g_string_free (path, FALSE), type, FALSE);
}
Ejemplo n.º 17
0
int irc_cmd_ctcp(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
{
	/* we have defined args as args[0] is target and args[1] is ctcp command */
	char *buf;
	GString *string;

	/* check if we have args */
	if (!args || !args[0] || !args[1])
		return 0;

	/* TODO:strip newlines or send each line as separate ctcp or something
	 * actually, this shouldn't be done here but somewhere else since irc should support escaping newlines */

	string = g_string_new(args[1]);
	g_string_prepend_c (string,'\001');
	g_string_append_c (string,'\001');
	buf = irc_format(irc, "vn:", "PRIVMSG", args[0], string->str);
	g_string_free(string,TRUE);

	irc_send(irc, buf);
	g_free(buf);

	return 1;
}
Ejemplo n.º 18
0
gboolean xa_tar_extract(XArchive *archive,GSList *files)
{
	gchar *command,*e_filename = NULL;
	GSList *list = NULL,*_files = NULL;
	GString *names = g_string_new("");
	gboolean result = FALSE;

	_files = files;
	while (_files)
	{
		e_filename = xa_escape_filename((gchar*)_files->data,"$'`\"\\!?* ()[]&|:;<>#");
		g_string_prepend_c (names,' ');
		g_string_prepend (names,e_filename);
		_files = _files->next;
	}
	g_slist_foreach(files,(GFunc)g_free,NULL);
	g_slist_free(files);

	switch (archive->type)
	{
		case XARCHIVETYPE_TAR:
		if (archive->full_path)
		{
			command = g_strconcat (tar, " -xvf " , archive->escaped_path,
						#ifdef __FreeBSD__
								archive->overwrite ? " " : " -k",
						#else
								archive->overwrite ? " --overwrite" : " --keep-old-files",
						#endif
								archive->tar_touch ? " --touch" : "",
								" -C ",archive->extraction_path," ",names->str,NULL);
		}
		else
		{
			result = xa_extract_tar_without_directories ( "tar -xvf ",archive,names->str);
			command = NULL;
		}
		break;

		case XARCHIVETYPE_TAR_BZ2:
		if (archive->full_path)
		{
			command = g_strconcat (tar, " -xjvf " , archive->escaped_path,
						#ifdef __FreeBSD__
								archive->overwrite ? " " : " -k",
						#else
								archive->overwrite ? " --overwrite" : " --keep-old-files",
						#endif
								archive->tar_touch ? " --touch" : "",
								" -C ",archive->extraction_path," ",names->str,NULL);
		}
		else
		{
			result = xa_extract_tar_without_directories ( "tar -xjvf ",archive,names->str);
			command = NULL;
		}
		break;

		case XARCHIVETYPE_TAR_GZ:
		if (archive->full_path == 1)
		{
			command = g_strconcat (tar, " -xzvf " , archive->escaped_path,
						#ifdef __FreeBSD__
								archive->overwrite ? " " : " -k",
						#else
								archive->overwrite ? " --overwrite" : " --keep-old-files",
						#endif
								archive->tar_touch ? " --touch" : "",
								" -C ",archive->extraction_path," ",names->str,NULL);
		}
		else
		{
			result = xa_extract_tar_without_directories ( "tar -xzvf ",archive,names->str);
			command = NULL;
		}
		break;

		case XARCHIVETYPE_TAR_LZMA:
		if (archive->full_path == 1)
		{
			command = g_strconcat (tar, " --use-compress-program=lzma -xvf " , archive->escaped_path,
						#ifdef __FreeBSD__
								archive->overwrite ? " " : " -k",
						#else
								archive->overwrite ? " --overwrite" : " --keep-old-files",
						#endif
								archive->tar_touch ? " --touch" : "",
								" -C ",archive->extraction_path," ",names->str,NULL);
		}
		else
		{
			result = xa_extract_tar_without_directories ( "tar --use-compress-program=lzma -xvf ",archive,names->str);
			command = NULL;
		}
		break;

		case XARCHIVETYPE_TAR_LZOP:
		if (archive->full_path == 1)
		{
			command = g_strconcat (tar, " --use-compress-program=lzop -xvf " , archive->escaped_path,
						#ifdef __FreeBSD__
								archive->overwrite ? " " : " -k",
						#else
								archive->overwrite ? " --overwrite" : " --keep-old-files",
						#endif
								archive->tar_touch ? " --touch" : "",
								" -C ",archive->extraction_path," ",names->str,NULL);
		}
		else
		{
			result = xa_extract_tar_without_directories ( "tar --use-compress-program=lzop -xvf ",archive,names->str);
			command = NULL;
		}
		break;

		case XARCHIVETYPE_LZMA:
		result = lzma_bzip2_extract(archive,NULL);
		command = NULL;
		break;

		case XARCHIVETYPE_LZOP:
		result = lzma_bzip2_extract(archive,NULL);
		command = NULL;
		break;

		case XARCHIVETYPE_BZIP2:
		result = lzma_bzip2_extract(archive,NULL);
		command = NULL;
		break;

		case XARCHIVETYPE_GZIP:
		result = gzip_extract(archive,NULL);
		command = NULL;
		break;

		default:
		command = NULL;
	}
	if (command != NULL)
	{
		g_string_free(names,TRUE);
		list = g_slist_append(list,command);
		result = xa_run_command (archive,list);
	}
	return result;
}
Ejemplo n.º 19
0
static void
set_preview_widget (TablePreferences *tpref)
{
	GtkWidget *preview = NULL;
	GtkTreeIter iter;

	if (!tpref->priv->current_column)
		return;

	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (tpref->priv->plugins_combo), &iter)) {
		GdauiPlugin *plugin;
		GtkTreeModel *model;
		GType gtype;

		gtype = tpref->priv->current_column->gtype;
		
		model = tpref->priv->plugins_model;
		gtk_tree_model_get (model, &iter, PL_COLUMN_PLUGIN, &plugin, -1);
		if (plugin) {
			GString *string = NULL;
			if (tpref->priv->options_wid) {
				GdaSet *plist;
				GSList *list;
				
				plist = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM (tpref->priv->options_wid));
				for (list = plist->holders; list; list = list->next) {
					GdaHolder *holder;
					holder = GDA_HOLDER (list->data);
					if (gda_holder_is_valid (holder)) {
						const GValue *cvalue;
						cvalue = gda_holder_get_value (holder);
						if (cvalue && (G_VALUE_TYPE (cvalue) != GDA_TYPE_NULL)) {
							gchar *str = gda_value_stringify (cvalue);
							gchar *r1, *r2;
							if (!string)
								string = g_string_new ("");
							else
								g_string_append_c (string, ';');
							r1 = gda_rfc1738_encode (gda_holder_get_id (holder));
							r2 = gda_rfc1738_encode (str);
							g_free (str);
							g_string_append_printf (string, "%s=%s", r1, r2);
							g_free (r1);
							g_free (r2);
						}
					}
				}
			}
			if (string) {
				g_string_prepend_c (string, ':');
				g_string_prepend (string, plugin->plugin_name);
				preview = GTK_WIDGET (gdaui_new_data_entry (gtype, string->str));
				g_string_free (string, TRUE);
			}
			else
				preview = GTK_WIDGET (gdaui_new_data_entry (gtype, plugin->plugin_name));
		}
		else
			preview = GTK_WIDGET (gdaui_new_data_entry (gtype, NULL));
	}

	GValue *prev_value = NULL;
	if (tpref->priv->preview_wid) {
		prev_value = gdaui_data_entry_get_value (GDAUI_DATA_ENTRY (tpref->priv->preview_wid));
		gtk_widget_destroy (tpref->priv->preview_wid);
		gtk_widget_show (tpref->priv->preview_none);
		tpref->priv->preview_wid = NULL;
	}
	if (preview) {
		if (prev_value &&
		    (G_VALUE_TYPE (prev_value) == gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (preview))))
			gdaui_data_entry_set_value (GDAUI_DATA_ENTRY (preview), prev_value);
		gdaui_data_entry_set_attributes (GDAUI_DATA_ENTRY (preview),
						 0, GDA_VALUE_ATTR_ACTIONS_SHOWN);
		tpref->priv->preview_wid = preview;
		gtk_box_pack_start (GTK_BOX (tpref->priv->preview_vbox), preview, TRUE, TRUE, 0);
		gtk_widget_hide (tpref->priv->preview_none);
		gtk_widget_show (tpref->priv->preview_wid);
	}
	if (prev_value)
		gda_value_free (prev_value);
}
Ejemplo n.º 20
0
static void
get_mpi_flavors(GebrdMpiConfig *mpi_config, GString *mpi_flavors) {
	mpi_flavors = g_string_prepend_c(mpi_flavors, ',');
	mpi_flavors = g_string_prepend(mpi_flavors, mpi_config->name->str);
	g_debug("%s", mpi_config->name->str);
}
Ejemplo n.º 21
0
static void
read_config_file (const char *filename, gboolean enoent_error)
{
  FILE *file;
    
  GString *line_buffer;
  GString *tmp_buffer1;
  GString *tmp_buffer2;
  char *errstring = NULL;
  const char *pos;
  char *section = NULL;
  int line = 0;

  file = fopen (filename, "r");
  if (!file)
    {
      if (errno != ENOENT || enoent_error)
	fprintf (stderr, "Pangolite:%s: Error opening config file: %s\n",
		 filename, g_strerror (errno));
      return;
    }
  
  line_buffer = g_string_new (NULL);
  tmp_buffer1 = g_string_new (NULL);
  tmp_buffer2 = g_string_new (NULL);

  while (pangolite_read_line (file, line_buffer))
    {
      line++;

      pos = line_buffer->str;
      if (!pangolite_skip_space (&pos))
	continue;

      if (*pos == '[')	/* Section */
	{
	  pos++;
	  if (!pangolite_skip_space (&pos) ||
	      !pangolite_scan_word (&pos, tmp_buffer1) ||
	      !pangolite_skip_space (&pos) ||
	      *(pos++) != ']' ||
	      pangolite_skip_space (&pos))
	    {
	      errstring = g_strdup ("Error parsing [SECTION] declaration");
	      goto error;
	    }

	  section = g_strdup (tmp_buffer1->str);
	}
      else			/* Key */
	{
	  gboolean empty = FALSE;
	  gboolean append = FALSE;
	  char *k, *v;

	  if (!section)
	    {
	      errstring = g_strdup ("A [SECTION] declaration must occur first");
	      goto error;
	    }

	  if (!pangolite_scan_word (&pos, tmp_buffer1) ||
	      !pangolite_skip_space (&pos))
	    {
	      errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
	      goto error;
	    }
	  if (*pos == '+')
	    {
	      append = TRUE;
	      pos++;
	    }

	  if (*(pos++) != '=')
	    {
	      errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
	      goto error;
	    }
	    
	  if (!pangolite_skip_space (&pos))
	    {
	      empty = TRUE;
	    }
	  else
	    {
	      if (!pangolite_scan_string (&pos, tmp_buffer2))
		{
		  errstring = g_strdup ("Error parsing value string");
		  goto error;
		}
	      if (pangolite_skip_space (&pos))
		{
		  errstring = g_strdup ("Junk after value string");
		  goto error;
		}
	    }

	  g_string_prepend_c (tmp_buffer1, '/');
	  g_string_prepend (tmp_buffer1, section);

	  /* Remove any existing values */
	  if (g_hash_table_lookup_extended (config_hash, tmp_buffer1->str,
					    (gpointer *)&k, (gpointer *)&v))
	    {
	      g_free (k);
	      if (append)
		{
		  g_string_prepend (tmp_buffer2, v);
		  g_free (v);
		}
	    }
	      
	  if (!empty)
	    {
	      g_hash_table_insert (config_hash,
				   g_strdup (tmp_buffer1->str),
				   g_strdup (tmp_buffer2->str));
	    }
	}
    }
      
  if (ferror (file))
    errstring = g_strdup ("g_strerror(errno)");
  
 error:

  if (errstring)
    {
      fprintf (stderr, "Pangolite:%s:%d: %s\n", filename, line, errstring);
      g_free (errstring);
    }
      
  g_free (section);
  g_string_free (line_buffer, TRUE);
  g_string_free (tmp_buffer1, TRUE);
  g_string_free (tmp_buffer2, TRUE);

  fclose (file);
}
Ejemplo n.º 22
0
void
msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
{
    char *cur;
    GString *pre  = g_string_new(NULL);
    GString *post = g_string_new(NULL);
    unsigned int colors[3];

    if (pre_ret  != NULL) *pre_ret  = NULL;
    if (post_ret != NULL) *post_ret = NULL;

    cur = strstr(mime, "FN=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        pre = g_string_append(pre, "<FONT FACE=\"");

        while (*cur && *cur != ';')
        {
            pre = g_string_append_c(pre, *cur);
            cur++;
        }

        pre = g_string_append(pre, "\">");
        post = g_string_prepend(post, "</FONT>");
    }

    cur = strstr(mime, "EF=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        while (*cur && *cur != ';')
        {
            pre = g_string_append_c(pre, '<');
            pre = g_string_append_c(pre, *cur);
            pre = g_string_append_c(pre, '>');
            post = g_string_prepend_c(post, '>');
            post = g_string_prepend_c(post, *cur);
            post = g_string_prepend_c(post, '/');
            post = g_string_prepend_c(post, '<');
            cur++;
        }
    }

    cur = strstr(mime, "CO=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        int i;

        i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);

        if (i > 0)
        {
            char tag[64];

            if (i == 1)
            {
                colors[1] = 0;
                colors[2] = 0;
            }
            else if (i == 2)
            {
                unsigned int temp = colors[0];

                colors[0] = colors[1];
                colors[1] = temp;
                colors[2] = 0;
            }
            else if (i == 3)
            {
                unsigned int temp = colors[2];

                colors[2] = colors[0];
                colors[0] = temp;
            }

            g_snprintf(tag, sizeof(tag),
                       "<FONT COLOR=\"#%02x%02x%02x\">",
                       colors[0] & 0xFF, colors[1] & 0xFF,
                       colors[2] & 0xFF);

            pre = g_string_append(pre, tag);
            post = g_string_prepend(post, "</FONT>");
        }
    }

    cur = strstr(mime, "RL=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        if (*cur == '1')
        {
            /* RTL text was received */
            pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">");
            post = g_string_prepend(post, "</SPAN>");
        }
    }

    cur = g_strdup(purple_url_decode(pre->str));
    g_string_free(pre, TRUE);

    if (pre_ret != NULL)
        *pre_ret = cur;
    else
        g_free(cur);

    cur = g_strdup(purple_url_decode(post->str));
    g_string_free(post, TRUE);

    if (post_ret != NULL)
        *post_ret = cur;
    else
        g_free(cur);
}
Ejemplo n.º 23
0
void
msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
{
	char *cur;
	GString *pre  = g_string_new(NULL);
	GString *post = g_string_new(NULL);
	unsigned int colors[3];

	if (pre_ret  != NULL) *pre_ret  = NULL;
	if (post_ret != NULL) *post_ret = NULL;

	cur = strstr(mime, "FN=");

	if (cur && (*(cur = cur + 3) != ';'))
	{
		pre = g_string_append(pre, "<FONT FACE=\"");

		while (*cur && *cur != ';')
		{
			pre = g_string_append_c(pre, *cur);
			cur++;
		}

		pre = g_string_append(pre, "\">");
		post = g_string_prepend(post, "</FONT>");
	}

	cur = strstr(mime, "EF=");

	if (cur && (*(cur = cur + 3) != ';'))
	{
		while (*cur && *cur != ';')
		{
			pre = g_string_append_c(pre, '<');
			pre = g_string_append_c(pre, *cur);
			pre = g_string_append_c(pre, '>');
			post = g_string_prepend_c(post, '>');
			post = g_string_prepend_c(post, *cur);
			post = g_string_prepend_c(post, '/');
			post = g_string_prepend_c(post, '<');
			cur++;
		}
	}

	cur = strstr(mime, "CO=");

	if (cur && (*(cur = cur + 3) != ';'))
	{
		int i;

		i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);

		if (i > 0)
		{
			char tag[64];

			if (i == 1)
			{
				colors[1] = 0;
				colors[2] = 0;
			}
			else if (i == 2)
			{
				unsigned int temp = colors[0];

				colors[0] = colors[1];
				colors[1] = temp;
				colors[2] = 0;
			}
			else if (i == 3)
			{
				unsigned int temp = colors[2];

				colors[2] = colors[0];
				colors[0] = temp;
			}

			/* hh is undefined in mingw's gcc 4.4
			 *  https://sourceforge.net/tracker/index.php?func=detail&aid=2818436&group_id=2435&atid=102435
			 */
			g_snprintf(tag, sizeof(tag),
					   "<FONT COLOR=\"#%02x%02x%02x\">",
					   (unsigned char)colors[0], (unsigned char)colors[1], (unsigned char)colors[2]);

			pre = g_string_append(pre, tag);
			post = g_string_prepend(post, "</FONT>");
		}
	}

	cur = strstr(mime, "RL=");

	if (cur && (*(cur = cur + 3) != ';'))
	{
		if (*cur == '1')
		{
			/* RTL text was received */
			pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">");
			post = g_string_prepend(post, "</SPAN>");
		}
	}

	cur = sipmsg_uri_unescape(pre->str);
	g_string_free(pre, TRUE);

	if (pre_ret != NULL)
		*pre_ret = cur;
	else
		g_free(cur);

	cur = sipmsg_uri_unescape(post->str);
	g_string_free(post, TRUE);

	if (post_ret != NULL)
		*post_ret = cur;
	else
		g_free(cur);
}
static void gydp_ydp_parse_control(GydpYDPContext *context) {
	/* copy current position (after start of control code) */
	const gchar *rtf = ++context->rtf;

	/* clear previous control code */
	g_string_truncate(context->control, 0);

	/* check first character of control code */
	switch( *rtf ) {
	case '\\': /* it was escaped character */
	case '{':
	case '}':
		g_string_append_c(context->text, *(rtf++));
		return;
	default: /* read control code */
		for(gboolean is_control = TRUE; is_control; ++rtf)
			switch( *rtf ) {
			case ' ': ++rtf;                      /* omit, control code terminator */
			case '{':                             /* control code terminator */
			case '}':                             /* control code terminator */
			case '\\': is_control = FALSE; break; /* control code terminator */
			case 'a' ... 'z':                     /* control code letter */
			case 'A' ... 'Z':
			case '0' ... '9':                     /* control code parameter */
				g_string_append_c(context->control, *rtf); break;
			default:   is_control = FALSE; break; /* other symbol, terminator */
			}
		break;
	}

	/* empty control code */
	if( !context->control->len )
		return;

	/* extract numeric parameter */
	gint parameter = 0;

	{ /* extract numeric parameter form control code */
		const gssize last = context->control->len - 1;
		gchar *str = context->control->str;

		for(gssize pos = last, mul = 1; pos >= 0; --pos, mul *= 10)
			switch( str[pos] ) {
			case '0' ... '9':
				parameter += (str[pos] - '0') * mul;
				break;
			case '-':              /* negate parameter and break */
				g_string_truncate(context->control, pos);
				parameter *= -1;
				pos = 0;             /* set stop position */
				break;
			default:               /* found letter, complete control word and parameter */
				g_string_truncate(context->control, pos + 1);
				parameter = (pos == last)? 1: parameter;
				pos = 0;             /* set stop position */
				break;
			}
	}

	/* set context position */
	context->rtf = rtf - 1;

	/* extract current state */
	GydpYDPState *state = context->state->data;

	/* parse control code */
	const gchar *str = context->control->str;
	gboolean is_unknown = FALSE;

	switch( context->control->len ) {
	case 1:
		if( !strcmp(str, "b") ) {                      /* bold */
			if( parameter ) state->bold = TRUE;
			else            state->bold = FALSE;
		} else if( !strcmp(str, "i") ) {               /* italic */
			if( parameter ) state->italic = TRUE;
			else            state->italic = FALSE;
		} else if( !strcmp(str, "f") ) {               /* font */
			switch( parameter ) {
			case 0: state->phonetic = FALSE; break;
			case 1: state->phonetic = TRUE; break;
			case 2: state->phonetic = FALSE; break;
			}
		} else
			is_unknown = TRUE;
		break;
	case 2:
		if( !strcmp(str, "cf") ) {                    /* color foreground */
			switch( parameter ) {
			case 0: break;
			case 1: break;
			case 2: state->color = GYDP_YDP_COLOR_BLUE; break;
			case 4: break;
			}
		} else if( !strcmp(str, "cb") ) {             /* color background */
		} else if( !strcmp(str, "fi") ) {             /* first indent */
			state->indent = parameter;
		} else if( !strcmp(str, "li") ) {             /* left indent */
			state->margin_left = parameter;
		} else if( !strcmp(str, "ri") ) {             /* right indent */
			state->margin_right = parameter;
		} else if( !strcmp(str, "sa") ) {             /* space after */
			g_string_append_c(context->text, '\t');
		} else if( !strcmp(str, "sb") ) {             /* space before */
			g_string_prepend_c(context->text, '\t');
		} else if( !strcmp(str, "qc") ) {             /* center */
			state->align = GYDP_YDP_ALIGN_CENTER;
		} else
			is_unknown = TRUE;
		break;
	case 3:
		if( !strcmp(str, "par") ) {                    /* paragraph */
			g_string_append_c(context->text, '\n');
		} else
			is_unknown = TRUE;
		break;
	case 4:
		if( !strcmp(str, "pard") ) {                   /* reset paragraph */
			state->align = GYDP_YDP_ALIGN_NONE;
			state->indent = 0;
			state->margin_left = 0;
			state->margin_right = 0;
		} else if( !strcmp(str, "line") ) {            /* new line */
			g_string_append_c(context->text, '\n');
		} else
			is_unknown = TRUE;
		break;
	case 5:
		if( !strcmp(str, "super") ) {                  /* superscript */
			state->script = GYDP_YDP_SCRIPT_SUPER;
		} else
			is_unknown = TRUE;
		break;
	default:
		is_unknown = TRUE;
		break;
	}

	/* unknown control word, print */
	if( is_unknown ) {
		g_string_append_c(context->text, '\\');
		g_string_append(context->text, str);
	}
}
Ejemplo n.º 25
0
static void
server_api_status_callback (SoupServer * server, SoupMessage * msg, const char *path, GHashTable * query, SoupClientContext * client, gpointer user_data)
{
  (void) server;
  (void) path;
  (void) query;
  (void) client;
  (void) user_data;
  char *response = NULL;
  GPtrArray *r_array = NULL;
  GPtrArray *unr_array = NULL;
  GPtrArray *connected_sensors = NULL;
  GHashTable *hash;
  GString *st_sensors = NULL;
  GString *st_unrsensors = NULL;
  GString *st_csensors = NULL;
  gchar *per_session_stats = NULL;
  gchar *engine_stats = NULL;
  gchar *server_stats = NULL;
  GTimeVal current_time;
  SoupSocket *sock = NULL;
  SoupAddress *sockaddr = NULL;
  SoupURI *uri = NULL;
  guint i;
  /* Only get methods and no params */
  g_get_current_time (&current_time);
  if (msg->method != SOUP_METHOD_GET || query != NULL)
  {
    soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
    return;
  }
 /* Verificación anti listos */
  if ((sock = soup_client_context_get_socket (client)) == NULL) 
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }
  /* If host == 127.0.0.1 or host == localhost, verify that the localaddress == 127.0.0.1 */
  if ((uri = soup_message_get_uri (msg)) == NULL)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }
  if (strcmp (uri->host,"127.0.0.1") == 0 || strcmp (uri->host,"localhost") == 0)
  {
    if ((sockaddr = soup_socket_get_local_address (sock)) == NULL)
    {
      soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
      return;
    }
    else
    {
      /* Aquí hay un listo */
      if (strcmp ( soup_address_get_physical(sockaddr),"127.0.0.1") != 0)
      {
        soup_message_set_status (msg, SOUP_STATUS_UNAUTHORIZED);
        return;
      }
    }
  }

  if (server_api_get_info_sensors (&r_array, &unr_array, &hash) == FALSE)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }
/* Load the info of connected sensors */
  if (sim_server_get_sensor_uuids_unique (ossim.server, &connected_sensors) == FALSE)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }


  if ((st_sensors = g_string_new ("")) == NULL)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }
  if ((st_unrsensors = g_string_new ("")) == NULL)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }
  if ((st_csensors = g_string_new ("")) == NULL)
  {
    soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
    return;
  }


  /* For the register sensors */
  if (r_array->len > 0)
  {

    for (i = 0; i < r_array->len; i++)
    {
      g_string_append_printf (st_sensors, "\"%s\"", (gchar *) g_ptr_array_index (r_array, i));
      if ((i != (r_array->len - 1)))
      {
        g_string_append_c (st_sensors, ',');
      }
    }
    g_string_prepend_c (st_sensors, '[');
    g_string_append_c (st_sensors, ']');
  }
  else
  {
    g_string_printf (st_sensors, "[null]");
  }

  /* For the unregister sensors */
  if (unr_array->len > 0)
  {
    for (i = 0; i < unr_array->len; i++)
    {
      g_string_append_printf (st_unrsensors, "\"%s\"", (gchar *) g_ptr_array_index (unr_array, i));
      if ((i != (unr_array->len - 1)))
      {
        g_string_append_c (st_unrsensors, ',');
      }
    }
    g_string_prepend_c (st_unrsensors, '[');
    g_string_append_c (st_unrsensors, ']');
  }
  else
  {
    g_string_printf (st_unrsensors, "[null]");
  }
  /* The connected sensors */
  if (connected_sensors->len > 0)
  {
    int count = 0;
    for (i = 0; i < connected_sensors->len; i++)
    {
      char *av_uuid;
      if ((av_uuid = g_hash_table_lookup (hash, (gchar *) g_ptr_array_index (connected_sensors, i))) != NULL)
      {
        g_string_append_printf (st_csensors, "\"%s\"", av_uuid);
        count++;
        if ((i != (connected_sensors->len - 1)))
        {
          g_string_append_c (st_csensors, ',');
        }
      }
    }
    if (count > 0)
    {
      g_string_prepend_c (st_csensors, '[');
      g_string_append_c (st_csensors, ']');
    }
    else
    {
      g_string_printf (st_csensors, "[null]");

    }
  }
  else
  {
    g_string_printf (st_csensors, "[null]");
  }




  per_session_stats = sim_server_api_get_per_session_stats ();
  server_stats = server_api_get_server_stats (&current_time);
  engine_stats = server_api_get_engine_stats (&current_time);
  old_time.tv_sec = current_time.tv_sec;

response =
      g_strdup_printf ("{\"result\":{\"request\":\"/server/status\",\n\"timestamp\":\"%lld\",\n\"rsensors\":%s,\n\"unrsensors\":%s,\n\"csensors\":%s,\n\"engine_stats\":[%s],\n\"server_stats\":%s,\n\"per_session_stats\":%s\n},\n\"status\":\"OK\"\n}",
                       (long long) time (NULL),
                       st_sensors->str,
                       st_unrsensors->str,
                       st_csensors->str,
                       engine_stats,
                       server_stats,
                       per_session_stats
        );

  soup_message_set_response (msg, "application/json", SOUP_MEMORY_TAKE, response, strlen (response));
  soup_message_set_status (msg, SOUP_STATUS_OK);
  if (r_array != NULL)
    g_ptr_array_unref (r_array);
  if (unr_array != NULL)
    g_ptr_array_unref (unr_array);
  if (hash != NULL)
    g_hash_table_destroy (hash);
  if (st_sensors != NULL)
  {
    g_string_free (st_sensors, TRUE);
  }
  if (st_unrsensors != NULL)
  {
    g_string_free (st_unrsensors, TRUE);
  }
  if (st_csensors != NULL)
  {
    g_string_free (st_csensors, TRUE);
  }
  if (connected_sensors != NULL)
     g_ptr_array_unref (connected_sensors);
  g_free (per_session_stats);
  g_free (engine_stats);
  g_free (server_stats);
}
Ejemplo n.º 26
0
void gfire_join_game(const gfire_game_data *p_game_data)
{
	const gfire_game_configuration *gconf = gfire_game_config_by_id(p_game_data->id);
	if(!gconf)
	{
		purple_debug_error("gfire", "gfire_join_game: Game not configured!\n");
		return;
	}

	gchar *game_launch_command = gfire_game_config_get_command(gconf, p_game_data);
	if (!game_launch_command)
	{
		purple_debug_error("gfire", "gfire_join_game: Couldn't generate game launch command!\n");
		return;
	}

	GString *command = g_string_new(game_launch_command);
	g_free(game_launch_command);

	// Set environment if needed
	gchar **env = NULL;
	gint env_len = 0;
	if(gconf->launch_prefix)
	{
		gchar *prefix = NULL;
		GList *env_keys = NULL;
		GList *env_values = NULL;

		gfire_join_game_parse_prefix(gconf->launch_prefix, &prefix, &env_keys, &env_values);
		if(prefix)
		{
			g_string_prepend_c(command, ' ');
			g_string_prepend(command, prefix);
			g_free(prefix);
		}

		if(env_keys)
		{
			gchar **cur_env = g_listenv();
			gint i = 0;
			for(; i < g_strv_length(cur_env); i++)
			{
				env_len++;
				env = (gchar**)g_realloc(env, sizeof(gchar*) * (env_len + 1));
				env[env_len - 1] = g_strdup_printf("%s=%s", cur_env[i], g_getenv(cur_env[i]));
				env[env_len] = NULL;
			}

			GList *cur_key = env_keys;
			GList *cur_value = env_values;
			while(cur_key)
			{
				for(i = 0; i < g_strv_length(cur_env); i++)
				{
					if(g_strcmp0(cur_env[i], (gchar*)cur_key->data) == 0)
						break;
				}

				if(i == g_strv_length(cur_env))
				{
					env_len++;
					env = (gchar**)g_realloc(env, sizeof(gchar*) * (env_len + 1));
					env[env_len - 1] = g_strdup_printf("%s=%s", (gchar*)cur_key->data, (gchar*)cur_value->data);
					env[env_len] = NULL;
				}
				else
				{
					g_free(env[i]);
					env[i] = g_strdup_printf("%s=%s", (gchar*)cur_key->data, (gchar*)cur_value->data);
				}

				cur_key = g_list_next(cur_key);
				cur_value = g_list_next(cur_value);
			}

			g_strfreev(cur_env);

			gfire_list_clear(env_keys);
			gfire_list_clear(env_values);
		}
	}

	// Launch command
	gchar **argv = NULL;
	if(!g_shell_parse_argv(command->str, NULL, &argv, NULL))
	{
		purple_debug_error("gfire", "g_shell_parse_argv failed!");
		g_string_free(command, TRUE);
		g_strfreev(env);
		return;
	}

	purple_debug_misc("gfire", "Launching game and joining server: %s\n", command->str);
	g_string_free(command, TRUE);

	// Get working directory
	gchar *wd = g_path_get_dirname(argv[0]);

	// Launch
	g_spawn_async(wd, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
	g_free(wd);
	g_strfreev(argv);
	g_strfreev(env);
}
Ejemplo n.º 27
0
static void
prefs_start_element_handler (GMarkupParseContext *context,
		const gchar *element_name,
		const gchar **attribute_names,
		const gchar **attribute_values,
		gpointer user_data,
		GError **error)
{
	PurplePrefType pref_type = PURPLE_PREF_NONE;
	int i;
	const char *pref_name = NULL, *pref_value = NULL;
	GString *pref_name_full;
	GList *tmp;

	if(!purple_strequal(element_name, "pref") &&
	   !purple_strequal(element_name, "item"))
		return;

	for(i = 0; attribute_names[i]; i++) {
		if(purple_strequal(attribute_names[i], "name")) {
			pref_name = attribute_values[i];
		} else if(purple_strequal(attribute_names[i], "type")) {
			if(purple_strequal(attribute_values[i], "bool"))
				pref_type = PURPLE_PREF_BOOLEAN;
			else if(purple_strequal(attribute_values[i], "int"))
				pref_type = PURPLE_PREF_INT;
			else if(purple_strequal(attribute_values[i], "string"))
				pref_type = PURPLE_PREF_STRING;
			else if(purple_strequal(attribute_values[i], "stringlist"))
				pref_type = PURPLE_PREF_STRING_LIST;
			else if(purple_strequal(attribute_values[i], "path"))
				pref_type = PURPLE_PREF_PATH;
			else if(purple_strequal(attribute_values[i], "pathlist"))
				pref_type = PURPLE_PREF_PATH_LIST;
			else
				return;
		} else if(purple_strequal(attribute_names[i], "value")) {
			pref_value = attribute_values[i];
		}
	}

	if(purple_strequal(element_name, "item")) {
		struct purple_pref *pref;

		pref_name_full = g_string_new("");

		for(tmp = prefs_stack; tmp; tmp = tmp->next) {
			pref_name_full = g_string_prepend(pref_name_full, tmp->data);
			pref_name_full = g_string_prepend_c(pref_name_full, '/');
		}

		pref = find_pref(pref_name_full->str);

		if(pref) {
			if(pref->type == PURPLE_PREF_STRING_LIST) {
				pref->value.stringlist = g_list_append(pref->value.stringlist,
						g_strdup(pref_value));
			} else if(pref->type == PURPLE_PREF_PATH_LIST) {
				pref->value.stringlist = g_list_append(pref->value.stringlist,
						g_filename_from_utf8(pref_value, -1, NULL, NULL, NULL));
			}
		}
		g_string_free(pref_name_full, TRUE);
	} else {
		char *decoded;

		if(!pref_name || purple_strequal(pref_name, "/"))
			return;

		pref_name_full = g_string_new(pref_name);

		for(tmp = prefs_stack; tmp; tmp = tmp->next) {
			pref_name_full = g_string_prepend_c(pref_name_full, '/');
			pref_name_full = g_string_prepend(pref_name_full, tmp->data);
		}

		pref_name_full = g_string_prepend_c(pref_name_full, '/');

		switch(pref_type) {
			case PURPLE_PREF_NONE:
				purple_prefs_add_none(pref_name_full->str);
				break;
			case PURPLE_PREF_BOOLEAN:
				purple_prefs_set_bool(pref_name_full->str, atoi(pref_value));
				break;
			case PURPLE_PREF_INT:
				purple_prefs_set_int(pref_name_full->str, atoi(pref_value));
				break;
			case PURPLE_PREF_STRING:
				purple_prefs_set_string(pref_name_full->str, pref_value);
				break;
			case PURPLE_PREF_STRING_LIST:
				purple_prefs_set_string_list(pref_name_full->str, NULL);
				break;
			case PURPLE_PREF_PATH:
				if (pref_value) {
					decoded = g_filename_from_utf8(pref_value, -1, NULL, NULL, NULL);
					purple_prefs_set_path(pref_name_full->str, decoded);
					g_free(decoded);
				} else {
					purple_prefs_set_path(pref_name_full->str, NULL);
				}
				break;
			case PURPLE_PREF_PATH_LIST:
				purple_prefs_set_path_list(pref_name_full->str, NULL);
				break;
		}
		prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name));
		g_string_free(pref_name_full, TRUE);
	}
}