mirror of
https://github.com/zsh-users/zsh
synced 2024-07-25 04:04:52 +00:00
13280: NewImproved handling of colon modifiers w.r.t. paths
This commit is contained in:
parent
441648bf5d
commit
cd02c345af
|
@ -1,3 +1,9 @@
|
||||||
|
2001-02-19 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* Alexandre: 13280: Doc/Zsh/expn.yo, Src/hist.c, Src/string.c,
|
||||||
|
Src/system.h: More sh-like and path-like handling of colon
|
||||||
|
modifiers.
|
||||||
|
|
||||||
2001-02-17 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
|
2001-02-17 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
|
||||||
|
|
||||||
* unposted: Doc/Zsh/metafaq.yo: site name change from Geoff.
|
* unposted: Doc/Zsh/metafaq.yo: site name change from Geoff.
|
||||||
|
|
|
@ -202,16 +202,19 @@ noted.
|
||||||
|
|
||||||
startitem()
|
startitem()
|
||||||
item(tt(h))(
|
item(tt(h))(
|
||||||
Remove a trailing pathname component, leaving the head.
|
Remove a trailing pathname component, leaving the head. This works
|
||||||
|
like `tt(dirname)'.
|
||||||
)
|
)
|
||||||
item(tt(r))(
|
item(tt(r))(
|
||||||
Remove a trailing suffix of the form `tt(.)var(xxx)', leaving the basename.
|
Remove a filename extension of the form `tt(.)var(xxx)', leaving
|
||||||
|
the root name.
|
||||||
)
|
)
|
||||||
item(tt(e))(
|
item(tt(e))(
|
||||||
Remove all but the suffix.
|
Remove all but the extension.
|
||||||
)
|
)
|
||||||
item(tt(t))(
|
item(tt(t))(
|
||||||
Remove all leading pathname components, leaving the tail.
|
Remove all leading pathname components, leaving the tail. This works
|
||||||
|
like `tt(basename)'.
|
||||||
)
|
)
|
||||||
item(tt(p))(
|
item(tt(p))(
|
||||||
Print the new command but do not execute it. Only works with history
|
Print the new command but do not execute it. Only works with history
|
||||||
|
|
73
Src/hist.c
73
Src/hist.c
|
@ -1350,28 +1350,45 @@ hcomsearch(char *str)
|
||||||
int
|
int
|
||||||
remtpath(char **junkptr)
|
remtpath(char **junkptr)
|
||||||
{
|
{
|
||||||
char *str = *junkptr, *remcut;
|
char *str = strend(*junkptr);
|
||||||
|
|
||||||
if ((remcut = strrchr(str, '/'))) {
|
/* ignore trailing slashes */
|
||||||
if (str != remcut)
|
while (str >= *junkptr && IS_DIRSEP(*str))
|
||||||
*remcut = '\0';
|
--str;
|
||||||
else
|
/* skip filename */
|
||||||
str[1] = '\0';
|
while (str >= *junkptr && !IS_DIRSEP(*str))
|
||||||
return 1;
|
--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
|
int
|
||||||
remtext(char **junkptr)
|
remtext(char **junkptr)
|
||||||
{
|
{
|
||||||
char *str = *junkptr, *remcut;
|
char *str;
|
||||||
|
|
||||||
if ((remcut = strrchr(str, '.')) && remcut != str) {
|
for (str = strend(*junkptr); str >= *junkptr && !IS_DIRSEP(*str); --str)
|
||||||
*remcut = '\0';
|
if (*str == '.') {
|
||||||
return 1;
|
*str = '\0';
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1379,12 +1396,15 @@ remtext(char **junkptr)
|
||||||
int
|
int
|
||||||
rembutext(char **junkptr)
|
rembutext(char **junkptr)
|
||||||
{
|
{
|
||||||
char *str = *junkptr, *remcut;
|
char *str;
|
||||||
|
|
||||||
if ((remcut = strrchr(str, '.')) && remcut != str) {
|
for (str = strend(*junkptr); str >= *junkptr && !IS_DIRSEP(*str); --str)
|
||||||
*junkptr = dupstring(remcut + 1); /* .xx or xx? */
|
if (*str == '.') {
|
||||||
return 1;
|
*junkptr = dupstring(str + 1); /* .xx or xx? */
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
/* no extension */
|
||||||
|
*junkptr = dupstring ("");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1392,13 +1412,20 @@ rembutext(char **junkptr)
|
||||||
mod_export int
|
mod_export int
|
||||||
remlpaths(char **junkptr)
|
remlpaths(char **junkptr)
|
||||||
{
|
{
|
||||||
char *str = *junkptr, *remcut;
|
char *str = strend(*junkptr);
|
||||||
|
|
||||||
if ((remcut = strrchr(str, '/'))) {
|
if (IS_DIRSEP(*str)) {
|
||||||
*remcut = '\0';
|
/* remove trailing slashes */
|
||||||
*junkptr = dupstring(remcut + 1);
|
while (str >= *junkptr && IS_DIRSEP(*str))
|
||||||
return 1;
|
--str;
|
||||||
|
str[1] = '\0';
|
||||||
}
|
}
|
||||||
|
for (; str >= *junkptr; --str)
|
||||||
|
if (IS_DIRSEP(*str)) {
|
||||||
|
*str = '\0';
|
||||||
|
*junkptr = dupstring(str + 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
Src/string.c
14
Src/string.c
|
@ -79,7 +79,7 @@ zhtricat(char const *s1, char const *s2, char const *s3)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
size_t l1 = strlen(s1);
|
size_t l1 = strlen(s1);
|
||||||
size_t l2 = strlen(s2);
|
size_t l2 = strlen(s2);
|
||||||
|
|
||||||
ptr = (char *)zhalloc(l1 + l2 + strlen(s3) + 1);
|
ptr = (char *)zhalloc(l1 + l2 + strlen(s3) + 1);
|
||||||
strcpy(ptr, s1);
|
strcpy(ptr, s1);
|
||||||
strcpy(ptr + l1, s2);
|
strcpy(ptr + l1, s2);
|
||||||
|
@ -133,3 +133,15 @@ appstr(char *base, char const *append)
|
||||||
{
|
{
|
||||||
return strcat(realloc(base, strlen(base) + strlen(append) + 1), append);
|
return strcat(realloc(base, strlen(base) + strlen(append) + 1), append);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return a pointer to the last character of a string,
|
||||||
|
unless the string is empty. */
|
||||||
|
|
||||||
|
/**/
|
||||||
|
mod_export char *
|
||||||
|
strend(char *str)
|
||||||
|
{
|
||||||
|
if (*str == '\0')
|
||||||
|
return str;
|
||||||
|
return str + strlen (str) - 1;
|
||||||
|
}
|
||||||
|
|
|
@ -657,3 +657,9 @@ extern short ospeed;
|
||||||
#ifndef MAILDIR_SUPPORT
|
#ifndef MAILDIR_SUPPORT
|
||||||
#define mailstat(X,Y) stat(X,Y)
|
#define mailstat(X,Y) stat(X,Y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
# define IS_DIRSEP(c) ((c) == '/' || (c) == '\\')
|
||||||
|
#else
|
||||||
|
# define IS_DIRSEP(c) ((c) == '/')
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue