stargazing/cosmo-mini/lr.patch

65 lines
2.1 KiB
Diff

--- lr/lr.c.old
+++ lr/lr.c
@@ -934,6 +910,25 @@
}
static const char *
+xextnam(const char *s)
+{
+ /* does not treat extensionless dotfiles as file extensions */
+ char *r = strrchr(s, '/');
+ char *e = strrchr(s, '.');
+ if (!r || r + 1 < e)
+ return e && e != s ? e + 1 : "";
+ return "";
+}
+
+static char
+dotted(const char *s)
+{
+ char *r = strrchr(s, '/');
+ char *e = strchr(r ? r : s, '.');
+ return (r && r + 1 == e || s == e) ? '.' : '\0';
+}
+
+static const char *
readlin(const char *p, const char *alt)
{
static char b[PATH_MAX];
@@ -1453,6 +1447,8 @@
case 'I': CMP(fb->sb.st_ino, fa->sb.st_ino);
case 'd': CMP(fa->depth, fb->depth);
case 'D': CMP(fb->depth, fa->depth);
+ case 'u': CMP(!dotted(fa->fpath), !dotted(fb->fpath));
+ case 'U': CMP(!dotted(fb->fpath), !dotted(fa->fpath));
case 't': CMP("ZZZZAZZZZZZZZZZZ"[(fa->sb.st_mode >> 12) & 0x0f],
"ZZZZAZZZZZZZZZZZ"[(fb->sb.st_mode >> 12) & 0x0f]);
case 'T': CMP("ZZZZAZZZZZZZZZZZ"[(fb->sb.st_mode >> 12) & 0x0f],
@@ -1461,8 +1457,8 @@
case 'N': STRCMP(fb->fpath, fa->fpath);
case 'f': STRCMP(basenam(fa->fpath), basenam(fb->fpath));
case 'F': STRCMP(basenam(fb->fpath), basenam(fa->fpath));
- case 'e': STRCMP(extnam(fa->fpath), extnam(fb->fpath));
- case 'E': STRCMP(extnam(fb->fpath), extnam(fa->fpath));
+ case 'e': STRCMP(xextnam(fa->fpath), xextnam(fb->fpath));
+ case 'E': STRCMP(xextnam(fb->fpath), xextnam(fa->fpath));
case 'p': DIRCMP(fa->fpath, fb->fpath);
case 'P': DIRCMP(fb->fpath, fa->fpath);
case 'v': VERCMP(fa->fpath, fb->fpath);
@@ -2156,6 +2152,15 @@
fi->color = current_color;
memcpy((char *)&fi->sb, (char *)sb, sizeof (struct stat));
+ if (IsWindows() && !S_ISDIR(fi->sb.st_mode)) {
+ /* pretend that only .exe and .com files are executable */
+ char *ext = extnam(fi->fpath);
+ if (strcasecmp(ext, "exe") && strcasecmp(ext, "com"))
+ fi->sb.st_mode &= ~0111;
+ /* MSYS also reads the first two bytes of the file and compares
+ * them to "MZ" and "#!", but let's avoid doing that for now. */
+ }
+
prune = 0;
if (expr && !eval(expr, fi)) {
if (Bflag && S_ISDIR(fi->sb.st_mode) && !prune) {