/* dconf-dump.c generated by valac 0.37.1, the Vala compiler
 * generated from dconf-dump.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <dconf.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _dconf_changeset_unref0(var) ((var == NULL) ? NULL : (var = (dconf_changeset_unref (var), NULL)))



void add_to_keyfile (GKeyFile* kf, DConfClient* client, const gchar* topdir, const gchar* rel);
void dconf_dump (gchar** args, int args_length1, GError** error);
GKeyFile* keyfile_from_stdin (GError** error);
void dconf_load (gchar** args, int args_length1, GError** error);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static gchar* string_slice (const gchar* self, glong start, glong end) {
	gchar* result = NULL;
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	glong _tmp2_;
	glong _tmp5_;
	gboolean _tmp8_ = FALSE;
	glong _tmp9_;
	gboolean _tmp12_ = FALSE;
	glong _tmp13_;
	glong _tmp16_;
	glong _tmp17_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	gchar* _tmp21_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	_tmp2_ = start;
	if (_tmp2_ < ((glong) 0)) {
		glong _tmp3_;
		glong _tmp4_;
		_tmp3_ = string_length;
		_tmp4_ = start;
		start = _tmp3_ + _tmp4_;
	}
	_tmp5_ = end;
	if (_tmp5_ < ((glong) 0)) {
		glong _tmp6_;
		glong _tmp7_;
		_tmp6_ = string_length;
		_tmp7_ = end;
		end = _tmp6_ + _tmp7_;
	}
	_tmp9_ = start;
	if (_tmp9_ >= ((glong) 0)) {
		glong _tmp10_;
		glong _tmp11_;
		_tmp10_ = start;
		_tmp11_ = string_length;
		_tmp8_ = _tmp10_ <= _tmp11_;
	} else {
		_tmp8_ = FALSE;
	}
	g_return_val_if_fail (_tmp8_, NULL);
	_tmp13_ = end;
	if (_tmp13_ >= ((glong) 0)) {
		glong _tmp14_;
		glong _tmp15_;
		_tmp14_ = end;
		_tmp15_ = string_length;
		_tmp12_ = _tmp14_ <= _tmp15_;
	} else {
		_tmp12_ = FALSE;
	}
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp16_ = start;
	_tmp17_ = end;
	g_return_val_if_fail (_tmp16_ <= _tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	_tmp20_ = start;
	_tmp21_ = g_strndup (((gchar*) self) + _tmp18_, (gsize) (_tmp19_ - _tmp20_));
	result = _tmp21_;
	return result;
}


void add_to_keyfile (GKeyFile* kf, DConfClient* client, const gchar* topdir, const gchar* rel) {
	gchar* this_dir = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* this_group = NULL;
	const gchar* _tmp3_;
	DConfClient* _tmp7_;
	const gchar* _tmp8_;
	gint _tmp9_;
	gchar** _tmp10_;
	g_return_if_fail (kf != NULL);
	g_return_if_fail (client != NULL);
	g_return_if_fail (topdir != NULL);
	_tmp0_ = topdir;
	_tmp1_ = rel;
	_tmp2_ = g_strconcat (_tmp0_, _tmp1_, NULL);
	this_dir = _tmp2_;
	_tmp3_ = rel;
	if (g_strcmp0 (_tmp3_, "") != 0) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = rel;
		_tmp5_ = string_slice (_tmp4_, (glong) 0, (glong) -1);
		_g_free0 (this_group);
		this_group = _tmp5_;
	} else {
		gchar* _tmp6_;
		_tmp6_ = g_strdup ("/");
		_g_free0 (this_group);
		this_group = _tmp6_;
	}
	_tmp7_ = client;
	_tmp8_ = this_dir;
	_tmp10_ = dconf_client_list (_tmp7_, _tmp8_, &_tmp9_);
	{
		gchar** item_collection = NULL;
		gint item_collection_length1 = 0;
		gint _item_collection_size_ = 0;
		gint item_it = 0;
		item_collection = _tmp10_;
		item_collection_length1 = _tmp9_;
		for (item_it = 0; item_it < _tmp9_; item_it = item_it + 1) {
			gchar* _tmp11_;
			gchar* item = NULL;
			_tmp11_ = g_strdup (item_collection[item_it]);
			item = _tmp11_;
			{
				const gchar* _tmp12_;
				gboolean _tmp13_;
				_tmp12_ = item;
				_tmp13_ = g_str_has_suffix (_tmp12_, "/");
				if (_tmp13_) {
					GKeyFile* _tmp14_;
					DConfClient* _tmp15_;
					const gchar* _tmp16_;
					const gchar* _tmp17_;
					const gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					_tmp14_ = kf;
					_tmp15_ = client;
					_tmp16_ = topdir;
					_tmp17_ = rel;
					_tmp18_ = item;
					_tmp19_ = g_strconcat (_tmp17_, _tmp18_, NULL);
					_tmp20_ = _tmp19_;
					add_to_keyfile (_tmp14_, _tmp15_, _tmp16_, _tmp20_);
					_g_free0 (_tmp20_);
				} else {
					GVariant* val = NULL;
					DConfClient* _tmp21_;
					const gchar* _tmp22_;
					const gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					GVariant* _tmp26_;
					GVariant* _tmp27_;
					GVariant* _tmp28_;
					_tmp21_ = client;
					_tmp22_ = this_dir;
					_tmp23_ = item;
					_tmp24_ = g_strconcat (_tmp22_, _tmp23_, NULL);
					_tmp25_ = _tmp24_;
					_tmp26_ = dconf_client_read (_tmp21_, _tmp25_);
					_tmp27_ = _tmp26_;
					_g_free0 (_tmp25_);
					val = _tmp27_;
					_tmp28_ = val;
					if (_tmp28_ != NULL) {
						GKeyFile* _tmp29_;
						const gchar* _tmp30_;
						const gchar* _tmp31_;
						GVariant* _tmp32_;
						gchar* _tmp33_;
						gchar* _tmp34_;
						_tmp29_ = kf;
						_tmp30_ = this_group;
						_tmp31_ = item;
						_tmp32_ = val;
						_tmp33_ = g_variant_print (_tmp32_, TRUE);
						_tmp34_ = _tmp33_;
						g_key_file_set_value (_tmp29_, _tmp30_, _tmp31_, _tmp34_);
						_g_free0 (_tmp34_);
					}
					_g_variant_unref0 (val);
				}
				_g_free0 (item);
			}
		}
		item_collection = (_vala_array_free (item_collection, item_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_g_free0 (this_group);
	_g_free0 (this_dir);
}


void dconf_dump (gchar** args, int args_length1, GError** error) {
	DConfClient* client = NULL;
	DConfClient* _tmp0_;
	GKeyFile* kf = NULL;
	GKeyFile* _tmp1_;
	gchar* dir = NULL;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	_tmp0_ = dconf_client_new ();
	client = _tmp0_;
	_tmp1_ = g_key_file_new ();
	kf = _tmp1_;
	_tmp2_ = args;
	_tmp2__length1 = args_length1;
	_tmp3_ = _tmp2_[2];
	_tmp4_ = g_strdup (_tmp3_);
	dir = _tmp4_;
	dconf_is_dir (dir, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (dir);
		_g_key_file_unref0 (kf);
		_g_object_unref0 (client);
		return;
	}
	add_to_keyfile (kf, client, dir, "");
	_tmp5_ = g_key_file_to_data (kf, NULL, NULL);
	_tmp6_ = _tmp5_;
	g_print ("%s", _tmp6_);
	_g_free0 (_tmp6_);
	_g_free0 (dir);
	_g_key_file_unref0 (kf);
	_g_object_unref0 (client);
}


GKeyFile* keyfile_from_stdin (GError** error) {
	GKeyFile* result = NULL;
	const gchar* tmp = NULL;
	gchar buffer[1024] = {0};
	GString* s = NULL;
	GString* _tmp0_;
	GKeyFile* kf = NULL;
	GKeyFile* _tmp6_;
	GString* _tmp7_;
	const gchar* _tmp8_;
	GString* _tmp9_;
	gssize _tmp10_;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_string_new ("");
	s = _tmp0_;
	while (TRUE) {
		FILE* _tmp1_;
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		GString* _tmp4_;
		const gchar* _tmp5_;
		_tmp1_ = stdin;
		_tmp2_ = fgets (buffer, 1024, _tmp1_);
		tmp = _tmp2_;
		_tmp3_ = tmp;
		if (!(_tmp3_ != NULL)) {
			break;
		}
		_tmp4_ = s;
		_tmp5_ = tmp;
		g_string_append (_tmp4_, _tmp5_);
	}
	_tmp6_ = g_key_file_new ();
	kf = _tmp6_;
	_tmp7_ = s;
	_tmp8_ = _tmp7_->str;
	_tmp9_ = s;
	_tmp10_ = _tmp9_->len;
	g_key_file_load_from_data (kf, _tmp8_, (gsize) _tmp10_, 0, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_key_file_unref0 (kf);
		_g_string_free0 (s);
		return NULL;
	}
	result = kf;
	_g_string_free0 (s);
	return result;
}


void dconf_load (gchar** args, int args_length1, GError** error) {
	gchar* dir = NULL;
	gchar** _tmp0_;
	gint _tmp0__length1;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	DConfChangeset* changeset = NULL;
	DConfChangeset* _tmp4_;
	GKeyFile* kf = NULL;
	GKeyFile* _tmp5_;
	GKeyFile* _tmp6_;
	gsize _tmp7_;
	gchar** _tmp8_;
	DConfClient* client = NULL;
	DConfClient* _tmp38_;
	DConfClient* _tmp39_;
	DConfChangeset* _tmp40_;
	GError * _inner_error_ = NULL;
	_tmp0_ = args;
	_tmp0__length1 = args_length1;
	_tmp1_ = _tmp0_[2];
	_tmp2_ = g_strdup (_tmp1_);
	dir = _tmp2_;
	_tmp3_ = dir;
	dconf_is_dir (_tmp3_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (dir);
		return;
	}
	_tmp4_ = dconf_changeset_new ();
	changeset = _tmp4_;
	_tmp5_ = keyfile_from_stdin (&_inner_error_);
	kf = _tmp5_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_dconf_changeset_unref0 (changeset);
		_g_free0 (dir);
		return;
	}
	_tmp6_ = kf;
	_tmp8_ = g_key_file_get_groups (_tmp6_, &_tmp7_);
	{
		gchar** group_collection = NULL;
		gint group_collection_length1 = 0;
		gint _group_collection_size_ = 0;
		gint group_it = 0;
		group_collection = _tmp8_;
		group_collection_length1 = _tmp7_;
		for (group_it = 0; group_it < _tmp7_; group_it = group_it + 1) {
			gchar* _tmp9_;
			gchar* group = NULL;
			_tmp9_ = g_strdup (group_collection[group_it]);
			group = _tmp9_;
			{
				gchar** _tmp10_ = NULL;
				GKeyFile* _tmp11_;
				const gchar* _tmp12_;
				gsize _tmp13_;
				gchar** _tmp14_;
				gint _tmp10__length1;
				gint __tmp10__size_;
				gchar** _tmp15_;
				gint _tmp15__length1;
				_tmp11_ = kf;
				_tmp12_ = group;
				_tmp14_ = g_key_file_get_keys (_tmp11_, _tmp12_, &_tmp13_, &_inner_error_);
				_tmp10_ = _tmp14_;
				_tmp10__length1 = _tmp13_;
				__tmp10__size_ = _tmp10__length1;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					g_propagate_error (error, _inner_error_);
					_g_free0 (group);
					group_collection = (_vala_array_free (group_collection, group_collection_length1, (GDestroyNotify) g_free), NULL);
					_g_key_file_unref0 (kf);
					_dconf_changeset_unref0 (changeset);
					_g_free0 (dir);
					return;
				}
				_tmp15_ = _tmp10_;
				_tmp15__length1 = _tmp10__length1;
				_tmp10_ = NULL;
				_tmp10__length1 = 0;
				{
					gchar** key_collection = NULL;
					gint key_collection_length1 = 0;
					gint _key_collection_size_ = 0;
					gint key_it = 0;
					key_collection = _tmp15_;
					key_collection_length1 = _tmp15__length1;
					for (key_it = 0; key_it < _tmp15__length1; key_it = key_it + 1) {
						gchar* _tmp16_;
						gchar* key = NULL;
						_tmp16_ = g_strdup (key_collection[key_it]);
						key = _tmp16_;
						{
							gchar* _tmp17_ = NULL;
							const gchar* _tmp18_;
							gchar* path = NULL;
							const gchar* _tmp22_;
							gchar* _tmp23_;
							gchar* _tmp24_;
							const gchar* _tmp25_;
							gchar* _tmp26_;
							gchar* _tmp27_;
							const gchar* _tmp28_;
							gchar* _tmp29_ = NULL;
							GKeyFile* _tmp30_;
							const gchar* _tmp31_;
							const gchar* _tmp32_;
							gchar* _tmp33_;
							GVariant* _tmp34_ = NULL;
							GVariant* _tmp35_;
							DConfChangeset* _tmp36_;
							const gchar* _tmp37_;
							_tmp18_ = group;
							if (g_strcmp0 (_tmp18_, "/") == 0) {
								gchar* _tmp19_;
								_tmp19_ = g_strdup ("");
								_g_free0 (_tmp17_);
								_tmp17_ = _tmp19_;
							} else {
								const gchar* _tmp20_;
								gchar* _tmp21_;
								_tmp20_ = group;
								_tmp21_ = g_strconcat (_tmp20_, "/", NULL);
								_g_free0 (_tmp17_);
								_tmp17_ = _tmp21_;
							}
							_tmp22_ = dir;
							_tmp23_ = g_strconcat (_tmp22_, _tmp17_, NULL);
							_tmp24_ = _tmp23_;
							_tmp25_ = key;
							_tmp26_ = g_strconcat (_tmp24_, _tmp25_, NULL);
							_tmp27_ = _tmp26_;
							_g_free0 (_tmp24_);
							path = _tmp27_;
							_tmp28_ = path;
							dconf_is_key (_tmp28_, &_inner_error_);
							if (G_UNLIKELY (_inner_error_ != NULL)) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (path);
								_g_free0 (_tmp17_);
								_g_free0 (key);
								key_collection = (_vala_array_free (key_collection, key_collection_length1, (GDestroyNotify) g_free), NULL);
								_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (group);
								group_collection = (_vala_array_free (group_collection, group_collection_length1, (GDestroyNotify) g_free), NULL);
								_g_key_file_unref0 (kf);
								_dconf_changeset_unref0 (changeset);
								_g_free0 (dir);
								return;
							}
							_tmp30_ = kf;
							_tmp31_ = group;
							_tmp32_ = key;
							_tmp33_ = g_key_file_get_value (_tmp30_, _tmp31_, _tmp32_, &_inner_error_);
							_tmp29_ = _tmp33_;
							if (G_UNLIKELY (_inner_error_ != NULL)) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (path);
								_g_free0 (_tmp17_);
								_g_free0 (key);
								key_collection = (_vala_array_free (key_collection, key_collection_length1, (GDestroyNotify) g_free), NULL);
								_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (group);
								group_collection = (_vala_array_free (group_collection, group_collection_length1, (GDestroyNotify) g_free), NULL);
								_g_key_file_unref0 (kf);
								_dconf_changeset_unref0 (changeset);
								_g_free0 (dir);
								return;
							}
							_tmp35_ = g_variant_parse (NULL, _tmp29_, NULL, NULL, &_inner_error_);
							_tmp34_ = _tmp35_;
							if (G_UNLIKELY (_inner_error_ != NULL)) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (_tmp29_);
								_g_free0 (path);
								_g_free0 (_tmp17_);
								_g_free0 (key);
								key_collection = (_vala_array_free (key_collection, key_collection_length1, (GDestroyNotify) g_free), NULL);
								_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (group);
								group_collection = (_vala_array_free (group_collection, group_collection_length1, (GDestroyNotify) g_free), NULL);
								_g_key_file_unref0 (kf);
								_dconf_changeset_unref0 (changeset);
								_g_free0 (dir);
								return;
							}
							_tmp36_ = changeset;
							_tmp37_ = path;
							dconf_changeset_set (_tmp36_, _tmp37_, _tmp34_);
							_g_variant_unref0 (_tmp34_);
							_g_free0 (_tmp29_);
							_g_free0 (path);
							_g_free0 (_tmp17_);
							_g_free0 (key);
						}
					}
					key_collection = (_vala_array_free (key_collection, key_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (group);
			}
		}
		group_collection = (_vala_array_free (group_collection, group_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp38_ = dconf_client_new ();
	client = _tmp38_;
	_tmp39_ = client;
	_tmp40_ = changeset;
	dconf_client_change_sync (_tmp39_, _tmp40_, NULL, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (client);
		_g_key_file_unref0 (kf);
		_dconf_changeset_unref0 (changeset);
		_g_free0 (dir);
		return;
	}
	_g_object_unref0 (client);
	_g_key_file_unref0 (kf);
	_dconf_changeset_unref0 (changeset);
	_g_free0 (dir);
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



