Patch, sort exe files on top after directories.



Hello All!

Patch for Exe files sort.
Idea from Dos Navigator.
All x files on top after directories.

diff -urN mc-4.6.0.orig/pc/drive.c mc-4.6.0/pc/drive.c
--- mc-4.6.0.orig/pc/drive.c	Mon Oct 21 06:13:52 2002
+++ mc-4.6.0/pc/drive.c	Mon Feb 10 14:31:47 2003
@@ -151,6 +151,7 @@
 				this_panel->sort_type,
 				this_panel->reverse,
 				this_panel->case_sensitive,
+				this_panel->exe_first,
 				this_panel->filter);
 			this_panel->top_file = 0;
 			this_panel->selected = 0;
diff -urN mc-4.6.0.orig/src/boxes.c mc-4.6.0/src/boxes.c
--- mc-4.6.0.orig/src/boxes.c	Sun Dec  8 05:16:30 2002
+++ mc-4.6.0/src/boxes.c	Mon Feb 10 14:32:54 2003
@@ -266,17 +266,18 @@
 static char *sort_orders_names [SORT_TYPES];
 
 sortfn *
-sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
+sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exe_first)
 {
     int i, r, l;
     sortfn *result;
-    WCheck *c, *case_sense;
+    WCheck *c, *case_sense, *exe_sense;
 
 	char* ok_button = _("&OK");
 	char* cancel_button = _("&Cancel");
 	char* reverse_label = _("&Reverse");
 	char* case_label = _("case sensi&tive");
 	char* sort_title = _("Sort order");
+	char* exe_label = _("exe &first");
 
 	static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
 
@@ -336,6 +337,8 @@
 		button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
 		0, 0, "ok-button"));
 
+    exe_sense = check_new (5, check_pos, *exe_first, exe_label, "exe-check");
+    add_widget (dd, exe_sense);
     case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
     add_widget (dd, case_sense);
     c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
@@ -352,6 +355,7 @@
 	result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
 	*reverse = c->state & C_BOOL;
 	*case_sensitive = case_sense->state & C_BOOL;
+	*exe_first = exe_sense->state & C_BOOL;
     } else
 	result = sort_fn;
     destroy_dlg (dd);
diff -urN mc-4.6.0.orig/src/boxes.h mc-4.6.0/src/boxes.h
--- mc-4.6.0.orig/src/boxes.h	Mon Aug 19 03:01:20 2002
+++ mc-4.6.0/src/boxes.h	Mon Feb 10 14:31:31 2003
@@ -4,7 +4,7 @@
 int     display_box      (WPanel *p, char **user, char **mini,
 			  int *use_msformat, int num);
 sortfn *sort_box         (sortfn *sort_fn, int *reverse,
-			  int *case_sensitive);
+			  int *case_sensitive, int *exe_first);
 void    confirm_box      (void);
 void    display_bits_box (void);
 void    configure_vfs    (void);
diff -urN mc-4.6.0.orig/src/dir.c mc-4.6.0/src/dir.c
--- mc-4.6.0.orig/src/dir.c	Tue Jan 21 01:41:45 2003
+++ mc-4.6.0/src/dir.c	Mon Feb 10 14:37:44 2003
@@ -44,7 +44,12 @@
 /* Are the files sorted case sensitively? */
 static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
 
+/* Are the files sorted with exe first? */
+static int exe_first = OS_SORT_EXE_FIRST_DEFAULT;
+
 #define MY_ISDIR(x) ( (S_ISDIR (x->buf.st_mode) || x->f.link_to_dir) ? 1 : 0)
+// Alexander Riedel
+#define MY_ISEXEC(x) ( ((x->buf.st_mode & 00100 || x->buf.st_mode & 00010 || x->buf.st_mode & 00001) ) ? 1 : 0)
 
 sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
     { N_("&Unsorted"),    unsorted },
@@ -119,6 +124,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return string_sortcomp (a->fname, b->fname) * reverse;
     return bd-ad;
@@ -132,6 +142,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files){
 	exta = extension (a->fname);
 	extb = extension (b->fname);
@@ -150,6 +165,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return string_sortcomp (get_owner (a->buf.st_uid), get_owner (a->buf.st_uid)) * reverse;
     return bd-ad;
@@ -161,6 +181,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return string_sortcomp (get_group (a->buf.st_gid), get_group (a->buf.st_gid)) * reverse;
     return bd-ad;
@@ -172,6 +197,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (a->buf.st_mtime - b->buf.st_mtime) * reverse;
     else
@@ -184,6 +214,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (a->buf.st_ctime - b->buf.st_ctime) * reverse;
     else
@@ -196,6 +231,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (a->buf.st_atime - b->buf.st_atime) * reverse;
     else
@@ -208,6 +248,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (a->buf.st_ino - b->buf.st_ino) * reverse;
     else
@@ -220,6 +265,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad != bd && !mix_all_files)
 	return bd - ad;
 
