f-spot r4588 - trunk/libfspot



Author: sdelcroix
Date: Sun Nov 16 19:43:38 2008
New Revision: 4588
URL: http://svn.gnome.org/viewvc/f-spot?rev=4588&view=rev

Log:
Revert "dropping unused f-utils"

This reverts commit 29cc1f5f1936808ca299c7d9b399b6244a2df65e.

Added:
   trunk/libfspot/f-utils.c
   trunk/libfspot/f-utils.h
Modified:
   trunk/libfspot/Makefile.am

Modified: trunk/libfspot/Makefile.am
==============================================================================
--- trunk/libfspot/Makefile.am	(original)
+++ trunk/libfspot/Makefile.am	Sun Nov 16 19:43:38 2008
@@ -25,7 +25,9 @@
 	f-pixbuf-unsharp.c			\
 	f-marshal.c				\
 	f-marshal.h				\
-	f-screen-utils.c
+	f-screen-utils.c			\
+	f-utils.c				\
+	f-utils.h
 
 libfspot_la_LIBADD = 					\
 	$(LCMS_LIBS)					\

Added: trunk/libfspot/f-utils.c
==============================================================================
--- (empty file)
+++ trunk/libfspot/f-utils.c	Sun Nov 16 19:43:38 2008
@@ -0,0 +1,105 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* f-utils.h
+ *
+ * Copyright (C) 2003  Ettore Perazzoli
+ *
+ * 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.
+ *
+ * Author: Ettore Perazzoli <ettore ximian com>
+ */
+
+#include <config.h>
+
+#include "f-utils.h"
+
+#include <glib/gmacros.h>
+
+
+char *
+f_build_relative_path (const char *start_path,
+		       const char *destination_path)
+{
+	const char *sp, *dp;
+	GString *relative_path;
+	gboolean need_separator;
+	char *retval;
+
+	g_return_val_if_fail (g_path_is_absolute (start_path), NULL);
+	g_return_val_if_fail (g_path_is_absolute (destination_path), NULL);
+
+	sp = start_path;
+	dp = destination_path;
+
+	/* Look for a common subpath at the beginning of the paths.  */
+
+	while (*sp == *dp && *sp != 0) {
+		sp ++;
+		dp ++;
+	}
+
+	if (*sp == 0 && *dp == 0)
+		return g_strdup ("");
+
+	/* Roll back to the path element.  This is guarranteed to not run past
+	   the beginning of the string because of the g_path_is_absolute()
+	   checks above.  */
+
+	while (*sp != G_DIR_SEPARATOR && *sp != 0)
+		sp --;
+	while (*dp != G_DIR_SEPARATOR && *dp != 0)
+		dp --;
+
+	g_assert (*dp == G_DIR_SEPARATOR || *dp == 0);
+	g_assert (*sp == G_DIR_SEPARATOR || *sp == 0);
+
+	/* Start constructing the string by adding one ".." for each path
+	   component in the source path that is not in the destination
+	   path.  */
+
+	relative_path = g_string_new ("");
+
+	need_separator = FALSE;
+	while (*sp != 0) {
+		sp ++;
+
+		if (*sp == G_DIR_SEPARATOR || *sp == 0) {
+			while (*sp == G_DIR_SEPARATOR)
+				sp ++;
+
+			if (need_separator)
+				g_string_append (relative_path, G_DIR_SEPARATOR_S);
+				
+			g_string_append (relative_path, "..");
+			need_separator = TRUE;
+		}
+	}
+
+	/* Add the rest of the path elements, if any.  */
+
+	if (*dp != 0) {
+  		/*  (Notice that DP is guaranteed to point to either a null character
+		    or to a separator so we don't need to add it ourselves.)  */
+  		if (need_separator)
+			g_string_append (relative_path, dp);
+		else
+			g_string_append (relative_path, dp + 1);
+	}
+
+	retval = relative_path->str;
+	g_string_free (relative_path, FALSE);
+
+	return retval;
+}

