eet: add a more verbose eet -l.
authorcedric <cedric>
Wed, 31 Oct 2012 05:55:53 +0000 (05:55 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 31 Oct 2012 05:55:53 +0000 (05:55 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eet@78689 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/bin/eet_main.c
src/lib/Eet.h
src/lib/eet_lib.c

index 6afdc47..f490dfb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-10-04  Vincent Torri
 
        * Update lz4 code to rev. 77. This fix compilation on NetBSD 5.0
+
+2012-10-31  Cedric Bail
+
+       * Add eet_list_entries().
+       * Add eet -l -v to give more information about an eet file.
diff --git a/NEWS b/NEWS
index fdd882d..b6208e0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,11 @@
-Eet 1.7.1
+Eet 1.8.0
 
 Changes since Eet 1.7.0:
 --------------------------
 
+Improvements:
+    * Display more information with eet -l.
+
 Fixes:
     * Fix PPC (big endian) image codec bug.
 
index 8a93d11..eff7207 100644 (file)
@@ -44,11 +44,12 @@ static int _eet_main_log_dom = -1;
 #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_main_log_dom, __VA_ARGS__)
 
 static void
-do_eet_list(const char *file)
+do_eet_list(const char *file, Eina_Bool verbose)
 {
-   int i, num;
-   char **list;
+   Eina_Iterator *it;
+   Eet_Entry *entry;
    Eet_File *ef;
+   unsigned long long total = 0;
 
    ef = eet_open(file, EET_FILE_MODE_READ);
    if (!ef)
@@ -57,12 +58,38 @@ do_eet_list(const char *file)
         exit(-1);
      }
 
-   list = eet_list(ef, "*", &num);
-   if (list)
+   it = eet_list_entries(ef);
+   EINA_ITERATOR_FOREACH(it, entry)
      {
-        for (i = 0; i < num; i++)
-          printf("%s\n", list[i]);
-        free(list);
+        if (verbose)
+          {
+             if (entry->alias)
+               {
+                  printf("%s is an alias for %s\n",
+                         entry->name, eet_alias_get(ef, entry->name));
+               }
+             else
+               {
+                  if (entry->compression)
+                    printf("%s start at %i with a size of %i Bytes with an uncompressed size of %i Bytes.\n",
+                           entry->name, entry->offset, entry->size, entry->data_size);
+                  else
+                    printf("%s start at %i with a size of %i Bytes.\n",
+                           entry->name, entry->offset, entry->size);
+                  total += entry->size;
+               }
+          }
+        else
+          {
+             printf("%s\n", entry->name);
+          }
+     }
+   eina_iterator_free(it);
+
+   if (verbose)
+     {
+        printf("*** ***\n");
+        printf("Total payload size : %lli.\n", total);
      }
 
    eet_close(ef);
@@ -415,7 +442,7 @@ main(int    argc,
 help:
         printf(
           "Usage:\n"
-          "  eet -l FILE.EET                                    list all keys in FILE.EET\n"
+          "  eet -l [-v] FILE.EET                               list all keys in FILE.EET\n"
           "  eet -x FILE.EET KEY [OUT-FILE] [CRYPTO_KEY]        extract data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
           "  eet -d FILE.EET KEY [OUT-FILE] [CRYPTO_KEY]        extract and decode data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
           "  eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY]  insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
@@ -431,8 +458,15 @@ help:
 
    if ((!strncmp(argv[1], "-h", 2)))
      goto help;
-   else if ((!strcmp(argv[1], "-l")) && (argc > 2))
-     do_eet_list(argv[2]);
+   else if (((!strcmp(argv[1], "-l")) || (!strcmp(argv[1], "-v"))) && (argc > 2))
+     {
+        if (argc == 3)
+          do_eet_list(argv[2], EINA_FALSE);
+        else if ((!strcmp(argv[2], "-l")) || (!strcmp(argv[2], "-v")))
+          do_eet_list(argv[3], EINA_TRUE);
+        else
+          goto help;
+     }
    else if ((!strcmp(argv[1], "-x")) && (argc > 3))
      {
         switch (argc)
index fccfc18..b794ad1 100644 (file)
@@ -538,6 +538,27 @@ typedef struct _Eet_File Eet_File;
 typedef struct _Eet_Dictionary Eet_Dictionary;
 
 /**
+ * @typedef Eet_Entries
+ * Eet files may contains multiple Entries per file, this handle describe them. You can get that handle from an iterator given by eet_list_entries().
+ *
+ * @see eet_list_entries()
+ * @since 1.8.0
+ */
+typedef struct _Eet_Entry Eet_Entry;
+struct _Eet_Entry
+{
+   const char *name; /**< The entry name */
+
+   int offset;       /**< Where it start in the file  */
+   int size;         /**< The size on disk */
+   int data_size;    /**< The decompressed size if relevant */
+
+   Eina_Bool compression; /**< Is this data compressed ? */
+   Eina_Bool ciphered;    /**< Is it ciphered ? */
+   Eina_Bool alias;       /**< Is it an alias ? */
+};
+
+/**
  * @}
  */
 
@@ -892,6 +913,17 @@ eet_list(Eet_File *ef,
          int *count_ret);
 
 /**
+ * Return an iterator that will describe each entry of an Eet_File.
+ * @param ef A valid eet file handle.
+ * @return An interator of Eet_Entry.
+ *
+ * @since 1.8.0
+ * @ingroup Eet_File_Group
+ */
+
+EAPI Eina_Iterator *eet_list_entries(Eet_File *ef);
+
+/**
  * Return the number of entries in the specified eet file.
  * @param ef A valid eet file handle.
  * @return Number of entries in ef or -1 if the number of entries
index 32b55cf..6ea5647 100644 (file)
@@ -2675,6 +2675,122 @@ eet_num_entries(Eet_File *ef)
    return ret;
 }
 
+typedef struct _Eet_Entries_Iterator Eet_Entries_Iterator;
+struct _Eet_Entries_Iterator
+{
+   Eina_Iterator iterator;
+
+   Eet_File *ef;
+   Eet_File_Node *efn;
+   int index;
+
+   Eet_Entry entry;
+
+   Eina_Bool locked;
+};
+
+Eina_Bool
+_eet_entries_iterator_next(Eet_Entries_Iterator *it, void **data)
+{
+   if (it->efn == NULL)
+     {
+        int num;
+
+        num = (1 << it->ef->header->directory->size);
+
+        do
+          {
+             it->index++;
+
+             if (!(it->index < num))
+               return EINA_FALSE;
+
+             it->efn = it->ef->header->directory->nodes[it->index];
+          }
+        while (!it->efn);
+     }
+
+   /* copy info in public header */
+   it->entry.name = it->efn->name;
+   it->entry.offset = it->efn->offset;
+   it->entry.size = it->efn->size;
+   it->entry.data_size = it->efn->data_size;
+   it->entry.compression = it->efn->compression;
+   it->entry.ciphered = it->efn->ciphered;
+   it->entry.alias = it->efn->alias;
+
+   *data = &it->entry;
+   it->efn = it->efn->next;
+   return EINA_TRUE;
+}
+
+void *
+_eet_entries_iterator_container(Eet_Entries_Iterator *it)
+{
+   return it->ef;
+}
+
+void
+_eet_entries_iterator_free(Eet_Entries_Iterator *it)
+{
+   if (it->locked)
+     {
+        CRIT("Iterator still LOCKED !");
+        UNLOCK_FILE(it->ef);
+     }
+}
+
+Eina_Bool
+_eet_entries_iterator_lock(Eet_Entries_Iterator *it)
+{
+   if (it->locked)
+     {
+        CRIT("Iterator already LOCKED !");
+        return EINA_TRUE;
+     }
+
+   LOCK_FILE(it->ef);
+   it->locked = EINA_TRUE;
+   return EINA_TRUE;
+}
+
+Eina_Bool
+_eet_entries_iterator_unlock(Eet_Entries_Iterator *it)
+{
+   if (!it->locked)
+     {
+        CRIT("Iterator already UNLOCKED !");
+        return EINA_TRUE;
+     }
+
+   UNLOCK_FILE(it->ef);
+   it->locked = EINA_FALSE;
+   return EINA_TRUE;
+}
+
+EAPI Eina_Iterator *
+eet_list_entries(Eet_File *ef)
+{
+   Eet_Entries_Iterator *it;
+
+   it = malloc(sizeof (Eet_Entries_Iterator));
+   if (!it) return NULL;
+
+   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
+   it->ef = ef;
+   it->efn = NULL;
+   it->index = -1;
+   it->locked = EINA_FALSE;
+   it->iterator.version = EINA_ITERATOR_VERSION;
+   it->iterator.next = FUNC_ITERATOR_NEXT(_eet_entries_iterator_next);
+   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eet_entries_iterator_container);
+   it->iterator.free = FUNC_ITERATOR_FREE(_eet_entries_iterator_free);
+   it->iterator.lock = FUNC_ITERATOR_LOCK(_eet_entries_iterator_lock);
+   it->iterator.unlock = FUNC_ITERATOR_LOCK(_eet_entries_iterator_unlock);
+
+   return &it->iterator;
+}
+
 static Eet_File_Node *
 find_node_by_name(Eet_File   *ef,
                   const char *name)