summary refs log tree commit diff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-06-05 11:21:22 +0100
committerPeter Stephenson <pws@zsh.org>2015-06-05 11:21:22 +0100
commit2abba7243a736a2fc626f3cc917d8a67014d4d20 (patch)
treec91850e5786a9a8e0c9ebbedc65abbc3a3131cd0 /Src/utils.c
parent4804a7c5ff144fc7cc974484d16f2f88cc131264 (diff)
downloadzsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.tar.gz
zsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.tar.xz
zsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.zip
35386: expand tabs where useful in builtins outputing function.
Also add to zed -f.

Option is -x <numm>.
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/Src/utils.c b/Src/utils.c
index 7409dc876..c33c16d5a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4471,9 +4471,37 @@ ztrlen(char const *s)
     for (l = 0; *s; l++) {
 	if (*s++ == Meta) {
 #ifdef DEBUG
-	    if (! *s)
+	    if (! *s) {
 		fprintf(stderr, "BUG: unexpected end of string in ztrlen()\n");
-	    else
+		break;
+	    } else
+#endif
+	    s++;
+	}
+    }
+    return l;
+}
+
+#ifndef MULTIBYTE_SUPPORT
+/*
+ * ztrlen() but with explicit end point for non-null-terminated
+ * segments.  eptr may not be NULL.
+ */
+
+/**/
+mod_export int
+ztrlenend(char const *s, char const *eptr)
+{
+    int l;
+
+    for (l = 0; s < eptr; l++) {
+	if (*s++ == Meta) {
+#ifdef DEBUG
+	    if (! *s) {
+		fprintf(stderr,
+			"BUG: unexpected end of string in ztrlenend()\n");
+		break;
+	    } else
 #endif
 	    s++;
 	}
@@ -4481,6 +4509,8 @@ ztrlen(char const *s)
     return l;
 }
 
+#endif /* MULTIBYTE_SUPPORT */
+
 /* Subtract two pointers in a metafied string. */
 
 /**/
@@ -4879,11 +4909,16 @@ mb_metacharlenconv(const char *s, wint_t *wcp)
  * If width is 1, return total character width rather than number.
  * If width is greater than 1, return 1 if character has non-zero width,
  * else 0.
+ *
+ * Ends if either *ptr is '\0', the normal case (eptr may be NULL for
+ * this), or ptr is eptr (i.e.  *eptr is where the null would be if null
+ * terminated) for strings not delimited by nulls --- note these are
+ * still metafied.
  */
 
 /**/
 mod_export int
-mb_metastrlen(char *ptr, int width)
+mb_metastrlenend(char *ptr, int width, char *eptr)
 {
     char inchar, *laststart;
     size_t ret;
@@ -4898,7 +4933,7 @@ mb_metastrlen(char *ptr, int width)
     num = num_in_char = 0;
 
     memset(&mb_shiftstate, 0, sizeof(mb_shiftstate));
-    while (*ptr) {
+    while (*ptr && !(eptr && ptr >= eptr)) {
 	if (*ptr == Meta)
 	    inchar = *++ptr ^ 32;
 	else