| 1 |
/* |
| 2 |
birthday |
| 3 |
|
| 4 |
Birthday/Anniversary display on login |
| 5 |
|
| 6 |
(c) 1996 AS Mortimer |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU General Public License as |
| 10 |
published by the Free Software Foundation; either version 2 of the |
| 11 |
License, or (at your option) any later version. You may also |
| 12 |
distribute it under the Artistic License, as comes with Perl. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program; if not, write to the Free Software |
| 20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 |
|
| 22 |
You should also have recieved a copy of the Artistic license with |
| 23 |
this program. |
| 24 |
|
| 25 |
$Id: bdcal.c,v 1.4 2005/12/09 18:06:59 andymort Exp $ */ |
| 26 |
|
| 27 |
#include <time.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "birthday.h" |
| 31 |
|
| 32 |
int iCLines = 6; /* lines-per-day in the calendar */ |
| 33 |
int iCWidth = 80; /* width of calendar, in characters */ |
| 34 |
int iCWeeks = 0; /* weeks-per-page in the calendar, or 0 to supress page-breaks */ |
| 35 |
int iCTotal = 28; /* total number of days to print the calendar for */ |
| 36 |
|
| 37 |
/* output the list in a calendar-style format */ |
| 38 |
|
| 39 |
void do_cal(struct event *evl, const struct date *today) |
| 40 |
{ |
| 41 |
unsigned i,j,k,lines, chars; |
| 42 |
char *buf = xmalloc(iCWidth+1); |
| 43 |
char *buf2 = xmalloc(iCWidth*3+1); |
| 44 |
struct tm btime; |
| 45 |
|
| 46 |
/* need the day-of-week info for whatever we're using as today */ |
| 47 |
{ |
| 48 |
time_t now; |
| 49 |
struct tm tmtoday; |
| 50 |
tmtoday.tm_sec = 0; |
| 51 |
tmtoday.tm_min = 0; |
| 52 |
tmtoday.tm_hour = 12; /* safely halfway through the day */ |
| 53 |
tmtoday.tm_mday = today->day; |
| 54 |
tmtoday.tm_mon = today->month - 1; |
| 55 |
tmtoday.tm_year = today->year - 1900; |
| 56 |
now = mktime( &tmtoday ); |
| 57 |
btime = *localtime( &now ); |
| 58 |
} |
| 59 |
|
| 60 |
for (i=j=0; i < iCTotal; i++) |
| 61 |
{ |
| 62 |
if (iCWeeks != 0 && i!=0 && (i%(iCWeeks*7))==0) printf("\x0c"); |
| 63 |
strftime(buf, iCWidth+1, "---%A-%B-%d-%Y", &btime); |
| 64 |
for (k=0; buf[k]!=0; k++) |
| 65 |
if (buf[k]==' ') buf[k]='-'; |
| 66 |
for (;k < iCWidth; k++) buf[k]='-'; |
| 67 |
buf[iCWidth]=0; |
| 68 |
if (btime.tm_wday==0 || btime.tm_wday==6) /* weekend---make it bold */ |
| 69 |
{ |
| 70 |
for (k=0; buf[k]!=0; k++) |
| 71 |
{ |
| 72 |
buf2[k*3]=buf[k]; |
| 73 |
buf2[k*3+1]='\b'; |
| 74 |
buf2[k*3+2]=buf[k]; |
| 75 |
} |
| 76 |
buf2[k*3]=0; |
| 77 |
printf("%s\n", buf2); |
| 78 |
} |
| 79 |
else |
| 80 |
printf("%s\n", buf); |
| 81 |
|
| 82 |
lines=1; |
| 83 |
chars=0; |
| 84 |
/* assuming the events are ordered by date, this will process all the events for the current day, if any, and |
| 85 |
leave j pointing to the first event which is not for today */ |
| 86 |
for (; evl[j].text != NULL && delta(&(evl[j].date), today) <= i; j++) |
| 87 |
if (delta(&(evl[j].date), today) == i) |
| 88 |
{ |
| 89 |
chars+=strlen(evl[j].text)+4; |
| 90 |
if (chars > iCWidth) |
| 91 |
{ |
| 92 |
chars=strlen(evl[j].text); |
| 93 |
printf("\n"); |
| 94 |
lines++; |
| 95 |
} |
| 96 |
printf("%s ", evl[j].text); |
| 97 |
} |
| 98 |
for (;lines < iCLines; lines++) printf("\n"); |
| 99 |
|
| 100 |
/* increment d */ |
| 101 |
btime.tm_mday++; |
| 102 |
btime.tm_wday=(++btime.tm_wday)%7; |
| 103 |
if(btime.tm_mday>mlen(btime.tm_mon+1, btime.tm_year)) |
| 104 |
{ |
| 105 |
if (btime.tm_mon==11) |
| 106 |
{ |
| 107 |
btime.tm_year++; |
| 108 |
btime.tm_mon = 0; |
| 109 |
} |
| 110 |
else |
| 111 |
btime.tm_mon++; |
| 112 |
btime.tm_mday=1; |
| 113 |
} |
| 114 |
} |
| 115 |
free(buf); |
| 116 |
free(buf2); |
| 117 |
} |