xref: /dragonfly/usr.bin/calendar/dates.h (revision d19ef5a2)
1*d19ef5a2SAaron LI /*-
2*d19ef5a2SAaron LI  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*d19ef5a2SAaron LI  *
4*d19ef5a2SAaron LI  * Copyright (c) 2020 The DragonFly Project.  All rights reserved.
5*d19ef5a2SAaron LI  * Copyright (c) 1992-2009 Edwin Groothuis <edwin@FreeBSD.org>.
6*d19ef5a2SAaron LI  * All rights reserved.
7*d19ef5a2SAaron LI  *
8*d19ef5a2SAaron LI  * This code is derived from software contributed to The DragonFly Project
9*d19ef5a2SAaron LI  * by Aaron LI <aly@aaronly.me>
10*d19ef5a2SAaron LI  *
11*d19ef5a2SAaron LI  * Redistribution and use in source and binary forms, with or without
12*d19ef5a2SAaron LI  * modification, are permitted provided that the following conditions
13*d19ef5a2SAaron LI  * are met:
14*d19ef5a2SAaron LI  * 1. Redistributions of source code must retain the above copyright
15*d19ef5a2SAaron LI  *    notice, this list of conditions and the following disclaimer.
16*d19ef5a2SAaron LI  * 2. Redistributions in binary form must reproduce the above copyright
17*d19ef5a2SAaron LI  *    notice, this list of conditions and the following disclaimer in the
18*d19ef5a2SAaron LI  *    documentation and/or other materials provided with the distribution.
19*d19ef5a2SAaron LI  *
20*d19ef5a2SAaron LI  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21*d19ef5a2SAaron LI  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*d19ef5a2SAaron LI  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*d19ef5a2SAaron LI  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*d19ef5a2SAaron LI  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*d19ef5a2SAaron LI  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*d19ef5a2SAaron LI  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*d19ef5a2SAaron LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*d19ef5a2SAaron LI  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*d19ef5a2SAaron LI  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*d19ef5a2SAaron LI  * SUCH DAMAGE.
31*d19ef5a2SAaron LI  */
32*d19ef5a2SAaron LI 
33*d19ef5a2SAaron LI #ifndef DATES_H_
34*d19ef5a2SAaron LI #define DATES_H_
35*d19ef5a2SAaron LI 
36*d19ef5a2SAaron LI #include <stdbool.h>
37*d19ef5a2SAaron LI #include <stdio.h>
38*d19ef5a2SAaron LI 
39*d19ef5a2SAaron LI struct event;
40*d19ef5a2SAaron LI struct cal_desc;
41*d19ef5a2SAaron LI 
42*d19ef5a2SAaron LI struct cal_day {
43*d19ef5a2SAaron LI 	int	rd;
44*d19ef5a2SAaron LI 	int	year;
45*d19ef5a2SAaron LI 	int	month;
46*d19ef5a2SAaron LI 	int	day;
47*d19ef5a2SAaron LI 	int	dow[3];  /* [day-of-week, index-in-month, reverse-index] */
48*d19ef5a2SAaron LI 	bool	last_dom;  /* true if the last day of month */
49*d19ef5a2SAaron LI 	struct event *events;
50*d19ef5a2SAaron LI };
51*d19ef5a2SAaron LI 
52*d19ef5a2SAaron LI void	generate_dates(void);
53*d19ef5a2SAaron LI void	free_dates(void);
54*d19ef5a2SAaron LI struct cal_day *loop_dates(struct cal_day *dp);
55*d19ef5a2SAaron LI 
56*d19ef5a2SAaron LI struct cal_day *find_rd(int rd, int offset);
57*d19ef5a2SAaron LI 
58*d19ef5a2SAaron LI struct event *event_add(struct cal_day *dp, bool day_first, bool variable,
59*d19ef5a2SAaron LI 			struct cal_desc *desc, char *extra);
60*d19ef5a2SAaron LI void	event_print_all(FILE *fp);
61*d19ef5a2SAaron LI 
62*d19ef5a2SAaron LI #endif
63