1 /* $OpenBSD: calendar.h,v 1.17 2019/02/01 16:22:53 millert Exp $ */ 2 3 /* 4 * Copyright (c) 1989, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #include <sys/types.h> 33 #include <time.h> 34 35 extern struct passwd *pw; 36 extern int doall; 37 extern int daynames; 38 extern int bodun_always; 39 extern time_t f_time; 40 extern struct tm *tp; 41 extern char *calendarFile; 42 extern char *calendarHome; 43 extern char *optarg; 44 45 struct fixs { 46 char *name; 47 int len; 48 }; 49 50 #define PRINT_DATE_BASE_LEN 35 51 52 struct event { 53 time_t when; 54 char print_date[PRINT_DATE_BASE_LEN+1]; 55 char **desc; 56 char *ldesc; 57 struct event *next; 58 }; 59 60 struct match { 61 time_t when; 62 char print_date[PRINT_DATE_BASE_LEN]; 63 int bodun; 64 int var; 65 struct match *next; 66 }; 67 68 struct specialev { 69 char *name; 70 int nlen; 71 char *uname; 72 int ulen; 73 int (*getev)(int); 74 }; 75 76 void cal(void); 77 void closecal(FILE *); 78 int getday(char *); 79 int getdayvar(char *); 80 int getfield(char *, char **, int *); 81 int getmonth(char *); 82 int pesach(int); 83 int easter(int); 84 int paskha(int); 85 void insert(struct event **, struct event *); 86 struct match *isnow(char *, int); 87 FILE *opencal(void); 88 void settime(time_t *); 89 time_t Mktime(char *); 90 void usage(void); 91 int foy(int); 92 void variable_weekday(int *, int, int); 93 void setnnames(void); 94 95 /* some flags */ 96 #define F_ISMONTH 0x01 /* month (Januar ...) */ 97 #define F_ISDAY 0x02 /* day of week (Sun, Mon, ...) */ 98 /*#define F_ISDAYVAR 0x04 variables day of week, like SundayLast */ 99 #define F_SPECIAL 0x08 /* Events that occur once a year but don't track 100 * calendar time--e.g. Easter or easter depending 101 * days */ 102 103 #define SECSPERDAY (24 * 60 * 60) 104 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) 105 106 extern int f_dayAfter; /* days after current date */ 107 extern int f_dayBefore; /* days before current date */ 108 extern int f_Setday; /* calendar invoked with -A or -B */ 109 110 /* Special events; see also setnnames() in day.c */ 111 /* '=' is not a valid character in a special event name */ 112 #define PESACH "pesach" 113 #define PESACHLEN (sizeof(PESACH) - 1) 114 #define EASTER "easter" 115 #define EASTERNAMELEN (sizeof(EASTER) - 1) 116 #define PASKHA "paskha" 117 #define PASKHALEN (sizeof(PASKHA) - 1) 118 119 /* calendars */ 120 extern enum calendars { GREGORIAN = 0, JULIAN, LUNAR } calendar; 121 extern u_long julian; 122 123 #define NUMEV 3 /* Total number of such special events */ 124 extern struct specialev spev[NUMEV]; 125 126 /* For calendar -a, specify a maximum time (in seconds) to spend parsing 127 * each user's calendar files. This prevents them from hanging calendar 128 * (e.g. by using named pipes) 129 */ 130 #define USERTIMEOUT 20 131