Added: trunk/libfspot/f-utils.h
==============================================================================
--- (empty file)
+++ trunk/libfspot/f-utils.h	Sun Nov 16 19:43:38 2008
@@ -0,0 +1,123 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* f-utils.h
+ *
+ * Copyright (C) 2003  Ettore Perazzoli
+ *
+ * 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.
+ *
+ * Author: Ettore Perazzoli <ettore ximian com>
+ */
+
+#ifndef F_UTILS_H
+#define F_UTILS_H
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <math.h>
+
+
+#define F_MAKE_TYPE(name, underscore_name)							\
+	GType											\
+	underscore_name##_get_type (void)							\
+	{											\
+		static GType type = 0;								\
+												\
+		if (type == 0) {								\
+			static const GTypeInfo info = {						\
+				sizeof (name##Class),						\
+				(GBaseInitFunc) NULL,						\
+				(GBaseFinalizeFunc) NULL,					\
+				(GClassInitFunc) class_init,					\
+				NULL,           /* class_finalize */				\
+				NULL,           /* class_data */				\
+				sizeof (name),							\
+				0,               /* n_preallocs */				\
+				(GInstanceInitFunc) init,					\
+			};									\
+												\
+			type = g_type_register_static (PARENT_TYPE, #name, &info, 0);		\
+		}										\
+												\
+		return type;									\
+	}
+	
+#define F_MAKE_TYPE_WITH_ERROR(name, underscore_name)						\
+	F_MAKE_TYPE (name, underscore_name)							\
+	GQuark											\
+	underscore_name##_error_quark (void)							\
+	{											\
+		static GQuark q = 0;								\
+												\
+		if (q == 0)									\
+			q = g_quark_from_static_string (#underscore_name "_error_quark");	\
+												\
+		return q;									\
+	}
+
+
+/* Refcounting macros.  Note that some of these evaluates OBJ multiple times,
+   which is not ideal...  So you want to pass only variables (not functions) to
+   them.  */
+
+#define F_UNREF(obj)				\
+	G_STMT_START {				\
+		if ((obj) != NULL) {		\
+			g_object_unref (obj);	\
+			(obj) = NULL;		\
+		} 				\
+	} G_STMT_END
+
+#define F_REF(obj)					\
+	((obj) != NULL ? (g_object_ref (obj), (obj))	\
+		       : NULL)
+
+#define F_ASSIGN(dest, src)			\
+	G_STMT_START {				\
+		F_UNREF(dest);			\
+		(dest) = F_REF(src);		\
+	} G_STMT_END
+
+#define F_WEAK_NULL(dest)									\
+	G_STMT_START {										\
+		if ((dest) != NULL) {								\
+			g_object_remove_weak_pointer (G_OBJECT (dest), (void **) & (dest));	\
+			(dest) = NULL;								\
+		}										\
+	} G_STMT_END
+
+#define F_WEAK_ASSIGN(dest, src)								\
+	G_STMT_START {										\
+		F_WEAK_NULL(dest);								\
+		if ((src) != NULL) {								\
+			(dest) = (src);								\
+			g_object_add_weak_pointer (G_OBJECT (dest), (void **) & (dest));	\
+		}										\
+	} G_STMT_END
+
+#define F_BOOLEAN_MEMBER(name)				\
+	unsigned int name : 1
+
+#define F_LIST_FOREACH(list, iterator) 		\
+	for ((iterator) = (list); (iterator) != NULL; (iterator) = (iterator)->next)
+
+#define F_DOUBLE_EQUAL(a, b)			\
+	(fabs (a - b) < 1e-6)
+
+
+/* Build a relative path from START_PATH to DESTINATION_PATH.  */
+char *f_build_relative_path (const char *start_path,
+			     const char *destination_path);
+
+#endif /* F_UTILS_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]