Deleted Added
full compact
vary.c (69457) vary.c (91079)
1/*-
2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
1/*-
2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
29 "$FreeBSD: head/bin/date/vary.c 69457 2000-12-01 09:59:40Z brian $";
29 "$FreeBSD: head/bin/date/vary.c 91079 2002-02-22 20:51:00Z markm $";
30#endif /* not lint */
31
30#endif /* not lint */
31
32#include <sys/cdefs.h>
32#include <err.h>
33#include <time.h>
34#include <string.h>
35#include <stdlib.h>
36#include "vary.h"
37
38struct trans {
39 int val;
33#include <err.h>
34#include <time.h>
35#include <string.h>
36#include <stdlib.h>
37#include "vary.h"
38
39struct trans {
40 int val;
40 char *str;
41 const char *str;
41};
42
43static struct trans trans_mon[] = {
44 { 1, "january" }, { 2, "february" }, { 3, "march" }, { 4, "april" },
45 { 5, "may"}, { 6, "june" }, { 7, "july" }, { 8, "august" },
46 { 9, "september" }, { 10, "october" }, { 11, "november" }, { 12, "december" },
47 { -1, NULL }
48};

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

198 }
199
200 return !mk || domktime(t, type) != -1;
201}
202
203static int
204adjday(struct tm *t, char type, int val, int mk)
205{
42};
43
44static struct trans trans_mon[] = {
45 { 1, "january" }, { 2, "february" }, { 3, "march" }, { 4, "april" },
46 { 5, "may"}, { 6, "june" }, { 7, "july" }, { 8, "august" },
47 { 9, "september" }, { 10, "october" }, { 11, "november" }, { 12, "december" },
48 { -1, NULL }
49};

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

199 }
200
201 return !mk || domktime(t, type) != -1;
202}
203
204static int
205adjday(struct tm *t, char type, int val, int mk)
206{
206 int mdays;
207 int lmdays;
207
208 switch (type) {
209 case '+':
210 while (val) {
208
209 switch (type) {
210 case '+':
211 while (val) {
211 mdays = daysinmonth(t);
212 if (val > mdays - t->tm_mday) {
213 val -= mdays - t->tm_mday + 1;
212 lmdays = daysinmonth(t);
213 if (val > lmdays - t->tm_mday) {
214 val -= lmdays - t->tm_mday + 1;
214 t->tm_mday = 1;
215 if (!adjmon(t, '+', 1, 0, 0))
216 return 0;
217 } else {
218 t->tm_mday += val;
219 val = 0;
220 }
221 }

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

408}
409
410const struct vary *
411vary_apply(const struct vary *v, struct tm *t)
412{
413 char type;
414 char which;
415 char *arg;
215 t->tm_mday = 1;
216 if (!adjmon(t, '+', 1, 0, 0))
217 return 0;
218 } else {
219 t->tm_mday += val;
220 val = 0;
221 }
222 }

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

409}
410
411const struct vary *
412vary_apply(const struct vary *v, struct tm *t)
413{
414 char type;
415 char which;
416 char *arg;
416 int len;
417 size_t len;
417 int val;
418
419 for (; v; v = v->next) {
420 type = *v->arg;
421 arg = v->arg;
422 if (type == '+' || type == '-')
423 arg++;
424 else

--- 77 unchanged lines hidden ---
418 int val;
419
420 for (; v; v = v->next) {
421 type = *v->arg;
422 arg = v->arg;
423 if (type == '+' || type == '-')
424 arg++;
425 else

--- 77 unchanged lines hidden ---