annotate bday.c @ 24:c621d710d12e default tip

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