[Xfce4-commits] <squeeze:master> Added squeeze-cli testing program
Peter de Ridder
noreply at xfce.org
Sat Sep 10 21:52:01 CEST 2011
Updating branch refs/heads/master
to 2c45e0b76bec6c4d5a9fab1be626962a5f35ba91 (commit)
from 90d780c5f750df7276177283327bd838c0600129 (commit)
commit 2c45e0b76bec6c4d5a9fab1be626962a5f35ba91
Author: Peter de Ridder <peter at xfce.org>
Date: Sat Sep 10 21:39:37 2011 +0200
Added squeeze-cli testing program
.gitignore | 1 +
Makefile.am | 2 +-
configure.in.in | 22 ++++
squeeze-cli/Makefile.am | 27 +++++
squeeze-cli/cli.c | 254 ++++++++++++++++++++++++++++++++++++++++
squeeze-cli/cli.h | 56 +++++++++
squeeze-cli/main.c | 298 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 659 insertions(+), 1 deletions(-)
diff --git a/.gitignore b/.gitignore
index 88ffff4..4702bae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,6 +34,7 @@ po/.intltool-merge-cache
po/Makefile.in.in
po/POTFILES
po/stamp-it
+squeeze-cli/squeeze-cli
squeeze.desktop
src/squeeze
src/throbber-fallback.c
diff --git a/Makefile.am b/Makefile.am
index 7b008d4..0947863 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = pixmaps libsqueeze po docs src icons data
+SUBDIRS = pixmaps libsqueeze po docs src icons data squeeze-cli
wrapperdir = $(libexecdir)/thunar-archive-plugin
wrapper_SCRIPTS = squeeze.tap
diff --git a/configure.in.in b/configure.in.in
index fd5b3c2..6c0bd27 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -130,6 +130,27 @@ if test "$lsq_gslices" = "yes"; then
AC_DEFINE([USE_GSLICES], [1], [Define if we should use GSlices])
fi
+AC_ARG_ENABLE([profiling],
+ [AC_HELP_STRING([--enable-profiling=no|prof|gprof|instrument],
+ [Build with profiler support (default=disabled)])],
+ [enable_profiling=$enableval],
+ [enable_profiling=no])
+
+case "$enable_profiling" in
+ no) ;;
+ prof)
+ AC_DEFINE([WANT_PROFILING_PROF], [1], [Define if --enable-profiling=prof])
+ CFLAGS="$CFLAGS -p" ;;
+ gprof)
+ AC_DEFINE([WANT_PROFILING_GPROF], [1], [Define if --enable-profiling=gprof])
+ CFLAGS="$CFLAGS -pg" ;;
+ instrument)
+ AC_DEFINE([WANT_PROFILING_INSTRUMENT], [1], [Define if --enable-profiling=instrument])
+ CFLAGS="$CFLAGS -finstrument-functions" ;;
+ *)
+ AC_MSG_ERROR([Bad value $enableval for --enable-profiling, need no/prof/gprof/instrument]) ;;
+esac
+
dnl check for debugging support
XDT_FEATURE_DEBUG([squeeze_debug_default])
@@ -140,6 +161,7 @@ Makefile
po/Makefile.in
src/Makefile
libsqueeze/Makefile
+squeeze-cli/Makefile
icons/Makefile
icons/16x16/Makefile
icons/48x48/Makefile
diff --git a/squeeze-cli/Makefile.am b/squeeze-cli/Makefile.am
new file mode 100644
index 0000000..169f541
--- /dev/null
+++ b/squeeze-cli/Makefile.am
@@ -0,0 +1,27 @@
+check_PROGRAMS = squeeze-cli
+
+squeeze_cli_SOURCES = \
+ main.c \
+ cli.c cli.h
+
+squeeze_cli_CFLAGS = \
+ -DDATADIR=\"$(datadir)\" \
+ -DSRCDIR=\"$(top_srcdir)\" \
+ -DLOCALEDIR=\"$(localedir)\" \
+ $(GLIB_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(LIBXFCE4UTIL_CFLAGS)
+
+squeeze_cli_LDADD = \
+ $(top_builddir)/libsqueeze/libsqueeze-2.la
+
+squeeze_cli_LDFLAGS = \
+ $(GLIB_LIBS) \
+ $(GIO_LIBS) \
+ $(XFCONF_LIBS) \
+ $(LIBXFCE4UTIL_LIBS)
+
+
+INCLUDES = \
+ -I${top_srcdir}
+
diff --git a/squeeze-cli/cli.c b/squeeze-cli/cli.c
new file mode 100644
index 0000000..05cd174
--- /dev/null
+++ b/squeeze-cli/cli.c
@@ -0,0 +1,254 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <gio/gio.h>
+
+#include <libsqueeze/libsqueeze.h>
+
+#include "cli.h"
+
+static void sq_cli_refreshed_cb ( LSQArchive *, SQCli * );
+
+struct _SQCli
+{
+ GObject parent;
+
+ gboolean silent;
+};
+
+struct _SQCliClass
+{
+ GObjectClass parent;
+};
+
+G_DEFINE_TYPE( SQCli, sq_cli, G_TYPE_OBJECT )
+
+static void
+sq_cli_init ( SQCli *cli )
+{
+}
+
+static void
+sq_cli_class_init ( SQCliClass *cli )
+{
+}
+
+SQCli *
+sq_cli_new ( void )
+{
+ SQCli *cli;
+
+ cli = g_object_new( SQ_TYPE_CLI, NULL );
+
+ return cli;
+}
+
+gint
+sq_cli_extract_archive ( SQCli *cli, GFile *file, gchar *dest_path )
+{
+ LSQArchive *lp_archive = NULL;
+ if ( 0 != lsq_open_archive( file, &lp_archive ) )
+ {
+ /*
+ * Could not open archive (mime type not supported or file did not exist)
+ * Should be a more specific error message.
+ */
+ g_error( "%s", _("Could not open archive, MIME-type unsupported or file does not exist") );
+ return 1;
+ }
+ if ( NULL == dest_path )
+ {
+ lsq_close_archive( lp_archive );
+ return 1;
+ }
+ if ( FALSE == lsq_archive_operate( lp_archive, LSQ_COMMAND_TYPE_EXTRACT, NULL, dest_path ) )
+ {
+ g_warning( "%s", _("Squeeze cannot extract this archive type,\nthe application to support this is missing.") );
+ }
+ return 0;
+}
+
+gint
+sq_cli_new_archive ( SQCli *cli, GFile *file, GSList *files )
+{
+ LSQArchive *lp_archive = NULL;
+
+ if ( NULL == file )
+ {
+ return 1;
+ }
+ else
+ {
+ if ( 0 != lsq_new_archive( file, FALSE, &lp_archive ) )
+ {
+ /*
+ * Could not open archive (mime type not supported or file did not exist)
+ * Should be a more specific error message.
+ */
+ g_error( "%s", _("Could not open archive, MIME-type unsupported or file exists") );
+ return 1;
+ }
+ }
+ if ( FALSE == lsq_archive_operate( lp_archive, LSQ_COMMAND_TYPE_ADD, NULL, NULL ) )
+ {
+ /* FIXME: show warning dialog */
+ g_warning( "%s", _("Squeeze cannot add files to this archive type,\nthe application to support this is missing.") );
+ }
+ return 0;
+}
+
+gint
+sq_cli_add_archive ( SQCli *cli, GFile *file, GSList *files )
+{
+ LSQArchive *lp_archive = NULL;
+
+ if ( NULL == file )
+ {
+ return 1;
+ }
+ else
+ {
+ if ( 0 != lsq_open_archive( file, &lp_archive ) )
+ {
+ /*
+ * Could not open archive (mime type not supported or file did not exist)
+ * Should be a more specific error message.
+ */
+ g_error( "%s", _("Could not open archive, MIME-type unsupported or file does not exist") );
+ return 1;
+ }
+ }
+ if ( FALSE == lsq_archive_operate( lp_archive, LSQ_COMMAND_TYPE_ADD, NULL, NULL ) )
+ {
+ /* FIXME: show warning dialog */
+ g_warning( "%s", _("Squeeze cannot add files to this archive type,\nthe application to support this is missing.") );
+ }
+ return 0;
+}
+
+gint
+sq_cli_open_archive ( SQCli *cli, GFile *file )
+{
+ LSQArchive *archive = NULL;
+
+ if ( 0 != lsq_open_archive( file, &archive ) )
+ {
+ g_error( "%s", _("Failed to open file") );
+ return 1;
+ }
+ else
+ {
+ g_signal_connect( archive, "refreshed", G_CALLBACK(sq_cli_refreshed_cb), cli );
+ lsq_archive_operate( archive, LSQ_COMMAND_TYPE_REFRESH, NULL, NULL );
+ g_object_ref( cli );
+ }
+ return 0;
+}
+
+void
+sq_cli_set_silent ( SQCli *cli, gboolean silent )
+{
+ cli->silent = silent;
+}
+
+
+typedef struct _SQdepth SQdepth;
+struct _SQdepth
+{
+ SQdepth *next;
+ gchar line;
+};
+
+static void
+sq_cli_print_iter ( LSQArchiveIter *node, SQdepth *depth )
+{
+ const gchar *filename;
+ const gchar *dir;
+ LSQArchiveIter *iter;
+ guint i, size;
+ SQdepth *depth_iter;
+ SQdepth *depth_last = NULL;
+
+ filename = lsq_archive_iter_get_filename( node );
+ dir = ( FALSE == lsq_archive_iter_is_directory( node ) ) ? "" : "/";
+ if ( NULL == filename )
+ {
+ filename = "/";
+ }
+
+ for ( depth_iter = depth; depth_iter; depth_iter = depth_iter->next )
+ {
+ gchar symbol = ( NULL == depth_iter->next ) ? '+' : depth_iter->line;
+ g_printf( " %c", symbol );
+ depth_last = depth_iter;
+ }
+
+ g_printf( "-%s%s\n", filename, dir );
+
+ size = lsq_archive_iter_n_children( node );
+
+ if ( 0 < size )
+ {
+ depth_iter = g_new( SQdepth, 1 );
+ depth_iter->next = 0;
+ depth_iter->line = '|';
+ if ( NULL == depth_last )
+ {
+ depth = depth_iter;
+ }
+ else
+ {
+ depth_last->next = depth_iter;
+ }
+
+ for ( i = 0; i < size; ++i )
+ {
+ if ( size - 1 == i )
+ {
+ depth_iter->line = ' ';
+ }
+ iter = lsq_archive_iter_nth_child( node, i );
+ sq_cli_print_iter( iter, depth );
+ }
+
+ if ( NULL != depth_last )
+ {
+ depth_last->next = NULL;
+ }
+ g_free( depth_iter );
+ }
+}
+
+static void
+sq_cli_refreshed_cb ( LSQArchive *archive, SQCli *cli )
+{
+ LSQArchiveIter *root;
+
+ if ( FALSE == cli->silent )
+ {
+ root = lsq_archive_get_iter( archive, NULL );
+ sq_cli_print_iter( root, NULL );
+ }
+
+ g_object_unref( archive );
+
+ g_object_unref( cli );
+}
+
diff --git a/squeeze-cli/cli.h b/squeeze-cli/cli.h
new file mode 100644
index 0000000..349197a
--- /dev/null
+++ b/squeeze-cli/cli.h
@@ -0,0 +1,56 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __SQUEEZE_CLI__H__
+#define __SQUEEZE_CLI__H__
+G_BEGIN_DECLS
+
+#define SQ_TYPE_CLI sq_cli_get_type()
+
+#define SQ_CLI(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ SQ_TYPE_CLI, \
+ SQCli))
+
+#define SQ_IS_CLI(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ SQ_TYPE_CLI))
+
+#define SQ_CLI_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ SQ_TYPE_CLI, \
+ SQCliClass))
+
+#define SQ_IS_CLI_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ SQ_TYPE_CLI()))
+
+typedef struct _SQCli SQCli;
+
+typedef struct _SQCliClass SQCliClass;
+
+GType sq_cli_get_type ( void );
+SQCli * sq_cli_new ( void );
+
+gint sq_cli_extract_archive ( SQCli *, GFile *, gchar * );
+gint sq_cli_new_archive ( SQCli *, GFile *, GSList * );
+gint sq_cli_add_archive ( SQCli *, GFile *, GSList * );
+gint sq_cli_open_archive ( SQCli *, GFile * );
+
+void sq_cli_set_silent ( SQCli *, gboolean );
+
+G_END_DECLS
+#endif /* __SQUEEZE_CLI__H__ */
diff --git a/squeeze-cli/main.c b/squeeze-cli/main.c
new file mode 100644
index 0000000..3fc843b
--- /dev/null
+++ b/squeeze-cli/main.c
@@ -0,0 +1,298 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include <libsqueeze/libsqueeze.h>
+
+#include "cli.h"
+
+gboolean version = FALSE;
+
+gchar *extract_archive_path = NULL;
+gchar *new_archive = NULL;
+gchar *add_archive_path = NULL;
+
+gboolean verbose = FALSE;
+gboolean silent = FALSE;
+
+#ifdef LSQ_ENTRY_CHILD_BUFFER_DYNAMIC_SIZE
+extern guint buffer_flush_size;
+#endif
+
+gpointer command;
+
+gint opened_archives = 0;
+
+static GOptionEntry entries[] =
+{
+ {
+ "extract-to", 'x', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &extract_archive_path,
+ NULL,
+ N_("[destination path]")
+ },
+ {
+ "add-to", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &add_archive_path,
+ NULL,
+ N_("[archive path] [file1] [file2] ... [fileN]")
+ },
+ {
+ "new", 'n', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &new_archive,
+ NULL,
+ N_("[file1] [file2] ... [fileN]")
+ },
+ {
+ "verbose", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &verbose,
+ N_("Version information"),
+ NULL
+ },
+ {
+ "silent", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &silent,
+ N_("Version information"),
+ NULL
+ },
+ {
+ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
+ N_("Version information"),
+ NULL
+ },
+#ifdef LSQ_ENTRY_CHILD_BUFFER_DYNAMIC_SIZE
+ {
+ "flush", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &buffer_flush_size,
+ NULL,
+ NULL
+ },
+#endif
+ { NULL }
+};
+
+int
+main ( int argc, char **argv )
+{
+ GError *cli_error = NULL;
+ gint i = 0;
+ GFile *file = NULL;
+ GMainLoop *main_loop;
+ GOptionContext *option_ctx;
+ SQCli *cli;
+
+#ifdef ENABLE_NLS
+ bindtextdomain( GETTEXT_PACKAGE, LOCALEDIR );
+ bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
+ textdomain( GETTEXT_PACKAGE );
+#endif
+
+ /*
+ * Setup the command line options
+ */
+ option_ctx = g_option_context_new( "[archive]" );
+ g_option_context_add_main_entries( option_ctx, entries, PACKAGE );
+
+ /*
+ * Parse the command line options
+ */
+ if ( FALSE == g_option_context_parse( option_ctx, &argc, &argv, &cli_error ) )
+ {
+ /*
+ * We should always have an error here
+ */
+ if ( G_LIKELY( NULL != cli_error ) )
+ {
+ g_print(
+ _("%s: %s\nTry %s --help to see a full list of available command line options.\n"),
+ PACKAGE,
+ cli_error->message,
+ g_get_prgname()
+ );
+
+ g_error_free( cli_error );
+ g_option_context_free( option_ctx );
+
+ return 1;
+ }
+ }
+
+ g_option_context_free( option_ctx );
+
+ if ( version )
+ {
+ g_print( "%s\n", PACKAGE_STRING );
+ return 0;
+ }
+
+ g_type_init();
+ main_loop = g_main_loop_new( NULL, FALSE );
+
+ lsq_init();
+
+ cli = sq_cli_new();
+
+ g_object_weak_ref( G_OBJECT(cli), (GWeakNotify)g_main_loop_quit, main_loop );
+
+ sq_cli_set_silent ( cli, silent );
+
+ /*
+ * Extract files
+ */
+ if ( NULL != extract_archive_path )
+ {
+ gint err = 0;
+ if ( 1 >= argc )
+ {
+ g_print( _("%s: No archive file.\n"), PACKAGE );
+ return 1;
+ }
+ if ( 2 < argc )
+ {
+ g_print( _("%s: To many files.\n"), PACKAGE );
+ return 1;
+ }
+ for ( i = 1; i < argc; ++i )
+ {
+ file = g_file_new_for_path( argv[i] );
+ if ( NULL != file )
+ {
+ if ( 0 != sq_cli_extract_archive( cli, file, extract_archive_path ) )
+ {
+ ++err;
+ }
+ g_object_unref( file );
+ }
+ else
+ {
+ ++err;
+ }
+ }
+ if ( 0 < err )
+ {
+ g_print( _("%s: %d archive(s) failed to start extracting.\n"), PACKAGE, err );
+ return 1;
+ }
+ }
+ /*
+ * Add files
+ */
+ else if ( NULL != new_archive || NULL != add_archive_path )
+ {
+ gint err = 0;
+ GSList *files = NULL;
+
+ /*
+ * Remove prefix if it is the pwd
+ */
+ for ( i = 1; i < argc; ++i )
+ {
+ file = g_file_new_for_path( new_archive );
+ files = g_slist_prepend( files, file );
+ }
+
+ if ( NULL != new_archive )
+ {
+ file = g_file_new_for_path( new_archive );
+ if ( NULL != file )
+ {
+ if ( 0 != sq_cli_new_archive( cli, file, files ) )
+ {
+ ++err;
+ }
+ }
+ else
+ {
+ ++err;
+ }
+ if ( 0 < err )
+ {
+ g_print( _("%s: failed to create new archive.\n"), PACKAGE );
+ return 1;
+ }
+ }
+ else
+ {
+ file = g_file_new_for_path( add_archive_path );
+ if ( NULL != file )
+ {
+ if ( 0 != sq_cli_add_archive( cli, file, files ) )
+ {
+ ++err;
+ }
+ }
+ else
+ {
+ ++err;
+ }
+ if ( 0 < err )
+ {
+ g_print( _("%s: failed to add files to archive.\n"), PACKAGE );
+ return 1;
+ }
+ }
+ }
+ /*
+ * List archive
+ */
+ else
+ {
+ gint err = 0;
+ if ( 1 >= argc )
+ {
+ g_print(
+ _("%s: %s\nTry %s --help to see a full list of available command line options.\n"),
+ PACKAGE,
+ _("No archive file."),
+ g_get_prgname()
+ );
+ return 1;
+ }
+ if ( 2 < argc )
+ {
+ g_print( _("%s: To many files.\n"), PACKAGE );
+ return 1;
+ }
+ for(i = 1; i < argc; i++)
+ {
+ file = g_file_new_for_path( argv[i] );
+ if ( NULL != file )
+ {
+ if ( 0 != sq_cli_open_archive( cli, file ) )
+ {
+ ++err;
+ }
+ }
+ else
+ {
+ ++err;
+ }
+ }
+ if ( 0 < err )
+ {
+ g_print( _("%s: %d archive(s) failed to open.\n"), PACKAGE, err );
+ return 1;
+ }
+ }
+
+ g_object_unref( cli );
+
+ g_main_loop_run( main_loop );
+
+ lsq_shutdown();
+ g_main_loop_unref( main_loop );
+
+ return 0;
+}
More information about the Xfce4-commits
mailing list