summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-05-12 16:49:59 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-05-12 16:49:59 +0000
commitea09bb1cefa9af8bf941ac588b4e52582ff878cf (patch)
treefd4b654b598752ea29fd2bd4fcf3434cde920e7a
parentbd70d684fcf40ff1fba07ec69bd08e1ce40cbd2f (diff)
downloadzsh-ea09bb1cefa9af8bf941ac588b4e52582ff878cf.tar.gz
zsh-ea09bb1cefa9af8bf941ac588b4e52582ff878cf.zip
25006, 25009: fix "or" orphaned symlink highlighting
fix ordering of statd versus extension and pattern highlight tests
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/mod_complist.yo3
-rw-r--r--Src/Zle/complist.c79
3 files changed, 51 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index c7500cdca..a00a87be7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2008-05-12 Peter Stephenson <pws@csr.com>
+ * 25006, 25009: Src/Zle/complist.c: do "or" symlink orphan
+ highlighting; make stat-ed file types take precedence over
+ extensions and patterns.
+
* 25002: Src/builtin.c, Src/init.c, Src/input.c, Src/loop.c,
Src/prompt.c, Src/subst.c, Src/utils.c, Src/zsh.h,
Src/Zle/zle_main.c, Src/Zle/zle_refresh.c: only update
diff --git a/Doc/Zsh/mod_complist.yo b/Doc/Zsh/mod_complist.yo
index f918a4345..a787a5a58 100644
--- a/Doc/Zsh/mod_complist.yo
+++ b/Doc/Zsh/mod_complist.yo
@@ -54,8 +54,7 @@ item(tt(cd 44;37))(
for character devices
)
item(tt(or) var(none))(
-for a symlink to nonexistent file (default is the value defined for tt(fi));
-this code is currently not used
+for a symlink to nonexistent file (default is the value defined for tt(ln)).
)
item(tt(mi) var(none))(
for a non-existent file (default is the value defined for tt(fi)); this code
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 9f4cbdeaa..e513a8475 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -533,9 +533,10 @@ getcols()
lr_caplen = strlen(mcolors.files[COL_LC]->col) +
strlen(mcolors.files[COL_RC]->col);
- /* Default for orphans and missing files. Currently not used */
+ /* Default for orphan is same as link. */
if (!mcolors.files[COL_OR] || !mcolors.files[COL_OR]->col)
- mcolors.files[COL_OR] = mcolors.files[COL_FI];
+ mcolors.files[COL_OR] = mcolors.files[COL_LN];
+ /* Default for missing files: currently not used */
if (!mcolors.files[COL_MI] || !mcolors.files[COL_MI]->col)
mcolors.files[COL_MI] = mcolors.files[COL_FI];
@@ -871,36 +872,15 @@ putmatchcol(char *group, char *n)
* file modes. */
static int
-putfilecol(char *group, char *n, mode_t m)
+putfilecol(char *group, char *n, mode_t m, int special)
{
- int colour;
+ int colour = -1;
Extcol ec;
Patcol pc;
- for (ec = mcolors.exts; ec; ec = ec->next)
- if (strsfx(ec->ext, n) &&
- (!ec->prog || !group || pattry(ec->prog, group))) {
- zlrputs(ec->col);
-
- return 0;
- }
-
- nrefs = MAX_POS - 1;
-
- for (pc = mcolors.pats; pc; pc = pc->next)
- if ((!pc->prog || !group || pattry(pc->prog, group)) &&
- pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) {
- if (pc->cols[1]) {
- patcols = pc->cols;
-
- return 1;
- }
- zlrputs(pc->cols[0]);
-
- return 0;
- }
-
- if (S_ISDIR(m)) {
+ if (special != -1) {
+ colour = special;
+ } else if (S_ISDIR(m)) {
if (m & S_IWOTH)
if (m & S_ISVTX)
colour = COL_TW;
@@ -926,10 +906,36 @@ putfilecol(char *group, char *n, mode_t m)
colour = COL_SG;
else if (S_ISREG(m) && (m & S_IXUGO))
colour = COL_EX;
- else
- colour = COL_FI;
- zcputs(group, colour);
+ if (colour != -1) {
+ zcputs(group, colour);
+ return 0;
+ }
+
+ for (ec = mcolors.exts; ec; ec = ec->next)
+ if (strsfx(ec->ext, n) &&
+ (!ec->prog || !group || pattry(ec->prog, group))) {
+ zlrputs(ec->col);
+
+ return 0;
+ }
+
+ nrefs = MAX_POS - 1;
+
+ for (pc = mcolors.pats; pc; pc = pc->next)
+ if ((!pc->prog || !group || pattry(pc->prog, group)) &&
+ pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) {
+ if (pc->cols[1]) {
+ patcols = pc->cols;
+
+ return 1;
+ }
+ zlrputs(pc->cols[0]);
+
+ return 0;
+ }
+
+ zcputs(group, COL_FI);
return 0;
}
@@ -1752,10 +1758,17 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)))
zcputs(g->name, COL_DU);
else if (m->mode) {
+ /*
+ * Symlink is orphaned if we read the mode with lstat
+ * but couldn't read one with stat. That's the
+ * only way they can be different so the following
+ * test should be enough.
+ */
+ int orphan_colour = (m->mode && !m->fmode) ? COL_OR : -1;
if (mcolors.flags & LC_FOLLOW_SYMLINKS) {
- subcols = putfilecol(g->name, m->str, m->fmode);
+ subcols = putfilecol(g->name, m->str, m->fmode, orphan_colour);
} else {
- subcols = putfilecol(g->name, m->str, m->mode);
+ subcols = putfilecol(g->name, m->str, m->mode, orphan_colour);
}
}
else