[build] Updated to compile cpml-util
[adg.git] / adg / adg-util.c
blob8cb538d9d08d62760d56b3bbca7b214fcda8c6c0
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. It is equivalent to a typical
35 * struct forward declaration, for example:
37 * |[
38 * ADG_FORWARD_DECL(test)
39 * ]|
41 * will expand to:
43 * |[
44 * typedef struct _test test
45 * ]|
47 * This macro is needed to fake <command>gtk-doc</command>, because
48 * up to now (v.1.12) it generates two conflicting links when using
49 * forward declarations: the first in the source with the declaration
50 * and the second where the type is defined. Using ADG_FORWARD_DECL()
51 * instead of the usual typedef avoids the parsing of the declaration
52 * in the first file (<command>gtk-doc</command> is not able to do C
53 * preprocessing).
55 * The same principle can be applied in the definition file. Following
56 * the previous example, you can use something like this where struct
57 * _type is defined:
59 * |[
60 * #if 0
61 * // This is declared in another file
62 * typedef struct _type type;
63 * #endif
64 * struct _type {
65 * ...
66 * };
67 * ]|
68 **/
71 #include <string.h>
72 #include <limits.h>
75 /**
76 * adg_strcmp:
77 * @s1: first string to compare
78 * @s2: second string to compare
80 * A strcmp() function guarded against %NULL values. It works in the
81 * same way exept for the following situations:
83 * <itemizedlist>
84 * <listitem><code>s1 == NULL && s2 == NULL</code>: returns %0;</listitem>
85 * <listitem><code>s1 == NULL</code>: returns %INT_MIN;</listitem>
86 * <listitem><code>s2 == NULL</code>: returns %INT_MAX.</listitem>
87 * </itemizedlist>
89 * Returns: %0 if @s1 matches @s2, a value less than %0 if @s1 is less
90 * than @s2 or greather than %0 if @s1 is greather than @s2
91 **/
92 int
93 adg_strcmp(const char *s1, const char *s2)
95 /* This will also catch the NULL == NULL case */
96 if (s1 == s2)
97 return 0;
99 if (s1 == NULL)
100 return INT_MIN;
102 if (s2 == NULL)
103 return INT_MAX;
105 return strcmp(s1, s2);