use getchar() for queryuser function; lots of minor lint
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 16 Nov 1990 05:03:06 +0000 (21:03 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 16 Nov 1990 05:03:06 +0000 (21:03 -0800)
SCCS-vsn: usr.bin/find/find.c 4.35
SCCS-vsn: usr.bin/find/find.h 5.3
SCCS-vsn: usr.bin/find/function.c 5.11
SCCS-vsn: usr.bin/find/misc.c 5.5
SCCS-vsn: usr.bin/find/operator.c 5.2

usr/src/usr.bin/find/find.c
usr/src/usr.bin/find/find.h
usr/src/usr.bin/find/function.c
usr/src/usr.bin/find/misc.c
usr/src/usr.bin/find/operator.c

index 61d6a40..0affdf0 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)find.c     4.34 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c     4.35 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -88,8 +88,8 @@ find_formplan(argv)
        char **argv;
 {
        PLAN *plan, *tail, *new;
        char **argv;
 {
        PLAN *plan, *tail, *new;
-       PLAN *c_print(), *find_create(), *find_squish_not(), *find_squish_or();
-       PLAN *find_squish_paren();
+       PLAN *c_print(), *find_create(), *not_squish(), *or_squish();
+       PLAN *paren_squish();
 
        /*
         * for each argument in the command line, determine what kind of node
 
        /*
         * for each argument in the command line, determine what kind of node
@@ -157,9 +157,9 @@ find_formplan(argv)
         * operators are handled in order of precedence.
         */
 
         * operators are handled in order of precedence.
         */
 
-       plan = find_squish_paren(plan);         /* ()'s */
-       plan = find_squish_not(plan);           /* !'s */
-       plan = find_squish_or(plan);            /* -o's */
+       plan = paren_squish(plan);              /* ()'s */
+       plan = not_squish(plan);                /* !'s */
+       plan = or_squish(plan);                 /* -o's */
        return(plan);
 }
  
        return(plan);
 }
  
index 301078a..a4418bf 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)find.h      5.2 (Berkeley) %G%
+ *     @(#)find.h      5.3 (Berkeley) %G%
  */
 
 /* node definition */
  */
 
 /* node definition */
@@ -81,4 +81,4 @@ typedef struct _plandata {
 
 extern int ftsoptions;
 extern int isdeprecated, isdepth, isoutput, isrelative, isstopdnx;
 
 extern int ftsoptions;
 extern int isdeprecated, isdepth, isoutput, isrelative, isstopdnx;
-char *emalloc();
+void *emalloc();
index 38e53cd..845223a 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)function.c 5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)function.c 5.11 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -168,7 +168,6 @@ f_always_true(plan, entry)
 PLAN *
 c_depth()
 {
 PLAN *
 c_depth()
 {
-       extern int depth;
        PLAN *new;
     
        isdepth = 1;
        PLAN *new;
     
        isdepth = 1;
@@ -196,14 +195,14 @@ f_exec(plan, entry)
        register int cnt;
        union wait pstat;
        pid_t pid, waitpid();
        register int cnt;
        union wait pstat;
        pid_t pid, waitpid();
-       void find_subst();
+       void brace_subst();
 
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
 
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
-                       find_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
+                       brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
                            entry->fts_accpath, plan->e_len[cnt]);
 
                            entry->fts_accpath, plan->e_len[cnt]);
 
-       if (plan->flags && !find_queryuser(plan->e_argv))
+       if (plan->flags && !queryuser(plan->e_argv))
                return(0);
 
        switch(pid = vfork()) {
                return(0);
 
        switch(pid = vfork()) {
@@ -454,7 +453,7 @@ c_links(arg)
        ftsoptions &= ~FTS_NOSTAT;
     
        NEW(T_LINKS, f_links);
        ftsoptions &= ~FTS_NOSTAT;
     
        NEW(T_LINKS, f_links);
-       new->l_data = find_parsenum(new, "-links", arg, (char *)NULL);
+       new->l_data = (nlink_t)find_parsenum(new, "-links", arg, (char *)NULL);
        return(new);
 }
  
        return(new);
 }
  
