annotate bday.c @ 15:032af48d590b

reformating of the source code
author markus schnalke <meillo@marmaro.de>
date Mon, 24 Feb 2014 17:46:57 +0100
parents a56120a4678f
children 79d22407a6be
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
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
29 text=date flags
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:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
32 date is yyyy-mm-dd
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
33 flags is ONE or ZERO of
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
34 bd for a birthday (default)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
35 ann for an anniversary
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
36 ev for an event
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
37 and zero or more of
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
38 w <n> to set the warn-in-advance time to n days
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
39 (don't include the brackets! :)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
40 to <date>
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
41 for <days>
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
42 to specify the length of time taken by an
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
43 event, for example a holiday.
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
44
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
45 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
46
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
47 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
48 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
49 error, which probably isn't ideal behaviour. Oh, well.
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
50
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
51 =====================================================================
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
52 */
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
53
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
54
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
55 /* standard time to warn in advance, when no explicit w flag is given. */
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
56 #define DEF_WARN 14
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
57
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
58
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
59 #include <stdarg.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
60 #include <stdio.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
61 #include <stdlib.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
62 #include <string.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
63 #include <sys/types.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
64 #include <time.h>
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
65 #include <unistd.h>
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
68
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
69 /* ========== Global constants and data types */
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
72 /* month lengths etc */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
73 #define isleapyear(y) ((y)%4==0 && ((y)%100 != 0 || (y)%400 == 0))
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
74 const unsigned MLENDAT[];
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
75 #define mlen(m,y) (MLENDAT[(m)-1] != -1 ? MLENDAT[(m)-1] : (isleapyear((y)) ? 29 : 28))
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
76 #define before(a,b) ((a).month < (b).month || ((a).month == (b).month && (a).day < (b).day))
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
77 #define ydelta(a,b) ((int) (b).year - (a).year + before((a),(b)))
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
78
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
79 /* -------- modifier flags */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
80 #define F_MTYPE 0x07
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
81 #define F_TBIRTHDAY 1
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
82 #define F_TANNIVERSARY 2
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
83 #define F_TEVENT 3
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
84
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
85 /* flags processed immediately on encountering */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
86 #define F_MIMMEDIATE 0x24
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
87 #define F_WTIME_P 0x08
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
88 #define F_FORDAYS 0x16
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
89 #define F_TODATE 0x24
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
90
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
91 struct _ftable {char* txt; unsigned flag;};
7
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 const struct _ftable FTABLE[];
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
94
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
95 struct date {
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
96 unsigned day;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
97 unsigned month;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
98 unsigned year;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
99 };
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
100
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
101 struct event {
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
102 char* text;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
103 struct date date;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
104 struct date enddate;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
105 int warn;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
106 };
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
107
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
108 typedef int (*prnfunc)(const char *);
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 /* ========== Global Variables */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
111
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
112 struct event *readlist(void);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
113 void gettoday(void);
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
114 unsigned delta(struct date *);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
115 unsigned ddiff(struct date *D1, struct date *D2);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
116 void liststrings(struct event *evl, prnfunc outf);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
117 char *tdelta(struct date *d);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
118 char *ttime(int yr, int mn, int wk, int dy);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
119 int skptok(int j, char *ptr);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
120 int evcmp(const void *e1, const void *e2);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
121
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
122
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
123 struct date today;
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
124 int iDWarn = DEF_WARN;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
125
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
126 const unsigned MLENDAT[] = {31,-1,31,30,31,30,31,31,30,31,30,31};
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
127
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
128 const struct _ftable FTABLE[] = {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
129 {"bd", F_TBIRTHDAY},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
130 {"ann",F_TANNIVERSARY},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
131 {"ev", F_TEVENT},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
132 {"w", F_WTIME_P},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
133 {"to", F_TODATE},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
134 {"for", F_FORDAYS},
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
135 {NULL, 0}
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
138
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
139
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
140
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
141
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
142
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
143 /*
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
144 xmalloc/xrealloc functions
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
145 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
146 $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
147 */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
148
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
149 void *
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
150 xmalloc(size_t size)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
151 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
152 register void *value = malloc (size);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
153 if (value == 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
154 fprintf(stderr, "virtual memory exhausted\n");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
155 exit(1);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
156 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
157 return value;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
158 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
159
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
160 void *
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
161 xrealloc(void *ptr, size_t size)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
162 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
163 register void *value = realloc (ptr, size);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
164 if (value == 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
165 fprintf(stderr, "virtual memory exhausted\n");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
166 exit(1);
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 return value;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
169 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
170
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
171
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
172 /* ========== */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
173
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
174
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
175 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
176 like strcat(), but lets the buffer automagically grow :-)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
177 (needs local variable "size" with the buffer size)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
178 */
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
179 #define append(where, what) do { \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
180 if (strlen(what) > (size - strlen(where))) { \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
181 xrealloc(where, size + 128 + strlen(what)); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
182 size += 128 + strlen(what); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
183 } \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
184 strcat(where, what); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
185 } while(0)
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
186
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
187 /* ========== */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
188
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
189 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
190 returns delta(d) in days, weeks, months, etc
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
191 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
192 */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
193 char *
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
194 tdelta(struct date *d)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
195 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
196 int dy, wk, mn, yr;
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
197 char *tmp;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
198 char *buf = xmalloc(128);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
199 int size = 128;
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
200
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
201 *buf = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
202 switch (delta(d)) {
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
203 case 0:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
204 append(buf, "today");
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
205 return buf;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
206 case 1:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
207 append(buf, "tomorrow");
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
208 return buf;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
209 default:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
210 /* like delta(), we ignore the year */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
211 yr = -before(*d, today);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
212 mn = d->month - today.month;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
213 dy = d->day - today.day;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
214
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
215 if (dy < 0) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
216 dy += mlen(today.month, today.year);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
217 mn--;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
218 }
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
219 if (mn < 0) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
220 mn += 12;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
221 yr++;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
222 }
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
223
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
224 wk = (dy / 7);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
225 dy %= 7;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
226
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
227 append(buf, "in ");
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
228 tmp = ttime(yr, mn, wk, dy);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
229 append(buf, tmp);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
230 free(tmp);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
231
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
232 return buf;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
233 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
234 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
235
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
236
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
237
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
238
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
239
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
240 /*
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
241 void
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
242 donum(n,txt)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
243 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
244 if (n > 0) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
245 snprintf(tmp, sizeof(tmp), "%d", n);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
246 append(buf, tmp);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
247 append(buf, " " txt);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
248 if (n != 1)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
249 append(buf, "s");
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
250 terms--;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
251 if (orgterms > 1) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
252 if (terms == 1)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
253 append(buf, " and ");
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
254 else if (terms > 1)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
255 append(buf, ", ");
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
256 }
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
257 }
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
258 }
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
259 */
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
260
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
261
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
262 #define donum(n,txt) do { \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
263 if (n > 0) { \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
264 snprintf(tmp, sizeof(tmp), "%d", n); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
265 append(buf, tmp); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
266 append(buf, " " txt); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
267 if (n != 1) \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
268 append(buf, "s"); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
269 terms--; \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
270 if (orgterms > 1) { \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
271 if (terms == 1) \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
272 append(buf, " and "); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
273 else if (terms > 1) \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
274 append(buf, ", "); \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
275 } \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
276 } \
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
277 } while(0)
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
278
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
279
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
280 /* returns allocated buffer, don't forget to free() */
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
281 char *
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
282 ttime(int yr, int mn, int wk, int dy)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
283 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
284 char *buf = xmalloc(128);
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
285 int size = 128;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
286 int terms, orgterms;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
287 char tmp[128];
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
288
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
289 *buf = 0; /* Initialize buffer */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
290 terms = orgterms = (yr!=0) + (mn!=0) + (wk!=0) + (dy!=0);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
291
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
292 donum(yr, "year");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
293 donum(mn, "month");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
294 donum(wk, "week");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
295 donum(dy, "day");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
296
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
297 return buf;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
298 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
299 #undef donum
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
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
311 liststrings(struct event *evl, prnfunc outf)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
312 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
313 int i,j;
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
317 for (i = 0; evl[i].text != NULL; i++) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
318 buf = xmalloc(128);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
319 *buf = '\0';
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
320 size = 128;
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) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
323 append(buf, evl[i].text);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
324 } else if (evl[i].enddate.day == 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
325 if (delta(&(evl[i].date)) <= evl[i].warn) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
326 append(buf, evl[i].text);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
327 append(buf, " ");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
328 tmp = tdelta(&(evl[i].date));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
329 append(buf, tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
330 free(tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
331 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
332 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
333 if (delta(&(evl[i].date)) <= evl[i].warn) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
334 append(buf, evl[i].text);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
335 append(buf, " for ");
14
a56120a4678f wrapping of long lines
meillo@marmaro.de
parents: 9
diff changeset
336 /* +1 because, if the difference between two dates is one day,
a56120a4678f wrapping of long lines
meillo@marmaro.de
parents: 9
diff changeset
337 then the length of an event on those days is two days */
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
338 j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
339 tmp = ttime(0, 0, j/7, j%7);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
340 append(buf, tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
341 free(tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
342 append(buf, " ");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
343 tmp = tdelta(&(evl[i].date));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
344 append(buf, tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
345 } else if (delta(&(evl[i].enddate)) <= evl[i].warn) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
346 append(buf, evl[i].text);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
347 append(buf, " ");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
348 j = delta(&(evl[i].enddate));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
349 if (j) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
350 append(buf, "for ");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
351 tmp = ttime(0, 0, j/7, j%7);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
352 append(buf, tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
353 free(tmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
354 append(buf, " longer");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
355 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
356 append(buf, "finishes today");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
357 }
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 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
360 if (*buf) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
361 append(buf, ".");
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
362 outf(buf);
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 free(buf);
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
369
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
370
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
371
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
372
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
373
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
374
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
375 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
376 sort the events by the time before the next time they come up,
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
377 putting those where the start has passed but we are still in the
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
378 time-period first
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
379 */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
380 int
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
381 evcmp(const void *p1, const void *p2)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
382 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
383 struct event *e1=(struct event *) p1;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
384 struct event *e2=(struct event *) p2;
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
385 unsigned d1, d2;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
386
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
387 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
388 if the delta for the enddate is less than that for the start
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
389 date, then we have passed the start date but not yet the end
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
390 date, and so we should display the enddate; otherwise, we
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
391 should display the start date
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
392 */
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
393
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
394 d1=delta(&(e1->date));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
395 if (e1->enddate.day && delta(&(e1->enddate)) < d1)
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
396 d1=delta(&(e1->enddate));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
397
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
398 d2=delta(&(e2->date));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
399 if (e2->enddate.day && delta(&(e2->enddate)) < d2)
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
400 d2=delta(&(e2->enddate));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
401
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
402 if (d1 < d2) return -1;
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
403 if (d1 > d2) return 1;
7
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 return strcmp(e1->text, e2->text);
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
408
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
411
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
412
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
413 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
414 difference in days between two dates
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
415 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
416 */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
417 unsigned
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
418 ddiff(struct date *D1, struct date *D2)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
419 {
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
420 struct date d1, d2;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
421 int dd, m;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
422
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
423 /* make working copies */
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
424 d1 = *D1;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
425 d2 = *D2;
7
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 /* sort out zero years */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
428 if (d1.year == 0 || d2.year==0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
429 if (d1.year != d2.year) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
430 if (d1.year == 0) {
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
431 if (before(d1,d2))
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
432 d1.year = d2.year;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
433 else
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
434 d1.year = d2.year - 1;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
435 } else {
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
436 if (before(d1, d2))
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
437 d2.year = d1.year;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
438 else
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
439 d2.year = d1.year + 1;
7
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 } else { /* both years zero */
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
442 if (before(d1, d2))
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
443 d1.year = d2.year = today.year;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
444 else {
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
445 d1.year = today.year;
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
446 d2.year = d1.year + 1;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
447 }
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 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
450
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
451 /* now we can actually do the comparison ... */
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
452 dd = 0;
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 /* to start with, we work in months */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
455 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
456 dd += mlen(((m-1)%12)+1, d1.year + m/12);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
457
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
458 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
459 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
460 the first month was included in our calculations
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
461 */
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
462 dd -= d1.day;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
463 /* but the last one wasn't */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
464 dd += d2.day;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
465
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
466 return dd;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
467 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
468
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
469
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
472
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
473
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
474
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
475
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
476 /*
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
477 actually until the next anniversary of ...
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
478 */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
479 unsigned
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
480 delta(struct date *date)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
481 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
482 struct date d;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
483 unsigned dt, mn;
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 memcpy(&d, date, sizeof(struct date));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
486
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
487 /* past the end of the year */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
488 if (before(d, today)) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
489 d.year = 1;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
490 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
491 d.year = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
492 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
493
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
494 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
495 dt += mlen(((mn-1)%12) + 1,today.year + mn/12);
8
19c1ad697022 beautifing :-)
meillo@marmaro.de
parents: 7
diff changeset
496 }
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
497
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
498 dt -= today.day;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
499 dt += d.day;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
500
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
501 return dt;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
502 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
503
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
504
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
505
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
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
509 void
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
510 gettoday(void)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
511 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
512 struct tm *tm;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
513 time_t t;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
514
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
515 time(&t);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
516 tm = localtime(&t);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
517 today.day = tm->tm_mday;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
518 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
519 today.year = tm->tm_year + 1900;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
520 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
521
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
522
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
523
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
524
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
525
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
526
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
527
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
528
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
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
531 struct event *
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
532 readlist()
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
533 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
534 int i, j, k, l, d;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
535 struct event *evl;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
536 char buf[1024], buf2[1024];
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
537 char *ptr;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
538 unsigned flags;
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 /* initialise */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
541 gettoday();
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
542
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
543 for (i = 0, evl = NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
544 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
545
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
546 /* ignore comments and empty lines */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
547 if (*buf == '#' || *buf == '\n') {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
548 i--;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
549 continue;
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 /* parse string in buf */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
553 ptr = strrchr(buf, '='); /* allow '=' in text */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
554
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
555 /* not a valid line, so ignore it! Cool, huh? */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
556 /* Attention: only recognizes lines without '=' */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
557 if (ptr == NULL) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
558 fprintf(stderr, "WARNING: Invalid line in input:\n%s", buf);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
559 i--;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
560 continue;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
561 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
562
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
563 *(ptr++) = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
564
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
565 j = sscanf(ptr, "%u-%u-%u", &(evl[i].date.year),
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
566 &(evl[i].date.month), &(evl[i].date.day));
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
567 /* ... unless it wasn't read, in which case set it to zero */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
568 if (j==2) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
569 evl[i].date.year = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
570 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
571
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 /* parse flags */
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].warn = iDWarn;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
576 evl[i].enddate.day = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
577 evl[i].enddate.month = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
578 evl[i].enddate.year = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
579
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
580 flags = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
581 j = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
582
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
583 while(j = skptok(j, ptr), ptr[j] != 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
584 for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++) {
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
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
587 switch (FTABLE[k].flag) {
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
588 case F_WTIME_P: /* w <n> -- sets warning time */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
589 sscanf(ptr + j, "w %u", &(evl[i].warn));
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
590 break;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
591 case F_FORDAYS: /* for <days> -- sets the duration of the event */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
592 sscanf(ptr + j, "for %u", &d);
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
593 evl[i].enddate=evl[i].date;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
594 for (l = 1; l < d; l++) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
595 evl[i].enddate.day++;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
596 if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
597 evl[i].enddate.month++;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
598 evl[i].enddate.day = 1;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
599 }
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
600 if (evl[i].enddate.month > 12) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
601 evl[i].enddate.year++;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
602 evl[i].enddate.month = 1;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
603 }
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
604 }
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
605 break;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
606 case F_TODATE: /* to <date> -- sets the end date of the event */
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
607 l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day));
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
608 if (l == 2) {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
609 evl[i].enddate.year = 0;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
610 }
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
611 break;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
612 case 0:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
613 break;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
614 default:
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
615 flags |= FTABLE[k].flag;
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
616 break;
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
617 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
618 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
619
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
620
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
621 /* construct event text */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
622
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
623 switch(flags & F_MTYPE) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
624 case F_TBIRTHDAY:
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
625 default: /* assume it's a birthday */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
626 if (evl[i].date.year != 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
627 int tmp_age = ydelta(evl[i].date, today);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
628 if (tmp_age != 1) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
629 sprintf(buf2, "%s is %d years old", buf, tmp_age);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
630 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
631 sprintf(buf2, "%s is %d year old", buf, tmp_age);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
632 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
633 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
634 sprintf(buf2, "%s has a birthday", buf);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
635 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
636 break;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
637 case F_TANNIVERSARY:
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
638 if (evl[i].date.year != 0) {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
639 sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
640 } else {
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
641 strcpy(buf2, buf);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
642 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
643 break;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
644 case F_TEVENT:
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
645 /* if a year was specified, and this warning isn't for it, ignore! */
14
a56120a4678f wrapping of long lines
meillo@marmaro.de
parents: 9
diff changeset
646 if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0)
a56120a4678f wrapping of long lines
meillo@marmaro.de
parents: 9
diff changeset
647 && (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
648 i--;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
649 continue;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
650 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
651 strcpy(buf2, buf);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
652 break;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
653 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
654 evl[i].text = strdup(buf2);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
655 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
656
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
657 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
658 evl[i].date.day = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
659 evl[i].date.month = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
660 evl[i].date.year = 0;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
661 evl[i].text = (char *) NULL;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
662
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
663 fclose(stdin);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
664
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
665 /* NB uses i from above */
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
666 qsort(evl, i, sizeof(struct event), evcmp);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
667 return evl;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
668 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
669
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
670
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
671
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
672
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
673
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
674 int
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
675 skptok(int j, char *ptr)
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
676 {
7
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
677 for (; ptr[j] != 0 && ptr[j] != ' ' && ptr[j] != '\t' ; j++);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
678 for (; ptr[j] != 0 && (ptr[j] == ' ' || ptr[j] == '\t'); j++);
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
679
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
680 return j;
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
681 }
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
682
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
683
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
684
b6f4c7fba64a all sources now in one file
meillo@marmaro.de
parents: 6
diff changeset
685
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
686
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
687
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
688 int
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
689 main(int argc, char *argv[])
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
690 {
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
691 while (--argc > 0 && (*++argv)[0] == '-') {
5
5af6bf2cb271 reads only stdin now, no files anymore; removed -f option aswell; code beatifing
meillo@marmaro.de
parents: 3
diff changeset
692 if (strcmp(argv[0], "-W") == 0) {
6
fc6e40f7bd5a minor stuff
meillo@marmaro.de
parents: 5
diff changeset
693 /* TODO: catch if no value given */
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
694 iDWarn = atoi((++argv)[0]);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
695 argc--;
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
696 } else {
3
dc2f94280b01 new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents: 0
diff changeset
697 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
698 exit(1);
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
699 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
700 }
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
701
6
fc6e40f7bd5a minor stuff
meillo@marmaro.de
parents: 5
diff changeset
702 liststrings(readlist(), puts);
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
703
15
032af48d590b reformating of the source code
markus schnalke <meillo@marmaro.de>
parents: 14
diff changeset
704 return 0;
0
22b6e71de68e initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff changeset
705 }