[AdgLDim] Avoid arrange() on the same data
[adg.git] / adg / adg-util.c
blob53a78c6c29cda0efdd70bdbe74d5f04b5f2060b7
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-util
23 * @Section_Id:utilities
24 * @title: Utilities
25 * @short_description: Assorted macros and functions
27 * Collection of macros and functions that do not fit inside any other topic.
28 **/
30 /**
31 * ADG_DIR_RIGHT:
33 * Symbolic constant for the right direction (in radians).
34 **/
36 /**
37 * ADG_DIR_DOWN:
39 * Symbolic constant for the down direction (in radians).
40 **/
42 /**
43 * ADG_DIR_LEFT:
45 * Symbolic constant for the left direction (in radians).
46 **/
48 /**
49 * ADG_DIR_UP:
51 * Symbolic constant for the up direction (in radians).
52 **/
54 /**
55 * ADG_FORWARD_DECL:
56 * @id: The name of a struct
58 * Forward declaration of struct @id. It is equivalent to a typical
59 * struct forward declaration, for example:
61 * |[
62 * ADG_FORWARD_DECL(test)
63 * ]|
65 * will expand to:
67 * |[
68 * typedef struct _test test
69 * ]|
71 * This macro is needed to fake <command>gtk-doc</command>, because
72 * up to now (v.1.12) it generates two conflicting links when using
73 * forward declarations: the first in the source with the declaration
74 * and the second where the type is defined. Using ADG_FORWARD_DECL()
75 * instead of the usual typedef avoids the parsing of the declaration
76 * in the first file (<command>gtk-doc</command> is not able to do C
77 * preprocessing).
79 * The same principle can be applied in the definition file. Following
80 * the previous example, you can use something like this where struct
81 * _type is defined:
83 * |[
84 * #if 0
85 * // This is declared in another file
86 * typedef struct _type type;
87 * #endif
88 * struct _type {
89 * ...
90 * };
91 * ]|
92 **/
94 /**
95 * ADG_MESSAGE:
96 * @message: the message string
98 * A convenient function to output debug information. It is similar
99 * to g_message() but prepends @message with some text specifying
100 * the position where this function has been called.
104 #include "adg-util.h"
105 #include <string.h>
106 #include <limits.h>
110 * adg_strcmp:
111 * @s1: first string to compare
112 * @s2: second string to compare
114 * A strcmp() function guarded against %NULL values. It works in the
115 * same way exept for the following situations:
117 * <itemizedlist>
118 * <listitem><code>s1 == NULL && s2 == NULL</code>: returns %0;</listitem>
119 * <listitem><code>s1 == NULL</code>: returns %INT_MIN;</listitem>
120 * <listitem><code>s2 == NULL</code>: returns %INT_MAX.</listitem>
121 * </itemizedlist>
123 * Returns: %0 if @s1 matches @s2, a value less than %0 if @s1 is less
124 * than @s2 or greather than %0 if @s1 is greather than @s2
126 gint
127 adg_strcmp(const gchar *s1, const gchar *s2)
129 /* This will also catch the NULL == NULL case */
130 if (s1 == s2)
131 return 0;
133 if (s1 == NULL)
134 return INT_MIN;
136 if (s2 == NULL)
137 return INT_MAX;
139 return strcmp(s1, s2);