index 1aecc7a..1c6d28c 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)misc.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c     5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -17,18 +17,20 @@ static char sccsid[] = "@(#)misc.c  5.4 (Berkeley) %G%";
 #include <sys/errno.h>
 #include <stdio.h>
 #include "find.h"
 #include <sys/errno.h>
 #include <stdio.h>
 #include "find.h"
+#include <stdlib.h>
+#include <string.h>
  
 /*
  
 /*
- * find_subst --
+ * brace_subst --
  *     Replace occurrences of {} in s1 with s2 and return the result string.
  */
  *     Replace occurrences of {} in s1 with s2 and return the result string.
  */
-find_subst(orig, store, path, len)
+void
+brace_subst(orig, store, path, len)
        char *orig, **store, *path;
        int len;
 {
        register int plen;
        register char ch, *p;
        char *orig, **store, *path;
        int len;
 {
        register int plen;
        register char ch, *p;
-       char *realloc(), *strerror();
 
        plen = strlen(path);
        for (p = *store; ch = *orig; ++orig)
 
        plen = strlen(path);
        for (p = *store; ch = *orig; ++orig)
@@ -48,21 +50,37 @@ find_subst(orig, store, path, len)
 }
 
 /*
 }
 
 /*
- * find_queryuser --
+ * queryuser --
  *     print a message to standard error and then read input from standard
  *     input. If the input is 'y' then 1 is returned.
  */
  *     print a message to standard error and then read input from standard
  *     input. If the input is 'y' then 1 is returned.
  */
-find_queryuser(argv)
+queryuser(argv)
        register char **argv;
 {
        register char **argv;
 {
-       char buf[10];
+       int ch, first, nl;
 
        (void)fprintf(stderr, "\"%s", *argv);
        while (*++argv)
                (void)fprintf(stderr, " %s", *argv);
        (void)fprintf(stderr, "\"? ");
        (void)fflush(stderr);
 
        (void)fprintf(stderr, "\"%s", *argv);
        while (*++argv)
                (void)fprintf(stderr, " %s", *argv);
        (void)fprintf(stderr, "\"? ");
        (void)fflush(stderr);
-       return(!fgets(buf, sizeof(buf), stdin) || buf[0] != 'y' ? 0 : 1);
+
+       first = ch = getchar();
+       for (nl = 0;;) {
+               if (ch == '\n') {
+                       nl = 1;
+                       break;
+               }
+               if (ch == EOF)
+                       break;
+               ch = getchar();
+       }
+
+       if (!nl) {
+               (void)fprintf(stderr, "\n");
+               (void)fflush(stderr);
+       }
+        return(first == 'y');
 }
  
 /*
 }
  
 /*
@@ -81,11 +99,11 @@ bad_arg(option, error)
  * emalloc --
  *     malloc with error checking.
  */
  * emalloc --
  *     malloc with error checking.
  */
-char *
+void *
 emalloc(len)
        u_int len;
 {
 emalloc(len)
        u_int len;
 {
-       char *p, *malloc(), *strerror();
+       void *p;
 
        if (!(p = malloc(len))) {
                (void)fprintf(stderr, "find: %s.\n", strerror(errno));
 
        if (!(p = malloc(len))) {
                (void)fprintf(stderr, "find: %s.\n", strerror(errno));
index c3e2ede..0774b1b 100644 (file)
@@ -9,19 +9,21 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)operator.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)operator.c 5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "find.h"
     
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "find.h"
     
+void bad_arg();
+
 /*
 /*
- * find_yanknode --
+ * yanknode --
  *     destructively removes the top from the plan
  */
 PLAN *
  *     destructively removes the top from the plan
  */
 PLAN *
-find_yanknode(planp)    
+yanknode(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
        PLAN *node;             /* top node removed from the plan */
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
        PLAN *node;             /* top node removed from the plan */
@@ -34,13 +36,13 @@ find_yanknode(planp)
 }
  
 /*
 }
  
 /*
- * find_yankexpr --
+ * yankexpr --
  *     Removes one expression from the plan.  This is used mainly by
  *     Removes one expression from the plan.  This is used mainly by
- *     find_squish_paren.  In comments below, an expression is either
- *     simple node or a T_EXPR node containing a list of simple nodes.
+ *     paren_squish.  In comments below, an expression is either a
+ *     simple node or a T_EXPR node containing a list of simple nodes.
  */
 PLAN *
  */
 PLAN *
-find_yankexpr(planp)    
+yankexpr(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
        register PLAN *next;    /* temp node holding subexpression results */
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
        register PLAN *next;    /* temp node holding subexpression results */
@@ -50,7 +52,7 @@ find_yankexpr(planp)
        int f_expr();
     
        /* first pull the top node from the plan */
        int f_expr();
     
        /* first pull the top node from the plan */
-       if ((node = find_yanknode(planp)) == NULL)
+       if ((node = yanknode(planp)) == NULL)
                return(NULL);
     
        /*
                return(NULL);
     
        /*
@@ -61,7 +63,7 @@ find_yankexpr(planp)
         */
        if (node->type == T_OPENPAREN)
                for (tail = subplan = NULL;;) {
         */
        if (node->type == T_OPENPAREN)
                for (tail = subplan = NULL;;) {
-                       if ((next = find_yankexpr(planp)) == NULL)
+                       if ((next = yankexpr(planp)) == NULL)
                                bad_arg("(", "missing closing ')'");
                        /*
                         * If we find a closing ')' we store the collected
                                bad_arg("(", "missing closing ')'");
                        /*
                         * If we find a closing ')' we store the collected
@@ -91,11 +93,11 @@ find_yankexpr(planp)
 }
  
 /*
 }
  
 /*
- * find_squish_paren --
+ * paren_squish --
  *     replaces "parentheisized" plans in our search plan with "expr" nodes.
  */
 PLAN *
  *     replaces "parentheisized" plans in our search plan with "expr" nodes.
  */
 PLAN *
-find_squish_paren(plan)
+paren_squish(plan)
        PLAN *plan;             /* plan with ( ) nodes */
 {
        register PLAN *expr;    /* pointer to next expression */
        PLAN *plan;             /* plan with ( ) nodes */
 {
        register PLAN *expr;    /* pointer to next expression */
@@ -105,10 +107,10 @@ find_squish_paren(plan)
        result = tail = NULL;
 
        /*
        result = tail = NULL;
 
        /*
-        * the basic idea is to have find_yankexpr do all our work and just
+        * the basic idea is to have yankexpr do all our work and just
         * collect it's results together.
         */
         * collect it's results together.
         */
-       while ((expr = find_yankexpr(&plan)) != NULL) {
+       while ((expr = yankexpr(&plan)) != NULL) {
                /*
                 * if we find an unclaimed ')' it means there is a missing
                 * '(' someplace.
                /*
                 * if we find an unclaimed ')' it means there is a missing
                 * '(' someplace.
@@ -129,11 +131,11 @@ find_squish_paren(plan)
 }
  
 /*
 }
  
 /*
- * find_squish_not --
+ * not_squish --
  *     compresses "!" expressions in our search plan.
  */
 PLAN *
  *     compresses "!" expressions in our search plan.
  */
 PLAN *
-find_squish_not(plan)
+not_squish(plan)
        PLAN *plan;             /* plan to process */
 {
        register PLAN *next;    /* next node being processed */
        PLAN *plan;             /* plan to process */
 {
        register PLAN *next;    /* next node being processed */
@@ -143,13 +145,13 @@ find_squish_not(plan)
     
        tail = result = next = NULL;
     
     
        tail = result = next = NULL;
     
-       while ((next = find_yanknode(&plan)) != NULL) {
+       while ((next = yanknode(&plan)) != NULL) {
                /*
                 * if we encounter a ( expression ) then look for nots in
                 * the expr subplan.
                 */
                if (next->type == T_EXPR)
                /*
                 * if we encounter a ( expression ) then look for nots in
                 * the expr subplan.
                 */
                if (next->type == T_EXPR)
-                       next->p_data[0] = find_squish_not(next->p_data[0]);
+                       next->p_data[0] = not_squish(next->p_data[0]);
 
                /*
                 * if we encounter a not, then snag the next node and place
 
                /*
                 * if we encounter a not, then snag the next node and place
@@ -159,10 +161,10 @@ find_squish_not(plan)
                if (next->type == T_NOT) {
                        int notlevel = 1;
 
                if (next->type == T_NOT) {
                        int notlevel = 1;
 
-                       node = find_yanknode(&plan);
+                       node = yanknode(&plan);
                        while (node->type == T_NOT) {
                                ++notlevel;
                        while (node->type == T_NOT) {
                                ++notlevel;
-                               node = find_yanknode(&plan);
+                               node = yanknode(&plan);
                        }
                        if (node == NULL)
                                bad_arg("!", "no following expression");
                        }
                        if (node == NULL)
                                bad_arg("!", "no following expression");
@@ -187,11 +189,11 @@ find_squish_not(plan)
 }
  
 /*
 }
  
 /*
- * find_squish_or --
+ * or_squish --
  *     compresses -o expressions in our search plan.
  */
 PLAN *
  *     compresses -o expressions in our search plan.
  */
 PLAN *
-find_squish_or(plan)
+or_squish(plan)
        PLAN *plan;             /* plan with ors to be squished */
 {
        register PLAN *next;    /* next node being processed */
        PLAN *plan;             /* plan with ors to be squished */
 {
        register PLAN *next;    /* next node being processed */
@@ -200,17 +202,17 @@ find_squish_or(plan)
     
        tail = result = next = NULL;
     
     
        tail = result = next = NULL;
     
-       while ((next = find_yanknode(&plan)) != NULL) {
+       while ((next = yanknode(&plan)) != NULL) {
                /*
                 * if we encounter a ( expression ) then look for or's in
                 * the expr subplan.
                 */
                if (next->type == T_EXPR)
                /*
                 * if we encounter a ( expression ) then look for or's in
                 * the expr subplan.
                 */
                if (next->type == T_EXPR)
-                       next->p_data[0] = find_squish_or(next->p_data[0]);
+                       next->p_data[0] = or_squish(next->p_data[0]);
 
                /* if we encounter a not then look for not's in the subplan */
                if (next->type == T_NOT)
 
                /* if we encounter a not then look for not's in the subplan */
                if (next->type == T_NOT)
-                       next->p_data[0] = find_squish_or(next->p_data[0]);
+                       next->p_data[0] = or_squish(next->p_data[0]);
 
                /*
                 * if we encounter an or, then place our collected plan in the
 
                /*
                 * if we encounter an or, then place our collected plan in the
@@ -221,7 +223,7 @@ find_squish_or(plan)
                        if (result == NULL)
                                bad_arg("-o", "no expression before -o");
                        next->p_data[0] = result;
                        if (result == NULL)
                                bad_arg("-o", "no expression before -o");
                        next->p_data[0] = result;
-                       next->p_data[1] = find_squish_or(plan);
+                       next->p_data[1] = or_squish(plan);
                        if (next->p_data[1] == NULL)
                                bad_arg("-o", "no expression after -o");
                        return(next);
                        if (next->p_data[1] == NULL)
                                bad_arg("-o", "no expression after -o");
                        return(next);