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;
113 sub = calloc(1,
sizeof(My_Conf_Subtype));
125 _my_conf_free(My_Conf_Type *my_conf)
127 My_Conf_Subtype *sub;
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;
169 _my_conf_save(
const My_Conf_Type *my_conf,
170 const char *filename)
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 :
"",
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();
EAPI void eina_stringshare_del(Eina_Stringshare *str)
Note that the given string has lost an instance.
Definition: eina_stringshare.c:537
EAPI Eina_Stringshare * eina_stringshare_add(const char *str)
Retrieve an instance of a string for use in a program.
Definition: eina_stringshare.c:610
EAPI Eet_File * eet_open(const char *file, Eet_File_Mode mode)
Open an eet file on disk, and returns a handle to it.
Definition: eet_lib.c:1491
EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress)
Write a data structure from memory and store in an eet file.
Definition: eet_data.c:2411
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:338
struct _Eet_File Eet_File
Opaque handle that defines an Eet file (or memory).
Definition: Eet.h:518
File is read-only.
Definition: Eet.h:475
EAPI int eet_shutdown(void)
Shut down the EET library.
Definition: eet_lib.c:607
#define EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(clas, type)
This macro is an helper that set all the parameter of an Eet_Data_Descriptor_Class correctly when you...
Definition: Eet.h:3024
int eina_init(void)
Initialize the Eina library.
Definition: eina_main.c:250
EAPI void eet_data_descriptor_free(Eet_Data_Descriptor *edd)
This function frees a data descriptor when it is not needed anymore.
Definition: eet_data.c:2110
#define EET_T_STRING
Data type: char *.
Definition: Eet.h:2580
#define EET_T_UINT
Data type: unsigned int.
Definition: Eet.h:2578
#define EET_T_UCHAR
Data type: unsigned char.
Definition: Eet.h:2576
#define EET_T_INT
Data type: int.
Definition: Eet.h:2572
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:344
int eina_shutdown(void)
Shut down the Eina library.
Definition: eina_main.c:316
Eina_List * eina_list_append(Eina_List *list, const void *data)
Append the given data to the given linked list.
Definition: eina_list.c:550
The file that provides the eet functions.
File is write-only.
Definition: Eet.h:476
EAPI size_t eina_strlcpy(char *dst, const char *src, size_t siz) EINA_ARG_NONNULL(1
Copy a c-string to another.
EAPI Eet_Data_Descriptor * eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
This function creates a new data descriptor and returns a handle to the new data descriptor.
Definition: eet_data.c:2090
EAPI void * eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name)
Read a data structure from an eet file and decodes it.
Definition: eet_data.c:2377
Instructs Eet about memory management for different needs under serialization and parse process...
Definition: Eet.h:2818
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:332
#define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype)
Add a linked list type to a data descriptor.
Definition: Eet.h:3499
EAPI Eet_Error eet_close(Eet_File *ef)
Close an eet file handle and flush pending writes.
Definition: eet_lib.c:1891
struct _Eet_Data_Descriptor Eet_Data_Descriptor
Opaque handle that have information on a type members.
Definition: Eet.h:2622
#define EINA_LIST_FREE(list, data)
Macro to remove each list node while having access to each node's data.
Definition: eina_list.h:1626
Type for a generic double linked list.
Definition: eina_list.h:320
#define EINA_LIST_FOREACH(list, l, data)
Macro to iterate over a list.
Definition: eina_list.h:1414
EAPI int eet_init(void)
Initialize the EET library.
Definition: eet_lib.c:553