BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / find / operator.c
index 0774b1b..b62add6 100644 (file)
@@ -5,24 +5,48 @@
  * This code is derived from software contributed to Berkeley by
  * Cimarron D. Taylor of the University of California, Berkeley.
  *
  * This code is derived from software contributed to Berkeley by
  * Cimarron D. Taylor of the University of California, Berkeley.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)operator.c 5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)operator.c 5.4 (Berkeley) 5/24/91";
 #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();
-
 /*
  * yanknode --
  *     destructively removes the top from the plan
  */
 /*
  * yanknode --
  *     destructively removes the top from the plan
  */
-PLAN *
+static PLAN *
 yanknode(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
 yanknode(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
@@ -39,9 +63,9 @@ yanknode(planp)
  * yankexpr --
  *     Removes one expression from the plan.  This is used mainly by
  *     paren_squish.  In comments below, an expression is either a
  * yankexpr --
  *     Removes one expression from the plan.  This is used mainly by
  *     paren_squish.  In comments below, an expression is either a
- *     simple node or a T_EXPR node containing a list of simple nodes.
+ *     simple node or a N_EXPR node containing a list of simple nodes.
  */
  */
-PLAN *
+static PLAN *
 yankexpr(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
 yankexpr(planp)    
        PLAN **planp;           /* pointer to top of plan (modified) */
 {
@@ -61,22 +85,23 @@ yankexpr(planp)
         * just return it and unwind our recursion; all other nodes are
         * complete expressions, so just return them.
         */
         * just return it and unwind our recursion; all other nodes are
         * complete expressions, so just return them.
         */
-       if (node->type == T_OPENPAREN)
+       if (node->type == N_OPENPAREN)
                for (tail = subplan = NULL;;) {
                        if ((next = yankexpr(planp)) == NULL)
                for (tail = subplan = NULL;;) {
                        if ((next = yankexpr(planp)) == NULL)
-                               bad_arg("(", "missing closing ')'");
+                               err("%s: %s", "(", "missing closing ')'");
                        /*
                         * If we find a closing ')' we store the collected
                         * subplan in our '(' node and convert the node to
                        /*
                         * If we find a closing ')' we store the collected
                         * subplan in our '(' node and convert the node to
-                        * a T_EXPR.  The ')' we found is ignored.  Otherwise,
+                        * a N_EXPR.  The ')' we found is ignored.  Otherwise,
                         * we just continue to add whatever we get to our
                         * subplan.
                         */
                         * we just continue to add whatever we get to our
                         * subplan.
                         */
-                       if (next->type == T_CLOSEPAREN) {
+                       if (next->type == N_CLOSEPAREN) {
                                if (subplan == NULL)
                                if (subplan == NULL)
-                                       bad_arg("()", "empty inner expression");
+                                       err("%s: %s",
+                                           "()", "empty inner expression");
                                node->p_data[0] = subplan;
                                node->p_data[0] = subplan;
-                               node->type = T_EXPR;
+                               node->type = N_EXPR;
                                node->eval = f_expr;
                                break;
                        } else {
                                node->eval = f_expr;
                                break;
                        } else {
@@ -115,8 +140,8 @@ paren_squish(plan)
                 * if we find an unclaimed ')' it means there is a missing
                 * '(' someplace.
                 */
                 * if we find an unclaimed ')' it means there is a missing
                 * '(' someplace.
                 */
-               if (expr->type == T_CLOSEPAREN)
-                       bad_arg(")", "no beginning '('");
+               if (expr->type == N_CLOSEPAREN)
+                       err("%s: %s", ")", "no beginning '('");
 
                /* add the expression to our result plan */
                if (result == NULL)
 
                /* add the expression to our result plan */
                if (result == NULL)
@@ -139,7 +164,7 @@ 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 */
-       register PLAN *node;    /* temporary node used in T_NOT processing */
+       register PLAN *node;    /* temporary node used in N_NOT processing */
        register PLAN *tail;    /* pointer to tail of result plan */
        PLAN *result;           /* pointer to head of result plan */
     
        register PLAN *tail;    /* pointer to tail of result plan */
        PLAN *result;           /* pointer to head of result plan */
     
@@ -150,7 +175,7 @@ not_squish(plan)
                 * if we encounter a ( expression ) then look for nots in
                 * the expr subplan.
                 */
                 * if we encounter a ( expression ) then look for nots in
                 * the expr subplan.
                 */
-               if (next->type == T_EXPR)
+               if (next->type == N_EXPR)
                        next->p_data[0] = not_squish(next->p_data[0]);
 
                /*
                        next->p_data[0] = not_squish(next->p_data[0]);
 
                /*
@@ -158,18 +183,18 @@ not_squish(plan)
                 * it in the not's subplan.  As an optimization we compress
                 * several not's to zero or one not.
                 */
                 * it in the not's subplan.  As an optimization we compress
                 * several not's to zero or one not.
                 */
-               if (next->type == T_NOT) {
+               if (next->type == N_NOT) {
                        int notlevel = 1;
 
                        node = yanknode(&plan);
                        int notlevel = 1;
 
                        node = yanknode(&plan);
-                       while (node->type == T_NOT) {
+                       while (node->type == N_NOT) {
                                ++notlevel;
                                node = yanknode(&plan);
                        }
                        if (node == NULL)
                                ++notlevel;
                                node = yanknode(&plan);
                        }
                        if (node == NULL)
-                               bad_arg("!", "no following expression");
-                       if (node->type == T_OR)
-                               bad_arg("!", "nothing between ! and -o");
+                               err("%s: %s", "!", "no following expression");
+                       if (node->type == N_OR)
+                               err("%s: %s", "!", "nothing between ! and -o");
                        if (notlevel % 2 != 1)
                                next = node;
                        else
                        if (notlevel % 2 != 1)
                                next = node;
                        else
@@ -207,11 +232,11 @@ or_squish(plan)
                 * if we encounter a ( expression ) then look for or's in
                 * the expr subplan.
                 */
                 * if we encounter a ( expression ) then look for or's in
                 * the expr subplan.
                 */
-               if (next->type == T_EXPR)
+               if (next->type == N_EXPR)
                        next->p_data[0] = or_squish(next->p_data[0]);
 
                /* if we encounter a not then look for not's in the subplan */
                        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 (next->type == N_NOT)
                        next->p_data[0] = or_squish(next->p_data[0]);
 
                /*
                        next->p_data[0] = or_squish(next->p_data[0]);
 
                /*
@@ -219,13 +244,13 @@ or_squish(plan)
                 * or's first subplan and then recursively collect the
                 * remaining stuff into the second subplan and return the or.
                 */
                 * or's first subplan and then recursively collect the
                 * remaining stuff into the second subplan and return the or.
                 */
-               if (next->type == T_OR) {
+               if (next->type == N_OR) {
                        if (result == NULL)
                        if (result == NULL)
-                               bad_arg("-o", "no expression before -o");
+                               err("%s: %s", "-o", "no expression before -o");
                        next->p_data[0] = result;
                        next->p_data[1] = or_squish(plan);
                        if (next->p_data[1] == NULL)
                        next->p_data[0] = result;
                        next->p_data[1] = or_squish(plan);
                        if (next->p_data[1] == NULL)
-                               bad_arg("-o", "no expression after -o");
+                               err("%s: %s", "-o", "no expression after -o");
                        return(next);
                }
 
                        return(next);
                }