Deleted Added
full compact
day.c (15714) day.c (15720)
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

--- 46 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
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

--- 46 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
66static char *months[] = {
67 "jan", "feb", "mar", "apr", "may", "jun",
68 "jul", "aug", "sep", "oct", "nov", "dec", NULL,
69};
70
63static char *months[] = {
64 "jan", "feb", "mar", "apr", "may", "jun",
65 "jul", "aug", "sep", "oct", "nov", "dec", NULL,
66};
67
71static char *fnmonths[13]; /* full national months names */
72static char *nmonths[13]; /* short national month names */
68static struct fixs fndays[8]; /* full national days names */
69static struct fixs ndays[8]; /* short national days names */
73
70
71static struct fixs fnmonths[13]; /* full national months names */
72static struct fixs nmonths[13]; /* short national month names */
74
73
74
75void setnnames(void)
76{
77 char buf[80];
78 int i, l;
79 struct tm tm;
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';
75void setnnames(void)
76{
77 char buf[80];
78 int i, l;
79 struct tm tm;
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);
89 if (ndays[i].name != NULL)
90 free(ndays[i].name);
91 ndays[i].name = strdup(buf);
92 ndays[i].len = strlen(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';
93
94 strftime(buf, sizeof(buf), "%A", &tm);
95 for (l = strlen(buf);
96 l > 0 && isspace((unsigned char)buf[l - 1]);
97 l--)
98 ;
99 buf[l] = '\0';
99 if (fndays[i] != NULL)
100 free(fndays[i]);
101 fndays[i] = strdup(buf);
100 if (fndays[i].name != NULL)
101 free(fndays[i].name);
102 fndays[i].name = strdup(buf);
103 fndays[i].len = strlen(buf);
102#ifdef DEBUG
103 printf("ndays[%d] = %s, fndays[%d] = %s\n",
104#ifdef DEBUG
105 printf("ndays[%d] = %s, fndays[%d] = %s\n",
104 i, ndays[i], i, fndays[i]);
106 i, ndays[i].name, i, fndays[i].name);
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';
107#endif
108 }
109
110 for (i = 0; i < 12; i++) {
111 tm.tm_mon = i;
112 strftime(buf, sizeof(buf), "%b", &tm);
113 for (l = strlen(buf);
114 l > 0 && isspace((unsigned char)buf[l - 1]);
115 l--)
116 ;
117 buf[l] = '\0';
116 if (nmonths[i] != NULL)
117 free(nmonths[i]);
118 nmonths[i] = strdup(buf);
118 if (nmonths[i].name != NULL)
119 free(nmonths[i].name);
120 nmonths[i].name = strdup(buf);
121 nmonths[i].len = strlen(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';
122
123 strftime(buf, sizeof(buf), "%B", &tm);
124 for (l = strlen(buf);
125 l > 0 && isspace((unsigned char)buf[l - 1]);
126 l--)
127 ;
128 buf[l] = '\0';
126 if (fnmonths[i] != NULL)
127 free(fnmonths[i]);
128 fnmonths[i] = strdup(buf);
129 if (fnmonths[i].name != NULL)
130 free(fnmonths[i].name);
131 fnmonths[i].name = strdup(buf);
132 fnmonths[i].len = strlen(buf);
129#ifdef DEBUG
130 printf("nmonths[%d] = %s, fnmonths[%d] = %s\n",
133#ifdef DEBUG
134 printf("nmonths[%d] = %s, fnmonths[%d] = %s\n",
131 i, nmonths[i], i, fnmonths[i]);
135 i, nmonths[i].name, i, fnmonths[i].name);
132#endif
133 }
134}
135
136void
137settime(now)
138 time_t now;
139{

--- 243 unchanged lines hidden (view full) ---

383}
384
385
386int
387getmonth(s)
388 register char *s;
389{
390 register char **p;
136#endif
137 }
138}
139
140void
141settime(now)
142 time_t now;
143{

--- 243 unchanged lines hidden (view full) ---

387}
388
389
390int
391getmonth(s)
392 register char *s;
393{
394 register char **p;
395 struct fixs *n;
391
396
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);
397 for (n = fnmonths; n->name; ++n)
398 if (!strncasecmp(s, n->name, n->len))
399 return ((n - fnmonths) + 1);
400 for (n = nmonths; n->name; ++n)
401 if (!strncasecmp(s, n->name, n->len))
402 return ((n - nmonths) + 1);
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;
403 for (p = months; *p; ++p)
404 if (!strncasecmp(s, *p, 3))
405 return ((p - months) + 1);
406 return (0);
407}
408
409
410int
411getday(s)
412 register char *s;
413{
414 register char **p;
415 struct fixs *n;
410
416
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);
417 for (n = fndays; n->name; ++n)
418 if (!strncasecmp(s, n->name, n->len))
419 return ((n - fndays) + 1);
420 for (n = ndays; n->name; ++n)
421 if (!strncasecmp(s, n->name, n->len))
422 return ((n - ndays) + 1);
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 ---
423 for (p = days; *p; ++p)
424 if (!strncasecmp(s, *p, 3))
425 return ((p - days) + 1);
426 return (0);
427}
428
429/* return offset for variable weekdays
430 * -1 -> last weekday in month

--- 47 unchanged lines hidden ---