X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgresource-tool.c;h=cc4e78b9ff5c373d8021820713bd21d44df973fd;hb=c8d10470939847069b1a346d4c44f2adde3469f6;hp=3e0d95c3349a72aeb85c1766fbbd6e68a9facea7;hpb=716cf3558510be0a7ba7075a431ac2a5ad13b2bf;p=platform%2Fupstream%2Fglib.git
diff --git a/gio/gresource-tool.c b/gio/gresource-tool.c
index 3e0d95c..cc4e78b 100644
--- a/gio/gresource-tool.c
+++ b/gio/gresource-tool.c
@@ -12,9 +12,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see .
*
* Author: Matthias Clasen
*/
@@ -28,16 +26,22 @@
#include
#include
#include
-#include
+#include
#ifdef HAVE_LIBELF
#include
#include
+#include
#endif
#include
+#include
#include
+#ifdef G_OS_WIN32
+#include "glib/glib-private.h"
+#endif
+
/* GResource functions {{{1 */
static GResource *
get_resource (const gchar *file)
@@ -92,7 +96,7 @@ list_resource (GResource *resource,
if (g_resource_get_info (resource, child, 0, &size, &flags, NULL))
{
if (details)
- g_print ("%s%s%6ld %s %s\n", section, section[0] ? " " : "", size, flags & G_RESOURCE_FLAGS_COMPRESSED ? "c" : "u", child);
+ g_print ("%s%s%6"G_GSIZE_FORMAT " %s %s\n", section, section[0] ? " " : "", size, flags & G_RESOURCE_FLAGS_COMPRESSED ? "c" : "u", child);
else
g_print ("%s\n", child);
}
@@ -122,10 +126,6 @@ extract_resource (GResource *resource,
g_printerr ("Data truncated\n");
g_bytes_unref (bytes);
}
- else
- {
- g_printerr ("Can't find resource path %s\n", path);
- }
}
/* Elf functions {{{1 */
@@ -141,16 +141,24 @@ get_elf (const gchar *file,
if (elf_version (EV_CURRENT) == EV_NONE )
return NULL;
- *fd = open (file, O_RDONLY);
+ *fd = g_open (file, O_RDONLY, 0);
if (*fd < 0)
return NULL;
elf = elf_begin (*fd, ELF_C_READ, NULL);
if (elf == NULL)
- return NULL;
+ {
+ g_close (*fd, NULL);
+ *fd = -1;
+ return NULL;
+ }
if (elf_kind (elf) != ELF_K_ELF)
- return NULL;
+ {
+ g_close (*fd, NULL);
+ *fd = -1;
+ return NULL;
+ }
return elf;
}
@@ -216,10 +224,16 @@ resource_from_section (GElf_Shdr *shdr,
if (contents != MAP_FAILED)
{
GBytes *bytes;
+ GError *error = NULL;
bytes = g_bytes_new_static (contents + page_offset, shdr->sh_size);
- resource = g_resource_new_from_data (bytes, NULL);
+ resource = g_resource_new_from_data (bytes, &error);
g_bytes_unref (bytes);
+ if (error)
+ {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ }
}
else
{
@@ -302,7 +316,10 @@ extract_resource_cb (GElf_Shdr *shdr,
extract_resource (resource, d->path);
g_resource_unref (resource);
- return FALSE;
+ if (d->section)
+ return FALSE;
+
+ return TRUE;
}
static void
@@ -383,7 +400,6 @@ cmd_list (const gchar *file,
GResource *resource;
#ifdef HAVE_LIBELF
-
Elf *elf;
int fd;
@@ -467,13 +483,13 @@ cmd_help (gboolean requested,
else if (strcmp (command, "help") == 0)
{
description = _("Print help");
- synopsis = "[COMMAND]";
+ synopsis = _("[COMMAND]");
}
else if (strcmp (command, "sections") == 0)
{
description = _("List sections containing resources in an elf FILE");
- synopsis = "FILE";
+ synopsis = _("FILE");
}
else if (strcmp (command, "list") == 0)
@@ -481,7 +497,7 @@ cmd_help (gboolean requested,
description = _("List resources\n"
"If SECTION is given, only list resources in this section\n"
"If PATH is given, only list matching resources");
- synopsis = "FILE [PATH]";
+ synopsis = _("FILE [PATH]");
option = g_strdup_printf ("[--section %s]", _("SECTION"));
}
@@ -491,14 +507,14 @@ cmd_help (gboolean requested,
"If SECTION is given, only list resources in this section\n"
"If PATH is given, only list matching resources\n"
"Details include the section, size and compression");
- synopsis = "FILE [PATH]";
+ synopsis = _("FILE [PATH]");
option = g_strdup_printf ("[--section %s]", _("SECTION"));
}
else if (strcmp (command, "extract") == 0)
{
description = _("Extract a resource file to stdout");
- synopsis = "FILE PATH";
+ synopsis = _("FILE PATH");
option = g_strdup_printf ("[--section %s]", _("SECTION"));
}
@@ -527,7 +543,7 @@ cmd_help (gboolean requested,
else
{
g_string_append_printf (string, _("Usage:\n gresource %s%s%s %s\n\n%s\n\n"),
- option ? option : "", option ? " " : "", command, synopsis[0] ? _(synopsis) : "", description);
+ option ? option : "", option ? " " : "", command, synopsis[0] ? synopsis : "", description);
g_string_append (string, _("Arguments:\n"));
@@ -535,11 +551,11 @@ cmd_help (gboolean requested,
g_string_append (string,
_(" SECTION An (optional) elf section name\n"));
- if (strstr (synopsis, "[COMMAND]"))
+ if (strstr (synopsis, _("[COMMAND]")))
g_string_append (string,
_(" COMMAND The (optional) command to explain\n"));
- if (strstr (synopsis, "FILE"))
+ if (strstr (synopsis, _("FILE")))
{
if (strcmp (command, "sections") == 0)
g_string_append (string,
@@ -550,10 +566,10 @@ cmd_help (gboolean requested,
" or a compiled resource file\n"));
}
- if (strstr (synopsis, "[PATH"))
+ if (strstr (synopsis, _("[PATH]")))
g_string_append (string,
_(" PATH An (optional) resource path (may be partial)\n"));
- else if (strstr (synopsis, "PATH"))
+ else if (strstr (synopsis, _("PATH")))
g_string_append (string,
_(" PATH A resource path\n"));
@@ -580,7 +596,24 @@ main (int argc, char *argv[])
gboolean details = FALSE;
void (* function) (const gchar *, const gchar *, const gchar *, gboolean);
- g_type_init ();
+#ifdef G_OS_WIN32
+ gchar *tmp;
+#endif
+
+ setlocale (LC_ALL, "");
+ textdomain (GETTEXT_PACKAGE);
+
+#ifdef G_OS_WIN32
+ tmp = _glib_get_locale_dir ();
+ bindtextdomain (GETTEXT_PACKAGE, tmp);
+ g_free (tmp);
+#else
+ bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
+#endif
+
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
if (argc < 2)
return cmd_help (FALSE, NULL);