File mc-nice-fnames.diff of Package mc46

--- src/util.h.orig	2015-08-29 23:01:30.291565979 +0300
+++ src/util.h	2015-08-29 23:05:32.676533316 +0300
@@ -35,6 +35,7 @@
  * Use "~" to show where the string was truncated.
  * Return static buffer, no need to free() it. */
 const char *name_trunc (const char *txt, int trunc_len);
+const char *name_trunc_any (const char *txt, int trunc_len, int alignment);
 
 /* path_trunc() is the same as name_trunc() above but
  * it deletes possible password from path for security
--- src/util.c.orig	2015-08-29 23:01:35.802666561 +0300
+++ src/util.c	2015-08-30 01:09:58.282975402 +0300
@@ -409,16 +409,22 @@
     return g_strdup (s);
 }
 
+#define J_LEFT 		1
+#define J_RIGHT		2
+#define J_CENTER	3
+
 /*
  * Remove the middle part of the string to fit given length.
  * Use "~" to show where the string was truncated.
  * Return static buffer, no need to free() it.
  */
 const char *
-name_trunc (const char *txt, int trunc_len)
+name_trunc_any (const char *txt, int trunc_len, int alignment)
 {
     static char x[MC_MAXPATHLEN + MC_MAXPATHLEN];
     int txt_len, first, skip;
+    int proceed = 0;
+    int truncating = 0;
     char *p;
     const char *str;
 
@@ -429,7 +435,14 @@
     first = 0;
     skip = 0;
     if (txt_len > trunc_len) {
+      truncating = 1;
       first = trunc_len / 2;
+      if (J_LEFT == alignment) {
+          first = trunc_len - 1;
+      }
+      if (J_RIGHT == alignment) {
+          first = 0;
+      }
       skip = txt_len - trunc_len + 1;
     }
 
@@ -446,6 +459,7 @@
 	  wchar_t wc;
 	  int len;
 
+        if (proceed || first) {
 	  len = mbrtowc (&wc, str, mbmax, &s);
 	  if (!len)
 	      break;
@@ -464,19 +478,21 @@
 	      memcpy (p, str, len);
 	      str += len;
 	  }
-	  if (first) {
-	      --trunc_len;
-	      --first;
+	  if (first || !skip) {
 	      p += len;
-	      if (!first && p < x + sizeof (x) - 1 && trunc_len) {
+	      --trunc_len;
+	  }
+	  if (first) --first;
+	}
+	      if (!proceed && !first) {
+	        if (truncating && p < x + sizeof (x) - 1 && trunc_len) {
 		  *p++ = '~';
 		  --trunc_len;
+		}
+		proceed = 1;
 	      }
-	  } else if (skip)
+	  if (!first && skip) {
 	      --skip;
-	  else {
-	      --trunc_len;
-	      p += len;
 	  }
       }
     } else
@@ -485,6 +501,7 @@
       str = txt;
       p = x;
       while (p < x + sizeof (x) - 1) {
+        if (proceed || first) {
 	  if (*str == '\0')
 	      break;
 	  else if (!is_printable (*str))
@@ -492,19 +509,26 @@
 	  else
 	      *p++ = *str;
 	  ++str;
-	  if (first) {
-	      --first;
-	      if (!first) {
+	  if (first) --first;
+	}
+	      if (!first && !proceed) {
+		if (truncating)
 		  *p++ = '~';
 		  str += skip;
+		  proceed = 1;
 	      }
-	  }
       }
     }
     *p = '\0';
     return x;
 }
 
+const char *
+name_trunc (const char *txt, int trunc_len)
+{
+    return name_trunc_any (txt, trunc_len, J_CENTER);
+}
+
 /*
  * path_trunc() is the same as name_trunc() above but
  * it deletes possible password from path for security
--- src/screen.c.orig	2015-08-29 23:01:43.923734516 +0300
+++ src/screen.c	2015-08-30 01:05:49.110030870 +0300
@@ -642,6 +642,14 @@
 			int width2 = 0;
 			int len1 = len / 2;
 			int len2;
+			int alignment = HIDE_FIT(format->just_mode);
+			
+			if (J_LEFT == alignment) {
+				len1 = len - 1;
+			}
+			if (J_RIGHT == alignment) {
+				len1 = 0;
+			}
 			
 			while (1) {
 			    int w = wcwidth(((wchar_t *) buffer)[n1]);
@@ -681,7 +689,7 @@
 	    } else {
 		if (over) {
 		    if (IS_FIT (format->just_mode))
-			strcpy (buffer, name_trunc(txt, len));
+			strcpy (buffer, name_trunc_any(txt, len, HIDE_FIT(format->just_mode)));
 		    else
 			memcpy (buffer, txt + still, len);
 		} else {
openSUSE Build Service is sponsored by