mc-4.6.1-versionsort.patch
Roland Illig
roland.illig at gmx.de
Sat Feb 7 12:52:45 UTC 2004
Hi,
I added a versionsort option to the directory sort options. As most C
libraries may not have strverscmp(3), I copied the file from glibc and
added it as the files mc-strverscmp.{c,h}.
Roland
PS: I am not on the mailing list, so please cc me.
-------------- next part --------------
diff -uN mc-4.6.1-pre1/src/dir.c mc-4.6.0-4.6.1-pre1.new/src/dir.c
--- mc-4.6.1-pre1/src/dir.c 2003-10-24 19:55:36.000000000 +0200
+++ mc-4.6.0-4.6.1-pre1.new/src/dir.c 2004-02-07 13:41:44.000000000 +0100
@@ -27,6 +27,7 @@
#include "dir.h"
#include "wtools.h"
#include "treestore.h"
+#include "mc-strverscmp.h"
/* If true show files starting with a dot */
int show_dot_files = 1;
@@ -48,6 +49,7 @@
sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
{ N_("&Unsorted"), unsorted },
{ N_("&Name"), sort_name },
+ { N_("Name (&Version)"), sort_vers },
{ N_("&Extension"), sort_ext },
{ N_("&Modify time"), sort_time },
{ N_("&Access time"), sort_atime },
@@ -124,6 +126,19 @@
}
int
+sort_vers (const file_entry *a, const file_entry *b)
+{
+ int ad = MY_ISDIR (a);
+ int bd = MY_ISDIR (b);
+
+ if (ad == bd || mix_all_files) {
+ return mc_strverscmp (a->fname, b->fname) * reverse;
+ } else {
+ return bd - ad;
+ }
+}
+
+int
sort_ext (const file_entry *a, const file_entry *b)
{
char *exta, *extb;
diff -uN mc-4.6.1-pre1/src/dir.h mc-4.6.0-4.6.1-pre1.new/src/dir.h
--- mc-4.6.1-pre1/src/dir.h 2003-10-24 19:55:36.000000000 +0200
+++ mc-4.6.0-4.6.1-pre1.new/src/dir.h 2004-02-07 13:41:14.000000000 +0100
@@ -43,6 +43,7 @@
/* Sorting functions */
int unsorted (const file_entry *a, const file_entry *b);
int sort_name (const file_entry *a, const file_entry *b);
+int sort_vers (const file_entry *a, const file_entry *b);
int sort_ext (const file_entry *a, const file_entry *b);
int sort_time (const file_entry *a, const file_entry *b);
int sort_atime (const file_entry *a, const file_entry *b);
@@ -57,7 +58,7 @@
int sort_group (const file_entry *a, const file_entry *b);
/* SORT_TYPES is used to build the nice dialog box entries */
-#define SORT_TYPES 8
+#define SORT_TYPES 9
/* This is the number of sort types not available in that dialog box */
#define SORT_TYPES_EXTRA 6
diff -uN mc-4.6.1-pre1/src/Makefile.am mc-4.6.0-4.6.1-pre1.new/src/Makefile.am
--- mc-4.6.1-pre1/src/Makefile.am 2003-11-27 19:06:57.000000000 +0100
+++ mc-4.6.0-4.6.1-pre1.new/src/Makefile.am 2004-02-07 13:30:04.000000000 +0100
@@ -52,7 +52,8 @@
glibcompat.c glibcompat.h global.h help.c help.h hotlist.c \
hotlist.h info.c info.h key.c key.h keyxdef.c layout.c \
layout.h learn.c learn.h listmode.c listmode.h main.c main.h \
- menu.c menu.h mountlist.c mountlist.h mouse.c mouse.h myslang.h \
+ menu.c mc-strverscmp.c menu.h mountlist.c mountlist.h mouse.c \
+ mouse.h myslang.h \
option.c option.h panel.h panelize.c panelize.h poptalloca.h \
popt.c poptconfig.c popt.h popthelp.c poptint.h poptparse.c \
profile.c profile.h regex.c rxvt.c screen.c setup.c setup.h \
diff -uN mc-4.6.1-pre1/src/mc-strverscmp.c mc-4.6.0-4.6.1-pre1.new/src/mc-strverscmp.c
--- mc-4.6.1-pre1/src/mc-strverscmp.c 1970-01-01 01:00:00.000000000 +0100
+++ mc-4.6.0-4.6.1-pre1.new/src/mc-strverscmp.c 2004-02-07 13:29:49.000000000 +0100
@@ -0,0 +1,109 @@
+/* Compare strings while treating digits characters numerically.
+ Copyright (C) 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jean-Fran?ois Bignolles <bignolle at ecoledoc.ibp.fr>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ctype.h>
+
+/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
+ fractionnal parts, S_Z: idem but with leading Zeroes only */
+#define S_N 0x0
+#define S_I 0x4
+#define S_F 0x8
+#define S_Z 0xC
+
+/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
+#define CMP 2
+#define LEN 3
+
+
+/* Compare S1 and S2 as strings holding indices/version numbers,
+ returning less than, equal to or greater than zero if S1 is less than,
+ equal to or greater than S2 (for more info, see the texinfo doc).
+*/
+
+extern int mc_strverscmp (s1, s2)
+ const char *s1;
+ const char *s2;
+{
+ const unsigned char *p1 = (const unsigned char *) s1;
+ const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+ int state;
+ int diff;
+
+ /* Symbol(s) 0 [1-9] others (padding)
+ Transition (10) 0 (01) d (00) x (11) - */
+ static const unsigned int next_state[] =
+ {
+ /* state x d 0 - */
+ /* S_N */ S_N, S_I, S_Z, S_N,
+ /* S_I */ S_N, S_I, S_I, S_I,
+ /* S_F */ S_N, S_F, S_F, S_F,
+ /* S_Z */ S_N, S_F, S_Z, S_Z
+ };
+
+ static const int result_type[] =
+ {
+ /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
+ 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
+
+ /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
+ +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
+ /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
+ -1, CMP, CMP, CMP
+ };
+
+ if (p1 == p2)
+ return 0;
+
+ c1 = *p1++;
+ c2 = *p2++;
+ /* Hint: '0' is a digit too. */
+ state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
+
+ while ((diff = c1 - c2) == 0 && c1 != '\0')
+ {
+ state = next_state[state];
+ c1 = *p1++;
+ c2 = *p2++;
+ state |= (c1 == '0') + (isdigit (c1) != 0);
+ }
+
+ state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))];
+
+ switch (state)
+ {
+ case CMP:
+ return diff;
+
+ case LEN:
+ while (isdigit (*p1++))
+ if (!isdigit (*p2++))
+ return 1;
+
+ return isdigit (*p2) ? -1 : diff;
+
+ default:
+ return state;
+ }
+}
diff -uN mc-4.6.1-pre1/src/mc-strverscmp.h mc-4.6.0-4.6.1-pre1.new/src/mc-strverscmp.h
--- mc-4.6.1-pre1/src/mc-strverscmp.h 1970-01-01 01:00:00.000000000 +0100
+++ mc-4.6.0-4.6.1-pre1.new/src/mc-strverscmp.h 2004-02-07 13:27:25.000000000 +0100
@@ -0,0 +1,6 @@
+#ifndef MC_STRVERSCMP_H
+#define MC_STRVERSCMP_H
+
+extern int mc_strverscmp (const char *, const char *);
+
+#endif
More information about the mc-devel
mailing list