summaryrefslogtreecommitdiff
path: root/legacy/eet/src/examples/eet-data-simple.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
commit926db95c5476a7e58ae30873227140b627fc292d (patch)
tree921fa2fb03c97910853287c1a15379175e845994 /legacy/eet/src/examples/eet-data-simple.c
parentba10bce4342f61992ceaf06dc6299639cac83a81 (diff)
testing uncrustify on eet. this shall be standard efl formatting from
now on. you may run indent on code and convert to your own formatting if you want.. but all code MUST be "uncrustified" before being cxommitted to svn or before generating patches. time to get the formatting monster under control. SVN revision: 50563
Diffstat (limited to '')
-rw-r--r--legacy/eet/src/examples/eet-data-simple.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/legacy/eet/src/examples/eet-data-simple.c b/legacy/eet/src/examples/eet-data-simple.c
index 72d00c96d9..a4efd4ad7a 100644
--- a/legacy/eet/src/examples/eet-data-simple.c
+++ b/legacy/eet/src/examples/eet-data-simple.c
@@ -11,7 +11,8 @@
11// will be automatically handled. The other members will have their 11// will be automatically handled. The other members will have their
12// space reserved and zeroed (as it uses calloc()), but not 12// space reserved and zeroed (as it uses calloc()), but not
13// saved or loaded from eet files. 13// saved or loaded from eet files.
14typedef struct { 14typedef struct
15{
15 unsigned int version; // it is recommended to use versioned configuration! 16 unsigned int version; // it is recommended to use versioned configuration!
16 const char *name; 17 const char *name;
17 int id; 18 int id;
@@ -52,13 +53,13 @@ _my_conf_descriptor_init(void)
52 53
53 // Describe the members to be saved: 54 // Describe the members to be saved:
54 // Use a temporary macro so we don't type a lot, also avoid errors: 55 // Use a temporary macro so we don't type a lot, also avoid errors:
55#define MY_CONF_ADD_BASIC(member, eet_type) \ 56#define MY_CONF_ADD_BASIC(member, eet_type) \
56 EET_DATA_DESCRIPTOR_ADD_BASIC \ 57 EET_DATA_DESCRIPTOR_ADD_BASIC \
57 (_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) 58 (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
58 59
59 MY_CONF_ADD_BASIC(version, EET_T_UINT); 60 MY_CONF_ADD_BASIC(version, EET_T_UINT);
60 MY_CONF_ADD_BASIC(name, EET_T_STRING); 61 MY_CONF_ADD_BASIC(name, EET_T_STRING);
61 MY_CONF_ADD_BASIC(id, EET_T_INT); 62 MY_CONF_ADD_BASIC(id, EET_T_INT);
62 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); 63 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
63 64
64#undef MY_CONF_ADD_BASIC 65#undef MY_CONF_ADD_BASIC
@@ -76,8 +77,8 @@ _my_conf_new(void)
76 My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); 77 My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
77 if (!my_conf) 78 if (!my_conf)
78 { 79 {
79 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); 80 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
80 return NULL; 81 return NULL;
81 } 82 }
82 83
83 my_conf->version = 0x112233; 84 my_conf->version = 0x112233;
@@ -99,25 +100,25 @@ _my_conf_load(const char *filename)
99 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); 100 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
100 if (!ef) 101 if (!ef)
101 { 102 {
102 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); 103 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
103 return NULL; 104 return NULL;
104 } 105 }
105 106
106 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); 107 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
107 if (!my_conf) 108 if (!my_conf)
108 goto end; 109 goto end;
109 110
110 if (my_conf->version < 0x112233) 111 if (my_conf->version < 0x112233)
111 { 112 {
112 fprintf(stderr, 113 fprintf(stderr,
113 "WARNING: version %#x was too old, upgrading it to %#x\n", 114 "WARNING: version %#x was too old, upgrading it to %#x\n",
114 my_conf->version, 0x112233); 115 my_conf->version, 0x112233);
115 116
116 my_conf->version = 0x112233; 117 my_conf->version = 0x112233;
117 my_conf->enabled = EINA_TRUE; 118 my_conf->enabled = EINA_TRUE;
118 } 119 }
119 120
120 end: 121end:
121 eet_close(ef); 122 eet_close(ef);
122 return my_conf; 123 return my_conf;
123} 124}
@@ -134,33 +135,33 @@ _my_conf_save(const My_Conf_Type *my_conf, const char *filename)
134 len = eina_strlcpy(tmp, filename, sizeof(tmp)); 135 len = eina_strlcpy(tmp, filename, sizeof(tmp));
135 if (len + 12 >= (int)sizeof(tmp)) 136 if (len + 12 >= (int)sizeof(tmp))
136 { 137 {
137 fprintf(stderr, "ERROR: file name is too big: %s\n", filename); 138 fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
138 return EINA_FALSE; 139 return EINA_FALSE;
139 } 140 }
140 141
141 i = 0; 142 i = 0;
142 do 143 do
143 { 144 {
144 snprintf(tmp + len, 12, ".%u", i); 145 snprintf(tmp + len, 12, ".%u", i);
145 i++; 146 i++;
146 } 147 }
147 while (stat(tmp, &st) == 0); 148 while (stat(tmp, &st) == 0);
148 149
149 ef = eet_open(tmp, EET_FILE_MODE_WRITE); 150 ef = eet_open(tmp, EET_FILE_MODE_WRITE);
150 if (!ef) 151 if (!ef)
151 { 152 {
152 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); 153 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
153 return EINA_FALSE; 154 return EINA_FALSE;
154 } 155 }
155 156
156 ret = eet_data_write 157 ret = eet_data_write
157 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); 158 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
158 eet_close(ef); 159 eet_close(ef);
159 160
160 if (ret) 161 if (ret)
161 { 162 {
162 unlink(filename); 163 unlink(filename);
163 rename(tmp, filename); 164 rename(tmp, filename);
164 } 165 }
165 166
166 return ret; 167 return ret;
@@ -173,8 +174,8 @@ int main(int argc, char *argv[])
173 174
174 if (argc != 3) 175 if (argc != 3)
175 { 176 {
176 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]); 177 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
177 return -1; 178 return -1;
178 } 179 }
179 180
180 eina_init(); 181 eina_init();
@@ -184,31 +185,31 @@ int main(int argc, char *argv[])
184 my_conf = _my_conf_load(argv[1]); 185 my_conf = _my_conf_load(argv[1]);
185 if (!my_conf) 186 if (!my_conf)
186 { 187 {
187 printf("creating new configuration.\n"); 188 printf("creating new configuration.\n");
188 my_conf = _my_conf_new(); 189 my_conf = _my_conf_new();
189 if (!my_conf) 190 if (!my_conf)
190 { 191 {
191 ret = -2; 192 ret = -2;
192 goto end; 193 goto end;
193 } 194 }
194 } 195 }
195 196
196 printf("My_Conf_Type:\n" 197 printf("My_Conf_Type:\n"
197 "\tversion: %#x\n" 198 "\tversion: %#x\n"
198 "\tname...: '%s'\n" 199 "\tname...: '%s'\n"
199 "\tid.....: %d\n" 200 "\tid.....: %d\n"
200 "\tenabled: %hhu\n", 201 "\tenabled: %hhu\n",
201 my_conf->version, 202 my_conf->version,
202 my_conf->name ? my_conf->name : "", 203 my_conf->name ? my_conf->name : "",
203 my_conf->id, 204 my_conf->id,
204 my_conf->enabled); 205 my_conf->enabled);
205 206
206 if (!_my_conf_save(my_conf, argv[2])) 207 if (!_my_conf_save(my_conf, argv[2]))
207 ret = -3; 208 ret = -3;
208 209
209 _my_conf_free(my_conf); 210 _my_conf_free(my_conf);
210 211
211 end: 212end:
212 _my_conf_descriptor_shutdown(); 213 _my_conf_descriptor_shutdown();
213 eet_shutdown(); 214 eet_shutdown();
214 eina_shutdown(); 215 eina_shutdown();