day.c (15160) | day.c (15714) |
---|---|
1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 | 1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 |
35#include <ctype.h> 36#include <locale.h> |
|
35#include <stdio.h> | 37#include <stdio.h> |
38#include <string.h> |
|
36#include <sys/types.h> 37#include <time.h> 38#include <sys/uio.h> 39#include <string.h> 40#include <stdlib.h> 41 42#include "pathnames.h" 43#include "calendar.h" --- 8 unchanged lines hidden (view full) --- 52 { 0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }, 53 { 0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, 54}; 55 56static char *days[] = { 57 "sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL, 58}; 59 | 39#include <sys/types.h> 40#include <time.h> 41#include <sys/uio.h> 42#include <string.h> 43#include <stdlib.h> 44 45#include "pathnames.h" 46#include "calendar.h" --- 8 unchanged lines hidden (view full) --- 55 { 0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }, 56 { 0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, 57}; 58 59static char *days[] = { 60 "sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL, 61}; 62 |
63static char *fndays[8]; /* full national days names */ 64static char *ndays[8]; /* short national days names */ 65 |
|
60static char *months[] = { 61 "jan", "feb", "mar", "apr", "may", "jun", 62 "jul", "aug", "sep", "oct", "nov", "dec", NULL, 63}; 64 | 66static char *months[] = { 67 "jan", "feb", "mar", "apr", "may", "jun", 68 "jul", "aug", "sep", "oct", "nov", "dec", NULL, 69}; 70 |
71static char *fnmonths[13]; /* full national months names */ 72static char *nmonths[13]; /* short national month names */ |
|
65 66 | 73 74 |
75void setnnames(void) 76{ 77 char buf[80]; 78 int i, l; 79 struct tm tm; |
|
67 | 80 |
81 for (i = 0; i < 7; i++) { 82 tm.tm_wday = i; 83 strftime(buf, sizeof(buf), "%a", &tm); 84 for (l = strlen(buf); 85 l > 0 && isspace((unsigned char)buf[l - 1]); 86 l--) 87 ; 88 buf[l] = '\0'; 89 if (ndays[i] != NULL) 90 free(ndays[i]); 91 ndays[i] = strdup(buf); 92 93 strftime(buf, sizeof(buf), "%A", &tm); 94 for (l = strlen(buf); 95 l > 0 && isspace((unsigned char)buf[l - 1]); 96 l--) 97 ; 98 buf[l] = '\0'; 99 if (fndays[i] != NULL) 100 free(fndays[i]); 101 fndays[i] = strdup(buf); 102#ifdef DEBUG 103 printf("ndays[%d] = %s, fndays[%d] = %s\n", 104 i, ndays[i], i, fndays[i]); 105#endif 106 } 107 108 for (i = 0; i < 12; i++) { 109 tm.tm_mon = i; 110 strftime(buf, sizeof(buf), "%b", &tm); 111 for (l = strlen(buf); 112 l > 0 && isspace((unsigned char)buf[l - 1]); 113 l--) 114 ; 115 buf[l] = '\0'; 116 if (nmonths[i] != NULL) 117 free(nmonths[i]); 118 nmonths[i] = strdup(buf); 119 120 strftime(buf, sizeof(buf), "%B", &tm); 121 for (l = strlen(buf); 122 l > 0 && isspace((unsigned char)buf[l - 1]); 123 l--) 124 ; 125 buf[l] = '\0'; 126 if (fnmonths[i] != NULL) 127 free(fnmonths[i]); 128 fnmonths[i] = strdup(buf); 129#ifdef DEBUG 130 printf("nmonths[%d] = %s, fnmonths[%d] = %s\n", 131 i, nmonths[i], i, fnmonths[i]); 132#endif 133 } 134} 135 |
|
68void 69settime(now) 70 time_t now; 71{ | 136void 137settime(now) 138 time_t now; 139{ |
72 | |
73 tp = localtime(&now); 74 if ( isleap(tp->tm_year + 1900) ) { 75 yrdays = 366; 76 cumdays = daytab[1]; 77 } else { 78 yrdays = 365; 79 cumdays = daytab[0]; 80 } 81 /* Friday displays Monday's events */ 82 offset = tp->tm_wday == 5 ? 3 : 1; 83 header[5].iov_base = dayname; | 140 tp = localtime(&now); 141 if ( isleap(tp->tm_year + 1900) ) { 142 yrdays = 366; 143 cumdays = daytab[1]; 144 } else { 145 yrdays = 365; 146 cumdays = daytab[0]; 147 } 148 /* Friday displays Monday's events */ 149 offset = tp->tm_wday == 5 ? 3 : 1; 150 header[5].iov_base = dayname; |
151 152 (void) setlocale(LC_TIME, "C"); |
|
84 header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp); | 153 header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp); |
154 (void) setlocale(LC_TIME, ""); 155 156 setnnames(); |
|
85} 86 87/* convert Day[/Month][/Year] into unix time (since 1970) 88 * Day: two digits, Month: two digits, Year: digits 89 */ 90time_t Mktime (date) 91 char *date; 92{ --- 51 unchanged lines hidden (view full) --- 144 */ 145int 146isnow(endp, monthp, dayp, varp) 147 char *endp; 148 int *monthp; 149 int *dayp; 150 int *varp; 151{ | 157} 158 159/* convert Day[/Month][/Year] into unix time (since 1970) 160 * Day: two digits, Month: two digits, Year: digits 161 */ 162time_t Mktime (date) 163 char *date; 164{ --- 51 unchanged lines hidden (view full) --- 216 */ 217int 218isnow(endp, monthp, dayp, varp) 219 char *endp; 220 int *monthp; 221 int *dayp; 222 int *varp; 223{ |
152 int day, flags, month, v1, v2; | 224 int day, flags, month = 0, v1, v2; |
153 154 /* 155 * CONVENTION 156 * 157 * Month: 1-12 158 * Monthname: Jan .. Dec 159 * Day: 1-31 160 * Weekday: Mon-Sun --- 151 unchanged lines hidden (view full) --- 312 313 314int 315getmonth(s) 316 register char *s; 317{ 318 register char **p; 319 | 225 226 /* 227 * CONVENTION 228 * 229 * Month: 1-12 230 * Monthname: Jan .. Dec 231 * Day: 1-31 232 * Weekday: Mon-Sun --- 151 unchanged lines hidden (view full) --- 384 385 386int 387getmonth(s) 388 register char *s; 389{ 390 register char **p; 391 |
392 for (p = fnmonths; *p; ++p) 393 if (!strncasecmp(s, *p, strlen(*p))) 394 return ((p - fnmonths) + 1); 395 for (p = nmonths; *p; ++p) 396 if (!strncasecmp(s, *p, strlen(*p))) 397 return ((p - nmonths) + 1); |
|
320 for (p = months; *p; ++p) 321 if (!strncasecmp(s, *p, 3)) 322 return ((p - months) + 1); 323 return (0); 324} 325 326 327int 328getday(s) 329 register char *s; 330{ 331 register char **p; 332 | 398 for (p = months; *p; ++p) 399 if (!strncasecmp(s, *p, 3)) 400 return ((p - months) + 1); 401 return (0); 402} 403 404 405int 406getday(s) 407 register char *s; 408{ 409 register char **p; 410 |
411 for (p = fndays; *p; ++p) 412 if (!strncasecmp(s, *p, strlen(*p))) 413 return ((p - fndays) + 1); 414 for (p = ndays; *p; ++p) 415 if (!strncasecmp(s, *p, strlen(*p))) 416 return ((p - ndays) + 1); |
|
333 for (p = days; *p; ++p) 334 if (!strncasecmp(s, *p, 3)) 335 return ((p - days) + 1); 336 return (0); 337} 338 339/* return offset for variable weekdays 340 * -1 -> last weekday in month --- 47 unchanged lines hidden --- | 417 for (p = days; *p; ++p) 418 if (!strncasecmp(s, *p, 3)) 419 return ((p - days) + 1); 420 return (0); 421} 422 423/* return offset for variable weekdays 424 * -1 -> last weekday in month --- 47 unchanged lines hidden --- |