Author: colossus
Date: 2006-08-24 12:58:23 +0000 (Thu, 24 Aug 2006)
New Revision: 22867

Modified:
   xarchiver/trunk/TODO
   xarchiver/trunk/src/7zip.c
   xarchiver/trunk/src/arj.c
   xarchiver/trunk/src/bzip2.c
   xarchiver/trunk/src/callbacks.c
   xarchiver/trunk/src/callbacks.h
   xarchiver/trunk/src/extract_dialog.c
   xarchiver/trunk/src/interface.c
   xarchiver/trunk/src/iso.c
   xarchiver/trunk/src/main.c
   xarchiver/trunk/src/rar.c
   xarchiver/trunk/src/rpm.c
   xarchiver/trunk/src/string_utils.c
   xarchiver/trunk/src/string_utils.h
   xarchiver/trunk/src/zip.c
Log:
Updated TODO.
Fixed bug causing filenames with [] not to be extracted from tar archives.


Modified: xarchiver/trunk/TODO
===================================================================
--- xarchiver/trunk/TODO        2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/TODO        2006-08-24 12:58:23 UTC (rev 22867)
@@ -1,4 +1,5 @@
 - fix bug #1736, #2176.
+- change CRC with Checksum in rar.c and zip.c
 - allow switching by right click on the toolbar to icons with text/ no text/ 
small icons.
 - add a small progress window when using Xarchiver cmd-line switches.
 - redesign the new dialog.

Modified: xarchiver/trunk/src/7zip.c
===================================================================
--- xarchiver/trunk/src/7zip.c  2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/7zip.c  2006-08-24 12:58:23 UTC (rev 22867)
@@ -18,6 +18,7 @@
  
 #include "config.h"
 #include "7zip.h"
