Author: stephan
Date: 2007-02-12 09:34:48 +0000 (Mon, 12 Feb 2007)
New Revision: 24952
Modified:
squeeze/trunk/libsqueeze/archive-command.c
squeeze/trunk/libsqueeze/archive-command.h
squeeze/trunk/libsqueeze/archive-support-zip.c
Log:
zip now uses command structure
Modified: squeeze/trunk/libsqueeze/archive-command.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.c 2007-02-12 00:04:30 UTC (rev
24951)
+++ squeeze/trunk/libsqueeze/archive-command.c 2007-02-12 09:34:48 UTC (rev
24952)
@@ -86,6 +86,7 @@
static void
lsq_archive_command_init(LSQArchiveCommand *archive_command)
{
+ archive_command->parse_stdout = NULL;
}
/**
@@ -115,6 +116,8 @@
* %%1$s is the application to be executed.
*
* %%2$s are the files to be appended
+ *
+ * %%3$s are any additional options
*
* Returns: a new LSQArchiveCommand object
*/
@@ -193,6 +196,13 @@
return TRUE;
}
+/**
+ * lsq_archive_command_stop
+ * @archive_command:
+ *
+ *
+ * Returns: TRUE on success, FALSE if the command is not running
+ */
gboolean
lsq_archive_command_stop(LSQArchiveCommand *archive_command)
{
@@ -203,12 +213,26 @@
return TRUE;
}
+/**
+ * lsq_archive_command_child_watch_func:
+ * @pid:
+ * @status:
+ * @data:
+ */
void
lsq_archive_command_child_watch_func(GPid pid, gint status, gpointer data)
{
g_object_unref(G_OBJECT(data));
}
+/**
+ * lsq_archive_command_parse_stdout:
+ * @ioc:
+ * @cond:
+ * @data:
+ *
+ * Returns:
+ */
gboolean
lsq_archive_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer
data)
{
@@ -236,3 +260,30 @@
}
return TRUE;
}
+
+gboolean
+lsq_archive_command_set_parse_func(LSQArchiveCommand *archive_command, guint
fd, LSQParseFunc func)
+{
+ switch(fd)
+ {
+ case 1:
+ archive_command->parse_stdout = func;
+ default:
+ break;
+ }
+}
+
+GIOStatus
+lsq_archive_command_read_line(LSQArchiveCommand *archive_command, guint fd,
gchar **line, gsize *length)
+{
+ GIOStatus status = G_IO_STATUS_EOF;
+ switch(fd)
+ {
+ case 1:
+ status =
g_io_channel_read_line(archive_command->ioc_out, line, length, NULL, NULL);
+ break;
+ default:
+ break;
+ }
+ return status;
+}
Modified: squeeze/trunk/libsqueeze/archive-command.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.h 2007-02-12 00:04:30 UTC (rev
24951)
+++ squeeze/trunk/libsqueeze/archive-command.h 2007-02-12 09:34:48 UTC (rev
24952)
@@ -37,6 +37,8 @@
typedef struct _LSQArchiveCommand LSQArchiveCommand;
+typedef gboolean (*LSQParseFunc) (LSQArchiveCommand *archive_command);
+
struct _LSQArchiveCommand
{
GObject parent;
@@ -49,7 +51,7 @@
GIOChannel *ioc_err;
gboolean safe;
- gboolean (*parse_stdout)(LSQArchiveCommand *archive_command);
+ LSQParseFunc parse_stdout;
};
typedef struct _LSQArchiveCommandClass LSQArchiveCommandClass;
@@ -68,6 +70,10 @@
gboolean lsq_archive_command_run(LSQArchiveCommand
*archive_command) G_GNUC_INTERNAL;
gboolean lsq_archive_command_stop(LSQArchiveCommand
*archive_command) G_GNUC_INTERNAL;
+GIOStatus lsq_archive_command_read_line(LSQArchiveCommand
*archive_command,
+ guint fd,
+ gchar **lines,
+ gsize *length)
G_GNUC_INTERNAL;
G_END_DECLS
Modified: squeeze/trunk/libsqueeze/archive-support-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.c 2007-02-12 00:04:30 UTC
(rev 24951)
+++ squeeze/trunk/libsqueeze/archive-support-zip.c 2007-02-12 09:34:48 UTC
(rev 24952)
@@ -53,7 +53,7 @@
lsq_archive_support_zip_class_init(LSQArchiveSupportZipClass *supportclass);
gboolean
-lsq_archive_support_zip_refresh_parse_output(GIOChannel *ioc, GIOCondition
cond, gpointer data);
+lsq_archive_support_zip_refresh_parse_output(LSQArchiveCommand
*archive_command);
static void
lsq_archive_support_zip_set_property(GObject *object, guint prop_id, const
GValue *value, GParamSpec *pspec);
@@ -221,6 +221,7 @@
archive_command = lsq_archive_command_new("", archive,
"zip -r %1$s %2$s", FALSE);
g_object_set(archive_command, "files", files, NULL);
g_free(files);
+ lsq_archive_command_run(archive_command);
g_object_unref(archive_command);
}
}
@@ -256,6 +257,7 @@
archive_command = lsq_archive_command_new("", archive,
"zip -o %1$s %2$s %3$s", TRUE);
g_object_set(archive_command, "files", files, NULL);
g_object_set(archive_command, "options", options, NULL);
+ lsq_archive_command_run(archive_command);
g_object_unref(archive_command);
g_free(dest_path);
g_free(options);
@@ -288,8 +290,9 @@
archive_command = lsq_archive_command_new("", archive,
"zip -d %1$s %2$s", FALSE);
g_object_set(archive_command, "files", files, NULL);
- g_free(files);
+ lsq_archive_command_run(archive_command);
g_object_unref(archive_command);
+ g_free(files);
}
}
return 0;
@@ -343,141 +346,129 @@
i++;
}
archive_command = lsq_archive_command_new("", archive, "unzip
-lv -qq %1$s", TRUE);
+ lsq_archive_command_run(archive_command);
+ g_object_unref(archive_command);
}
return 0;
}
gboolean
-lsq_archive_support_zip_refresh_parse_output(GIOChannel *ioc, GIOCondition
cond, gpointer data)
+lsq_archive_support_zip_refresh_parse_output(LSQArchiveCommand
*archive_command)
{
+ gchar *line = NULL;
+ gsize linesize= 0;
GIOStatus status = G_IO_STATUS_NORMAL;
- LSQArchive *archive = data;
- gchar *line = NULL;
- LSQArchiveIter *entry;
-
+ LSQArchive *archive = archive_command->archive;
guint64 size;
guint64 length;
gpointer props[8];
gint n = 0, a = 0, i = 0, o = 0;
gchar *temp_filename = NULL;
- gint linesize = 0;
- if(!LSQ_IS_ARCHIVE(archive))
- return FALSE;
+ LSQArchiveIter *entry;
+ status = lsq_archive_command_read_line(archive_command, 1, &line,
&linesize);
+ if (line == NULL)
+ {
+ if(status == G_IO_STATUS_AGAIN)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ /* length, method , size, ratio, date, time, crc-32, filename*/
+ for(n=0; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- if(cond & (G_IO_PRI | G_IO_IN))
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_length)
{
- for(o = 0; o < 500; o++)
- {
- i = 0;
+ line[n]='\0';
+ length = g_ascii_strtoull(line + a, NULL, 0);
+ props[i] = &length;
+ i++;
+ }
+ n++;
- status = g_io_channel_read_line(ioc, &line,
NULL,NULL,NULL);
- if (line == NULL)
- break;
- /* length, method , size, ratio, date, time, crc-32,
filename*/
- linesize = strlen(line);
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(n=0; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_method)
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_length)
- {
- line[n]='\0';
- length = g_ascii_strtoull(line + a, NULL, 0);
- props[i] = &length;
- i++;
- }
- n++;
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_size)
+ {
+ line[n]='\0';
+ size = g_ascii_strtoull(line + a, NULL, 0);
+ props[i] = &size;
+ i++;
+ }
+ n++;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_method)
- {
- line[n] = '\0';
- props[i] = line + a;
- i++;
- }
- n++;
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_ratio)
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_size)
- {
- line[n]='\0';
- size = g_ascii_strtoull(line + a, NULL, 0);
- props[i] = &size;
- i++;
- }
- n++;
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_date)
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_ratio)
- {
- line[n] = '\0';
- props[i] = line + a;
- i++;
- }
- n++;
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_time)
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_date)
- {
- line[n] = '\0';
- props[i] = line + a;
- i++;
- }
- n++;
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_crc_32)
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n+=2;
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_time)
- {
- line[n] = '\0';
- props[i] = line + a;
- i++;
- }
- n++;
+ line[linesize-1] = '\0';
+ temp_filename = line+n;
- for(; n < linesize && line[n] == ' '; n++);
- a = n;
- for(; n < linesize && line[n] != ' '; n++);
+ entry = lsq_archive_add_file(archive, temp_filename);
+ lsq_archive_iter_set_propsv(entry, (gconstpointer*)props);
+ g_free(line);
-
if(LSQ_ARCHIVE_SUPPORT_ZIP(archive->support)->_view_crc_32)
- {
- line[n] = '\0';
- props[i] = line + a;
- i++;
- }
- n+=2;
-
- line[linesize-1] = '\0';
- temp_filename = line+n;
-
- entry = lsq_archive_add_file(archive, temp_filename);
- lsq_archive_iter_set_propsv(entry,
(gconstpointer*)props);
- g_free(line);
- }
- }
- if(cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
- {
- g_io_channel_shutdown ( ioc,TRUE,NULL );
- g_io_channel_unref (ioc);
- return FALSE;
- }
return TRUE;
}
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits