2 * Copyright © 2001 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Red Hat not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. Red Hat makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Author: Owen Taylor, Red Hat, Inc.
27 #include <X11/Xmd.h> /* For CARD32 */
29 #include "xsettings-common.h"
32 xsettings_setting_copy (XSettingsSetting
*setting
)
34 XSettingsSetting
*result
;
37 result
= malloc (sizeof *result
);
41 str_len
= strlen (setting
->name
);
42 result
->name
= malloc (str_len
+ 1);
46 memcpy (result
->name
, setting
->name
, str_len
+ 1);
48 result
->type
= setting
->type
;
50 switch (setting
->type
)
52 case XSETTINGS_TYPE_INT
:
53 result
->data
.v_int
= setting
->data
.v_int
;
55 case XSETTINGS_TYPE_COLOR
:
56 result
->data
.v_color
= setting
->data
.v_color
;
58 case XSETTINGS_TYPE_STRING
:
59 str_len
= strlen (setting
->data
.v_string
);
60 result
->data
.v_string
= malloc (str_len
+ 1);
61 if (!result
->data
.v_string
)
64 memcpy (result
->data
.v_string
, setting
->data
.v_string
, str_len
+ 1);
70 result
->last_change_serial
= setting
->last_change_serial
;
83 xsettings_list_copy (XSettingsList
*list
)
85 XSettingsList
*new = NULL
;
86 XSettingsList
*old_iter
= list
;
87 XSettingsList
*new_iter
= NULL
;
91 XSettingsList
*new_node
;
93 new_node
= malloc (sizeof *new_node
);
97 new_node
->setting
= xsettings_setting_copy (old_iter
->setting
);
98 if (!new_node
->setting
)
105 new_iter
->next
= new_node
;
111 old_iter
= old_iter
->next
;
117 xsettings_list_free (new);
122 xsettings_setting_equal (XSettingsSetting
*setting_a
,
123 XSettingsSetting
*setting_b
)
125 if (setting_a
->type
!= setting_b
->type
)
128 if (strcmp (setting_a
->name
, setting_b
->name
) != 0)
131 switch (setting_a
->type
)
133 case XSETTINGS_TYPE_INT
:
134 return setting_a
->data
.v_int
== setting_b
->data
.v_int
;
135 case XSETTINGS_TYPE_COLOR
:
136 return (setting_a
->data
.v_color
.red
== setting_b
->data
.v_color
.red
&&
137 setting_a
->data
.v_color
.green
== setting_b
->data
.v_color
.green
&&
138 setting_a
->data
.v_color
.blue
== setting_b
->data
.v_color
.blue
&&
139 setting_a
->data
.v_color
.alpha
== setting_b
->data
.v_color
.alpha
);
140 case XSETTINGS_TYPE_STRING
:
141 return strcmp (setting_a
->data
.v_string
, setting_b
->data
.v_string
) == 0;
150 xsettings_setting_free (XSettingsSetting
*setting
)
152 if (setting
->type
== XSETTINGS_TYPE_STRING
)
153 free (setting
->data
.v_string
);
156 free (setting
->name
);
162 xsettings_list_free (XSettingsList
*list
)
166 XSettingsList
*next
= list
->next
;
168 xsettings_setting_free (list
->setting
);
176 xsettings_list_insert (XSettingsList
**list
,
177 XSettingsSetting
*setting
)
181 XSettingsList
*last
= NULL
;
183 node
= malloc (sizeof *node
);
185 return XSETTINGS_NO_MEM
;
186 node
->setting
= setting
;
191 int cmp
= strcmp (setting
->name
, iter
->setting
->name
);
198 return XSETTINGS_DUPLICATE_ENTRY
;
212 return XSETTINGS_SUCCESS
;
216 xsettings_list_delete (XSettingsList
**list
,
220 XSettingsList
*last
= NULL
;
225 if (strcmp (name
, iter
->setting
->name
) == 0)
228 last
->next
= iter
->next
;
232 xsettings_setting_free (iter
->setting
);
235 return XSETTINGS_SUCCESS
;
242 return XSETTINGS_FAILED
;
246 xsettings_list_lookup (XSettingsList
*list
,
254 if (strcmp (name
, iter
->setting
->name
) == 0)
255 return iter
->setting
;
264 xsettings_byte_order (void)
266 CARD32 myint
= 0x01020304;
267 return (*(char *)&myint
== 1) ? MSBFirst
: LSBFirst
;