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