/* projectgenerator.c generated by valac 0.12.1.1-323029-dirty, the Vala compiler
 * generated from projectgenerator.vala, do not modify */

/* projectgenerator.vala
 *
 * Copyright (C) 2007-2010  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 * 	Andrea Del Signore <sejerpz@tin.it>
 * 	Nicolas Joseph <nicolas.joseph@valaide.org>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <config.h>


#define GEN_PROJECT_TYPE_PROJECT_GENERATOR (gen_project_project_generator_get_type ())
#define GEN_PROJECT_PROJECT_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEN_PROJECT_TYPE_PROJECT_GENERATOR, GenProjectProjectGenerator))
#define GEN_PROJECT_PROJECT_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEN_PROJECT_TYPE_PROJECT_GENERATOR, GenProjectProjectGeneratorClass))
#define GEN_PROJECT_IS_PROJECT_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEN_PROJECT_TYPE_PROJECT_GENERATOR))
#define GEN_PROJECT_IS_PROJECT_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEN_PROJECT_TYPE_PROJECT_GENERATOR))
#define GEN_PROJECT_PROJECT_GENERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEN_PROJECT_TYPE_PROJECT_GENERATOR, GenProjectProjectGeneratorClass))

typedef struct _GenProjectProjectGenerator GenProjectProjectGenerator;
typedef struct _GenProjectProjectGeneratorClass GenProjectProjectGeneratorClass;
typedef struct _GenProjectProjectGeneratorPrivate GenProjectProjectGeneratorPrivate;

#define GEN_PROJECT_TYPE_PROJECT_OPTIONS (gen_project_project_options_get_type ())
#define GEN_PROJECT_PROJECT_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEN_PROJECT_TYPE_PROJECT_OPTIONS, GenProjectProjectOptions))
#define GEN_PROJECT_PROJECT_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEN_PROJECT_TYPE_PROJECT_OPTIONS, GenProjectProjectOptionsClass))
#define GEN_PROJECT_IS_PROJECT_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEN_PROJECT_TYPE_PROJECT_OPTIONS))
#define GEN_PROJECT_IS_PROJECT_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEN_PROJECT_TYPE_PROJECT_OPTIONS))
#define GEN_PROJECT_PROJECT_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEN_PROJECT_TYPE_PROJECT_OPTIONS, GenProjectProjectOptionsClass))

typedef struct _GenProjectProjectOptions GenProjectProjectOptions;
typedef struct _GenProjectProjectOptionsClass GenProjectProjectOptionsClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gen_project_project_options_unref0(var) ((var == NULL) ? NULL : (var = (gen_project_project_options_unref (var), NULL)))
typedef struct _GenProjectProjectOptionsPrivate GenProjectProjectOptionsPrivate;

#define GEN_PROJECT_TYPE_TEMPLATE_DEFINITION (gen_project_template_definition_get_type ())
#define GEN_PROJECT_TEMPLATE_DEFINITION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinition))
#define GEN_PROJECT_TEMPLATE_DEFINITION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinitionClass))
#define GEN_PROJECT_IS_TEMPLATE_DEFINITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION))
#define GEN_PROJECT_IS_TEMPLATE_DEFINITION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION))
#define GEN_PROJECT_TEMPLATE_DEFINITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinitionClass))

typedef struct _GenProjectTemplateDefinition GenProjectTemplateDefinition;
typedef struct _GenProjectTemplateDefinitionClass GenProjectTemplateDefinitionClass;

#define GEN_PROJECT_TYPE_PROJECT_LICENSE (gen_project_project_license_get_type ())
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_dir_close0(var) ((var == NULL) ? NULL : (var = (g_dir_close (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

struct _GenProjectProjectGenerator {
	GObject parent_instance;
	GenProjectProjectGeneratorPrivate * priv;
};

struct _GenProjectProjectGeneratorClass {
	GObjectClass parent_class;
};

struct _GenProjectProjectGeneratorPrivate {
	gchar* make_name;
	gchar* upper_case_make_name;
	gchar* license_program_type;
	gchar* license_name;
	gchar* license_version;
	gchar* license_publisher;
	gchar* license_website;
	gchar* license_header;
	gchar* license_header_vala;
	GenProjectProjectOptions* _options;
};

typedef enum  {
	GEN_PROJECT_PROJECT_LICENSE_GPL2,
	GEN_PROJECT_PROJECT_LICENSE_GPL3,
	GEN_PROJECT_PROJECT_LICENSE_LGPL2,
	GEN_PROJECT_PROJECT_LICENSE_LGPL3
} GenProjectProjectLicense;

struct _GenProjectProjectOptions {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GenProjectProjectOptionsPrivate * priv;
	GenProjectTemplateDefinition* template;
	gchar* path;
	gboolean version;
	gchar* author;
	gchar* email;
	gchar* name;
	gchar** files;
	gint files_length1;
	GenProjectProjectLicense license;
};

struct _GenProjectProjectOptionsClass {
	GTypeClass parent_class;
	void (*finalize) (GenProjectProjectOptions *self);
};


static gpointer gen_project_project_generator_parent_class = NULL;

GType gen_project_project_generator_get_type (void) G_GNUC_CONST;
gpointer gen_project_project_options_ref (gpointer instance);
void gen_project_project_options_unref (gpointer instance);
GParamSpec* gen_project_param_spec_project_options (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void gen_project_value_set_project_options (GValue* value, gpointer v_object);
void gen_project_value_take_project_options (GValue* value, gpointer v_object);
gpointer gen_project_value_get_project_options (const GValue* value);
GType gen_project_project_options_get_type (void) G_GNUC_CONST;
#define GEN_PROJECT_PROJECT_GENERATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEN_PROJECT_TYPE_PROJECT_GENERATOR, GenProjectProjectGeneratorPrivate))
enum  {
	GEN_PROJECT_PROJECT_GENERATOR_DUMMY_PROPERTY,
	GEN_PROJECT_PROJECT_GENERATOR_OPTIONS
};
GenProjectProjectGenerator* gen_project_project_generator_new (GenProjectProjectOptions* options);
GenProjectProjectGenerator* gen_project_project_generator_construct (GType object_type, GenProjectProjectOptions* options);
void gen_project_project_generator_create_project (GenProjectProjectGenerator* self);
GenProjectProjectOptions* gen_project_project_generator_get_options (GenProjectProjectGenerator* self);
GType gen_project_template_definition_get_type (void) G_GNUC_CONST;
GType gen_project_project_license_get_type (void) G_GNUC_CONST;
const gchar* gen_project_template_definition_get_name (GenProjectTemplateDefinition* self);
const gchar* gen_project_template_definition_get_archive_filename (GenProjectTemplateDefinition* self);
static void gen_project_project_generator_scan_path_for_tag_substitution (GenProjectProjectGenerator* self, const gchar* path);
static gchar* gen_project_project_generator_replace_tags (GenProjectProjectGenerator* self, const gchar* data);
static void gen_project_project_generator_set_options (GenProjectProjectGenerator* self, GenProjectProjectOptions* value);
static void gen_project_project_generator_finalize (GObject* obj);
static void _vala_gen_project_project_generator_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_gen_project_project_generator_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
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 gint _vala_array_length (gpointer array);


GenProjectProjectGenerator* gen_project_project_generator_construct (GType object_type, GenProjectProjectOptions* options) {
	GenProjectProjectGenerator * self = NULL;
	g_return_val_if_fail (options != NULL, NULL);
	self = (GenProjectProjectGenerator*) g_object_new (object_type, "options", options, NULL);
	return self;
}


GenProjectProjectGenerator* gen_project_project_generator_new (GenProjectProjectOptions* options) {
	return gen_project_project_generator_construct (GEN_PROJECT_TYPE_PROJECT_GENERATOR, options);
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	g_return_val_if_fail (self != NULL, '\0');
	result = ((gchar*) self)[index];
	return result;
}


void gen_project_project_generator_create_project (GenProjectProjectGenerator* self) {
	GString* _tmp0_ = NULL;
	GString* project_name_str;
	GString* _tmp1_ = NULL;
	GString* make_name_str;
	GString* _tmp2_ = NULL;
	GString* namespace_name_str;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_ = NULL;
	const gchar* _tmp15_ = NULL;
	const gchar* _tmp16_ = NULL;
	gboolean _tmp17_;
	gchar* std_out = NULL;
	gchar* std_err = NULL;
	gchar* s = NULL;
	gint exit_status = 0;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	const gchar* _tmp22_ = NULL;
	gchar* _tmp23_;
	gchar** _tmp24_ = NULL;
	gchar** argv;
	gint argv_length1;
	gint _argv_size_;
	gchar* _tmp25_ = NULL;
	gchar* _tmp26_ = NULL;
	gint _tmp27_;
	gboolean _tmp28_;
	gboolean _tmp29_;
	gchar* license_filename;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gboolean _tmp69_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_string_new ("");
	project_name_str = _tmp0_;
	_tmp1_ = g_string_new ("");
	make_name_str = _tmp1_;
	_tmp2_ = g_string_new ("");
	namespace_name_str = _tmp2_;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp3_;
			_tmp3_ = TRUE;
			while (TRUE) {
				gint _tmp4_;
				gchar _tmp5_;
				gunichar c;
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gboolean _tmp8_ = FALSE;
				if (!_tmp3_) {
					i++;
				}
				_tmp3_ = FALSE;
				_tmp4_ = strlen (self->priv->_options->name);
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp5_ = string_get (self->priv->_options->name, (glong) i);
				c = (gunichar) _tmp5_;
				if (c >= 'a') {
					_tmp8_ = c <= 'z';
				} else {
					_tmp8_ = FALSE;
				}
				if (_tmp8_) {
					_tmp7_ = TRUE;
				} else {
					gboolean _tmp9_ = FALSE;
					if (c >= 'A') {
						_tmp9_ = c <= 'Z';
					} else {
						_tmp9_ = FALSE;
					}
					_tmp7_ = _tmp9_;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp10_ = FALSE;
					if (c >= '0') {
						_tmp10_ = c <= '9';
					} else {
						_tmp10_ = FALSE;
					}
					_tmp6_ = _tmp10_;
				}
				if (_tmp6_) {
					g_string_append_unichar (project_name_str, c);
					g_string_append_unichar (make_name_str, c);
					g_string_append_unichar (namespace_name_str, c);
				} else {
					gboolean _tmp11_ = FALSE;
					if (c == '-') {
						_tmp11_ = TRUE;
					} else {
						_tmp11_ = c == ' ';
					}
					if (_tmp11_) {
						g_string_append_unichar (project_name_str, (gunichar) '-');
						g_string_append_unichar (make_name_str, (gunichar) '_');
					}
				}
			}
		}
	}
	_tmp12_ = g_strdup (project_name_str->str);
	_g_free0 (self->priv->_options->name);
	self->priv->_options->name = _tmp12_;
	_tmp13_ = g_strdup (make_name_str->str);
	_g_free0 (self->priv->make_name);
	self->priv->make_name = _tmp13_;
	_tmp14_ = g_utf8_strup (self->priv->make_name, (gssize) (-1));
	_g_free0 (self->priv->upper_case_make_name);
	self->priv->upper_case_make_name = _tmp14_;
	_tmp15_ = _ ("creating project %s in %s with template %s...\n");
	_tmp16_ = gen_project_template_definition_get_name (self->priv->_options->template);
	g_print (_tmp15_, self->priv->_options->name, self->priv->_options->path, _tmp16_);
	_tmp17_ = g_file_test (self->priv->_options->path, G_FILE_TEST_EXISTS);
	if (!_tmp17_) {
		g_mkdir_with_parents (self->priv->_options->path, 0777);
	}
	_tmp18_ = g_strdup ("tar");
	_tmp19_ = g_strdup ("-C");
	_tmp20_ = g_strdup (self->priv->_options->path);
	_tmp21_ = g_strdup ("-zpxf");
	_tmp22_ = gen_project_template_definition_get_archive_filename (self->priv->_options->template);
	_tmp23_ = g_strdup (_tmp22_);
	_tmp24_ = g_new0 (gchar*, 5 + 1);
	_tmp24_[0] = _tmp18_;
	_tmp24_[1] = _tmp19_;
	_tmp24_[2] = _tmp20_;
	_tmp24_[3] = _tmp21_;
	_tmp24_[4] = _tmp23_;
	argv = _tmp24_;
	argv_length1 = 5;
	_argv_size_ = 5;
	_tmp28_ = g_spawn_sync (self->priv->_options->path, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp25_, &_tmp26_, &_tmp27_, &_inner_error_);
	_g_free0 (std_out);
	std_out = _tmp25_;
	_g_free0 (std_err);
	std_err = _tmp26_;
	exit_status = _tmp27_;
	_tmp29_ = _tmp28_;
	if (_inner_error_ != NULL) {
		argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (s);
		_g_free0 (std_err);
		_g_free0 (std_out);
		goto __catch0_g_error;
	}
	if (!_tmp29_) {
		g_critical ("projectgenerator.vala:91: error extracting data from template. exit co" \
"de %d", exit_status);
		argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (s);
		_g_free0 (std_err);
		_g_free0 (std_out);
		_g_string_free0 (namespace_name_str);
		_g_string_free0 (make_name_str);
		_g_string_free0 (project_name_str);
		return;
	}
	license_filename = NULL;
	_tmp30_ = g_strdup ("program");
	_g_free0 (self->priv->license_program_type);
	self->priv->license_program_type = _tmp30_;
	_tmp31_ = g_strdup ("");
	_g_free0 (self->priv->license_header);
	self->priv->license_header = _tmp31_;
	_tmp32_ = g_strdup ("");
	_g_free0 (self->priv->license_header_vala);
	self->priv->license_header_vala = _tmp32_;
	_tmp33_ = g_strdup ("");
	_g_free0 (self->priv->license_name);
	self->priv->license_name = _tmp33_;
	_tmp34_ = g_strdup ("");
	_g_free0 (self->priv->license_version);
	self->priv->license_version = _tmp34_;
	_tmp35_ = g_strdup ("");
	_g_free0 (self->priv->license_publisher);
	self->priv->license_publisher = _tmp35_;
	_tmp36_ = g_strdup ("");
	_g_free0 (self->priv->license_website);
	self->priv->license_website = _tmp36_;
	switch (self->priv->_options->license) {
		case GEN_PROJECT_PROJECT_LICENSE_GPL2:
		case GEN_PROJECT_PROJECT_LICENSE_GPL3:
		case GEN_PROJECT_PROJECT_LICENSE_LGPL2:
		case GEN_PROJECT_PROJECT_LICENSE_LGPL3:
		{
			gchar* _tmp37_;
			gchar* _tmp38_;
			gchar* _tmp39_;
			_tmp37_ = g_strdup ("This ${license-program-type} is free software: you can redistribute it" \
" and/or modify\n" \
"it under the terms of the ${license-name} as published by\n" \
"the ${license-publisher}, either version ${license-version} of the Lic" \
"ense, or\n" \
"(at your option) any later version.\n" \
" \n" \
"This ${license-program-type} is distributed in the hope that it will b" \
"e useful,\n" \
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" \
"${license-name} for more details.\n" \
" \n" \
"You should have received a copy of the ${license-name}\n" \
"along with this ${license-program-type}.  If not, see ${license-web-si" \
"te}.\n");
			_g_free0 (self->priv->license_header);
			self->priv->license_header = _tmp37_;
			_tmp38_ = g_strdup ("Free Software Foundation");
			_g_free0 (self->priv->license_publisher);
			self->priv->license_publisher = _tmp38_;
			_tmp39_ = g_strdup ("<http://www.gnu.org/licenses/>");
			_g_free0 (self->priv->license_website);
			self->priv->license_website = _tmp39_;
			break;
		}
		default:
		break;
	}
	switch (self->priv->_options->license) {
		case GEN_PROJECT_PROJECT_LICENSE_GPL2:
		{
			gchar* _tmp40_;
			gboolean _tmp41_;
			gchar* _tmp43_;
			gchar* _tmp44_;
			gchar* _tmp45_;
			_tmp40_ = g_strdup (PACKAGE_DATADIR "/licenses/gpl-2.0.txt");
			_g_free0 (license_filename);
			license_filename = _tmp40_;
			_tmp41_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
			if (!_tmp41_) {
				gchar* _tmp42_;
				_tmp42_ = g_strdup ("/usr/share/common-licenses/GPL-2");
				_g_free0 (license_filename);
				license_filename = _tmp42_;
			}
			_tmp43_ = g_strdup ("GNU General Public License");
			_g_free0 (self->priv->license_name);
			self->priv->license_name = _tmp43_;
			_tmp44_ = g_strdup ("2");
			_g_free0 (self->priv->license_version);
			self->priv->license_version = _tmp44_;
			_tmp45_ = g_strdup ("program");
			_g_free0 (self->priv->license_program_type);
			self->priv->license_program_type = _tmp45_;
			break;
		}
		case GEN_PROJECT_PROJECT_LICENSE_GPL3:
		{
			gchar* _tmp46_;
			gboolean _tmp47_;
			gchar* _tmp49_;
			gchar* _tmp50_;
			gchar* _tmp51_;
			_tmp46_ = g_strdup (PACKAGE_DATADIR "/licenses/gpl-3.0.txt");
			_g_free0 (license_filename);
			license_filename = _tmp46_;
			_tmp47_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
			if (!_tmp47_) {
				gchar* _tmp48_;
				_tmp48_ = g_strdup ("/usr/share/common-licenses/GPL-3");
				_g_free0 (license_filename);
				license_filename = _tmp48_;
			}
			_tmp49_ = g_strdup ("GNU General Public License");
			_g_free0 (self->priv->license_name);
			self->priv->license_name = _tmp49_;
			_tmp50_ = g_strdup ("3");
			_g_free0 (self->priv->license_version);
			self->priv->license_version = _tmp50_;
			_tmp51_ = g_strdup ("program");
			_g_free0 (self->priv->license_program_type);
			self->priv->license_program_type = _tmp51_;
			break;
		}
		case GEN_PROJECT_PROJECT_LICENSE_LGPL2:
		{
			gchar* _tmp52_;
			gboolean _tmp53_;
			gchar* _tmp55_;
			gchar* _tmp56_;
			gchar* _tmp57_;
			_tmp52_ = g_strdup (PACKAGE_DATADIR "/licenses/lgpl-2.1.txt");
			_g_free0 (license_filename);
			license_filename = _tmp52_;
			_tmp53_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
			if (!_tmp53_) {
				gchar* _tmp54_;
				_tmp54_ = g_strdup ("/usr/share/common-licenses/LGPL-2.1");
				_g_free0 (license_filename);
				license_filename = _tmp54_;
			}
			_tmp55_ = g_strdup ("GNU Lesser General Public License");
			_g_free0 (self->priv->license_name);
			self->priv->license_name = _tmp55_;
			_tmp56_ = g_strdup ("2.1");
			_g_free0 (self->priv->license_version);
			self->priv->license_version = _tmp56_;
			_tmp57_ = g_strdup ("library");
			_g_free0 (self->priv->license_program_type);
			self->priv->license_program_type = _tmp57_;
			break;
		}
		case GEN_PROJECT_PROJECT_LICENSE_LGPL3:
		{
			gchar* _tmp58_;
			gboolean _tmp59_;
			gchar* _tmp61_;
			gchar* _tmp62_;
			gchar* _tmp63_;
			_tmp58_ = g_strdup (PACKAGE_DATADIR "/licenses/lgpl-3.0.txt");
			_g_free0 (license_filename);
			license_filename = _tmp58_;
			_tmp59_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
			if (!_tmp59_) {
				gchar* _tmp60_;
				_tmp60_ = g_strdup ("/usr/share/common-licenses/LGPL-3");
				_g_free0 (license_filename);
				license_filename = _tmp60_;
			}
			_tmp61_ = g_strdup ("GNU Lesser General Public License");
			_g_free0 (self->priv->license_name);
			self->priv->license_name = _tmp61_;
			_tmp62_ = g_strdup ("3");
			_g_free0 (self->priv->license_version);
			self->priv->license_version = _tmp62_;
			_tmp63_ = g_strdup ("library");
			_g_free0 (self->priv->license_program_type);
			self->priv->license_program_type = _tmp63_;
			break;
		}
		default:
		break;
	}
	if (self->priv->license_header != NULL) {
		GString* _tmp64_ = NULL;
		GString* sb;
		gchar** _tmp65_;
		gchar** _tmp66_ = NULL;
		gchar* _tmp68_;
		_tmp64_ = g_string_new ("");
		sb = _tmp64_;
		g_string_append (sb, "\n");
		_tmp66_ = _tmp65_ = g_strsplit (self->priv->license_header, "\n", 0);
		{
			gchar** line_collection;
			int line_collection_length1;
			int line_it;
			line_collection = _tmp66_;
			line_collection_length1 = _vala_array_length (_tmp65_);
			for (line_it = 0; line_it < _vala_array_length (_tmp65_); line_it = line_it + 1) {
				gchar* _tmp67_;
				gchar* line;
				_tmp67_ = g_strdup (line_collection[line_it]);
				line = _tmp67_;
				{
					g_string_append (sb, " * ");
					g_string_append (sb, line);
					g_string_append (sb, "\n");
					_g_free0 (line);
				}
			}
			line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
		}
		g_string_truncate (sb, (gsize) (sb->len - 1));
		_tmp68_ = g_strdup (sb->str);
		_g_free0 (self->priv->license_header_vala);
		self->priv->license_header_vala = _tmp68_;
		_g_string_free0 (sb);
	}
	if (license_filename != NULL) {
		gboolean _tmp70_;
		_tmp70_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
		_tmp69_ = _tmp70_;
	} else {
		_tmp69_ = FALSE;
	}
	if (_tmp69_) {
		gchar* _tmp71_ = NULL;
		gchar* _tmp72_;
		gchar* _tmp73_;
		g_file_get_contents (license_filename, &_tmp71_, NULL, &_inner_error_);
		_g_free0 (s);
		s = _tmp71_;
		if (_inner_error_ != NULL) {
			_g_free0 (license_filename);
			argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (s);
			_g_free0 (std_err);
			_g_free0 (std_out);
			goto __catch0_g_error;
		}
		_tmp72_ = g_strconcat (self->priv->_options->path, "/COPYING", NULL);
		_tmp73_ = _tmp72_;
		g_file_set_contents (_tmp73_, s, (gssize) (-1), &_inner_error_);
		_g_free0 (_tmp73_);
		if (_inner_error_ != NULL) {
			_g_free0 (license_filename);
			argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (s);
			_g_free0 (std_err);
			_g_free0 (std_out);
			goto __catch0_g_error;
		}
	}
	gen_project_project_generator_scan_path_for_tag_substitution (self, self->priv->_options->path);
	_g_free0 (license_filename);
	argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (s);
	_g_free0 (std_err);
	_g_free0 (std_out);
	goto __finally0;
	__catch0_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_critical ("projectgenerator.vala:192: Error while creating project: %s", e->message);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_string_free0 (namespace_name_str);
		_g_string_free0 (make_name_str);
		_g_string_free0 (project_name_str);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_g_string_free0 (namespace_name_str);
	_g_string_free0 (make_name_str);
	_g_string_free0 (project_name_str);
}


static glong string_strnlen (gchar* str, glong maxlen) {
	glong result = 0L;
	gchar* _tmp0_ = NULL;
	gchar* end;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	if (end == NULL) {
		result = maxlen;
		return result;
	} else {
		result = (glong) (end - str);
		return result;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= 0) {
		_tmp0_ = len >= 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		glong _tmp1_;
		_tmp1_ = string_strnlen ((gchar*) self, offset + len);
		string_length = _tmp1_;
	} else {
		gint _tmp2_;
		_tmp2_ = strlen (self);
		string_length = (glong) _tmp2_;
	}
	if (offset < 0) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= 0, NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < 0) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}


static void gen_project_project_generator_scan_path_for_tag_substitution (GenProjectProjectGenerator* self, const gchar* path) {
	GDir* _tmp0_ = NULL;
	GDir* dir;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	_tmp0_ = g_dir_open (path, (guint) 0, &_inner_error_);
	dir = _tmp0_;
	if (_inner_error_ != NULL) {
		goto __catch1_g_error;
	}
	if (dir != NULL) {
		gchar* file = NULL;
		while (TRUE) {
			const gchar* _tmp1_ = NULL;
			gchar* _tmp2_;
			gchar* _tmp3_ = NULL;
			gchar* file_path;
			gboolean _tmp4_;
			_tmp1_ = g_dir_read_name (dir);
			_tmp2_ = g_strdup (_tmp1_);
			_g_free0 (file);
			file = _tmp2_;
			if (!(file != NULL)) {
				break;
			}
			_tmp3_ = g_build_filename (path, file, NULL);
			file_path = _tmp3_;
			_tmp4_ = g_file_test (file_path, G_FILE_TEST_IS_DIR);
			if (_tmp4_) {
				gen_project_project_generator_scan_path_for_tag_substitution (self, file_path);
			} else {
				gboolean _tmp5_;
				_tmp5_ = g_str_has_suffix (file, ".template");
				if (_tmp5_) {
					gchar* c = NULL;
					gchar* _tmp6_ = NULL;
					gchar* _tmp7_ = NULL;
					gint _tmp8_;
					gint _tmp9_;
					gchar* _tmp10_ = NULL;
					gchar* new_file_path;
					gboolean _tmp11_;
					g_file_get_contents (file_path, &_tmp6_, NULL, &_inner_error_);
					_g_free0 (c);
					c = _tmp6_;
					if (_inner_error_ != NULL) {
						_g_free0 (c);
						_g_free0 (file_path);
						_g_free0 (file);
						_g_dir_close0 (dir);
						goto __catch1_g_error;
					}
					_tmp7_ = gen_project_project_generator_replace_tags (self, c);
					_g_free0 (c);
					c = _tmp7_;
					g_file_set_contents (file_path, c, (gssize) (-1), &_inner_error_);
					if (_inner_error_ != NULL) {
						_g_free0 (c);
						_g_free0 (file_path);
						_g_free0 (file);
						_g_dir_close0 (dir);
						goto __catch1_g_error;
					}
					_tmp8_ = strlen (file_path);
					_tmp9_ = strlen (".template");
					_tmp10_ = string_substring (file_path, (glong) 0, (glong) (_tmp8_ - _tmp9_));
					new_file_path = _tmp10_;
					g_rename (file_path, new_file_path);
					_tmp11_ = g_str_has_suffix (new_file_path, "/autogen.sh");
					if (_tmp11_) {
						g_chmod (new_file_path, 0755);
					}
					_g_free0 (new_file_path);
					_g_free0 (c);
				}
			}
			_g_free0 (file_path);
		}
		_g_free0 (file);
	}
	_g_dir_close0 (dir);
	goto __finally1;
	__catch1_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_warning ("projectgenerator.vala:226: replace_tags: error reading path %s", path);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	GRegex* _tmp2_ = NULL;
	GRegex* _tmp3_;
	GRegex* regex;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	_tmp0_ = g_regex_escape_string (old, -1);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_regex_new (_tmp1_, 0, 0, &_inner_error_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	regex = _tmp3_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch2_g_regex_error;
		}
		g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp4_ = g_regex_replace_literal (regex, self, (gssize) (-1), 0, replacement, 0, &_inner_error_);
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		_g_regex_unref0 (regex);
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch2_g_regex_error;
		}
		_g_regex_unref0 (regex);
		g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	result = _tmp5_;
	_g_regex_unref0 (regex);
	return result;
	_g_regex_unref0 (regex);
	goto __finally2;
	__catch2_g_regex_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally2:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


static gchar* gen_project_project_generator_replace_tags (GenProjectProjectGenerator* self, const gchar* data) {
	gchar* result = NULL;
	gchar* _tmp0_;
	gchar* _result_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	_tmp0_ = g_strdup (data);
	_result_ = _tmp0_;
	_tmp1_ = string_replace (_result_, "${license-header}", self->priv->license_header);
	_g_free0 (_result_);
	_result_ = _tmp1_;
	_tmp2_ = string_replace (_result_, "${license-header-vala}", self->priv->license_header_vala);
	_g_free0 (_result_);
	_result_ = _tmp2_;
	_tmp3_ = string_replace (_result_, "${license-program-type}", self->priv->license_program_type);
	_g_free0 (_result_);
	_result_ = _tmp3_;
	_tmp4_ = string_replace (_result_, "${license-name}", self->priv->license_name);
	_g_free0 (_result_);
	_result_ = _tmp4_;
	_tmp5_ = string_replace (_result_, "${license-version}", self->priv->license_version);
	_g_free0 (_result_);
	_result_ = _tmp5_;
	_tmp6_ = string_replace (_result_, "${license-web-site}", self->priv->license_website);
	_g_free0 (_result_);
	_result_ = _tmp6_;
	_tmp7_ = string_replace (_result_, "${license-publisher}", self->priv->license_publisher);
	_g_free0 (_result_);
	_result_ = _tmp7_;
	_tmp8_ = string_replace (_result_, "${author-name}", self->priv->_options->author);
	_g_free0 (_result_);
	_result_ = _tmp8_;
	_tmp9_ = string_replace (_result_, "${author-email}", self->priv->_options->email);
	_g_free0 (_result_);
	_result_ = _tmp9_;
	_tmp10_ = string_replace (_result_, "${project-name}", self->priv->_options->name);
	_g_free0 (_result_);
	_result_ = _tmp10_;
	_tmp11_ = string_replace (_result_, "${project-description}", self->priv->_options->name);
	_g_free0 (_result_);
	_result_ = _tmp11_;
	_tmp12_ = string_replace (_result_, "${project-uppercase-make-name}", self->priv->upper_case_make_name);
	_g_free0 (_result_);
	_result_ = _tmp12_;
	_tmp13_ = string_replace (_result_, "${project-make-name}", self->priv->make_name);
	_g_free0 (_result_);
	_result_ = _tmp13_;
	result = _result_;
	return result;
}


GenProjectProjectOptions* gen_project_project_generator_get_options (GenProjectProjectGenerator* self) {
	GenProjectProjectOptions* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_options;
	return result;
}


static gpointer _gen_project_project_options_ref0 (gpointer self) {
	return self ? gen_project_project_options_ref (self) : NULL;
}


static void gen_project_project_generator_set_options (GenProjectProjectGenerator* self, GenProjectProjectOptions* value) {
	GenProjectProjectOptions* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _gen_project_project_options_ref0 (value);
	_gen_project_project_options_unref0 (self->priv->_options);
	self->priv->_options = _tmp0_;
	g_object_notify ((GObject *) self, "options");
}


static void gen_project_project_generator_class_init (GenProjectProjectGeneratorClass * klass) {
	gen_project_project_generator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GenProjectProjectGeneratorPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_gen_project_project_generator_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gen_project_project_generator_set_property;
	G_OBJECT_CLASS (klass)->finalize = gen_project_project_generator_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEN_PROJECT_PROJECT_GENERATOR_OPTIONS, gen_project_param_spec_project_options ("options", "options", "options", GEN_PROJECT_TYPE_PROJECT_OPTIONS, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}


static void gen_project_project_generator_instance_init (GenProjectProjectGenerator * self) {
	self->priv = GEN_PROJECT_PROJECT_GENERATOR_GET_PRIVATE (self);
}


static void gen_project_project_generator_finalize (GObject* obj) {
	GenProjectProjectGenerator * self;
	self = GEN_PROJECT_PROJECT_GENERATOR (obj);
	_g_free0 (self->priv->make_name);
	_g_free0 (self->priv->upper_case_make_name);
	_g_free0 (self->priv->license_program_type);
	_g_free0 (self->priv->license_name);
	_g_free0 (self->priv->license_version);
	_g_free0 (self->priv->license_publisher);
	_g_free0 (self->priv->license_website);
	_g_free0 (self->priv->license_header);
	_g_free0 (self->priv->license_header_vala);
	_gen_project_project_options_unref0 (self->priv->_options);
	G_OBJECT_CLASS (gen_project_project_generator_parent_class)->finalize (obj);
}


GType gen_project_project_generator_get_type (void) {
	static volatile gsize gen_project_project_generator_type_id__volatile = 0;
	if (g_once_init_enter (&gen_project_project_generator_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GenProjectProjectGeneratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gen_project_project_generator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GenProjectProjectGenerator), 0, (GInstanceInitFunc) gen_project_project_generator_instance_init, NULL };
		GType gen_project_project_generator_type_id;
		gen_project_project_generator_type_id = g_type_register_static (G_TYPE_OBJECT, "GenProjectProjectGenerator", &g_define_type_info, 0);
		g_once_init_leave (&gen_project_project_generator_type_id__volatile, gen_project_project_generator_type_id);
	}
	return gen_project_project_generator_type_id__volatile;
}


static void _vala_gen_project_project_generator_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GenProjectProjectGenerator * self;
	self = GEN_PROJECT_PROJECT_GENERATOR (object);
	switch (property_id) {
		case GEN_PROJECT_PROJECT_GENERATOR_OPTIONS:
		gen_project_value_set_project_options (value, gen_project_project_generator_get_options (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_gen_project_project_generator_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GenProjectProjectGenerator * self;
	self = GEN_PROJECT_PROJECT_GENERATOR (object);
	switch (property_id) {
		case GEN_PROJECT_PROJECT_GENERATOR_OPTIONS:
		gen_project_project_generator_set_options (self, gen_project_value_get_project_options (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


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);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



