[docs] Updated TODO.xml
[adg.git] / adg / adg-util.c
blob0ac000172e08f98f903eec108d1a8ca638a1ae7e
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_FORWARD_DECL:
32 * @id: The name of a struct
34 * Forward declaration of struct @id. For example,
35 * <code>ADG_FORWARD_DECL(test)</code> will expand to:
37 * <informalexample><programlisting>
38 * typedef struct _test test
39 * </programlisting></informalexample>
41 * This macro is useful to trick <command>gtk-doc</command>, as up
42 * to now (v.1.12) it generates two conflicting links when using
43 * forward declarations: the first in the source with the declaration
44 * and the second where the type is defined. Using ADG_FORWARD_DECL()
45 * instead of the usual typedef avoids the parsing of the declaration
46 * in the first file (<command>gtk-doc</command> is not able to do C
47 * preprocessing).
49 * The same principle can be applied in the definition file. Following
50 * the previous example, you can use something like this where struct
51 * _type is defined:
53 * <informalexample><programlisting>
54 * #if 0
55 * // This is declared in another file
56 * typedef struct _type type;
57 * #endif
58 * struct _type {
59 * ...
60 * };
61 * </programlisting></informalexample>
62 **/
65 #include <string.h>
66 #include <limits.h>
69 /**
70 * adg_strcmp:
71 * @s1: first string to compare
72 * @s2: second string to compare
74 * A strcmp() function guarded against %NULL values. It works in the
75 * same way exept for the following situations:
77 * <itemizedlist>
78 * <listitem><code>s1 == NULL && s2 == NULL</code>: returns %0;</listitem>
79 * <listitem><code>s1 == NULL</code>: returns %INT_MIN;</listitem>
80 * <listitem><code>s2 == NULL</code>: returns %INT_MAX.</listitem>
81 * </itemizedlist>
83 * Returns: %0 if @s1 matches @s2, a value less than %0 if @s1 is less
84 * than @s2 or greather than %0 if @s1 is greather than @s2
85 **/
86 int
87 adg_strcmp(const char *s1, const char *s2)
89 /* This will also catch the NULL == NULL case */
90 if (s1 == s2)
91 return 0;
93 if (s1 == NULL)
94 return INT_MIN;
96 if (s2 == NULL)
97 return INT_MAX;
99 return strcmp(s1, s2);