annotate bdengine.c @ 3:dc2f94280b01

new Makefile; removed MinWarn and MaxWarn; adjusted manpage
author meillo@marmaro.de
date Mon, 17 Dec 2007 11:28:40 +0100
parents 9ec037775c38
children 5326c222cd4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
1 /*
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
2 birthday.c
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
3
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
4 Birthday/Anniversary display on login
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
5
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
6 (c) 1996 AS Mortimer
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
7
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
8 This program is free software; you can redistribute it and/or
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
9 modify it under the terms of the GNU General Public License as
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
10 published by the Free Software Foundation; either version 2 of the
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
11 License, or (at your option) any later version. You may also
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
12 distribute it under the Artistic License, as comes with Perl.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
13
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
17
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
19 along with this program; if not, write to the Free Software
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
21
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
22 You should also have recieved a copy of the Artistic license with
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
23 this program.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
24
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
25 $Id: bdengine.c,v 1.14 2001/10/21 07:03:49 andy Exp $
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
26
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
27 We're getting there. At the moment, the file used by default is ~/.birthdays
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
28 under UNIX, or C:\PERSONAL\BDAYS.LST under DOS, but this can be overridden on
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
29 the command line. The file has the following format:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
30
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
31 name/event/whatever=date flags
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
32 where:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
33 date is dd/mm, dd/mm/yy (assumes 20th century!) or dd/mm/yyyy
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
34 flags is ONE or ZERO of
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
35 o bd for a birthday (default)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
36 o bir for a birthday (exactly equivalent to `bd')
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
37 o ann for an anniversary
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
38 o ev for an event
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
39 and zero or more of
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
40 o w<n> to set the warn-in-advance time to n days (don't include the
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
41 brackets! :)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
42 o to<date>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
43 o for<days>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
44 to specify the length of time taken by an event, for example a
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
45 holiday.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
46
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
47 Comment lines are preceeded by #.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
48
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
49 Note: If you deviate from this format, I cannot guarantee anything about
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
50 it's behaviour. In most cases, it will just quietly ignore the error,
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
51 which probably isn't ideal behaviour. Oh, well.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
52
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
53 2003/05/20: Automatic reallocation of output buffer in listsrings() by
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
54 Sebastian Schmidt <yath@yath.eu.org>.
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
55
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
56 */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
57
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
58
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
59
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
60 /* ========== */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
61
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
62
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
63 #include <stdio.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
64 #include <stdarg.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
65 #include <stdlib.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
66 #include <string.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
67 #include <time.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
68
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
69 #include <sys/types.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
70 #include <unistd.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
71 #include <pwd.h>
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
72
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
73 #include "birthday.h"
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
74
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
75 /* ========== */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
76
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
77
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
78
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
79 /*
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
80 xmalloc/xrealloc functions, and fatal exit function
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
81 Note: the x* functions are lifted straight from the GNU libc info docs
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
82 $Id: xmalloc.c,v 1.2 1999/01/16 17:08:59 andy Exp $
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
83 */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
84
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
85 void* xmalloc (size_t size) {
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
86 register void* value = malloc (size);
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
87 if (value == 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
88 fprintf(stderr, "virtual memory exhausted\n");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
89 exit(1);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
90 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
91 return value;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
92 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
93
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
94
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
95 void* xrealloc (void* ptr, size_t size) {
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
96 register void* value = realloc (ptr, size);
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
97 if (value == 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
98 fprintf(stderr, "virtual memory exhausted\n");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
99 exit(1);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
100 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
101 return value;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
102 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
103
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
104 /* ========== */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
105
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
106
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
107
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
108
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
109
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
110
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
111 int skptok(int j, char *ptr);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
112 int evcmp(const void *e1, const void *e2);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
113 char *deffname(void);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
114
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
115
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
116 /* ========== Global variables */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
117
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
118 struct date today;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
119 int iDWarn = DEF_WARN;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
120
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
121 const unsigned MLENDAT[]={31,-1,31,30,31,30,31,31,30,31,30,31};
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
122
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
123 const struct _ftable FTABLE[] = {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
124 {"bir",F_TBIRTHDAY},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
125 {"bd", F_TBIRTHDAY},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
126 {"ann",F_TANNIVERSARY},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
127 {"ev", F_TEVENT},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
128 {"mes", F_TMESSAGE},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
129 {"w", F_WTIME_P},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
130 {"to", F_TODATE},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
131 {"for", F_FORDAYS},
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
132 {NULL, 0}
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
133 };
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
134
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
135
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
136
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
137 /* ========== */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
138
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
139
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
140
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
141
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
142 /* compare the first strlen(a) characters of a and b */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
143 #define strbegcmp(a,b) strncmp(a,b,strlen(a))
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
144
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
145 /* like strcat(), but lets the buffer automagically grow :-)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
146 * (needs local variable "size" with the buffer size) */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
147 #define append(where, what) do { \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
148 if (strlen(what) > (size - strlen(where))) { \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
149 xrealloc(where, size + 128 + strlen(what)); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
150 size += 128 + strlen(what); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
151 } \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
152 strcat(where, what); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
153 } while(0)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
154
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
155 /* ========== */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
156
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
157 /* returns delta(d) in days, weeks, months, etc
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
158 * the returned buffer is malloc()ed, do not forget to free() it */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
159 char *tdelta(struct date *d) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
160 int dy, wk, mn, yr;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
161 char *tmp;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
162 char *buf = xmalloc(128);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
163 int size = 128;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
164 *buf = 0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
165
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
166 switch (delta(d)) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
167 case 0:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
168 append(buf, "today");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
169 return buf;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
170 case 1:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
171 append(buf, "tomorrow");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
172 return buf;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
173 default:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
174 /* like delta(), we ignore the year */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
175 yr=-before(*d,today);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
176 mn=d->month - today.month;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
177 dy=d->day - today.day;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
178
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
179 if (dy < 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
180 dy += mlen(today.month, today.year);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
181 mn--;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
182 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
183 if (mn < 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
184 mn += 12;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
185 yr++;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
186 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
187
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
188 wk = (dy/7);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
189 dy%=7;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
190
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
191 append(buf, "in ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
192 tmp = ttime(yr, mn, wk, dy);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
193 append(buf, tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
194 free(tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
195
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
196 if (*(buf + strlen(buf) - 1) == 's')
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
197 append(buf, "'");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
198 else
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
199 append(buf, "'s");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
200
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
201 append(buf, " time");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
202
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
203 return buf;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
204 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
205 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
206
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
207
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
208
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
209
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
210
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
211 /*
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
212 void donum(n,txt) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
213 do {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
214 if (n > 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
215 snprintf(tmp, sizeof(tmp), "%d", n);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
216 append(buf, tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
217 append(buf, " " txt);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
218 if (n != 1)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
219 append(buf, "s");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
220 terms--;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
221 if (orgterms > 1) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
222 if (terms == 1)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
223 append(buf, " and ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
224 else if (terms > 1)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
225 append(buf, ", ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
226 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
227 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
228 } while(0)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
229 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
230 */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
231
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
232
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
233 #define donum(n,txt) do { \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
234 if (n > 0) { \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
235 snprintf(tmp, sizeof(tmp), "%d", n); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
236 append(buf, tmp); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
237 append(buf, " " txt); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
238 if (n != 1) \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
239 append(buf, "s"); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
240 terms--; \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
241 if (orgterms > 1) { \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
242 if (terms == 1) \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
243 append(buf, " and "); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
244 else if (terms > 1) \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
245 append(buf, ", "); \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
246 } \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
247 } \
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
248 } while(0)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
249
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
250
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
251 /* returns allocated buffer, don't forget to free() */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
252 char* ttime(int yr, int mn, int wk, int dy) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
253 char* buf = xmalloc(128);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
254 int size = 128;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
255 int terms, orgterms;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
256 char tmp[128];
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
257
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
258 *buf = 0; /* Initialize buffer */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
259 terms = orgterms = (yr!=0) + (mn!=0) + (wk!=0) + (dy!=0);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
260
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
261 donum(yr, "year");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
262 donum(mn, "month");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
263 donum(wk, "week");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
264 donum(dy, "day");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
265
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
266 return buf;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
267 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
268 #undef donum
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
269
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
270
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
271
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
272
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
273
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
274
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
275 /* lists the birthdays in their string format, one by one, and passes the string
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
276 to a function. */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
277 void liststrings(struct event *evl, prnfunc outf) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
278 int i,j;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
279 char *buf, *tmp;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
280 int size;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
281
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
282 for (i = 0; evl[i].text != NULL; i++) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
283 buf = xmalloc(128);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
284 *buf = '\0';
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
285 size = 128;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
286
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
287 if (evl[i].warn == -1 && delta(&(evl[i].date))==0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
288 append(buf, evl[i].text);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
289 } else if (evl[i].enddate.day == 0) {
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
290 if (delta(&(evl[i].date)) <= evl[i].warn) {
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
291 append(buf, evl[i].text);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
292 append(buf, " ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
293 tmp = tdelta(&(evl[i].date));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
294 append(buf, tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
295 free(tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
296 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
297 } else {
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
298 if (delta(&(evl[i].date)) <= evl[i].warn) {
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
299 append(buf, evl[i].text);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
300 append(buf, " for ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
301 /* +1 because, if the difference between two dates is one day,
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
302 then the length of an event on those days is two days */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
303 j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
304 tmp = ttime(0, 0, j/7, j%7);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
305 append(buf, tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
306 free(tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
307 append(buf, " ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
308 tmp = tdelta(&(evl[i].date));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
309 append(buf, tmp);
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 2
diff changeset
310 } else if (delta(&(evl[i].enddate)) <= evl[i].warn) {
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
311 append(buf, evl[i].text);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
312 append(buf, " ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
313 j = delta(&(evl[i].enddate));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
314 if (j) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
315 append(buf, "for ");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
316 tmp = ttime(0, 0, j/7, j%7);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
317 append(buf, tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
318 free(tmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
319 append(buf, " longer");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
320 } else {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
321 append(buf, "finishes today");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
322 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
323 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
324 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
325 if (*buf) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
326 append(buf, ".");
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
327 outf(buf);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
328 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
329 free(buf);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
330 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
331 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
332
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
333
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
334
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
335
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
336
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
337
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
338
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
339 char* deffname(void) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
340 char buf[256];
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
341
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
342 strcpy(buf, getpwuid(getuid())->pw_dir);
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
343 strcat(buf, "/" DEFAULT_FILE);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
344
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
345 return strdup(buf);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
346 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
347
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
348
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
349
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
350
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
351
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
352
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
353 /* sort the events by the time before the next time they come up, putting those
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
354 where the start has passed but we are still in the time-period first */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
355 int evcmp(const void *p1, const void *p2) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
356 struct event *e1=(struct event *)p1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
357 struct event *e2=(struct event *)p2;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
358 unsigned d1,d2;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
359
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
360 /* if the delta for the enddate is less than that for the start date, then we
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
361 have passed the start date but not yet the end date, and so we should
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
362 display the enddate; otherwise, we should display the start date */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
363
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
364 d1=delta(&(e1->date));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
365 if (e1->enddate.day && delta(&(e1->enddate)) < d1)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
366 d1=delta(&(e1->enddate));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
367
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
368 d2=delta(&(e2->date));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
369 if (e2->enddate.day && delta(&(e2->enddate)) < d2)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
370 d2=delta(&(e2->enddate));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
371
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
372 if (d1 < d2) return -1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
373 if (d1 > d2) return 1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
374
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
375 return strcmp(e1->text, e2->text);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
376 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
377
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
378
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
379
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
380
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
381
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
382
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
383 /* difference in days between two dates */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
384 /* it is assumed that D1 < D2, and so the result is always positive */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
385 unsigned ddiff(struct date *D1, struct date *D2) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
386 struct date d1,d2;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
387 int dd,m;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
388
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
389 /* make working copies */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
390 d1=*D1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
391 d2=*D2;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
392
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
393 /* sort out zero years */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
394 if (d1.year == 0 || d2.year==0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
395 if (d1.year != d2.year) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
396 if (d1.year == 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
397 if (before(d1,d2))
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
398 d1.year=d2.year;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
399 else
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
400 d1.year=d2.year-1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
401 } else {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
402 if (before(d1,d2))
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
403 d2.year=d1.year;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
404 else
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
405 d2.year=d1.year+1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
406 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
407 } else { /* both years zero */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
408 if (before(d1,d2))
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
409 d1.year=d2.year=today.year;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
410 else {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
411 d1.year=today.year;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
412 d2.year=d1.year+1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
413 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
414 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
415 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
416
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
417 /* now we can actually do the comparison ... */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
418 dd=0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
419
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
420 /* to start with, we work in months */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
421 for (m=d1.month; m < d2.month + (d2.year-d1.year)*12; m++)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
422 dd += mlen(((m-1)%12)+1, d1.year + m/12);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
423
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
424 /* and then we renormalise for the days within the months */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
425 /* the first month was included in our calculations */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
426 dd -= d1.day;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
427 /* but the last one wasn't */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
428 dd += d2.day;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
429
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
430 return dd;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
431 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
432
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
433
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
434
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
435
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
436
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
437
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
438
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
439
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
440 /* actually until the next anniversary of ... */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
441 unsigned delta(struct date *date) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
442 struct date d;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
443 unsigned dt, mn;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
444
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
445 memcpy(&d, date, sizeof(struct date));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
446
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
447 /* past the end of the year */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
448 if (before(d, today)) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
449 d.year = 1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
450 } else {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
451 d.year = 0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
452 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
453
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
454 for (mn = today.month, dt=0; mn < d.month + 12*d.year; mn++)
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
455 dt += mlen(((mn-1)%12) + 1,today.year + mn/12);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
456
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
457 dt -= today.day;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
458 dt += d.day;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
459
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
460 return dt;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
461 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
462
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
463
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
464
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
465
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
466
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
467
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
468 void gettoday(void) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
469 struct tm *tm;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
470 time_t t;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
471
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
472 time(&t);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
473 tm = localtime(&t);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
474 today.day = tm->tm_mday;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
475 today.month = tm->tm_mon + 1; /* 1-12 instead of 0-11 */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
476 today.year = tm->tm_year;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
477 today.year += 1900;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
478 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
479
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
480
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
481
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
482
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
483
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
484 struct event *readlist(char *fname) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
485 FILE *file;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
486 int i,j,k,l,d;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
487 struct event *evl;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
488 char buf[1024], buf2[1024];
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
489 char *ptr;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
490 unsigned flags;
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
491
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
492 /* initialise */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
493 if (fname==NULL) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
494 fname=deffname();
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
495 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
496
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
497 gettoday();
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
498
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
499 if (fname[0] == '-' && fname[1] == 0) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
500 /* read from stdin */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
501 file=stdin;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
502 } else {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
503 /* now read it */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
504 if((file=fopen(fname, "rt"))==NULL) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
505 fprintf(stderr, "Unable to open file \"%s\"\n", fname);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
506 exit(1);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
507 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
508 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
509
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
510
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
511 for (i = 0, evl=NULL; fgets(buf, sizeof(buf), file) != NULL; i++) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
512 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
513
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
514 /* ignore comments and empty lines */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
515 if (*buf == '#' || *buf == '\n') {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
516 i--;
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
517 continue;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
518 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
519
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
520 /* parse string in buf */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
521 ptr = strrchr(buf, '='); /* allow '=' in text */
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
522
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
523 /* not a valid line, so ignore it! Cool, huh? */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
524 if (ptr == NULL) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
525 fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
526 i--;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
527 continue;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
528 }
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
529
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
530 *(ptr++) = 0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
531
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
532 j = sscanf(ptr, "%u-%u-%u", &(evl[i].date.year), &(evl[i].date.month), &(evl[i].date.day));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
533 /* if our year is only two digits, add 1900 to it ... */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
534 if(evl[i].date.year < 100) evl[i].date.year+=1900;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
535 /* ... unless it wasn't read, in which case set it to zero */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
536 if(j==2) evl[i].date.year=0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
537
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
538 /* parse flags */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
539
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
540 evl[i].warn=iDWarn;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
541 evl[i].enddate.day=evl[i].enddate.month=evl[i].enddate.year=0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
542
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
543 flags=j=0;
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
544 while(j = skptok(j, ptr),ptr[j]!=0) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
545 for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
546 switch (FTABLE[k].flag) {
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
547 case F_WTIME_P: /* w<n> -- sets warning time */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
548 sscanf(ptr + j, "w %u", &(evl[i].warn));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
549 break;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
550 case F_FORDAYS: /* for<days> -- sets the duration of the event */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
551 sscanf(ptr + j, "for %d", &d);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
552 evl[i].enddate=evl[i].date;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
553 for (l=1; l < d; l++) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
554 evl[i].enddate.day++;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
555 if (evl[i].enddate.day > mlen(evl[i].enddate.month,
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
556 evl[i].enddate.year)) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
557 evl[i].enddate.month++;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
558 evl[i].enddate.day=1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
559 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
560 if (evl[i].enddate.month > 12) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
561 evl[i].enddate.year++;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
562 evl[i].enddate.month=1;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
563 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
564 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
565 break;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
566 case F_TODATE:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
567 l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day));
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
568 if (evl[i].enddate.year < 100) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
569 evl[i].enddate.year+=1900;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
570 }
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
571 if (l == 2) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
572 evl[i].enddate.year=0;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
573 }
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
574 break;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
575 case 0:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
576 break;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
577 default:
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
578 flags|=FTABLE[k].flag;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
579 break;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
580 }
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
581 }
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
582
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
583
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
584 /* construct event text */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
585
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
586 switch(flags & F_MTYPE) {
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
587 case F_TBIRTHDAY:
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
588 default: /* assume it's a birthday */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
589 if (evl[i].date.year != 0) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
590 int tmp_age=ydelta(evl[i].date, today);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
591 if (tmp_age!=1) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
592 sprintf(buf2, "%s is %d years old", buf, tmp_age);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
593 } else {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
594 sprintf(buf2, "%s is %d year old", buf, tmp_age);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
595 }
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
596 } else {
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
597 sprintf(buf2, "%s has a birthday", buf);
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
598 }
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
599 break;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
600 case F_TANNIVERSARY:
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
601 if (evl[i].date.year != 0) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
602 sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today));
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
603 } else {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
604 strcpy(buf2, buf);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
605 }
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
606 break;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
607 case F_TEVENT:
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
608 /* if a year was specified, and this warning isn't for it, ignore! */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
609 if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
610 (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
611 i--;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
612 continue;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
613 }
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
614 strcpy(buf2, buf);
2
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
615 break;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
616 case F_TMESSAGE:
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
617 /* Like an event, except that it only comes up on the given date, and no text at all is appended */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
618 if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
619 (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
620 i--;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
621 continue;
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
622 }
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
623 strcpy(buf2, buf);
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
624 evl[i].warn=-1; /* special code! */
9ec037775c38 removed code for &include in input files
meillo@marmaro.de
parents: 0
diff changeset
625 break;
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
626 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
627 evl[i].text = strdup(buf2);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
628 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
629
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
630 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
631 evl[i].date.day=evl[i].date.month=evl[i].date.year=0;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
632 evl[i].text = (char *) NULL;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
633
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
634 fclose(file);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
635 free(fname);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
636
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
637 /* NB uses i from above */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
638 qsort(evl, i, sizeof(struct event), evcmp);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
639 return evl;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
640 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
641
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
642
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
643
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
644
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
645
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
646
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
647
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
648
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
649 int skptok(int j, char *ptr) {
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
650 for (; ptr[j] != 0 && ptr[j] != ' ' && ptr[j] != '\t' ; j++);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
651 for (; ptr[j] != 0 && (ptr[j] == ' ' || ptr[j] == '\t'); j++);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
652
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
653 return j;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
654 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
655
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
656