patch 9.1.0997: too many strlen() calls in drawscreen.c

Problem:  too many strlen() calls in drawscreen.c
Solution: refactor drawscreen.c and remove calls to strlen(),
          make get_keymap_str() (in screen.c) return string length
          instead of TRUE/FALSE (John Marriott).

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/buffer.c b/src/buffer.c
index 147d20d..a925552 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -3914,7 +3914,7 @@
 		n);
 	validate_virtcol();
 	len = STRLEN(buffer);
-	col_print((char_u *)buffer + len, IOSIZE - len,
+	(void)col_print((char_u *)buffer + len, IOSIZE - len,
 		   (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
     }
 
@@ -3946,7 +3946,7 @@
     vim_free(buffer);
 }
 
-    void
+    int
 col_print(
     char_u  *buf,
     size_t  buflen,
@@ -3954,9 +3954,9 @@
     int	    vcol)
 {
     if (col == vcol)
-	vim_snprintf((char *)buf, buflen, "%d", col);
-    else
-	vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
+	return vim_snprintf((char *)buf, buflen, "%d", col);
+
+    return vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
 }
 
 static char_u *lasttitle = NULL;
@@ -4820,7 +4820,7 @@
 
 	case STL_ALTPERCENT:
 	    str = buf_tmp;
-	    get_rel_pos(wp, str, TMPLEN);
+	    (void)get_rel_pos(wp, str, TMPLEN);
 	    break;
 
 	case STL_SHOWCMD:
@@ -4837,7 +4837,7 @@
 
 	case STL_KEYMAP:
 	    fillable = FALSE;
-	    if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN))
+	    if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN) > 0)
 		str = buf_tmp;
 	    break;
 	case STL_PAGENUM:
@@ -5271,7 +5271,7 @@
  * Get relative cursor position in window into "buf[buflen]", in the localized
  * percentage form like %99, 99%; using "Top", "Bot" or "All" when appropriate.
  */
-    void
+    int
 get_rel_pos(
     win_T	*wp,
     char_u	*buf,
@@ -5279,9 +5279,10 @@
 {
     long	above; // number of lines above window
     long	below; // number of lines below window
+    int		len;
 
     if (buflen < 3) // need at least 3 chars for writing
-	return;
+	return 0;
     above = wp->w_topline - 1;
 #ifdef FEAT_DIFF
     above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill;
@@ -5292,28 +5293,27 @@
 #endif
     below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1;
     if (below <= 0)
-	vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")),
-		    (size_t)(buflen - 1));
+	len = vim_snprintf((char *)buf, buflen, "%s", (above == 0) ? _("All") : _("Bot"));
     else if (above <= 0)
-	vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1));
+	len = vim_snprintf((char *)buf, buflen, "%s", _("Top"));
     else
     {
 	int perc = (above > 1000000L)
-			?  (int)(above / ((above + below) / 100L))
-			:  (int)(above * 100L / (above + below));
+		    ?  (int)(above / ((above + below) / 100L))
+		    :  (int)(above * 100L / (above + below));
 
-	char *p = (char *)buf;
-	size_t l = buflen;
-	if (perc < 10)
-	{
-	    // prepend one space
-	    buf[0] = ' ';
-	    ++p;
-	    --l;
-	}
 	// localized percentage value
-	vim_snprintf(p, l, _("%d%%"), perc);
+	len = vim_snprintf((char *)buf, buflen, _("%s%d%%"), (perc < 10) ? " " : "", perc);
     }
+    if (len < 0)
+    {
+	buf[0] = NUL;
+	len = 0;
+    }
+    else if (len > buflen - 1)
+	len = buflen - 1;
+
+    return len;
 }
 
 /*