-
Notifications
You must be signed in to change notification settings - Fork 1
/
gy_property.c
108 lines (93 loc) · 3.07 KB
/
gy_property.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright 2013 Thibaut Paumard
This file is part of gy (GObject Introspection for Yorick).
Gyoto 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 3 of the License, or
(at your option) any later version.
Gyoto 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 gy. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gy.h"
GIPropertyInfo *
gy_base_info_find_property_info(GIBaseInfo * objectinfo, char * name)
{
if (GI_IS_STRUCT_INFO(objectinfo)) return NULL;
gboolean isobject = GI_IS_OBJECT_INFO(objectinfo);
gint iprop, nprop = isobject?
g_object_info_get_n_properties(objectinfo):
g_interface_info_get_n_properties(objectinfo);
GIPropertyInfo * cur=NULL;
int hyphenize;
char * oname = NULL;
for (hyphenize=0; hyphenize<=1; ++hyphenize) {
if (hyphenize) {
GY_DEBUG("Property %s not found, trying to replace underscores with hyphens\n", name);
oname = p_strcpy(name);
g_strdelimit(name, "_", '-');
if (!strcmp(name, oname)) {
p_free(oname);
return NULL;
}
}
for (iprop=0; iprop<nprop; ++iprop) {
GY_DEBUG("i=%d/%d\n", iprop, nprop);
cur = isobject?
g_object_info_get_property (objectinfo, iprop):
g_interface_info_get_property (objectinfo, iprop);
GY_DEBUG("comparing %s with %s\n", name, g_base_info_get_name(cur));
if (!strcmp(name, g_base_info_get_name(cur))) {
GY_DEBUG("found it\n");
p_free(oname);
return cur;
}
g_base_info_unref(cur);
}
}
strcpy(name, oname);
p_free(oname);
return NULL;
}
GIPropertyInfo *
gy_base_info_find_field_info(GIBaseInfo * objectinfo, char * name)
{
if (GI_IS_INTERFACE_INFO(objectinfo)) return NULL;
gboolean isobject = GI_IS_OBJECT_INFO(objectinfo);
gint iprop, nprop = isobject?
g_object_info_get_n_fields(objectinfo):
g_struct_info_get_n_fields(objectinfo);
GIFieldInfo * cur=NULL;
int hyphenize;
char * oname = NULL;
for (hyphenize=0; hyphenize<=1; ++hyphenize) {
if (hyphenize) {
GY_DEBUG("Field %s not found, trying to replace underscores with hyphens\n", name);
oname = p_strcpy(name);
g_strdelimit(name, "_", '-');
if (!strcmp(name, oname)) {
p_free(oname);
return NULL;
}
}
for (iprop=0; iprop<nprop; ++iprop) {
GY_DEBUG("i=%d/%d\n", iprop, nprop);
cur = isobject?
g_object_info_get_field (objectinfo, iprop):
g_struct_info_get_field (objectinfo, iprop);
GY_DEBUG("comparing %s with %s\n", name, g_base_info_get_name(cur));
if (!strcmp(name, g_base_info_get_name(cur))) {
GY_DEBUG("found it\n");
p_free(oname);
return cur;
}
g_base_info_unref(cur);
}
}
strcpy(name, oname);
p_free(oname);
return NULL;
}