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)
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");
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");
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");
216 _my_account_free(My_Account *acc)
221 _eet_string_free(acc->name);
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");
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)
269 _my_cache_account_find(My_Cache *my_cache,
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)
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);
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]);
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]);
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]);
474 printf(
"\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
475 acc->id, acc->name ? acc->name :
"",
482 const My_Message *msg;
483 printf(
"\t |messages:\n");
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);
515 if (!_my_cache_save(my_cache, argv[2]))
518 _my_cache_free(my_cache);
523 _my_cache_descriptor_shutdown();
void eina_stringshare_del(Eina_Stringshare *str)
Note that the given string has lost an instance.
Definition: eina_stringshare.c:537
Eina_Stringshare * eina_stringshare_add(const char *str)
Retrieve an instance of a string for use in a program.
Definition: eina_stringshare.c:610
#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:3340
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:1502
#define rename(src, dst)
Wrapper around evil_rename().
Definition: evil_stdio.h:226
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:2357
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:311
struct _Eet_File Eet_File
Opaque handle that defines an Eet file (or memory).
Definition: Eet.h:485
Eina_Bool eina_hash_direct_add(Eina_Hash *hash, const void *key, const void *data)
Add an entry to the given hash table without duplicating the string key.
Definition: eina_hash.c:911
Eina_Hash * eina_hash_string_small_new(Eina_Free_Cb data_free_cb)
Create a new hash table for use with strings with small bucket size.
Definition: eina_hash.c:762
void eina_iterator_free(Eina_Iterator *iterator)
Free an iterator.
Definition: eina_iterator.c:96
File is read-only.
Definition: Eet.h:466
EAPI int eet_shutdown(void)
Shut down the EET library.
Definition: eet_lib.c:622
int eina_init(void)
Initialize the Eina library.
Definition: eina_main.c:247
static unsigned int eina_list_count(const Eina_List *list)
Get the count of the number of items in a list.
#define EET_DATA_DESCRIPTOR_ADD_HASH(edd, struct_type, name, member, subtype)
Add a hash type to a data descriptor.
Definition: Eet.h:3195
void eina_hash_foreach(const Eina_Hash *hash, Eina_Hash_Foreach func, const void *fdata)
Call a function on every member stored in the hash table.
Definition: eina_hash.c:1187
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:2104
#define EET_T_STRING
Data type: char *.
Definition: Eet.h:2379
#define EINA_ITERATOR_FOREACH(itr,data)
Macro to iterate over all elements easily.
Definition: eina_iterator.h:332
#define EET_T_UINT
Data type: unsigned int.
Definition: Eet.h:2377
void eina_hash_free(Eina_Hash *hash)
Free the given hash table resources.
Definition: eina_hash.c:830
struct _Eet_Dictionary Eet_Dictionary
Opaque handle that defines a file-backed (mmaped) dictionary of strings.
Definition: Eet.h:491
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:499
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:317
int eina_shutdown(void)
Shut down the Eina library.
Definition: eina_main.c:317
Eina_List * eina_list_append(Eina_List *list, const void *data)
Append the given data to the given linked list.
Definition: eina_list.c:530
The file that provides the eet functions.
struct _Eina_Hash Eina_Hash
Type for a generic hash table.
Definition: eina_hash.h:288
File is write-only.
Definition: Eet.h:467
EAPI size_t eina_strlcpy(char *dst, const char *src, size_t siz) EINA_ARG_NONNULL(1
Copy a c-string to another.
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:2323
Instructs Eet about memory management for different needs under serialization and parse process...
Definition: Eet.h:2473
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:305
#define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype)
Add a linked list type to a data descriptor.
Definition: Eet.h:3145
EAPI Eet_Error eet_close(Eet_File *ef)
Close an eet file handle and flush pending writes.
Definition: eet_lib.c:1752
struct _Eet_Data_Descriptor Eet_Data_Descriptor
Opaque handle that have information on a type members.
Definition: Eet.h:2421
#define EINA_LIST_FREE(list, data)
Macro to remove each list node while having access to each node's data.
Definition: eina_list.h:1599
void * eina_hash_find(const Eina_Hash *hash, const void *key)
Retrieve a specific entry in the given hash table.
Definition: eina_hash.c:1033
Eina_Iterator * eina_hash_iterator_data_new(const Eina_Hash *hash)
Returned a new iterator associated to hash data.
Definition: eina_hash.c:1210
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:2090
structure of an iterator
Definition: eina_iterator.h:158
int eina_hash_population(const Eina_Hash *hash)
Returns the number of entries in the given hash table.
Definition: eina_hash.c:820
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:1387
#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:2720
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:2649
EAPI int eet_init(void)
Initialize the EET library.
Definition: eet_lib.c:539