[PATCH 2/2] Fix ZERO_FILL flag to mkstring()

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

 



The ZERO_FILL flag should in fact be honoured during justification,
not for the formatting. This patch makes it possible to use
the ZERO_FILL flag for any type, not just LONG_DEC.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>
Fix ZERO_FILL flag to mkstring()

The ZERO_FILL flag should in fact be honoured during justification,
not for the formatting. This patch makes it possible to use
the ZERO_FILL flag for any type, not just LONG_DEC.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>

---
 tools.c |   25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

--- a/tools.c
+++ b/tools.c
@@ -1524,7 +1524,7 @@ shift_string_left(char *s, int cnt)
  *  inserting space characters.  (caller confirms space is available)
  */
 char *
-shift_string_right(char *s, int cnt)
+shift_string_right(char *s, int cnt, int fillchar)
 {
         int origlen;
 
@@ -1534,7 +1534,7 @@ shift_string_right(char *s, int cnt)
         origlen = strlen(s);
         memmove(s+cnt, s, origlen);
         s[origlen+cnt] = NULLCHAR;
-	return(memset(s, ' ', cnt));
+	return(memset(s, fillchar, cnt));
 }
 
 /*
@@ -1553,8 +1553,9 @@ mkstring(char *s, int size, ulong flags,
 	int extra;
 	int left;
 	int right;
+	int fillchar;
 
-	switch (flags & (LONG_DEC|LONG_HEX|INT_HEX|INT_DEC|LONGLONG_HEX|ZERO_FILL)) 
+	switch (flags & (LONG_DEC|LONG_HEX|INT_HEX|INT_DEC|LONGLONG_HEX))
 	{
 	case LONG_DEC:
 		sprintf(s, "%lu", (ulong)opt);
@@ -1562,12 +1563,6 @@ mkstring(char *s, int size, ulong flags,
 	case LONG_HEX:
 		sprintf(s, "%lx", (ulong)opt);
 		break;
-	case (LONG_HEX|ZERO_FILL):
-		if (VADDR_PRLEN == 8)
-			sprintf(s, "%08lx", (ulong)opt);
-		else if (VADDR_PRLEN == 16)
-			sprintf(s, "%016lx", (ulong)opt);
-		break;
 	case INT_DEC:
 		sprintf(s, "%u", (uint)((ulong)opt));
 		break;
@@ -1595,6 +1590,8 @@ mkstring(char *s, int size, ulong flags,
 		return(s);
 	extra = size - len;
 
+	fillchar = (flags & ZERO_FILL) ? '0' : ' ';
+
 	if (flags & CENTER) {
 		/*
 		 *  If absolute centering is not possible, justify the
@@ -1618,9 +1615,9 @@ mkstring(char *s, int size, ulong flags,
 		else 
 			left = right = extra/2;
 
-		shift_string_right(s, left);
+		shift_string_right(s, left, fillchar);
 		len = strlen(s);
-		memset(s + len, ' ', right);
+		memset(s + len, fillchar, right);
 		s[len + right] = NULLCHAR;
 	
 		return(s);
@@ -1628,10 +1625,10 @@ mkstring(char *s, int size, ulong flags,
 
 	if (flags & LJUST) {
 		len = strlen(s);
-		memset(s + len, ' ', extra);
+		memset(s + len, fillchar, extra);
 		s[len + extra] = NULLCHAR;
 	} else if (flags & RJUST) 
-		shift_string_right(s, extra);
+		shift_string_right(s, extra, fillchar);
 
 	return(s);
 }
@@ -2569,7 +2566,7 @@ eval_common(char *s, int flags, int *err
 		strcpy(work, s);
 
         if (work[0] == '-') {
-                shift_string_right(work, 1);
+                shift_string_right(work, 1, ' ');
                 work[0] = '0';
         }
 
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux