>From 23cc463e6e52d0ca975ee077c91f06bb9a2748f0 Mon Sep 17 00:00:00 2001
From: Bastien Dejean <nihilh...@gmail.com>
Date: Wed, 24 Apr 2013 12:06:52 +0200
Subject: [PATCH] Add an option to select non-matching files

---
 stest.1 | 3 +++
 stest.c | 8 +++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/stest.1 b/stest.1
index bb48f45..18a1ba2 100644
--- a/stest.1
+++ b/stest.1
@@ -67,6 +67,9 @@ Test that files are not empty.
 .B \-u
 Test that files have their set-user-ID flag set.
 .TP
+.B \-v
+Inverse the sense of matching, to select non-matching files.
+.TP
 .B \-w
 Test that files are writable.
 .TP
diff --git a/stest.c b/stest.c
index e1dcf36..813bd2b 100644
--- a/stest.c
+++ b/stest.c
@@ -22,7 +22,7 @@ main(int argc, char *argv[]) {
        DIR *dir;
        int opt;
 
-       while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuwx")) != -1)
+       while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuwxv")) != -1)
                switch(opt) {
                case 'n': /* newer than file */
                case 'o': /* older than file */
@@ -59,8 +59,9 @@ main(int argc, char *argv[]) {
 void
 test(const char *path, const char *name) {
        struct stat st, ln;
+       bool m;
 
-       if(!stat(path, &st) && (FLAG('a') || name[0] != '.')          /* hidden 
files      */
+       m = !stat(path, &st) && (FLAG('a') || name[0] != '.')          /* 
hidden files      */
        && (!FLAG('b') || S_ISBLK(st.st_mode))                        /* block 
special     */
        && (!FLAG('c') || S_ISCHR(st.st_mode))                        /* 
character special */
        && (!FLAG('d') || S_ISDIR(st.st_mode))                        /* 
directory         */
@@ -75,7 +76,8 @@ test(const char *path, const char *name) {
        && (!FLAG('s') || st.st_size > 0)                             /* not 
empty         */
        && (!FLAG('u') || st.st_mode & S_ISUID)                       /* 
set-user-id flag  */
        && (!FLAG('w') || access(path, W_OK) == 0)                    /* 
writable          */
-       && (!FLAG('x') || access(path, X_OK) == 0)) {                 /* 
executable        */
+       && (!FLAG('x') || access(path, X_OK) == 0);                   /* 
executable        */
+       if((!FLAG('v') && m) || (FLAG('v') && !m)) {
                if(FLAG('q'))
                        exit(0);
                match = true;
-- 
1.8.2.1

Reply via email to