@@ -232,6 +282,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (b->buf.st_nlink - a->buf.st_nlink) * reverse;
     else
@@ -244,6 +299,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (b->buf.st_gid - a->buf.st_gid) * reverse;
     else
@@ -256,6 +316,11 @@
     int ad = MY_ISDIR (a);
     int bd = MY_ISDIR (b);
 
+    if (exe_first && !(ad || bd)){
+	ad = MY_ISEXEC (a);
+	bd = MY_ISEXEC (b);
+    }    
+
     if (ad == bd || mix_all_files)
 	return (b->buf.st_uid - a->buf.st_uid) * reverse;
     else
@@ -301,7 +366,7 @@
 
 
 void
-do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f)
+do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f, int exe_first_f)
 {
     int i;
     int dot_dot_found = 0;
@@ -321,6 +386,7 @@
 
     reverse = reverse_f ? -1 : 1;
     case_sensitive = case_sensitive_f;
+    exe_first = exe_first_f;
     qsort (&(list->list) [dot_dot_found],
 	   top + 1 - dot_dot_found, sizeof (file_entry), sort);
 }
@@ -462,7 +528,7 @@
 }
 
 int
-do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive,
+do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive, int exe_first,
 	     char *filter)
 {
     DIR *dirp;
@@ -506,7 +572,7 @@
 	/* Add ".." except the root directory */
 	if (strcmp (vfs_canon ("."), "/") != 0)
 	    add_dotdot_to_list (list, next_free++);
-	do_sort (list, sort, next_free - 1, reverse, case_sensitive);
+	do_sort (list, sort, next_free - 1, reverse, case_sensitive, exe_first);
     } else {
 	tree_store_end_check ();
 	mc_closedir (dirp);
@@ -568,7 +634,7 @@
 /* If filter is null, then it is a match */
 int
 do_reload_dir (dir_list * list, sortfn * sort, int count, int rev,
-	       int case_sensitive, char *filter)
+	       int case_sensitive, int exe_first, char *filter)
 {
     DIR *dirp;
     struct dirent *dp;
@@ -658,7 +724,7 @@
 	/* Add ".." except the root directory */
 	if (strcmp (vfs_canon ("."), "/") != 0)
 	    add_dotdot_to_list (list, next_free++);
-	do_sort (list, sort, next_free - 1, rev, case_sensitive);
+	do_sort (list, sort, next_free - 1, rev, case_sensitive, exe_first);
     } else
 	next_free = set_zero_dir (list);
     clean_dir (&dir_copy, count);
diff -urN mc-4.6.0.orig/src/dir.h mc-4.6.0/src/dir.h
--- mc-4.6.0.orig/src/dir.h	Fri Nov 15 07:38:55 2002
+++ mc-4.6.0/src/dir.h	Mon Feb 10 14:23:00 2003
@@ -30,12 +30,12 @@
 typedef int sortfn (const void *, const void *);
 
 int        do_load_dir     (dir_list *list, sortfn *sort,
-			    int reverse, int case_sensitive, char *filter);
+			    int reverse, int case_sensitive, int exe_first, char *filter);
 void       do_sort         (dir_list *list, sortfn *sort, int top,
-			    int reverse, int case_sensitive);
+			    int reverse, int case_sensitive, int exe_first);
 dir_list  *do_collect_stat (dir_list *dir, int top);
 int        do_reload_dir   (dir_list *list, sortfn *sort, int count,
-			    int reverse, int case_sensitive, char *filter);
+			    int reverse, int case_sensitive, int exe_first, char *filter);
 void       clean_dir       (dir_list *list, int count);
 int        set_zero_dir    (dir_list *list);
 
diff -urN mc-4.6.0.orig/src/main.c mc-4.6.0/src/main.c
--- mc-4.6.0.orig/src/main.c	Wed Feb  5 16:54:34 2003
+++ mc-4.6.0/src/main.c	Mon Feb 10 14:28:16 2003
@@ -787,7 +787,7 @@
     panel_clean_dir (panel);
     panel->count =
 	do_load_dir (&panel->dir, panel->sort_type, panel->reverse,
-		     panel->case_sensitive, panel->filter);
+		     panel->case_sensitive, panel->exe_first, panel->filter);
     try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
     load_hint (0);
     panel_update_contents (panel);
