Deleted Added
full compact
function.c (71422) function.c (72945)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. 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 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
40#else
41static const char rcsid[] =
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. 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 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38#if 0
39static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
40#else
41static const char rcsid[] =
42 "$FreeBSD: head/usr.bin/find/function.c 71422 2001-01-23 11:16:50Z peter $";
42 "$FreeBSD: head/usr.bin/find/function.c 72945 2001-02-23 16:20:55Z knu $";
43#endif
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/ucred.h>
48#include <sys/stat.h>
49#include <sys/wait.h>
50#include <sys/mount.h>
51
52#include <dirent.h>
53#include <err.h>
54#include <errno.h>
55#include <fnmatch.h>
56#include <fts.h>
57#include <grp.h>
58#include <pwd.h>
43#endif
44#endif /* not lint */
45
46#include <sys/param.h>
47#include <sys/ucred.h>
48#include <sys/stat.h>
49#include <sys/wait.h>
50#include <sys/mount.h>
51
52#include <dirent.h>
53#include <err.h>
54#include <errno.h>
55#include <fnmatch.h>
56#include <fts.h>
57#include <grp.h>
58#include <pwd.h>
59#include <regex.h>
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <unistd.h>
63
64#include "find.h"
65
66#define COMPARE(a, b) { \

--- 4 unchanged lines hidden (view full) ---

71 return (a < b); \
72 case F_GREATER: \
73 return (a > b); \
74 default: \
75 abort(); \
76 } \
77}
78
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65#include "find.h"
66
67#define COMPARE(a, b) { \

--- 4 unchanged lines hidden (view full) ---

72 return (a < b); \
73 case F_GREATER: \
74 return (a > b); \
75 default: \
76 abort(); \
77 } \
78}
79
80static int do_f_regex __P((PLAN *, FTSENT *, int));
81static PLAN *do_c_regex __P((char *, int));
79static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
80
81/*
82 * find_parsenum --
83 * Parse a string of the form [+-]# and return the value.
84 */
85static long long
86find_parsenum(plan, option, vp, endch)

--- 832 unchanged lines hidden (view full) ---

919{
920 PLAN *new;
921
922 new = palloc(N_NAME, f_name);
923 new->c_data = pattern;
924 return (new);
925}
926
82static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
83
84/*
85 * find_parsenum --
86 * Parse a string of the form [+-]# and return the value.
87 */
88static long long
89find_parsenum(plan, option, vp, endch)

--- 832 unchanged lines hidden (view full) ---