+#include "string_utils.h"
  
 void Open7Zip ( XArchive *archive)
 {

Modified: xarchiver/trunk/src/arj.c
===================================================================
--- xarchiver/trunk/src/arj.c   2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/arj.c   2006-08-24 12:58:23 UTC (rev 22867)
@@ -18,6 +18,7 @@
  
 #include "config.h"
 #include "arj.h"
+#include "string_utils.h"
 
 void OpenArj ( XArchive *archive )
 {

Modified: xarchiver/trunk/src/bzip2.c
===================================================================
--- xarchiver/trunk/src/bzip2.c 2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/bzip2.c 2006-08-24 12:58:23 UTC (rev 22867)
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "bzip2.h"
 #include "extract_dialog.h"
+#include "string_utils.h"
 
 extern gboolean TarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
 extern int output_fd;

Modified: xarchiver/trunk/src/callbacks.c
===================================================================
--- xarchiver/trunk/src/callbacks.c     2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/callbacks.c     2006-08-24 12:58:23 UTC (rev 22867)
@@ -236,7 +236,7 @@
        xa_set_button_state (1,1,1,0,0 );
        archive->path = g_strdup (path);
        g_free (path);
-    archive->escaped_path = EscapeBadChars (archive->path , 0);
+    archive->escaped_path = EscapeBadChars (archive->path , "$\'`\"\\!?* 
()&|@#:;");
     EmptyTextBuffer();
     archive->has_passwd = FALSE;
     gtk_widget_set_sensitive ( iso_info , FALSE );
@@ -294,7 +294,7 @@
        archive = xa_init_archive_structure(archive);
        archive->path = g_strdup (path);
        g_free (path);
-       archive->escaped_path = EscapeBadChars ( archive->path , 0 );
+       archive->escaped_path = EscapeBadChars ( archive->path , "$\'`\"\\!?* 
()&|@#:;" );
     
        OffDeleteandViewButtons();
     gtk_widget_set_sensitive ( iso_info , FALSE );
@@ -1076,8 +1076,13 @@
                        archive->has_passwd = FALSE;
 }
 
-void View_File_Window ( GtkMenuItem *menuitem , gpointer user_data )
+void xa_view_file_inside_archive ( GtkMenuItem *menuitem , gpointer user_data )
 {
+       GIOChannel *ioc_view = NULL;
+       gchar *line = NULL;
+       gchar *filename = NULL;
+       GError *error = NULL;
+       gchar *string = NULL;
        gchar *command = NULL;
        GtkTreeSelection *selection;
        GtkTreeModel *model;
@@ -1086,6 +1091,8 @@
        gchar *dummy_name;
        unsigned short int COL_NAME;
        gboolean is_dir = FALSE;
+       gboolean tofree = FALSE;
+       gboolean result = FALSE;
        GList *row_list = NULL;
 
        if ( archive->has_passwd )
@@ -1150,23 +1157,20 @@
                
        archive->full_path = 0;
        archive->overwrite = 1;
+
+       names = g_string_new (" ");
+       gtk_tree_model_get (model, &iter, 0, &dummy_name, -1);
+       ConcatenateFileNames2 ( dummy_name , names );
        
-       gtk_tree_model_get (model, &iter, 0, &dummy_name, -1);
-       dir = EscapeBadChars ( dummy_name , 1 );
-       names = g_string_new (" ");
-       g_string_append ( names , dir );
-       archive->parse_output = 0;
-
        if (archive->type == XARCHIVETYPE_ISO)
        {
                gtk_tree_model_get (model, &iter,
-                       0, &name,
+                       0, &dummy_name,
                        1, &permissions,
                        2, &file_size,
                        4, &file_offset,
                        -1);
-               xa_extract_iso_file (archive, permissions, "/tmp/", name , 
file_size, file_offset );
-               ViewFileFromArchive (archive->child_pid , 0 , name);
+               xa_extract_iso_file (archive, permissions, "/tmp/", dummy_name 
, file_size, file_offset );
                g_free (permissions);
        }
        else if (archive->type == XARCHIVETYPE_TAR || archive->type == 
XARCHIVETYPE_TAR_BZ2 || archive->type == XARCHIVETYPE_TAR_GZ)
@@ -1183,52 +1187,28 @@
                command = g_strconcat ("tar 
--strip-components=",digit,option,archive->escaped_path," -C 
/tmp",names->str,NULL);
                g_free (digit);
        }
-       else if (archive->type == XARCHIVETYPE_RPM)
-       {
-               command = xa_extract_single_files ( archive , names, "/tmp");
-               ViewFileFromArchive (archive->child_pid , 0 , dummy_name);
-       }
        else
                command = xa_extract_single_files ( archive , names, "/tmp");
 
        g_string_free (names,TRUE);
        archive->full_path = full_path;
        archive->overwrite = overwrite;
-
+       EmptyTextBuffer();
        if (command != NULL)
        {
-               SpawnAsyncProcess ( archive , command , 0, 0);
+               result = xa_run_command (command , 0);
                g_free (command);
-               if ( archive->child_pid == 0 )
+               if ( result == 0 )
+               {
+                       unlink (dummy_name);
+                       g_free (dummy_name);
                        return;
+               }
        }
-       g_child_watch_add ( archive->child_pid , (GChildWatchFunc) 
ViewFileFromArchive , dummy_name );
-}
 
-GChildWatchFunc *ViewFileFromArchive (GPid pid , gint status , gchar *data)
-{
-       GIOChannel *ioc_view = NULL;
-       gchar *line = NULL;
-       gchar *filename = NULL;
-       GError *error = NULL;
-       gchar *string = NULL;
-       gboolean tofree = FALSE;
-
-       if ( WIFEXITED( status ) )
-       {
-               if ( WEXITSTATUS ( status ) )
-               {
-               gtk_window_set_title ( GTK_WINDOW (MainWindow) , "Xarchiver " 
VERSION );
-                       response = ShowGtkMessageDialog 
(GTK_WINDOW(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,_("An
 error occurred while extracting the file to be viewed!"),("Do you want to open 
the error messages window?") );
-                       if (response == GTK_RESPONSE_YES)
-                               ShowShellOutput (NULL);
-                       unlink ( (char*)data );
-                       return NULL;
-               }
-       }
-       string = StripPathFromFilename ( data, "/" );
+       string = StripPathFromFilename ( dummy_name, "/" );
        if (  string == NULL )
-               filename = g_strconcat ( "/tmp/" , data, NULL );
+               filename = g_strconcat ( "/tmp/" , dummy_name, NULL );
        else
        {
                if ( strchr ( string , ' ' ) )
@@ -1240,7 +1220,7 @@
                if ( tofree )
                        g_free ( string );
        }
-       g_free (data);
+       g_free (dummy_name);
        view_window = view_win();
        ioc_view = g_io_channel_new_file ( filename , "r" , &error );
        if (error == NULL)
@@ -1261,14 +1241,15 @@
        {
                response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,"An error 
occurred while extracting the file to be viewed:",error->message);
                g_error_free (error);
+               unlink ( filename );
                Update_StatusBar ( _("Operation failed."));
-               return NULL;
+               return;
        }
        unlink ( filename );
        gtk_widget_show (view_window);
        g_free (filename);
+       OffTooltipPadlock();
        Update_StatusBar (_("Operation completed."));
-       return NULL;
 }
 
 void xa_iso_properties ( GtkMenuItem *menuitem , gpointer user_data )
@@ -1481,7 +1462,32 @@
 
 void ConcatenateFileNames2 (gchar *filename , GString *data)
 {
-       gchar *esc_filename = EscapeBadChars ( filename , 1 );
+       gchar *esc_filename = NULL;
+       gchar *escaped = NULL;
+       gchar *escaped2 = NULL;
+                       
+       if ( strstr (filename, "[") || strstr (filename, "]"))
+       {
+               if (archive->type == XARCHIVETYPE_ZIP)
+               {
+                       escaped = EscapeBadChars ( filename ,"*?[]");
+                       escaped2 = escape_str_common (escaped , "*?[]", '\\', 
0);
+                       g_free (escaped);
+                       esc_filename = escaped2;
+               }
+               else if ( (archive->type == XARCHIVETYPE_TAR_BZ2 || 
archive->type == XARCHIVETYPE_TAR_GZ || archive->type == XARCHIVETYPE_TAR) && 
archive->status == XA_ARCHIVESTATUS_EXTRACT)
+               {
+                       escaped = EscapeBadChars ( filename ,"?*\\'& !|()@#:;");
+                       escaped2 = escape_str_common ( escaped , "[]", '[', 
']');
+                       g_free (escaped);
+                       esc_filename = escaped2;
+               }
+               else
+                       esc_filename = EscapeBadChars ( filename , "$\'`\"\\!?* 
()[]&|@#:;" );
+       }
+       else
+               esc_filename = EscapeBadChars ( filename , "$\'`\"\\!?* 
()[]&|@#:;" );
+       
        g_string_prepend (data, esc_filename);
        g_string_prepend_c (data, ' ');
        g_free (esc_filename);
@@ -1489,7 +1495,8 @@
 
 void ConcatenateFileNames (GtkTreeModel *model, GtkTreePath *treepath, 
GtkTreeIter *iter, GString *data)
 {
-       gchar *filename;
+       gchar *filename = NULL;
+       
        gtk_tree_model_get (model, iter, 0, &filename, -1);
        ConcatenateFileNames2 ( filename , data );
        g_free (filename);

Modified: xarchiver/trunk/src/callbacks.h
===================================================================
--- xarchiver/trunk/src/callbacks.h     2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/callbacks.h     2006-08-24 12:58:23 UTC (rev 22867)
@@ -86,7 +86,7 @@
 void xa_iso_properties ( GtkMenuItem *menuitem , gpointer user_data );
 void xa_archive_properties ( GtkMenuItem *menuitem , gpointer user_data );
 void xa_append_rows ( XArchive *archive , unsigned short int nc );
-void View_File_Window ( GtkMenuItem *menuitem , gpointer user_data);
+void xa_view_file_inside_archive ( GtkMenuItem *menuitem , gpointer user_data 
);
 void xa_cancel_archive ( GtkMenuItem *menuitem , gpointer user_data);
 void xa_add_files_archive ( GtkMenuItem *menuitem, gpointer user_data );
 void Activate_buttons();
@@ -97,10 +97,7 @@
 
 GSList *Add_File_Dialog ( gchar *mode );
 int ShowGtkMessageDialog ( GtkWindow *window, int mode,int type,int button, 
const gchar *message1,const gchar *message2);
-int CountCharacter ( gchar *string , int chr );
-int is_escaped_char(char c);
 int DetectArchiveType ( gchar *filename );
-GChildWatchFunc *ViewFileFromArchive (GPid pid , gint status , gchar *data);
 
 gboolean key_press_function ( GtkWidget* widget, GdkEventKey* event,gpointer 
data);
 gboolean treeview_select_search (GtkTreeModel *model,gint column,const gchar 
*key,GtkTreeIter *iter,gpointer search_data);
@@ -120,14 +117,7 @@
 void OffTooltipPadlock();
 void Update_StatusBar (gchar *msg);
 void xa_watch_child ( GPid pid, gint status, gpointer data);
-gchar *EscapeBadChars ( gchar *string , gboolean doublesquare);
-gchar *StripPathFromFilename ( gchar *name, gchar *pattern );
-gchar *JoinPathArchiveName ( const gchar * , gchar * );
 char *Show_File_Dialog (int dummy , gpointer title);
-char *eat_spaces (char *line);
-gchar *remove_level_from_path (const gchar *path);
-gchar *extract_local_path (gchar *path , gchar *filename);
-gchar *RemoveBackSlashes ( gchar *name);
 void xa_about_activate_link (GtkAboutDialog *about, const gchar *link, 
gpointer data);
 gchar *name;
 gchar *permissions;

Modified: xarchiver/trunk/src/extract_dialog.c
===================================================================
--- xarchiver/trunk/src/extract_dialog.c        2006-08-24 12:23:22 UTC (rev 
22866)
+++ xarchiver/trunk/src/extract_dialog.c        2006-08-24 12:58:23 UTC (rev 
22867)
@@ -22,6 +22,7 @@
 #include "extract_dialog.h"
 #include "interface.h"
 #include "callbacks.h"
+#include "string_utils.h"
 #include "support.h"
 
 gboolean stop_flag;
@@ -309,7 +310,7 @@
 
                        case GTK_RESPONSE_OK:
                        destination_path = g_strdup (gtk_entry_get_text ( 
GTK_ENTRY (dialog_data->destination_path_entry) ));
-                       archive->extraction_path = EscapeBadChars ( 
destination_path , 0 );
+                       archive->extraction_path = EscapeBadChars ( 
destination_path , "$\'`\"\\!?* ()&|@#:;" );
 
                        if ( strlen ( archive->extraction_path ) == 0 )
                        {
@@ -324,7 +325,7 @@
                                response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK, _("This archive 
is encrypted!"),_("Please enter the password.") );
                                break;
                        }
-                       if (g_file_test (destination_path , G_FILE_TEST_EXISTS) 
== FALSE )
+                       if (g_file_test (destination_path , G_FILE_TEST_EXISTS) 
== FALSE) 
                        {
                                int result = mkdir (destination_path , S_IRUSR 
| S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXGRP);
                                if (result == -1)
@@ -335,7 +336,7 @@
                                        break;
                                }
                        }
-                       if (access (destination_path, R_OK | W_OK | X_OK | F_OK 
) != 0)
+                       if ( g_file_test (destination_path , 
G_FILE_TEST_IS_DIR) && access (destination_path, R_OK | W_OK | X_OK ) )
                        {
                                gchar *utf8_path;
                                gchar  *msg;
@@ -364,6 +365,7 @@
 
                        gtk_widget_set_sensitive (Stop_button,TRUE);
                        gtk_widget_hide (dialog_data->dialog1);
+                       archive->status = XA_ARCHIVESTATUS_EXTRACT;
                        /* Are all files selected? */
                        if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( 
dialog_data->all_files_radio )) )
                        {
@@ -600,7 +602,7 @@
                }
                else
                {
-                       xa_extract_tar_without_directories ( "tar -xvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, TRUE );
+                       xa_extract_tar_without_directories ( "tar -xvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, FALSE );
                        command = NULL;
                }
                break;
@@ -615,7 +617,7 @@
                }
                else
                {
-                       xa_extract_tar_without_directories ( "tar -xjvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, TRUE );
+                       xa_extract_tar_without_directories ( "tar -xjvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, FALSE );
                        command = NULL;
                }
                break;
@@ -630,7 +632,7 @@
                }
                else
                {
-                       xa_extract_tar_without_directories ( "tar -xzvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, TRUE );
+                       xa_extract_tar_without_directories ( "tar -xzvf " , 
archive->escaped_path, archive->overwrite,archive->tar_touch,path, FALSE );
                        command = NULL;
                }
                break;
@@ -744,13 +746,15 @@
        gchar *permission = NULL;
        gchar tmp_dir[14] = "";
        GtkTreeSelection *selection;
-       GString *names;
+       GString *names, *unescaped_names;
        gboolean end = FALSE;
        GtkTreeIter iter;
        GList *row_list;
+       GSList *filenames = NULL;
        gboolean result;
 
        names = g_string_new ("");
+       unescaped_names = g_string_new ("");
        selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview1) );
        row_list = gtk_tree_selection_get_selected_rows (selection, &model);
        
@@ -766,7 +770,10 @@
                        gtk_tree_path_free (row_list->data);
 
                        if (strstr (permission ,"d") == NULL)
+                       {
                                ConcatenateFileNames2 ( name , names );
+                               filenames = g_slist_append ( filenames,name );
+                       }
                        g_free (permission);
                        row_list = row_list->next;
                }
@@ -780,7 +787,10 @@
                        gtk_tree_model_get (model, &iter,       0, &name,
                                                                                
                1, &permission, -1);
                        if (strstr (permission ,"d") == NULL)
+                       {
                                ConcatenateFileNames2 ( name , names );
+                               filenames = g_slist_append ( filenames,name );
+                       }
                        g_free (permission);
                        end = gtk_tree_model_iter_next (model,&iter);
                }
@@ -800,6 +810,7 @@
                                                                                
tar_touch ? " --touch" : "",
                                                                                
" -C " , tmp_dir , names->str, NULL );
        result = xa_run_command (command , 0);
+       g_string_free (names, TRUE);
        g_free (command);
 
        if (result == 0 || stop_flag)
@@ -810,10 +821,20 @@
                return FALSE;
        }
        chdir (tmp_dir);
-       command = g_strconcat ( "mv -f ", names->str, " " , extract_path , NULL 
);
+       while (filenames)
+       {
+               gchar *unescaped = EscapeBadChars ( filenames->data , 
"$\'`\"\\!?* ()[]&|@#:;");
+               g_string_prepend ( unescaped_names, unescaped );
+               g_string_prepend_c (unescaped_names, ' ');
+               g_free (unescaped);
+               filenames = filenames->next;
+       }
+       command = g_strconcat ( "mv -f ", unescaped_names->str, " " , 
extract_path , NULL );
        result = xa_run_command (command , 0);
        g_free (command);
-       g_string_free (names, TRUE);
+       g_slist_free (filenames);
+       g_string_free ( unescaped_names, TRUE );
+
        if (result == 0 || stop_flag)
        {
                xa_delete_temp_directory ( tmp_dir, 0 );
@@ -825,6 +846,7 @@
                xa_delete_temp_directory ( tmp_dir, 0 );
        else
                xa_delete_temp_directory ( tmp_dir, 1 );
+       
        return result;
 }
 
@@ -851,3 +873,4 @@
        }
        return TRUE;
 }
+

Modified: xarchiver/trunk/src/interface.c
===================================================================
--- xarchiver/trunk/src/interface.c     2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/interface.c     2006-08-24 12:58:23 UTC (rev 22867)
@@ -357,7 +357,7 @@
        g_signal_connect ((gpointer) iso_info, "activate", G_CALLBACK 
(xa_iso_properties), NULL);
        g_signal_connect ((gpointer) quit1, "activate", G_CALLBACK 
(xa_quit_application), NULL);
        g_signal_connect ((gpointer) delete_menu, "activate", G_CALLBACK 
(xa_delete_archive), NULL);
-       g_signal_connect ((gpointer) view_menu, "activate", G_CALLBACK 
(View_File_Window), NULL);
+       g_signal_connect ((gpointer) view_menu, "activate", G_CALLBACK 
(xa_view_file_inside_archive), NULL);
        g_signal_connect ((gpointer) about1, "activate", G_CALLBACK (xa_about), 
NULL);
 
        g_signal_connect ((gpointer) New_button, "clicked", G_CALLBACK 
(xa_new_archive), NULL);
@@ -365,7 +365,7 @@
        g_signal_connect ((gpointer) AddFile_button, "clicked", G_CALLBACK 
(xa_add_files_archive), NULL);
     g_signal_connect ((gpointer) Extract_button, "clicked", G_CALLBACK 
(xa_extract_archive), NULL);
        g_signal_connect ((gpointer) Delete_button, "clicked", G_CALLBACK 
(xa_delete_archive), NULL);
-       g_signal_connect ((gpointer) View_button, "clicked", G_CALLBACK 
(View_File_Window), NULL);
+       g_signal_connect ((gpointer) View_button, "clicked", G_CALLBACK 
(xa_view_file_inside_archive), NULL);
        g_signal_connect ((gpointer) Stop_button, "clicked", G_CALLBACK 
(xa_cancel_archive), NULL);
        g_signal_connect (MainWindow, "key-press-event", G_CALLBACK 
(key_press_function), NULL);
 

Modified: xarchiver/trunk/src/iso.c
===================================================================
--- xarchiver/trunk/src/iso.c   2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/iso.c   2006-08-24 12:58:23 UTC (rev 22867)
@@ -21,6 +21,7 @@
 
 #include "config.h"
 #include "iso.h"
+#include "string_utils.h"
 
 unsigned char buffer[2048];
 

Modified: xarchiver/trunk/src/main.c
===================================================================
--- xarchiver/trunk/src/main.c  2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/main.c  2006-08-24 12:58:23 UTC (rev 22867)
@@ -18,6 +18,7 @@
  
 #include "config.h"
 #include "main.h"
+#include "string_utils.h"
 
 gint exit_status;
 gchar *cli_command = NULL;
@@ -98,7 +99,7 @@
                                                GString *string = g_string_new 
( "" );
                                                archive->full_path = 1;
                                                archive->overwrite = 1;
-                                               gchar *escaped_path = 
EscapeBadChars (extract_path , 1);
+                                               gchar *escaped_path = 
EscapeBadChars (extract_path , "$\'`\"\\!?* ()[]&|@#:;");
                                                archive->extraction_path = 
g_strdup (extract_path);
                                                cli_command = 
xa_extract_single_files ( archive , string, escaped_path );
                                                g_free (escaped_path);
@@ -281,6 +282,14 @@
                g_free (absolute_path);
        }
 
+       absolute_path = g_find_program_in_path("rar");
+    if ( absolute_path )
+       {
+               ArchiveType = g_list_prepend ( ArchiveType, ".rar");
+               ArchiveSuffix = g_list_prepend ( ArchiveSuffix, "*.rar");
+               g_free (absolute_path);
+       }
+
        absolute_path = g_find_program_in_path("tar");
        if ( absolute_path )
        {
@@ -300,14 +309,6 @@
                }
        }
 
-       absolute_path = g_find_program_in_path("rar");
-    if ( absolute_path )
-       {
-               ArchiveType = g_list_prepend ( ArchiveType, ".rar");
-               ArchiveSuffix = g_list_prepend ( ArchiveSuffix, "*.rar");
-               g_free (absolute_path);
-       }
-
        absolute_path = g_find_program_in_path("zip");
     if ( absolute_path )
        {
@@ -383,7 +384,7 @@
 {
        archive = xa_init_archive_structure (archive);
        archive->path = g_strdup (filename);
-       archive->escaped_path = EscapeBadChars(filename , 0);
+       archive->escaped_path = EscapeBadChars(filename , "$\'`\"\\!?* 
()&|@#:;");
        archive->type = DetectArchiveType ( archive->path );
        if (archive->type == -2)
                return NULL;

Modified: xarchiver/trunk/src/rar.c
===================================================================
--- xarchiver/trunk/src/rar.c   2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/rar.c   2006-08-24 12:58:23 UTC (rev 22867)
@@ -18,6 +18,7 @@
  
 #include "config.h"
 #include "rar.h"
+#include "string_utils.h"
 
 void OpenRar ( XArchive *archive )
 {

Modified: xarchiver/trunk/src/rpm.c
===================================================================
--- xarchiver/trunk/src/rpm.c   2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/rpm.c   2006-08-24 12:58:23 UTC (rev 22867)
@@ -19,6 +19,7 @@
  
 #include "config.h"
 #include "rpm.h"
+#include "string_utils.h"
 
 extern int output_fd, input_fd;
 FILE *stream;

Modified: xarchiver/trunk/src/string_utils.c
===================================================================
--- xarchiver/trunk/src/string_utils.c  2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/string_utils.c  2006-08-24 12:58:23 UTC (rev 22867)
@@ -21,74 +21,12 @@
 #include <string.h>
 #include "string_utils.h"
 
-//Taken from xarchive - http://xarchive.sourceforge.net
-int is_escaped_char (char c)
+gchar *EscapeBadChars ( gchar *string , gchar *pattern)
 {
-    switch ( c )
-    {
-        case ' ':
-        case '\'':
-        case '"':
-        case '(':
-        case ')':
-        case '$':
-        case '\\':
-        case ';':
-        case '<':
-        case '>':
-        case '&':
-        case '#':
-        case '*':
-        case '|':
-        case '`':
-        case '!':
-        return 1;
-        default:
-        return 0;
-    }
+       return escape_str_common (string, pattern, '\\', 0);
 }
 
-gchar *EscapeBadChars ( gchar *string , gboolean doublesquare)
-{
-       char *q;
-       char *escaped;
-       int escapechars = 0;
-       char *p = string;
 
-       while (*p != '\000')
-       {
-        if (is_escaped_char(*p))
-                       escapechars++;
-               /* The following is mine */
-               else if ( doublesquare && (*p == '[' || *p == ']') )
-                       escapechars += 2;
-               p++;
-    }
-
-       if (!escapechars)
-               return g_strdup(string);
-       escaped = (char *) g_malloc (strlen(string) + escapechars + 1);
-
-       p = string;
-       q = escaped;
-
-       while (*p != '\000')
-       {
-               if (is_escaped_char(*p))
-                       *q++ = '\\';
-               /* The following is mine */
-               else if ( doublesquare && (*p == '[' || *p == ']') )
-               {
-                       *q++ = '\\';
-                       *q++ = '\\';
-               }
-               *q++ = *p++;
-       }
-       *q = '\000';
-       return escaped;
-}
-//End code from xarchive
-
 gchar *StripPathFromFilename ( gchar *name, gchar *pattern )
 {
     return g_strrstr ( name , pattern );
@@ -126,6 +64,58 @@
 }
 
 /* These functions are from File-Roller code */
+static int count_chars_to_escape (const char *str, const char *meta_chars)
+{
+        int         meta_chars_n = strlen (meta_chars);
+        const char *s;
+        int         n = 0;
+
+        for (s = str; *s != 0; s++) {
+                int i;
+                for (i = 0; i < meta_chars_n; i++)
+                        if (*s == meta_chars[i]) {
+                                n++;
+                                break;
+                        }
+        }
+        return n;
+}
+char *escape_str_common (const char *str, const char *meta_chars, const char  
prefix, const char  postfix)
+{
+        int         meta_chars_n = strlen (meta_chars);
+        char       *escaped;
+        int         i, new_l, extra_chars = 0;
+        const char *s;
+        char       *t;
+
+        if (str == NULL)
+                return NULL;
+
+        if (prefix)
+                extra_chars++;
+        if (postfix)
+                extra_chars++;
+
+        new_l = strlen (str) + (count_chars_to_escape (str, meta_chars) * 
extra_chars);
+        escaped = g_malloc (new_l + 1);
+
+        s = str;
+        t = escaped;
+        while (*s) {
+                gboolean is_bad = FALSE;
+                for (i = 0; (i < meta_chars_n) && !is_bad; i++)
+                        is_bad = (*s == meta_chars[i]);
+                if (is_bad && prefix)
+                        *t++ = prefix;
+                *t++ = *s++;
+                if (is_bad && postfix)
+                        *t++ = postfix;
+        }
+        *t = 0;
+
+        return escaped;
+}
+
 char *eat_spaces (char *line)
 {
        if (line == NULL)
@@ -175,11 +165,10 @@
        }
        else
                x = strlen (path) - strlen ( filename );
-    //g_print ("%d\t%d\t%d\n",x,strlen (path),strlen (filename));
     local_path = (gchar *) g_malloc ( x + 1);
     strncpy ( local_path, path, x );
     local_path [x] = '\000';
-    local_escaped_path = EscapeBadChars ( local_path , 1);
+    local_escaped_path = EscapeBadChars ( local_path ,"$\'`\"\\!?* 
()[]&|@#:;");
     g_free (local_path);
     return local_escaped_path;
 }

Modified: xarchiver/trunk/src/string_utils.h
===================================================================
--- xarchiver/trunk/src/string_utils.h  2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/string_utils.h  2006-08-24 12:58:23 UTC (rev 22867)
@@ -19,12 +19,12 @@
 #ifndef STRING_UTILS_H
 #define STRING_UTILS_H
 
-int is_escaped_char (char c);
-gchar *EscapeBadChars ( gchar *string , gboolean doublesquare);
+gchar *EscapeBadChars ( gchar *string , gchar *pattern);
 gchar *StripPathFromFilename ( gchar *name, gchar *pattern );
 gchar *JoinPathArchiveName ( const gchar *extract_path , gchar *path );
 int CountCharacter ( gchar *string , int chr );
 gchar *RemoveBackSlashes ( gchar *name);
+char *escape_str_common (const char *str, const char *meta_chars, const char  
prefix, const char  postfix);
 char *eat_spaces (char *line);
 gchar *remove_level_from_path (const gchar *path);
 gboolean file_extension_is (const char *filename, const char *ext);

Modified: xarchiver/trunk/src/zip.c
===================================================================
--- xarchiver/trunk/src/zip.c   2006-08-24 12:23:22 UTC (rev 22866)
+++ xarchiver/trunk/src/zip.c   2006-08-24 12:58:23 UTC (rev 22867)
@@ -19,7 +19,8 @@
  
 #include "config.h"
 #include "zip.h"
- 
+#include "string_utils.h"
+
 void OpenZip ( XArchive *archive )
 {
        gchar *command = g_strconcat ("unzip -vl -qq " , archive->escaped_path, 
NULL );

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to