36 static const char MY_CONF_FILE_ENTRY[] =
"config";
45 _my_conf_descriptor_init(
void)
69 #define MY_CONF_ADD_BASIC(member, eet_type) \
70 EET_DATA_DESCRIPTOR_ADD_BASIC \
71 (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
72 #define MY_CONF_SUB_ADD_BASIC(member, eet_type) \
73 EET_DATA_DESCRIPTOR_ADD_BASIC \
74 (_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type)
86 (_my_conf_descriptor, My_Conf_Type,
"subs", subs, _my_conf_sub_descriptor);
88 #undef MY_CONF_ADD_BASIC
89 #undef MY_CONF_SUB_ADD_BASIC
93 _my_conf_descriptor_shutdown(
void)
102 My_Conf_Type *my_conf = calloc(1,
sizeof(My_Conf_Type));
103 My_Conf_Subtype *sub;
106 fprintf(stderr,
"ERROR: could not calloc My_Conf_Type\n");
110 my_conf->version = 0x112233;
111 my_conf->enabled = EINA_TRUE;
113 sub = calloc(1,
sizeof(My_Conf_Subtype));
116 sub->server = eina_stringshare_add(
"my-server.com");
118 my_conf->subs = eina_list_append(my_conf->subs, sub);
125 _my_conf_free(My_Conf_Type *my_conf)
127 My_Conf_Subtype *sub;
128 EINA_LIST_FREE(my_conf->subs, sub)
130 eina_stringshare_del(sub->server);
134 eina_stringshare_del(my_conf->name);
138 static My_Conf_Type *
139 _my_conf_load(
const char *filename)
141 My_Conf_Type *my_conf;
145 fprintf(stderr,
"ERROR: could not open '%s' for read\n", filename);
149 my_conf =
eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
153 if (my_conf->version < 0x112233)
156 "WARNING: version %#x was too old, upgrading it to %#x\n",
157 my_conf->version, 0x112233);
159 my_conf->version = 0x112233;
160 my_conf->enabled = EINA_TRUE;
169 _my_conf_save(
const My_Conf_Type *my_conf,
170 const char *filename)
178 len = eina_strlcpy(tmp, filename,
sizeof(tmp));
179 if (len + 12 >= (
int)
sizeof(tmp))
181 fprintf(stderr,
"ERROR: file name is too big: %s\n", filename);
188 snprintf(tmp + len, 12,
".%u", i);
191 while (stat(tmp, &st) == 0);
196 fprintf(stderr,
"ERROR: could not open '%s' for write\n", tmp);
201 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
207 rename(tmp, filename);
217 My_Conf_Type *my_conf;
218 const My_Conf_Subtype *sub;
224 fprintf(stderr,
"Usage:\n\t%s <input> <output>\n\n", argv[0]);
230 _my_conf_descriptor_init();
232 my_conf = _my_conf_load(argv[1]);
235 printf(
"creating new configuration.\n");
236 my_conf = _my_conf_new();
244 printf(
"My_Conf_Type:\n"
251 my_conf->name ? my_conf->name :
"",
255 EINA_LIST_FOREACH(my_conf->subs, l, sub)
256 printf("\t\tserver: '%s', port: %d\n",
257 sub->server ? sub->server : "",
260 if (!_my_conf_save(my_conf, argv[2]))
263 _my_conf_free(my_conf);
266 _my_conf_descriptor_shutdown();