15 const char *screen_name;
19 unsigned int status_id;
21 unsigned int timeline;
48 static const char MY_CACHE_FILE_ENTRY[] =
"cache";
59 static Eet_File *_my_cache_file = NULL;
63 _my_cache_descriptor_init(
void)
85 #define ADD_BASIC(member, eet_type) \ 86 EET_DATA_DESCRIPTOR_ADD_BASIC \ 87 (_my_message_descriptor, My_Message, # member, member, eet_type) 97 #define ADD_BASIC(member, eet_type) \ 98 EET_DATA_DESCRIPTOR_ADD_BASIC \ 99 (_my_post_descriptor, My_Post, # member, member, eet_type) 104 #define ADD_BASIC(member, eet_type) \ 105 EET_DATA_DESCRIPTOR_ADD_BASIC \ 106 (_my_account_descriptor, My_Account, # member, member, eet_type) 112 (_my_account_descriptor, My_Account,
"messages", messages,
113 _my_message_descriptor);
115 (_my_account_descriptor, My_Account,
"posts", posts,
116 _my_post_descriptor);
118 #define ADD_BASIC(member, eet_type) \ 119 EET_DATA_DESCRIPTOR_ADD_BASIC \ 120 (_my_cache_descriptor, My_Cache, # member, member, eet_type) 125 (_my_cache_descriptor, My_Cache,
"accounts", accounts,
126 _my_account_descriptor);
130 _my_cache_descriptor_shutdown(
void)
141 _eet_string_free(
const char *str)
149 eina_stringshare_del(str);
153 _my_message_new(
const char *message)
155 My_Message *msg = calloc(1,
sizeof(My_Message));
158 fprintf(stderr,
"ERROR: could not calloc My_Message\n");
162 msg->message = eina_stringshare_add(message);
167 _my_message_free(My_Message *msg)
169 _eet_string_free(msg->screen_name);
170 _eet_string_free(msg->name);
171 _eet_string_free(msg->message);
176 _my_post_add(My_Account *acc,
179 int new_count = acc->posts_count + 1;
180 My_Post *post = realloc(acc->posts, new_count *
sizeof(My_Post));
183 fprintf(stderr,
"ERROR: could add My_Post\n");
187 post[acc->posts_count].message = eina_stringshare_add(message);
188 post[acc->posts_count].dm_to = NULL;
189 acc->posts_count = new_count;
195 _my_post_free(My_Post *post)
197 _eet_string_free(post->dm_to);
198 _eet_string_free(post->message);
202 _my_account_new(
const char *name)
204 My_Account *acc = calloc(1,
sizeof(My_Account));
207 fprintf(stderr,
"ERROR: could not calloc My_Account\n");
211 acc->name = eina_stringshare_add(name);
216 _my_account_free(My_Account *acc)
221 _eet_string_free(acc->name);
223 EINA_LIST_FREE(acc->messages, m)
226 for (i = 0; i < acc->posts_count; i++)
227 _my_post_free(&acc->posts[i]);
236 My_Cache *my_cache = calloc(1,
sizeof(My_Cache));
239 fprintf(stderr,
"ERROR: could not calloc My_Cache\n");
243 my_cache->accounts = eina_hash_string_small_new(NULL);
245 my_cache->version = 1;
250 _my_cache_account_free_cb(
const Eina_Hash *hash,
255 _my_account_free(data);
260 _my_cache_free(My_Cache *my_cache)
263 eina_hash_foreach(my_cache->accounts, _my_cache_account_free_cb, NULL);
264 eina_hash_free(my_cache->accounts);
269 _my_cache_account_find(My_Cache *my_cache,
272 return eina_hash_find(my_cache->accounts, name);
276 _my_cache_load(
const char *filename)
282 fprintf(stderr,
"ERROR: could not open '%s' for read\n", filename);
286 my_cache =
eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY);
293 if (my_cache->version < 1)
296 "WARNING: version %#x was too old, upgrading it to %#x\n",
297 my_cache->version, 1);
299 my_cache->version = 1;
312 _my_cache_save(
const My_Cache *my_cache,
313 const char *filename)
321 len = eina_strlcpy(tmp, filename,
sizeof(tmp));
322 if (len + 12 >= (
int)
sizeof(tmp))
324 fprintf(stderr,
"ERROR: file name is too big: %s\n", filename);
331 snprintf(tmp + len, 12,
".%u", i);
334 while (stat(tmp, &st) == 0);
339 fprintf(stderr,
"ERROR: could not open '%s' for write\n", tmp);
344 (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE);
359 rename(tmp, filename);
370 const Eina_List *l_acc;
378 "Usage:\n\t%s <input> <output> [action] [action-params]\n\n" 379 "Where actions and their parameters:\n" 381 "\tpost <account-name> <message>\n" 382 "\tmessage <account-name> <message>\n" 390 _my_cache_descriptor_init();
392 my_cache = _my_cache_load(argv[1]);
395 printf(
"creating new cache.\n");
396 my_cache = _my_cache_new();
406 if (strcmp(argv[3],
"acc") == 0)
410 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
413 acc = _my_account_new(argv[4]);
414 eina_hash_direct_add(my_cache->accounts, acc->name, acc);
417 fprintf(stderr,
"ERROR: account '%s' already exists.\n",
422 "ERROR: wrong number of parameters (%d).\n",
425 else if (strcmp(argv[3],
"post") == 0)
429 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
432 _my_post_add(acc, argv[5]);
435 fprintf(stderr,
"ERROR: unknown account: '%s'\n", argv[4]);
439 "ERROR: wrong number of parameters (%d).\n",
442 else if (strcmp(argv[3],
"message") == 0)
446 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
449 My_Message *msg = _my_message_new(argv[5]);
450 acc->messages = eina_list_append(acc->messages, msg);
453 fprintf(stderr,
"ERROR: unknown account: '%s'\n", argv[4]);
457 "ERROR: wrong number of parameters (%d).\n",
461 fprintf(stderr,
"ERROR: unknown action '%s'\n", argv[2]);
468 eina_hash_population(my_cache->accounts));
469 it = eina_hash_iterator_data_new(my_cache->accounts);
470 EINA_ITERATOR_FOREACH(it, acc)
474 printf(
"\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
475 acc->id, acc->name ? acc->name :
"",
476 eina_list_count(acc->messages),
479 if (eina_list_count(acc->messages))
482 const My_Message *msg;
483 printf(
"\t |messages:\n");
485 EINA_LIST_FOREACH(acc->messages, l, msg)
487 printf(
"\t | %-8x '%s' [%s]: '%.20s'\n",
489 msg->name ? msg->name :
"",
490 msg->screen_name ? msg->screen_name :
"",
491 msg->message ? msg->message :
"");
495 if (acc->posts_count)
499 printf(
"\t |posts:\n");
501 for (i = 0; i < acc->posts_count; i++)
503 post = &acc->posts[i];
505 printf(
"\t | @%s: '%.20s'\n", post->dm_to, post->message);
507 printf(
"\t | '%.20s'\n", post->message);
513 eina_iterator_free(it);
515 if (!_my_cache_save(my_cache, argv[2]))
518 _my_cache_free(my_cache);
523 _my_cache_descriptor_shutdown();
#define EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, struct_type, name, member, subtype)
Add a variable size array type to a data descriptor.
Definition: Eet.h:3288
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:1419
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:2164
Definition: Eet_private.h:74
File is read-only.
Definition: Eet.h:513
EAPI int eet_shutdown(void)
Shut down the EET library.
Definition: eet_lib.c:634
#define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype)
Add a hash type to a data descriptor.
Definition: Eet.h:3143
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:1920
#define EET_T_STRING
Data type: char *.
Definition: Eet.h:2363
#define EET_T_UINT
Data type: unsigned int.
Definition: Eet.h:2361
EAPI int eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
Check if a given string comes from a given dictionary.
Definition: eet_dictionary.c:486
The file that provides the eet functions.
File is write-only.
Definition: Eet.h:514
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:2132
Instructs Eet about memory management for different needs under serialization and parse process...
Definition: Eet.h:2455
#define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype)
Add a linked list type to a data descriptor.
Definition: Eet.h:3093
EAPI Eet_Error eet_close(Eet_File *ef)
Close an eet file handle and flush pending writes.
Definition: eet_lib.c:1659
struct _Eet_Data_Descriptor Eet_Data_Descriptor
Opaque handle that have information on a type members.
Definition: Eet.h:2403
EAPI Eet_Data_Descriptor * eet_data_descriptor_file_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:1914
Definition: Eet_private.h:40
#define EET_EINA_FILE_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:2702
EAPI Eet_Dictionary * eet_dictionary_get(Eet_File *ef)
Return a handle to the shared string dictionary of the Eet file.
Definition: eet_lib.c:2553
EAPI int eet_init(void)
Initialize the EET library.
Definition: eet_lib.c:553