function.c (7fd5ee41e3fc0035fa23ee3022cd53fa8cb0c53d) function.c (adff4fca3dc53af29a7a4d04d4b8f53ba247a3c3)
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

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

62#include <stdlib.h>
63#include <string.h>
64#include <unistd.h>
65
66#include "find.h"
67
68time_t get_date __P((char *date, struct timeb *now));
69
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

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

62#include <stdlib.h>
63#include <string.h>
64#include <unistd.h>
65
66#include "find.h"
67
68time_t get_date __P((char *date, struct timeb *now));
69
70#define COMPARE(a, b) { \
70#define COMPARE(a, b) do { \
71 switch (plan->flags & F_ELG_MASK) { \
72 case F_EQUAL: \
73 return (a == b); \
74 case F_LESSTHAN: \
75 return (a < b); \
76 case F_GREATER: \
77 return (a > b); \
78 default: \
79 abort(); \
80 } \
71 switch (plan->flags & F_ELG_MASK) { \
72 case F_EQUAL: \
73 return (a == b); \
74 case F_LESSTHAN: \
75 return (a < b); \
76 case F_GREATER: \
77 return (a > b); \
78 default: \
79 abort(); \
80 } \
81}
81} while(0)
82
83static PLAN *
84palloc(option)
85 OPTION *option;
86{
87 PLAN *new;
88
89 if ((new = malloc(sizeof(PLAN))) == NULL)

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

133 if (endchar[0] && (endch == NULL || endchar[0] != *endch))
134 errx(1, "%s: %s: illegal trailing character", option, vp);
135 if (endch)
136 *endch = endchar[0];
137 return value;
138}
139
140/*
82
83static PLAN *
84palloc(option)
85 OPTION *option;
86{
87 PLAN *new;
88
89 if ((new = malloc(sizeof(PLAN))) == NULL)

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

133 if (endchar[0] && (endch == NULL || endchar[0] != *endch))
134 errx(1, "%s: %s: illegal trailing character", option, vp);
135 if (endch)
136 *endch = endchar[0];
137 return value;
138}
139
140/*
141 * find_parsetime --
142 * Parse a string of the form [+-]([0-9]+[smhdw]?)+ and return the value.
143 */
144static long long
145find_parsetime(plan, option, vp)
146 PLAN *plan;
147 char *option, *vp;
148{
149 long long secs, value;
150 char *str, *unit; /* Pointer to character ending conversion. */
151
152 /* Determine comparison from leading + or -. */
153 str = vp;
154 switch (*str) {
155 case '+':
156 ++str;
157 plan->flags |= F_GREATER;
158 break;
159 case '-':
160 ++str;
161 plan->flags |= F_LESSTHAN;
162 break;
163 default:
164 plan->flags |= F_EQUAL;
165 break;
166 }
167
168 value = strtoq(str, &unit, 10);
169 if (value == 0 && unit == str) {
170 errx(1, "%s: %s: illegal time value", option, vp);
171 /* NOTREACHED */
172 }
173 if (*unit == '\0')
174 return value;
175
176 /* Units syntax. */
177 secs = 0;
178 for (;;) {
179 switch(*unit) {
180 case 's': /* seconds */
181 secs += value;
182 break;
183 case 'm': /* minutes */
184 secs += value * 60;
185 break;
186 case 'h': /* hours */
187 secs += value * 3600;
188 break;
189 case 'd': /* days */
190 secs += value * 86400;
191 break;
192 case 'w': /* weeks */
193 secs += value * 604800;
194 break;
195 default:
196 errx(1, "%s: %s: bad unit '%c'", option, vp, *unit);
197 /* NOTREACHED */
198 }
199 str = unit + 1;
200 if (*str == '\0') /* EOS */
201 break;
202 value = strtoq(str, &unit, 10);
203 if (value == 0 && unit == str) {
204 errx(1, "%s: %s: illegal time value", option, vp);
205 /* NOTREACHED */
206 }
207 if (*unit == '\0') {
208 errx(1, "%s: %s: missing trailing unit", option, vp);
209 /* NOTREACHED */
210 }
211 }
212 plan->flags |= F_EXACTTIME;
213 return secs;
214}
215
216/*
141 * nextarg --
142 * Check that another argument still exists, return a pointer to it,
143 * and increment the argument vector pointer.
144 */
145static char *
146nextarg(option, argvp)
147 OPTION *option;
148 char ***argvp;

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

