summaryrefslogtreecommitdiff
path: root/src/bin/eldbus/utils.c
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 11:40:05 -0300
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-04-23 12:36:29 -0300
commit4e3804041f8e865e007b2a6a0d45a05f39500c3b (patch)
treea493b9c8f8a610d2667651f3ba81819ed16fbe8c /src/bin/eldbus/utils.c
parent4cf68bf728b5a858ce1c0efac25ded1a49ba8d9d (diff)
Rename edbus->eldbus
git grep -l edbus2 | while read f; do sed -i 's/edbus2/eldbus/g' "$f"; done find . -name '*edbus2*' -exec rename edbus2 eldbus {} \; git grep -l "EDBUS" | while read f; do sed -i 's/EDBUS/ELDBUS/g' "$f"; done git grep -l "EDBus" | while read f; do sed -i 's/EDBus/Eldbus/g' "$f"; done git grep -l "edbus (v2)" | while read f; do sed -i 's/edbus (v2)/eldbus/g' "$f"; done git grep -l "Edbus" | while read f; do sed -i 's/Edbus/Eldbus/g' "$f"; done git grep -l "edbus" | while read f; do sed -i 's/edbus/eldbus/g' "$f"; done find . -name '*edbus*' -exec rename edbus eldbus {} \; find . -name '*EDBus*' -exec rename EDBus Eldbus {} \;
Diffstat (limited to 'src/bin/eldbus/utils.c')
-rw-r--r--src/bin/eldbus/utils.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/bin/eldbus/utils.c b/src/bin/eldbus/utils.c
new file mode 100644
index 0000000000..a020445e1d
--- /dev/null
+++ b/src/bin/eldbus/utils.c
@@ -0,0 +1,165 @@
1#include "codegen.h"
2#include <ctype.h>
3
4Eina_Bool
5file_read(const char *file_name, char **buffer)
6{
7 FILE *xml_handler;
8 int data; /* fgetc needs int to detect EOF correctly */
9 Eina_Strbuf *buf;
10
11 xml_handler = fopen(file_name, "rt");
12 if (!xml_handler)
13 {
14 printf("Error to read file: %s\n", file_name);
15 return EINA_FALSE;
16 }
17 buf = eina_strbuf_new();
18
19 while ((data = fgetc(xml_handler)) != EOF)
20 eina_strbuf_append_char(buf, (char)data);
21
22 fclose(xml_handler);
23 *buffer = eina_strbuf_string_steal(buf);
24 eina_strbuf_free(buf);
25
26 return EINA_TRUE;
27}
28
29Eina_Bool
30file_write(const char *file_name, const char *buffer)
31{
32 FILE *file_handler;
33
34 file_handler = fopen(file_name, "wt");
35 if (!file_handler)
36 {
37 printf("Error to write file: %s\n", file_name);
38 return EINA_FALSE;
39 }
40
41 fwrite(buffer, strlen(buffer), 1, file_handler);
42 fclose(file_handler);
43
44 return EINA_TRUE;
45}
46
47char *
48dbus_name_to_c(const char *dbus)
49{
50 char *str_cpy = strdup(dbus), *pch, *ret;
51 Eina_Strbuf *buffer = eina_strbuf_new();
52 unsigned i;
53
54 pch = strtok(str_cpy, "/.");
55 if (!pch)
56 {
57 ret = strdup("root");
58 goto end;
59 }
60 eina_strbuf_append(buffer, pch);
61
62 while ((pch = strtok(NULL, "/.")))
63 eina_strbuf_append_printf(buffer, "_%s",pch);
64
65 ret = eina_strbuf_string_steal(buffer);
66 for (i = 0; ret[i]; i++)
67 {
68 if (i > 0 && ret[i-1] != '_' && ret[i] > '@' && ret[i] < '[')//upper case
69 eina_strbuf_append_printf(buffer, "_%c", tolower(ret[i]));
70 else
71 eina_strbuf_append_char(buffer, tolower(ret[i]));
72 }
73 free(ret);
74 ret = eina_strbuf_string_steal(buffer);
75end:
76 free(str_cpy);
77 eina_strbuf_free(buffer);
78 return ret;
79}
80
81char *
82replace_string(const char *string, const char *substr, const char *replacement)
83{
84 char *str_cpy = strdup(string);
85 char *pch;
86 char *ret;
87 Eina_Strbuf *buffer = eina_strbuf_new();
88
89 pch = strtok(str_cpy, substr);
90 eina_strbuf_append(buffer, pch);
91
92 while ((pch = strtok(NULL, substr)))
93 eina_strbuf_append_printf(buffer, "%s%s", replacement, pch);
94
95 ret = eina_strbuf_string_steal(buffer);
96 free(str_cpy);
97 eina_strbuf_free(buffer);
98 return ret;
99}
100
101char *
102get_pieces(const char *string, char break_in, int amount)
103{
104 int i;
105 int found = 0;
106
107 for (i = strlen(string) - 1; i && amount > found; i--)
108 if (string[i] == break_in)
109 found++;
110
111 if (found)
112 return strdup(string+i+2);
113 else
114 return strdup(string);
115}
116
117char *
118string_build(const char *fmt, ...)
119{
120 va_list ap;
121 Eina_Strbuf *buffer = eina_strbuf_new();
122 char *ret;
123
124 va_start(ap, fmt);
125 eina_strbuf_prepend_vprintf(buffer, fmt, ap);
126 va_end(ap);
127
128 ret = eina_strbuf_string_steal(buffer);
129 eina_strbuf_free(buffer);
130
131 return ret;
132}
133
134#define UTIL_H "\
135#ifndef ELDBUS_UTILS_H\n\
136#define ELDBUS_UTILS_H 1\n\
137\n\
138typedef struct _Eldbus_Error_Info\n\
139{\n\
140 const char *error;\n\
141 const char *message;\n\
142} Eldbus_Error_Info;\n\
143\n\
144typedef void (*Eldbus_Codegen_Property_Set_Cb)(void *data, const char *propname, Eldbus_Proxy *proxy, Eldbus_Pending *p, Eldbus_Error_Info *error_info);\n\
145\n\
146typedef void (*Eldbus_Codegen_Property_String_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, const char *value);\n\
147typedef void (*Eldbus_Codegen_Property_Int32_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, int value);\n\
148typedef void (*Eldbus_Codegen_Property_Byte_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, unsigned char value);\n\
149typedef void (*Eldbus_Codegen_Property_Bool_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, Eina_Bool value);\n\
150typedef void (*Eldbus_Codegen_Property_Int16_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, short int value);\n\
151typedef void (*Eldbus_Codegen_Property_Uint16_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, unsigned short int value);\n\
152typedef void (*Eldbus_Codegen_Property_Uint32_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, unsigned int value);\n\
153typedef void (*Eldbus_Codegen_Property_Double_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, double value);\n\
154typedef void (*Eldbus_Codegen_Property_Int64_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, int64_t value);\n\
155typedef void (*Eldbus_Codegen_Property_Uint64_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, uint64_t value);\n\
156typedef void (*Eldbus_Codegen_Property_Complex_Get_Cb)(void *data, Eldbus_Pending *p, const char *propname, Eldbus_Proxy *proxy, Eldbus_Error_Info *error_info, Eina_Value *value);\n\
157\n\
158#endif\
159"
160
161Eina_Bool
162util_h_write(void)
163{
164 return file_write("eldbus_utils.h", UTIL_H);
165}