xref: /titanic_52/usr/src/cmd/acct/lib/pnpsplit.c (revision 414388d7cb2ee98771e2ac7c2338c460abd44304)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*414388d7Ssl108498  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * pnpsplit splits interval into prime & nonprime portions
357c478bd9Sstevel@tonic-gate  * ONLY ROUTINE THAT KNOWS ABOUT HOLIDAYS AND DEFN OF PRIME/NONPRIME
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include "acctdef.h"
427c478bd9Sstevel@tonic-gate #include <time.h>
437c478bd9Sstevel@tonic-gate #include <ctype.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /* validate that hours and minutes of prime/non-prime read in
467c478bd9Sstevel@tonic-gate  * from holidays file fall within proper boundaries.
477c478bd9Sstevel@tonic-gate  * Time is expected in the form and range of 0000-2359.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static int	thisyear = 1970;	/* this is changed by holidays file */
517c478bd9Sstevel@tonic-gate static int	holidays[NHOLIDAYS];	/* holidays file day-of-year table */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate static int day_tab[2][13] = {
547c478bd9Sstevel@tonic-gate 	{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
557c478bd9Sstevel@tonic-gate 	{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
567c478bd9Sstevel@tonic-gate };
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  *	prime(0) and nonprime(1) times during a day
607c478bd9Sstevel@tonic-gate  *	for BTL, prime time is 9AM to 5PM
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate static struct hours {
637c478bd9Sstevel@tonic-gate 	int	h_sec;		/* normally always zero */
647c478bd9Sstevel@tonic-gate 	int	h_min;		/* initialized from holidays file (time%100) */
657c478bd9Sstevel@tonic-gate 	int	h_hour;		/* initialized from holidays file (time/100) */
667c478bd9Sstevel@tonic-gate 	long	h_type;		/* prime/nonprime of previous period */
677c478bd9Sstevel@tonic-gate } h[4];
687c478bd9Sstevel@tonic-gate int	daysend[] = {60, 59, 23};	/* the sec, min, hr of the day's end */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate struct tm *localtime();
717c478bd9Sstevel@tonic-gate long	tmsecs();
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * split interval of length etime, starting at start into prime/nonprime
757c478bd9Sstevel@tonic-gate  * values, return as result
767c478bd9Sstevel@tonic-gate  * input values in seconds
777c478bd9Sstevel@tonic-gate  */
78*414388d7Ssl108498 int
797c478bd9Sstevel@tonic-gate pnpsplit(start, etime, result)
807c478bd9Sstevel@tonic-gate long start, result[2];
817c478bd9Sstevel@tonic-gate ulong_t etime;
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate 	struct tm cur, end;
847c478bd9Sstevel@tonic-gate 	time_t tcur, tend;
857c478bd9Sstevel@tonic-gate 	long tmp;
86*414388d7Ssl108498 	int sameday;
877c478bd9Sstevel@tonic-gate 	register struct hours *hp;
887c478bd9Sstevel@tonic-gate 	char *memcpy();
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	/* once holidays file is read, this is zero */
917c478bd9Sstevel@tonic-gate 	if (thisyear && (checkhol() == 0)) {
927c478bd9Sstevel@tonic-gate 		return(0);
937c478bd9Sstevel@tonic-gate 	}
947c478bd9Sstevel@tonic-gate 	tcur = start;
957c478bd9Sstevel@tonic-gate 	tend = start+etime;
967c478bd9Sstevel@tonic-gate 	memcpy(&end, localtime(&tend), sizeof(end));
977c478bd9Sstevel@tonic-gate 	result[PRIME] = 0;
987c478bd9Sstevel@tonic-gate 	result[NONPRIME] = 0;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	while (tcur < tend) {	/* one iteration per day or part thereof */
1017c478bd9Sstevel@tonic-gate 		memcpy(&cur, localtime(&tcur), sizeof(cur));
1027c478bd9Sstevel@tonic-gate 		sameday = cur.tm_yday == end.tm_yday;
1037c478bd9Sstevel@tonic-gate 		if (ssh(&cur)) {	/* ssh:only NONPRIME */
1047c478bd9Sstevel@tonic-gate 			if (sameday) {
1057c478bd9Sstevel@tonic-gate 				result[NONPRIME] += tend-tcur;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 				break;
1087c478bd9Sstevel@tonic-gate 			} else {
1097c478bd9Sstevel@tonic-gate 				tmp = tmsecs(&cur, daysend);
1107c478bd9Sstevel@tonic-gate 				result[NONPRIME] += tmp;
1117c478bd9Sstevel@tonic-gate 				tcur += tmp;
1127c478bd9Sstevel@tonic-gate 			}
1137c478bd9Sstevel@tonic-gate 		} else {	/* working day, PRIME or NONPRIME */
1147c478bd9Sstevel@tonic-gate 			for (hp = h; tmless(hp, &cur); hp++);
1157c478bd9Sstevel@tonic-gate 			for (; hp->h_sec >= 0; hp++) {
1167c478bd9Sstevel@tonic-gate 				if (sameday && tmless(&end, hp)) {
1177c478bd9Sstevel@tonic-gate 			/* WHCC mod, change from = to +=   3/6/86   Paul */
1187c478bd9Sstevel@tonic-gate 					result[hp->h_type] += tend-tcur;
1197c478bd9Sstevel@tonic-gate 					tcur = tend;
1207c478bd9Sstevel@tonic-gate 					break;	/* all done */
1217c478bd9Sstevel@tonic-gate 				} else {	/* time to next PRIME /NONPRIME change */
1227c478bd9Sstevel@tonic-gate 					tmp = tmsecs(&cur, hp);
1237c478bd9Sstevel@tonic-gate 					result[hp->h_type] += tmp;
1247c478bd9Sstevel@tonic-gate 					tcur += tmp;
1257c478bd9Sstevel@tonic-gate 					cur.tm_sec = hp->h_sec;
1267c478bd9Sstevel@tonic-gate 					cur.tm_min = hp->h_min;
1277c478bd9Sstevel@tonic-gate 					cur.tm_hour = hp->h_hour;
1287c478bd9Sstevel@tonic-gate 				}
1297c478bd9Sstevel@tonic-gate 			}
1307c478bd9Sstevel@tonic-gate 		}
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 	return(1);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  *	Starting day after Christmas, complain if holidays not yet updated.
1377c478bd9Sstevel@tonic-gate  *	This code is only executed once per program invocation.
1387c478bd9Sstevel@tonic-gate  */
139*414388d7Ssl108498 int
1407c478bd9Sstevel@tonic-gate checkhol()
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate 	register struct tm *tp;
1437c478bd9Sstevel@tonic-gate 	time_t t;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	if(inithol() == 0) {
1467c478bd9Sstevel@tonic-gate 		fprintf(stderr, "pnpsplit: holidays table setup failed\n");
1477c478bd9Sstevel@tonic-gate 		thisyear = 0;
1487c478bd9Sstevel@tonic-gate 		holidays[0] = -1;
1497c478bd9Sstevel@tonic-gate 		return(0);
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 	time(&t);
1527c478bd9Sstevel@tonic-gate 	tp = localtime(&t);
1537c478bd9Sstevel@tonic-gate 	tp->tm_year += 1900;
1547c478bd9Sstevel@tonic-gate 	if ((tp->tm_year == thisyear && tp->tm_yday > 359)
1557c478bd9Sstevel@tonic-gate 		|| tp->tm_year > thisyear)
1567c478bd9Sstevel@tonic-gate 		fprintf(stderr,
1577c478bd9Sstevel@tonic-gate 			"***UPDATE %s WITH NEW HOLIDAYS***\n", HOLFILE);
1587c478bd9Sstevel@tonic-gate 	thisyear = 0;	/* checkhol() will not be called again */
1597c478bd9Sstevel@tonic-gate 	return(1);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * ssh returns 1 if Sat, Sun, or Holiday
1647c478bd9Sstevel@tonic-gate  */
165*414388d7Ssl108498 int
1667c478bd9Sstevel@tonic-gate ssh(ltp)
1677c478bd9Sstevel@tonic-gate register struct tm *ltp;
1687c478bd9Sstevel@tonic-gate {
169*414388d7Ssl108498 	int i;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	if (ltp->tm_wday == 0 || ltp->tm_wday == 6)
1727c478bd9Sstevel@tonic-gate 		return(1);
1737c478bd9Sstevel@tonic-gate 	for (i = 0; holidays[i] >= 0; i++)
1747c478bd9Sstevel@tonic-gate 		if (ltp->tm_yday == holidays[i])
1757c478bd9Sstevel@tonic-gate 			return(1);
1767c478bd9Sstevel@tonic-gate 	return(0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * inithol - read from an ascii file and initialize the "thisyear"
1817c478bd9Sstevel@tonic-gate  * variable, the times that prime and non-prime start, and the
1827c478bd9Sstevel@tonic-gate  * holidays array.
1837c478bd9Sstevel@tonic-gate  */
184*414388d7Ssl108498 int
1857c478bd9Sstevel@tonic-gate inithol()
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate 	FILE		*fopen(), *holptr;
1887c478bd9Sstevel@tonic-gate 	char		*fgets(), holbuf[128];
1897c478bd9Sstevel@tonic-gate 	register int	line = 0,
1907c478bd9Sstevel@tonic-gate 			holindx = 0,
1917c478bd9Sstevel@tonic-gate 			errflag = 0;
1927c478bd9Sstevel@tonic-gate 	int		pstart, npstart;
1937c478bd9Sstevel@tonic-gate 	int		doy;	/* day of the year */
1947c478bd9Sstevel@tonic-gate 	int 		month, day;
1957c478bd9Sstevel@tonic-gate 	char		*c;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	if((holptr=fopen(HOLFILE, "r")) == NULL) {
1987c478bd9Sstevel@tonic-gate 		perror(HOLFILE);
1997c478bd9Sstevel@tonic-gate 		fclose(holptr);
2007c478bd9Sstevel@tonic-gate 		return(0);
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 	while(fgets(holbuf, sizeof(holbuf), holptr) != NULL) {
2037c478bd9Sstevel@tonic-gate 		/* skip over blank lines and comments */
2047c478bd9Sstevel@tonic-gate 		if (holbuf[0] == '*')
2057c478bd9Sstevel@tonic-gate 			continue;
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 		for (c = holbuf; isspace(*c); c++)
2087c478bd9Sstevel@tonic-gate 			/* is a space */;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 		if (*c == '\0')
2117c478bd9Sstevel@tonic-gate 			continue;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 		else if(++line == 1) {	/* format: year p-start np-start */
2147c478bd9Sstevel@tonic-gate 			if(sscanf(holbuf, "%4d %4d %4d",
2157c478bd9Sstevel@tonic-gate 				&thisyear, &pstart, &npstart) != 3) {
2167c478bd9Sstevel@tonic-gate 				fprintf(stderr,
2177c478bd9Sstevel@tonic-gate 					"%s: bad {yr ptime nptime} conversion\n",
2187c478bd9Sstevel@tonic-gate 					HOLFILE);
2197c478bd9Sstevel@tonic-gate 				errflag++;
2207c478bd9Sstevel@tonic-gate 				break;
2217c478bd9Sstevel@tonic-gate 			}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 			/* validate year */
2247c478bd9Sstevel@tonic-gate 			if(thisyear < 1970 || thisyear > 2037) {
2257c478bd9Sstevel@tonic-gate 				fprintf(stderr, "pnpsplit: invalid year: %d\n",
2267c478bd9Sstevel@tonic-gate 					thisyear);
2277c478bd9Sstevel@tonic-gate 				errflag++;
2287c478bd9Sstevel@tonic-gate 				break;
2297c478bd9Sstevel@tonic-gate 			}
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 			/* validate prime/nonprime hours */
2327c478bd9Sstevel@tonic-gate 			if((! okay(pstart)) || (! okay(npstart))) {
2337c478bd9Sstevel@tonic-gate 				fprintf(stderr,
2347c478bd9Sstevel@tonic-gate 					"pnpsplit: invalid p/np hours\n");
2357c478bd9Sstevel@tonic-gate 				errflag++;
2367c478bd9Sstevel@tonic-gate 				break;
2377c478bd9Sstevel@tonic-gate 			}
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 			/* Set up start of prime time; 2400 == 0000 */
2407c478bd9Sstevel@tonic-gate 			h[0].h_sec = 0;
2417c478bd9Sstevel@tonic-gate 			h[0].h_min = pstart%100;
2427c478bd9Sstevel@tonic-gate 			h[0].h_hour = (pstart/100==24) ? 0 : pstart/100;
2437c478bd9Sstevel@tonic-gate 			h[0].h_type = NONPRIME;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 			/* Set up start of non-prime time; 2400 == 0000 */
2467c478bd9Sstevel@tonic-gate 			h[1].h_sec = 0;
2477c478bd9Sstevel@tonic-gate 			h[1].h_min = npstart%100;
2487c478bd9Sstevel@tonic-gate 			h[1].h_hour = (npstart/100==24) ? 0 : npstart/100;
2497c478bd9Sstevel@tonic-gate 			h[1].h_type = PRIME ;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 			/* This is the end of the day */
2527c478bd9Sstevel@tonic-gate 			h[2].h_sec = 60;
2537c478bd9Sstevel@tonic-gate 			h[2].h_min = 59;
2547c478bd9Sstevel@tonic-gate 			h[2].h_hour = 23;
2557c478bd9Sstevel@tonic-gate 			h[2].h_type = NONPRIME;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 			/* The end of the array */
2587c478bd9Sstevel@tonic-gate 			h[3].h_sec = -1;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 			continue;
2617c478bd9Sstevel@tonic-gate 		}
2627c478bd9Sstevel@tonic-gate 		else if(holindx >= NHOLIDAYS) {
2637c478bd9Sstevel@tonic-gate 			fprintf(stderr, "pnpsplit: too many holidays, ");
2647c478bd9Sstevel@tonic-gate 			fprintf(stderr, "recompile with larger NHOLIDAYS\n");
2657c478bd9Sstevel@tonic-gate 			errflag++;
2667c478bd9Sstevel@tonic-gate 			break;
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		/* Fill up holidays array from holidays file */
2707c478bd9Sstevel@tonic-gate 		sscanf(holbuf, "%d/%d	%*s %*s	%*[^\n]\n", &month, &day);
2717c478bd9Sstevel@tonic-gate 		if (month < 0 || month > 12) {
2727c478bd9Sstevel@tonic-gate 			fprintf(stderr, "pnpsplit: invalid month %d\n", month);
2737c478bd9Sstevel@tonic-gate 			errflag++;
2747c478bd9Sstevel@tonic-gate 			break;
2757c478bd9Sstevel@tonic-gate 		}
2767c478bd9Sstevel@tonic-gate 		if (day < 0 || day > 31) {
2777c478bd9Sstevel@tonic-gate 			fprintf(stderr, "pnpsplit: invalid day %d\n", day);
2787c478bd9Sstevel@tonic-gate 			errflag++;
2797c478bd9Sstevel@tonic-gate 			break;
2807c478bd9Sstevel@tonic-gate 		}
2817c478bd9Sstevel@tonic-gate 		doy = day_of_year(thisyear, month, day);
2827c478bd9Sstevel@tonic-gate 		holidays[holindx++] = (doy - 1);
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 	fclose(holptr);
2857c478bd9Sstevel@tonic-gate 	if(!errflag && holindx < NHOLIDAYS) {
2867c478bd9Sstevel@tonic-gate 		holidays[holindx] = -1;
2877c478bd9Sstevel@tonic-gate 		return(1);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate 	else
2907c478bd9Sstevel@tonic-gate 		return(0);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  *	tmsecs returns number of seconds from t1 to t2,
2957c478bd9Sstevel@tonic-gate  *	times expressed in localtime format.
2967c478bd9Sstevel@tonic-gate  *	assumed that t1 <= t2, and are in same day.
2977c478bd9Sstevel@tonic-gate  */
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate long
3007c478bd9Sstevel@tonic-gate tmsecs(t1, t2)
3017c478bd9Sstevel@tonic-gate register struct tm *t1, *t2;
3027c478bd9Sstevel@tonic-gate {
3037c478bd9Sstevel@tonic-gate 	return((t2->tm_sec - t1->tm_sec) +
3047c478bd9Sstevel@tonic-gate 		60*(t2->tm_min - t1->tm_min) +
3057c478bd9Sstevel@tonic-gate 		3600L*(t2->tm_hour - t1->tm_hour));
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  *	return 1 if t1 earlier than t2 (times in localtime format)
3107c478bd9Sstevel@tonic-gate  *	assumed that t1 and t2 are in same day
3117c478bd9Sstevel@tonic-gate  */
3127c478bd9Sstevel@tonic-gate 
313*414388d7Ssl108498 int
3147c478bd9Sstevel@tonic-gate tmless(t1, t2)
3157c478bd9Sstevel@tonic-gate register struct tm *t1, *t2;
3167c478bd9Sstevel@tonic-gate {
3177c478bd9Sstevel@tonic-gate 	if (t1->tm_hour != t2->tm_hour)
3187c478bd9Sstevel@tonic-gate 		return(t1->tm_hour < t2->tm_hour);
3197c478bd9Sstevel@tonic-gate 	if (t1->tm_min != t2->tm_min)
3207c478bd9Sstevel@tonic-gate 		return(t1->tm_min < t2->tm_min);
3217c478bd9Sstevel@tonic-gate 	return(t1->tm_sec < t2->tm_sec);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /* set day of year from month and day */
3257c478bd9Sstevel@tonic-gate 
326*414388d7Ssl108498 int
3277c478bd9Sstevel@tonic-gate day_of_year(year, month, day)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	int i, leap;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	leap = year%4 == 0 && year%100 || year%400 == 0;
3327c478bd9Sstevel@tonic-gate 	for (i = 1; i < month; i++)
3337c478bd9Sstevel@tonic-gate 		day += day_tab[leap][i];
3347c478bd9Sstevel@tonic-gate 	return(day);
3357c478bd9Sstevel@tonic-gate }
336