1998-02-27 07:54:42 +03:00
|
|
|
/* Directory routines
|
|
|
|
Copyright (C) 1994 Miguel de Icaza.
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
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.
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
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 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
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
|
|
|
#include <errno.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <sys/stat.h>
|
2001-09-07 21:52:19 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "global.h"
|
2001-09-07 21:52:19 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "dir.h"
|
2002-11-14 10:25:18 +03:00
|
|
|
#include "wtools.h"
|
2003-10-24 03:57:59 +04:00
|
|
|
#include "treestore.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-11-15 02:20:37 +03:00
|
|
|
/* If true show files starting with a dot */
|
1998-02-27 07:54:42 +03:00
|
|
|
int show_dot_files = 1;
|
|
|
|
|
|
|
|
/* If true show files ending in ~ */
|
2002-01-17 08:42:00 +03:00
|
|
|
int show_backups = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* If false then directories are shown separately from files */
|
|
|
|
int mix_all_files = 0;
|
|
|
|
|
|
|
|
/* Reverse flag */
|
|
|
|
static int reverse = 1;
|
|
|
|
|
|
|
|
/* Are the files sorted case sensitively? */
|
|
|
|
static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
|
|
|
|
|
2003-08-18 04:47:43 +04:00
|
|
|
#define MY_ISDIR(x) ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 1 : 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
|
Fri Apr 3 05:23:20 1998 Alex Tkachenko <alex@bcs.zp.ua>
* configure.in: ALL_LINGUAS test added, to allow specify list
of languages to be installed by setting env variable before
configure. If it is empty, it defaults to full list.
* src/menu.h menu_entry.{hot_pos, is_dupped} dropped
* src/menu.c: consistency fixes: pull-down menu items are now
accessible either with arrow keys or with hotkeys, denoted with &
(and highlighted). (key combinations, placed to the right of items
intended to be used from outside the menus). Freeing menu entries
removed as it no longer needed
* src/main.c, edit/editmenu.c: menubar init code is changed to conform
above fixes.
* edit/edit.h: use of "Cancel" in error_dialogs replaced with
"Dismiss", to avoid collisions in translation of "Cancel" in other
places with this case.
* src/boxes.c: select_format() and it's support removed, as it is
obsoleted by input line history feature. display_init()/display_callback
fixed to suite i18n changes. sort_box() - alike.
* src/option.c: pause_options added &'s and gettext calls to expand
statically assigned values.
* src/widget.c: (radio_callback) hotkey recognition is changed to
&-notation, rather than simple uppercase.
* src/dlg.c: (dlg_try_hotkey) plain symbol comparison replaced with
call to isalpha(), this fixes errorneous exit from input line, when
button hotkey is 8-bit NLS char.
1998-04-04 00:00:00 +04:00
|
|
|
{ N_("&Unsorted"), unsorted },
|
|
|
|
{ N_("&Name"), sort_name },
|
|
|
|
{ N_("&Extension"), sort_ext },
|
|
|
|
{ N_("&Modify time"), sort_time },
|
|
|
|
{ N_("&Access time"), sort_atime },
|
|
|
|
{ N_("&Change time"), sort_ctime },
|
|
|
|
{ N_("&Size"), sort_size },
|
|
|
|
{ N_("&Inode"), sort_inode },
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* New sort orders */
|
Fri Apr 3 05:23:20 1998 Alex Tkachenko <alex@bcs.zp.ua>
* configure.in: ALL_LINGUAS test added, to allow specify list
of languages to be installed by setting env variable before
configure. If it is empty, it defaults to full list.
* src/menu.h menu_entry.{hot_pos, is_dupped} dropped
* src/menu.c: consistency fixes: pull-down menu items are now
accessible either with arrow keys or with hotkeys, denoted with &
(and highlighted). (key combinations, placed to the right of items
intended to be used from outside the menus). Freeing menu entries
removed as it no longer needed
* src/main.c, edit/editmenu.c: menubar init code is changed to conform
above fixes.
* edit/edit.h: use of "Cancel" in error_dialogs replaced with
"Dismiss", to avoid collisions in translation of "Cancel" in other
places with this case.
* src/boxes.c: select_format() and it's support removed, as it is
obsoleted by input line history feature. display_init()/display_callback
fixed to suite i18n changes. sort_box() - alike.
* src/option.c: pause_options added &'s and gettext calls to expand
statically assigned values.
* src/widget.c: (radio_callback) hotkey recognition is changed to
&-notation, rather than simple uppercase.
* src/dlg.c: (dlg_try_hotkey) plain symbol comparison replaced with
call to isalpha(), this fixes errorneous exit from input line, when
button hotkey is 8-bit NLS char.
1998-04-04 00:00:00 +04:00
|
|
|
{ N_("&Type"), sort_type },
|
|
|
|
{ N_("&Links"), sort_links },
|
|
|
|
{ N_("N&GID"), sort_ngid },
|
|
|
|
{ N_("N&UID"), sort_nuid },
|
|
|
|
{ N_("&Owner"), sort_owner },
|
|
|
|
{ N_("&Group"), sort_group }
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
2001-08-12 12:20:31 +04:00
|
|
|
#ifdef HAVE_STRCOLL
|
2001-01-27 08:51:26 +03:00
|
|
|
/*
|
2001-08-12 12:20:31 +04:00
|
|
|
* g_strcasecmp() doesn't work well in some locales because it relies on
|
|
|
|
* the locale-specific toupper(). On the other hand, strcoll() is case
|
|
|
|
* sensitive in the "C" and "POSIX" locales, unlike other locales.
|
|
|
|
* Solution: always use strcmp() for case sensitive sort. For case
|
|
|
|
* insensitive sort use strcoll() if it's case insensitive for ASCII and
|
|
|
|
* g_strcasecmp() otherwise.
|
2001-01-27 08:51:26 +03:00
|
|
|
*/
|
2001-08-12 12:20:31 +04:00
|
|
|
typedef enum {
|
|
|
|
STRCOLL_NO,
|
|
|
|
STRCOLL_YES,
|
|
|
|
STRCOLL_TEST
|
|
|
|
} strcoll_status;
|
|
|
|
|
2004-08-30 02:38:06 +04:00
|
|
|
static int string_sortcomp (const char *str1, const char *str2)
|
2001-08-12 12:20:31 +04:00
|
|
|
{
|
|
|
|
static strcoll_status use_strcoll = STRCOLL_TEST;
|
|
|
|
|
|
|
|
if (case_sensitive) {
|
|
|
|
return strcmp (str1, str2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize use_strcoll once. */
|
|
|
|
if (use_strcoll == STRCOLL_TEST) {
|
|
|
|
/* Only use strcoll() if it considers "B" between "a" and "c". */
|
|
|
|
if (strcoll ("a", "B") * strcoll ("B", "c") > 0) {
|
|
|
|
use_strcoll = STRCOLL_YES;
|
|
|
|
} else {
|
|
|
|
use_strcoll = STRCOLL_NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_strcoll == STRCOLL_NO)
|
|
|
|
return g_strcasecmp (str1, str2);
|
|
|
|
else
|
|
|
|
return strcoll (str1, str2);
|
|
|
|
}
|
2001-01-27 08:51:26 +03:00
|
|
|
#else
|
|
|
|
#define string_sortcomp(a,b) (case_sensitive ? strcmp (a,b) : g_strcasecmp (a,b))
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
unsorted (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
2005-02-09 01:33:52 +03:00
|
|
|
(void) a;
|
|
|
|
(void) b;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_name (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (ad == bd || mix_all_files)
|
|
|
|
return string_sortcomp (a->fname, b->fname) * reverse;
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_ext (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
2004-08-30 02:38:06 +04:00
|
|
|
const char *exta, *extb;
|
1998-02-27 07:54:42 +03:00
|
|
|
int r;
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files){
|
|
|
|
exta = extension (a->fname);
|
|
|
|
extb = extension (b->fname);
|
|
|
|
r = string_sortcomp (exta, extb);
|
|
|
|
if (r)
|
|
|
|
return r * reverse;
|
|
|
|
else
|
|
|
|
return sort_name (a, b);
|
|
|
|
} else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_owner (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return string_sortcomp (get_owner (a->st.st_uid), get_owner (a->st.st_uid)) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_group (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return string_sortcomp (get_group (a->st.st_gid), get_group (a->st.st_gid)) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_time (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (a->st.st_mtime - b->st.st_mtime) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_ctime (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (a->st.st_ctime - b->st.st_ctime) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_atime (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (a->st.st_atime - b->st.st_atime) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_inode (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (a->st.st_ino - b->st.st_ino) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_size (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
2003-01-20 20:06:24 +03:00
|
|
|
if (ad != bd && !mix_all_files)
|
|
|
|
return bd - ad;
|
|
|
|
|
2003-08-18 04:47:43 +04:00
|
|
|
return (2 * (b->st.st_size > a->st.st_size) - 1) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_links (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (b->st.st_nlink - a->st.st_nlink) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_ngid (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (b->st.st_gid - a->st.st_gid) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_nuid (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int ad = MY_ISDIR (a);
|
|
|
|
int bd = MY_ISDIR (b);
|
|
|
|
|
|
|
|
if (ad == bd || mix_all_files)
|
2003-08-18 04:47:43 +04:00
|
|
|
return (b->st.st_uid - a->st.st_uid) * reverse;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
return bd-ad;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static int
|
|
|
|
file_type_to_num (const file_entry *fe)
|
|
|
|
{
|
2003-08-18 04:47:43 +04:00
|
|
|
const struct stat *s = &fe->st;
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (S_ISDIR (s->st_mode))
|
|
|
|
return 0;
|
|
|
|
if (S_ISLNK (s->st_mode)){
|
|
|
|
if (fe->f.link_to_dir)
|
|
|
|
return 1;
|
2002-10-14 02:23:17 +04:00
|
|
|
if (fe->f.stale_link)
|
1998-02-27 07:54:42 +03:00
|
|
|
return 2;
|
|
|
|
else
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (S_ISSOCK (s->st_mode))
|
|
|
|
return 4;
|
|
|
|
if (S_ISCHR (s->st_mode))
|
|
|
|
return 5;
|
|
|
|
if (S_ISBLK (s->st_mode))
|
|
|
|
return 6;
|
|
|
|
if (S_ISFIFO (s->st_mode))
|
|
|
|
return 7;
|
2004-11-03 23:31:59 +03:00
|
|
|
if (S_ISNAM (s->st_mode)) /* Special named files will be shown as block devices */
|
|
|
|
return 6;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_exe (s->st_mode))
|
|
|
|
return 8;
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sort_type (const file_entry *a, const file_entry *b)
|
|
|
|
{
|
|
|
|
int aa = file_type_to_num (a);
|
|
|
|
int bb = file_type_to_num (b);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return bb-aa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f)
|
|
|
|
{
|
2001-11-14 23:32:47 +03:00
|
|
|
int dot_dot_found = 0;
|
2006-01-29 14:23:36 +03:00
|
|
|
|
|
|
|
if (top == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If there is an ".." entry the caller must take care to
|
|
|
|
ensure that it occupies the first list element. */
|
|
|
|
if (!strcmp (list->list [0].fname, ".."))
|
|
|
|
dot_dot_found = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
reverse = reverse_f ? -1 : 1;
|
|
|
|
case_sensitive = case_sensitive_f;
|
2001-11-14 23:32:47 +03:00
|
|
|
qsort (&(list->list) [dot_dot_found],
|
|
|
|
top + 1 - dot_dot_found, sizeof (file_entry), sort);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-02-18 03:07:26 +03:00
|
|
|
void
|
|
|
|
clean_dir (dir_list *list, int count)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (list->list [i].fname);
|
1998-02-27 07:54:42 +03:00
|
|
|
list->list [i].fname = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 09:01:08 +04:00
|
|
|
static int
|
1998-02-27 07:54:42 +03:00
|
|
|
add_dotdot_to_list (dir_list *list, int index)
|
|
|
|
{
|
|
|
|
/* Need to grow the *list? */
|
|
|
|
if (index == list->size) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
list->list = g_realloc (list->list, sizeof (file_entry) *
|
1998-02-27 07:54:42 +03:00
|
|
|
(list->size + RESIZE_STEPS));
|
|
|
|
if (!list->list)
|
|
|
|
return 0;
|
|
|
|
list->size += RESIZE_STEPS;
|
|
|
|
}
|
|
|
|
|
2002-01-20 23:05:40 +03:00
|
|
|
memset (&(list->list) [index], 0, sizeof(file_entry));
|
1998-02-27 07:54:42 +03:00
|
|
|
(list->list) [index].fnamelen = 2;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
(list->list) [index].fname = g_strdup ("..");
|
1998-02-27 07:54:42 +03:00
|
|
|
(list->list) [index].f.link_to_dir = 0;
|
2002-10-14 02:23:17 +04:00
|
|
|
(list->list) [index].f.stale_link = 0;
|
1998-12-25 00:37:24 +03:00
|
|
|
(list->list) [index].f.dir_size_computed = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
(list->list) [index].f.marked = 0;
|
2003-08-18 04:47:43 +04:00
|
|
|
(list->list) [index].st.st_mode = 040755;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used to set up a directory list when there is no access to a directory */
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
|
|
|
set_zero_dir (dir_list *list)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return (add_dotdot_to_list (list, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If you change handle_dirent then check also handle_path. */
|
|
|
|
/* Return values: -1 = failure, 0 = don't add, 1 = add to the list */
|
2003-10-15 01:58:56 +04:00
|
|
|
static int
|
2004-08-30 02:38:06 +04:00
|
|
|
handle_dirent (dir_list *list, const char *filter, struct dirent *dp,
|
1999-02-18 03:07:26 +03:00
|
|
|
struct stat *buf1, int next_free, int *link_to_dir,
|
2002-10-14 02:23:17 +04:00
|
|
|
int *stale_link)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-01-19 15:07:43 +03:00
|
|
|
if (dp->d_name[0] == '.' && dp->d_name[1] == 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
2003-01-19 15:07:43 +03:00
|
|
|
if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0)
|
2002-06-21 01:10:06 +04:00
|
|
|
return 0;
|
2003-01-19 15:07:43 +03:00
|
|
|
if (!show_dot_files && (dp->d_name[0] == '.'))
|
2002-06-21 01:10:06 +04:00
|
|
|
return 0;
|
2003-01-19 15:07:43 +03:00
|
|
|
if (!show_backups && dp->d_name[NLENGTH (dp) - 1] == '~')
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
1998-11-03 00:47:06 +03:00
|
|
|
if (mc_lstat (dp->d_name, buf1) == -1) {
|
2003-01-19 15:07:43 +03:00
|
|
|
/*
|
2003-01-21 03:31:43 +03:00
|
|
|
* lstat() fails - such entries should be identified by
|
|
|
|
* buf1->st_mode being 0.
|
|
|
|
* It happens on QNX Neutrino for /fs/cd0 if no CD is inserted.
|
2003-01-19 15:07:43 +03:00
|
|
|
*/
|
2003-01-21 03:31:43 +03:00
|
|
|
memset (buf1, 0, sizeof (*buf1));
|
1998-11-03 00:47:06 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (S_ISDIR (buf1->st_mode))
|
1999-01-09 06:43:05 +03:00
|
|
|
tree_store_mark_checked (dp->d_name);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* A link to a file or a directory? */
|
|
|
|
*link_to_dir = 0;
|
2002-10-14 02:23:17 +04:00
|
|
|
*stale_link = 0;
|
2003-01-19 15:07:43 +03:00
|
|
|
if (S_ISLNK (buf1->st_mode)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
struct stat buf2;
|
|
|
|
if (!mc_stat (dp->d_name, &buf2))
|
2003-01-19 15:07:43 +03:00
|
|
|
*link_to_dir = S_ISDIR (buf2.st_mode) != 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
2002-10-14 02:23:17 +04:00
|
|
|
*stale_link = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-01-19 15:07:43 +03:00
|
|
|
if (!(S_ISDIR (buf1->st_mode) || *link_to_dir) && filter
|
|
|
|
&& !regexp_match (filter, dp->d_name, match_file))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Need to grow the *list? */
|
2003-01-19 15:07:43 +03:00
|
|
|
if (next_free == list->size) {
|
|
|
|
list->list =
|
|
|
|
g_realloc (list->list,
|
|
|
|
sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!list->list)
|
|
|
|
return -1;
|
|
|
|
list->size += RESIZE_STEPS;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-08-27 09:01:08 +04:00
|
|
|
/* handle_path is a simplified handle_dirent. The difference is that
|
1998-02-27 07:54:42 +03:00
|
|
|
handle_path doesn't pay attention to show_dot_files and show_backups.
|
1999-08-27 09:01:08 +04:00
|
|
|
Moreover handle_path can't be used with a filemask.
|
1998-02-27 07:54:42 +03:00
|
|
|
If you change handle_path then check also handle_dirent. */
|
|
|
|
/* Return values: -1 = failure, 0 = don't add, 1 = add to the list */
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
2004-08-29 20:42:40 +04:00
|
|
|
handle_path (dir_list *list, const char *path,
|
1999-02-18 03:07:26 +03:00
|
|
|
struct stat *buf1, int next_free, int *link_to_dir,
|
2002-10-14 02:23:17 +04:00
|
|
|
int *stale_link)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (path [0] == '.' && path [1] == 0)
|
|
|
|
return 0;
|
2002-06-21 01:10:06 +04:00
|
|
|
if (path [0] == '.' && path [1] == '.' && path [2] == 0)
|
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mc_lstat (path, buf1) == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (S_ISDIR (buf1->st_mode))
|
1999-01-09 06:43:05 +03:00
|
|
|
tree_store_mark_checked (path);
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* A link to a file or a directory? */
|
|
|
|
*link_to_dir = 0;
|
2002-10-14 02:23:17 +04:00
|
|
|
*stale_link = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (S_ISLNK(buf1->st_mode)){
|
|
|
|
struct stat buf2;
|
|
|
|
if (!mc_stat (path, &buf2))
|
|
|
|
*link_to_dir = S_ISDIR(buf2.st_mode) != 0;
|
|
|
|
else
|
2002-10-14 02:23:17 +04:00
|
|
|
*stale_link = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to grow the *list? */
|
|
|
|
if (next_free == list->size){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
list->list = g_realloc (list->list, sizeof (file_entry) *
|
1998-02-27 07:54:42 +03:00
|
|
|
(list->size + RESIZE_STEPS));
|
|
|
|
if (!list->list)
|
|
|
|
return -1;
|
|
|
|
list->size += RESIZE_STEPS;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
2004-08-29 20:42:40 +04:00
|
|
|
do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse,
|
|
|
|
int case_sensitive, const char *filter)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-12-16 09:42:15 +03:00
|
|
|
DIR *dirp;
|
1998-02-27 07:54:42 +03:00
|
|
|
struct dirent *dp;
|
2002-12-16 09:42:15 +03:00
|
|
|
int status, link_to_dir, stale_link;
|
|
|
|
int next_free = 0;
|
2003-08-18 04:47:43 +04:00
|
|
|
struct stat st;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2006-01-29 14:23:36 +03:00
|
|
|
/* ".." (if any) must be the first entry in the list */
|
|
|
|
if (set_zero_dir (list) == 0)
|
|
|
|
return next_free;
|
|
|
|
next_free++;
|
|
|
|
|
2003-10-24 03:37:52 +04:00
|
|
|
dirp = mc_opendir (path);
|
2002-12-16 09:42:15 +03:00
|
|
|
if (!dirp) {
|
|
|
|
message (1, MSG_ERROR, _("Cannot read directory contents"));
|
2006-01-29 14:23:36 +03:00
|
|
|
return next_free;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-10-24 03:37:52 +04:00
|
|
|
tree_store_start_check (path);
|
2006-01-29 14:23:36 +03:00
|
|
|
/* Do not add a ".." entry to the root directory */
|
|
|
|
if (!strcmp (path, "/"))
|
|
|
|
next_free--;
|
2003-10-24 17:48:12 +04:00
|
|
|
while ((dp = mc_readdir (dirp))) {
|
2002-12-16 09:42:15 +03:00
|
|
|
status =
|
2003-08-18 04:47:43 +04:00
|
|
|
handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
|
2002-12-16 09:42:15 +03:00
|
|
|
&stale_link);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (status == 0)
|
|
|
|
continue;
|
2002-12-16 09:42:15 +03:00
|
|
|
if (status == -1) {
|
1999-02-13 01:23:35 +03:00
|
|
|
tree_store_end_check ();
|
2002-08-15 06:02:49 +04:00
|
|
|
mc_closedir (dirp);
|
1998-02-27 07:54:42 +03:00
|
|
|
return next_free;
|
1999-02-13 01:23:35 +03:00
|
|
|
}
|
2002-12-16 09:42:15 +03:00
|
|
|
list->list[next_free].fnamelen = NLENGTH (dp);
|
|
|
|
list->list[next_free].fname = g_strdup (dp->d_name);
|
|
|
|
list->list[next_free].f.marked = 0;
|
|
|
|
list->list[next_free].f.link_to_dir = link_to_dir;
|
|
|
|
list->list[next_free].f.stale_link = stale_link;
|
|
|
|
list->list[next_free].f.dir_size_computed = 0;
|
2003-08-18 04:47:43 +04:00
|
|
|
list->list[next_free].st = st;
|
1998-02-27 07:54:42 +03:00
|
|
|
next_free++;
|
|
|
|
if (!(next_free % 32))
|
|
|
|
rotate_dash ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_free) {
|
2002-12-16 09:42:15 +03:00
|
|
|
do_sort (list, sort, next_free - 1, reverse, case_sensitive);
|
1999-02-13 01:23:35 +03:00
|
|
|
}
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mc_closedir (dirp);
|
1999-01-09 06:43:05 +03:00
|
|
|
tree_store_end_check ();
|
1998-02-27 07:54:42 +03:00
|
|
|
return next_free;
|
|
|
|
}
|
|
|
|
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
2003-10-24 17:48:12 +04:00
|
|
|
link_isdir (const file_entry *file)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-12-07 05:36:23 +03:00
|
|
|
if (file->f.link_to_dir)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
2003-10-24 17:48:12 +04:00
|
|
|
if_link_is_exe (const char *full_name, const file_entry *file)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct stat b;
|
|
|
|
|
2003-10-24 17:48:12 +04:00
|
|
|
if (S_ISLNK (file->st.st_mode) && !mc_stat (full_name, &b)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
return is_exe (b.st_mode);
|
1999-02-18 03:07:26 +03:00
|
|
|
} else
|
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static dir_list dir_copy = { 0, 0 };
|
|
|
|
|
1999-02-18 03:07:26 +03:00
|
|
|
static void
|
|
|
|
alloc_dir_copy (int size)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
1999-08-27 09:01:08 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (dir_copy.size < size){
|
|
|
|
if (dir_copy.list){
|
|
|
|
|
|
|
|
for (i = 0; i < dir_copy.size; i++) {
|
2004-09-25 02:22:35 +04:00
|
|
|
g_free (dir_copy.list [i].fname);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (dir_copy.list);
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_copy.list = 0;
|
|
|
|
}
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
dir_copy.list = g_new (file_entry, size);
|
1998-12-07 05:36:23 +03:00
|
|
|
for (i = 0; i < size; i++)
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_copy.list [i].fname = 0;
|
1998-12-07 05:36:23 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_copy.size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If filter is null, then it is a match */
|
1999-02-18 03:07:26 +03:00
|
|
|
int
|
2004-08-29 20:42:40 +04:00
|
|
|
do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
|
|
|
int rev, int case_sensitive, const char *filter)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-12-04 00:39:41 +03:00
|
|
|
DIR *dirp;
|
1998-02-27 07:54:42 +03:00
|
|
|
struct dirent *dp;
|
2001-12-04 00:39:41 +03:00
|
|
|
int next_free = 0;
|
2002-10-14 02:23:17 +04:00
|
|
|
int i, status, link_to_dir, stale_link;
|
2003-08-18 04:47:43 +04:00
|
|
|
struct stat st;
|
2001-12-04 00:39:41 +03:00
|
|
|
int marked_cnt;
|
2003-10-24 02:55:48 +04:00
|
|
|
GHashTable *marked_files;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-24 03:37:52 +04:00
|
|
|
dirp = mc_opendir (path);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!dirp) {
|
2002-12-16 09:42:15 +03:00
|
|
|
message (1, MSG_ERROR, _("Cannot read directory contents"));
|
2001-12-04 00:39:41 +03:00
|
|
|
clean_dir (list, count);
|
1998-02-27 07:54:42 +03:00
|
|
|
return set_zero_dir (list);
|
|
|
|
}
|
|
|
|
|
2003-10-24 03:37:52 +04:00
|
|
|
tree_store_start_check (path);
|
2003-10-24 02:55:48 +04:00
|
|
|
marked_files = g_hash_table_new (g_str_hash, g_str_equal);
|
1998-02-27 07:54:42 +03:00
|
|
|
alloc_dir_copy (list->size);
|
2001-12-04 00:39:41 +03:00
|
|
|
for (marked_cnt = i = 0; i < count; i++) {
|
|
|
|
dir_copy.list[i].fnamelen = list->list[i].fnamelen;
|
|
|
|
dir_copy.list[i].fname = list->list[i].fname;
|
|
|
|
dir_copy.list[i].f.marked = list->list[i].f.marked;
|
|
|
|
dir_copy.list[i].f.dir_size_computed =
|
|
|
|
list->list[i].f.dir_size_computed;
|
|
|
|
dir_copy.list[i].f.link_to_dir = list->list[i].f.link_to_dir;
|
2002-10-14 02:23:17 +04:00
|
|
|
dir_copy.list[i].f.stale_link = list->list[i].f.stale_link;
|
2001-12-11 03:30:12 +03:00
|
|
|
if (list->list[i].f.marked) {
|
|
|
|
g_hash_table_insert (marked_files, dir_copy.list[i].fname,
|
|
|
|
&dir_copy.list[i]);
|
2001-12-04 00:39:41 +03:00
|
|
|
marked_cnt++;
|
2001-12-11 03:30:12 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2006-01-29 14:23:36 +03:00
|
|
|
/* Add ".." except to the root directory. The ".." entry
|
|
|
|
(if any) must be the first in the list. */
|
|
|
|
if (strcmp (path, "/") != 0) {
|
|
|
|
if (set_zero_dir (list) == 0) {
|
|
|
|
clean_dir (list, count);
|
|
|
|
clean_dir (&dir_copy, count);
|
|
|
|
return next_free;
|
|
|
|
}
|
|
|
|
next_free++;
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:55:48 +04:00
|
|
|
while ((dp = mc_readdir (dirp))) {
|
2001-12-04 00:39:41 +03:00
|
|
|
status =
|
2003-08-18 04:47:43 +04:00
|
|
|
handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
|
2002-10-14 02:23:17 +04:00
|
|
|
&stale_link);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (status == 0)
|
|
|
|
continue;
|
|
|
|
if (status == -1) {
|
|
|
|
mc_closedir (dirp);
|
1999-08-27 09:01:08 +04:00
|
|
|
/* Norbert (Feb 12, 1997):
|
2001-12-04 00:39:41 +03:00
|
|
|
Just in case someone finds this memory leak:
|
|
|
|
-1 means big trouble (at the moment no memory left),
|
|
|
|
I don't bother with further cleanup because if one gets to
|
|
|
|
this point he will have more problems than a few memory
|
|
|
|
leaks and because one 'clean_dir' would not be enough (and
|
|
|
|
because I don't want to spent the time to make it working,
|
|
|
|
IMHO it's not worthwhile).
|
|
|
|
clean_dir (&dir_copy, count);
|
|
|
|
*/
|
1999-02-11 00:58:05 +03:00
|
|
|
tree_store_end_check ();
|
2003-10-24 02:55:48 +04:00
|
|
|
g_hash_table_destroy (marked_files);
|
1998-02-27 07:54:42 +03:00
|
|
|
return next_free;
|
|
|
|
}
|
1999-08-27 09:01:08 +04:00
|
|
|
|
2001-12-04 00:39:41 +03:00
|
|
|
list->list[next_free].f.marked = 0;
|
1999-08-27 09:01:08 +04:00
|
|
|
|
2001-12-04 00:39:41 +03:00
|
|
|
/*
|
|
|
|
* If we have marked files in the copy, scan through the copy
|
|
|
|
* to find matching file. Decrease number of remaining marks if
|
|
|
|
* we copied one.
|
|
|
|
*/
|
|
|
|
if (marked_cnt > 0) {
|
2003-10-24 17:48:12 +04:00
|
|
|
if ((g_hash_table_lookup (marked_files, dp->d_name))) {
|
2001-12-11 03:30:12 +03:00
|
|
|
list->list[next_free].f.marked = 1;
|
|
|
|
marked_cnt--;
|
2001-12-04 00:39:41 +03:00
|
|
|
}
|
|
|
|
}
|
1999-08-27 09:01:08 +04:00
|
|
|
|
2001-12-11 03:30:12 +03:00
|
|
|
list->list[next_free].fnamelen = NLENGTH (dp);
|
2001-12-04 00:39:41 +03:00
|
|
|
list->list[next_free].fname = g_strdup (dp->d_name);
|
|
|
|
list->list[next_free].f.link_to_dir = link_to_dir;
|
2002-10-14 02:23:17 +04:00
|
|
|
list->list[next_free].f.stale_link = stale_link;
|
2001-12-04 00:39:41 +03:00
|
|
|
list->list[next_free].f.dir_size_computed = 0;
|
2003-08-18 04:47:43 +04:00
|
|
|
list->list[next_free].st = st;
|
1998-02-27 07:54:42 +03:00
|
|
|
next_free++;
|
|
|
|
if (!(next_free % 16))
|
|
|
|
rotate_dash ();
|
|
|
|
}
|
|
|
|
mc_closedir (dirp);
|
1999-01-09 06:43:05 +03:00
|
|
|
tree_store_end_check ();
|
2001-12-11 03:30:12 +03:00
|
|
|
g_hash_table_destroy (marked_files);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (next_free) {
|
2001-12-04 00:39:41 +03:00
|
|
|
do_sort (list, sort, next_free - 1, rev, case_sensitive);
|
2006-01-29 14:23:36 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
clean_dir (&dir_copy, count);
|
|
|
|
return next_free;
|
|
|
|
}
|
|
|
|
|