Logo Search packages:      
Sourcecode: valatoys version File versions  Download package

projectgenerator.c

/* projectgenerator.c generated by valac 0.10.0, 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;
};

00086 struct _GenProjectProjectGeneratorPrivate {
      char* make_name;
      char* upper_case_make_name;
      char* license_program_type;
      char* license_name;
      char* license_version;
      char* license_publisher;
      char* license_website;
      char* license_header;
      char* 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;
      char* path;
      gboolean version;
      char* author;
      char* email;
      char* name;
      char** 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 char* gen_project_template_definition_get_name (GenProjectTemplateDefinition* self);
const char* gen_project_template_definition_get_archive_filename (GenProjectTemplateDefinition* self);
static void gen_project_project_generator_scan_path_for_tag_substitution (GenProjectProjectGenerator* self, const char* path);
static char* gen_project_project_generator_replace_tags (GenProjectProjectGenerator* self, const char* data);
static void gen_project_project_generator_set_options (GenProjectProjectGenerator* self, GenProjectProjectOptions* value);
static void gen_project_project_generator_finalize (GObject* obj);
static void gen_project_project_generator_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void 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;
      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);
}


void gen_project_project_generator_create_project (GenProjectProjectGenerator* self) {
      GString* project_name_str;
      GString* make_name_str;
      GString* namespace_name_str;
      char* _tmp7_;
      char* _tmp8_;
      char* _tmp9_;
      GError * _inner_error_ = NULL;
      g_return_if_fail (self != NULL);
      project_name_str = g_string_new ("");
      make_name_str = g_string_new ("");
      namespace_name_str = g_string_new ("");
      {
            gint i;
            i = 0;
            {
                  gboolean _tmp0_;
                  _tmp0_ = TRUE;
                  while (TRUE) {
                        gunichar c;
                        gboolean _tmp1_ = FALSE;
                        gboolean _tmp2_ = FALSE;
                        gboolean _tmp3_ = FALSE;
                        if (!_tmp0_) {
                              i++;
                        }
                        _tmp0_ = FALSE;
                        if (!(i < g_utf8_strlen (self->priv->_options->name, -1))) {
                              break;
                        }
                        c = g_utf8_get_char (g_utf8_offset_to_pointer (self->priv->_options->name, i));
                        if (c >= 'a') {
                              _tmp3_ = c <= 'z';
                        } else {
                              _tmp3_ = FALSE;
                        }
                        if (_tmp3_) {
                              _tmp2_ = TRUE;
                        } else {
                              gboolean _tmp4_ = FALSE;
                              if (c >= 'A') {
                                    _tmp4_ = c <= 'Z';
                              } else {
                                    _tmp4_ = FALSE;
                              }
                              _tmp2_ = _tmp4_;
                        }
                        if (_tmp2_) {
                              _tmp1_ = TRUE;
                        } else {
                              gboolean _tmp5_ = FALSE;
                              if (c >= '0') {
                                    _tmp5_ = c <= '9';
                              } else {
                                    _tmp5_ = FALSE;
                              }
                              _tmp1_ = _tmp5_;
                        }
                        if (_tmp1_) {
                              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 _tmp6_ = FALSE;
                              if (c == '-') {
                                    _tmp6_ = TRUE;
                              } else {
                                    _tmp6_ = c == ' ';
                              }
                              if (_tmp6_) {
                                    g_string_append_unichar (project_name_str, (gunichar) '-');
                                    g_string_append_unichar (make_name_str, (gunichar) '_');
                              }
                        }
                  }
            }
      }
      self->priv->_options->name = (_tmp7_ = g_strdup (project_name_str->str), _g_free0 (self->priv->_options->name), _tmp7_);
      self->priv->make_name = (_tmp8_ = g_strdup (make_name_str->str), _g_free0 (self->priv->make_name), _tmp8_);
      self->priv->upper_case_make_name = (_tmp9_ = g_utf8_strup (self->priv->make_name, -1), _g_free0 (self->priv->upper_case_make_name), _tmp9_);
      g_print (_ ("creating project %s in %s with template %s...\n"), self->priv->_options->name, self->priv->_options->path, gen_project_template_definition_get_name (self->priv->_options->template));
      {
            char* std_out;
            char* std_err;
            char* s;
            gint exit_status = 0;
            gint argv_length1;
            gint _argv_size_;
            char** _tmp11_;
            char** _tmp10_ = NULL;
            char** argv;
            char* _tmp12_ = NULL;
            gboolean _tmp13_;
            char* _tmp14_;
            char* _tmp15_ = NULL;
            gboolean _tmp16_;
            char* _tmp17_;
            gboolean _tmp18_;
            char* license_filename;
            char* _tmp19_;
            char* _tmp20_;
            char* _tmp21_;
            char* _tmp22_;
            char* _tmp23_;
            char* _tmp24_;
            char* _tmp25_;
            gboolean _tmp51_ = FALSE;
            if (!g_file_test (self->priv->_options->path, G_FILE_TEST_EXISTS)) {
                  g_mkdir_with_parents (self->priv->_options->path, 0777);
            }
            std_out = NULL;
            std_err = NULL;
            s = NULL;
            argv = (_tmp11_ = (_tmp10_ = g_new0 (char*, 5 + 1), _tmp10_[0] = g_strdup ("tar"), _tmp10_[1] = g_strdup ("-C"), _tmp10_[2] = g_strdup (self->priv->_options->path), _tmp10_[3] = g_strdup ("-zpxf"), _tmp10_[4] = g_strdup (gen_project_template_definition_get_archive_filename (self->priv->_options->template)), _tmp10_), argv_length1 = 5, _argv_size_ = argv_length1, _tmp11_);
            _tmp18_ = (_tmp16_ = (_tmp13_ = g_spawn_sync (self->priv->_options->path, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp12_, &_tmp15_, &exit_status, &_inner_error_), std_out = (_tmp14_ = _tmp12_, _g_free0 (std_out), _tmp14_), _tmp13_), std_err = (_tmp17_ = _tmp15_, _g_free0 (std_err), _tmp17_), _tmp16_);
            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 (!_tmp18_) {
                  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;
            self->priv->license_program_type = (_tmp19_ = g_strdup ("program"), _g_free0 (self->priv->license_program_type), _tmp19_);
            self->priv->license_header = (_tmp20_ = g_strdup (""), _g_free0 (self->priv->license_header), _tmp20_);
            self->priv->license_header_vala = (_tmp21_ = g_strdup (""), _g_free0 (self->priv->license_header_vala), _tmp21_);
            self->priv->license_name = (_tmp22_ = g_strdup (""), _g_free0 (self->priv->license_name), _tmp22_);
            self->priv->license_version = (_tmp23_ = g_strdup (""), _g_free0 (self->priv->license_version), _tmp23_);
            self->priv->license_publisher = (_tmp24_ = g_strdup (""), _g_free0 (self->priv->license_publisher), _tmp24_);
            self->priv->license_website = (_tmp25_ = g_strdup (""), _g_free0 (self->priv->license_website), _tmp25_);
            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:
                  {
                        char* _tmp26_;
                        char* _tmp27_;
                        char* _tmp28_;
                        self->priv->license_header = (_tmp26_ = 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), _tmp26_);
                        self->priv->license_publisher = (_tmp27_ = g_strdup ("Free Software Foundation"), _g_free0 (self->priv->license_publisher), _tmp27_);
                        self->priv->license_website = (_tmp28_ = g_strdup ("<http://www.gnu.org/licenses/>"), _g_free0 (self->priv->license_website), _tmp28_);
                        break;
                  }
            }
            switch (self->priv->_options->license) {
                  case GEN_PROJECT_PROJECT_LICENSE_GPL2:
                  {
                        char* _tmp29_;
                        char* _tmp31_;
                        char* _tmp32_;
                        char* _tmp33_;
                        license_filename = (_tmp29_ = g_strdup (PACKAGE_DATADIR "/licenses/gpl-2.0.txt"), _g_free0 (license_filename), _tmp29_);
                        if (!g_file_test (license_filename, G_FILE_TEST_EXISTS)) {
                              char* _tmp30_;
                              license_filename = (_tmp30_ = g_strdup ("/usr/share/common-licenses/GPL-2"), _g_free0 (license_filename), _tmp30_);
                        }
                        self->priv->license_name = (_tmp31_ = g_strdup ("GNU General Public License"), _g_free0 (self->priv->license_name), _tmp31_);
                        self->priv->license_version = (_tmp32_ = g_strdup ("2"), _g_free0 (self->priv->license_version), _tmp32_);
                        self->priv->license_program_type = (_tmp33_ = g_strdup ("program"), _g_free0 (self->priv->license_program_type), _tmp33_);
                        break;
                  }
                  case GEN_PROJECT_PROJECT_LICENSE_GPL3:
                  {
                        char* _tmp34_;
                        char* _tmp36_;
                        char* _tmp37_;
                        char* _tmp38_;
                        license_filename = (_tmp34_ = g_strdup (PACKAGE_DATADIR "/licenses/gpl-3.0.txt"), _g_free0 (license_filename), _tmp34_);
                        if (!g_file_test (license_filename, G_FILE_TEST_EXISTS)) {
                              char* _tmp35_;
                              license_filename = (_tmp35_ = g_strdup ("/usr/share/common-licenses/GPL-3"), _g_free0 (license_filename), _tmp35_);
                        }
                        self->priv->license_name = (_tmp36_ = g_strdup ("GNU General Public License"), _g_free0 (self->priv->license_name), _tmp36_);
                        self->priv->license_version = (_tmp37_ = g_strdup ("3"), _g_free0 (self->priv->license_version), _tmp37_);
                        self->priv->license_program_type = (_tmp38_ = g_strdup ("program"), _g_free0 (self->priv->license_program_type), _tmp38_);
                        break;
                  }
                  case GEN_PROJECT_PROJECT_LICENSE_LGPL2:
                  {
                        char* _tmp39_;
                        char* _tmp41_;
                        char* _tmp42_;
                        char* _tmp43_;
                        license_filename = (_tmp39_ = g_strdup (PACKAGE_DATADIR "/licenses/lgpl-2.1.txt"), _g_free0 (license_filename), _tmp39_);
                        if (!g_file_test (license_filename, G_FILE_TEST_EXISTS)) {
                              char* _tmp40_;
                              license_filename = (_tmp40_ = g_strdup ("/usr/share/common-licenses/LGPL-2.1"), _g_free0 (license_filename), _tmp40_);
                        }
                        self->priv->license_name = (_tmp41_ = g_strdup ("GNU Lesser General Public License"), _g_free0 (self->priv->license_name), _tmp41_);
                        self->priv->license_version = (_tmp42_ = g_strdup ("2.1"), _g_free0 (self->priv->license_version), _tmp42_);
                        self->priv->license_program_type = (_tmp43_ = g_strdup ("library"), _g_free0 (self->priv->license_program_type), _tmp43_);
                        break;
                  }
                  case GEN_PROJECT_PROJECT_LICENSE_LGPL3:
                  {
                        char* _tmp44_;
                        char* _tmp46_;
                        char* _tmp47_;
                        char* _tmp48_;
                        license_filename = (_tmp44_ = g_strdup (PACKAGE_DATADIR "/licenses/lgpl-3.0.txt"), _g_free0 (license_filename), _tmp44_);
                        if (!g_file_test (license_filename, G_FILE_TEST_EXISTS)) {
                              char* _tmp45_;
                              license_filename = (_tmp45_ = g_strdup ("/usr/share/common-licenses/LGPL-3"), _g_free0 (license_filename), _tmp45_);
                        }
                        self->priv->license_name = (_tmp46_ = g_strdup ("GNU Lesser General Public License"), _g_free0 (self->priv->license_name), _tmp46_);
                        self->priv->license_version = (_tmp47_ = g_strdup ("3"), _g_free0 (self->priv->license_version), _tmp47_);
                        self->priv->license_program_type = (_tmp48_ = g_strdup ("library"), _g_free0 (self->priv->license_program_type), _tmp48_);
                        break;
                  }
            }
            if (self->priv->license_header != NULL) {
                  GString* sb;
                  char* _tmp50_;
                  sb = g_string_new ("");
                  g_string_append (sb, "\n");
                  {
                        char** _tmp49_;
                        char** line_collection;
                        int line_collection_length1;
                        int line_it;
                        line_collection = _tmp49_ = g_strsplit (self->priv->license_header, "\n", 0);
                        line_collection_length1 = _vala_array_length (_tmp49_);
                        for (line_it = 0; line_it < _vala_array_length (_tmp49_); line_it = line_it + 1) {
                              char* line;
                              line = g_strdup (line_collection[line_it]);
                              {
                                    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));
                  self->priv->license_header_vala = (_tmp50_ = g_strdup (sb->str), _g_free0 (self->priv->license_header_vala), _tmp50_);
                  _g_string_free0 (sb);
            }
            if (license_filename != NULL) {
                  _tmp51_ = g_file_test (license_filename, G_FILE_TEST_EXISTS);
            } else {
                  _tmp51_ = FALSE;
            }
            if (_tmp51_) {
                  char* _tmp52_ = NULL;
                  char* _tmp53_;
                  char* _tmp54_;
                  g_file_get_contents (license_filename, &_tmp52_, NULL, &_inner_error_);
                  s = (_tmp53_ = _tmp52_, _g_free0 (s), _tmp53_);
                  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;
                  }
                  g_file_set_contents (_tmp54_ = g_strconcat (self->priv->_options->path, "/COPYING", NULL), s, (gssize) (-1), &_inner_error_);
                  _g_free0 (_tmp54_);
                  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_get_length (const char* self) {
      glong result;
      g_return_val_if_fail (self != NULL, 0L);
      result = g_utf8_strlen (self, (gssize) (-1));
      return result;
}


static char* string_substring (const char* self, glong offset, glong len) {
      char* result = NULL;
      glong string_length;
      const char* start;
      g_return_val_if_fail (self != NULL, NULL);
      string_length = string_get_length (self);
      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);
      start = g_utf8_offset_to_pointer (self, offset);
      result = g_strndup (start, ((gchar*) g_utf8_offset_to_pointer (start, len)) - ((gchar*) start));
      return result;
}


static void gen_project_project_generator_scan_path_for_tag_substitution (GenProjectProjectGenerator* self, const char* path) {
      GError * _inner_error_ = NULL;
      g_return_if_fail (self != NULL);
      g_return_if_fail (path != NULL);
      {
            GDir* dir;
            dir = g_dir_open (path, 0, &_inner_error_);
            if (_inner_error_ != NULL) {
                  goto __catch1_g_error;
            }
            if (dir != NULL) {
                  char* file;
                  file = NULL;
                  while (TRUE) {
                        char* _tmp0_;
                        char* file_path;
                        if (!((file = (_tmp0_ = g_strdup (g_dir_read_name (dir)), _g_free0 (file), _tmp0_)) != NULL)) {
                              break;
                        }
                        file_path = g_build_filename (path, file, NULL);
                        if (g_file_test (file_path, G_FILE_TEST_IS_DIR)) {
                              gen_project_project_generator_scan_path_for_tag_substitution (self, file_path);
                        } else {
                              if (g_str_has_suffix (file, ".template")) {
                                    char* c;
                                    char* _tmp1_ = NULL;
                                    char* _tmp2_;
                                    char* _tmp3_;
                                    char* new_file_path;
                                    c = NULL;
                                    g_file_get_contents (file_path, &_tmp1_, NULL, &_inner_error_);
                                    c = (_tmp2_ = _tmp1_, _g_free0 (c), _tmp2_);
                                    if (_inner_error_ != NULL) {
                                          _g_free0 (c);
                                          _g_free0 (file_path);
                                          _g_free0 (file);
                                          _g_dir_close0 (dir);
                                          goto __catch1_g_error;
                                    }
                                    c = (_tmp3_ = gen_project_project_generator_replace_tags (self, c), _g_free0 (c), _tmp3_);
                                    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;
                                    }
                                    new_file_path = string_substring (file_path, (glong) 0, string_get_length (file_path) - string_get_length (".template"));
                                    g_rename (file_path, new_file_path);
                                    if (g_str_has_suffix (new_file_path, "/autogen.sh")) {
                                          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 char* string_replace (const char* self, const char* old, const char* replacement) {
      char* result = NULL;
      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);
      {
            char* _tmp0_;
            GRegex* _tmp1_;
            GRegex* regex;
            char* _tmp2_;
            regex = (_tmp1_ = g_regex_new (_tmp0_ = g_regex_escape_string (old, -1), 0, 0, &_inner_error_), _g_free0 (_tmp0_), _tmp1_);
            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;
            }
            _tmp2_ = g_regex_replace_literal (regex, self, (gssize) (-1), 0, replacement, 0, &_inner_error_);
            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 = _tmp2_;
            _g_regex_unref0 (regex);
            return result;
      }
      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 char* gen_project_project_generator_replace_tags (GenProjectProjectGenerator* self, const char* data) {
      char* result = NULL;
      char* _result_;
      char* _tmp0_;
      char* _tmp1_;
      char* _tmp2_;
      char* _tmp3_;
      char* _tmp4_;
      char* _tmp5_;
      char* _tmp6_;
      char* _tmp7_;
      char* _tmp8_;
      char* _tmp9_;
      char* _tmp10_;
      char* _tmp11_;
      char* _tmp12_;
      g_return_val_if_fail (self != NULL, NULL);
      g_return_val_if_fail (data != NULL, NULL);
      _result_ = g_strdup (data);
      _result_ = (_tmp0_ = string_replace (_result_, "${license-header}", self->priv->license_header), _g_free0 (_result_), _tmp0_);
      _result_ = (_tmp1_ = string_replace (_result_, "${license-header-vala}", self->priv->license_header_vala), _g_free0 (_result_), _tmp1_);
      _result_ = (_tmp2_ = string_replace (_result_, "${license-program-type}", self->priv->license_program_type), _g_free0 (_result_), _tmp2_);
      _result_ = (_tmp3_ = string_replace (_result_, "${license-name}", self->priv->license_name), _g_free0 (_result_), _tmp3_);
      _result_ = (_tmp4_ = string_replace (_result_, "${license-version}", self->priv->license_version), _g_free0 (_result_), _tmp4_);
      _result_ = (_tmp5_ = string_replace (_result_, "${license-web-site}", self->priv->license_website), _g_free0 (_result_), _tmp5_);
      _result_ = (_tmp6_ = string_replace (_result_, "${license-publisher}", self->priv->license_publisher), _g_free0 (_result_), _tmp6_);
      _result_ = (_tmp7_ = string_replace (_result_, "${author-name}", self->priv->_options->author), _g_free0 (_result_), _tmp7_);
      _result_ = (_tmp8_ = string_replace (_result_, "${author-email}", self->priv->_options->email), _g_free0 (_result_), _tmp8_);
      _result_ = (_tmp9_ = string_replace (_result_, "${project-name}", self->priv->_options->name), _g_free0 (_result_), _tmp9_);
      _result_ = (_tmp10_ = string_replace (_result_, "${project-description}", self->priv->_options->name), _g_free0 (_result_), _tmp10_);
      _result_ = (_tmp11_ = string_replace (_result_, "${project-uppercase-make-name}", self->priv->upper_case_make_name), _g_free0 (_result_), _tmp11_);
      _result_ = (_tmp12_ = string_replace (_result_, "${project-make-name}", self->priv->make_name), _g_free0 (_result_), _tmp12_);
      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);
      self->priv->_options = (_tmp0_ = _gen_project_project_options_ref0 (value), _gen_project_project_options_unref0 (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 = gen_project_project_generator_get_property;
      G_OBJECT_CLASS (klass)->set_property = 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 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 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;
}





Generated by  Doxygen 1.6.0   Back to index