221 */
222
223int
224f_Xtime(plan, entry)
225 PLAN *plan;
226 FTSENT *entry;
227{
228 extern time_t now;
217 * nextarg --
218 * Check that another argument still exists, return a pointer to it,
219 * and increment the argument vector pointer.
220 */
221static char *
222nextarg(option, argvp)
223 OPTION *option;
224 char ***argvp;

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

297 */
298
299int
300f_Xtime(plan, entry)
301 PLAN *plan;
302 FTSENT *entry;
303{
304 extern time_t now;
305 int exact_time;
229
306
307 exact_time = plan->flags & F_EXACTTIME;
308
230 if (plan->flags & F_TIME_C) {
309 if (plan->flags & F_TIME_C) {
231 COMPARE((now - entry->fts_statp->st_ctime +
232 86400 - 1) / 86400, plan->t_data);
310 if (exact_time)
311 COMPARE(now - entry->fts_statp->st_ctime,
312 plan->t_data);
313 else
314 COMPARE((now - entry->fts_statp->st_ctime +
315 86400 - 1) / 86400, plan->t_data);
233 } else if (plan->flags & F_TIME_A) {
316 } else if (plan->flags & F_TIME_A) {
234 COMPARE((now - entry->fts_statp->st_atime +
235 86400 - 1) / 86400, plan->t_data);
317 if (exact_time)
318 COMPARE(now - entry->fts_statp->st_atime,
319 plan->t_data);
320 else
321 COMPARE((now - entry->fts_statp->st_atime +
322 86400 - 1) / 86400, plan->t_data);
236 } else {
323 } else {
237 COMPARE((now - entry->fts_statp->st_mtime +
238 86400 - 1) / 86400, plan->t_data);
324 if (exact_time)
325 COMPARE(now - entry->fts_statp->st_mtime,
326 plan->t_data);
327 else
328 COMPARE((now - entry->fts_statp->st_mtime +
329 86400 - 1) / 86400, plan->t_data);
239 }
240}
241
242PLAN *
243c_Xtime(option, argvp)
244 OPTION *option;
245 char ***argvp;
246{
330 }
331}
332
333PLAN *
334c_Xtime(option, argvp)
335 OPTION *option;
336 char ***argvp;
337{
247 char *ndays;
338 char *value;
248 PLAN *new;
249
339 PLAN *new;
340
250 ndays = nextarg(option, argvp);
341 value = nextarg(option, argvp);
251 ftsoptions &= ~FTS_NOSTAT;
252
253 new = palloc(option);
342 ftsoptions &= ~FTS_NOSTAT;
343
344 new = palloc(option);
254 new->t_data = find_parsenum(new, option->name, ndays, NULL);
255 TIME_CORRECT(new);
345 new->t_data = find_parsetime(new, option->name, value);
346 if (!(new->flags & F_EXACTTIME))
347 TIME_CORRECT(new);
256 return new;
257}
258
259/*
260 * -maxdepth/-mindepth n functions --
261 *
262 * Does the same as -prune if the level of the current file is
263 * greater/less than the specified maximum/minimum depth.

--- 1196 unchanged lines hidden ---
348 return new;
349}
350
351/*
352 * -maxdepth/-mindepth n functions --
353 *
354 * Does the same as -prune if the level of the current file is
355 * greater/less than the specified maximum/minimum depth.

--- 1196 unchanged lines hidden ---