calendar.h revision 181322
113877Swosch/*
213877Swosch * Copyright (c) 1989, 1993, 1994
313877Swosch *	The Regents of the University of California.  All rights reserved.
413877Swosch *
513877Swosch * Redistribution and use in source and binary forms, with or without
613877Swosch * modification, are permitted provided that the following conditions
713877Swosch * are met:
813877Swosch * 1. Redistributions of source code must retain the above copyright
913877Swosch *    notice, this list of conditions and the following disclaimer.
1013877Swosch * 2. Redistributions in binary form must reproduce the above copyright
1113877Swosch *    notice, this list of conditions and the following disclaimer in the
1213877Swosch *    documentation and/or other materials provided with the distribution.
1313877Swosch * 3. All advertising materials mentioning features or use of this software
1413877Swosch *    must display the following acknowledgement:
1513877Swosch *	This product includes software developed by the University of
1613877Swosch *	California, Berkeley and its contributors.
1713877Swosch * 4. Neither the name of the University nor the names of its contributors
1813877Swosch *    may be used to endorse or promote products derived from this software
1913877Swosch *    without specific prior written permission.
2013877Swosch *
2113877Swosch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2213877Swosch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2313877Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2413877Swosch * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2513877Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2613877Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2713877Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2813877Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2913877Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3013877Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3113877Swosch * SUCH DAMAGE.
3259945Sphantom *
3359945Sphantom * $FreeBSD: head/usr.bin/calendar/calendar.h 181322 2008-08-05 08:11:54Z edwin $
3413877Swosch */
3513877Swosch
36129814Sstefanf#include <sys/types.h>
37129814Sstefanf#include <sys/uio.h>
3813877Swosch
3913877Swoschextern struct passwd *pw;
4013877Swoschextern int doall;
4113877Swoschextern struct iovec header[];
4213877Swoschextern struct tm *tp;
4387235Smarkmextern const char *calendarFile;
44169343Sdwmaloneextern int *cumdays;
45170447Sgrogextern int yrdays;
46169343Sdwmaloneextern struct fixs neaster, npaskha;
4713877Swosch
48181322Sedwinvoid	cal(void);
49181322Sedwinvoid	closecal(FILE *);
50181322Sedwinint	getday(char *);
51181322Sedwinint	getdayvar(char *);
52181322Sedwinint	getfield(char *, char **, int *);
53181322Sedwinint	getmonth(char *);
54181322Sedwinint	geteaster(char *, int);
55181322Sedwinint	getpaskha(char *, int);
56181322Sedwinint	easter(int);
57181322Sedwinint	isnow(char *, int *, int *, int *);
5892920SimpFILE	*opencal(void);
59181322Sedwinvoid	settime(time_t);
60181322Sedwintime_t	Mktime(char *);
61181322Sedwinvoid	usage(void);
62181322Sedwinvoid	setnnames(void);
6313877Swosch
6415714Sache#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
6513877Swosch
6613877Swosch/* some flags */
67181322Sedwin#define	F_ISMONTH	0x01	/* month (January ...) */
68181322Sedwin#define	F_ISDAY		0x02	/* day of week (Sun, Mon, ...) */
69181322Sedwin#define	F_ISDAYVAR	0x04	/* variables day of week, like SundayLast */
70181322Sedwin#define	F_EASTER	0x08	/* Easter or easter depending days */
7113877Swosch
72181322Sedwinextern int	f_dayAfter;	/* days after current date */
73181322Sedwinextern int	f_dayBefore;	/* days before current date */
74181322Sedwinextern int	Friday;		/* day before weekend */
7515720Sache
76181322Sedwin/*
77181322Sedwin * Event sorting related functions:
78181322Sedwin * - Use event_add() to create a new event
79181322Sedwin * - Use event_continue() to add more text to the last added event
80181322Sedwin * - Use event_print_all() to display them in time chronological order
81181322Sedwin */
82181322Sedwinstruct event *event_add(struct event *, int, int, char *, int, char *);
83181322Sedwinvoid	event_continue(struct event *events, char *txt);
84181322Sedwinvoid	event_print_all(FILE *fp, struct event *events);
85170447Sgrogstruct event {
86181322Sedwin	int	month;
87181322Sedwin	int	day;
88181322Sedwin	int	var;
89181322Sedwin	char	*date;
90181322Sedwin	char	*text;
91170447Sgrog	struct event *next;
92170447Sgrog};
93181322Sedwin
94181322Sedwinstruct fixs {
95181322Sedwin	char	*name;
96181322Sedwin	int	len;
97181322Sedwin};
98