91
83
#endif /* !HAVE_STRCASESTR */
93
gchar *EscapeBadChars ( gchar *string , gchar *pattern)
95
return escape_str_common (string, pattern, '\\', 0);
98
gchar *JoinPathArchiveName ( const gchar *extract_path , gchar *path )
100
return g_strconcat (extract_path , path , NULL);
103
int CountCharacter ( gchar *string , int chr )
108
if ( *string == chr ) n++;
114
gchar *RemoveBackSlashes ( gchar *name)
117
int x = CountCharacter ( name , '\\' );
118
nome = (char *) g_malloc (strlen(name) - x + 1);
122
if ( *name == '\\' ) name++;
85
gchar *xa_escape_bad_chars ( gchar *string , gchar *pattern)
87
return xa_escape_common_chars (string, pattern, '\\', 0);
129
90
/* These functions are from File-Roller code */
130
char *get_last_field (char *line,int last_field)
139
field = eat_spaces (line);
140
for (i = 0; i < last_field; i++) {
143
field = strchr (field, ' ');
144
field = eat_spaces (field);
146
//The following line is mine, I replace the \n with the null terminated
147
if (field != NULL) field [ strlen(field) -1 ] = '\000';
151
char **split_line (char *line,int n_fields)
154
char *scan, *field_end;
157
fields = g_new0 (char *, n_fields + 1);
158
fields[n_fields] = NULL;
160
scan = eat_spaces (line);
161
for (i = 0; i < n_fields; i++)
168
field_end = strchr (scan, ' ');
169
//The following line is mine, I added the case when the last field ends with a newline
170
if (field_end == NULL) field_end = strchr (scan, '\n');
171
if (field_end != NULL)
173
fields[i] = g_strndup (scan, field_end - scan);
174
scan = eat_spaces (field_end);
180
92
static int count_chars_to_escape (const char *str, const char *meta_chars)
182
int meta_chars_n = strlen (meta_chars);
94
int meta_chars_n = strlen (meta_chars);
186
for (s = str; *s != 0; s++) {
188
for (i = 0; i < meta_chars_n; i++)
189
if (*s == meta_chars[i]) {
98
for (s = str; *s != 0; s++)
101
for (i = 0; i < meta_chars_n; i++)
102
if (*s == meta_chars[i])
196
char *escape_str_common (const char *str, const char *meta_chars, const char prefix, const char postfix)
110
char *xa_escape_common_chars (const char *str, const char *meta_chars, const char prefix, const char postfix)
198
112
int meta_chars_n = strlen (meta_chars);
265
173
/* End code from File-Roller */
267
gchar *extract_local_path (gchar *path)
270
gchar *local_escaped_path;
272
local_path = g_path_get_dirname (path);
273
local_escaped_path = EscapeBadChars ( local_path ,"$\'`\"\\!?* ()[]&|@#:;");
275
return local_escaped_path;
278
void xa_set_window_title ( GtkWidget *window , gchar *title)
175
void xa_set_window_title (GtkWidget *window,gchar *title)
281
178
gchar *slash= NULL;
182
slash = g_strrstr (title , "/");
283
189
if (title == NULL)
284
gtk_window_set_title ( GTK_WINDOW (window) , "Xarchiver " VERSION );
287
slash = g_strrstr (title , "/");
290
x = g_strconcat ( title , " - " , "Xarchiver " , VERSION , NULL);
291
gtk_window_set_title ( GTK_WINDOW (window) , x);
190
x = g_strconcat ("Xarchiver ",VERSION,NULL);
192
x = g_strconcat (slash, " - Xarchiver ",VERSION,NULL);
193
gtk_window_set_title (GTK_WINDOW (window),x);
197
gboolean match_patterns (char **patterns,const char *string,int flags)
202
if (patterns[0] == NULL)
208
result = FNM_NOMATCH;
210
while ((result != 0) && (patterns[i] != NULL))
212
result = g_utf8_fnmatch (patterns[i],string,flags);
215
return (result == 0);
218
gchar *xa_remove_path_from_archive_name(gchar *name)
220
gchar *utf8_string,*text;
222
text = g_strrstr (name,"/");
226
utf8_string = g_filename_display_name (text);
229
utf8_string = g_filename_display_name (name);
234
gchar *xa_escape_filename (gchar *filename,gchar *meta_chars)
236
return xa_escape_common_chars (filename,meta_chars,'\\',0);
239
gchar *xa_strip_current_working_dir_from_path(gchar *working_dir,gchar *filename)
244
if (working_dir == NULL)
246
len = strlen(working_dir)+1;
247
slash = g_strrstr(filename,"/");
248
if (slash == NULL || ! g_path_is_absolute(filename))
254
void xa_cat_filenames (XArchive *archive,GSList *list,GString *data)
256
gchar *basename, *name, *e_filename;
257
GSList *slist = list;
261
if (archive->location_entry_path != NULL)
263
if (archive->full_path == 0)
265
basename = xa_strip_current_working_dir_from_path(archive->working_dir ? archive->working_dir : archive->tmp,slist->data);
266
name = g_strconcat(archive->location_entry_path,basename,NULL);
267
e_filename = xa_escape_filename(name,"$'`\"\\!?* ()[]&|:;<>#");
268
g_string_prepend (data,e_filename);
269
g_string_prepend_c (data,' ');
274
name = g_strconcat(archive->location_entry_path,slist->data,NULL);
275
e_filename = xa_escape_filename(name,"$'`\"\\!?* ()[]&|:;<>#");
276
g_string_prepend (data,e_filename);
277
g_string_prepend_c (data,' ');
283
if (archive->full_path == 0)
285
basename = xa_strip_current_working_dir_from_path(archive->working_dir ? archive->working_dir : archive->tmp,slist->data);
286
e_filename = xa_escape_filename(basename,"$'`\"\\!?* ()[]&|:;<>#");
287
g_string_prepend (data,e_filename);
288
g_string_prepend_c (data,' ');
292
e_filename = xa_escape_filename(slist->data,"$'`\"\\!?* ()[]&|:;<>#");
293
g_string_prepend (data,e_filename);
294
g_string_prepend_c (data,' ');
301
GSList *xa_slist_copy(GSList *list)
308
y = g_slist_prepend(y,g_strdup(x->data));
311
return g_slist_reverse(y);
314
void xa_recurse_local_directory(gchar *path,GSList **list,gboolean recurse,gint type)
317
struct dirent *dirlist;
318
gchar *fullname = NULL,*basename = NULL;
322
is_dir = g_file_test(path,G_FILE_TEST_IS_DIR);
323
if (is_dir && type != XARCHIVETYPE_ARJ && is_tar_compressed(type) == FALSE)
324
*list = g_slist_prepend(*list,g_strdup(path));
329
basename = g_path_get_basename(path);
330
*list = g_slist_prepend(*list,basename);
297
x = g_strconcat ( slash , " - " , "Xarchiver " , VERSION , NULL);
299
gtk_window_set_title ( GTK_WINDOW (window) , x);
335
while ((dirlist = readdir(dir)))
337
if (strcmp(dirlist->d_name,".") == 0 || strcmp(dirlist->d_name,"..") == 0)
339
fullname = g_strconcat (path,"/",dirlist->d_name,NULL);
340
is_dir = g_file_test(fullname,G_FILE_TEST_IS_DIR);
342
*list = g_slist_prepend(*list,fullname);
343
if (recurse && is_dir)
344
xa_recurse_local_directory(fullname,list,recurse,type);