@@ -921,7 +921,7 @@
 	return;
 
     p = MENU_PANEL;
-    sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive);
+    sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive, &p->exe_first);
 
     panel_set_sort_order (p, sort_order);
 
diff -urN mc-4.6.0.orig/src/panel.h mc-4.6.0/src/panel.h
--- mc-4.6.0.orig/src/panel.h	Thu Nov 14 08:25:19 2002
+++ mc-4.6.0/src/panel.h	Mon Feb 10 14:20:23 2003
@@ -51,6 +51,7 @@
     int      selected;		/* Index to the selected file */
     int      reverse;		/* Show listing in reverse? */
     int      case_sensitive;    /* Listing is case sensitive? */
+    int      exe_first;    	/* Listing is case sensitive? */
     int      split;		/* Split panel to allow two columns */
     int      is_panelized;	/* Flag: special filelisting, can't reload */
     int      frame_size;	/* half or full frame */
diff -urN mc-4.6.0.orig/src/screen.c mc-4.6.0/src/screen.c
--- mc-4.6.0.orig/src/screen.c	Tue Jan 28 23:58:22 2003
+++ mc-4.6.0/src/screen.c	Mon Feb 10 14:27:10 2003
@@ -996,7 +996,7 @@
 
     /* Load the default format */
     panel->count = do_load_dir (&panel->dir, panel->sort_type,
-				panel->reverse, panel->case_sensitive, panel->filter);
+				panel->reverse, panel->case_sensitive, panel->exe_first, panel->filter);
     return panel;
 }
 
@@ -1029,7 +1029,7 @@
     }
 
     panel->count = do_reload_dir (&panel->dir, panel->sort_type, panel->count,
-				  panel->reverse, panel->case_sensitive, panel->filter);
+				  panel->reverse, panel->case_sensitive, panel->exe_first, panel->filter);
 
     panel->dirty = 1;
     if (panel->selected >= panel->count)
@@ -2355,7 +2355,7 @@
 
     filename = g_strdup (selection (panel)->fname);
     unselect_item (panel);
-    do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive);
+    do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive, panel->exe_first);
     panel->selected = -1;
     for (i = panel->count; i; i--){
 	if (!strcmp (panel->dir.list [i-1].fname, filename)){
diff -urN mc-4.6.0.orig/src/setup.c mc-4.6.0/src/setup.c
--- mc-4.6.0.orig/src/setup.c	Thu Jan 23 16:51:01 2003
+++ mc-4.6.0/src/setup.c	Mon Feb 10 14:25:44 2003
@@ -226,6 +226,8 @@
     save_string (section, "reverse", buffer, profile_name);
     g_snprintf (buffer, sizeof (buffer), "%d", panel->case_sensitive);
     save_string (section, "case_sensitive", buffer, profile_name);
+    g_snprintf (buffer, sizeof (buffer), "%d", panel->exe_first);
+    save_string (section, "exe_first", buffer, profile_name);
     for (i = 0; sort_names [i].key; i++)
 	if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
 	    save_string (section, "sort_order",
@@ -362,6 +364,7 @@
 
     panel->reverse = load_int (section, "reverse", 0);
     panel->case_sensitive = load_int (section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
+    panel->exe_first = load_int (section, "exe_first", OS_SORT_EXE_FIRST_DEFAULT);
 
     /* Load sort order */
     load_string (section, "sort_order", "name", buffer, sizeof (buffer));
diff -urN mc-4.6.0.orig/src/util.h mc-4.6.0/src/util.h
--- mc-4.6.0.orig/src/util.h	Mon Jan 27 22:07:29 2003
+++ mc-4.6.0/src/util.h	Mon Feb 10 14:33:48 2003
@@ -149,6 +149,7 @@
 #    define TMPDIR_DEFAULT "c:\\temp"
 #    define SCRIPT_SUFFIX ".cmd"
 #    define OS_SORT_CASE_SENSITIVE_DEFAULT 0
+#    define OS_SORT_EXE_FIRST_DEFAULT 0
 #    define STRCOMP stricmp
 #    define STRNCOMP strnicmp
 #    define MC_ARCH_FLAGS REG_ICASE
@@ -163,6 +164,7 @@
 #    define SCRIPT_SUFFIX ""
 #    define get_default_editor() "vi"
 #    define OS_SORT_CASE_SENSITIVE_DEFAULT 1
+#    define OS_SORT_EXE_FIRST_DEFAULT 1
 #    define STRCOMP strcmp
 #    define STRNCOMP strncmp
 #    define MC_ARCH_FLAGS 0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]