+eet_alias_get, related, docs, some spelling corrections
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 30 Jul 2011 01:31:40 +0000 (01:31 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 30 Jul 2011 01:31:40 +0000 (01:31 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eet@61915 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/lib/Eet.h
src/lib/eet_lib.c

index fb57e97..b108bff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * On Windows, open() in text mode followed by fdopen() in
        binary mode does not create a stream in binary mode.
        So add O_BINARY to open().
+
+2011-07-29  Mike Blumenkrantz
+
+        * Add eet_alias_get to return the destination name of an alias
index 7a722bf..b09d3a4 100644 (file)
@@ -20,6 +20,7 @@ These routines are used for Eet Library interaction
 @author Mathieu Taillefumier <mathieu.taillefumier@@free.fr>
 @author Albin "Lutin" Tonnerre <albin.tonnerre@@gmail.com>
 @author Adam Simpkins <adam@@adamsimpkins.net>
+@author Mike Blumenkrantz <mike@zentific.com>
 @date 2000-2011
 
 @section toc Table of Contents
@@ -750,11 +751,11 @@ eet_delete(Eet_File   *ef,
  * no check are done.
  * @param ef A valid eet file handle opened for writing.
  * @param name Name of the entry. eg: "/base/file_i_want".
- * @param destination Destionation of the alias. eg: "/base/the_real_stuff_i_want".
+ * @param destination Destination of the alias. eg: "/base/the_real_stuff_i_want".
  * @param compress Compression flags (1 == compress, 0 = don't compress).
  * @return EINA_TRUE on success, EINA_FALSE on failure.
  *
- * Name and Destination must not be NULL, otherwhise EINA_FALSE will be returned.
+ * Name and Destination must not be NULL, otherwise EINA_FALSE will be returned.
  *
  * @since 1.3.3
  * @ingroup Eet_File_Group
@@ -766,6 +767,21 @@ eet_alias(Eet_File   *ef,
           int         compress);
 
 /**
+ * Retrieve the destination name of an alias
+ * @param ef A valid eet file handle opened for writing
+ * @param name Name of the entry. eg: "/base/file_i_want"
+ * @return Destination of the alias. eg: "/base/the_real_stuff_i_want", NULL on failure
+ *
+ * Name must not be NULL, otherwise NULL will be returned.
+ *
+ * @since 1.5
+ * @ingroup Eet_File_Group
+ */
+EAPI const char *
+eet_alias_get(Eet_File *ef,
+              const char *name);
+
+/**
  * List all entries in eet file matching shell glob.
  * @param ef A valid eet file handle.
  * @param glob A shell glob to match against.
index 6ee10c4..f8f64ee 100644 (file)
@@ -1983,6 +1983,83 @@ on_error:
    return NULL;
 } /* eet_read_direct */
 
+EAPI const char *
+eet_alias_get(Eet_File *ef,
+              const char *name)
+{
+   Eet_File_Node *efn;
+   const char *data = NULL;
+   int size = 0;
+
+   /* check to see its' an eet file pointer */
+   if (eet_check_pointer(ef))
+      return NULL;
+
+   if (!name)
+      return NULL;
+
+   if ((ef->mode != EET_FILE_MODE_READ) &&
+       (ef->mode != EET_FILE_MODE_READ_WRITE))
+      return NULL;
+
+   /* no header, return NULL */
+   if (eet_check_header(ef))
+      return NULL;
+
+   LOCK_FILE(ef);
+
+   /* hunt hash bucket */
+   efn = find_node_by_name(ef, name);
+   if (!efn)
+      goto on_error;
+
+   /* trick to detect data in memory instead of mmaped from disk */
+   if (efn->offset > ef->data_size && !efn->data)
+      goto on_error;
+
+   /* get size (uncompressed, if compressed at all) */
+   size = efn->data_size;
+
+   if (!efn->alias) return NULL;
+   data = efn->data ? efn->data : ef->data + efn->offset;
+
+   /* handle alias case */
+   if (efn->compression)
+     {
+        char *tmp;
+        int compr_size = efn->size;
+        uLongf dlen;
+
+        tmp = alloca(sizeof (compr_size));
+        dlen = size;
+
+        if (uncompress((Bytef *)tmp, &dlen, (Bytef *)data,
+                       (uLongf)compr_size))
+           goto on_error;
+
+        if (tmp[compr_size - 1] != '\0')
+           goto on_error;
+
+        UNLOCK_FILE(ef);
+
+        return eina_stringshare_add(tmp);
+     }
+
+   if (!data)
+      goto on_error;
+
+   if (data[size - 1] != '\0')
+      goto on_error;
+
+   UNLOCK_FILE(ef);
+
+   return eina_stringshare_add(data);
+
+on_error:
+   UNLOCK_FILE(ef);
+   return NULL;
+}
+
 EAPI Eina_Bool
 eet_alias(Eet_File   *ef,
           const char *name,