- /* Parse any options */
- for (i = firstopt; i < argc; i++) {
- if (strcmp(argv[i], "-follow") == 0)
- dereference = TRUE;
- else if (strcmp(argv[i], "-print") == 0) {
- ;
- }
- else if (strcmp(argv[i], "-name") == 0) {
- if (++i == argc)
- bb_error_msg_and_die(msg_req_arg, "-name");
- pattern = argv[i];
-#ifdef CONFIG_FEATURE_FIND_TYPE
- } else if (strcmp(argv[i], "-type") == 0) {
- if (++i == argc)
- bb_error_msg_and_die(msg_req_arg, "-type");
- type_mask = find_type(argv[i]);
+ appp = xzalloc(2 * sizeof(*appp)); /* appp[0],[1] == NULL */
+
+// Actions have side effects and return a true or false value
+// We implement: -print, -print0, -exec
+
+// The rest are tests.
+
+// Tests and actions are grouped by operators
+// ( expr ) Force precedence
+// ! expr True if expr is false
+// -not expr Same as ! expr
+// expr1 [-a[nd]] expr2 And; expr2 is not evaluated if expr1 is false
+// expr1 -o[r] expr2 Or; expr2 is not evaluated if expr1 is true
+// expr1 , expr2 List; both expr1 and expr2 are always evaluated
+// We implement: (), -a, -o
+
+ while (*argv) {
+ char *arg = argv[0];
+ char *arg1 = argv[1];
+ /* --- Operators --- */
+ if (strcmp(arg, "-a") == 0
+ USE_DESKTOP(|| strcmp(arg, "-and") == 0)
+ ) {
+ /* no special handling required */
+ }
+ else if (strcmp(arg, "-o") == 0
+ USE_DESKTOP(|| strcmp(arg, "-or") == 0)
+ ) {
+ /* start new OR group */
+ cur_group++;
+ appp = xrealloc(appp, (cur_group+2) * sizeof(*appp));
+ appp[cur_group] = NULL;
+ appp[cur_group+1] = NULL;
+ cur_action = 0;
+ }
+
+ /* --- Tests and actions --- */
+ else if (strcmp(arg, "-print") == 0) {
+ need_print = 0;
+ (void) ALLOC_ACTION(print);
+ }
+#if ENABLE_FEATURE_FIND_PRINT0
+ else if (strcmp(arg, "-print0") == 0) {
+ need_print = 0;
+ (void) ALLOC_ACTION(print0);
+ }