add FTS_XDEV
[unix-history] / usr / src / usr.bin / find / function.c
CommitLineData
45fc66f9
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Cimarron D. Taylor of the University of California, Berkeley.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#ifndef lint
f2037504 12static char sccsid[] = "@(#)function.c 5.4 (Berkeley) %G%";
45fc66f9
KB
13#endif /* not lint */
14
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <sys/wait.h>
18#include <sys/mount.h>
19#include <grp.h>
20#include <pwd.h>
21#include <fts.h>
22#include <unistd.h>
23#include <tzfile.h>
24#include <stdio.h>
38dde0cd 25#include <string.h>
45fc66f9
KB
26#include "find.h"
27
28#define FIND_EQUAL 0
29#define FIND_LESSTHAN 1
30#define FIND_GREATER 2
31
45fc66f9
KB
32#define COMPARE(a, b) { \
33 switch(plan->flags) { \
34 case FIND_EQUAL: \
35 return(a == b); \
36 case FIND_LESSTHAN: \
37 return(a < b); \
38 case FIND_GREATER: \
39 return(a > b); \
40 } \
f2037504 41 return(0); \
45fc66f9
KB
42}
43
44#define NEW(t, f) { \
45 new = (PLAN *)emalloc(sizeof(PLAN)); \
46 new->type = t; \
47 new->eval = f; \
48 new->flags = 0; \
49 new->next = NULL; \
50}
51
52/*
53 * find_parsenum --
54 * Parse a string of the form [+-]# and return the value.
55 */
56long
57find_parsenum(plan, option, str, endch)
58 PLAN *plan;
59 char *option, *str, *endch;
60{
61 long value;
62 char *endchar; /* pointer to character ending conversion */
63
64 /* determine comparison from leading + or - */
65 switch(*str) {
66 case '+':
67 ++str;
68 plan->flags = FIND_GREATER;
69 break;
70 case '-':
71 ++str;
72 plan->flags = FIND_LESSTHAN;
73 break;
74 default:
75 plan->flags = FIND_EQUAL;
76 break;
77 }
78
79 /*
80 * convert the string with strtol(). Note, if strtol() returns zero
81 * and endchar points to the beginning of the string we know we have
82 * a syntax error.
83 */
84 value = strtol(str, &endchar, 10);
85 if (!value && endchar == str ||
86 endchar[0] && (!endch || endchar[0] != *endch))
87 bad_arg(option, "illegal numeric value");
88 if (endch)
89 *endch = endchar[0];
90 return(value);
91}
92
93/*
94 * -atime n functions --
95 *
96 * True if the difference between the file access time and the
97 * current time is n 24 hour periods.
98 *
99 */
100f_atime(plan, entry)
101 PLAN *plan;
102 FTSENT *entry;
103{
104 extern time_t now;
105
f2037504
KB
106 COMPARE((now - entry->fts_statb.st_atime +
107 SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
45fc66f9
KB
108}
109
110PLAN *
111c_atime(arg)
112 char *arg;
113{
114 PLAN *new;
115
116 ftsoptions &= ~FTS_NOSTAT;
117
118 NEW(T_ATIME, f_atime);
119 new->t_data = find_parsenum(new, "-atime", arg, (char *)NULL);
120 return(new);
121}
122/*
123 * -ctime n functions --
124 *
125 * True if the difference between the last change of file
126 * status information and the current time is n 24 hour periods.
127 */
128f_ctime(plan, entry)
129 PLAN *plan;
130 FTSENT *entry;
131{
132 extern time_t now;
133
f2037504
KB
134 COMPARE((now - entry->fts_statb.st_ctime +
135 SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
45fc66f9
KB
136}
137
138PLAN *
139c_ctime(arg)
140 char *arg;
141{
142 PLAN *new;
143
144 ftsoptions &= ~FTS_NOSTAT;
145
146 NEW(T_CTIME, f_ctime);
147 new->t_data = find_parsenum(new, "-ctime", arg, (char *)NULL);
148 return(new);
149}
150
151/*
152 * -depth functions --
153 *
154 * Always true, causes descent of the directory hierarchy to be done
155 * so that all entries in a directory are acted on before the directory
156 * itself.
157 */
158/* ARGSUSED */
159f_always_true(plan, entry)
160 PLAN *plan;
161 FTSENT *entry;
162{
f2037504 163 return(1);
45fc66f9
KB
164}
165
166PLAN *
167c_depth()
168{
169 extern int depth;
170 PLAN *new;
171
172 depth = 1;
173
174 NEW(T_DEPTH, f_always_true);
175 return(new);
176}
177
178/*
179 * [-exec | -ok] utility [arg ... ] ; functions --
180 *
181 * True if the executed utility returns a zero value as exit status.
182 * The end of the primary expression is delimited by a semicolon. If
183 * "{}" occurs anywhere, it gets replaced by the current pathname.
184 * The current directory for the execution of utility is the same as
185 * the current directory when the find utility was started.
186 *
187 * The primary -ok is different in that it requests affirmation of the
188 * user before executing the utility.
189 */
190f_exec(plan, entry)
191 register PLAN *plan;
192 FTSENT *entry;
193{
194 register int cnt;
195 char *find_subst();
196 union wait pstat;
197 pid_t pid, waitpid();
198
199 for (cnt = 0; plan->e_argv[cnt]; ++cnt)
200 if (plan->e_len[cnt])
201 find_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
f2037504 202 entry->fts_path, plan->e_len[cnt]);
45fc66f9
KB
203
204 if (plan->flags && !find_queryuser(plan->e_argv))
f2037504 205 return(0);
45fc66f9
KB
206
207 switch(pid = vfork()) {
208 case -1:
209 (void)fprintf(stderr, "find: fork: %s.\n", strerror(errno));
210 exit(1);
211 /* NOTREACHED */
212 case 0:
213 execvp(plan->e_argv[0], plan->e_argv);
214 (void)fprintf(stderr,
215 "find: %s: %s.\n", plan->e_argv[0], strerror(errno));
216 exit(1);
217 /* NOTREACHED */
218 }
219 pid = waitpid(pid, &pstat, 0);
f2037504 220 return(pid != -1 && !pstat.w_status);
45fc66f9
KB
221}
222
223/*
224 * c_exec --
225 * build three parallel arrays, one with pointers to the strings passed
226 * on the command line, one with (possibly duplicated) pointers to the
227 * argv array, and one with integer values that are lengths of the
228 * strings, but also flags meaning that the string has to be massaged.
229 */
230PLAN *
231c_exec(argvp, isok)
232 char ***argvp;
233 int isok;
234{
235 PLAN *new; /* node returned */
236 register int cnt;
237 register char **argv, **ap, *p;
238
239 ftsoptions |= FTS_NOCHDIR;
240 output_specified = 1;
241
242 NEW(T_EXEC, f_exec);
243 new->flags = isok;
244
245 for (ap = argv = *argvp;; ++ap) {
246 if (!*ap)
247 bad_arg(isok ? "-ok" : "-exec", "no terminating \";\"");
248 if (**ap == ';')
249 break;
250 }
251
252 cnt = ap - *argvp + 1;
253 new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *));
254 new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *));
255 new->e_len = (int *)emalloc((u_int)cnt * sizeof(u_char));
256
257 for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
258 new->e_orig[cnt] = *argv;
259 for (p = *argv; *p; ++p)
260 if (p[0] == '{' && p[1] == '}') {
261 new->e_argv[cnt] = emalloc((u_int)1024);
262 new->e_len[cnt] = 1024;
263 break;
264 }
265 if (!*p) {
266 new->e_argv[cnt] = *argv;
267 new->e_len[cnt] = 0;
268 }
269 }
270 new->e_argv[cnt] = new->e_orig[cnt] = NULL;
271
272 *argvp = argv + 1;
273 return(new);
274}
275
276/*
277 * -follow functions --
278 *
279 * Always true, causes symbolic links to be followed on a global
280 * basis.
281 */
282PLAN *
283c_follow()
284{
285 PLAN *new;
286
287 ftsoptions &= ~FTS_PHYSICAL;
288 ftsoptions |= FTS_LOGICAL;
289
290 NEW(T_FOLLOW, f_always_true);
291 return(new);
292}
293
294/*
295 * -fstype functions --
296 *
297 * True if the file is of a certain type.
298 */
299f_fstype(plan, entry)
300 PLAN *plan;
301 FTSENT *entry;
302{
303 extern dev_t curdev;
304 struct statfs sb;
f2037504 305 static short val;
45fc66f9
KB
306
307 /* only check when we cross mount point */
f2037504
KB
308 if (curdev != entry->fts_statb.st_dev) {
309 if (statfs(entry->fts_accpath, &sb)) {
45fc66f9 310 (void)fprintf(stderr, "find: %s: %s.\n",
f2037504 311 entry->fts_accpath, strerror(errno));
45fc66f9
KB
312 exit(1);
313 }
f2037504 314 val = plan->flags == MOUNT_NONE ? sb.f_flags : sb.f_type;
45fc66f9 315 }
f2037504
KB
316 return(plan->flags == MOUNT_NONE ?
317 val & MNT_LOCAL : val == plan->flags);
45fc66f9
KB
318}
319
320PLAN *
321c_fstype(arg)
322 char *arg;
323{
324 register PLAN *new;
325
326 ftsoptions &= ~FTS_NOSTAT;
327
328 NEW(T_FSTYPE, f_fstype);
329 switch(*arg) {
f2037504
KB
330 case 'l':
331 if (!strcmp(arg, "local")) {
332 new->flags = MOUNT_NONE;
333 return(new);
334 }
335 break;
45fc66f9
KB
336 case 'm':
337 if (!strcmp(arg, "mfs")) {
338 new->flags = MOUNT_MFS;
339 return(new);
340 }
341 break;
342 case 'n':
343 if (!strcmp(arg, "nfs")) {
344 new->flags = MOUNT_NFS;
345 return(new);
346 }
347 break;
348 case 'p':
349 if (!strcmp(arg, "pc")) {
350 new->flags = MOUNT_PC;
351 return(new);
352 }
353 break;
354 case 'u':
355 if (!strcmp(arg, "ufs")) {
356 new->flags = MOUNT_UFS;
357 return(new);
358 }
359 break;
360 }
361 (void)fprintf(stderr, "find: unknown file type %s.\n", arg);
362 exit(1);
363 /* NOTREACHED */
364}
365
366/*
367 * -group gname functions --
368 *
369 * True if the file belongs to the group gname. If gname is numeric and
370 * an equivalent of the getgrnam() function does not return a valid group
371 * name, gname is taken as a group ID.
372 */
373f_group(plan, entry)
374 PLAN *plan;
375 FTSENT *entry;
376{
f2037504 377 return(entry->fts_statb.st_gid == plan->g_data);
45fc66f9
KB
378}
379
380PLAN *
381c_group(gname)
382 char *gname;
383{
384 PLAN *new;
385 struct group *g;
386 gid_t gid;
387
388 ftsoptions &= ~FTS_NOSTAT;
389
390 g = getgrnam(gname);
391 if (g == NULL) {
392 gid = atoi(gname);
393 if (gid == 0 && gname[0] != '0')
394 bad_arg("-group", "no such group");
395 } else
396 gid = g->gr_gid;
397
398 NEW(T_GROUP, f_group);
399 new->g_data = gid;
400 return(new);
401}
402
403/*
404 * -inum n functions --
405 *
406 * True if the file has inode # n.
407 */
408f_inum(plan, entry)
409 PLAN *plan;
410 FTSENT *entry;
411{
f2037504 412 COMPARE(entry->fts_statb.st_ino, plan->i_data);
45fc66f9
KB
413}
414
415PLAN *
416c_inum(arg)
417 char *arg;
418{
419 PLAN *new;
420
421 ftsoptions &= ~FTS_NOSTAT;
422
423 NEW(T_INUM, f_inum);
424 new->i_data = find_parsenum(new, "-inum", arg, (char *)NULL);
425 return(new);
426}
427
428/*
429 * -links n functions --
430 *
431 * True if the file has n links.
432 */
433f_links(plan, entry)
434 PLAN *plan;
435 FTSENT *entry;
436{
f2037504 437 COMPARE(entry->fts_statb.st_nlink, plan->l_data);
45fc66f9
KB
438}
439
440PLAN *
441c_links(arg)
442 char *arg;
443{
444 PLAN *new;
445
446 ftsoptions &= ~FTS_NOSTAT;
447
448 NEW(T_LINKS, f_links);
449 new->l_data = find_parsenum(new, "-links", arg, (char *)NULL);
450 return(new);
451}
452
453/*
454 * -ls functions --
455 *
456 * Always true - prints the current entry to stdout in "ls" format.
457 */
458/* ARGSUSED */
459f_ls(plan, entry)
460 PLAN *plan;
461 FTSENT *entry;
462{
f2037504
KB
463 printlong(entry->fts_path, entry->fts_accpath, &entry->fts_statb);
464 return(1);
45fc66f9
KB
465}
466
467PLAN *
468c_ls()
469{
470 PLAN *new;
471
472 ftsoptions &= ~FTS_NOSTAT;
473 output_specified = 1;
474
475 NEW(T_LS, f_ls);
476 return(new);
477}
478
479/*
480 * -name functions --
481 *
482 * True if the basename of the filename being examined
483 * matches pattern using Pattern Matching Notation S3.14
484 */
485f_name(plan, entry)
486 PLAN *plan;
487 FTSENT *entry;
488{
f2037504 489 return(fnmatch(plan->c_data, entry->fts_name, FNM_QUOTE));
45fc66f9
KB
490}
491
492PLAN *
493c_name(pattern)
494 char *pattern;
495{
496 PLAN *new;
497
498 NEW(T_NAME, f_name);
499 new->c_data = pattern;
500 return(new);
501}
502
503/*
504 * -newer file functions --
505 *
506 * True if the current file has been modified more recently
507 * then the modification time of the file named by the pathname
508 * file.
509 */
510f_newer(plan, entry)
511 PLAN *plan;
512 FTSENT *entry;
513{
f2037504 514 return(entry->fts_statb.st_mtime > plan->t_data);
45fc66f9
KB
515}
516
517PLAN *
518c_newer(filename)
519 char *filename;
520{
521 PLAN *new;
522 struct stat sb;
523
524 ftsoptions &= ~FTS_NOSTAT;
525
526 if (stat(filename, &sb)) {
527 (void)fprintf(stderr, "find: %s: %s.\n",
528 filename, strerror(errno));
529 exit(1);
530 }
531 NEW(T_NEWER, f_newer);
532 new->t_data = sb.st_mtime;
533 return(new);
534}
535
536/*
537 * -nogroup functions --
538 *
539 * True if file belongs to a user ID for which the equivalent
540 * of the getgrnam() 9.2.1 [POSIX.1] function returns NULL.
541 */
542/* ARGSUSED */
543f_nogroup(plan, entry)
544 PLAN *plan;
545 FTSENT *entry;
546{
f2037504 547 return(group_from_gid(entry->fts_statb.st_gid, 1));
45fc66f9
KB
548}
549
550PLAN *
551c_nogroup()
552{
553 PLAN *new;
554
555 ftsoptions &= ~FTS_NOSTAT;
556
557 NEW(T_NOGROUP, f_nogroup);
558 return(new);
559}
560
561/*
562 * -nouser functions --
563 *
564 * True if file belongs to a user ID for which the equivalent
565 * of the getpwuid() 9.2.2 [POSIX.1] function returns NULL.
566 */
567/* ARGSUSED */
568f_nouser(plan, entry)
569 PLAN *plan;
570 FTSENT *entry;
571{
f2037504 572 return(user_from_uid(entry->fts_statb.st_uid, 1));
45fc66f9
KB
573}
574
575PLAN *
576c_nouser()
577{
578 PLAN *new;
579
580 ftsoptions &= ~FTS_NOSTAT;
581
582 NEW(T_NOUSER, f_nouser);
583 return(new);
584}
585
586/*
587 * -perm functions --
588 *
589 * The mode argument is used to represent file mode bits. If it starts
590 * with a leading digit, it's treated as an octal mode, otherwise as a
591 * symbolic mode.
592 */
593f_perm(plan, entry)
594 PLAN *plan;
595 FTSENT *entry;
596{
597 mode_t mode;
598
f2037504 599 mode = entry->fts_statb.st_mode &
45fc66f9
KB
600 (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
601 if (plan->flags)
602 return((plan->m_data | mode) == mode);
603 else
604 return(mode == plan->m_data);
605 /* NOTREACHED */
606}
607
608PLAN *
609c_perm(perm)
610 char *perm;
611{
612 PLAN *new;
613
614 ftsoptions &= ~FTS_NOSTAT;
615
616 NEW(T_PERM, f_perm);
617
618 if (*perm == '-') {
619 new->flags = 1;
620 ++perm;
621 }
622
623 if (setmode(perm))
624 bad_arg("-perm", "illegal mode string");
625
626 new->m_data = getmode(0);
627 return(new);
628}
629
630/*
631 * -print functions --
632 *
633 * Always true, causes the current pathame to be written to
634 * standard output.
635 */
636/* ARGSUSED */
637f_print(plan, entry)
638 PLAN *plan;
639 FTSENT *entry;
640{
f2037504
KB
641 (void)printf("%s\n", entry->fts_path);
642 return(1);
45fc66f9
KB
643}
644
645PLAN *
646c_print()
647{
648 PLAN *new;
649
650 output_specified = 1;
651
652 NEW(T_PRINT, f_print);
653 return(new);
654}
655
656/*
657 * -prune functions --
658 *
659 * Prune a portion of the hierarchy.
660 */
661/* ARGSUSED */
662f_prune(plan, entry)
663 PLAN *plan;
664 FTSENT *entry;
665{
666 extern FTS *tree;
667
668 if (ftsset(tree, entry, FTS_SKIP)) {
669 (void)fprintf(stderr,
f2037504 670 "find: %s: %s.\n", entry->fts_path, strerror(errno));
45fc66f9
KB
671 exit(1);
672 }
f2037504 673 return(1);
45fc66f9
KB
674}
675
676PLAN *
677c_prune()
678{
679 PLAN *new;
680
681 NEW(T_PRUNE, f_prune);
682 return(new);
683}
684
685/*
686 * -size n[c] functions --
687 *
688 * True if the file size in bytes, divided by an implementation defined
689 * value and rounded up to the next integer, is n. If n is followed by
690 * a c, the size is in bytes.
691 */
692#define FIND_SIZE 512
693static int divsize = 1;
694
695f_size(plan, entry)
696 PLAN *plan;
697 FTSENT *entry;
698{
699 off_t size;
700
f2037504
KB
701 size = divsize ? (entry->fts_statb.st_size + FIND_SIZE - 1) /
702 FIND_SIZE : entry->fts_statb.st_size;
45fc66f9
KB
703 COMPARE(size, plan->o_data);
704}
705
706PLAN *
707c_size(arg)
708 char *arg;
709{
710 PLAN *new;
711 char endch;
712
713 ftsoptions &= ~FTS_NOSTAT;
714
715 NEW(T_SIZE, f_size);
716 new->o_data = find_parsenum(new, "-size", arg, &endch);
717 if (endch == 'c')
718 divsize = 0;
719 return(new);
720}
721
722/*
723 * -type c functions --
724 *
725 * True if the type of the file is c, where c is b, c, d, p, or f for
726 * block special file, character special file, directory, FIFO, or
727 * regular file, respectively.
728 */
729f_type(plan, entry)
730 PLAN *plan;
731 FTSENT *entry;
732{
f2037504 733 return(entry->fts_statb.st_mode & plan->m_data);
45fc66f9
KB
734}
735
736PLAN *
737c_type(typestring)
738 char *typestring;
739{
740 PLAN *new;
741 mode_t mask;
742
743 ftsoptions &= ~FTS_NOSTAT;
744
745 switch (typestring[0]) {
746 case 'b':
747 mask = S_IFBLK;
748 break;
749 case 'c':
750 mask = S_IFCHR;
751 break;
752 case 'd':
753 mask = S_IFDIR;
754 break;
755 case 'f':
756 mask = S_IFREG;
757 break;
758 case 'l':
759 mask = S_IFLNK;
760 break;
761 case 'p':
762 mask = S_IFIFO;
763 break;
764 case 's':
765 mask = S_IFSOCK;
766 break;
767 default:
768 bad_arg("-type", "unknown type");
769 }
770
771 NEW(T_TYPE, f_type);
772 new->m_data = mask;
773 return(new);
774}
775
776/*
777 * -user uname functions --
778 *
779 * True if the file belongs to the user uname. If uname is numeric and
780 * an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not
781 * return a valid user name, uname is taken as a user ID.
782 */
783f_user(plan, entry)
784 PLAN *plan;
785 FTSENT *entry;
786{
f2037504 787 return(entry->fts_statb.st_uid == plan->u_data);
45fc66f9
KB
788}
789
790PLAN *
791c_user(username)
792 char *username;
793{
794 PLAN *new;
795 struct passwd *p;
796 uid_t uid;
797
798 ftsoptions &= ~FTS_NOSTAT;
799
800 p = getpwnam(username);
801 if (p == NULL) {
802 uid = atoi(username);
803 if (uid == 0 && username[0] != '0')
804 bad_arg("-user", "no such user");
805 } else
806 uid = p->pw_uid;
807
808 NEW(T_USER, f_user);
809 new->u_data = uid;
810 return(new);
811}
812
813/*
814 * -xdev functions --
815 *
816 * Always true, causes find not to decend past directories that have a
817 * different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
818 *
819 * Note: this checking is done in find_execute().
820 */
821PLAN *
822c_xdev()
823{
824 extern int xdev;
825 PLAN *new;
826
827 xdev = 1;
828 ftsoptions &= ~FTS_NOSTAT;
829
830 NEW(T_XDEV, f_always_true);
831 return(new);
832}
833
834/*
835 * ( expression ) functions --
836 *
837 * True if expression is true.
838 */
839f_expr(plan, entry)
840 PLAN *plan;
841 FTSENT *entry;
842{
843 register PLAN *p;
844 register int state;
845
846 for (p = plan->p_data[0];
847 p && (state = (p->eval)(p, entry)); p = p->next);
848 return(state);
849}
850
851/*
852 * T_OPENPAREN and T_CLOSEPAREN nodes are temporary place markers. They are
853 * eliminated during phase 2 of find_formplan() --- the '(' node is converted
854 * to a T_EXPR node containing the expression and the ')' node is discarded.
855 */
856PLAN *
857c_openparen()
858{
859 PLAN *new;
860
861 NEW(T_OPENPAREN, (int (*)())-1);
862 return(new);
863}
864
865PLAN *
866c_closeparen()
867{
868 PLAN *new;
869
870 NEW(T_CLOSEPAREN, (int (*)())-1);
871 return(new);
872}
873
874/*
875 * -mtime n functions --
876 *
877 * True if the difference between the file modification time and the
878 * current time is n 24 hour periods.
879 */
880f_mtime(plan, entry)
881 PLAN *plan;
882 FTSENT *entry;
883{
884 extern time_t now;
885
f2037504
KB
886 COMPARE((now - entry->fts_statb.st_mtime + SECSPERDAY - 1) /
887 SECSPERDAY, plan->t_data);
45fc66f9
KB
888}
889
890PLAN *
891c_mtime(arg)
892 char *arg;
893{
894 PLAN *new;
895
896 ftsoptions &= ~FTS_NOSTAT;
897
898 NEW(T_MTIME, f_mtime);
899 new->t_data = find_parsenum(new, "-mtime", arg, (char *)NULL);
900 return(new);
901}
902
903/*
904 * ! expression functions --
905 *
906 * Negation of a primary; the unary NOT operator.
907 */
908f_not(plan, entry)
909 PLAN *plan;
910 FTSENT *entry;
911{
912 register PLAN *p;
913 register int state;
914
915 for (p = plan->p_data[0];
916 p && (state = (p->eval)(p, entry)); p = p->next);
917 return(!state);
918}
919
920PLAN *
921c_not()
922{
923 PLAN *new;
924
925 NEW(T_NOT, f_not);
926 return(new);
927}
928
929/*
930 * expression -o expression functions --
931 *
932 * Alternation of primaries; the OR operator. The second expression is
933 * not evaluated if the first expression is true.
934 */
935f_or(plan, entry)
936 PLAN *plan;
937 FTSENT *entry;
938{
939 register PLAN *p;
940 register int state;
941
942 for (p = plan->p_data[0];
943 p && (state = (p->eval)(p, entry)); p = p->next);
944
945 if (state)
f2037504 946 return(1);
45fc66f9
KB
947
948 for (p = plan->p_data[1];
949 p && (state = (p->eval)(p, entry)); p = p->next);
950 return(state);
951}
952
953PLAN *
954c_or()
955{
956 PLAN *new;
957
958 NEW(T_OR, f_or);
959 return(new);
960}