922{
923 PLAN *new;
924
925 new = palloc(N_NAME, f_name);
926 new->c_data = pattern;
927 return (new);
928}
929
930
927/*
931/*
932 * -iname functions --
933 *
934 * Like -iname, but the match is case insensitive.
935 */
936int
937f_iname(plan, entry)
938 PLAN *plan;
939 FTSENT *entry;
940{
941 return (!fnmatch(plan->c_data, entry->fts_name, FNM_CASEFOLD));
942}
943
944PLAN *
945c_iname(pattern)
946 char *pattern;
947{
948 PLAN *new;
949
950 new = palloc(N_INAME, f_iname);
951 new->c_data = pattern;
952 return (new);
953}
954
955
956/*
957 * -regex functions --
958 *
959 * True if the whole path of the file matches pattern using
960 * regular expression.
961 */
962int
963f_regex(plan, entry)
964 PLAN *plan;
965 FTSENT *entry;
966{
967 return (do_f_regex(plan, entry, 0));
968}
969
970PLAN *
971c_regex(pattern)
972 char *pattern;
973{
974 return (do_c_regex(pattern, 0));
975}
976
977/*
978 * -iregex functions --
979 *
980 * Like -regex, but the match is case insensitive.
981 */
982int
983f_iregex(plan, entry)
984 PLAN *plan;
985 FTSENT *entry;
986{
987 return (do_f_regex(plan, entry, REG_ICASE));
988}
989
990PLAN *
991c_iregex(pattern)
992 char *pattern;
993{
994 return (do_c_regex(pattern, REG_ICASE));
995}
996
997static int
998do_f_regex(plan, entry, icase)
999 PLAN *plan;
1000 FTSENT *entry;
1001 int icase;
1002{
1003 char *str;
1004 size_t len;
1005 regex_t *pre;
1006 regmatch_t pmatch;
1007 int errcode;
1008 char errbuf[LINE_MAX];
1009 int matched;
1010
1011 pre = plan->re_data;
1012 str = entry->fts_path;
1013 len = strlen(str);
1014 matched = 0;
1015
1016 pmatch.rm_so = 0;
1017 pmatch.rm_eo = len;
1018
1019 errcode = regexec(pre, str, 1, &pmatch, REG_STARTEND);
1020
1021 if (errcode != 0 && errcode != REG_NOMATCH) {
1022 regerror(errcode, pre, errbuf, sizeof errbuf);
1023 errx(1, "%s: %s",
1024 icase == 0 ? "-regex" : "-iregex", errbuf);
1025 }
1026
1027 if (errcode == 0 && pmatch.rm_so == 0 && pmatch.rm_eo == len)
1028 matched = 1;
1029
1030 return (matched);
1031}
1032
1033PLAN *
1034do_c_regex(pattern, icase)
1035 char *pattern;
1036 int icase;
1037{
1038 PLAN *new;
1039 regex_t *pre;
1040 int errcode;
1041 char errbuf[LINE_MAX];
1042
1043 if ((pre = malloc(sizeof(regex_t))) == NULL)
1044 err(1, NULL);
1045
1046 if ((errcode = regcomp(pre, pattern, regexp_flags | icase)) != 0) {
1047 regerror(errcode, pre, errbuf, sizeof errbuf);
1048 errx(1, "%s: %s: %s",
1049 icase == 0 ? "-regex" : "-iregex", pattern, errbuf);
1050 }
1051
1052 new = icase == 0 ? palloc(N_REGEX, f_regex) : palloc(N_IREGEX, f_iregex);
1053 new->re_data = pre;
1054 return (new);
1055}
1056
1057/*
928 * -newer file functions --
929 *
930 * True if the current file has been modified more recently
931 * then the modification time of the file named by the pathname
932 * file.
933 */
934int
935f_newer(plan, entry)

--- 78 unchanged lines hidden (view full) ---

1014}
1015
1016PLAN *
1017c_path(pattern)
1018 char *pattern;
1019{
1020 PLAN *new;
1021
1058 * -newer file functions --
1059 *
1060 * True if the current file has been modified more recently
1061 * then the modification time of the file named by the pathname
1062 * file.
1063 */
1064int
1065f_newer(plan, entry)

--- 78 unchanged lines hidden (view full) ---

1144}
1145
1146PLAN *
1147c_path(pattern)
1148 char *pattern;
1149{
1150 PLAN *new;
1151
1022 new = palloc(N_NAME, f_path);
1152 new = palloc(N_PATH, f_path);
1023 new->c_data = pattern;
1024 return (new);
1025}
1026
1027/*
1153 new->c_data = pattern;
1154 return (new);
1155}
1156
1157/*
1158 * -ipath functions --
1159 *
1160 * Like -path, but the match is case insensitive.
1161 */
1162int
1163f_ipath(plan, entry)
1164 PLAN *plan;
1165 FTSENT *entry;
1166{
1167 return (!fnmatch(plan->c_data, entry->fts_path, FNM_CASEFOLD));
1168}
1169
1170PLAN *
1171c_ipath(pattern)
1172 char *pattern;
1173{
1174 PLAN *new;
1175
1176 new = palloc(N_IPATH, f_ipath);
1177 new->c_data = pattern;
1178 return (new);
1179}
1180
1181/*
1028 * -perm functions --
1029 *
1030 * The mode argument is used to represent file mode bits. If it starts
1031 * with a leading digit, it's treated as an octal mode, otherwise as a
1032 * symbolic mode.
1033 */
1034int
1035f_perm(plan, entry)

--- 484 unchanged lines hidden ---
1182 * -perm functions --
1183 *
1184 * The mode argument is used to represent file mode bits. If it starts
1185 * with a leading digit, it's treated as an octal mode, otherwise as a
1186 * symbolic mode.
1187 */
1188int
1189f_perm(plan, entry)

--- 484 unchanged lines hidden ---