about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2001-02-19 10:26:52 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2001-02-19 10:26:52 +0000
commitcd02c345afdedd31b767530dfb826b56c61ac6d7 (patch)
tree2021aed216adfc9cd18e9e3ae3740edb192b5a44 /Src/hist.c
parent441648bf5d1fed6a087affc6dd80c4d604704173 (diff)
downloadzsh-cd02c345afdedd31b767530dfb826b56c61ac6d7.tar.gz
zsh-cd02c345afdedd31b767530dfb826b56c61ac6d7.tar.xz
zsh-cd02c345afdedd31b767530dfb826b56c61ac6d7.zip
13280: NewImproved handling of colon modifiers w.r.t. paths
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/Src/hist.c b/Src/hist.c
index b9480d786..138cb1bf5 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1350,28 +1350,45 @@ hcomsearch(char *str)
 int
 remtpath(char **junkptr)
 {
-    char *str = *junkptr, *remcut;
-
-    if ((remcut = strrchr(str, '/'))) {
-	if (str != remcut)
-	    *remcut = '\0';
-	else
-	    str[1] = '\0';
-	return 1;
+    char *str = strend(*junkptr);
+
+    /* ignore trailing slashes */
+    while (str >= *junkptr && IS_DIRSEP(*str))
+	--str;
+    /* skip filename */
+    while (str >= *junkptr && !IS_DIRSEP(*str))
+	--str;
+    if (str < *junkptr) {
+	*junkptr = dupstring (".");
+	return 0;
     }
-    return 0;
+    /* repeated slashes are considered like a single slash */
+    while (str > *junkptr && IS_DIRSEP(str[-1]))
+	--str;
+    /* never erase the root slash */
+    if (str == *junkptr) {
+	++str;
+	/* Leading doubled slashes (`//') have a special meaning on cygwin
+	   and some old flavor of UNIX, so we do not assimilate them to
+	   a single slash.  However a greater number is ok to squeeze. */
+	if (IS_DIRSEP(*str) && !IS_DIRSEP(str[1]))
+	    ++str;
+    }
+    *str = '\0';
+    return 1;
 }
 
 /**/
 int
 remtext(char **junkptr)
 {
-    char *str = *junkptr, *remcut;
+    char *str;
 
-    if ((remcut = strrchr(str, '.')) && remcut != str) {
-	*remcut = '\0';
-	return 1;
-    }
+    for (str = strend(*junkptr); str >= *junkptr && !IS_DIRSEP(*str); --str)
+	if (*str == '.') {
+	    *str = '\0';
+	    return 1;
+	}
     return 0;
 }
 
@@ -1379,12 +1396,15 @@ remtext(char **junkptr)
 int
 rembutext(char **junkptr)
 {
-    char *str = *junkptr, *remcut;
+    char *str;
 
-    if ((remcut = strrchr(str, '.')) && remcut != str) {
-	*junkptr = dupstring(remcut + 1);	/* .xx or xx? */
-	return 1;
-    }
+    for (str = strend(*junkptr); str >= *junkptr && !IS_DIRSEP(*str); --str)
+	if (*str == '.') {
+	    *junkptr = dupstring(str + 1); /* .xx or xx? */
+	    return 1;
+	}
+    /* no extension */
+    *junkptr = dupstring ("");
     return 0;
 }
 
@@ -1392,13 +1412,20 @@ rembutext(char **junkptr)
 mod_export int
 remlpaths(char **junkptr)
 {
-    char *str = *junkptr, *remcut;
+    char *str = strend(*junkptr);
 
-    if ((remcut = strrchr(str, '/'))) {
-	*remcut = '\0';
-	*junkptr = dupstring(remcut + 1);
-	return 1;
+    if (IS_DIRSEP(*str)) {
+	/* remove trailing slashes */
+	while (str >= *junkptr && IS_DIRSEP(*str))
+	    --str;
+	str[1] = '\0';
     }
+    for (; str >= *junkptr; --str)
+	if (IS_DIRSEP(*str)) {
+	    *str = '\0';
+	    *junkptr = dupstring(str + 1);
+	    return 1;
+	}
     return 0;
 }