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

vtgvcsbackendsbzr.c

/* vtgvcsbackendsbzr.c generated by valac 0.10.0, the Vala compiler
 * generated from vtgvcsbackendsbzr.vala, do not modify */

/*
 *  vtgvcsbackendsbzr.vala - Vala developer toys for GEdit
 *  
 *  Copyright (C) 2008 - Andrea Del Signore <sejerpz@tin.it>
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *   
 *  This program 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 General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330,
 *  Boston, MA 02111-1307, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <valagee.h>
#include <sys/wait.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>


#define VTG_VCS_BACKENDS_TYPE_VCS_BASE (vtg_vcs_backends_vcs_base_get_type ())
#define VTG_VCS_BACKENDS_VCS_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBase))
#define VTG_VCS_BACKENDS_VCS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBaseClass))
#define VTG_VCS_BACKENDS_IS_VCS_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE))
#define VTG_VCS_BACKENDS_IS_VCS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_VCS_BASE))
#define VTG_VCS_BACKENDS_VCS_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBaseClass))

typedef struct _VtgVcsBackendsVcsBase VtgVcsBackendsVcsBase;
typedef struct _VtgVcsBackendsVcsBaseClass VtgVcsBackendsVcsBaseClass;
typedef struct _VtgVcsBackendsVcsBasePrivate VtgVcsBackendsVcsBasePrivate;

#define VTG_VCS_BACKENDS_TYPE_ITEM (vtg_vcs_backends_item_get_type ())
#define VTG_VCS_BACKENDS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItem))
#define VTG_VCS_BACKENDS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItemClass))
#define VTG_VCS_BACKENDS_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_ITEM))
#define VTG_VCS_BACKENDS_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_ITEM))
#define VTG_VCS_BACKENDS_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItemClass))

typedef struct _VtgVcsBackendsItem VtgVcsBackendsItem;
typedef struct _VtgVcsBackendsItemClass VtgVcsBackendsItemClass;

#define VTG_VCS_BACKENDS_TYPE_BZR (vtg_vcs_backends_bzr_get_type ())
#define VTG_VCS_BACKENDS_BZR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_BZR, VtgVcsBackendsBzr))
#define VTG_VCS_BACKENDS_BZR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_BZR, VtgVcsBackendsBzrClass))
#define VTG_VCS_BACKENDS_IS_BZR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_BZR))
#define VTG_VCS_BACKENDS_IS_BZR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_BZR))
#define VTG_VCS_BACKENDS_BZR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_BZR, VtgVcsBackendsBzrClass))

typedef struct _VtgVcsBackendsBzr VtgVcsBackendsBzr;
typedef struct _VtgVcsBackendsBzrClass VtgVcsBackendsBzrClass;
typedef struct _VtgVcsBackendsBzrPrivate VtgVcsBackendsBzrPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_collection_object_unref0(var) ((var == NULL) ? NULL : (var = (vala_collection_object_unref (var), NULL)))

#define VTG_VCS_BACKENDS_TYPE_STATES (vtg_vcs_backends_states_get_type ())
typedef struct _VtgVcsBackendsItemPrivate VtgVcsBackendsItemPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

00073 struct _VtgVcsBackendsVcsBase {
      GObject parent_instance;
      VtgVcsBackendsVcsBasePrivate * priv;
};

00078 struct _VtgVcsBackendsVcsBaseClass {
      GObjectClass parent_class;
      ValaList* (*get_items) (VtgVcsBackendsVcsBase* self, const char* path, GError** error);
      gboolean (*test) (VtgVcsBackendsVcsBase* self, const char* path);
};

00084 struct _VtgVcsBackendsBzr {
      VtgVcsBackendsVcsBase parent_instance;
      VtgVcsBackendsBzrPrivate * priv;
};

00089 struct _VtgVcsBackendsBzrClass {
      VtgVcsBackendsVcsBaseClass parent_class;
};

typedef enum  {
      VTG_VCS_BACKENDS_STATES_UNTRACKED,
      VTG_VCS_BACKENDS_STATES_ADDED,
      VTG_VCS_BACKENDS_STATES_MODIFIED,
      VTG_VCS_BACKENDS_STATES_DELETED
} VtgVcsBackendsStates;

struct _VtgVcsBackendsItem {
      GObject parent_instance;
      VtgVcsBackendsItemPrivate * priv;
      char* name;
      VtgVcsBackendsStates state;
};

struct _VtgVcsBackendsItemClass {
      GObjectClass parent_class;
};

typedef enum  {
      VTG_VCS_BACKENDS_VCS_ERROR_CommandFailed
} VtgVcsBackendsVcsError;
#define VTG_VCS_BACKENDS_VCS_ERROR vtg_vcs_backends_vcs_error_quark ()

static gpointer vtg_vcs_backends_bzr_parent_class = NULL;
static GType vtg_vcs_backends_bzr_type_id = 0;

GType vtg_vcs_backends_vcs_base_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_vcs_base_register_type (GTypeModule * module);
GType vtg_vcs_backends_item_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_item_register_type (GTypeModule * module);
GType vtg_vcs_backends_bzr_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_bzr_register_type (GTypeModule * module);
enum  {
      VTG_VCS_BACKENDS_BZR_DUMMY_PROPERTY
};
VtgVcsBackendsBzr* vtg_vcs_backends_bzr_new (void);
VtgVcsBackendsBzr* vtg_vcs_backends_bzr_construct (GType object_type);
VtgVcsBackendsVcsBase* vtg_vcs_backends_vcs_base_construct (GType object_type);
static ValaList* vtg_vcs_backends_bzr_real_get_items (VtgVcsBackendsVcsBase* base, const char* path, GError** error);
VtgVcsBackendsItem* vtg_vcs_backends_item_new (void);
VtgVcsBackendsItem* vtg_vcs_backends_item_construct (GType object_type);
GType vtg_vcs_backends_states_get_type (void) G_GNUC_CONST;
GQuark vtg_vcs_backends_vcs_error_quark (void);
static gboolean vtg_vcs_backends_bzr_real_test (VtgVcsBackendsVcsBase* base, const char* path);
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);



VtgVcsBackendsBzr* vtg_vcs_backends_bzr_construct (GType object_type) {
      VtgVcsBackendsBzr * self;
      self = (VtgVcsBackendsBzr*) vtg_vcs_backends_vcs_base_construct (object_type);
      return self;
}


VtgVcsBackendsBzr* vtg_vcs_backends_bzr_new (void) {
      return vtg_vcs_backends_bzr_construct (VTG_VCS_BACKENDS_TYPE_BZR);
}


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 ValaList* vtg_vcs_backends_bzr_real_get_items (VtgVcsBackendsVcsBase* base, const char* path, GError** error) {
      VtgVcsBackendsBzr * self;
      ValaList* result = NULL;
      ValaList* results;
      char* stdo;
      char* stde;
      gint exit_status = 0;
      char** _tmp0_ = NULL;
      char** _tmp1_;
      gint _tmp1__length1;
      char* _tmp2_ = NULL;
      gboolean _tmp3_;
      char* _tmp4_;
      char* _tmp5_ = NULL;
      gboolean _tmp6_;
      char* _tmp7_;
      gboolean _tmp8_;
      gboolean _tmp9_;
      GError * _inner_error_ = NULL;
      self = (VtgVcsBackendsBzr*) base;
      g_return_val_if_fail (path != NULL, NULL);
      results = (ValaList*) vala_array_list_new (VTG_VCS_BACKENDS_TYPE_ITEM, (GBoxedCopyFunc) g_object_ref, g_object_unref, g_direct_equal);
      stdo = NULL;
      stde = NULL;
      _tmp9_ = (_tmp8_ = (_tmp6_ = (_tmp3_ = g_spawn_sync (path, (_tmp1_ = (_tmp0_ = g_new0 (char*, 2 + 1), _tmp0_[0] = g_strdup ("bzr"), _tmp0_[1] = g_strdup ("status"), _tmp0_), _tmp1__length1 = 2, _tmp1_), NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp2_, &_tmp5_, &exit_status, &_inner_error_), stdo = (_tmp4_ = _tmp2_, _g_free0 (stdo), _tmp4_), _tmp3_), stde = (_tmp7_ = _tmp5_, _g_free0 (stde), _tmp7_), _tmp6_), _tmp1_ = (_vala_array_free (_tmp1_, _tmp1__length1, (GDestroyNotify) g_free), NULL), _tmp8_);
      if (_inner_error_ != NULL) {
            g_propagate_error (error, _inner_error_);
            _g_free0 (stde);
            _g_free0 (stdo);
            _vala_collection_object_unref0 (results);
            return NULL;
      }
      if (_tmp9_) {
            gint exit;
            exit = WEXITSTATUS (exit_status);
            if (exit == 0) {
                  gint lines_length1;
                  gint _lines_size_;
                  char** _tmp11_;
                  char** _tmp10_;
                  char** lines;
                  gint idx;
                  gint status;
                  lines = (_tmp11_ = _tmp10_ = g_strsplit (stdo, "\n", 0), lines_length1 = _vala_array_length (_tmp10_), _lines_size_ = lines_length1, _tmp11_);
                  idx = 0;
                  status = 0;
                  while (TRUE) {
                        char* line;
                        if (!(lines[idx] != NULL)) {
                              break;
                        }
                        line = g_strdup (lines[idx]);
                        if (g_str_has_prefix (line, "added:")) {
                              status = 1;
                        } else {
                              if (g_str_has_prefix (line, "modified:")) {
                                    status = 2;
                              } else {
                                    if (!g_str_has_prefix (line, "  ")) {
                                          status = 0;
                                    } else {
                                          if (g_str_has_prefix (line, "  ")) {
                                                switch (status) {
                                                      case 1:
                                                      case 2:
                                                      {
                                                            VtgVcsBackendsItem* item;
                                                            VtgVcsBackendsStates _tmp12_ = 0;
                                                            char* _tmp13_;
                                                            item = vtg_vcs_backends_item_new ();
                                                            if (status == 1) {
                                                                  _tmp12_ = VTG_VCS_BACKENDS_STATES_ADDED;
                                                            } else {
                                                                  _tmp12_ = VTG_VCS_BACKENDS_STATES_MODIFIED;
                                                            }
                                                            item->state = _tmp12_;
                                                            item->name = (_tmp13_ = string_substring (line, (glong) 2, string_get_length (line) - 2), _g_free0 (item->name), _tmp13_);
                                                            vala_collection_add ((ValaCollection*) results, item);
                                                            _g_object_unref0 (item);
                                                            break;
                                                      }
                                                }
                                          }
                                    }
                              }
                        }
                        idx++;
                        _g_free0 (line);
                  }
                  lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
            } else {
                  char* _tmp14_;
                  GError* _tmp15_;
                  _inner_error_ = (_tmp15_ = g_error_new_literal (VTG_VCS_BACKENDS_VCS_ERROR, VTG_VCS_BACKENDS_VCS_ERROR_CommandFailed, _tmp14_ = g_strdup_printf (_ ("error executing the bzr status command.\n%s"), stde)), _g_free0 (_tmp14_), _tmp15_);
                  {
                        g_propagate_error (error, _inner_error_);
                        _g_free0 (stde);
                        _g_free0 (stdo);
                        _vala_collection_object_unref0 (results);
                        return NULL;
                  }
            }
      }
      result = results;
      _g_free0 (stde);
      _g_free0 (stdo);
      return result;
}


static gboolean vtg_vcs_backends_bzr_real_test (VtgVcsBackendsVcsBase* base, const char* path) {
      VtgVcsBackendsBzr * self;
      gboolean result = FALSE;
      char* bzr_dir;
      self = (VtgVcsBackendsBzr*) base;
      g_return_val_if_fail (path != NULL, FALSE);
      bzr_dir = g_build_filename (path, ".bzr", NULL);
      if (g_file_test (bzr_dir, G_FILE_TEST_IS_DIR)) {
            result = TRUE;
            _g_free0 (bzr_dir);
            return result;
      }
      result = FALSE;
      _g_free0 (bzr_dir);
      return result;
}


static void vtg_vcs_backends_bzr_class_init (VtgVcsBackendsBzrClass * klass) {
      vtg_vcs_backends_bzr_parent_class = g_type_class_peek_parent (klass);
      VTG_VCS_BACKENDS_VCS_BASE_CLASS (klass)->get_items = vtg_vcs_backends_bzr_real_get_items;
      VTG_VCS_BACKENDS_VCS_BASE_CLASS (klass)->test = vtg_vcs_backends_bzr_real_test;
}


static void vtg_vcs_backends_bzr_instance_init (VtgVcsBackendsBzr * self) {
}


GType vtg_vcs_backends_bzr_get_type (void) {
      return vtg_vcs_backends_bzr_type_id;
}


GType vtg_vcs_backends_bzr_register_type (GTypeModule * module) {
      static const GTypeInfo g_define_type_info = { sizeof (VtgVcsBackendsBzrClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vtg_vcs_backends_bzr_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (VtgVcsBackendsBzr), 0, (GInstanceInitFunc) vtg_vcs_backends_bzr_instance_init, NULL };
      vtg_vcs_backends_bzr_type_id = g_type_module_register_type (module, VTG_VCS_BACKENDS_TYPE_VCS_BASE, "VtgVcsBackendsBzr", &g_define_type_info, 0);
      return vtg_vcs_backends_bzr_type_id;
}


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